WindowsIconReader.st
author Claus Gittinger <cg@exept.de>
Wed, 02 Feb 2005 11:44:31 +0100
changeset 2034 08a022c3faee
parent 2031 c8527bd15f50
child 2333 a93f1f5392bd
permissions -rw-r--r--
oops
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
"
3f9277473954 Initial revision
claus
parents:
diff changeset
    12
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    13
"{ Package: 'stx:libview2' }"
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    14
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    15
ImageReader subclass:#WindowsIconReader
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    16
	instanceVariableNames:''
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    17
	classVariableNames:''
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    18
	poolDictionaries:''
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
    19
	category:'Graphics-Images-Readers'
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    20
!
3f9277473954 Initial revision
claus
parents:
diff changeset
    21
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    22
!WindowsIconReader class methodsFor:'documentation'!
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    23
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    24
copyright
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    25
"
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    26
 COPYRIGHT (c) 1993 by Claus Gittinger
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    27
	      All Rights Reserved
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    28
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    29
 This software is furnished under a license and may be used
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    30
 only in accordance with the terms of that license and with the
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    32
 be provided or otherwise made available to, or used by, any
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    33
 other person.  No title to or ownership of the software is
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    34
 hereby transferred.
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    35
"
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    36
!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    37
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    38
documentation
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    39
"
32
6bdcb6da4d4f *** empty log message ***
claus
parents: 28
diff changeset
    40
    this class provides methods for loading Windows and OS2 icon files.
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
    41
    Image writing is only supported for BMP format with depth 1,4,8 and 24 bit images.
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    42
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    43
    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
    44
    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
    45
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    46
    The class name *IconReader is a bad, historic choice - it ws originally
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    47
    written to read icons only, but evolved over time and it should now be also
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    48
    capapble of reading bmp and cursor files.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    49
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    50
    [See also:]
234
b6352d13e792 xrefs in documentation
Claus Gittinger <cg@exept.de>
parents: 211
diff changeset
    51
        Image Form Icon
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    52
        BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader 
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    53
        ST80FormReader SunRasterReader TargaReader TIFFReader  
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    54
        XBMReader XPMReader XWDReader 
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    55
"
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    56
!
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    57
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    58
fileFormatDescription
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    59
"
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    60
    Information from http://www.daubnet.com/formats/BMP.html - no Warranty.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    61
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    62
          Name           Size                Description
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    63
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    64
      Header            14 bytes            Windows Structure: BITMAPFILEHEADER
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    65
          Signature      2 bytes             'BM'
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    66
          FileSize       4 bytes             File size in bytes
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    67
          reserved       4 bytes             unused (=0)
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    68
          DataOffset     4 bytes             File offset to Raster Data
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    69
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    70
      InfoHeader        40 bytes            Windows Structure: BITMAPINFOHEADER
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    71
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    72
          Size           4 bytes             Size of InfoHeader =40 
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    73
          Width          4 bytes             Bitmap Width
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    74
          Height         4 bytes             Bitmap Height
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    75
          Planes         2 bytes             Number of Planes (=1)
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    76
          BitCount       2 bytes             Bits per Pixel   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    77
                                             1 = monochrome palette. NumColors = 1   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    78
                                             4 = 4bit palletized. NumColors = 16   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    79
                                             8 = 8bit palletized. NumColors = 256  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    80
                                             16 = 16bit RGB. NumColors = 65536 (?)  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    81
                                             24 = 24bit RGB. NumColors = 16M
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    82
          Compression    4 bytes             Type of Compression   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    83
                                             0 = BI_RGB   no compression   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    84
                                             1 = BI_RLE8 8bit RLE encoding   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    85
                                             2 = BI_RLE4 4bit RLE encoding
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    86
          ImageSize      4 bytes             (compressed) Size of Image  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    87
                                             It is valid to set this =0 if Compression = 0
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    88
          XpixelsPerM    4 bytes             horizontal resolution: Pixels/meter
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    89
          YpixelsPerM    4 bytes             vertical resolution: Pixels/meter
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    90
          ColorsUsed     4 bytes             Number of actually used colors
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    91
          ColorsImportant
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    92
                         4 bytes             Number of important colors  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    93
                                             0 = all
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    94
       ColorTable        4 * NumColors bytes
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    95
                                             present only if Info.BitsPerPixel <= 8   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    96
                                             colors should be ordered by importance
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    97
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    98
            Red           1 byte              Red intensity
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    99
            Green         1 byte              Green intensity
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   100
            Blue          1 byte              Blue intensity
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   101
            reserved      1 byte             unused (=0)
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   102
          repeated NumColors times
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   103
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   104
       Raster Data      Info.ImageSize bytes     The pixel data
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   105
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   106
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   107
Raster Data encoding:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   108
       Depending on the image's BitCount and on the Compression flag there are 6 different encoding schemes. 
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   109
       All of them share the following:  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   110
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   111
       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
   112
       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
   113
       color of 0 represents the first color table entry, a pixel color of 255 (if there are that many) represents the 256th entry.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   114
       For images with more than 256 colors there is no color table. 
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   115
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   116
Raster Data encoding for 1bit / black & white images:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   117
       BitCount = 1 Compression = 0  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   118
       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
   119
       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
   120
       pictures you should stick to this, with any other 2 colors this is not an issue. Remember padding with zeros up to a
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   121
       32bit boundary (This can be up to 31 zeros/pixels!!)                                                                 
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   122
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   123
Raster Data encoding for 4bit / 16 color images:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   124
       BitCount = 4 Compression = 0  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   125
       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
   126
       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
   127
       will result in up to 28 zeros = 7 'wasted pixels'.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   128
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   129
Raster Data encoding for 8bit / 256 color images:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   130
       BitCount = 8 Compression = 0  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   131
       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
   132
       result in up to 3 bytes of zeros = 3 'wasted pixels'.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   133
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   134
Raster Data encoding for 16bit / hicolor images:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   135
       BitCount = 16 Compression = 0  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   136
       Every 2bytes / 16bit holds 1 pixel.   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   137
       <information missing: the 16 bit was introduced together with Video For Windows? Is it a memory-only-format?>  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   138
       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
   139
       boundary will result in up to 2 zero bytes.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   140
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   141
Raster Data encoding for 24bit / truecolor images:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   142
       BitCount = 24 Compression = 0  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   143
       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
   144
       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
   145
       zero padding necessary.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   146
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   147
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   148
Raster Data compression for 4bit / 16 color images:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   149
       BitCount = 4 Compression = 2  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   150
       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
   151
       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
   152
       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
   153
       End-of-Bitmap is zero padded to end on a 32bit boundary. Due to the 16bit-ness of this structure this will always be
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   154
       either two zero bytes or none.   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   155
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   156
        n (byte 1) c (Byte 2)                                       Description
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   157
        >0        any      n pixels are to be drawn. The 1st, 3rd, 5th, ... pixels' color is in c's high-order 4 bits, the even
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   158
                            pixels' color is in c's low-order 4 bits. If both color indices are the same, it results in just n
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   159
                            pixels of color c
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   160
        0         0        End-of-line
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   161
        0         1        End-of-Bitmap
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   162
        0         2        Delta. The following 2 bytes define an unsigned offset in x and y direction (y being up) The
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   163
                            skipped pixels should get a color zero.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   164
        0         >=3      The following c bytes will be read as single pixel colors just as in uncompressed files. up to 12
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   165
                            bits of zeros follow, to put the file/memory pointer on a 16bit boundary again.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   166
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   167
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   168
                                      Example for 4bit RLE
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   169
        Compressed Data                           Expanded data
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   170
        03 04              0 4 0
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   171
        05 06              0 6 0 6 0
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   172
        00 06 45 56 67 00  4 5 5 6 6 7
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   173
        04 78              7 8 7 8
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   174
        00 02 05 01        Move 5 right and 1 up. (Windows docs say down, which is wrong)
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   175
        00 00              End-of-line
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   176
        09 1E              1 E 1 E 1 E 1 E 1
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   177
        00 01              EndofBitmap
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   178
        00 00              Zero padding for 32bit boundary
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 8bit / 256 color images:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   182
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   183
       BitCount = 8 Compression = 1  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   184
       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
   185
       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
   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
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   187
       either two zero bytes or none.   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   188
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   189
        n (byte 1)   c (Byte 2)                                    Description
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   190
        >0       any        n pixels of color number c
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   191
        0        0          End-of-line
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   192
        0        1          End Of Bitmap
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   193
        0        2          Delta. The following 2 bytes define an unsigned offset in x and y direction (y being up) The
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   194
                            skipped pixels should get a color zero.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   195
        0        >=3        The following c bytes will be read as single pixel colors just as in uncompressed files. A zero
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   196
                            follows, if c is odd, putting the file/memory pointer on a 16bit boundary again.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   197
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   198
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   199
                                      Example for 8bit RLE
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   200
        Compressed Data                           Expanded data
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   201
        03 04              04 04 04
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   202
        05 06              06 06 06 06 06
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   203
        00 03 45 56 67 00  45 56 67
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   204
        02 78              78 78
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   205
        00 02 05 01        Move 5 right and 1 up. (Windows docs say down, which is wrong)
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   206
        00 00              End-of-line
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   207
        09 1E              1E 1E 1E 1E 1E 1E 1E 1E 1E
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   208
        00 01              End-of-bitmap
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   209
        00 00              Zero padding for 32bit boundary
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   210
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   211
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
Portability:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   215
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   216
       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
   217
       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
   218
       16bit BMPs have been introduced to Windows after the others, still puzzling many applications.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   219
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   220
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   221
Trademarks, Patents and Royalties
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   222
       To my knowledge: None.  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   223
"
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   224
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   225
! !
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   226
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
   227
!WindowsIconReader class methodsFor:'initialization'!
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
   228
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
   229
initialize
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   230
    "tell Image-class, that a new fileReader is present
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 387
diff changeset
   231
     for the '.bmp' and '.ico' extensions."
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   232
647
6f26c76aa0c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   233
    MIMETypes defineImageType:'image/x-MS-bitmap' suffix:'bmp' reader:self.
6f26c76aa0c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   234
    MIMETypes defineImageType:nil                 suffix:'ico' reader:self.
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   235
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 387
diff changeset
   236
    "Modified: 1.2.1997 / 15:03:59 / cg"
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
   237
! !
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
   238
102
claus
parents: 99
diff changeset
   239
!WindowsIconReader class methodsFor:'testing'!
claus
parents: 99
diff changeset
   240
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   241
canRepresent:anImage
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   242
    "return true, if anImage can be represented in my file format.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   243
     BMP supports depth 1,4,8 and 24."
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   244
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   245
    ^ (#(1 4 8 24) includes:anImage depth)
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   246
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   247
    "Created: 17.10.1997 / 20:18:23 / cg"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   248
!
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   249
102
claus
parents: 99
diff changeset
   250
isValidImageFile:aFileName
claus
parents: 99
diff changeset
   251
    "return true, if aFileName contains a valid windows bitmap-file image"
claus
parents: 99
diff changeset
   252
claus
parents: 99
diff changeset
   253
    |inStream header ok|
claus
parents: 99
diff changeset
   254
claus
parents: 99
diff changeset
   255
    inStream := self streamReadingFile:aFileName.
claus
parents: 99
diff changeset
   256
    inStream isNil ifTrue:[^ false].
claus
parents: 99
diff changeset
   257
claus
parents: 99
diff changeset
   258
    inStream binary.
104
claus
parents: 103
diff changeset
   259
    ok := false.
692
e6af4c70e066 size is going to be eliminated from the stream
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
   260
    inStream fileSize > 16 ifTrue:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   261
        header := ByteArray uninitializedNew:4.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   262
        inStream nextBytes:4 into:header.
102
claus
parents: 99
diff changeset
   263
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   264
        (header startsWith:#(66 77)) ifTrue:[     "BM"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   265
            ok := true.
104
claus
parents: 103
diff changeset
   266
"/            'WINREADER: Win3.x or OS/2 vsn 2 BM format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   267
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   268
        (header startsWith:#(66 65)) ifTrue:[     "BA"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   269
            ok := true.
104
claus
parents: 103
diff changeset
   270
"/            'WINREADER: OS/2 vsn 2 BA format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   271
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   272
        (header startsWith:#(73 67)) ifTrue:[     "IC"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   273
            ok := true.
104
claus
parents: 103
diff changeset
   274
"/            'WINREADER: OS/2 IC format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   275
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   276
        (header startsWith:#(80 84)) ifTrue:[     "PT"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   277
            ok := true.
104
claus
parents: 103
diff changeset
   278
"/            'WINREADER: OS/2 PT format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   279
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   280
        (header startsWith:#(0 0 1 0)) ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   281
            ok := true.
104
claus
parents: 103
diff changeset
   282
"/            'WINREADER: Win3.x ICO format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   283
        ].
102
claus
parents: 99
diff changeset
   284
    ].
104
claus
parents: 103
diff changeset
   285
    inStream close.
claus
parents: 103
diff changeset
   286
    ^ ok
102
claus
parents: 99
diff changeset
   287
claus
parents: 99
diff changeset
   288
    "
claus
parents: 99
diff changeset
   289
     WindowsIconReader isValidImageFile:'/phys/clam2/LocalLibrary/Images/OS2_icons/dos.ico'
claus
parents: 99
diff changeset
   290
    "
claus
parents: 99
diff changeset
   291
claus
parents: 99
diff changeset
   292
    "Created: 17.9.1995 / 17:14:20 / claus"
claus
parents: 99
diff changeset
   293
! !
claus
parents: 99
diff changeset
   294
103
claus
parents: 102
diff changeset
   295
!WindowsIconReader methodsFor:'private'!
claus
parents: 102
diff changeset
   296
claus
parents: 102
diff changeset
   297
loadBMPWidth:w height:h depth:d compression:c from:aStream into:data
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   298
    "helper: load a BMP image"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   299
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   300
    |buff idx fileBytesPerRow imgBytesPerRow|
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   301
103
claus
parents: 102
diff changeset
   302
    d == 8 ifTrue:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   303
        (self class loadBMP8Width:w height:h compression:c from:aStream into:data) ifFalse:[
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   304
            self fileFormatError:'read/decompression failed'.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   305
            ^ false
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   306
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   307
        ^ true
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   308
    ].
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   309
    d == 4 ifTrue:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   310
        (self class loadBMP4to8Width:w height:h compression:c from:aStream into:data) ifFalse:[
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   311
            self fileFormatError:'read/decompression failed'.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   312
            ^ false
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   313
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   314
        ^ true
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   315
    ].
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   316
    d == 2 ifTrue:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   317
        (self class loadBMP2to8Width:w height:h from:aStream into:data) ifFalse:[
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   318
            self fileFormatError:'read failed'.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   319
            ^ false
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   320
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   321
        ^ true
103
claus
parents: 102
diff changeset
   322
    ].
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   323
    d == 1 ifTrue:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   324
        (self class loadBMP1to8Width:w height:h from:aStream into:data) ifFalse:[
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   325
            self fileFormatError:'read failed'.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   326
            ^ false
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   327
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   328
        ^ true
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   329
    ].
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   330
    d == 24 ifTrue:[
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   331
        imgBytesPerRow := w * 3.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   332
        fileBytesPerRow := imgBytesPerRow.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   333
        (fileBytesPerRow bitAnd:3) ~~ 0 ifTrue:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   334
            fileBytesPerRow := (fileBytesPerRow bitAnd:(3 bitInvert)) + 4.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   335
        ].
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   336
        "/
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   337
        "/ stupid - last row comes first
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   338
        "/
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   339
        idx := imgBytesPerRow * (height - 1) + 1.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   340
        buff := ByteArray uninitializedNew:fileBytesPerRow.
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   341
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   342
        1 to:height do:[:row |
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   343
            (aStream nextBytes:fileBytesPerRow into:buff) ~~ fileBytesPerRow ifTrue:[
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   344
                self fileFormatError:'read failed'.
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   345
                ^ false
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   346
            ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   347
            data replaceFrom:idx to:idx+imgBytesPerRow-1 with:buff.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   348
            idx := idx - imgBytesPerRow.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   349
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   350
        ^ true
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   351
    ].
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   352
    self fileFormatError:('unsupported depth:' , d printString).
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   353
    ^ false
103
claus
parents: 102
diff changeset
   354
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   355
    "Created: / 17.9.1995 / 18:48:11 / claus"
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   356
    "Modified: / 3.2.1998 / 20:21:16 / cg"
103
claus
parents: 102
diff changeset
   357
! !
claus
parents: 102
diff changeset
   358
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   359
!WindowsIconReader methodsFor:'private-reading'!
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   360
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   361
readColorMap:nColors numBytesPerColor:nRawBytesPerColor from:aStream
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   362
    "read the colormap; notice: its in BGR order (sigh)."
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   363
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   364
    |rawMap rMap gMap bMap 
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   365
     srcIndex  "{ Class: SmallInteger }"
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   366
     skipDelta "{ Class: SmallInteger }"|
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   367
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   368
    rawMap := ByteArray uninitializedNew:(nColors*nRawBytesPerColor).
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   369
    aStream nextBytes:(nColors*nRawBytesPerColor) into:rawMap.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   370
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   371
    rMap := ByteArray new:nColors.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   372
    gMap := ByteArray new:nColors.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   373
    bMap := ByteArray new:nColors.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   374
    srcIndex := 1.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   375
    skipDelta := nRawBytesPerColor - 3.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   376
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   377
    "/ stupid: this is a BGR-ordered map (otherwise, could use #rgbBytesVector:-message)
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   378
    "/ also, there might be a fourth byte (alpha ?) which is (currently) skipped.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   379
    1 to:nColors do:[:i |
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   380
        bMap at:i put:(rawMap at:srcIndex).
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   381
        srcIndex := srcIndex + 1.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   382
        gMap at:i put:(rawMap at:srcIndex).
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   383
        srcIndex := srcIndex + 1.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   384
        rMap at:i put:(rawMap at:srcIndex).
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   385
        srcIndex := srcIndex + 1.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   386
        srcIndex := srcIndex + skipDelta.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   387
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   388
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   389
    ^ MappedPalette 
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   390
        redVector:rMap 
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   391
        greenVector:gMap 
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   392
        blueVector:bMap.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   393
! !
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   394
1805
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1790
diff changeset
   395
!WindowsIconReader methodsFor:'reading'!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   396
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   397
fromOS2File:aFilename
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   398
    "read an image from an OS/2 BMP file"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   399
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   400
    |reader stream|
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   401
1790
41f36b5a29c3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
   402
    stream := self class streamReadingFile:aFilename.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   403
    stream isNil ifTrue:[^ nil].
1790
41f36b5a29c3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
   404
    reader := (self class new) fromOS2Stream:stream.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   405
    stream close.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   406
    reader notNil ifTrue:[^ reader image].
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   407
    ^ nil
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   408
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   409
    "Modified: 23.4.1996 / 13:09:28 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   410
!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   411
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   412
fromOS2Stream:aStream
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   413
    "read an image from an OS/2 BMP stream"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   414
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   415
    |header inDepth 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
   416
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   417
    inStream := aStream.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   418
    aStream binary.
2031
c8527bd15f50 .ico stuff - ongoing work
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   419
    byteOrder := #lsb.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   420
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   421
    "read the header"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   422
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   423
    header := ByteArray uninitializedNew:8r110.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   424
    aStream nextBytes:16 into:header.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   425
445
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   426
    (header startsWith:#(73 67)) ifTrue:[         "IC"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   427
        "IC format"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   428
        aStream nextBytes:10 into:header startingAt:17.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   429
        width := header at:7.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   430
        height := header at:9.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   431
        inDepth := 2 "header at:11". "where is it"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   432
    ] ifFalse:[
445
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   433
        (header startsWith:#(67 73)) ifTrue:[     "CI"
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   434
            ^ self fileFormatError:'unsupported format: CI'.
445
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   435
        ] ifFalse:[
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   436
            aStream nextBytes:(8r110-16) into:header startingAt:17.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   437
            width := header at:8r101.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   438
            height := header at:8r103.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   439
            inDepth := header at:8r107.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   440
        ]
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   441
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   442
1846
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   443
    self reportDimension.
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   444
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   445
    "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
   446
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   447
    nColors := 1 bitShift:inDepth.
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   448
    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
   449
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   450
    "read the mask"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   451
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   452
    nByte := width * height + 7 // 8.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   453
    mask := ByteArray uninitializedNew:nByte.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   454
    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
   455
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   456
    "what is this ?"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   457
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   458
    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
   459
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   460
"/    "read the data bits"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   461
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   462
"/    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
   463
"/    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
   464
"/    inDepth == 8 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   465
"/    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   466
"/    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
   467
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   468
"/    "stupid: last row first"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   469
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   470
"/    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
   471
"/    srcIndex := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   472
"/    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
   473
"/    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
   474
"/        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
   475
"/                   with:data4 startingAt:srcIndex.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   476
"/        srcIndex := srcIndex + bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   477
"/        dstIndex := dstIndex - bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   478
"/    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   479
"/    data4 := tmp.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   480
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   481
"/    "expand into bytes"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   482
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   483
"/    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
   484
"/    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
   485
"/                  into:data mapping:nil.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   486
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   487
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   488
    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
   489
    "/ 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
   490
    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
   491
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   492
    data := ByteArray uninitializedNew:(height * width "bytesPerRow").
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   493
    (self loadBMPWidth:width height:height depth:inDepth compression:0 from:aStream into:data) ifFalse:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   494
        ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   495
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   496
    photometric := #palette.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   497
    samplesPerPixel := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   498
    bitsPerSample := #(8).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   499
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   500
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   501
     |i f|
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   502
     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
   503
     f := i asFormOn:Display.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   504
     v displayOpaqueForm:(f magnifyBy:2@2) x:5 y:5
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   505
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   506
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   507
    "Modified: / 17.9.1995 / 18:49:24 / claus"
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   508
    "Modified: / 3.2.1998 / 20:17:13 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   509
!
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   510
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   511
fromStream:aStream 
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   512
    "figure out which format the stream contains
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   513
     (there are various different bmp/ico formats around)
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   514
     and read the image."
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   515
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   516
    |fileSize header|
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   517
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   518
    inStream := aStream.
2031
c8527bd15f50 .ico stuff - ongoing work
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   519
    byteOrder := #lsb.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   520
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   521
    aStream binary.
692
e6af4c70e066 size is going to be eliminated from the stream
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
   522
    fileSize := aStream fileSize.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   523
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   524
    fileSize < 16 ifTrue:[
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   525
        ^ self fileFormatError:'short file'.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   526
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   527
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   528
    header := ByteArray uninitializedNew:4.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   529
    aStream nextBytes:4 into:header.
2031
c8527bd15f50 .ico stuff - ongoing work
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   530
    aStream position:0.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   531
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   532
    (header startsWith:#(66 77)) ifTrue:[     "BM"
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   533
"/        'WinIconReader [info]: Win3.x or OS/2 vsn 2 BM format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   534
        ^ self fromWindowsBMPStream:aStream
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   535
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   536
    (header startsWith:#(66 65)) ifTrue:[     "BA"
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   537
"/        'WinIconReader [info]: OS/2 vsn 2 BA format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   538
        ^ self fromOS2Stream:aStream
445
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   539
    ].                    
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   540
    (header startsWith:#(67 73)) ifTrue:[     "CI"
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   541
"/        'WinIconReader [info]: OS/2 vsn 2 BA format' infoPrintNL.
2031
c8527bd15f50 .ico stuff - ongoing work
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   542
"/        ^ self fromOS2Stream:aStream
c8527bd15f50 .ico stuff - ongoing work
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   543
        ^ self fileFormatError:'OS/2 CI format not supported'.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   544
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   545
    (header startsWith:#(73 67)) ifTrue:[     "IC"
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   546
"/        'WinIconReader [info]: OS/2 IC format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   547
        ^ self fromOS2Stream:aStream
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   548
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   549
    (header startsWith:#(80 84)) ifTrue:[     "PT"
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   550
"/        'WinIconReader [info]: OS/2 PT format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   551
        ^ self fromOS2Stream:aStream
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   552
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   553
    (header startsWith:#(16r53 16r5A)) ifTrue:[     "SZ"
1167
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   554
"/        'WinIconReader [info]: OS/2 SZ format' infoPrintNL.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   555
"/        ^ self fromOS2Stream:aStream
2031
c8527bd15f50 .ico stuff - ongoing work
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   556
        ^ self fileFormatError:'OS/2 SZ format not supported'.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   557
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   558
    (header startsWith:#(0 0 1 0)) ifTrue:[
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
   559
"/        'WinIconReader [info]: Win3.x ICO format' infoPrintNL.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   560
        ^ self fromWindowsICOStream:aStream
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   561
    ].
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   562
    ^ self fileFormatError:('format not supported:'
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   563
                            , ((header at:1) printStringRadix:16)
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   564
                            , ' ' 
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   565
                            , ((header at:2) printStringRadix:16)).
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   566
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   567
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   568
     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
   569
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   570
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   571
    "Modified: / 17.9.1995 / 18:59:07 / claus"
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   572
    "Modified: / 3.2.1998 / 20:18:14 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   573
!
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   574
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   575
fromWindowsBMPFile: aFilename 
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   576
    "read an image from a windows BMP file"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   577
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   578
    |reader stream|
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   579
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   580
    stream := self class streamReadingFile:aFilename.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   581
    stream isNil ifTrue:[^ nil].
1790
41f36b5a29c3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
   582
    reader := (self class new) fromWindowsBMPStream:stream.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   583
    stream close.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   584
    reader notNil ifTrue:[^ reader image].
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   585
    ^ nil
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   586
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   587
    "Modified: 23.4.1996 / 13:09:53 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   588
!
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   589
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   590
fromWindowsBMPStream:aStream 
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   591
    "read an image from a windows BMP stream"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   592
2031
c8527bd15f50 .ico stuff - ongoing work
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   593
    | header iSize inDepth inPlanes compression
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   594
      imgSize resH resV numColor numImportantColor
1073
1e1450185eb8 fixed r-g-b order (red & blue are swapped in file)
Claus Gittinger <cg@exept.de>
parents: 952
diff changeset
   595
      dataStart t
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   596
      bytesPerRow numBytesPerColorInColormap|
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   597
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   598
    inStream := aStream.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   599
    aStream binary.
2031
c8527bd15f50 .ico stuff - ongoing work
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   600
    byteOrder := #lsb.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   601
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   602
    "read the header"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   603
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   604
    header := ByteArray uninitializedNew:16r54.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   605
    aStream nextBytes:18 into:header.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   606
518
c9d492fbb1b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 445
diff changeset
   607
    iSize := header at:(16r0E + 1).
c9d492fbb1b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 445
diff changeset
   608
    (iSize == 40) ifTrue:[    "header-size"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   609
        "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   610
         its an Windows3.x BMP file
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   611
         or OS/2 vsn 2 BMP file
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   612
        "
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   613
        "/ 'WinIconReader [info]: Win3.x or OS/2 vsn 2 format' infoPrintCR.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   614
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   615
        aStream nextBytes:(40-4) into:header startingAt:19.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   616
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   617
        width := header wordAt:(16r12 + 1) MSB:false.  "(header at:19) + ((header at:20) * 256).   "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   618
        height := header wordAt:(16r16 + 1) MSB:false. "(header at:23) + ((header at:24) * 256).   "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   619
        inPlanes := header wordAt:(16r1A + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   620
        inDepth := header wordAt:(16r1C + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   621
        compression := header wordAt:(16r1E + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   622
        imgSize := header doubleWordAt:(16r22 + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   623
        resH := header doubleWordAt:(16r26 + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   624
        resV := header doubleWordAt:(16r2A + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   625
        numColor := header doubleWordAt:(16r2E + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   626
        numImportantColor := header doubleWordAt:(16r32 + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   627
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   628
        numColor == 0 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   629
            "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   630
             some bmp-writers seem to leave this as zero (which is wrong)
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   631
            "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   632
            inDepth <= 8 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   633
                numColor := 1 bitShift:inDepth.
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   634
                "/ 'WinIconReader [warning]: missing nColor in header - assume ' infoPrint. numColor infoPrintCR
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   635
            ]
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   636
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   637
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   638
        numBytesPerColorInColormap := 4.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   639
        dataStart := header wordAt:(16r0A + 1) MSB:false
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   640
    ] ifFalse:[
518
c9d492fbb1b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 445
diff changeset
   641
        (iSize == 12) ifTrue:[     "core-info header size"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   642
            "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   643
             its an OS/2 (vsn1.2) BMP file
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   644
            "
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   645
            "/ 'WinIconReader [info]: OS/2 vsn 1.2 format' infoPrintCR.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   646
            aStream nextBytes:(12-4) into:header startingAt:19.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   647
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   648
            width := header wordAt:(16r12 + 1) MSB:false.  "(header at:19) + ((header at:20) * 256).   "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   649
            height := header wordAt:(16r14 + 1) MSB:false. "(header at:21) + ((header at:22) * 256).   "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   650
            inPlanes := header wordAt:(16r16 + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   651
            inDepth := header wordAt:(16r18 + 1) MSB:false.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   652
            numColor := 1 bitShift:inDepth.
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   653
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   654
            numBytesPerColorInColormap := 3.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   655
            compression := 0.
565
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   656
            "/ dataStart := header wordAt:(16r0A + 1) MSB:false.
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   657
            dataStart := nil.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   658
        ] ifFalse:[
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   659
            ^ self fileFormatError:'unknown format'.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   660
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   661
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   662
1846
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   663
    self reportDimension.
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   664
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   665
    numColor ~~ 0 ifTrue:[
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   666
        "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
   667
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   668
        colorMap := self 
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   669
                        readColorMap:numColor 
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   670
                        numBytesPerColor:numBytesPerColorInColormap
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   671
                        from:aStream.
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   672
898
cdf6cc132b53 care for funny number of colors (nColor > (1<<depth))
Claus Gittinger <cg@exept.de>
parents: 819
diff changeset
   673
        numColor > (1 bitShift:inDepth) ifTrue:[
cdf6cc132b53 care for funny number of colors (nColor > (1<<depth))
Claus Gittinger <cg@exept.de>
parents: 819
diff changeset
   674
            'funny number of colors in image' infoPrintCR.
cdf6cc132b53 care for funny number of colors (nColor > (1<<depth))
Claus Gittinger <cg@exept.de>
parents: 819
diff changeset
   675
            numColor := 1 bitShift:inDepth.
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   676
            colorMap := colorMap copyTo:numColor.
898
cdf6cc132b53 care for funny number of colors (nColor > (1<<depth))
Claus Gittinger <cg@exept.de>
parents: 819
diff changeset
   677
        ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   678
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   679
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   680
    "/ check for valid compression
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   681
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   682
    compression ~~ 0 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   683
        "/ some compression
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   684
        compression == 1 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   685
            "/ RLE8 - must be depth-8
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   686
            inDepth ~~ 8 ifTrue:[
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   687
                ^ self fileFormatError:'RLE8 compression only supported with depth8 images'.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   688
            ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   689
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   690
        compression == 2 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   691
            "/ RLE4 - must be depth-4
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   692
            inDepth ~~ 4 ifTrue:[
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   693
                ^ self fileFormatError:'RLE4 compression only supported with depth4 images'.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   694
            ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   695
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   696
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   697
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   698
    inPlanes ~~ 1 ifTrue:[
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   699
        ^ 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
   700
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   701
565
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   702
    dataStart notNil ifTrue:[
1754
cc844dc3504e avoid position
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   703
        aStream position1Based:(dataStart + 1).
565
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
   704
    ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   705
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   706
    inDepth == 24 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   707
        bytesPerRow := width * 3
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   708
    ] ifFalse:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   709
        bytesPerRow := width
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   710
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   711
    data := ByteArray uninitializedNew:(height * bytesPerRow).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   712
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   713
    "/ read & possibly decompress
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   714
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   715
    (self loadBMPWidth:width height:height depth:inDepth compression:compression from:aStream into:data) ifFalse:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   716
        ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   717
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   718
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   719
    inDepth == 24 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   720
        photometric := #rgb.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   721
        samplesPerPixel := 3.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   722
        bitsPerSample := #(8 8 8).
1073
1e1450185eb8 fixed r-g-b order (red & blue are swapped in file)
Claus Gittinger <cg@exept.de>
parents: 952
diff changeset
   723
        "/ stupid must swap red & blue bytes
1e1450185eb8 fixed r-g-b order (red & blue are swapped in file)
Claus Gittinger <cg@exept.de>
parents: 952
diff changeset
   724
1e1450185eb8 fixed r-g-b order (red & blue are swapped in file)
Claus Gittinger <cg@exept.de>
parents: 952
diff changeset
   725
        1 to:data size by:3 do:[:i |
1e1450185eb8 fixed r-g-b order (red & blue are swapped in file)
Claus Gittinger <cg@exept.de>
parents: 952
diff changeset
   726
            t := data at:i.
1e1450185eb8 fixed r-g-b order (red & blue are swapped in file)
Claus Gittinger <cg@exept.de>
parents: 952
diff changeset
   727
            data at:i put:(data at:i+2).
1e1450185eb8 fixed r-g-b order (red & blue are swapped in file)
Claus Gittinger <cg@exept.de>
parents: 952
diff changeset
   728
            data at:i+2 put:t
1e1450185eb8 fixed r-g-b order (red & blue are swapped in file)
Claus Gittinger <cg@exept.de>
parents: 952
diff changeset
   729
        ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   730
        ^ self
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   731
    ].
898
cdf6cc132b53 care for funny number of colors (nColor > (1<<depth))
Claus Gittinger <cg@exept.de>
parents: 819
diff changeset
   732
    inDepth == 1 ifTrue:[
cdf6cc132b53 care for funny number of colors (nColor > (1<<depth))
Claus Gittinger <cg@exept.de>
parents: 819
diff changeset
   733
        photometric := #blackIs0.
cdf6cc132b53 care for funny number of colors (nColor > (1<<depth))
Claus Gittinger <cg@exept.de>
parents: 819
diff changeset
   734
        samplesPerPixel := 1.
cdf6cc132b53 care for funny number of colors (nColor > (1<<depth))
Claus Gittinger <cg@exept.de>
parents: 819
diff changeset
   735
        bitsPerSample := #(1).
cdf6cc132b53 care for funny number of colors (nColor > (1<<depth))
Claus Gittinger <cg@exept.de>
parents: 819
diff changeset
   736
        ^ self
cdf6cc132b53 care for funny number of colors (nColor > (1<<depth))
Claus Gittinger <cg@exept.de>
parents: 819
diff changeset
   737
    ].
899
a2676b9f61ba checkin from browser
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
   738
    (inDepth ~~ 8) ifTrue:[
a2676b9f61ba checkin from browser
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
   739
        "/ self halt:'unsupported depth'.
898
cdf6cc132b53 care for funny number of colors (nColor > (1<<depth))
Claus Gittinger <cg@exept.de>
parents: 819
diff changeset
   740
    ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   741
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   742
    photometric := #palette.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   743
    samplesPerPixel := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   744
    bitsPerSample := #(8).
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   745
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   746
    "Modified: / 17.9.1995 / 18:48:46 / claus"
1073
1e1450185eb8 fixed r-g-b order (red & blue are swapped in file)
Claus Gittinger <cg@exept.de>
parents: 952
diff changeset
   747
    "Modified: / 16.9.1998 / 01:09:08 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   748
!
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   749
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   750
fromWindowsICOFile:aFilename 
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   751
    "read an image from a windows ICO file"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   752
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   753
    |reader stream|
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   754
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   755
    stream := self class streamReadingFile:aFilename.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   756
    stream isNil ifTrue:[^ nil].
1790
41f36b5a29c3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
   757
    reader := (self class new) fromWindowsICOStream:stream.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   758
    stream close.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   759
    reader notNil ifTrue:[^ reader image].
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   760
    ^ nil
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   761
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   762
    "
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   763
     Image fromFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'.
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   764
    "
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   765
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   766
    "Modified: 23.4.1996 / 13:10:11 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   767
!
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   768
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   769
fromWindowsICOStream:aStream
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   770
    "read an image from a windows ICO stream"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   771
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   772
    |header inDepth
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   773
     srcIndex dstIndex
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   774
     rawData tmp bytesPerRow nColor cmapSize|
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   775
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   776
    inStream := aStream.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   777
    aStream binary.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   778
3f9277473954 Initial revision
claus
parents:
diff changeset
   779
    "read the header"
3f9277473954 Initial revision
claus
parents:
diff changeset
   780
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   781
    header := ByteArray uninitializedNew:(6 + 16 + 40).
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   782
    aStream nextBytes:(6 + 16 + 40) into:header.
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   783
    width := header at:(6+1).
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   784
    height := header at:(7+1).
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   785
    nColor := header at:(8+1).
430
50b841f4851d commentary
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   786
    "/ reserved := header at:(9+1).
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   787
    "/ nPlanes := header wordAt:(10+1).
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   788
    "/ nBitsPerPel := header wordAt:(12+1).
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   789
    "/ nBytesInResource := header doubleWordAt:(14+1).
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   790
    "/ ordinal := header wordAt:(18+1).
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   791
    "21, 22               ?"
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   792
    "23, ... , 62         ?"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   793
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   794
    inDepth := header at:16r25.
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   795
    "/ mhmh - some depth4 icons seem to have a 0 in the depth field ...
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   796
    inDepth == 0 ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   797
        inDepth := 4
1386
2d02a4fba456 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
   798
    ].
1569
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   799
    (#(4 8) includes:inDepth) ifFalse:[
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   800
        "/ only tested for depth 4/8 images.
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   801
        ^ self fileFormatError:'only depth 4/8 ico-images supported (depth is ' , inDepth printString , ')'.
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   802
"/        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
   803
    ].
1846
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   804
    self reportDimension.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   805
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   806
    "read the colormap"
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   807
    cmapSize := (1 bitShift:inDepth).
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   808
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   809
    colorMap := self
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   810
                readColorMap:cmapSize
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   811
                numBytesPerColor:4
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   812
                from:aStream.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   813
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   814
    "read the data bits"
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   815
3
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   816
    bytesPerRow := width * inDepth + 7 // 8.
1569
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   817
    rawData := ByteArray uninitializedNew:(height * bytesPerRow).
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   818
    aStream nextBytes:(height * bytesPerRow) into:rawData.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   819
3f9277473954 Initial revision
claus
parents:
diff changeset
   820
    "read mask"
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
   821
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   822
"
3f9277473954 Initial revision
claus
parents:
diff changeset
   823
    mask := ByteArray new:(width * height / 8).
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   824
    aStream nextBytes:(width * height / 8) into:mask.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   825
"
3f9277473954 Initial revision
claus
parents:
diff changeset
   826
3f9277473954 Initial revision
claus
parents:
diff changeset
   827
    "stupid: last row first"
3f9277473954 Initial revision
claus
parents:
diff changeset
   828
3
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
   829
    tmp := ByteArray uninitializedNew:(height * bytesPerRow).
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   830
    srcIndex := 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
   831
    dstIndex := (height - 1) * bytesPerRow + 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
   832
    1 to:height do:[:row |
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   833
        tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1)
1569
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   834
                   with:rawData startingAt:srcIndex.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   835
        srcIndex := srcIndex + bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   836
        dstIndex := dstIndex - bytesPerRow.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   837
    ].
1569
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   838
    rawData := tmp.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   839
3f9277473954 Initial revision
claus
parents:
diff changeset
   840
    photometric := #palette.
3f9277473954 Initial revision
claus
parents:
diff changeset
   841
    samplesPerPixel := 1.
298
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   842
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   843
    false ifTrue:[
1569
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   844
        "expand into bytes"
298
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   845
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   846
        data := ByteArray new:(width * height).
1569
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   847
        rawData expandPixels:inDepth width:width height:height
298
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   848
                      into:data mapping:nil.
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   849
        bitsPerSample := #(8).
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   850
    ] ifFalse:[
1569
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   851
        data := rawData.
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   852
        bitsPerSample := (Array with:inDepth).
298
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   853
    ].
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
   854
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   855
    "
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   856
     WindowsIconReader new fromWindowsICOFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   857
    "
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   858
1171
d848c46349ab sorry: only depth4 images are handled.
Claus Gittinger <cg@exept.de>
parents: 1168
diff changeset
   859
    "Modified: / 18.5.1999 / 15:40:00 / cg"
1805
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1790
diff changeset
   860
! !
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1790
diff changeset
   861
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1790
diff changeset
   862
!WindowsIconReader methodsFor:'writing'!
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   863
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   864
save:image onFile:aFileName
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   865
    "save image as BMP file on aFileName.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   866
     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
   867
1168
590e5660f69e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
   868
    aFileName asFilename suffix asLowercase = 'ico' ifTrue:[
590e5660f69e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
   869
"/        (image depth == 4
590e5660f69e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
   870
"/        and:[image width == 32
590e5660f69e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
   871
"/        and:[image height == 32]]) ifTrue:[
590e5660f69e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
   872
            ^ self saveICO:image onFile:aFileName.
590e5660f69e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
   873
"/        ]
590e5660f69e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
   874
    ].
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   875
    self saveBMP:image onFile:aFileName.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   876
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   877
    "Modified: 17.10.1997 / 20:16:53 / cg"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   878
!
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   879
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   880
saveBMP:image onFile:fileName 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   881
    "save image as BMP file on aFileName.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   882
     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
   883
1507
9bae072abf64 fixed bmp saving 24bit image (red & blue channels exchanged)
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
   884
    |depth bhSize biSize biClrUsed biSizeImage bfOffBits rowBytes imgBytesPerRow data srcIndex row t|
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   885
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   886
    depth := image depth.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   887
    width := image width.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   888
    height := image height.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   889
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   890
    (#(1 4 8 24) includes:depth) ifFalse:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   891
        ^ Image cannotRepresentImageSignal 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   892
            raiseWith:image
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   893
            errorString:('BMP format only supports depths 1,4,8 and 24').
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   894
    ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   895
    image mask notNil ifTrue:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   896
        Image informationLostQuerySignal
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   897
            raiseWith:image
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   898
            errorString:('BMP format does not support an imageMask').
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   899
    ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   900
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   901
    bhSize := 14.  "# bytes in file header"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   902
    biSize := 40.  "info header size in bytes" 
1734
290f382d40e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
   903
    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
   904
    bfOffBits := biSize + bhSize + (4*biClrUsed).
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   905
    "/ bmp aligns rows on a longword boundary
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   906
    rowBytes := ((depth min:24) * width + 31 // 32) * 4.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   907
    biSizeImage := height * rowBytes.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   908
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   909
    outStream := fileName asFilename writeStream.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   910
    outStream binary.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   911
    byteOrder := #lsb.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   912
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   913
    "Write the file header"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   914
    self writeShort:19778.  "bfType = BM" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   915
    self writeLong:(bfOffBits + biSizeImage).  "Entire file size in bytes"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   916
    self writeLong:0.  "bfReserved" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   917
    self writeLong:bfOffBits.  "Offset of bitmap data from start of hdr (and file)"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   918
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   919
    "Write the bitmap info header"
1754
cc844dc3504e avoid position
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
   920
    outStream position1Based: bhSize+1.
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   921
    self writeLong:biSize.  "info header size in bytes" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   922
    self writeLong:width.  "biWidth" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   923
    self writeLong:height.  "biHeight" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   924
    self writeShort:1.  "biPlanes" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   925
    self writeShort:(depth min:24).  "biBitCount" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   926
    self writeLong:0.  "biCompression" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   927
    self writeLong:biSizeImage.  "size of image section in bytes"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   928
    self writeLong:2800.  "biXPelsPerMeter" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   929
    self writeLong:2800.  "biYPelsPerMeter" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   930
    self writeLong:biClrUsed.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   931
    self writeLong:0.  "biClrImportant" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   932
    1 to:biClrUsed do:[:i |  "Color map"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   933
        |clr r g b|
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   934
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   935
        clr := image colorFromValue:i-1.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   936
        clr isNil ifTrue:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   937
            r := g := b := 0.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   938
        ] ifFalse:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   939
            r := clr redByte.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   940
            g := clr greenByte.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   941
            b := clr blueByte.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   942
        ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   943
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   944
        "/ put B,G,R
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   945
        outStream nextPut:b.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   946
        outStream nextPut:g.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   947
        outStream nextPut:r.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   948
        outStream nextPut:0.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   949
    ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   950
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   951
    imgBytesPerRow := image bytesPerRow.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   952
    data := image data.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   953
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   954
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   955
    "/ sorry, must extract rows individually
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   956
    "/ (even if alignment is correct),
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   957
    "/ since BMP saves rows bottom-to-top
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   958
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   959
    row := ByteArray new:rowBytes.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   960
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   961
    srcIndex := 1 + (height * imgBytesPerRow).
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   962
    1 to:height do:[:i |
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   963
        srcIndex := srcIndex - imgBytesPerRow.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   964
        row replaceFrom:1 to:imgBytesPerRow with:data startingAt:srcIndex.
1507
9bae072abf64 fixed bmp saving 24bit image (red & blue channels exchanged)
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
   965
        depth >= 24 ifTrue:[
9bae072abf64 fixed bmp saving 24bit image (red & blue channels exchanged)
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
   966
            "/ stupid must swap red & blue bytes
9bae072abf64 fixed bmp saving 24bit image (red & blue channels exchanged)
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
   967
9bae072abf64 fixed bmp saving 24bit image (red & blue channels exchanged)
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
   968
            1 to:row size by:3 do:[:i |
9bae072abf64 fixed bmp saving 24bit image (red & blue channels exchanged)
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
   969
                t := row at:i.
9bae072abf64 fixed bmp saving 24bit image (red & blue channels exchanged)
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
   970
                row at:i put:(row at:i+2).
9bae072abf64 fixed bmp saving 24bit image (red & blue channels exchanged)
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
   971
                row at:i+2 put:t
9bae072abf64 fixed bmp saving 24bit image (red & blue channels exchanged)
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
   972
            ].
9bae072abf64 fixed bmp saving 24bit image (red & blue channels exchanged)
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
   973
        ].
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   974
        outStream nextPutAll:row.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   975
    ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   976
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   977
    outStream close.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   978
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   979
    "
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   980
     |i|
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   981
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   982
     i := Image fromFile:'bitmaps/SBrowser.xbm'.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   983
     WindowsIconReader save:i onFile:'test.bmp'.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   984
    "
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   985
    "
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   986
     |i|
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   987
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   988
     i := Image fromFile:'bitmaps/gifImages/garfield.gif'.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   989
     WindowsIconReader save:i onFile:'test.bmp'.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   990
    "
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   991
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   992
    "Modified: 21.10.1997 / 05:02:02 / cg"
1167
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   993
!
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   994
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   995
saveICO:image onFile:fileName 
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   996
    "save image as ICO file on aFileName.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   997
     Only depth 4 images of size 32x32 can be represented in this format."
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   998
1233
6587cabeab10 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1171
diff changeset
   999
    |depth biSizeImage rowBytes imgBytesPerRow data srcIndex row|
1167
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1000
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1001
    depth := image depth.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1002
    width := image width.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1003
    height := image height.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1004
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1005
    depth ~~ 4 ifTrue:[
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1006
        ^ Image cannotRepresentImageSignal 
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1007
            raiseWith:image
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1008
            errorString:('ICO format only supports depths 4').
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1009
    ].
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1010
    (width ~~ 32 or:[height ~~ 32]) ifTrue:[
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1011
        ^ Image cannotRepresentImageSignal 
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1012
            raiseWith:image
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1013
            errorString:('ICO format (currently) only supports 32x32 bitmaps').
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1014
    ].
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1015
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1016
    "/ align rows on a longword boundary
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1017
    rowBytes := (depth * width + 31 // 32) * 4.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1018
    biSizeImage := height * rowBytes.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1019
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1020
    outStream := fileName asFilename writeStream.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1021
    outStream binary.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1022
    byteOrder := #lsb.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1023
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1024
    "Write the file header"
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1025
    outStream nextPutAll:#[0 0 1 0].    "/ ICO magic
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1026
    self writeShort:1.             "/ # of images in file
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1027
    outStream nextPut:image width.      "/
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1028
    outStream nextPut:image height.     "/
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1029
    outStream nextPut:(1 bitShift:image depth). "/ # of colors
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1030
    outStream nextPutAll:#[0 0 0 0 0 ]. "/ reserved
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1031
    self writeLong:16rE802.              "/ size pixels
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1032
    self writeLong:16r26.                "/ offset in file
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1033
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1034
    "/ 40 bytes - unknown format
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1035
    outStream nextPutAll:(ByteArray new:40).
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1036
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1037
    "/ 16-entry RGB map
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1038
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1039
    1 to:16 do:[:i |  "Color map"
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1040
        |clr r g b|
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1041
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1042
        clr := image colorFromValue:i-1.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1043
        clr isNil ifTrue:[
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1044
            r := g := b := 0.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1045
        ] ifFalse:[
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1046
            r := clr redByte.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1047
            g := clr greenByte.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1048
            b := clr blueByte.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1049
        ].
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1050
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1051
        "/ put B,G,R
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1052
        outStream nextPut:b.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1053
        outStream nextPut:g.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1054
        outStream nextPut:r.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1055
        outStream nextPut:0.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1056
    ].
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1057
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1058
    imgBytesPerRow := image bytesPerRow.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1059
    data := image data.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1060
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1061
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1062
    "/ sorry, must extract rows individually
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1063
    "/ (even if alignment is correct),
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1064
    "/ since ICO saves rows bottom-to-top
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1065
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1066
    row := ByteArray new:rowBytes.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1067
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1068
    srcIndex := 1 + (height * imgBytesPerRow).
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1069
    1 to:height do:[:i |
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1070
        srcIndex := srcIndex - imgBytesPerRow.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1071
        row replaceFrom:1 to:imgBytesPerRow with:data startingAt:srcIndex.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1072
        outStream nextPutAll:row.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1073
    ].
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1074
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1075
    "/ the mask ...
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1076
    image mask isNil ifTrue:[
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1077
        outStream next:128 put:16rFF
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1078
    ] ifFalse:[
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1079
        imgBytesPerRow := image mask bytesPerRow.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1080
        data := image mask data.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1081
        row := ByteArray new:4.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1082
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1083
        srcIndex := 1 + (height * imgBytesPerRow).
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1084
        1 to:height do:[:i |
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1085
            srcIndex := srcIndex - imgBytesPerRow.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1086
            row replaceFrom:1 to:imgBytesPerRow with:data startingAt:srcIndex.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1087
            outStream nextPutAll:row.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1088
        ].
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1089
    ].
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1090
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1091
    outStream close.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1092
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1093
    "
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1094
     |i|
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1095
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1096
     i := Image fromFile:'bitmaps/xpmBitmaps/SmalltalkX_clr.xpm'.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1097
     i := Depth4Image fromImage:i.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1098
     i := i magnifiedTo:32@32.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1099
     WindowsIconReader new saveICO:i onFile:'test.ico'.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1100
    "
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1101
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1102
    "Modified: 21.10.1997 / 05:02:02 / cg"
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1103
! !
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1104
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1105
!WindowsIconReader class methodsFor:'documentation'!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1106
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1107
version
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1108
    ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.60 2005-02-02 10:44:31 cg Exp $'
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1109
! !
1734
290f382d40e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  1110
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1111
WindowsIconReader initialize!