WindowsIconReader.st
author Claus Gittinger <cg@exept.de>
Tue, 02 Dec 2008 22:02:23 +0100
changeset 2571 ae60c0d0452d
parent 2333 a93f1f5392bd
child 2578 7d49dc8ecb63
permissions -rw-r--r--
many fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
3f9277473954 Initial revision
claus
parents:
diff changeset
     1
"
3f9277473954 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
     3
	      All Rights Reserved
0
3f9277473954 Initial revision
claus
parents:
diff changeset
     4
3f9277473954 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
3f9277473954 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
3f9277473954 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
3f9277473954 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
3f9277473954 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
3f9277473954 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
3f9277473954 Initial revision
claus
parents:
diff changeset
    11
"
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    12
"{ Package: 'stx:libview2' }"
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    13
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    14
ImageReader subclass:#WindowsIconReader
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
    15
	instanceVariableNames:'compression inDepth'
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    16
	classVariableNames:''
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
    17
	poolDictionaries:''
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
    18
	category:'Graphics-Images-Readers'
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    19
!
3f9277473954 Initial revision
claus
parents:
diff changeset
    20
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    21
!WindowsIconReader class methodsFor:'documentation'!
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    22
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    23
copyright
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    24
"
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    25
 COPYRIGHT (c) 1993 by Claus Gittinger
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
    26
	      All Rights Reserved
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    27
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    28
 This software is furnished under a license and may be used
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    29
 only in accordance with the terms of that license and with the
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    31
 be provided or otherwise made available to, or used by, any
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    32
 other person.  No title to or ownership of the software is
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    33
 hereby transferred.
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    34
"
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    35
!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
    36
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    37
documentation
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    38
"
32
6bdcb6da4d4f *** empty log message ***
claus
parents: 28
diff changeset
    39
    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
    40
    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
    41
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    42
    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
    43
    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
    44
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    45
    The class name *IconReader is a bad, historic choice - it ws originally
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    46
    written to read icons only, but evolved over time and it should now be also
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    47
    capapble of reading bmp and cursor files.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    48
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    49
    [See also:]
234
b6352d13e792 xrefs in documentation
Claus Gittinger <cg@exept.de>
parents: 211
diff changeset
    50
        Image Form Icon
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    51
        BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader 
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    52
        ST80FormReader SunRasterReader TargaReader TIFFReader  
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    53
        XBMReader XPMReader XWDReader 
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
    54
"
1385
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    55
!
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    56
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    57
fileFormatDescription
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    58
"
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    59
    Information from http://www.daubnet.com/formats/BMP.html - no Warranty.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    60
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    61
          Name           Size                Description
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    62
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    63
      Header            14 bytes            Windows Structure: BITMAPFILEHEADER
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    64
          Signature      2 bytes             'BM'
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    65
          FileSize       4 bytes             File size in bytes
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    66
          reserved       4 bytes             unused (=0)
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    67
          DataOffset     4 bytes             File offset to Raster Data
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    68
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    69
      InfoHeader        40 bytes            Windows Structure: BITMAPINFOHEADER
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    70
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    71
          Size           4 bytes             Size of InfoHeader =40 
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    72
          Width          4 bytes             Bitmap Width
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    73
          Height         4 bytes             Bitmap Height
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    74
          Planes         2 bytes             Number of Planes (=1)
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    75
          BitCount       2 bytes             Bits per Pixel   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    76
                                             1 = monochrome palette. NumColors = 1   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    77
                                             4 = 4bit palletized. NumColors = 16   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    78
                                             8 = 8bit palletized. NumColors = 256  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    79
                                             16 = 16bit RGB. NumColors = 65536 (?)  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    80
                                             24 = 24bit RGB. NumColors = 16M
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    81
          Compression    4 bytes             Type of Compression   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    82
                                             0 = BI_RGB   no compression   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    83
                                             1 = BI_RLE8 8bit RLE encoding   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    84
                                             2 = BI_RLE4 4bit RLE encoding
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    85
          ImageSize      4 bytes             (compressed) Size of Image  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    86
                                             It is valid to set this =0 if Compression = 0
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    87
          XpixelsPerM    4 bytes             horizontal resolution: Pixels/meter
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    88
          YpixelsPerM    4 bytes             vertical resolution: Pixels/meter
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    89
          ColorsUsed     4 bytes             Number of actually used colors
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    90
          ColorsImportant
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    91
                         4 bytes             Number of important colors  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    92
                                             0 = all
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    93
       ColorTable        4 * NumColors bytes
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    94
                                             present only if Info.BitsPerPixel <= 8   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    95
                                             colors should be ordered by importance
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    96
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    97
            Red           1 byte              Red intensity
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    98
            Green         1 byte              Green intensity
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
    99
            Blue          1 byte              Blue intensity
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   100
            reserved      1 byte             unused (=0)
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   101
          repeated NumColors times
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   102
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   103
       Raster Data      Info.ImageSize bytes     The pixel data
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   104
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   105
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   106
Raster Data encoding:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   107
       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
   108
       All of them share the following:  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   109
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   110
       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
   111
       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
   112
       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
   113
       For images with more than 256 colors there is no color table. 
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   114
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   115
Raster Data encoding for 1bit / black & white images:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   116
       BitCount = 1 Compression = 0  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   117
       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
   118
       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
   119
       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
   120
       32bit boundary (This can be up to 31 zeros/pixels!!)                                                                 
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   121
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   122
Raster Data encoding for 4bit / 16 color images:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   123
       BitCount = 4 Compression = 0  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   124
       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
   125
       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
   126
       will result in up to 28 zeros = 7 'wasted pixels'.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   127
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   128
Raster Data encoding for 8bit / 256 color images:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   129
       BitCount = 8 Compression = 0  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   130
       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
   131
       result in up to 3 bytes of zeros = 3 'wasted pixels'.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   132
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   133
Raster Data encoding for 16bit / hicolor images:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   134
       BitCount = 16 Compression = 0  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   135
       Every 2bytes / 16bit holds 1 pixel.   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   136
       <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
   137
       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
   138
       boundary will result in up to 2 zero bytes.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   139
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   140
Raster Data encoding for 24bit / truecolor images:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   141
       BitCount = 24 Compression = 0  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   142
       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
   143
       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
   144
       zero padding necessary.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   145
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   146
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   147
Raster Data compression for 4bit / 16 color images:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   148
       BitCount = 4 Compression = 2  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   149
       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
   150
       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
   151
       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
   152
       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
   153
       either two zero bytes or none.   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   154
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   155
        n (byte 1) c (Byte 2)                                       Description
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   156
        >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
   157
                            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
   158
                            pixels of color c
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   159
        0         0        End-of-line
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   160
        0         1        End-of-Bitmap
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   161
        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
   162
                            skipped pixels should get a color zero.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   163
        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
   164
                            bits of zeros follow, to put the file/memory pointer on a 16bit boundary again.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   165
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   166
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   167
                                      Example for 4bit RLE
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   168
        Compressed Data                           Expanded data
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   169
        03 04              0 4 0
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   170
        05 06              0 6 0 6 0
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   171
        00 06 45 56 67 00  4 5 5 6 6 7
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   172
        04 78              7 8 7 8
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   173
        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
   174
        00 00              End-of-line
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   175
        09 1E              1 E 1 E 1 E 1 E 1
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   176
        00 01              EndofBitmap
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   177
        00 00              Zero padding for 32bit boundary
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   178
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   179
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   180
Raster Data compression for 8bit / 256 color images:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   181
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   182
       BitCount = 8 Compression = 1  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   183
       The pixel data is stored in 2bytes / 16bit chunks.  The first of these specifies the number of consecutive pixels with the
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   184
       same 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
   185
       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
   186
       either two zero bytes or none.   
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   187
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   188
        n (byte 1)   c (Byte 2)                                    Description
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   189
        >0       any        n pixels of color number c
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   190
        0        0          End-of-line
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   191
        0        1          End Of Bitmap
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   192
        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
   193
                            skipped pixels should get a color zero.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   194
        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
   195
                            follows, if c is odd, putting the file/memory pointer on a 16bit boundary again.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   196
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   197
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   198
                                      Example for 8bit RLE
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   199
        Compressed Data                           Expanded data
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   200
        03 04              04 04 04
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   201
        05 06              06 06 06 06 06
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   202
        00 03 45 56 67 00  45 56 67
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   203
        02 78              78 78
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   204
        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
   205
        00 00              End-of-line
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   206
        09 1E              1E 1E 1E 1E 1E 1E 1E 1E 1E
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   207
        00 01              End-of-bitmap
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   208
        00 00              Zero padding for 32bit boundary
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   209
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
Portability:
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   214
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   215
       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
   216
       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
   217
       16bit BMPs have been introduced to Windows after the others, still puzzling many applications.
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   218
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   219
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   220
Trademarks, Patents and Royalties
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   221
       To my knowledge: None.  
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   222
"
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   223
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   224
! !
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   225
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
   226
!WindowsIconReader class methodsFor:'initialization'!
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
   227
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
   228
initialize
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   229
    "tell Image-class, that a new fileReader is present
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 387
diff changeset
   230
     for the '.bmp' and '.ico' extensions."
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   231
647
6f26c76aa0c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   232
    MIMETypes defineImageType:'image/x-MS-bitmap' suffix:'bmp' reader:self.
6f26c76aa0c9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
   233
    MIMETypes defineImageType:nil                 suffix:'ico' reader:self.
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   234
398
aef700d15416 new suffix-table
Claus Gittinger <cg@exept.de>
parents: 387
diff changeset
   235
    "Modified: 1.2.1997 / 15:03:59 / cg"
28
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
   236
! !
8daff0234d2e *** empty log message ***
claus
parents: 24
diff changeset
   237
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   238
!WindowsIconReader class methodsFor:'image support'!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   239
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   240
loadBMPWidth:w height:h bytesPerPixel:bpp compression:c from:aStream into:data
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   241
    |buff idx fileBytesPerRow imgBytesPerRow align|
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   242
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   243
    align := 4.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   244
    c == 0 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   245
        imgBytesPerRow := w * bpp.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   246
        fileBytesPerRow := imgBytesPerRow.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   247
        (fileBytesPerRow bitAnd:(align-1)) ~~ 0 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   248
            fileBytesPerRow := (fileBytesPerRow bitAnd:((align-1) bitInvert)) + align.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   249
        ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   250
        "/
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   251
        "/ stupid - last row comes first
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   252
        "/
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   253
        idx := imgBytesPerRow * (h - 1) + 1.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   254
        buff := ByteArray uninitializedNew:fileBytesPerRow.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   255
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   256
        1 to:h do:[:row |
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   257
            (aStream nextBytes:fileBytesPerRow into:buff) ~~ fileBytesPerRow ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   258
                ^ false
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   259
            ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   260
            data replaceFrom:idx to:idx+imgBytesPerRow-1 with:buff.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   261
            idx := idx - imgBytesPerRow.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   262
        ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   263
        ^ true
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   264
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   265
    ^ false.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   266
! !
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   267
102
claus
parents: 99
diff changeset
   268
!WindowsIconReader class methodsFor:'testing'!
claus
parents: 99
diff changeset
   269
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   270
canRepresent:anImage
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   271
    "return true, if anImage can be represented in my file format.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   272
     BMP supports depth 1,4,8 and 24."
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   273
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   274
    ^ (#(1 4 8 24) includes:anImage depth)
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   275
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   276
    "Created: 17.10.1997 / 20:18:23 / cg"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   277
!
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   278
102
claus
parents: 99
diff changeset
   279
isValidImageFile:aFileName
claus
parents: 99
diff changeset
   280
    "return true, if aFileName contains a valid windows bitmap-file image"
claus
parents: 99
diff changeset
   281
claus
parents: 99
diff changeset
   282
    |inStream header ok|
claus
parents: 99
diff changeset
   283
claus
parents: 99
diff changeset
   284
    inStream := self streamReadingFile:aFileName.
claus
parents: 99
diff changeset
   285
    inStream isNil ifTrue:[^ false].
claus
parents: 99
diff changeset
   286
claus
parents: 99
diff changeset
   287
    inStream binary.
104
claus
parents: 103
diff changeset
   288
    ok := false.
692
e6af4c70e066 size is going to be eliminated from the stream
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
   289
    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
   290
        header := ByteArray uninitializedNew:4.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   291
        inStream nextBytes:4 into:header.
102
claus
parents: 99
diff changeset
   292
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   293
        (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
   294
            ok := true.
104
claus
parents: 103
diff changeset
   295
"/            '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
   296
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   297
        (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
   298
            ok := true.
104
claus
parents: 103
diff changeset
   299
"/            '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
   300
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   301
        (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
   302
            ok := true.
104
claus
parents: 103
diff changeset
   303
"/            '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
   304
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   305
        (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
   306
            ok := true.
104
claus
parents: 103
diff changeset
   307
"/            '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
   308
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   309
        (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
   310
            ok := true.
104
claus
parents: 103
diff changeset
   311
"/            '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
   312
        ].
102
claus
parents: 99
diff changeset
   313
    ].
104
claus
parents: 103
diff changeset
   314
    inStream close.
claus
parents: 103
diff changeset
   315
    ^ ok
102
claus
parents: 99
diff changeset
   316
claus
parents: 99
diff changeset
   317
    "
claus
parents: 99
diff changeset
   318
     WindowsIconReader isValidImageFile:'/phys/clam2/LocalLibrary/Images/OS2_icons/dos.ico'
claus
parents: 99
diff changeset
   319
    "
claus
parents: 99
diff changeset
   320
claus
parents: 99
diff changeset
   321
    "Created: 17.9.1995 / 17:14:20 / claus"
claus
parents: 99
diff changeset
   322
! !
claus
parents: 99
diff changeset
   323
103
claus
parents: 102
diff changeset
   324
!WindowsIconReader methodsFor:'private'!
claus
parents: 102
diff changeset
   325
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   326
loadBMP1From:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   327
    "load bmp-1 bit per pixel imagedata."
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   328
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   329
    compression == 0 ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   330
        ^ false
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   331
    ].            
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   332
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   333
    ^ self loadUncompressedFrom:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   334
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   335
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   336
loadBMP2From:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   337
    "load bmp-2 bit per pixel imagedata."
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   338
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   339
    compression == 0 ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   340
        ^ false
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   341
    ].            
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   342
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   343
    ^ self loadUncompressedFrom:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   344
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   345
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   346
loadBMP4From:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   347
    "load bmp-4 bit per pixel imagedata."
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   348
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   349
    compression == 0 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   350
        ^ self loadUncompressedFrom:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   351
    ].            
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   352
    compression == 2 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   353
        ^ self loadRLECompressedBMP4From:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   354
    ].            
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   355
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   356
    ^ false
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   357
!
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   358
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   359
loadBMP4to8Width:width height:height from:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   360
    "load bmp-4 bit per pixel imagedata. A helper for BMP image reader.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   361
     Primitive c function for speed"
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   362
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   363
    |f bytes offset|
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   364
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   365
    aStream isExternalStream ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   366
        f := aStream filePointer.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   367
        f isNil ifTrue:[^ false].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   368
    ] ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   369
        aStream isInternalByteStream ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   370
            bytes := aStream collection.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   371
            bytes isNil ifTrue:[^ false].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   372
            offset := aStream position.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   373
        ] ifFalse:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   374
            ^ false
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   375
        ]
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   376
    ].
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   377
%{
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   378
#define GETC(fp, cp)    (fp ? getc(fp) : *cp++)
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   379
#define FERROR(fp)      (fp && ferror(fp))
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   380
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   381
    FILE *__fp = NULL;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   382
    char *__cp = NULL;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   383
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   384
    if (f != nil) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   385
        __fp = __FILEVal(f);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   386
    } else {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   387
        __cp = __stringVal(bytes);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   388
        __cp += __intVal(offset);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   389
    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   390
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   391
    if (! (__bothSmallInteger(width, height)
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   392
           && __isByteArray(aByteArray))) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   393
        RETURN (false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   394
    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   395
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   396
{
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   397
    int w = __intVal(width);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   398
    int h = __intVal(height);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   399
    int comp = __intVal(__INST(compression));
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   400
    unsigned char *dest = __ByteArrayInstPtr(aByteArray)->ba_element;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   401
    int szDest = __byteArraySize(aByteArray);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   402
    int   i, j, c, c1, nibnum, padw, x, y;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   403
    unsigned char *pp;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   404
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   405
    c = c1 = 0;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   406
    if (comp == 0) { /* read uncompressed data */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   407
        padw = ((w + 7)/8) * 8;  /* 'w', padded to be a multiple of 8pix (32bits) */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   408
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   409
        for (i=h-1; i>=0; i--) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   410
            pp = dest + (i * w);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   411
            for (j=nibnum=0; j<padw; j++,nibnum++) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   412
                if ((nibnum&1) == 0) { /* read the next byte */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   413
                    c = GETC(__fp, __cp);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   414
    console_printf("\nch: %02x ", c);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   415
                    if (c == EOF) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   416
                        if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   417
                            console_fprintf(stderr, "ImageReader [warning]: premature EOF\n");
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   418
                        }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   419
                        RETURN (false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   420
                    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   421
                    nibnum = 0;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   422
                }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   423
                if (j<w) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   424
                    if (pp >= (dest+szDest)) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   425
                        if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   426
                            console_fprintf(stderr, "ImageReader [warning]: BMP outBuffer overrun\n");
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   427
                        }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   428
                        { RETURN (false) };
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   429
                    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   430
                    *pp++ = (c & 0xF0) >> 4;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   431
console_printf("%d ", pp[-1]);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   432
                    c <<= 4;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   433
                }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   434
            }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   435
            if (FERROR(__fp)) { RETURN (false) };
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   436
        }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   437
        RETURN (true);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   438
    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   439
    if (comp == 2) {  /* read RLE4 compressed data */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   440
        x = y = 0;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   441
        pp = dest + x + (h-y-1)*w;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   442
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   443
        while (y<h) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   444
            c = GETC(__fp, __cp); if (c == EOF) { RETURN (false); }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   445
            if (c) {                                   /* encoded mode */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   446
                c &= 0xFF;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   447
                c1 = GETC(__fp, __cp); if (c1 == EOF) { RETURN (false); }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   448
                for (i=0; i<c; i++,x++,pp++) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   449
                    if (pp >= (dest+szDest)) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   450
                        if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   451
                            console_fprintf(stderr, "ImageReader [warning]: BMP outBuffer overrun\n");
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   452
                        }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   453
                        return 0;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   454
                    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   455
                    *pp = (i&1) ? (c1 & 0x0f) : ((c1>>4)&0x0f);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   456
                }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   457
            } else {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   458
                /* c==0x00  :  escape codes */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   459
                c = GETC(__fp, __cp); if (c == EOF) { RETURN (false); }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   460
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   461
                if (c == 0x00) {                    /* end of line */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   462
                    x=0;  y++;  pp = dest + x + (h-y-1)*w;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   463
                } else
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   464
                    if (c == 0x01) break;               /* end of pic8 */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   465
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   466
                    else if (c == 0x02) {                /* delta */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   467
                        c = GETC(__fp, __cp); if (c == EOF) { RETURN (false); }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   468
                        x += (c & 0xFF);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   469
                        c = GETC(__fp, __cp); if (c == EOF) { RETURN (false); }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   470
                        y += (c & 0xFF);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   471
                        pp = dest + x + (h-y-1)*w;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   472
                    } else {                        /* absolute mode */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   473
                        c &= 0xFF;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   474
                        for (i=0; i<c; i++, x++, pp++) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   475
                            if ((i&1) == 0) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   476
                                c1 = GETC(__fp, __cp); if (c1 == EOF) { RETURN (false); }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   477
                            }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   478
                            if (pp >= (dest+szDest)) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   479
                                if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   480
                                    console_fprintf(stderr, "ImageReader [warning]: BMP outBuffer overrun\n");
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   481
                                }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   482
                                return 0;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   483
                            }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   484
                            *pp = (i&1) ? (c1 & 0x0f) : ((c1>>4)&0x0f);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   485
                        }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   486
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   487
                        if (((c&3)==1) || ((c&3)==2)) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   488
                            GETC(__fp, __cp);  /* read pad byte */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   489
                        }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   490
                    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   491
            }  /* escape processing */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   492
            if (FERROR(__fp)) RETURN (false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   493
        }  /* while */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   494
        RETURN (true);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   495
    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   496
}
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   497
%}.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   498
    ^ false
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   499
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   500
    "Modified: 22.4.1996 / 19:14:32 / cg"
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   501
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   502
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   503
loadBMP8Width:width height:height from:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   504
    "load bmp-4 bit per pixel imagedata. A helper for BMP image reader.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   505
     Primitive c function for speed"
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   506
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   507
    |f bytes offset|
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   508
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   509
    aStream isExternalStream ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   510
        f := aStream filePointer.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   511
        f isNil ifTrue:[^ false].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   512
    ] ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   513
        aStream isInternalByteStream ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   514
            bytes := aStream collection.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   515
            bytes isNil ifTrue:[^ false].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   516
            offset := aStream position.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   517
        ] ifFalse:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   518
            ^ false
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   519
        ]
103
claus
parents: 102
diff changeset
   520
    ].
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   521
%{
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   522
#define GETC(fp, cp)    (fp ? getc(fp) : *cp++)
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   523
#define FERROR(fp)      (fp && ferror(fp))
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   524
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   525
    FILE *__fp = NULL;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   526
    char *__cp = NULL;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   527
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   528
    if (f != nil) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   529
        __fp = __FILEVal(f);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   530
    } else {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   531
        __cp = __stringVal(bytes);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   532
        __cp += __intVal(offset);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   533
    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   534
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   535
    if (! (__bothSmallInteger(width, height)
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   536
           && __isByteArray(aByteArray))) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   537
        RETURN (false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   538
    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   539
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   540
{
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   541
    int w = __intVal(width);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   542
    int h = __intVal(height);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   543
    int comp = __intVal(__INST(compression));
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   544
    unsigned char *dest = __ByteArrayInstPtr(aByteArray)->ba_element;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   545
    int szDest = __byteArraySize(aByteArray);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   546
    int   i,j,c,c1,padw,x,y;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   547
    unsigned char *pp;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   548
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   549
    if (comp == 0) {   /* uncompressed data */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   550
        padw = ((w + 3)/4) * 4;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   551
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   552
        for (i=h-1; i>=0; i--) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   553
            pp = dest + (i * w);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   554
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   555
            for (j=0; j<padw; j++) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   556
                c = GETC(__fp, __cp);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   557
                if (c==EOF) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   558
                    if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   559
                        console_fprintf(stderr, "ImageReader [warning]: BMP premature EOF [%d]\n", __LINE__);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   560
                        console_fprintf(stderr, "h=%d i=%d w=%d j=%d padw=%d\n", h, i, w, j, padw);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   561
                    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   562
                    RETURN(false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   563
                }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   564
                if (j<w) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   565
                    if (pp >= (dest+szDest)) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   566
                        if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   567
                            console_fprintf(stderr, "ImageReader [warning]: BMP outBuffer overrun\n");
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   568
                        }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   569
                        RETURN(false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   570
                    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   571
                    *pp++ = c;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   572
                }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   573
            }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   574
            if (FERROR(__fp)) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   575
                if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   576
                    console_fprintf(stderr, "ImageReader [warning]: BMP ferror set\n");
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   577
                }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   578
                RETURN(false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   579
            }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   580
        }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   581
        if (FERROR(__fp)) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   582
            if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   583
                console_fprintf(stderr, "ImageReader [warning]: BMP ferror set at end\n");
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   584
            }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   585
            RETURN(false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   586
        }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   587
        RETURN(true);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   588
    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   589
    if (comp == 1) {  /* RLE8 compressed */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   590
        x = y = 0;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   591
        pp = dest + x + (h-y-1)*w;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   592
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   593
        while (y<h) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   594
            c = GETC(__fp, __cp);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   595
            if (c == EOF) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   596
                if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   597
                    console_fprintf(stderr, "ImageReader [warning]: BMP/RLE8 premature EOF [%d]\n", __LINE__);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   598
                }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   599
                RETURN(false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   600
            }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   601
            if (c) {                                   /* encoded mode */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   602
                c1 = GETC(__fp, __cp);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   603
                if (c1 == EOF) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   604
                    if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   605
                        console_fprintf(stderr, "ImageReader [warning]: BMP/RLE8 premature EOF [%d]\n", __LINE__);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   606
                    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   607
                    RETURN(false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   608
                }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   609
                c &= 0xFF;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   610
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   611
                for (i=0; i<c; i++,x++,pp++) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   612
                    if (pp >= (dest+szDest)) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   613
                        if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   614
                            console_fprintf(stderr, "ImageReader [warning]: BMP/RLE8 outBuffer overrun\n");
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   615
                        }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   616
                        RETURN(false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   617
                    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   618
                    *pp = c1;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   619
                }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   620
            } else {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   621
                /* c==0x00  :  escape codes */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   622
                c = GETC(__fp, __cp);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   623
                if (c == EOF) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   624
                    if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   625
                        console_fprintf(stderr, "ImageReader [warning]: BMP/RLE8 premature EOF [%d]\n", __LINE__);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   626
                    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   627
                    RETURN(false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   628
                }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   629
                if (c == 0x00) {                    /* end of line */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   630
                    x=0;  y++;  pp = dest + x + (h-y-1)*w;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   631
                } else
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   632
                    if (c == 0x01) break;               /* end of pic8 */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   633
                    else if (c == 0x02) {               /* delta */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   634
                        c = GETC(__fp, __cp);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   635
                        if (c == EOF) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   636
                            if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   637
                                console_fprintf(stderr, "ImageReader [warning]: BMP/RLE8 premature EOF [%d]\n", __LINE__);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   638
                            }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   639
                            RETURN(false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   640
                        }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   641
                        x += (c & 0xFF);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   642
                        c = GETC(__fp, __cp);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   643
                        if (c == EOF) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   644
                            if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   645
                                console_fprintf(stderr, "ImageReader [warning]: BMP/RLE8 premature EOF [%d]\n", __LINE__);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   646
                            }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   647
                            RETURN(false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   648
                        }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   649
                        y += (c & 0xFF);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   650
                        pp = dest + x + (h-y-1)*w;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   651
                    } else {                            /* absolute mode */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   652
                        c &= 0xFF;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   653
                        for (i=0; i<c; i++, x++, pp++) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   654
                            c1 = GETC(__fp, __cp);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   655
                            if (c1 == EOF) { RETURN(false); }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   656
                            if (pp >= (dest+szDest)) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   657
                                if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   658
                                    console_fprintf(stderr, "ImageReader [warning]: BMP/RLE8 outBuffer overrun\n");
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   659
                                }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   660
                                RETURN(false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   661
                            }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   662
                            *pp = c1;
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   663
                        }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   664
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   665
                        if (c & 1) GETC(__fp, __cp);  /* odd length run: read an extra pad byte */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   666
                    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   667
            }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   668
            if (FERROR(__fp)) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   669
                if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   670
                    console_fprintf(stderr, "ImageReader [warning]: BMP/RLE8 ferror set\n");
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   671
                }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   672
                RETURN(false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   673
            }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   674
        }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   675
        if (FERROR(__fp)) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   676
            if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   677
                console_fprintf(stderr, "ImageReader [warning]: BMP/RLE8 ferror set at end\n");
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   678
            }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   679
            RETURN(false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   680
        }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   681
        RETURN(true);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   682
    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   683
    if (@global(InfoPrinting) == true) {
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   684
        console_fprintf(stderr, "ImageReader [warning]: BMP unhandled compression: %d\n", comp);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   685
    }
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   686
    RETURN(false);
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   687
}
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   688
%}.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   689
    ^ true
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   690
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   691
    "Modified: 22.4.1996 / 19:14:32 / cg"
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   692
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   693
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   694
loadBMPWidth:w height:h bytesPerPixel:bpp from:aStream into:data
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   695
    |buff idx fileBytesPerRow imgBytesPerRow align|
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   696
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   697
    align := 4.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   698
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   699
    compression == 0 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   700
        imgBytesPerRow := w * bpp.
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   701
        fileBytesPerRow := imgBytesPerRow.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   702
        (fileBytesPerRow bitAnd:(align-1)) ~~ 0 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   703
            fileBytesPerRow := (fileBytesPerRow bitAnd:((align-1) bitInvert)) + align.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   704
        ].
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   705
        "/
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   706
        "/ stupid - last row comes first
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   707
        "/
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   708
        idx := imgBytesPerRow * (h - 1) + 1.
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   709
        buff := ByteArray uninitializedNew:fileBytesPerRow.
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   710
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   711
        1 to:h do:[:row |
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   712
            (aStream nextBytes:fileBytesPerRow into:buff) ~~ fileBytesPerRow ifTrue:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   713
                ^ false
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   714
            ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   715
            data replaceFrom:idx to:idx+imgBytesPerRow-1 with:buff.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   716
            idx := idx - imgBytesPerRow.
172
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
        ^ true
160
ee4d64b12c94 handle depth 24 rgb BMP files
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   719
    ].
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   720
    ^ false.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   721
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   722
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   723
loadBMPWidth:w height:h depth:d from:aStream into:data
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   724
    "helper: load a BMP image"
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   725
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   726
    d == 8 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   727
        compression == 0 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   728
            ^ self loadUncompressedFrom:aStream into:data.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   729
        ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   730
        compression == 1 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   731
            ^ self loadRLECompressedBMP8From:aStream into:data.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   732
        ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   733
self halt.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   734
        ^ false
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   735
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   736
    d == 4 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   737
        ^ self loadBMP4From:aStream into:data
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   738
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   739
    d == 2 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   740
        ^ self loadBMP2From:aStream into:data
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   741
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   742
    d == 1 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   743
        ^ self loadBMP1From:aStream into:data
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   744
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   745
    ((d == 16) 
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   746
    or:[ (d == 24) 
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   747
    or:[ (d == 32) ]]) ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   748
        (self loadBMPWidth:w height:h bytesPerPixel:(d // 8) from:aStream into:data) ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   749
            ^ false
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   750
        ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   751
        inDepth == 16 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   752
            "/ Depth16Image keeps its data MSB (sigh); here they come LSB.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   753
            data swapBytes.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   754
        ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   755
        inDepth == 24 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   756
            "/ Depth24Image keeps its data r/g/b; BMP has it b/g/r (sigh)
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   757
            self swapBytesFromRGB_to_BGR.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   758
        ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   759
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   760
        ^ true
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   761
    ].
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   762
    ^ false
103
claus
parents: 102
diff changeset
   763
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   764
    "Created: / 17.9.1995 / 18:48:11 / claus"
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   765
    "Modified: / 3.2.1998 / 20:21:16 / cg"
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   766
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   767
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   768
loadRLECompressedBMP8From:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   769
    "load bmp-8 bit per pixel imagedata"
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   770
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   771
    |bytesPerRowInData x y dstIndex lineStartIndex cnt clr code n|
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   772
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   773
    bytesPerRowInData := self bytesPerRow.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   774
    x := 0.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   775
    y := height - 1.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   776
    lineStartIndex := (y * bytesPerRowInData) + 1.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   777
    dstIndex := lineStartIndex.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   778
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   779
    [ y < height ] whileTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   780
        cnt := aStream nextByte.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   781
        clr := aStream nextByte.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   782
        cnt ~~ 0 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   783
            aByteArray from:dstIndex to:dstIndex+cnt-1 put:clr.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   784
            x := x + cnt.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   785
            dstIndex := dstIndex + cnt.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   786
        ] ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   787
            "/ cnt == 0: escape codes */
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   788
            code := clr.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   789
            code == 0 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   790
                "/ end of line
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   791
                x := 0.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   792
                y := y - 1.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   793
                lineStartIndex := lineStartIndex - bytesPerRowInData.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   794
                dstIndex := lineStartIndex.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   795
            ] ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   796
                code == 1 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   797
                    "/ end of pic
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   798
                    ^ true
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   799
                ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   800
                code == 2 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   801
                    "/ delta
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   802
                    x := x + aStream nextSignedByte.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   803
                    y := y - aStream nextSignedByte.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   804
                    lineStartIndex := (y * bytesPerRowInData) + 1.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   805
                    dstIndex := lineStartIndex + x.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   806
                ] ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   807
                    "/ absolute; cnt pixels coming
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   808
                    cnt := code.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   809
                    n := aStream nextBytes:cnt into:aByteArray startingAt:dstIndex.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   810
                    n ~~ cnt ifTrue:[self halt. ^ false].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   811
                    x := x + cnt.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   812
                    dstIndex := dstIndex + cnt.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   813
                    "/ odd count - padd
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   814
                    cnt odd ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   815
                        aStream skip:1.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   816
                    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   817
                ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   818
            ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   819
        ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   820
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   821
    ^ true.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   822
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   823
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   824
loadUncompressedFrom:aStream into:aByteArray
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   825
    "load bmp-1,2,4 and 8 bit per pixel imagedata."
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   826
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   827
    |bytesPerRowInStream bytesPerRowInData skip dstIndex n|
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   828
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   829
    compression == 0 ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   830
        ^ false
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   831
    ].            
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   832
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   833
    bytesPerRowInStream := Image bytesPerRowForWidth:width depth:inDepth padding:32.   
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   834
    bytesPerRowInData := self bytesPerRow.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   835
    skip := bytesPerRowInStream - bytesPerRowInData.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   836
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   837
    "/ bottom row first...
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   838
    dstIndex := (height - 1) * bytesPerRowInData + 1.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   839
    height to:1 by:-1 do:[:y |
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   840
        n := aStream nextBytes:bytesPerRowInData into:aByteArray startingAt:dstIndex.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   841
        n ~~ bytesPerRowInData ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   842
            ^ false.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   843
        ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   844
        skip ~~ 0 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   845
            aStream skip:skip.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   846
        ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   847
        dstIndex := dstIndex - bytesPerRowInData.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   848
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   849
    ^ true.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   850
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   851
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   852
swapBytesFromRGB_to_BGR
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   853
    |idx bytesPerRow|
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   854
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   855
    "/ Depth24Image keeps its data r/g/b; BMP has it b/g/r (sigh)
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   856
    idx := 1.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   857
    bytesPerRow := self bytesPerRow.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   858
    1 to:height do:[:y |
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   859
        self class swap:bytesPerRow bytesFromRGB_to_BGR_in:data startingAt:idx.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   860
        idx := idx + bytesPerRow.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   861
    ].
103
claus
parents: 102
diff changeset
   862
! !
claus
parents: 102
diff changeset
   863
1848
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   864
!WindowsIconReader methodsFor:'private-reading'!
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   865
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   866
readColorMap:nColors numBytesPerColor:nRawBytesPerColor from:aStream
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   867
    "read the colormap; notice: its in BGR order (sigh)."
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   868
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   869
    |rawMap rMap gMap bMap 
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   870
     srcIndex  "{ Class: SmallInteger }"
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   871
     skipDelta "{ Class: SmallInteger }"|
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   872
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   873
    rawMap := ByteArray uninitializedNew:(nColors*nRawBytesPerColor).
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   874
    aStream nextBytes:(nColors*nRawBytesPerColor) into:rawMap.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   875
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   876
    rMap := ByteArray new:nColors.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   877
    gMap := ByteArray new:nColors.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   878
    bMap := ByteArray new:nColors.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   879
    srcIndex := 1.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   880
    skipDelta := nRawBytesPerColor - 3.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   881
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   882
    "/ stupid: this is a BGR-ordered map (otherwise, could use #rgbBytesVector:-message)
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   883
    "/ also, there might be a fourth byte (alpha ?) which is (currently) skipped.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   884
    1 to:nColors do:[:i |
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   885
        bMap at:i put:(rawMap at:srcIndex).
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   886
        srcIndex := srcIndex + 1.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   887
        gMap at:i put:(rawMap at:srcIndex).
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   888
        srcIndex := srcIndex + 1.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   889
        rMap at:i put:(rawMap at:srcIndex).
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   890
        srcIndex := srcIndex + 1.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   891
        srcIndex := srcIndex + skipDelta.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   892
    ].
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   893
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   894
    ^ MappedPalette 
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   895
        redVector:rMap 
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   896
        greenVector:gMap 
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   897
        blueVector:bMap.
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   898
! !
864ca2cd4e71 category
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   899
1805
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1790
diff changeset
   900
!WindowsIconReader methodsFor:'reading'!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   901
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   902
fromOS2File:aFilename
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   903
    "read an image from an OS/2 BMP file"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   904
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   905
    |reader stream|
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   906
1790
41f36b5a29c3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1759
diff changeset
   907
    stream := self class streamReadingFile:aFilename.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   908
    stream isNil ifTrue:[^ nil].
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
   909
    reader := self class new.
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
   910
    reader fromOS2Stream:stream.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
   911
    stream close.
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
   912
    ^ reader image
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   913
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
   914
    "Modified: / 30-05-2007 / 16:52:50 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
   915
!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
   916
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   917
fromOS2Stream:aStream
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   918
    "read an image from an OS/2 BMP stream"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   919
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   920
    ^ self fromOS2Stream:aStream alreadyRead:nil
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   921
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   922
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   923
fromOS2Stream:aStream alreadyRead:bytesAlreadyRead
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   924
    "read an image from an OS/2 BMP stream"
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   925
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   926
    |header inBytesPerRow mask bytesPerRow nColors nByte|
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   927
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   928
    inStream := aStream.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   929
    aStream binary.
2031
c8527bd15f50 .ico stuff - ongoing work
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
   930
    byteOrder := #lsb.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   931
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   932
    "read the header"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   933
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   934
    header := ByteArray uninitializedNew:8r110.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   935
    bytesAlreadyRead size > 0 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   936
        header replaceFrom:1 with:bytesAlreadyRead
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   937
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   938
    aStream nextBytes:(16-bytesAlreadyRead size) into:header startingAt:(1+bytesAlreadyRead size).
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   939
445
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   940
    (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
   941
        "IC format"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   942
        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
   943
        width := header at:7.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   944
        height := header at:9.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   945
        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
   946
    ] ifFalse:[
445
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   947
        (header startsWith:#(67 73)) ifTrue:[     "CI"
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   948
            ^ self fileFormatError:'unsupported format: CI'.
445
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   949
        ] ifFalse:[
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   950
            aStream nextBytes:(8r110-16) into:header startingAt:17.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   951
            width := header at:8r101.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   952
            height := header at:8r103.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   953
            inDepth := header at:8r107.
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   954
        ]
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   955
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   956
1846
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   957
    self reportDimension.
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
   958
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   959
    "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
   960
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   961
    nColors := 1 bitShift:inDepth.
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   962
    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
   963
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   964
    "read the mask"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   965
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   966
    nByte := ((width * height) + 7) // 8.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   967
    mask := ByteArray uninitializedNew:nByte.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   968
    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
   969
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
   970
    "what is this ?"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   971
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   972
    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
   973
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   974
"/    "read the data bits"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   975
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   976
"/    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
   977
"/    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
   978
"/    inDepth == 8 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   979
"/    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   980
"/    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
   981
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   982
"/    "stupid: last row first"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   983
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   984
"/    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
   985
"/    srcIndex := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   986
"/    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
   987
"/    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
   988
"/        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
   989
"/                   with:data4 startingAt:srcIndex.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   990
"/        srcIndex := srcIndex + bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   991
"/        dstIndex := dstIndex - bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   992
"/    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   993
"/    data4 := tmp.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   994
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   995
"/    "expand into bytes"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   996
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   997
"/    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
   998
"/    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
   999
"/                  into:data mapping:nil.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1000
"/
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1001
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1002
    bytesPerRow := ((width * inDepth) + 7) // 8.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1003
    "/ 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
  1004
    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
  1005
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1006
    data := ByteArray uninitializedNew:(height * width "bytesPerRow").
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1007
    compression := 0. 
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1008
    (self loadBMPWidth:width height:height depth:inDepth from:aStream into:data) ifFalse:[
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1009
        ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1010
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1011
    photometric := #palette.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1012
    samplesPerPixel := 1.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1013
    bitsPerSample := #(8).
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1014
    ^ self image
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1015
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1016
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1017
     |i f|
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1018
     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
  1019
     f := i asFormOn:Display.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1020
     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
  1021
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1022
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1023
    "Modified: / 17-09-1995 / 18:49:24 / claus"
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1024
    "Modified: / 30-05-2007 / 16:53:24 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1025
!
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1026
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1027
fromStream:aStream 
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1028
    "figure out which format the stream contains
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1029
     (there are various different bmp/ico formats around)
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1030
     and read the image."
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1031
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1032
    |fileSize header|
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1033
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1034
    inStream := aStream.
2031
c8527bd15f50 .ico stuff - ongoing work
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
  1035
    byteOrder := #lsb.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1036
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1037
    aStream binary.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1038
    aStream isFileStream ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1039
        fileSize := aStream fileSize.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1040
        fileSize < 16 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1041
            ^ self fileFormatError:'short file'.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1042
        ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1043
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1044
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1045
    header := ByteArray uninitializedNew:4.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1046
    aStream nextBytes:4 into:header.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1047
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1048
    (header startsWith:#(66 77)) ifTrue:[     "BM"
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
  1049
"/        'WinIconReader [info]: Win3.x or OS/2 vsn 2 BM format' infoPrintNL.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1050
        ^ self fromWindowsBMPStream:aStream alreadyRead:header
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1051
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1052
    (header startsWith:#(66 65)) ifTrue:[     "BA"
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
  1053
"/        'WinIconReader [info]: OS/2 vsn 2 BA format' infoPrintNL.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1054
        ^ self fromOS2Stream:aStream alreadyRead:header
445
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
  1055
    ].                    
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
  1056
    (header startsWith:#(67 73)) ifTrue:[     "CI"
899af8ff2a5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
  1057
"/        'WinIconReader [info]: OS/2 vsn 2 BA format' infoPrintNL.
2031
c8527bd15f50 .ico stuff - ongoing work
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
  1058
"/        ^ self fromOS2Stream:aStream
c8527bd15f50 .ico stuff - ongoing work
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
  1059
        ^ 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
  1060
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1061
    (header startsWith:#(73 67)) ifTrue:[     "IC"
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
  1062
"/        'WinIconReader [info]: OS/2 IC format' infoPrintNL.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1063
        ^ self fromOS2Stream:aStream alreadyRead:header
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1064
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1065
    (header startsWith:#(80 84)) ifTrue:[     "PT"
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
  1066
"/        'WinIconReader [info]: OS/2 PT format' infoPrintNL.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1067
        ^ self fromOS2Stream:aStream alreadyRead:header
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1068
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1069
    (header startsWith:#(16r53 16r5A)) ifTrue:[     "SZ"
1167
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1070
"/        'WinIconReader [info]: OS/2 SZ format' infoPrintNL.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1071
"/        ^ self fromOS2Stream:aStream
2031
c8527bd15f50 .ico stuff - ongoing work
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
  1072
        ^ 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
  1073
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1074
    (header startsWith:#(0 0 1 0)) ifTrue:[
387
0f4c8ef0e973 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 298
diff changeset
  1075
"/        'WinIconReader [info]: Win3.x ICO format' infoPrintNL.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1076
        ^ self fromWindowsICOStream:aStream alreadyRead:header
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1077
    ].
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
  1078
    ^ self fileFormatError:('format not supported:'
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
  1079
                            , ((header at:1) printStringRadix:16)
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
  1080
                            , ' ' 
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
  1081
                            , ((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
  1082
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1083
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1084
     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
  1085
    "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1086
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
  1087
    "Modified: / 17.9.1995 / 18:59:07 / claus"
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
  1088
    "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
  1089
!
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1090
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1091
fromWindowsBMPFile: aFilename 
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1092
    "read an image from a windows BMP file"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1093
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1094
    |reader stream|
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1095
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1096
    stream := self class streamReadingFile:aFilename.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1097
    stream isNil ifTrue:[^ nil].
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1098
    reader := self class new.
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1099
    reader fromWindowsBMPStream:stream.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1100
    stream close.
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1101
    ^ reader image.
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1102
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1103
    "Modified: / 30-05-2007 / 16:53:48 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1104
!
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1105
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1106
fromWindowsBMPStream:aStream 
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1107
    "read an image from a windows BMP stream"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1108
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1109
    ^ self fromWindowsBMPStream:aStream alreadyRead:nil
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1110
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1111
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1112
fromWindowsBMPStream:aStream alreadyRead:bytesAlreadyRead
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1113
    "read an image from a windows BMP stream"
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1114
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1115
    | header iSize inPlanes 
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1116
      imgSize resH resV numColor numImportantColor
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1117
      dataStart redMask greenMask blueMask alphaMask
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1118
      bytesPerRow numBytesPerColorInColormap|
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1119
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1120
    inStream := aStream.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1121
    aStream binary.
2031
c8527bd15f50 .ico stuff - ongoing work
Claus Gittinger <cg@exept.de>
parents: 1848
diff changeset
  1122
    byteOrder := #lsb.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1123
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1124
    "read the header"
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1125
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1126
    header := ByteArray uninitializedNew:16r54.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1127
    bytesAlreadyRead size > 0 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1128
        header replaceFrom:1 with:bytesAlreadyRead
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1129
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1130
    aStream nextBytes:(18-bytesAlreadyRead size) into:header startingAt:(1+bytesAlreadyRead size).
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1131
518
c9d492fbb1b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 445
diff changeset
  1132
    iSize := header at:(16r0E + 1).
c9d492fbb1b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 445
diff changeset
  1133
    (iSize == 40) ifTrue:[    "header-size"
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1134
        "/
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1135
        "/ a Windows3.x BMP file
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1136
        "/
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1137
        "/ 'WinIconReader [info]: Win3.x format' infoPrintCR.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1138
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1139
        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
  1140
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1141
        width := header wordAt:(16r12 + 1) MSB:false.  
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1142
        height := header wordAt:(16r16 + 1) MSB:false. 
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1143
        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
  1144
        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
  1145
        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
  1146
        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
  1147
        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
  1148
        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
  1149
        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
  1150
        numImportantColor := header doubleWordAt:(16r32 + 1) MSB:false.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1151
        redMask := header doubleWordAt:(16r36 + 1) MSB:false.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1152
        greenMask := header doubleWordAt:(16r3A + 1) MSB:false.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1153
        blueMask := header doubleWordAt:(16r3E + 1) MSB:false.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1154
        alphaMask := header doubleWordAt:(16r42 + 1) MSB:false.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1155
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1156
        numColor == 0 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1157
            "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1158
             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
  1159
            "
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1160
            inDepth <= 8 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1161
                numColor := 1 bitShift:inDepth.
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1162
                "/ '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
  1163
            ]
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1164
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1165
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1166
        numBytesPerColorInColormap := 4.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1167
        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
  1168
    ] ifFalse:[
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1169
        ((iSize == 12) or:[iSize >= 64]) ifTrue:[     
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1170
            "/
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1171
            "/ its an OS/2 BMP file
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1172
            "/
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1173
            "/ 'WinIconReader [info]: OS/2 format' infoPrintCR.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1174
            aStream nextBytes:(iSize-4) into:header startingAt:19.
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1175
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1176
            numBytesPerColorInColormap := 3.
565
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1177
            dataStart := nil.
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1178
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1179
            iSize == 12 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1180
                width := header wordAt:(16r12 + 1) MSB:false.  
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1181
                height := header wordAt:(16r14 + 1) MSB:false. 
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1182
                inPlanes := header wordAt:(16r16 + 1) MSB:false.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1183
                inDepth := header wordAt:(16r18 + 1) MSB:false.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1184
                "/ dataStart := header wordAt:(16r0A + 1) MSB:false.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1185
                compression := 0.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1186
            ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1187
            iSize >= 64 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1188
                "/
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1189
                "/ its an OS/2 (vsn2) BMP file
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1190
                "/
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1191
                width := header doubleWordAt:(16r12 + 1) MSB:false.  
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1192
                height := header doubleWordAt:(16r16 + 1) MSB:false.  
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1193
                inPlanes := header wordAt:(16r1A + 1) MSB:false.  
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1194
                inDepth := header wordAt:(16r1c + 1) MSB:false. 
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1195
                compression := header doubleWordAt:(16r1e + 1) MSB:false. 
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1196
                numColor := header doubleWordAt:(16r2E + 1) MSB:false.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1197
                numImportantColor := header doubleWordAt:(16r32 + 1) MSB:false.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1198
                dataStart := header wordAt:(16r0A + 1) MSB:false.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1199
            ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1200
            numColor := 1 bitShift:inDepth.
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1201
        ] ifFalse:[
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
  1202
            ^ 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
  1203
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1204
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1205
1846
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
  1206
    self reportDimension.
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
  1207
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1208
    numColor ~~ 0 ifTrue:[
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1209
        "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
  1210
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1211
        colorMap := self 
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1212
                        readColorMap:numColor 
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1213
                        numBytesPerColor:numBytesPerColorInColormap
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1214
                        from:aStream.
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1215
898
cdf6cc132b53 care for funny number of colors (nColor > (1<<depth))
Claus Gittinger <cg@exept.de>
parents: 819
diff changeset
  1216
        numColor > (1 bitShift:inDepth) ifTrue:[
cdf6cc132b53 care for funny number of colors (nColor > (1<<depth))
Claus Gittinger <cg@exept.de>
parents: 819
diff changeset
  1217
            '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
  1218
            numColor := 1 bitShift:inDepth.
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1219
            colorMap := colorMap copyTo:numColor.
898
cdf6cc132b53 care for funny number of colors (nColor > (1<<depth))
Claus Gittinger <cg@exept.de>
parents: 819
diff changeset
  1220
        ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1221
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1222
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1223
    "/ check for valid compression
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1224
    compression ~~ 0 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1225
        "/ some compression
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1226
        compression == 1 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1227
            "/ 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
  1228
            inDepth ~~ 8 ifTrue:[
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
  1229
                ^ 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
  1230
            ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1231
        ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1232
        compression == 2 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1233
            "/ 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
  1234
            inDepth ~~ 4 ifTrue:[
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
  1235
                ^ 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
  1236
            ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1237
        ].
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1238
        compression == 3 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1239
            "/ BITFIELDS - must be depth-16 or 32
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1240
            ((inDepth ~~ 16) and:[inDepth ~~ 32]) ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1241
                ^ self fileFormatError:'BITFIELDS compression only supported with depth16/32 images'.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1242
            ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1243
        ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1244
        compression >= 4 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1245
             ^ self fileFormatError:'unsupported compression'.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1246
        ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1247
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1248
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1249
    inPlanes ~~ 1 ifTrue:[
819
e358c08e45ea common error reporter
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
  1250
        ^ 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
  1251
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1252
565
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1253
    dataStart notNil ifTrue:[
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1254
        aStream position:dataStart.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1255
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1256
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1257
    inDepth <= 8 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1258
        samplesPerPixel := 1.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1259
        bitsPerSample := Array with:inDepth.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1260
        photometric := #palette.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1261
    ] ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1262
        inDepth == 16 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1263
            photometric := #palette.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1264
            samplesPerPixel := 3.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1265
            bitsPerSample := #(5 5 5).
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1266
            colorMap := FixedPalette
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1267
                            redShift:10 redMask:16r1f
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1268
                            greenShift:5 greenMask:16r1f 
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1269
                            blueShift:0 blueMask:16r1F.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1270
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1271
        ] ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1272
            inDepth == 24 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1273
                photometric := #rgb.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1274
                samplesPerPixel := 3.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1275
                bitsPerSample := #(8 8 8).
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1276
            ] ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1277
                inDepth == 32 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1278
                    photometric := #rgb.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1279
                    samplesPerPixel := 4.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1280
                    bitsPerSample := #(8 8 8 8).
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1281
                ] ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1282
                    ^ self fileFormatError:'unsupported depth'.
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1283
                ]
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1284
            ]
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1285
        ]
565
03b84a590f49 fixed os2 bmp reading
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1286
    ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1287
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1288
    inDepth == 24 ifTrue:[
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1289
        bytesPerRow := width * 3
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1290
    ] ifFalse:[
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1291
        inDepth == 16 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1292
            bytesPerRow := width * 2
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1293
        ] ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1294
            inDepth == 32 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1295
                bytesPerRow := width * 4
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1296
            ] ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1297
                bytesPerRow := self bytesPerRow
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1298
            ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1299
        ].
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1300
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1301
    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
  1302
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1303
    "/ read & possibly decompress
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1304
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1305
    (self loadBMPWidth:width height:height depth:inDepth from:aStream into:data) ifFalse:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1306
        self fileFormatError:('read/decompression error').
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1307
        ^ nil
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1308
    ].
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1309
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1310
    ^ self image
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1311
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1312
    "Modified: / 17-09-1995 / 18:48:46 / claus"
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1313
    "Modified: / 30-05-2007 / 16:57:39 / cg"
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1314
!
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1315
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1316
fromWindowsICOFile:aFilename 
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1317
    "read an image from a windows ICO file"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1318
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1319
    |reader stream|
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1320
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1321
    stream := self class streamReadingFile:aFilename.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1322
    stream isNil ifTrue:[^ nil].
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1323
    reader := self class new.
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1324
    reader fromWindowsICOStream:stream.
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1325
    stream close.
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1326
    ^ reader image.
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1327
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1328
    "
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1329
     Image fromFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'.
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1330
    "
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1331
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1332
    "Modified: / 30-05-2007 / 16:57:52 / cg"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1333
!
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1334
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1335
fromWindowsICOStream:aStream
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1336
    "read an image from a windows ICO stream"
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1337
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1338
    ^ self fromWindowsICOStream:aStream alreadyRead:nil
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1339
!
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1340
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1341
fromWindowsICOStream:aStream alreadyRead:bytesAlreadyRead
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1342
    "read an image from a windows ICO stream"
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1343
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1344
    |header 
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1345
     srcIndex dstIndex
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1346
     rawData tmp bytesPerRow nColor cmapSize|
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1347
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1348
    inStream := aStream.
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1349
    aStream binary.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1350
3f9277473954 Initial revision
claus
parents:
diff changeset
  1351
    "read the header"
3f9277473954 Initial revision
claus
parents:
diff changeset
  1352
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1353
    header := ByteArray uninitializedNew:(6 + 16 + 40).
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1354
    bytesAlreadyRead size > 0 ifTrue:[
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1355
        header replaceFrom:1 with:bytesAlreadyRead
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1356
    ].
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1357
    aStream nextBytes:((6 + 16 + 40)-bytesAlreadyRead size) into:header startingAt:(1+bytesAlreadyRead size).
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1358
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1359
    width := header at:(6+1).
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1360
    height := header at:(7+1).
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1361
    nColor := header at:(8+1).
430
50b841f4851d commentary
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
  1362
    "/ reserved := header at:(9+1).
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1363
    "/ nPlanes := header wordAt:(10+1).
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1364
    "/ nBitsPerPel := header wordAt:(12+1).
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1365
    "/ nBytesInResource := header doubleWordAt:(14+1).
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1366
    "/ ordinal := header wordAt:(18+1).
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1367
    "21, 22               ?"
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1368
    "23, ... , 62         ?"
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1369
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1370
    inDepth := header at:16r25.
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1371
    "/ mhmh - some depth4 icons seem to have a 0 in the depth field ...
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1372
    inDepth == 0 ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1373
        inDepth := 4
1386
2d02a4fba456 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  1374
    ].
1569
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
  1375
    (#(4 8) includes:inDepth) ifFalse:[
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
  1376
        "/ only tested for depth 4/8 images.
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
  1377
        ^ 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
  1378
"/        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
  1379
    ].
1846
d29322944b05 dimensionReport
Claus Gittinger <cg@exept.de>
parents: 1805
diff changeset
  1380
    self reportDimension.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1381
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1382
    "read the colormap"
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1383
    cmapSize := (1 bitShift:inDepth).
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1384
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1385
    colorMap := self
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1386
                readColorMap:cmapSize
1745
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1387
                numBytesPerColor:4
4fa0fad2a463 code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents: 1734
diff changeset
  1388
                from:aStream.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1389
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1390
    "read the data bits"
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1391
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1392
    bytesPerRow := ((width * inDepth) + 7) // 8.
1569
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
  1393
    rawData := ByteArray uninitializedNew:(height * bytesPerRow).
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
  1394
    aStream nextBytes:(height * bytesPerRow) into:rawData.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1395
3f9277473954 Initial revision
claus
parents:
diff changeset
  1396
    "read mask"
2034
Claus Gittinger <cg@exept.de>
parents: 2031
diff changeset
  1397
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1398
"
3f9277473954 Initial revision
claus
parents:
diff changeset
  1399
    mask := ByteArray new:(width * height / 8).
41
66edc847b9c8 *** empty log message ***
claus
parents: 36
diff changeset
  1400
    aStream nextBytes:(width * height / 8) into:mask.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1401
"
3f9277473954 Initial revision
claus
parents:
diff changeset
  1402
3f9277473954 Initial revision
claus
parents:
diff changeset
  1403
    "stupid: last row first"
3f9277473954 Initial revision
claus
parents:
diff changeset
  1404
3
78aaa5408119 *** empty log message ***
claus
parents: 0
diff changeset
  1405
    tmp := ByteArray uninitializedNew:(height * bytesPerRow).
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1406
    srcIndex := 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
  1407
    dstIndex := (height - 1) * bytesPerRow + 1.
3f9277473954 Initial revision
claus
parents:
diff changeset
  1408
    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
  1409
        tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1)
1569
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
  1410
                   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
  1411
        srcIndex := srcIndex + bytesPerRow.
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1412
        dstIndex := dstIndex - bytesPerRow.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1413
    ].
1569
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
  1414
    rawData := tmp.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1415
3f9277473954 Initial revision
claus
parents:
diff changeset
  1416
    photometric := #palette.
3f9277473954 Initial revision
claus
parents:
diff changeset
  1417
    samplesPerPixel := 1.
298
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
  1418
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
  1419
    false ifTrue:[
1569
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
  1420
        "expand into bytes"
298
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
  1421
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
  1422
        data := ByteArray new:(width * height).
1569
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
  1423
        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
  1424
                      into:data mapping:nil.
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
  1425
        bitsPerSample := #(8).
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
  1426
    ] ifFalse:[
1569
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
  1427
        data := rawData.
3954e576ff38 support depth 8 ico files
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
  1428
        bitsPerSample := (Array with:inDepth).
298
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
  1429
    ].
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1430
    ^ self image
298
cd59c474524a return .ico files as Depth4Images (not Depth8)
Claus Gittinger <cg@exept.de>
parents: 259
diff changeset
  1431
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1432
    "
21
66b31c91177f *** empty log message ***
claus
parents: 18
diff changeset
  1433
     WindowsIconReader new fromWindowsICOFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'.
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1434
    "
211
3eb140e89e2e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
  1435
2333
a93f1f5392bd from*Stream: methods return the image
Claus Gittinger <cg@exept.de>
parents: 2034
diff changeset
  1436
    "Modified: / 30-05-2007 / 16:58:11 / cg"
1805
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1790
diff changeset
  1437
! !
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1790
diff changeset
  1438
93f557cbe600 category changes
Claus Gittinger <cg@exept.de>
parents: 1790
diff changeset
  1439
!WindowsIconReader methodsFor:'writing'!
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1440
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1441
save:image onFile:aFileName
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1442
    "save image as BMP file on aFileName.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1443
     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
  1444
1168
590e5660f69e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
  1445
    aFileName asFilename suffix asLowercase = 'ico' ifTrue:[
590e5660f69e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
  1446
"/        (image depth == 4
590e5660f69e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
  1447
"/        and:[image width == 32
590e5660f69e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
  1448
"/        and:[image height == 32]]) ifTrue:[
590e5660f69e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
  1449
            ^ self saveICO:image onFile:aFileName.
590e5660f69e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
  1450
"/        ]
590e5660f69e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
  1451
    ].
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1452
    self saveBMP:image onFile:aFileName.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1453
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1454
    "Modified: 17.10.1997 / 20:16:53 / cg"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1455
!
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1456
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1457
saveBMP:image onFile:fileName 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1458
    "save image as BMP file on aFileName.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1459
     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
  1460
1507
9bae072abf64 fixed bmp saving 24bit image (red & blue channels exchanged)
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1461
    |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
  1462
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1463
    depth := image depth.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1464
    width := image width.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1465
    height := image height.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1466
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1467
    (#(1 4 8 24) includes:depth) ifFalse:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1468
        ^ Image cannotRepresentImageSignal 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1469
            raiseWith:image
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1470
            errorString:('BMP format only supports depths 1,4,8 and 24').
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1471
    ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1472
    image mask notNil ifTrue:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1473
        Image informationLostQuerySignal
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1474
            raiseWith:image
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1475
            errorString:('BMP format does not support an imageMask').
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1476
    ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1477
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1478
    bhSize := 14.  "# bytes in file header"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1479
    biSize := 40.  "info header size in bytes" 
1734
290f382d40e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  1480
    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
  1481
    bfOffBits := biSize + bhSize + (4*biClrUsed).
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1482
    "/ bmp aligns rows on a longword boundary
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1483
    rowBytes := ((depth min:24) * width + 31 // 32) * 4.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1484
    biSizeImage := height * rowBytes.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1485
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1486
    outStream := fileName asFilename writeStream.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1487
    outStream binary.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1488
    byteOrder := #lsb.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1489
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1490
    "Write the file header"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1491
    self writeShort:19778.  "bfType = BM" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1492
    self writeLong:(bfOffBits + biSizeImage).  "Entire file size in bytes"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1493
    self writeLong:0.  "bfReserved" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1494
    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
  1495
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1496
    "Write the bitmap info header"
1754
cc844dc3504e avoid position
Claus Gittinger <cg@exept.de>
parents: 1745
diff changeset
  1497
    outStream position1Based: bhSize+1.
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1498
    self writeLong:biSize.  "info header size in bytes" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1499
    self writeLong:width.  "biWidth" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1500
    self writeLong:height.  "biHeight" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1501
    self writeShort:1.  "biPlanes" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1502
    self writeShort:(depth min:24).  "biBitCount" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1503
    self writeLong:0.  "biCompression" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1504
    self writeLong:biSizeImage.  "size of image section in bytes"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1505
    self writeLong:2800.  "biXPelsPerMeter" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1506
    self writeLong:2800.  "biYPelsPerMeter" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1507
    self writeLong:biClrUsed.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1508
    self writeLong:0.  "biClrImportant" 
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1509
    1 to:biClrUsed do:[:i |  "Color map"
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1510
        |clr r g b|
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1511
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1512
        clr := image colorFromValue:i-1.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1513
        clr isNil ifTrue:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1514
            r := g := b := 0.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1515
        ] ifFalse:[
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1516
            r := clr redByte.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1517
            g := clr greenByte.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1518
            b := clr blueByte.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1519
        ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1520
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1521
        "/ put B,G,R
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1522
        outStream nextPut:b.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1523
        outStream nextPut:g.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1524
        outStream nextPut:r.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1525
        outStream nextPut:0.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1526
    ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1527
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1528
    imgBytesPerRow := image bytesPerRow.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1529
    data := image data.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1530
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1531
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1532
    "/ sorry, must extract rows individually
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1533
    "/ (even if alignment is correct),
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1534
    "/ since BMP saves rows bottom-to-top
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1535
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1536
    row := ByteArray new:rowBytes.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1537
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1538
    srcIndex := 1 + (height * imgBytesPerRow).
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1539
    1 to:height do:[:i |
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1540
        srcIndex := srcIndex - imgBytesPerRow.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1541
        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
  1542
        depth >= 24 ifTrue:[
9bae072abf64 fixed bmp saving 24bit image (red & blue channels exchanged)
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1543
            "/ 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
  1544
9bae072abf64 fixed bmp saving 24bit image (red & blue channels exchanged)
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1545
            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
  1546
                t := row at:i.
9bae072abf64 fixed bmp saving 24bit image (red & blue channels exchanged)
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1547
                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
  1548
                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
  1549
            ].
9bae072abf64 fixed bmp saving 24bit image (red & blue channels exchanged)
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  1550
        ].
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1551
        outStream nextPutAll:row.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1552
    ].
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1553
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1554
    outStream close.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1555
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1556
    "
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1557
     |i|
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1558
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1559
     i := Image fromFile:'bitmaps/SBrowser.xbm'.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1560
     WindowsIconReader save:i onFile:'test.bmp'.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1561
    "
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1562
    "
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1563
     |i|
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1564
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1565
     i := Image fromFile:'bitmaps/gifImages/garfield.gif'.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1566
     WindowsIconReader save:i onFile:'test.bmp'.
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1567
    "
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1568
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1569
    "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
  1570
!
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1571
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1572
saveICO:image onFile:fileName 
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1573
    "save image as ICO file on aFileName.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1574
     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
  1575
1233
6587cabeab10 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1171
diff changeset
  1576
    |depth biSizeImage rowBytes imgBytesPerRow data srcIndex row|
1167
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1577
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1578
    depth := image depth.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1579
    width := image width.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1580
    height := image height.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1581
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1582
    depth ~~ 4 ifTrue:[
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1583
        ^ Image cannotRepresentImageSignal 
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1584
            raiseWith:image
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1585
            errorString:('ICO format only supports depths 4').
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1586
    ].
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1587
    (width ~~ 32 or:[height ~~ 32]) ifTrue:[
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1588
        ^ Image cannotRepresentImageSignal 
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1589
            raiseWith:image
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1590
            errorString:('ICO format (currently) only supports 32x32 bitmaps').
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1591
    ].
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1592
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1593
    "/ align rows on a longword boundary
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1594
    rowBytes := (depth * width + 31 // 32) * 4.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1595
    biSizeImage := height * rowBytes.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1596
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1597
    outStream := fileName asFilename writeStream.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1598
    outStream binary.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1599
    byteOrder := #lsb.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1600
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1601
    "Write the file header"
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1602
    outStream nextPutAll:#[0 0 1 0].    "/ ICO magic
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1603
    self writeShort:1.             "/ # of images in file
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1604
    outStream nextPut:image width.      "/
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1605
    outStream nextPut:image height.     "/
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1606
    outStream nextPut:(1 bitShift:image depth). "/ # of colors
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1607
    outStream nextPutAll:#[0 0 0 0 0 ]. "/ reserved
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1608
    self writeLong:16rE802.              "/ size pixels
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1609
    self writeLong:16r26.                "/ offset in file
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1610
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1611
    "/ 40 bytes - unknown format
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1612
    outStream nextPutAll:(ByteArray new:40).
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1613
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1614
    "/ 16-entry RGB map
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1615
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1616
    1 to:16 do:[:i |  "Color map"
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1617
        |clr r g b|
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1618
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1619
        clr := image colorFromValue:i-1.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1620
        clr isNil ifTrue:[
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1621
            r := g := b := 0.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1622
        ] ifFalse:[
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1623
            r := clr redByte.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1624
            g := clr greenByte.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1625
            b := clr blueByte.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1626
        ].
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1627
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1628
        "/ put B,G,R
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1629
        outStream nextPut:b.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1630
        outStream nextPut:g.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1631
        outStream nextPut:r.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1632
        outStream nextPut:0.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1633
    ].
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1634
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1635
    imgBytesPerRow := image bytesPerRow.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1636
    data := image data.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1637
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1638
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1639
    "/ sorry, must extract rows individually
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1640
    "/ (even if alignment is correct),
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1641
    "/ since ICO saves rows bottom-to-top
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1642
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1643
    row := ByteArray new:rowBytes.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1644
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1645
    srcIndex := 1 + (height * imgBytesPerRow).
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1646
    1 to:height do:[:i |
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1647
        srcIndex := srcIndex - imgBytesPerRow.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1648
        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
  1649
        outStream nextPutAll:row.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1650
    ].
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1651
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1652
    "/ the mask ...
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1653
    image mask isNil ifTrue:[
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1654
        outStream next:128 put:16rFF
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1655
    ] ifFalse:[
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1656
        imgBytesPerRow := image mask bytesPerRow.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1657
        data := image mask data.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1658
        row := ByteArray new:4.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1659
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1660
        srcIndex := 1 + (height * imgBytesPerRow).
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1661
        1 to:height do:[:i |
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1662
            srcIndex := srcIndex - imgBytesPerRow.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1663
            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
  1664
            outStream nextPutAll:row.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1665
        ].
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1666
    ].
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1667
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1668
    outStream close.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1669
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1670
    "
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1671
     |i|
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1672
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1673
     i := Image fromFile:'bitmaps/xpmBitmaps/SmalltalkX_clr.xpm'.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1674
     i := Depth4Image fromImage:i.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1675
     i := i magnifiedTo:32@32.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1676
     WindowsIconReader new saveICO:i onFile:'test.ico'.
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1677
    "
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1678
78084516ae7c first attempt in saving ICO files.
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
  1679
    "Modified: 21.10.1997 / 05:02:02 / cg"
713
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1680
! !
548898fdd1dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
  1681
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1682
!WindowsIconReader class methodsFor:'documentation'!
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1683
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1684
version
2571
ae60c0d0452d many fixes
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
  1685
    ^ '$Header: /cvs/stx/stx/libview2/WindowsIconReader.st,v 1.62 2008-12-02 21:02:23 cg Exp $'
0
3f9277473954 Initial revision
claus
parents:
diff changeset
  1686
! !
1734
290f382d40e9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  1687
172
ee7d84977c86 use inforPrint instead of errorPrint (these are not fatal errors)
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
  1688
WindowsIconReader initialize!