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