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