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