WindowsIconReader.st
author Claus Gittinger <cg@exept.de>
Sat, 12 May 2018 14:23:45 +0200
changeset 4088 bbf9b58f99c8
parent 4014 17853d377ead
child 4102 853f7162fc69
permissions -rw-r--r--
#FEATURE by cg class: MIMETypes class changed: #initializeFileInfoMappings class: MIMETypes::MIMEType added: #asMimeType #isCHeaderType #isCPPSourceType #isCSourceType
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
3f9277473954 Initial revision
claus
parents:
diff changeset
     1
"
3f9277473954 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
     3
	      All Rights Reserved
0
3f9277473954 Initial revision
claus
parents:
diff changeset
     4
3f9277473954 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
3f9277473954 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
3f9277473954 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
3f9277473954 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
3f9277473954 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
3f9277473954 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
3f9277473954 Initial revision
claus
parents:
diff changeset
    11
"
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    12
"{ Package: 'stx:libview2' }"
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    13
3568
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
    14
"{ NameSpace: Smalltalk }"
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
    15
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    16
ImageReader subclass:#WindowsIconReader
3591
87336f7e44cf #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3590
diff changeset
    17
	instanceVariableNames:'compression inDepth topDown redMask greenMask blueMask alphaMask
87336f7e44cf #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3590
diff changeset
    18
		pngOrJPGImage'
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    19
	classVariableNames:''
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    20
	poolDictionaries:''
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
    21
	category:'Graphics-Images-Readers'
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    22
!
3f9277473954 Initial revision
claus
parents:
diff changeset
    23
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    24
!WindowsIconReader class methodsFor:'documentation'!
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    25
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    26
copyright
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    27
"
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    28
 COPYRIGHT (c) 1993 by Claus Gittinger
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    29
	      All Rights Reserved
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    30
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    31
 This software is furnished under a license and may be used
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    32
 only in accordance with the terms of that license and with the
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    33
 inclusion of the above copyright notice.   This software may not
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    34
 be provided or otherwise made available to, or used by, any
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    35
 other person.  No title to or ownership of the software is
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    36
 hereby transferred.
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    37
"
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    38
!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    39
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    40
documentation
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    41
"
3584
141dd71ce83f #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 3583
diff changeset
    42
    this class provides methods for loading Windows and OS2 icon and bmp files.
3897
0d38bd3b99ee #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3896
diff changeset
    43
3920
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
    44
    The class name *IconReader is a bad, historic choice - it was originally
3897
0d38bd3b99ee #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3896
diff changeset
    45
    written to read icons only, but evolved over time and is now also
0d38bd3b99ee #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3896
diff changeset
    46
    capable of reading/writing bmp and cursor files.
3896
58e71198a302 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3742
diff changeset
    47
    
3596
dee4584a243a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3595
diff changeset
    48
    The reader should support allmost all formats: Win2, Win3, Win4, Win5, WINCE and OS2.
3595
bf71946129f1 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3594
diff changeset
    49
    (incl. PNG and JPG compression, and WINCE depth2 images)
bf71946129f1 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3594
diff changeset
    50
    
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
    51
    Image writing is only supported for BMP format with depth 1,4,8 and 24 bit images.
3595
bf71946129f1 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3594
diff changeset
    52
    
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    53
    The reader tries to figure out which version of BMP/ICO is used.
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    54
    It seems to be able to load most formats, but who knows ...
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    55
3920
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
    56
    [notice:]
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
    57
        when reading an ICO/CUR file with multiple icons in it,
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
    58
        the first image is returned as such, holding on the other images via its
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
    59
        imageFrames instvar.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
    60
        Thus, the imageEditor will usually present the first of the images,
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
    61
        and offer a next-in-sequence button to step through them.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
    62
        To get a collection of all images, collect the images from the sequence, as in:
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
    63
            someIcoImage imageFrames collect:#image
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
    64
            
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    65
    [See also:]
3158
b017a13ec3f5 class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 2812
diff changeset
    66
        Image Form Icon
b017a13ec3f5 class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 2812
diff changeset
    67
        BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader
b017a13ec3f5 class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 2812
diff changeset
    68
        ST80FormReader SunRasterReader TargaReader TIFFReader
3920
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
    69
        XBMReader XPMReader XWDReader MacOSXIconReader
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    70
"
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    71
!
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    72
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    73
fileFormatDescription
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    74
"
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    75
    Information from http://www.daubnet.com/formats/BMP.html - no Warranty.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    76
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
    77
          Name           Size      Offset   Description
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    78
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    79
      Header            14 bytes            Windows Structure: BITMAPFILEHEADER
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
    80
          Signature      2 bytes      0      'BM'
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
    81
          FileSize       4 bytes      2      File size in bytes
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
    82
          reserved       4 bytes      6      unused (=0)
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
    83
          DataOffset     4 bytes     10      File offset to Raster Data
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    84
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    85
      InfoHeader        40 bytes            Windows Structure: BITMAPINFOHEADER
3594
695b4c2f1b83 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3593
diff changeset
    86
        different sizes, depending on Windows-version:
695b4c2f1b83 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3593
diff changeset
    87
                        12 - Win2.x or OS/2 1.x
695b4c2f1b83 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3593
diff changeset
    88
                        40 - WinNT, Win3.x or later
695b4c2f1b83 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3593
diff changeset
    89
                        52 - adds undocumented; adds r/g/b masks
695b4c2f1b83 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3593
diff changeset
    90
                        56 - adds undocumented; adds r/g/b/a masks
695b4c2f1b83 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3593
diff changeset
    91
                        64 - OS/2 2.x
695b4c2f1b83 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3593
diff changeset
    92
                        108 - WinNT4.0, 95 or later
695b4c2f1b83 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3593
diff changeset
    93
                        124 - WinNT5.0, 98 or later
695b4c2f1b83 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3593
diff changeset
    94
      
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
    95
          Size           4 bytes     14      Size of InfoHeader =40
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
    96
          Width          4 bytes     18      Bitmap Width
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
    97
          Height         4 bytes     22      Bitmap Height
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
    98
          Planes         2 bytes     26      Number of Planes (=1)
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
    99
          BitCount       2 bytes     28      Bits per Pixel
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   100
                                             1 = monochrome palette. NumColors = 1
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   101
                                             4 = 4bit palletized. NumColors = 16
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   102
                                             8 = 8bit palletized. NumColors = 256
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   103
                                             16 = 16bit RGB. NumColors = 65536 (?)
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   104
                                             24 = 24bit RGB. NumColors = 16M
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   105
          Compression    4 bytes     30      Type of Compression
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   106
                                             0 = RGB            no compression
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   107
                                             1 = RLE8           8bit RLE encoding
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   108
                                             2 = RLE4           4bit RLE encoding
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   109
                                             3 = BITFIELDS      Windows V3+ only
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   110
                                             4 = JPEG           Windows V3+ only
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   111
                                             5 = PNG            Windows V3+ only
3594
695b4c2f1b83 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3593
diff changeset
   112
                                             6 = ALPHA_BITFIELDS Windows CE only
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   113
        
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   114
                                             3 = HUFFMAN1D      OS/2 2.x-only
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   115
                                             4 = RLE24          OS/2 2.x-only
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   116
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   117
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   118
          ImageSize      4 bytes     34      (compressed) Size of Image
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   119
                                             It is valid to set this =0 if Compression = 0
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   120
          XpixelsPerM    4 bytes     38      horizontal resolution: Pixels/meter
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   121
          YpixelsPerM    4 bytes     42      vertical resolution: Pixels/meter
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   122
          ColorsUsed     4 bytes     46      Number of actually used colors
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   123
          ColorsImportant
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   124
                         4 bytes     50      Number of important colors
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   125
                                             0 = all
3594
695b4c2f1b83 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3593
diff changeset
   126
695b4c2f1b83 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3593
diff changeset
   127
       ColorTable        4 * NumColors bytes (3 on Win2)
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   128
                                             present only if Info.BitsPerPixel <= 8
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   129
                                             colors should be ordered by importance
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   130
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   131
            Red           1 byte              Red intensity
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   132
            Green         1 byte              Green intensity
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   133
            Blue          1 byte              Blue intensity
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   134
            reserved      1 byte             unused (=0)
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   135
          repeated NumColors times
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   136
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   137
       Raster Data      Info.ImageSize bytes     The pixel data
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   138
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   139
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   140
Raster Data encoding:
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   141
       Depending on the image's BitCount and on the Compression flag there are 6 different encoding schemes.
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   142
       All of them share the following:
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   143
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   144
       Pixels are stored bottom-up, left-to-right. Pixel lines are padded with zeros to end on a 32bit (4byte) boundary. For
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   145
       uncompressed formats every line will have the same number of bytes. Color indices are zero based, meaning a pixel
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   146
       color of 0 represents the first color table entry, a pixel color of 255 (if there are that many) represents the 256th entry.
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   147
       For images with more than 256 colors there is no color table.
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   148
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   149
Raster Data encoding for 1bit / black & white images:
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   150
       BitCount = 1 Compression = 0
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   151
       Every byte holds 8 pixels, its highest order bit representing the leftmost pixel of those. There are 2 color table entries.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   152
       Some readers will ignore them though, and assume that 0 is black and 1 is white. If you are storing black and white
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   153
       pictures you should stick to this, with any other 2 colors this is not an issue. Remember padding with zeros up to a
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   154
       32bit boundary (This can be up to 31 zeros/pixels!!)
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   155
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   156
Raster Data encoding for 4bit / 16 color images:
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   157
       BitCount = 4 Compression = 0
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   158
       Every byte holds 2 pixels, its high order 4 bits representing the left of those. There are 16 color table entries. These
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   159
       colors do not have to be the 16 MS-Windows standard colors. Padding each line with zeros up to a 32bit boundary
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   160
       will result in up to 28 zeros = 7 'wasted pixels'.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   161
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   162
Raster Data encoding for 8bit / 256 color images:
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   163
       BitCount = 8 Compression = 0
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   164
       Every byte holds 1 pixel. There are 256 color table entries. Padding each line with zeros up to a 32bit boundary will
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   165
       result in up to 3 bytes of zeros = 3 'wasted pixels'.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   166
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   167
Raster Data encoding for 16bit / hicolor images:
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   168
       BitCount = 16 Compression = 0
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   169
       Every 2bytes / 16bit holds 1 pixel.
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   170
       <information missing: the 16 bit was introduced together with Video For Windows? Is it a memory-only-format?>
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   171
       The pixels are no color table pointers. There are no color table entries. Padding each line with zeros up to a 16bit
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   172
       boundary will result in up to 2 zero bytes.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   173
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   174
Raster Data encoding for 24bit / truecolor images:
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   175
       BitCount = 24 Compression = 0
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   176
       Every 4bytes / 32bit holds 1 pixel. The first holds its red, the second its green, and the third its blue intensity. The
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   177
       fourth byte is reserved and should be zero. There are no color table entries. The pixels are no color table pointers. No
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   178
       zero padding necessary.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   179
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   180
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   181
Raster Data compression for 4bit / 16 color images:
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   182
       BitCount = 4 Compression = 2
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   183
       The pixel data is stored in 2bytes / 16bit chunks.  The first of these specifies the number of consecutive pixels with the
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   184
       same pair of color. The second byte defines two color indices. The resulting pixel pattern will be interleaved
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   185
       high-order 4bits and low order 4 bits (ABABA...). If the first byte is zero, the second defines an escape code. The
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   186
       End-of-Bitmap is zero padded to end on a 32bit boundary. Due to the 16bit-ness of this structure this will always be
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   187
       either two zero bytes or none.
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   188
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   189
        n (byte 1) c (Byte 2)                                       Description
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   190
        >0        any      n pixels are to be drawn. The 1st, 3rd, 5th, ... pixels' color is in c's high-order 4 bits, the even
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   191
                            pixels' color is in c's low-order 4 bits. If both color indices are the same, it results in just n
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   192
                            pixels of color c
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   193
        0         0        End-of-line
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   194
        0         1        End-of-Bitmap
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   195
        0         2        Delta. The following 2 bytes define an unsigned offset in x and y direction (y being up) The
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   196
                            skipped pixels should get a color zero.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   197
        0         >=3      The following c bytes will be read as single pixel colors just as in uncompressed files. up to 12
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   198
                            bits of zeros follow, to put the file/memory pointer on a 16bit boundary again.
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   199
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   200
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   201
                                      Example for 4bit RLE
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   202
        Compressed Data                           Expanded data
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   203
        03 04              0 4 0
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   204
        05 06              0 6 0 6 0
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   205
        00 06 45 56 67 00  4 5 5 6 6 7
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   206
        04 78              7 8 7 8
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   207
        00 02 05 01        Move 5 right and 1 up. (Windows docs say down, which is wrong)
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   208
        00 00              End-of-line
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   209
        09 1E              1 E 1 E 1 E 1 E 1
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   210
        00 01              EndofBitmap
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   211
        00 00              Zero padding for 32bit boundary
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   212
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   213
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   214
Raster Data compression for 8bit / 256 color images:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   215
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   216
       BitCount = 8 Compression = 1
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   217
       The pixel data is stored in 2bytes / 16bit chunks.  The first of these specifies the number of consecutive pixels with the
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   218
       same color. The second byte defines their color index. If the first byte is zero, the second defines an escape code. The
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   219
       End-of-Bitmap is zero padded to end on a 32bit boundary. Due to the 16bit-ness of this structure this will always be
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   220
       either two zero bytes or none.
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   221
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   222
        n (byte 1)   c (Byte 2)                                    Description
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   223
        >0       any        n pixels of color number c
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   224
        0        0          End-of-line
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   225
        0        1          End Of Bitmap
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   226
        0        2          Delta. The following 2 bytes define an unsigned offset in x and y direction (y being up) The
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   227
                            skipped pixels should get a color zero.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   228
        0        >=3        The following c bytes will be read as single pixel colors just as in uncompressed files. A zero
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   229
                            follows, if c is odd, putting the file/memory pointer on a 16bit boundary again.
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   230
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   231
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   232
                                      Example for 8bit RLE
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   233
        Compressed Data                           Expanded data
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   234
        03 04              04 04 04
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   235
        05 06              06 06 06 06 06
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   236
        00 03 45 56 67 00  45 56 67
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   237
        02 78              78 78
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   238
        00 02 05 01        Move 5 right and 1 up. (Windows docs say down, which is wrong)
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   239
        00 00              End-of-line
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   240
        09 1E              1E 1E 1E 1E 1E 1E 1E 1E 1E
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   241
        00 01              End-of-bitmap
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   242
        00 00              Zero padding for 32bit boundary
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   243
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   244
Portability:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   245
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   246
       Although BMPs were invented by Microsoft for its Windows platform, a lot of programs on other platforms are capable
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   247
       of reading and writing them. Notice the Intel order in 2byte and 4-byte integer values (Least significant byte first). The
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   248
       16bit BMPs have been introduced to Windows after the others, still puzzling many applications.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   249
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   250
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   251
Trademarks, Patents and Royalties
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   252
       To my knowledge: None.
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   253
"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   254
! !
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   255
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
   256
!WindowsIconReader class methodsFor:'initialization'!
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
   257
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
   258
initialize
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   259
    "tell Image-class, that a new fileReader is present
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 387
diff changeset
   260
     for the '.bmp' and '.ico' extensions."
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   261
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
   262
    MIMETypes defineImageType:'image/x-MS-bitmap'        suffix:'bmp' reader:self.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
   263
    MIMETypes defineImageType:'image/x-ms-bitmap'        suffix:'bmp' reader:self.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
   264
    MIMETypes defineImageType:'image/bmp'                suffix:'bmp' reader:self.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
   265
    MIMETypes defineImageType:'image/x-icon'             suffix:'ico' reader:self.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
   266
    MIMETypes defineImageType:'image/vnc.microsoft.icon' suffix:'ico' reader:self.
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   267
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
   268
    "
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
   269
     MIMETypes mimeTypeForSuffix:'ico'
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
   270
    "
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
   271
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
   272
    "Modified (comment): / 13-09-2017 / 09:04:38 / cg"
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
   273
! !
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
   274
102
claus
parents: 99
diff changeset
   275
!WindowsIconReader class methodsFor:'testing'!
claus
parents: 99
diff changeset
   276
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   277
canRepresent:anImage
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   278
    "return true, if anImage can be represented in my file format.
3896
58e71198a302 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3742
diff changeset
   279
     BMP supports depth 1,4,8, 24 and 32."
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   280
3726
37f44a063d46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3640
diff changeset
   281
    (#(1 4 8 24 32) includes:anImage depth) ifTrue:[^true].
3571
a830f0388ef6 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3568
diff changeset
   282
    ('WindwsIconReader [info]: image depth is not 1,4,8 or 24.') infoPrintCR.
a830f0388ef6 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3568
diff changeset
   283
    ^ false
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   284
3896
58e71198a302 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3742
diff changeset
   285
    "Created: / 17-10-1997 / 20:18:23 / cg"
58e71198a302 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3742
diff changeset
   286
    "Modified (comment): / 17-02-2017 / 08:55:32 / cg"
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   287
!
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   288
102
claus
parents: 99
diff changeset
   289
isValidImageFile:aFileName
claus
parents: 99
diff changeset
   290
    "return true, if aFileName contains a valid windows bitmap-file image"
claus
parents: 99
diff changeset
   291
claus
parents: 99
diff changeset
   292
    |inStream header ok|
claus
parents: 99
diff changeset
   293
claus
parents: 99
diff changeset
   294
    inStream := self streamReadingFile:aFileName.
claus
parents: 99
diff changeset
   295
    inStream isNil ifTrue:[^ false].
claus
parents: 99
diff changeset
   296
claus
parents: 99
diff changeset
   297
    inStream binary.
104
claus
parents: 103
diff changeset
   298
    ok := false.
692
e6af4c70e066 size is going to be eliminated from the stream
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
   299
    inStream fileSize > 16 ifTrue:[
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   300
	header := ByteArray uninitializedNew:4.
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   301
	inStream nextBytes:4 into:header.
102
claus
parents: 99
diff changeset
   302
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   303
	(header startsWith:#(66 77)) ifTrue:[     "BM"
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   304
	    ok := true.
104
claus
parents: 103
diff changeset
   305
"/            'WINREADER: Win3.x or OS/2 vsn 2 BM format' infoPrintNL.
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   306
	].
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   307
	(header startsWith:#(66 65)) ifTrue:[     "BA"
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   308
	    ok := true.
104
claus
parents: 103
diff changeset
   309
"/            'WINREADER: OS/2 vsn 2 BA format' infoPrintNL.
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   310
	].
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   311
	(header startsWith:#(73 67)) ifTrue:[     "IC"
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   312
	    ok := true.
104
claus
parents: 103
diff changeset
   313
"/            'WINREADER: OS/2 IC format' infoPrintNL.
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   314
	].
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   315
	(header startsWith:#(80 84)) ifTrue:[     "PT"
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   316
	    ok := true.
104
claus
parents: 103
diff changeset
   317
"/            'WINREADER: OS/2 PT format' infoPrintNL.
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   318
	].
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   319
	(header startsWith:#(0 0 1 0)) ifTrue:[
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   320
	    ok := true.
104
claus
parents: 103
diff changeset
   321
"/            'WINREADER: Win3.x ICO format' infoPrintNL.
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   322
	].
102
claus
parents: 99
diff changeset
   323
    ].
104
claus
parents: 103
diff changeset
   324
    inStream close.
claus
parents: 103
diff changeset
   325
    ^ ok
102
claus
parents: 99
diff changeset
   326
claus
parents: 99
diff changeset
   327
    "
claus
parents: 99
diff changeset
   328
     WindowsIconReader isValidImageFile:'/phys/clam2/LocalLibrary/Images/OS2_icons/dos.ico'
claus
parents: 99
diff changeset
   329
    "
claus
parents: 99
diff changeset
   330
claus
parents: 99
diff changeset
   331
    "Created: 17.9.1995 / 17:14:20 / claus"
claus
parents: 99
diff changeset
   332
! !
claus
parents: 99
diff changeset
   333
3591
87336f7e44cf #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3590
diff changeset
   334
!WindowsIconReader methodsFor:'accessing'!
87336f7e44cf #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3590
diff changeset
   335
87336f7e44cf #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3590
diff changeset
   336
image
87336f7e44cf #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3590
diff changeset
   337
    pngOrJPGImage notNil ifTrue:[^ pngOrJPGImage].
87336f7e44cf #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3590
diff changeset
   338
    ^ super image
87336f7e44cf #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3590
diff changeset
   339
! !
87336f7e44cf #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3590
diff changeset
   340
103
claus
parents: 102
diff changeset
   341
!WindowsIconReader methodsFor:'private'!
claus
parents: 102
diff changeset
   342
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   343
bitsPerPixel
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   344
    ^ inDepth
3584
141dd71ce83f #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 3583
diff changeset
   345
!
141dd71ce83f #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 3583
diff changeset
   346
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   347
convertPixels
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   348
    "/ figure out, how pixels should be processed,
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   349
    "/ according to the order of r/g/b components and masks
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   350
    "/ bring the pixels to a standard format:
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   351
    "/  rgb888/rgba8888 if possible and useful
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   352
    "/ 
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   353
    |swapAction redShift greenShift blueShift alphaShift pixelAction
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   354
     numRedBits numGreenBits numBlueBits numAlphaBits needPixelProcessing|
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   355
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   356
    inDepth == 1 ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   357
        colorMap isNil ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   358
            photometric := #blackIs0
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   359
        ] ifFalse:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   360
            photometric := #palette.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   361
            colorMap size == 2 ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   362
                ((colorMap at:1) = (Color white)
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   363
                and:[(colorMap at:2) = (Color black)]) ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   364
                    photometric := #whiteIs0.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   365
                    colorMap := nil.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   366
                ] ifFalse:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   367
                    ((colorMap at:1) = (Color black)
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   368
                    and:[(colorMap at:2) = (Color white)]) ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   369
                        photometric := #blackIs0.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   370
                        colorMap := nil.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   371
                    ]
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   372
                ].                    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   373
            ].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   374
        ].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   375
        samplesPerPixel := 1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   376
        bitsPerSample := Array with:inDepth.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   377
        ^ self.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   378
    ].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   379
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   380
    ((inDepth > 8) and:[redMask notNil]) ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   381
        numRedBits   := redMask bitCount.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   382
        numGreenBits := greenMask bitCount.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   383
        numBlueBits  := blueMask bitCount.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   384
        numAlphaBits := alphaMask bitCount.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   385
        redShift := redMask lowBit - 1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   386
        greenShift  := greenMask lowBit - 1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   387
        blueShift  := blueMask lowBit - 1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   388
        alphaShift := alphaMask lowBit - 1.
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   389
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   390
        alphaMask == 0 ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   391
            photometric := #rgb.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   392
            samplesPerPixel := 3
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   393
        ] ifFalse:[    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   394
            photometric := #rgba.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   395
            samplesPerPixel := 4
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   396
        ].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   397
        needPixelProcessing := false.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   398
        
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   399
        inDepth == 16 ifTrue:[
3590
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   400
            alphaMask == 0 ifTrue:[
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   401
                bitsPerSample := {numRedBits. numGreenBits. numBlueBits}.
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   402
                colorMap := FixedPalette
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   403
                                redShift:redShift redMask:(redMask >> redShift)
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   404
                                greenShift:greenShift greenMask:(greenMask >> greenShift)
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   405
                                blueShift:blueShift blueMask:(blueMask >> blueShift).
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   406
                photometric := #palette.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   407
            ] ifFalse:[
3590
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   408
                bitsPerSample := {numRedBits. numGreenBits. numBlueBits. numAlphaBits }.
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   409
                colorMap := FixedPaletteWithAlpha
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   410
                                redShift:redShift redMask:(redMask >> redShift)
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   411
                                greenShift:greenShift greenMask:(greenMask >> greenShift)
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   412
                                blueShift:blueShift blueMask:(blueMask >> blueShift).
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   413
                colorMap alphaShift:alphaShift alphaMask:(alphaMask >> alphaShift).                
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   414
                photometric := #palette.
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   415
            ].
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   416
            swapAction := [:bytes | data swapBytes].                
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   417
        ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   418
        inDepth == 24 ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   419
            (redShift ~~ 0
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   420
                or:[ greenShift ~~ 8
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   421
                or:[ blueShift ~~ 16
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   422
                or:[ numRedBits ~~ 8
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   423
                or:[ numGreenBits ~~ 8
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   424
                or:[ numBlueBits ~~ 8
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   425
                or:[ alphaMask ~~ 0]]]]]]
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   426
            ) ifTrue:[ 
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   427
                (redShift == 16 
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   428
                    and:[greenShift == 8
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   429
                    and:[blueShift == 0
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   430
                    and:[numRedBits == 8
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   431
                    and:[numGreenBits == 8
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   432
                    and:[numBlueBits == 8
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   433
                    and:[alphaMask == 0]]]]]]
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   434
                ) ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   435
                    "/ common case: swap r and b
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   436
                    swapAction := [:data | self swapBytesFromRGB_to_BGR].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   437
                ] ifFalse:[    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   438
                    needPixelProcessing := true
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   439
                ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   440
            ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   441
            bitsPerSample := #(8 8 8).
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   442
            photometric := #rgb.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   443
        ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   444
        inDepth == 32 ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   445
            (redShift ~~ 0
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   446
                or:[ greenShift ~~ 8
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   447
                or:[ redShift ~~ 16
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   448
                or:[ numRedBits ~~ 8
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   449
                or:[ numGreenBits ~~ 8
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   450
                or:[ numBlueBits ~~ 8
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   451
                or:[ alphaMask ~~ 0 and:[ alphaShift ~~ 24]]]]]]]
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   452
            ) ifTrue:[ 
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   453
                (redShift == 16 
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   454
                    and:[greenShift == 8
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   455
                    and:[blueShift == 0
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   456
                    and:[alphaShift == 24
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   457
                    and:[numRedBits == 8
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   458
                    and:[numGreenBits == 8
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   459
                    and:[numBlueBits == 8
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   460
                    and:[numAlphaBits == 8]]]]]]]
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   461
                ) ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   462
                    "/ common case: swap r and b
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   463
                    swapAction := [:data | self swapBytesFromRGBA_to_BGRA].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   464
                ] ifFalse:[    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   465
                    needPixelProcessing := true
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   466
                ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   467
            ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   468
            bitsPerSample := #(8 8 8 8).
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   469
            photometric := #rgba.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   470
        ].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   471
        
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   472
        needPixelProcessing ifTrue:[ 
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   473
            alphaMask == 0 ifTrue:[
3590
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   474
                pixelAction := [:v |
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   475
                                |r g b|
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   476
                                r := (v bitAnd:redMask) >> redShift.
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   477
                                g := (v bitAnd:greenMask) >> greenShift.
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   478
                                b := (v bitAnd:blueMask) >> blueShift.
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   479
                                (((b bitShift:8) bitOr:g) bitShift:8) bitOr:r
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   480
                               ].
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   481
            ] ifFalse:[    
3590
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   482
                pixelAction := [:v |
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   483
                                |r g b a|
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   484
                                r := (v bitAnd:redMask) >> redShift.
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   485
                                g := (v bitAnd:greenMask) >> greenShift.
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   486
                                b := (v bitAnd:blueMask) >> blueShift.
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   487
                                a := (v bitAnd:alphaMask) >> alphaShift.
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   488
                                (((((a bitShift:8) bitOr:b) bitShift:8) bitOr:g) bitShift:8) bitOr:r
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
   489
                               ].
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   490
            ].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   491
        ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   492
    ] ifFalse:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   493
        inDepth <= 8 ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   494
            photometric := #palette.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   495
        ] ifFalse:[    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   496
            inDepth == 16 ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   497
                bitsPerSample := #(5 5 5).
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   498
                colorMap := FixedPalette
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   499
                                redShift:10 redMask:16r1f
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   500
                                greenShift:5 greenMask:16r1f
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   501
                                blueShift:0 blueMask:16r1F.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   502
                photometric := #palette.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   503
                swapAction := [:bytes | data swapBytes].                
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   504
            ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   505
            inDepth == 24 ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   506
                bitsPerSample := #(8 8 8).
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   507
                photometric := #rgb.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   508
                swapAction := [:data | self swapBytesFromRGB_to_BGR].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   509
            ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   510
            inDepth == 32 ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   511
                bitsPerSample := #(8 8 8 8).
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   512
                photometric := #rgba.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   513
                swapAction := [:data | self swapBytesFromRGBA_to_BGRA].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   514
            ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   515
        ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   516
    ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   517
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   518
    "/ Depth32Image keeps its data r/g/b/a; BMP has it b/g/r/a (sigh)
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   519
    pixelAction notNil ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   520
        inDepth == 16 ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   521
            swapAction := 
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   522
                [:byteArray | 
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   523
                    |idx rowIdx oldValue newValue bpr|
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   524
                    rowIdx := 1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   525
                    bpr := self bytesPerRow.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   526
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   527
                    1 to:height do:[:y |
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   528
                        idx := rowIdx.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   529
                        1 to:width do:[:x |
3602
1b88866d2807 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3596
diff changeset
   530
                            oldValue := data unsignedInt16At:idx MSB:false.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   531
                            newValue := pixelAction value:oldValue.
3602
1b88866d2807 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3596
diff changeset
   532
                            data unsignedInt16At:idx put:newValue MSB:true.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   533
                            idx := idx + 2.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   534
                        ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   535
                        rowIdx := rowIdx + bpr.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   536
                    ]
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   537
               ].                 
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   538
        ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   539
        inDepth == 24 ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   540
            swapAction := 
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   541
                [:byteArray | 
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   542
                    |idx rowIdx oldValue newValue bpr|
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   543
                    rowIdx := 1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   544
                    bpr := self bytesPerRow.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   545
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   546
                    1 to:height do:[:y |
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   547
                        idx := rowIdx.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   548
                        1 to:width do:[:x |
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   549
                            oldValue := data unsignedIntegerAt:idx length:3 bigEndian:false.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   550
                            newValue := pixelAction value:oldValue.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   551
                            data unsignedIntegerAt:idx put:newValue length:3 bigEndian:true.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   552
                            idx := idx + 3.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   553
                        ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   554
                        rowIdx := rowIdx + bpr.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   555
                    ]
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   556
               ].                 
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   557
        ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   558
        inDepth == 32 ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   559
            swapAction := 
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   560
                [:byteArray | 
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   561
                    |idx rowIdx oldValue newValue bpr|
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   562
                    rowIdx := 1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   563
                    bpr := self bytesPerRow.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   564
                    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   565
                    1 to:height do:[:y |
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   566
                        idx := rowIdx.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   567
                        1 to:width do:[:x |
3604
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
   568
                            oldValue := data unsignedInt32At:idx MSB:false.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   569
                            newValue := pixelAction value:oldValue.
3604
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
   570
                            data unsignedInt32At:idx put:newValue MSB:false.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   571
                            idx := idx + 4.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   572
                        ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   573
                        rowIdx := rowIdx + bpr.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   574
                    ]
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   575
               ].                 
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   576
        ].
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   577
    ].
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   578
    swapAction notNil ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   579
        swapAction value:data
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   580
    ].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   581
!
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   582
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   583
loadBMP1From:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   584
    "load bmp-1 bit per pixel imagedata."
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   585
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   586
    compression == 0 ifFalse:[
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   587
	^ false
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   588
    ].
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   589
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   590
    ^ self loadUncompressedFrom:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   591
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   592
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   593
loadBMP2From:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   594
    "load bmp-2 bit per pixel imagedata."
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   595
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   596
    compression == 0 ifFalse:[
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   597
	^ false
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   598
    ].
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   599
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   600
    ^ self loadUncompressedFrom:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   601
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   602
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   603
loadBMP4From:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   604
    "load bmp-4 bit per pixel imagedata."
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   605
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   606
    compression == 0 ifTrue:[
4003
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   607
        ^ self loadUncompressedFrom:aStream into:aByteArray
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   608
    ].
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   609
    compression == 2 ifTrue:[
4003
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   610
        [
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   611
            ^ self loadRLECompressedBMP4From:aStream into:aByteArray
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   612
        ] on:Error do:[:ex |
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   613
            self fileFormatError:'Error during RLE decompression: %1' with:ex description.
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   614
            ^ false.
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   615
        ]
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   616
    ].
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   617
4003
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   618
    self fileFormatError:'unsupported compression: %1' with:compression.
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   619
    ^ false
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   620
!
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   621
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   622
loadBMP8From:aStream into:aByteArray
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   623
    "load bmp-8 bit per pixel imagedata."
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   624
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   625
    compression == 0 ifTrue:[
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   626
        ^ self loadUncompressedFrom:aStream into:aByteArray.
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   627
    ].
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   628
    compression == 1 ifTrue:[
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   629
        [
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   630
            ^ self loadRLECompressedBMP8From:aStream into:aByteArray.
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   631
        ] on:Error do:[:ex |
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   632
            self fileFormatError:'error during RLE decompression: %1' with:ex description.
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   633
            ^ false.
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   634
        ]
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   635
    ].
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   636
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   637
    self fileFormatError:'unsupported compression: %1' with:compression.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   638
    ^ false
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   639
!
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   640
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   641
loadBMPWidth:w height:h bytesPerPixel:bpp from:aStream into:aByteArray
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   642
    "load bmp-16/24/32 bit per pixel imagedata."
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   643
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   644
    |dstIdx fileBytesPerRow imgBytesPerRow skip align lineDelta|
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   645
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   646
    align := 4.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   647
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   648
    ((compression == 0) or:[compression == 3]) ifFalse:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   649
        "/ 'BMPReader: unsupported compression: ' infoPrint. compression infoPrintCR. 
4003
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   650
        self fileFormatError:'unsupported compression: %1' with:compression.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   651
        ^ false.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   652
    ].
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   653
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   654
    imgBytesPerRow := w * bpp.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   655
    fileBytesPerRow := imgBytesPerRow.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   656
    (fileBytesPerRow bitAnd:(align-1)) ~~ 0 ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   657
        fileBytesPerRow := (fileBytesPerRow bitAnd:((align-1) bitInvert)) + align.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   658
    ].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   659
    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   660
    topDown ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   661
        dstIdx := 1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   662
        lineDelta := imgBytesPerRow
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   663
    ] ifFalse:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   664
        dstIdx := imgBytesPerRow * (h - 1) + 1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   665
        lineDelta := imgBytesPerRow negated
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   666
    ].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   667
    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   668
    (lineDelta == fileBytesPerRow) ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   669
        (aStream nextBytes:(fileBytesPerRow*h) into:aByteArray startingAt:dstIdx) == (fileBytesPerRow*h) ifFalse:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   670
            ^ false
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   671
        ].
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   672
    ] ifFalse:[    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   673
        skip := fileBytesPerRow - imgBytesPerRow.
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   674
        1 to:h do:[:row |
3920
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
   675
            |nRead|
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
   676
            
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
   677
            nRead := aStream nextBytes:imgBytesPerRow into:aByteArray startingAt:dstIdx.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
   678
            nRead == imgBytesPerRow ifFalse:[
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   679
                ^ false
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   680
            ].
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   681
            skip ~~ 0 ifTrue:[ aStream skip:skip ].
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   682
            dstIdx := dstIdx + lineDelta.
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   683
        ].
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   684
    ].
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   685
    ^ true
3920
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
   686
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
   687
    "Modified: / 22-02-2017 / 16:20:50 / cg"
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   688
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   689
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   690
loadBMPWidth:w height:h depth:d from:aStream into:aByteArray
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   691
    "helper: load a BMP image"
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   692
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   693
    d == 8 ifTrue:[
4003
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   694
        ^ self loadBMP8From:aStream into:aByteArray
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   695
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   696
    d == 4 ifTrue:[
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   697
        ^ self loadBMP4From:aStream into:aByteArray
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   698
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   699
    d == 2 ifTrue:[
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   700
        ^ self loadBMP2From:aStream into:aByteArray
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   701
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   702
    d == 1 ifTrue:[
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   703
        ^ self loadBMP1From:aStream into:aByteArray
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   704
    ].
3920
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
   705
    
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
   706
    ((d == 16) or:[ (d == 24) or:[ (d == 32) ]]) ifTrue:[
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   707
        (self loadBMPWidth:w height:h bytesPerPixel:(d // 8) from:aStream into:aByteArray) ifFalse:[
2756
e8bf6a023191 halt in: #loadBMPWidth:height:depth:from:into:
Claus Gittinger <cg@exept.de>
parents: 2578
diff changeset
   708
            ^ false
e8bf6a023191 halt in: #loadBMPWidth:height:depth:from:into:
Claus Gittinger <cg@exept.de>
parents: 2578
diff changeset
   709
        ].
e8bf6a023191 halt in: #loadBMPWidth:height:depth:from:into:
Claus Gittinger <cg@exept.de>
parents: 2578
diff changeset
   710
        ^ true
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   711
    ].
4003
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   712
256b43a46036 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3999
diff changeset
   713
    self fileFormatError:'unsupported depth: %1' with:d.
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   714
    ^ false
103
claus
parents: 102
diff changeset
   715
3920
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
   716
    "Created: / 17-09-1995 / 18:48:11 / claus"
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
   717
    "Modified: / 03-02-1998 / 20:21:16 / cg"
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
   718
    "Modified (format): / 22-02-2017 / 17:04:56 / cg"
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   719
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   720
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   721
loadRLECompressedBMP4From:aStream into:aByteArray
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   722
    "load bmp-rle-4 pixel imagedata"
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   723
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   724
    |bytesPerRow x y dstIndex lineStartIndex cnt pair clr1 clr2 code nbyte byte bytes byteIdx rev|
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   725
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   726
    bytesPerRow := self bytesPerRow.
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   727
    x := 0.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   728
    
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   729
    topDown ifTrue:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   730
        y := 0.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   731
        lineStartIndex := 1.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   732
    ] ifFalse:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   733
        y := height - 1.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   734
        lineStartIndex := (y * bytesPerRow) + 1.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   735
    ].
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   736
    dstIndex := lineStartIndex.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   737
    "/ data atAllPut:16rBB.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   738
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   739
    [ y between:0 and:height-1 ] whileTrue:[
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   740
        cnt := aStream nextByte.
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   741
        pair := aStream nextByte.
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   742
        cnt ~~ 0 ifTrue:[
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   743
            ((x between:0 and:width-1) and:[y between:0 and:height-1]) ifFalse:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   744
                self breakPoint:#cg.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   745
                self fileFormatError:('invalid delta').
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   746
            ].    
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   747
            "/ Transcript printf:'RUN y: %d x: %d cnt: %d pair: %02x\n' with:y with:x with:cnt with:pair.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   748
            x even ifTrue:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   749
                (cnt >= 2) ifTrue:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   750
                    nbyte := cnt // 2.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   751
                    aByteArray from:dstIndex to:(dstIndex+nbyte-1) put:pair.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   752
                    dstIndex := dstIndex + nbyte.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   753
                ].
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   754
                cnt odd ifTrue:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   755
                    "/ got odd count
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   756
                    byte := aByteArray at:dstIndex.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   757
                    aByteArray at:dstIndex put:((byte bitAnd:16r0F) bitOr:(pair bitAnd:16rF0)).
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   758
                    "/ self halt.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   759
                ].    
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   760
            ] ifFalse:[
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   761
                clr1 := pair bitShift:-4. "/ left bit
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   762
                clr2 := pair bitAnd:16rF. "/ right bit
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   763
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   764
                "/ the first odd-x halfbyte
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   765
                byte := aByteArray at:dstIndex.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   766
                aByteArray at:dstIndex put:((byte bitAnd:16rF0) bitOr:clr1).
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   767
                dstIndex := dstIndex + 1.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   768
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   769
                nbyte := (cnt-1) // 2.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   770
                nbyte > 0 ifTrue:[
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   771
                    rev := (clr2 << 4) bitOr:clr1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   772
                    aByteArray from:dstIndex to:(dstIndex+nbyte-1) put:rev.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   773
                    dstIndex := dstIndex + nbyte.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   774
                ].
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   775
                cnt even ifTrue:[
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   776
                    "/ the final odd-x halfbyte
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   777
                    byte := aByteArray at:dstIndex.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   778
                    aByteArray at:dstIndex put:((byte bitAnd:16r0F) bitOr:(clr2 bitShift:4)).
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   779
                ].    
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   780
            ].
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   781
            x := x + cnt.
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   782
        ] ifFalse:[
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   783
            "/ cnt == 0: escape codes */
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   784
            code := pair.
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   785
            code == 0 ifTrue:[
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   786
                "/ end of line
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   787
                "/ Transcript printf:'EOL\n'.
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   788
                x := 0.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   789
                topDown ifTrue:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   790
                    y := y + 1.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   791
                    lineStartIndex := lineStartIndex + bytesPerRow.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   792
                ] ifFalse:[    
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   793
                    y := y - 1.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   794
                    lineStartIndex := lineStartIndex - bytesPerRow.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   795
                ].    
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   796
                dstIndex := lineStartIndex.
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   797
            ] ifFalse:[
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   798
                code == 1 ifTrue:[
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   799
                    "/ Transcript printf:'END\n'.
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   800
                    "/ end of pic
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   801
                    ^ true
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   802
                ].
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   803
                code == 2 ifTrue:[
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   804
                    "/ delta
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   805
                    x := x + aStream nextSignedByte.
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   806
                    y := y - aStream nextSignedByte.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   807
                    "/ Transcript printf:'MOVE y: %d x: %d\n' with:y with:x with:code.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   808
                    lineStartIndex := (y * bytesPerRow) + 1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   809
                    dstIndex := lineStartIndex + (x//2).
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   810
                ] ifFalse:[
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   811
                    "/ absolute; cnt pixels coming
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   812
                    ((x between:0 and:width-1) and:[y between:0 and:height-1]) ifFalse:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   813
                        self breakPoint:#cg.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   814
                        self fileFormatError:('invalid delta').
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   815
                    ].    
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   816
                    cnt := code.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   817
                    nbyte := (cnt+1) // 2.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   818
                    bytes := aStream nextBytes:nbyte.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   819
                    "/ odd byte count - padd
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   820
                    nbyte odd ifTrue:[
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   821
                        aStream skip:1.
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   822
                    ].
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   823
                    x + cnt > width ifTrue:[self halt].
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   824
                    byteIdx := 1.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   825
                    "/ Transcript printf:'PIXELS: %d x: %d count: %d nbyte: %d\n' with:y with:x with:cnt with:nbyte.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   826
                    x even ifTrue:[
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   827
                        nbyte := cnt // 2.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   828
                        aByteArray replaceFrom:dstIndex to:(dstIndex+nbyte-1) with:bytes startingAt:byteIdx.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   829
                        byteIdx := byteIdx + nbyte.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   830
                        dstIndex := dstIndex + nbyte.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   831
                        cnt odd ifTrue:[
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   832
                            "/ the last half-byte
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   833
                            pair := bytes at:byteIdx.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   834
                            byte := aByteArray at:dstIndex.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   835
                            aByteArray at:dstIndex put:((byte bitAnd:16r0F) bitOr:(pair bitAnd:16rF0)).
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   836
                            "/ self halt.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   837
                        ].
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   838
                    ] ifFalse:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   839
                        nbyte := (cnt // 2).
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   840
                        [nbyte > 0] whileTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   841
                            pair := bytes at:byteIdx. byteIdx := byteIdx + 1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   842
                            byte := aByteArray at:dstIndex.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   843
                            aByteArray at:dstIndex put:((byte bitAnd:16rF0) bitOr:((pair bitShift:-4) bitAnd:16r0F)).
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   844
                            dstIndex := dstIndex + 1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   845
                            byte := aByteArray at:dstIndex.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   846
                            aByteArray at:dstIndex put:((byte bitAnd:16r0F) bitOr:((pair bitShift:4) bitAnd:16rF0)).
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   847
                            nbyte := nbyte - 1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   848
                        ].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   849
                        cnt odd ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   850
                            pair := bytes at:byteIdx. byteIdx := byteIdx + 1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   851
                            byte := aByteArray at:dstIndex.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   852
                            aByteArray at:dstIndex put:((byte bitAnd:16rF0) bitOr:((pair bitShift:-4) bitAnd:16r0F)).
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   853
                            dstIndex := dstIndex + 1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   854
                        ].    
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   855
                    ].    
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   856
                    x := x + cnt. 
3578
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   857
                ].
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   858
            ].
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   859
        ].
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   860
    ].
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   861
    ^ true.
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   862
!
6bd3a34492f9 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3571
diff changeset
   863
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   864
loadRLECompressedBMP8From:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   865
    "load bmp-8 bit per pixel imagedata"
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   866
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   867
    |bytesPerRowInData x y dstIndex lineStartIndex cnt clr code n|
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   868
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   869
    bytesPerRowInData := self bytesPerRow.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   870
    x := 0.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   871
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   872
    topDown ifTrue:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   873
        y := 0.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   874
        lineStartIndex := 1.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   875
    ] ifFalse:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   876
        y := height - 1.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   877
        lineStartIndex := (y * bytesPerRowInData) + 1.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   878
    ].    
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   879
    dstIndex := lineStartIndex.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   880
    
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   881
    [ y between:0 and:height-1 ] whileTrue:[
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   882
        cnt := aStream nextByte.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   883
        clr := aStream nextByte.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   884
        cnt ~~ 0 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   885
            aByteArray from:dstIndex to:dstIndex+cnt-1 put:clr.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   886
            x := x + cnt.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   887
            dstIndex := dstIndex + cnt.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   888
        ] ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   889
            "/ cnt == 0: escape codes */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   890
            code := clr.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   891
            code == 0 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   892
                "/ end of line
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   893
                x := 0.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   894
                topDown ifTrue:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   895
                    y := y + 1.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   896
                    lineStartIndex := lineStartIndex + bytesPerRowInData.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   897
                ] ifFalse:[    
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   898
                    y := y - 1.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   899
                    lineStartIndex := lineStartIndex - bytesPerRowInData.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   900
                ].
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   901
                dstIndex := lineStartIndex.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   902
            ] ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   903
                code == 1 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   904
                    "/ end of pic
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   905
                    ^ true
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   906
                ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   907
                code == 2 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   908
                    "/ delta
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   909
                    x := x + aStream nextSignedByte.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   910
                    y := y - aStream nextSignedByte.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   911
                    lineStartIndex := (y * bytesPerRowInData) + 1.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   912
                    dstIndex := lineStartIndex + x.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   913
                ] ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   914
                    "/ absolute; cnt pixels coming
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   915
                    cnt := code.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   916
                    n := aStream nextBytes:cnt into:aByteArray startingAt:dstIndex.
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   917
                    n ~~ cnt ifTrue:[^ false].
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   918
                    x := x + cnt.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   919
                    dstIndex := dstIndex + cnt.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   920
                    "/ odd count - padd
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   921
                    cnt odd ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   922
                        aStream skip:1.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   923
                    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   924
                ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   925
            ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   926
        ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   927
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   928
    ^ true.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   929
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   930
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   931
loadUncompressedFrom:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   932
    "load bmp-1,2,4 and 8 bit per pixel imagedata."
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   933
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   934
    |bytesPerRowInStream bytesPerRowInData skip n
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   935
     dstIndex  "{ Class: SmallInteger }" 
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   936
     lineDelta "{ Class: SmallInteger }" 
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   937
     nRows     "{ Class: SmallInteger }" |
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   938
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   939
    compression == 0 ifFalse:[
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   940
        ^ false
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   941
    ].
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   942
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   943
    bytesPerRowInStream := Image bytesPerRowForWidth:width depth:inDepth padding:32.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   944
    bytesPerRowInData := self bytesPerRow.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   945
    skip := bytesPerRowInStream - bytesPerRowInData.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   946
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   947
    topDown ifTrue:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   948
        dstIndex := 1.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   949
        lineDelta := bytesPerRowInData.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   950
    ] ifFalse:[    
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   951
        "/ bottom row first...
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   952
        dstIndex := (height - 1) * bytesPerRowInData + 1.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   953
        lineDelta := bytesPerRowInData negated.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   954
    ].
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   955
    nRows := height.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   956
    
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   957
    1 to:nRows do:[:row |
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   958
        n := aStream nextBytes:bytesPerRowInData into:aByteArray startingAt:dstIndex.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   959
        n ~~ bytesPerRowInData ifTrue:[^ false].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   960
        skip ~~ 0 ifTrue:[aStream skip:skip].
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
   961
        dstIndex := dstIndex + lineDelta.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   962
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   963
    ^ true.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   964
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   965
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   966
readColorMap:nColors numBytesPerColor:nRawBytesPerColor from:aStream
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   967
    "read the colormap; notice: its in BGR order (sigh)."
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   968
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   969
    |rawMap rMap gMap bMap
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   970
     srcIndex  "{ Class: SmallInteger }"|
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   971
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   972
    rawMap := ByteArray uninitializedNew:(nColors*nRawBytesPerColor).
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   973
    aStream nextBytes:(nColors*nRawBytesPerColor) into:rawMap.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   974
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   975
    rMap := ByteArray new:nColors.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   976
    gMap := ByteArray new:nColors.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   977
    bMap := ByteArray new:nColors.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   978
    srcIndex := 1.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   979
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   980
    "/ stupid: this is a BGR-ordered map (otherwise, could use #rgbBytesVector:-message)
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   981
    "/ also, there might be a fourth byte (alpha ?) which is (currently) skipped.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   982
    1 to:nColors do:[:i |
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   983
        bMap at:i put:(rawMap at:srcIndex).
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   984
        gMap at:i put:(rawMap at:srcIndex+1).
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   985
        rMap at:i put:(rawMap at:srcIndex+2).
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   986
        srcIndex := srcIndex + nRawBytesPerColor.
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   987
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   988
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
   989
    ^ MappedPalette
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   990
        redVector:rMap
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   991
        greenVector:gMap
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   992
        blueVector:bMap.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   993
!
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   994
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   995
swapBytesFromRGBA_to_BGRA
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   996
    |idx bytesPerRow|
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   997
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   998
    "/ Depth32Image keeps its data r/g/b/a; BMP has it b/g/r/a (sigh)
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   999
    idx := 1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1000
    bytesPerRow := self bytesPerRow.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1001
    1 to:height do:[:y |
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1002
        self class swap:width pixelsFromRGB_to_BGR_in:data startingAt:idx bytesPerPixel:4.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1003
        idx := idx + bytesPerRow.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1004
    ].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1005
!
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1006
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1007
swapBytesFromRGB_to_BGR
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1008
    |idx bytesPerRow|
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1009
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1010
    "/ Depth24Image keeps its data r/g/b; BMP has it b/g/r (sigh)
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1011
    idx := 1.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1012
    bytesPerRow := self bytesPerRow.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1013
    1 to:height do:[:y |
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1014
        self class swap:width pixelsFromRGB_to_BGR_in:data startingAt:idx bytesPerPixel:3.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1015
        idx := idx + bytesPerRow.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1016
    ].
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1017
! !
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1018
1805
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1790
diff changeset
  1019
!WindowsIconReader methodsFor:'reading'!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1020
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1021
fromOS2File:aFilename
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1022
    "read an image from an OS/2 BMP file"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1023
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1024
    |reader stream|
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1025
1790
41f36b5a29c3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
  1026
    stream := self class streamReadingFile:aFilename.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1027
    stream isNil ifTrue:[^ nil].
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1028
    reader := self class new.
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1029
    reader fromOS2Stream:stream.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1030
    stream close.
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1031
    ^ reader image
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1032
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1033
    "Modified: / 30-05-2007 / 16:52:50 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1034
!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1035
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1036
fromOS2Stream:aStream
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1037
    "read an image from an OS/2 BMP stream"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1038
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1039
    ^ self fromOS2Stream:aStream alreadyRead:nil
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1040
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1041
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1042
fromOS2Stream:aStream alreadyRead:bytesAlreadyRead
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1043
    "read an image from an OS/2 BMP stream"
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1044
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1045
    |header inBytesPerRow mask bytesPerRow nColors nByte|
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1046
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1047
    inStream := aStream.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1048
    aStream binary.
2031
c8527bd15f50 .ico stuff - ongoing work
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
  1049
    byteOrder := #lsb.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1050
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1051
    "read the header"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1052
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1053
    header := ByteArray uninitializedNew:8r110.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1054
    bytesAlreadyRead size > 0 ifTrue:[
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1055
        header replaceFrom:1 with:bytesAlreadyRead
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1056
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1057
    aStream nextBytes:(16-bytesAlreadyRead size) into:header startingAt:(1+bytesAlreadyRead size).
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1058
445
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
  1059
    (header startsWith:#(73 67)) ifTrue:[         "IC"
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1060
        "IC format"
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1061
        aStream nextBytes:10 into:header startingAt:17.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1062
        width := header at:7.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1063
        height := header at:9.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1064
        inDepth := 2 "header at:11". "where is it"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1065
    ] ifFalse:[
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1066
        (header startsWith:#(67 73)) ifTrue:[     "CI"
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1067
            ^ self fileFormatError:'unsupported format: CI'.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1068
        ] ifFalse:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1069
            aStream nextBytes:(8r110-16) into:header startingAt:17.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1070
            width := header at:8r101.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1071
            height := header at:8r103.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1072
            inDepth := header at:8r107.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1073
        ]
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1074
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1075
1846
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
  1076
    self reportDimension.
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
  1077
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1078
    "read the colormap; notice: its in BGR order (sigh)"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1079
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1080
    nColors := 1 bitShift:inDepth.
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1081
    colorMap := self readColorMap:nColors numBytesPerColor:3 from:aStream.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1082
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1083
    "read the mask"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1084
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1085
    nByte := ((width * height) + 7) // 8.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1086
    mask := ByteArray uninitializedNew:nByte.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1087
    aStream nextBytes:nByte into:mask.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1088
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1089
    "what is this ?"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1090
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1091
    aStream nextBytes:nByte into:mask.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1092
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1093
"/    "read the data bits"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1094
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1095
"/    bytesPerRow := width * inDepth + 7 // 8.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1096
"/    data4 := ByteArray uninitializedNew:(height * bytesPerRow).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1097
"/    inDepth == 8 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1098
"/    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1099
"/    aStream nextBytes:(height * bytesPerRow) into:data4.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1100
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1101
"/    "stupid: last row first"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1102
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1103
"/    tmp := ByteArray new:(height * bytesPerRow).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1104
"/    srcIndex := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1105
"/    dstIndex := (height - 1) * bytesPerRow + 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1106
"/    1 to:height do:[:row |
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1107
"/        tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1)
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1108
"/                   with:data4 startingAt:srcIndex.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1109
"/        srcIndex := srcIndex + bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1110
"/        dstIndex := dstIndex - bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1111
"/    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1112
"/    data4 := tmp.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1113
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1114
"/    "expand into bytes"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1115
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1116
"/    data := ByteArray new:(width * height).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1117
"/    data4 expandPixels:inDepth width:width height:height
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1118
"/                  into:data mapping:nil.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1119
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1120
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1121
    bytesPerRow := ((width * inDepth) + 7) // 8.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1122
    "/ bmp data is always 32bit aligned; if required,
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1123
    inBytesPerRow := ((bytesPerRow + 3) // 4) * 4.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1124
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1125
    data := ByteArray uninitializedNew:(height * width "bytesPerRow").
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1126
    compression := 0.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1127
    (self loadBMPWidth:width height:height depth:inDepth from:aStream into:data) ifFalse:[
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1128
        ^ nil
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1129
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1130
    photometric := #palette.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1131
    samplesPerPixel := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1132
    bitsPerSample := #(8).
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1133
    ^ self image
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1134
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1135
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1136
     |i f|
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1137
     i := Image fromFile:'/LocalLibrary/Images/OS2/dos3.ico'.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1138
     f := i asFormOn:Display.
3742
634868214786 #OTHER by mawalch
mawalch
parents: 3726
diff changeset
  1139
     v displayOpaqueForm:(f magnifiedBy:2@2) x:5 y:5
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1140
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1141
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1142
    "Modified: / 17-09-1995 / 18:49:24 / claus"
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1143
    "Modified: / 30-05-2007 / 16:53:24 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1144
!
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1145
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1146
fromStream:aStream
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1147
    "figure out which format the stream contains
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1148
     (there are various different bmp/ico formats around)
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1149
     and read the image."
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1150
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1151
    |fileSize header|
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1152
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1153
    inStream := aStream.
2031
c8527bd15f50 .ico stuff - ongoing work
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
  1154
    byteOrder := #lsb.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1155
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1156
    aStream binary.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1157
    aStream signalAtEnd:true.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1158
    aStream isFileStream ifTrue:[
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1159
        fileSize := aStream fileSize.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1160
        fileSize < 16 ifTrue:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1161
            ^ self fileFormatError:'short/corrupted file'.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1162
        ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1163
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1164
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1165
    EndOfStreamError handle:[:ex |
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1166
        ^ self fileFormatError:'unexpected EOF while reading (short/corrupted file)'.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1167
    ] do:[    
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1168
        header := ByteArray uninitializedNew:4.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1169
        aStream nextBytes:4 into:header.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1170
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1171
        (header startsWith:#(66 77)) ifTrue:[     "BM"
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1172
            "/ 'WinIconReader [info]: Win3.x or OS/2 vsn 2 BM format' infoPrintNL.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1173
            ^ self fromWindowsBMPStream:aStream alreadyRead:header
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1174
        ].
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1175
        (header startsWith:#(66 65)) ifTrue:[     "BA"
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1176
            "/ 'WinIconReader [info]: OS/2 vsn 2 BA format' infoPrintNL.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1177
            ^ self fromOS2Stream:aStream alreadyRead:header
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1178
        ].
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1179
        (header startsWith:#(67 73)) ifTrue:[     "CI"
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1180
            "/ 'WinIconReader [info]: OS/2 vsn 2 BA format' infoPrintNL.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1181
            "/ ^ self fromOS2Stream:aStream
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1182
            ^ self fileFormatError:'OS/2 CI format not supported'.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1183
        ].
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1184
        (header startsWith:#(73 67)) ifTrue:[     "IC"
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1185
            "/ 'WinIconReader [info]: OS/2 IC format' infoPrintNL.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1186
            ^ self fromOS2Stream:aStream alreadyRead:header
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1187
        ].
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1188
        (header startsWith:#(80 84)) ifTrue:[     "PT"
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1189
            "/ 'WinIconReader [info]: OS/2 PT format' infoPrintNL.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1190
            ^ self fromOS2Stream:aStream alreadyRead:header
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1191
        ].
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1192
        (header startsWith:#(16r53 16r5A)) ifTrue:[     "SZ"
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1193
            "/ 'WinIconReader [info]: OS/2 SZ format' infoPrintNL.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1194
            "/ ^ self fromOS2Stream:aStream
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1195
            ^ self fileFormatError:'OS/2 SZ format not supported'.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1196
        ].
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1197
        (header startsWith:#(0 0 1 0)) ifTrue:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1198
            "/ 'WinIconReader [info]: Win3.x ICO format' infoPrintNL.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1199
            ^ self fromWindowsICOStream:aStream alreadyRead:header
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1200
        ].
3920
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1201
        (header startsWith:#(0 0 2 0)) ifTrue:[
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1202
            "/ 'WinIconReader [info]: Win3.x CUR format' infoPrintNL.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1203
            ^ self fromWindowsICOStream:aStream alreadyRead:header
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1204
        ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1205
    ].
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1206
    
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1207
    ^ self fileFormatError:('format not supported: %02x %02x' printfWith:(header at:1) with:(header at:2))
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1208
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1209
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1210
     Image fromFile:'/phys/clam//LocalLibrary/Images/OS2_icons/dos.ico'
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1211
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1212
3920
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1213
    "Modified: / 17-09-1995 / 18:59:07 / claus"
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1214
    "Modified: / 22-02-2017 / 18:12:21 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1215
!
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1216
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1217
fromWindowsBMPFile: aFilename
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1218
    "read an image from a windows BMP file"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1219
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1220
    |reader stream|
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1221
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1222
    stream := self class streamReadingFile:aFilename.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1223
    stream isNil ifTrue:[^ nil].
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1224
    reader := self class new.
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1225
    reader fromWindowsBMPStream:stream.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1226
    stream close.
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1227
    ^ reader image.
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1228
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1229
    "Modified: / 30-05-2007 / 16:53:48 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1230
!
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1231
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1232
fromWindowsBMPStream:aStream
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1233
    "read an image from a windows BMP stream"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1234
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1235
    ^ self fromWindowsBMPStream:aStream alreadyRead:nil
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1236
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1237
3920
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1238
fromWindowsBMPStream:aStream alreadyRead:fileHeaerBytesAlreadyRead
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1239
    "read an image from a windows BMP stream"
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1240
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1241
    | fileHeader bitmapHeader iSize inPlanes
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1242
      imgSize resH resV numColor numImportantColor
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1243
      dataStart 
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1244
      bytesPerRow numBytesPerColorInColormap|
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1245
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1246
    inStream := aStream.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1247
    aStream binary.
2031
c8527bd15f50 .ico stuff - ongoing work
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
  1248
    byteOrder := #lsb.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1249
    topDown := false.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1250
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1251
    "read the header"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1252
3920
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1253
    fileHeaerBytesAlreadyRead size >= 16 ifTrue:[
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1254
        "/ used when coming from an ICO file.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1255
        fileHeader := nil.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1256
    ] ifFalse:[    
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1257
        fileHeader := ByteArray new:14.    
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1258
        fileHeaerBytesAlreadyRead size > 0 ifTrue:[
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1259
            fileHeader replaceFrom:1 with:fileHeaerBytesAlreadyRead
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1260
        ].
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1261
        aStream nextBytes:(14-fileHeaerBytesAlreadyRead size) into:fileHeader startingAt:(1+fileHeaerBytesAlreadyRead size).
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1262
        dataStart := fileHeader unsignedInt32At:(10 + 1) MSB:false.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1263
    ].
3920
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1264
    
3640
8a96d595df32 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
  1265
    iSize := aStream nextUnsignedInt32MSB:false.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1266
    iSize > 124 ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1267
        ^ self fileFormatError:'unknown format'.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1268
    ].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1269
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1270
    bitmapHeader := ByteArray new:iSize+16. "/ reserve to allow masks to be read with iSize=40 
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1271
    aStream nextBytes:(iSize-4) into:bitmapHeader startingAt:(1+4).
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1272
3593
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1273
    alphaMask := 0.
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1274
3592
6a70bc638877 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3591
diff changeset
  1275
    ((iSize == 40) or:[iSize == 52 or:[iSize == 56 or:[iSize == 108 or:[iSize == 124]]]]) ifTrue:[    "header-size"
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1276
        "/
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1277
        "/ a Windows3.x BMP file (40)
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1278
        "/ a Windows4.x BMP file (108)
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1279
        "/ a Windows5.x BMP file (124)
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1280
        "/
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1281
        "/ 'WinIconReader [info]: Win3.x/Win4.x/Win5.x format' infoPrintCR.
3920
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1282
        fileHeader isNil ifTrue:[
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1283
            self assert:(bitmapHeader unsignedInt32At:(4 + 1) MSB:false) == width.
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1284
            self assert:(((bitmapHeader signedInt32At:(8 + 1) MSB:false) == (height*2))
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1285
                          or:[ (bitmapHeader signedInt32At:(8 + 1) MSB:false) == height ]).
3920
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1286
        ] ifFalse:[    
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1287
            width := bitmapHeader unsignedInt32At:(4 + 1) MSB:false.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1288
            height := bitmapHeader signedInt32At:(8 + 1) MSB:false.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1289
        ].
3602
1b88866d2807 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3596
diff changeset
  1290
        inPlanes := bitmapHeader unsignedInt16At:(12 + 1) MSB:false.
1b88866d2807 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3596
diff changeset
  1291
        inDepth := bitmapHeader unsignedInt16At:(14 + 1) MSB:false.
3604
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1292
        compression := bitmapHeader unsignedInt32At:(16 + 1) MSB:false.
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1293
        imgSize := bitmapHeader unsignedInt32At:(20 + 1) MSB:false.
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1294
        resH := bitmapHeader unsignedInt32At:(24 + 1) MSB:false.
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1295
        resV := bitmapHeader unsignedInt32At:(28 + 1) MSB:false.
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1296
        numColor := bitmapHeader unsignedInt32At:(32 + 1) MSB:false.
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1297
        numImportantColor := bitmapHeader unsignedInt32At:(36 + 1) MSB:false.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1298
        
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1299
        (compression > 3) ifTrue:[
3593
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1300
            compression == 4 ifTrue:[
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1301
                "/ JPG in data
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1302
                aStream position:dataStart.
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1303
                pngOrJPGImage := JPEGReader fromStream:aStream.
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1304
                ^ pngOrJPGImage
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1305
            ].    
3591
87336f7e44cf #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3590
diff changeset
  1306
            compression == 5 ifTrue:[
87336f7e44cf #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3590
diff changeset
  1307
                "/ PNG in data
87336f7e44cf #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3590
diff changeset
  1308
                aStream position:dataStart.
87336f7e44cf #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3590
diff changeset
  1309
                pngOrJPGImage := PNGReader fromStream:aStream.
87336f7e44cf #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3590
diff changeset
  1310
                ^ pngOrJPGImage
87336f7e44cf #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3590
diff changeset
  1311
            ].    
3593
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1312
            compression == 6 ifTrue:[
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1313
                "/ very seldom - alphamask compression
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1314
            ] ifFalse:[    
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1315
                ^ self fileFormatError:'unhandled compression'.
3591
87336f7e44cf #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3590
diff changeset
  1316
            ].    
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1317
        ].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1318
        
3593
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1319
        (iSize == 40 and:[(compression == 3) or:[compression == 6]]) ifTrue:[
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1320
            "/ masks are not counted in header (sigh)
3593
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1321
            compression == 6 ifTrue:[
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1322
                aStream next:4*4 into:bitmapHeader startingAt:iSize+1.
3604
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1323
                alphaMask := bitmapHeader unsignedInt32At:(52 + 1) MSB:false.
3593
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1324
                compression := 3.
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1325
            ] ifFalse:[        
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1326
                aStream next:4*3 into:bitmapHeader startingAt:iSize+1.
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1327
            ].    
3604
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1328
            redMask := bitmapHeader unsignedInt32At:(40 + 1) MSB:false.
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1329
            greenMask := bitmapHeader unsignedInt32At:(44 + 1) MSB:false.
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1330
            blueMask := bitmapHeader unsignedInt32At:(48 + 1) MSB:false.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1331
        ] ifFalse:[        
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1332
            iSize > 40 ifTrue:[
3592
6a70bc638877 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3591
diff changeset
  1333
                "/ masks are counted in header (sigh)
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1334
                ((compression == 3) or:[iSize == 108]) ifTrue:[
3592
6a70bc638877 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3591
diff changeset
  1335
                    iSize >= 52 ifTrue:[
3604
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1336
                        redMask := bitmapHeader unsignedInt32At:(40 + 1) MSB:false.
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1337
                        greenMask := bitmapHeader unsignedInt32At:(44 + 1) MSB:false.
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1338
                        blueMask := bitmapHeader unsignedInt32At:(48 + 1) MSB:false.
3592
6a70bc638877 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3591
diff changeset
  1339
                        iSize >= 56 ifTrue:[
3604
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1340
                            alphaMask := bitmapHeader unsignedInt32At:(52 + 1) MSB:false.
3592
6a70bc638877 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3591
diff changeset
  1341
                        ].
6a70bc638877 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3591
diff changeset
  1342
                    ].
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1343
                ].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1344
            ].
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1345
        ].
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1346
        
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1347
        numColor == 0 ifTrue:[
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1348
            "if 0 and depth is 8 or smaller, then the colormap has the size for the depth"
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1349
            inDepth <= 8 ifTrue:[
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1350
                numColor := 1 bitShift:inDepth.
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1351
            ]
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1352
        ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1353
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1354
        numBytesPerColorInColormap := 4.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1355
    ] ifFalse:[
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1356
        ((iSize == 12) or:[ (iSize == 16) or:[iSize == 64]]) ifTrue:[
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1357
            "/
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1358
            "/ its a Win2.x or OS/2 BMP file
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1359
            "/
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1360
            "/ 'WinIconReader [info]: Win2.x or OS/2 format' infoPrintCR.
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1361
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1362
            numBytesPerColorInColormap := 3.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1363
3594
695b4c2f1b83 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3593
diff changeset
  1364
            iSize == 64 ifTrue:[
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1365
                "/
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1366
                "/ its an OS/2 (vsn2) BMP file
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1367
                "/
3604
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1368
                width := bitmapHeader unsignedInt32At:(4 + 1) MSB:false.
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1369
                height := bitmapHeader signedInt32At:(8 + 1) MSB:false.
3602
1b88866d2807 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3596
diff changeset
  1370
                inPlanes := bitmapHeader unsignedInt16At:(12 + 1) MSB:false.
1b88866d2807 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3596
diff changeset
  1371
                inDepth := bitmapHeader unsignedInt16At:(14 + 1) MSB:false.
3604
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1372
                compression := bitmapHeader unsignedInt32At:(16 + 1) MSB:false.
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1373
                numColor := bitmapHeader unsignedInt32At:(32 + 1) MSB:false.
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1374
                numImportantColor := bitmapHeader unsignedInt32At:(36 + 1) MSB:false.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1375
                (compression > 2) ifTrue:[
3594
695b4c2f1b83 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3593
diff changeset
  1376
                    "/ 3 = HUFFMAN; 4 = RLE24
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1377
                    ^ self fileFormatError:'unhandled OS2 compression'.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1378
                ].
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1379
                numColor == 0 ifTrue:[
3988
1bc80a8c7566 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3931
diff changeset
  1380
                    "/ self halt.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1381
                    "if 0 and depth is 8 or smaller, then the colormap has the size for the depth"
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1382
                    inDepth <= 8 ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1383
                        numColor := 1 bitShift:inDepth.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1384
                    ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1385
                ].    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1386
                numBytesPerColorInColormap := 4.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1387
            ] ifFalse:[    
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1388
                iSize == 16 ifTrue:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1389
                    "/ an OS2 bitmap with large dimensions
3604
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1390
                    width := bitmapHeader unsignedInt32At:(4 + 1) MSB:false.
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1391
                    height := bitmapHeader signedInt32At:(8 + 1) MSB:false.
3602
1b88866d2807 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3596
diff changeset
  1392
                    inPlanes := bitmapHeader unsignedInt16At:(12 + 1) MSB:false.
1b88866d2807 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3596
diff changeset
  1393
                    inDepth := bitmapHeader unsignedInt16At:(14 + 1) MSB:false.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1394
                    numBytesPerColorInColormap := 4.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1395
                ] ifFalse:[
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1396
                    "/ size == 12:
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1397
                    "/ a Win2.x bitmap
3602
1b88866d2807 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3596
diff changeset
  1398
                    width := bitmapHeader unsignedInt16At:(4 + 1) MSB:false.
3604
5d4d8906ade6 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3602
diff changeset
  1399
                    height := bitmapHeader signedInt16At:(6 + 1) MSB:false.
3602
1b88866d2807 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3596
diff changeset
  1400
                    inPlanes := bitmapHeader unsignedInt16At:(8 + 1) MSB:false.
1b88866d2807 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3596
diff changeset
  1401
                    inDepth := bitmapHeader unsignedInt16At:(10 + 1) MSB:false.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1402
                ].
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1403
                compression := 0.
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1404
                inDepth <= 8 ifTrue:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1405
                    numColor := 1 bitShift:inDepth.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1406
                ].    
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1407
            ].
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1408
        ] ifFalse:[
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1409
            ^ self fileFormatError:'unknown format'.
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1410
        ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1411
    ].
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1412
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1413
    topDown := false.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1414
    height < 0 ifTrue:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1415
        height := height negated.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1416
        topDown := true.
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1417
    ].    
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1418
    ((width > 10000) or:[height > 10000]) ifTrue:[
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1419
        ^ self fileFormatError:'unreasonable width or height'.
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1420
    ].
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1421
    
1846
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
  1422
    self reportDimension.
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
  1423
3999
2e26f0d49ca9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3988
diff changeset
  1424
    numColor := numColor ? 0.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1425
    numColor ~~ 0 ifTrue:[
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1426
        "read the colormap - notice: its in BGR order (sigh)"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1427
3581
cbd1af2f743b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3579
diff changeset
  1428
        numColor > 4096 ifTrue:[
cbd1af2f743b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3579
diff changeset
  1429
            "/ colormap only allowed up to 12bit
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1430
            ^ self fileFormatError:'unreasonable colormap size'.
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1431
        ]. 
3590
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
  1432
"/        (dataStart - inStream position) ~= (numBytesPerColorInColormap*numColor) ifTrue:[
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
  1433
"/            self halt
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
  1434
"/        ].    
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1435
        
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1436
        colorMap := self
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1437
                        readColorMap:numColor
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1438
                        numBytesPerColor:numBytesPerColorInColormap
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1439
                        from:aStream.
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1440
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1441
        numColor > (1 bitShift:inDepth) ifTrue:[
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1442
            'funny number of colors in image' infoPrintCR.
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1443
            numColor := 1 bitShift:inDepth.
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1444
            colorMap := colorMap copyTo:numColor.
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1445
        ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1446
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1447
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1448
    "/ check for valid compression
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1449
    compression ~~ 0 ifTrue:[
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1450
        "/ some compression
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1451
        compression == 1 ifTrue:[
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1452
            "/ RLE8 - must be depth-8
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1453
            inDepth ~~ 8 ifTrue:[
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1454
                ^ self fileFormatError:'RLE8 compression only supported with depth8 images'.
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1455
            ].
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1456
        ].
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1457
        compression == 2 ifTrue:[
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1458
            "/ RLE4 - must be depth-4
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1459
            inDepth ~~ 4 ifTrue:[
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1460
                ^ self fileFormatError:'RLE4 compression only supported with depth4 images'.
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1461
            ].
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1462
        ].
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1463
        compression == 3 ifTrue:[
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1464
            "/ BITFIELDS - must be depth-16 or 32
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1465
            (inDepth < 16) ifTrue:[
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1466
                ^ self fileFormatError:'BITFIELDS compression only supported with depth16/32 images'.
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1467
            ].
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1468
        ].
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1469
        compression >= 4 ifTrue:[
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1470
             ^ self fileFormatError:'unsupported compression'.
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1471
        ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1472
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1473
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1474
    inPlanes ~~ 1 ifTrue:[
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1475
        ^ self fileFormatError:'only 1 plane images supported'.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1476
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1477
565
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1478
    dataStart notNil ifTrue:[
3590
104bc11d3845 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3589
diff changeset
  1479
        "/ (dataStart - inStream position) ~~ 0 ifTrue:[self halt].
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1480
        
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1481
        aStream position:dataStart.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1482
    ].
3581
cbd1af2f743b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3579
diff changeset
  1483
    
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1484
    inDepth == 24 ifTrue:[
3931
4291708939e9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3920
diff changeset
  1485
        bytesPerRow := width * 3.
4291708939e9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3920
diff changeset
  1486
        samplesPerPixel := 3.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1487
    ] ifFalse:[
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1488
        inDepth == 16 ifTrue:[
3931
4291708939e9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3920
diff changeset
  1489
            bytesPerRow := width * 2.
4291708939e9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3920
diff changeset
  1490
            samplesPerPixel := 3.
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1491
        ] ifFalse:[
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1492
            inDepth == 32 ifTrue:[
3931
4291708939e9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3920
diff changeset
  1493
                bytesPerRow := width * 4.
4291708939e9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3920
diff changeset
  1494
                samplesPerPixel := 4.
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1495
            ] ifFalse:[
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1496
                bitsPerSample := Array with:inDepth.
3931
4291708939e9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3920
diff changeset
  1497
                bytesPerRow := self bytesPerRow.
4291708939e9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3920
diff changeset
  1498
                samplesPerPixel := 1.
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1499
            ].
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1500
        ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1501
    ].
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1502
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1503
    data := ByteArray uninitializedNew:(height * bytesPerRow).
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1504
    "/ when compressed, there may be holes, which need to be filled with zeros
3593
cba067f384d3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3592
diff changeset
  1505
    ((compression ~~ 0) and:[compression ~~ 3]) ifTrue:[
3583
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1506
        data atAllPut:0
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1507
    ].
ccf4b1d2548a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3581
diff changeset
  1508
    
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1509
    "/ read & possibly decompress
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1510
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1511
    (self loadBMPWidth:width height:height depth:inDepth from:aStream into:data) ifFalse:[
3579
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1512
        self fileFormatError:('read/decompression error').
94a3b7222275 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3578
diff changeset
  1513
        ^ nil
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1514
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1515
3589
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1516
    self convertPixels.
ef1e5b12715f #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
  1517
    
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1518
    ^ self image
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1519
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1520
    "Modified: / 17-09-1995 / 18:48:46 / claus"
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1521
    "Modified: / 13-09-2017 / 09:40:01 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1522
!
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1523
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1524
fromWindowsICOFile:aFilename
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1525
    "read an image from a windows ICO file"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1526
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1527
    |reader stream|
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1528
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1529
    stream := self class streamReadingFile:aFilename.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1530
    stream isNil ifTrue:[^ nil].
3896
58e71198a302 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3742
diff changeset
  1531
    
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1532
    reader := self class new.
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1533
    reader fromWindowsICOStream:stream.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1534
    stream close.
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1535
    ^ reader image.
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1536
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1537
    "
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1538
     Image fromFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'.
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1539
    "
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1540
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1541
    "Modified: / 30-05-2007 / 16:57:52 / cg"
3896
58e71198a302 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3742
diff changeset
  1542
    "Modified (format): / 17-02-2017 / 08:52:31 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1543
!
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1544
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1545
fromWindowsICOStream:aStream
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1546
    "read an image from a windows ICO stream"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1547
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1548
    ^ self fromWindowsICOStream:aStream alreadyRead:nil
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1549
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1550
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1551
fromWindowsICOStream:aStream alreadyRead:bytesAlreadyRead
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1552
    "read an image from a windows ICO stream"
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1553
3920
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1554
    |header nImages images|
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1555
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1556
    inStream := aStream.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1557
    aStream binary.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1558
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1559
    "read the ICO/CUR header"
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1560
    header := ByteArray uninitializedNew:6.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1561
    bytesAlreadyRead notEmptyOrNil ifTrue:[
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1562
        header replaceFrom:1 with:bytesAlreadyRead
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1563
    ].
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1564
    aStream nextBytes:((6)-bytesAlreadyRead size) into:header startingAt:(1+bytesAlreadyRead size).
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1565
    (header startsWith:#[0 0 1 0]) ifFalse:[
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1566
        (header startsWith:#[0 0 2 0]) ifFalse:[
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1567
            self fileFormatError:'not an ICO/CUR file'.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1568
        ].    
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1569
    ]. 
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1570
    
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1571
    nImages := header unsignedInt16At:4+1 MSB:false.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1572
    images := ImageSequence new.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1573
    1 to:nImages do:[:each |
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1574
        |img|
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1575
        
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1576
        img := self readSingleImageFromWindowsICOStream:aStream.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1577
        img imageSequence:images.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1578
        images add:(ImageFrame new image:img).
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1579
    ].
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1580
    imageSequence := images.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1581
    ^ images first image.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1582
    
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1583
    "
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1584
     WindowsIconReader new fromWindowsICOFile:'~/work/exept/expecco/application/expecco.ico'
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1585
    "
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1586
    "
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1587
     |icons|
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1588
     
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1589
     icons := WindowsIconReader new fromWindowsICOFile:'~/work/exept/expecco/application/expecco.ico'
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1590
     MacOSXIconReader save:icons onFile:'~/work/exept/expecco/application/expecco.icns'.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1591
    "
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1592
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1593
    "Modified (comment): / 22-02-2017 / 18:14:12 / cg"
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1594
!
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1595
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1596
old_fromWindowsICOStream:aStream alreadyRead:bytesAlreadyRead
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1597
    "read an image from a windows ICO stream"
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1598
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1599
    |header
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1600
     srcIndex dstIndex
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1601
     rawData tmp bytesPerRow nColor cmapSize|
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1602
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1603
    inStream := aStream.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1604
    aStream binary.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1605
3f9277473954 Initial revision
claus
parents:
diff changeset
  1606
    "read the header"
3f9277473954 Initial revision
claus
parents:
diff changeset
  1607
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1608
    header := ByteArray uninitializedNew:(6 + 16 + 40).
3404
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1609
    bytesAlreadyRead notEmptyOrNil ifTrue:[
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1610
        header replaceFrom:1 with:bytesAlreadyRead
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1611
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1612
    aStream nextBytes:((6 + 16 + 40)-bytesAlreadyRead size) into:header startingAt:(1+bytesAlreadyRead size).
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1613
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1614
    width := header at:(6+1).
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1615
    height := header at:(7+1).
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1616
    nColor := header at:(8+1).
430
50b841f4851d commentary
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
  1617
    "/ reserved := header at:(9+1).
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1618
    "/ nPlanes := header wordAt:(10+1).
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1619
    "/ nBitsPerPel := header wordAt:(12+1).
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1620
    "/ nBytesInResource := header doubleWordAt:(14+1).
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1621
    "/ ordinal := header wordAt:(18+1).
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1622
    "21, 22               ?"
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1623
    "23, ... , 62         ?"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1624
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1625
    inDepth := header at:16r25.
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1626
    "/ mhmh - some depth4 icons seem to have a 0 in the depth field ...
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1627
    inDepth == 0 ifTrue:[
3404
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1628
        inDepth := 4
1386
2d02a4fba456 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1629
    ].
3404
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1630
    (#(4 8 32) includes:inDepth) ifFalse:[
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1631
        "/ only tested for depth 4/8 images.
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1632
        ^ self fileFormatError:'only depth 4/8/32 ico-images supported (depth is ' , inDepth printString , ')'.
1569
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
  1633
"/        self halt:'only depth 4 ico-images supported (depth is ' , inDepth printString , ')'.
1171
d848c46349ab sorry: only depth4 images are handled.
Claus Gittinger <cg@exept.de>
parents: 1168
diff changeset
  1634
    ].
1846
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
  1635
    self reportDimension.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1636
3404
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1637
    nColor > 0 ifTrue:[
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1638
        "read the colormap"
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1639
        cmapSize := (1 bitShift:inDepth).
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1640
3404
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1641
        colorMap := self readColorMap:cmapSize numBytesPerColor:4 from:aStream.
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1642
    ].
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1643
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1644
    "read the data bits"
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1645
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1646
    bytesPerRow := ((width * inDepth) + 7) // 8.
1569
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
  1647
    rawData := ByteArray uninitializedNew:(height * bytesPerRow).
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
  1648
    aStream nextBytes:(height * bytesPerRow) into:rawData.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1649
3f9277473954 Initial revision
claus
parents:
diff changeset
  1650
    "read mask"
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1651
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1652
"
3f9277473954 Initial revision
claus
parents:
diff changeset
  1653
    mask := ByteArray new:(width * height / 8).
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1654
    aStream nextBytes:(width * height / 8) into:mask.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1655
"
3f9277473954 Initial revision
claus
parents:
diff changeset
  1656
3f9277473954 Initial revision
claus
parents:
diff changeset
  1657
    "stupid: last row first"
3f9277473954 Initial revision
claus
parents:
diff changeset
  1658
3
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
  1659
    tmp := ByteArray uninitializedNew:(height * bytesPerRow).
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1660
    srcIndex := 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
  1661
    dstIndex := (height - 1) * bytesPerRow + 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
  1662
    1 to:height do:[:row |
3404
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1663
        tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1)
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1664
                   with:rawData startingAt:srcIndex.
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1665
        srcIndex := srcIndex + bytesPerRow.
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1666
        dstIndex := dstIndex - bytesPerRow.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1667
    ].
3568
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1668
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1669
    inDepth == 32 ifTrue:[
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1670
        srcIndex := 1.
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1671
        1 to:height do:[:row |
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1672
            1 to:width do:[:row |
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1673
                |b1 b2 b3 b4|
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1674
                b1 := tmp at:srcIndex.
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1675
                b2 := tmp at:srcIndex+1.
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1676
                b3 := tmp at:srcIndex+2.
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1677
                b4 := tmp at:srcIndex+3.
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1678
                tmp at:srcIndex put:b3.
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1679
                tmp at:srcIndex+2 put:b1.
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1680
                
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1681
                srcIndex := srcIndex + 4.
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1682
            ].
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1683
        ].
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1684
    ].
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  1685
1569
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
  1686
    rawData := tmp.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1687
3404
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1688
    nColor > 0 ifTrue:[
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1689
        photometric := #palette.
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1690
        samplesPerPixel := 1.
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1691
        bitsPerSample := (Array with:inDepth).
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1692
    ] ifFalse:[
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1693
        inDepth == 32 ifTrue:[
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1694
            photometric := #rgba.
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1695
            samplesPerPixel := 4.
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1696
            bitsPerSample := #(8 8 8 8).
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1697
        ] ifFalse:[
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1698
            ^ self fileFormatError:'unsupported image depth: ' , inDepth printString.
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1699
        ]
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1700
    ].
298
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
  1701
3404
703c3b400e7d class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 3213
diff changeset
  1702
    data := rawData.
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1703
    ^ self image
298
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
  1704
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1705
    "
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1706
     WindowsIconReader new fromWindowsICOFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1707
    "
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1708
3920
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1709
    "Created: / 22-02-2017 / 15:19:49 / cg"
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1710
!
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1711
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1712
readSingleImageFromWindowsICOStream:aStream 
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1713
    "read one image from a windows ICO stream"
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1714
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1715
    |icondirEntryHeader nBytes fileOffset savedPosition nColor nPlanes nBitsPerPixel img|
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1716
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1717
    inStream := aStream.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1718
    aStream binary.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1719
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1720
    "read the icondirEntryHeader"
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1721
    icondirEntryHeader := aStream nextBytes:16.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1722
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1723
    width := icondirEntryHeader at:0+1.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1724
    width == 0 ifTrue:[ width := 256].
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1725
    height := icondirEntryHeader at:1+1.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1726
    height == 0 ifTrue:[ height := 256].
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1727
    nColor := icondirEntryHeader at:2+1. "/ 0 if not a palette image
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1728
    "/ reserved := icondirEntryHeader at:3+1.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1729
    nPlanes := icondirEntryHeader unsignedInt16At:4+1 MSB:false.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1730
    nBitsPerPixel := icondirEntryHeader unsignedInt16At:6+1 MSB:false.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1731
    nBytes := icondirEntryHeader unsignedInt32At:(8+1) MSB:false.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1732
    fileOffset := icondirEntryHeader unsignedInt32At:(12+1) MSB:false.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1733
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1734
    savedPosition := aStream position.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1735
    aStream position:fileOffset.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1736
    (aStream nextBytes:(PNGReader pngHeader size)) = PNGReader pngHeader ifTrue:[
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1737
        "/ PNG incl bitmapFileHeader
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1738
        aStream position:fileOffset.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1739
        img := PNGReader fromStream:aStream.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1740
    ] ifFalse:[
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1741
        "/ BMP without bitmapFileHeader
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1742
        aStream position:fileOffset.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1743
        img := self fromWindowsBMPStream:aStream alreadyRead:icondirEntryHeader.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1744
    ].
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1745
    aStream position:savedPosition.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1746
    
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1747
    ^ img
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1748
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1749
    "
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1750
     WindowsIconReader new fromWindowsICOFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'.
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1751
    "
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1752
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1753
    "Created: / 22-02-2017 / 15:22:09 / cg"
1bbb4d6fff20 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
  1754
    "Modified (comment): / 22-02-2017 / 17:42:48 / cg"
1805
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1790
diff changeset
  1755
! !
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1790
diff changeset
  1756
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1790
diff changeset
  1757
!WindowsIconReader methodsFor:'writing'!
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1758
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1759
save:image onFile:aFileName
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1760
    "save image as BMP file on aFileName.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1761
     Only depth 1,4,8 and 24 images can be represented in this format."
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1762
1168
590e5660f69e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
  1763
    aFileName asFilename suffix asLowercase = 'ico' ifTrue:[
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1764
        self saveICO:image onFile:aFileName.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1765
        ^ self
1168
590e5660f69e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
  1766
    ].
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1767
    self saveBMP:image onFile:aFileName.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1768
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1769
    "Modified: / 13-09-2017 / 08:47:33 / cg"
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1770
!
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1771
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1772
saveBMP:image onFile:fileName
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1773
    "save image as BMP file on aFileName.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1774
     Only depth 1,4,8 and 24 images can be represented in this format."
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1775
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1776
    outStream := fileName asFilename writeStream.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1777
    outStream binary.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1778
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1779
    self saveBMP:image withFileHeader:true onStream:outStream.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1780
    
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1781
    outStream close.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1782
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1783
    "
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1784
     |i|
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1785
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1786
     i := Image fromFile:'bitmaps/SBrowser.xbm'.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1787
     WindowsIconReader save:i onFile:'test.bmp'.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1788
    "
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1789
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1790
    "
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1791
     |i i2|
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1792
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1793
     i := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1794
     i inspect.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1795
     WindowsIconReader save:i onFile:'garfield.bmp'.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1796
     i2 := Image fromFile:'garfield.bmp'.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1797
     i2 inspect.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1798
    "
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1799
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1800
    "Modified: / 13-09-2017 / 09:18:20 / cg"
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1801
!
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1802
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1803
saveBMP:imageArg withFileHeader:withFileHeaderBoolean onStream:aStream
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1804
    "save image as BMP file on aFileName.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1805
     If withFileHeaderBoolean is false, no bitmapFileHeader is written (used when saving ICO files).
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1806
     Only depth 1,4,8 and 24 images can be represented in this format."
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1807
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1808
    |image depth bhSize biSize biClrUsed biSizeImage bfOffBits rowBytes imgBytesPerRow 
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1809
     bits srcIndex row|
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1810
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1811
    image := imageArg.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1812
    
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1813
    outStream := aStream.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1814
    outStream binary.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1815
    
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1816
    depth := image depth.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1817
    width := image width.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1818
    height := image height.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1819
3726
37f44a063d46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3640
diff changeset
  1820
    (#(1 4 8 24 32) includes:depth) ifFalse:[
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1821
        |newImage|
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1822
        
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1823
        Image cannotRepresentImageSignal
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1824
            raiseRequestWith:image
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1825
            errorString:('BMP format only supports depths 1,4,8,24 and 32').
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1826
        newImage := ((depth < 8) ifTrue:[Depth8Image] ifFalse:[Depth32Image]) fromImage:image.   
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1827
        image := newImage.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1828
        depth := image depth.
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1829
    ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1830
    image mask notNil ifTrue:[
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1831
        |newImage|
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1832
        
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1833
        Image noMaskButAlphaSupportedQuerySignal
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1834
            raiseRequestWith:image
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1835
            errorString:('BMP format does not support an image-mask (but alpha instead)').
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1836
        newImage := Depth32Image fromImage:image.    
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1837
        newImage computeAlphaValuesFromMask:(image mask).
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1838
        image := newImage.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1839
        depth := image depth.
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1840
    ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1841
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1842
    bhSize := withFileHeaderBoolean ifTrue:[14] ifFalse:[0].  "# bytes in file header"     
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1843
    biSize := 40.  "info header size in bytes"
1734
290f382d40e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  1844
    biClrUsed := (depth >= 24) ifTrue:[0] ifFalse:[1 bitShift: depth].  "No. color table entries"
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1845
    bfOffBits := biSize + bhSize + (4*biClrUsed).
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1846
    "/ bmp aligns rows on a longword boundary
3726
37f44a063d46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3640
diff changeset
  1847
    rowBytes := (((depth min:32) * width + 31) // 32) * 4.
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1848
    biSizeImage := height * rowBytes.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1849
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1850
    byteOrder := #lsb.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1851
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1852
    withFileHeaderBoolean ifTrue:[
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1853
        "Write the file header"
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1854
        self writeShort:19778.                      "bfType = BM"
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1855
        self writeLong:(bfOffBits + biSizeImage).   "Entire file size in bytes"
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1856
        self writeLong:0.                           "bfReserved"
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1857
        self writeLong:bfOffBits.                   "Offset of bitmap data from start of hdr (and file)"
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1858
    ].
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1859
    
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1860
    "Write the bitmap info header"
3213
f89acb58aa7e class: WindowsIconReader
Stefan Vogel <sv@exept.de>
parents: 3158
diff changeset
  1861
    outStream position: bhSize.
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1862
    self writeLong:biSize.  "info header size in bytes"
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1863
    self writeLong:width.  "biWidth"
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1864
    self writeLong:height.  "biHeight"
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1865
    self writeShort:1.  "biPlanes"
3726
37f44a063d46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3640
diff changeset
  1866
    self writeShort:(depth min:32).  "biBitCount"
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1867
    self writeLong:0.  "biCompression"
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1868
    self writeLong:biSizeImage.  "size of image section in bytes"
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1869
    self writeLong:2800.  "biXPelsPerMeter"
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1870
    self writeLong:2800.  "biYPelsPerMeter"
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1871
    self writeLong:biClrUsed.
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1872
    self writeLong:0.  "biClrImportant"
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1873
    1 to:biClrUsed do:[:i |  "Color map"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1874
        |clr r g b|
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1875
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1876
        clr := image colorFromValue:i-1.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1877
        clr isNil ifTrue:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1878
            r := g := b := 0.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1879
        ] ifFalse:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1880
            r := clr redByte.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1881
            g := clr greenByte.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1882
            b := clr blueByte.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1883
        ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1884
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1885
        "/ put B,G,R
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1886
        outStream nextPut:b.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1887
        outStream nextPut:g.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1888
        outStream nextPut:r.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1889
        outStream nextPut:0.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1890
    ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1891
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1892
    imgBytesPerRow := image bytesPerRow.
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1893
    bits := image bits.
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1894
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1895
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1896
    "/ sorry, must extract rows individually
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1897
    "/ (even if alignment is correct),
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1898
    "/ since BMP saves rows bottom-to-top
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1899
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1900
    row := ByteArray new:rowBytes.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1901
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1902
    srcIndex := 1 + (height * imgBytesPerRow).
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1903
    1 to:height do:[:i |
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1904
        srcIndex := srcIndex - imgBytesPerRow.
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1905
        row replaceFrom:1 to:imgBytesPerRow with:bits startingAt:srcIndex.
3726
37f44a063d46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3640
diff changeset
  1906
        depth >= 24 ifTrue:[
1507
9bae072abf64 fixed bmp saving 24bit image (red & blue channels exchanged)
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1907
            "/ stupid must swap red & blue bytes
3726
37f44a063d46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3640
diff changeset
  1908
            depth >= 32 ifTrue:[
37f44a063d46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3640
diff changeset
  1909
                self class swap:row size bytesFromRGBA_to_BGRA_in:row startingAt:1.
37f44a063d46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3640
diff changeset
  1910
            ] ifFalse:[
37f44a063d46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3640
diff changeset
  1911
                self class swap:row size bytesFromRGB_to_BGR_in:row startingAt:1.
37f44a063d46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3640
diff changeset
  1912
            ]
1507
9bae072abf64 fixed bmp saving 24bit image (red & blue channels exchanged)
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1913
        ].
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1914
        outStream nextPutAll:row.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1915
    ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1916
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1917
    "
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1918
     |i|
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1919
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1920
     i := Image fromFile:'bitmaps/SBrowser.xbm'.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1921
     WindowsIconReader save:i onFile:'test.bmp'.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1922
    "
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1923
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1924
    "
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1925
     |i i2|
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1926
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1927
     i := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1928
     i inspect.
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1929
     WindowsIconReader save:i onFile:'garfield.bmp'.
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1930
     i2 := Image fromFile:'garfield.bmp'.
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1931
     i2 inspect.
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1932
    "
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1933
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1934
    "Created: / 13-09-2017 / 09:18:14 / cg"
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1935
    "Modified: / 13-09-2017 / 10:22:56 / cg"
1167
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1936
!
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1937
2578
7d49dc8ecb63 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2571
diff changeset
  1938
saveICO:image onFile:fileName
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1939
    "save image as ICO file on aFileName"
1167
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1940
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1941
    |depth numColors bmpData savOutStream|
1167
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1942
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1943
    depth := image depth.
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1944
4014
17853d377ead #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4012
diff changeset
  1945
    (#(1 2 4 8 24 32) includes:depth) ifFalse:[
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1946
        ^ Image cannotRepresentImageSignal
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1947
            raiseWith:image
4014
17853d377ead #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4012
diff changeset
  1948
            errorString:('ICO format (currently) only supports depths 1,2,4,8,24 or 32').
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1949
    ].
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1950
1167
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1951
    width := image width.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1952
    height := image height.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1953
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1954
    "/ align rows on a longword boundary
4014
17853d377ead #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4012
diff changeset
  1955
    numColors := depth <= 8 
17853d377ead #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4012
diff changeset
  1956
                    ifTrue:[ (1 bitShift:depth) ]
17853d377ead #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4012
diff changeset
  1957
                    ifFalse:[ 0 ].
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1958
    
1167
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1959
    outStream := fileName asFilename writeStream.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1960
    outStream binary.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1961
    byteOrder := #lsb.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1962
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1963
    "Write the file header"
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1964
    outStream nextPutAll:#[0 0].                "/ 0 magic
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1965
    outStream nextPutAll:#[1 0].                "/ 2 magic for ICO; 2 for CUR 
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1966
    outStream nextPutInt16:1 MSB:false.         "/ 4 # of images in file
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1967
    
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1968
    "Write the ICONDIRECTORY structure"
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1969
    outStream nextPut:width.                    "/ 0
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1970
    outStream nextPut:height.                   "/ 1
4014
17853d377ead #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4012
diff changeset
  1971
    outStream nextPut:numColors.                "/ 2 # of colors in colormap
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1972
    outStream nextPut:0.                        "/ 3 reserved
4014
17853d377ead #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4012
diff changeset
  1973
    "/ 4 for ICO: color planes (should be 0 or 1)
17853d377ead #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4012
diff changeset
  1974
    "/ 4 for CUR: hotspot-X
17853d377ead #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4012
diff changeset
  1975
    outStream nextPutInt16:((depth <= 8) ifTrue:[0] ifFalse:[1]) MSB:false.         
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1976
    
4014
17853d377ead #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4012
diff changeset
  1977
    "/ 6 for ICO: bits per pixel
17853d377ead #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4012
diff changeset
  1978
    "/ 6 for CUR: hotspot-Y
17853d377ead #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4012
diff changeset
  1979
    outStream nextPutInt16:depth MSB:false.      
1167
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1980
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1981
    savOutStream := outStream.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1982
    [
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1983
        |bmpStream|
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1984
        
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1985
        bmpStream := WriteStream on:(ByteArray new:100).
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1986
        self saveBMP:image withFileHeader:false onStream:bmpStream. 
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1987
        bmpData := bmpStream contents.
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1988
    ] ensure:[
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1989
        outStream := savOutStream
1167
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1990
    ].
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1991
    
4014
17853d377ead #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4012
diff changeset
  1992
    outStream nextPutInt32:(bmpData size) MSB:false.            "/ 8 size of image data
17853d377ead #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4012
diff changeset
  1993
    outStream nextPutInt32:(outStream position + 4) MSB:false.  "/ 12 offset in file
1167
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1994
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1995
    "/ followed by bmp format image without bitmap-file-header
1167
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1996
4012
af495a29eafa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4003
diff changeset
  1997
    outStream nextPutAll:bmpData.
1167
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1998
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1999
    outStream close.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  2000
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  2001
    "
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  2002
     |i|
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  2003
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  2004
     i := Image fromFile:'bitmaps/xpmBitmaps/SmalltalkX_clr.xpm'.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  2005
     i := Depth4Image fromImage:i.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  2006
     i := i magnifiedTo:32@32.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  2007
     WindowsIconReader new saveICO:i onFile:'test.ico'.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  2008
    "
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  2009
4014
17853d377ead #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4012
diff changeset
  2010
    "Modified (format): / 13-09-2017 / 17:13:58 / cg"
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  2011
! !
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  2012
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  2013
!WindowsIconReader class methodsFor:'documentation'!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  2014
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  2015
version
3568
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  2016
    ^ '$Header$'
2756
e8bf6a023191 halt in: #loadBMPWidth:height:depth:from:into:
Claus Gittinger <cg@exept.de>
parents: 2578
diff changeset
  2017
!
e8bf6a023191 halt in: #loadBMPWidth:height:depth:from:into:
Claus Gittinger <cg@exept.de>
parents: 2578
diff changeset
  2018
e8bf6a023191 halt in: #loadBMPWidth:height:depth:from:into:
Claus Gittinger <cg@exept.de>
parents: 2578
diff changeset
  2019
version_CVS
3568
a8900d28752b #BUGFIX
matilk
parents: 3404
diff changeset
  2020
    ^ '$Header$'
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  2021
! !
1734
290f382d40e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  2022
3158
b017a13ec3f5 class: WindowsIconReader
Claus Gittinger <cg@exept.de>
parents: 2812
diff changeset
  2023
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  2024
WindowsIconReader initialize!