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