0
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
28
|
3 |
All Rights Reserved
|
0
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
ImageReader subclass:#WindowsIconReader
|
28
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
32
|
17 |
category:'Graphics-Images support'
|
0
|
18 |
!
|
|
19 |
|
21
|
20 |
!WindowsIconReader class methodsFor:'documentation'!
|
|
21 |
|
|
22 |
copyright
|
|
23 |
"
|
|
24 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
28
|
25 |
All Rights Reserved
|
0
|
26 |
|
21
|
27 |
This software is furnished under a license and may be used
|
|
28 |
only in accordance with the terms of that license and with the
|
|
29 |
inclusion of the above copyright notice. This software may not
|
|
30 |
be provided or otherwise made available to, or used by, any
|
|
31 |
other person. No title to or ownership of the software is
|
|
32 |
hereby transferred.
|
|
33 |
"
|
|
34 |
!
|
0
|
35 |
|
21
|
36 |
version
|
|
37 |
"
|
104
|
38 |
$Header: /cvs/stx/stx/libview2/Attic/WinIconRdr.st,v 1.18 1995-09-18 10:35:20 claus Exp $
|
21
|
39 |
"
|
|
40 |
!
|
|
41 |
|
|
42 |
documentation
|
|
43 |
"
|
32
|
44 |
this class provides methods for loading Windows and OS2 icon files.
|
|
45 |
Image writing is not supported.
|
21
|
46 |
"
|
|
47 |
! !
|
0
|
48 |
|
28
|
49 |
!WindowsIconReader class methodsFor:'initialization'!
|
|
50 |
|
|
51 |
initialize
|
|
52 |
Image fileFormats at:'.bmp' put:self.
|
|
53 |
Image fileFormats at:'.ico' put:self.
|
|
54 |
! !
|
|
55 |
|
102
|
56 |
!WindowsIconReader class methodsFor:'testing'!
|
|
57 |
|
|
58 |
isValidImageFile:aFileName
|
|
59 |
"return true, if aFileName contains a valid windows bitmap-file image"
|
|
60 |
|
|
61 |
|inStream header ok|
|
|
62 |
|
|
63 |
inStream := self streamReadingFile:aFileName.
|
|
64 |
inStream isNil ifTrue:[^ false].
|
|
65 |
|
|
66 |
inStream binary.
|
104
|
67 |
ok := false.
|
|
68 |
inStream size > 16 ifTrue:[
|
|
69 |
header := ByteArray uninitializedNew:4.
|
|
70 |
inStream nextBytes:4 into:header.
|
102
|
71 |
|
104
|
72 |
(header startsWith:#(66 77)) ifTrue:[ "BM"
|
|
73 |
ok := true.
|
|
74 |
"/ 'WINREADER: Win3.x or OS/2 vsn 2 BM format' infoPrintNL.
|
|
75 |
].
|
|
76 |
(header startsWith:#(66 65)) ifTrue:[ "BA"
|
|
77 |
ok := true.
|
|
78 |
"/ 'WINREADER: OS/2 vsn 2 BA format' infoPrintNL.
|
|
79 |
].
|
|
80 |
(header startsWith:#(73 67)) ifTrue:[ "IC"
|
|
81 |
ok := true.
|
|
82 |
"/ 'WINREADER: OS/2 IC format' infoPrintNL.
|
|
83 |
].
|
|
84 |
(header startsWith:#(80 84)) ifTrue:[ "PT"
|
|
85 |
ok := true.
|
|
86 |
"/ 'WINREADER: OS/2 PT format' infoPrintNL.
|
|
87 |
].
|
|
88 |
(header startsWith:#(0 0 1 0)) ifTrue:[
|
|
89 |
ok := true.
|
|
90 |
"/ 'WINREADER: Win3.x ICO format' infoPrintNL.
|
|
91 |
].
|
102
|
92 |
].
|
104
|
93 |
inStream close.
|
|
94 |
^ ok
|
102
|
95 |
|
|
96 |
"
|
|
97 |
WindowsIconReader isValidImageFile:'/phys/clam2/LocalLibrary/Images/OS2_icons/dos.ico'
|
|
98 |
"
|
|
99 |
|
|
100 |
"Created: 17.9.1995 / 17:14:20 / claus"
|
|
101 |
! !
|
|
102 |
|
103
|
103 |
!WindowsIconReader methodsFor:'private'!
|
|
104 |
|
|
105 |
loadBMPWidth:w height:h depth:d compression:c from:aStream into:data
|
|
106 |
d == 8 ifTrue:[
|
|
107 |
(self class loadBMP8Width:w height:h compression:c from:aStream into:data) ifFalse:[
|
|
108 |
'BMP: read/decompression failed' errorPrintNL.
|
|
109 |
^ false
|
|
110 |
]
|
|
111 |
] ifFalse:[
|
|
112 |
d == 4 ifTrue:[
|
|
113 |
(self class loadBMP4to8Width:w height:h compression:c from:aStream into:data) ifFalse:[
|
|
114 |
'BMP: read/decompression failed' errorPrintNL.
|
|
115 |
^ false
|
|
116 |
]
|
|
117 |
] ifFalse:[
|
|
118 |
d == 2 ifTrue:[
|
|
119 |
(self class loadBMP2to8Width:w height:h from:aStream into:data) ifFalse:[
|
|
120 |
'BMP: read failed' errorPrintNL.
|
|
121 |
^ false
|
|
122 |
]
|
|
123 |
] ifFalse:[
|
|
124 |
d == 1 ifTrue:[
|
|
125 |
(self class loadBMP1to8Width:w height:h from:aStream into:data) ifFalse:[
|
|
126 |
'BMP: read failed' errorPrintNL.
|
|
127 |
^ false
|
|
128 |
]
|
|
129 |
] ifFalse:[
|
|
130 |
'BMP: unsupported depth:' errorPrint. d errorPrintNL.
|
|
131 |
^ false
|
|
132 |
]
|
|
133 |
]
|
|
134 |
]
|
|
135 |
].
|
|
136 |
^ true
|
|
137 |
|
|
138 |
"Created: 17.9.1995 / 18:48:11 / claus"
|
|
139 |
! !
|
|
140 |
|
53
|
141 |
!WindowsIconReader methodsFor:'reading from file'!
|
0
|
142 |
|
21
|
143 |
fromOS2File: aFilename
|
41
|
144 |
|reader stream|
|
|
145 |
|
|
146 |
stream := self streamReadingFile:aFilename.
|
|
147 |
stream isNil ifTrue:[^ nil].
|
83
|
148 |
reader := (self new) fromOS2Stream:stream.
|
41
|
149 |
stream close.
|
|
150 |
reader notNil ifTrue:[^ reader image].
|
|
151 |
^ nil
|
21
|
152 |
!
|
0
|
153 |
|
21
|
154 |
fromWindowsBMPFile: aFilename
|
41
|
155 |
|reader stream|
|
|
156 |
|
|
157 |
stream := self class streamReadingFile:aFilename.
|
|
158 |
stream isNil ifTrue:[^ nil].
|
83
|
159 |
reader := (self new) fromWindowsBMPStream:stream.
|
41
|
160 |
stream close.
|
|
161 |
reader notNil ifTrue:[^ reader image].
|
|
162 |
^ nil
|
21
|
163 |
!
|
|
164 |
|
|
165 |
fromWindowsICOFile: aFilename
|
41
|
166 |
|reader stream|
|
|
167 |
|
|
168 |
stream := self class streamReadingFile:aFilename.
|
|
169 |
stream isNil ifTrue:[^ nil].
|
83
|
170 |
reader := (self new) fromWindowsICOStream:stream.
|
41
|
171 |
stream close.
|
|
172 |
reader notNil ifTrue:[^ reader image].
|
|
173 |
^ nil
|
21
|
174 |
|
|
175 |
"
|
|
176 |
Image fromFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'.
|
|
177 |
"
|
|
178 |
!
|
|
179 |
|
41
|
180 |
fromWindowsICOStream:aStream
|
21
|
181 |
| header inDepth
|
|
182 |
rawMap rMap gMap bMap srcIndex dstIndex
|
|
183 |
data4 mask tmp bytesPerRow nColor|
|
0
|
184 |
|
41
|
185 |
inStream := aStream.
|
|
186 |
aStream binary.
|
0
|
187 |
|
|
188 |
"read the header"
|
|
189 |
|
21
|
190 |
header := ByteArray uninitializedNew:(6 + 16 + 40).
|
41
|
191 |
aStream nextBytes:(6 + 16 + 40) into:header.
|
21
|
192 |
width := header at:(6+1).
|
|
193 |
height := header at:(7+1).
|
|
194 |
nColor := header at:(8+1).
|
|
195 |
"10, 11, 12, 13, 14 ? (reserve)"
|
|
196 |
"15, 16, 17, 18 pixel array size"
|
|
197 |
"19, 20, 21, 22 offset "
|
|
198 |
"23, ... , 62 ?"
|
|
199 |
|
0
|
200 |
inDepth := header at:16r25.
|
|
201 |
|
|
202 |
"read the colormap"
|
|
203 |
|
21
|
204 |
rawMap := ByteArray uninitializedNew:(16*4).
|
41
|
205 |
aStream nextBytes:(16*4) into:rawMap.
|
0
|
206 |
rMap := Array new:16.
|
|
207 |
gMap := Array new:16.
|
|
208 |
bMap := Array new:16.
|
|
209 |
srcIndex := 1.
|
|
210 |
1 to:16 do:[:i |
|
28
|
211 |
bMap at:i put:(rawMap at:srcIndex).
|
|
212 |
srcIndex := srcIndex + 1.
|
|
213 |
gMap at:i put:(rawMap at:srcIndex).
|
|
214 |
srcIndex := srcIndex + 1.
|
|
215 |
rMap at:i put:(rawMap at:srcIndex).
|
|
216 |
srcIndex := srcIndex + 1.
|
|
217 |
srcIndex := srcIndex + 1.
|
0
|
218 |
].
|
|
219 |
|
|
220 |
"read the data bits"
|
|
221 |
|
3
|
222 |
bytesPerRow := width * inDepth + 7 // 8.
|
|
223 |
data4 := ByteArray uninitializedNew:(height * bytesPerRow).
|
41
|
224 |
aStream nextBytes:(height * bytesPerRow) into:data4.
|
0
|
225 |
|
|
226 |
"read mask"
|
|
227 |
|
|
228 |
"
|
|
229 |
mask := ByteArray new:(width * height / 8).
|
41
|
230 |
aStream nextBytes:(width * height / 8) into:mask.
|
0
|
231 |
"
|
|
232 |
|
|
233 |
"stupid: last row first"
|
|
234 |
|
3
|
235 |
tmp := ByteArray uninitializedNew:(height * bytesPerRow).
|
0
|
236 |
srcIndex := 1.
|
|
237 |
dstIndex := (height - 1) * bytesPerRow + 1.
|
|
238 |
1 to:height do:[:row |
|
28
|
239 |
tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1)
|
|
240 |
with:data4 startingAt:srcIndex.
|
|
241 |
srcIndex := srcIndex + bytesPerRow.
|
|
242 |
dstIndex := dstIndex - bytesPerRow.
|
0
|
243 |
].
|
|
244 |
data4 := tmp.
|
|
245 |
|
|
246 |
"expand into bytes"
|
|
247 |
|
|
248 |
data := ByteArray new:(width * height).
|
|
249 |
data4 expandPixels:inDepth width:width height:height
|
28
|
250 |
into:data mapping:nil.
|
0
|
251 |
|
|
252 |
photometric := #palette.
|
|
253 |
samplesPerPixel := 1.
|
|
254 |
bitsPerSample := #(8).
|
36
|
255 |
colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
|
0
|
256 |
|
|
257 |
"
|
21
|
258 |
WindowsIconReader new fromWindowsICOFile:'/phys/clam2//LocalLibrary/Images/WIN_icons/ibm.ico'.
|
0
|
259 |
"
|
|
260 |
!
|
|
261 |
|
41
|
262 |
fromWindowsBMPStream:aStream
|
21
|
263 |
| fileSize header inDepth inPlanes compression
|
|
264 |
imgSize resH resV numColor numImportantColor
|
|
265 |
dataStart
|
103
|
266 |
rawMap rMap gMap bMap srcIndex dstIndex inBytesPerRow
|
21
|
267 |
data4 mask tmp bytesPerRow fourBytesPerColorInfo|
|
|
268 |
|
41
|
269 |
inStream := aStream.
|
|
270 |
aStream binary.
|
|
271 |
|
|
272 |
fileSize := aStream size.
|
21
|
273 |
"read the header"
|
|
274 |
|
|
275 |
header := ByteArray uninitializedNew:16r54.
|
41
|
276 |
aStream nextBytes:18 into:header.
|
21
|
277 |
|
|
278 |
((header at:(16r0E + 1)) == 40) ifTrue:[ "header-size"
|
28
|
279 |
"
|
|
280 |
its an Windows3.x BMP file
|
|
281 |
or OS/2 vsn 2 BMP file
|
|
282 |
"
|
|
283 |
'BMP: Win3.x or OS/2 vsn 2 format' errorPrintNL.
|
21
|
284 |
|
41
|
285 |
aStream nextBytes:(40-4) into:header startingAt:19.
|
21
|
286 |
|
83
|
287 |
width := header wordAt:(16r12 + 1) MSB:false. "(header at:19) + ((header at:20) * 256). "
|
|
288 |
height := header wordAt:(16r16 + 1) MSB:false. "(header at:23) + ((header at:24) * 256). "
|
|
289 |
inPlanes := header wordAt:(16r1A + 1) MSB:false.
|
|
290 |
inDepth := header wordAt:(16r1C + 1) MSB:false.
|
|
291 |
compression := header wordAt:(16r1E + 1) MSB:false.
|
|
292 |
imgSize := header doubleWordAt:(16r22 + 1) MSB:false.
|
|
293 |
resH := header doubleWordAt:(16r26 + 1) MSB:false.
|
|
294 |
resV := header doubleWordAt:(16r2A + 1) MSB:false.
|
|
295 |
numColor := header doubleWordAt:(16r2E + 1) MSB:false.
|
|
296 |
numImportantColor := header doubleWordAt:(16r32 + 1) MSB:false.
|
21
|
297 |
|
28
|
298 |
numColor == 0 ifTrue:[
|
|
299 |
"
|
|
300 |
some bmp-writers seem to leave this as zero (which is wrong)
|
|
301 |
"
|
|
302 |
numColor := 1 bitShift:inDepth.
|
|
303 |
'BMP: missing nColor in header - assume ' errorPrint. numColor errorPrintNL
|
|
304 |
].
|
|
305 |
rawMap := ByteArray uninitializedNew:(numColor * 4).
|
41
|
306 |
aStream nextBytes:(numColor * 4) into:rawMap.
|
28
|
307 |
fourBytesPerColorInfo := true.
|
83
|
308 |
dataStart := header wordAt:(16r0A + 1) MSB:false
|
21
|
309 |
] ifFalse:[
|
28
|
310 |
((header at:(16r0E + 1)) == 12) ifTrue:[ "core-info header size"
|
|
311 |
"
|
|
312 |
its an OS/2 (vsn1.2) BMP file
|
|
313 |
"
|
|
314 |
'BMP: OS/2 vsn 1.2 format' errorPrintNL.
|
41
|
315 |
aStream nextBytes:(12-4) into:header startingAt:19.
|
21
|
316 |
|
83
|
317 |
width := header wordAt:(16r12 + 1) MSB:false. "(header at:19) + ((header at:20) * 256). "
|
|
318 |
height := header wordAt:(16r14 + 1) MSB:false. "(header at:21) + ((header at:22) * 256). "
|
|
319 |
inPlanes := header wordAt:(16r16 + 1) MSB:false.
|
|
320 |
inDepth := header wordAt:(16r18 + 1) MSB:false.
|
28
|
321 |
numColor := 1 bitShift:inDepth.
|
|
322 |
rawMap := ByteArray uninitializedNew:(numColor * 3).
|
41
|
323 |
aStream nextBytes:(numColor * 3) into:rawMap.
|
28
|
324 |
fourBytesPerColorInfo := false.
|
|
325 |
compression := 0.
|
83
|
326 |
dataStart := header wordAt:(16r0A + 1) MSB:false
|
28
|
327 |
] ifFalse:[
|
|
328 |
'BMP: unknown format' errorPrintNL.
|
|
329 |
^ nil
|
|
330 |
].
|
21
|
331 |
].
|
|
332 |
|
|
333 |
"read the colormap"
|
|
334 |
|
|
335 |
rMap := Array new:numColor.
|
|
336 |
gMap := Array new:numColor.
|
|
337 |
bMap := Array new:numColor.
|
|
338 |
srcIndex := 1.
|
|
339 |
1 to:numColor do:[:i |
|
28
|
340 |
bMap at:i put:(rawMap at:srcIndex).
|
|
341 |
srcIndex := srcIndex + 1.
|
|
342 |
gMap at:i put:(rawMap at:srcIndex).
|
|
343 |
srcIndex := srcIndex + 1.
|
|
344 |
rMap at:i put:(rawMap at:srcIndex).
|
|
345 |
srcIndex := srcIndex + 1.
|
|
346 |
fourBytesPerColorInfo ifTrue:[
|
|
347 |
srcIndex := srcIndex + 1.
|
|
348 |
]
|
21
|
349 |
].
|
|
350 |
|
102
|
351 |
"/ "
|
|
352 |
"/ currently only normal (non-rle) bitmaps
|
|
353 |
"/ supported
|
|
354 |
"/ "
|
|
355 |
"/ compression ~~ 0 ifTrue:[
|
|
356 |
"/ 'BMP compression type ' errorPrint. compression errorPrint.
|
|
357 |
"/ 'not supported' errorPrintNL.
|
|
358 |
"/ ^ nil
|
|
359 |
"/ ].
|
|
360 |
"/ inPlanes ~~ 1 ifTrue:[
|
|
361 |
"/ 'BMP only 1 plane images supported' errorPrintNL.
|
|
362 |
"/ ^ nil
|
|
363 |
"/ ].
|
|
364 |
"/
|
|
365 |
"/ "read the data bits"
|
|
366 |
"/
|
|
367 |
"/ bytesPerRow := width * inDepth + 7 // 8.
|
|
368 |
"/ data4 := ByteArray uninitializedNew:(height * bytesPerRow).
|
|
369 |
"/
|
|
370 |
"/ aStream position:(dataStart + 1).
|
|
371 |
"/ aStream nextBytes:(height * bytesPerRow) into:data4.
|
|
372 |
"/
|
|
373 |
"/ "read mask"
|
|
374 |
"/
|
|
375 |
"/"
|
|
376 |
"/ mask := ByteArray new:(width * height / 8).
|
|
377 |
"/ aStream nextBytes:(width * height / 8) into:mask.
|
|
378 |
"/"
|
|
379 |
"/
|
|
380 |
"/ "stupid: last row first"
|
|
381 |
"/
|
|
382 |
"/ tmp := ByteArray uninitializedNew:(height * bytesPerRow).
|
|
383 |
"/ srcIndex := 1.
|
|
384 |
"/ dstIndex := (height - 1) * bytesPerRow + 1.
|
|
385 |
"/ 1 to:height do:[:row |
|
|
386 |
"/ tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1)
|
|
387 |
"/ with:data4 startingAt:srcIndex.
|
|
388 |
"/ srcIndex := srcIndex + bytesPerRow.
|
|
389 |
"/ dstIndex := dstIndex - bytesPerRow.
|
|
390 |
"/ ].
|
|
391 |
"/ data4 := tmp.
|
103
|
392 |
"/ data := ByteArray new:(width * height).
|
|
393 |
"/ data4 expandPixels:inDepth width:width height:height
|
|
394 |
"/ into:data mapping:nil.
|
|
395 |
"/
|
102
|
396 |
|
21
|
397 |
compression ~~ 0 ifTrue:[
|
102
|
398 |
"/ some compression
|
|
399 |
compression == 1 ifTrue:[
|
|
400 |
"/ RLE8 - must be depth-8
|
|
401 |
inDepth == 8 ifFalse:[
|
|
402 |
'BMP: RLE8 compression only allowed with depth8 images' errorPrintNL.
|
|
403 |
^ nil
|
|
404 |
].
|
|
405 |
].
|
|
406 |
compression == 2 ifTrue:[
|
|
407 |
"/ RLE4 - must be depth-4
|
|
408 |
inDepth == 4 ifFalse:[
|
|
409 |
'BMP: RLE4 compression only allowed with depth4 images' errorPrintNL.
|
|
410 |
^ nil
|
|
411 |
].
|
|
412 |
].
|
21
|
413 |
].
|
102
|
414 |
|
21
|
415 |
inPlanes ~~ 1 ifTrue:[
|
102
|
416 |
'BMP: only 1 plane images supported' errorPrintNL.
|
28
|
417 |
^ nil
|
21
|
418 |
].
|
|
419 |
|
|
420 |
bytesPerRow := width * inDepth + 7 // 8.
|
102
|
421 |
"/ bmp data is always 32bit aligned; if required,
|
|
422 |
inBytesPerRow := ((bytesPerRow + 3) // 4) * 4.
|
41
|
423 |
aStream position:(dataStart + 1).
|
21
|
424 |
|
102
|
425 |
data := ByteArray uninitializedNew:(height * width "bytesPerRow").
|
103
|
426 |
(self loadBMPWidth:width height:height depth:inDepth compression:compression from:aStream into:data) ifFalse:[
|
|
427 |
^ nil
|
21
|
428 |
].
|
|
429 |
"expand into bytes"
|
|
430 |
|
|
431 |
photometric := #palette.
|
|
432 |
samplesPerPixel := 1.
|
|
433 |
bitsPerSample := #(8).
|
36
|
434 |
colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
|
103
|
435 |
|
|
436 |
"Modified: 17.9.1995 / 18:48:46 / claus"
|
21
|
437 |
!
|
|
438 |
|
41
|
439 |
fromStream:aStream
|
21
|
440 |
| fileSize header |
|
0
|
441 |
|
41
|
442 |
inStream := aStream.
|
0
|
443 |
|
41
|
444 |
aStream binary.
|
|
445 |
fileSize := aStream size.
|
0
|
446 |
|
21
|
447 |
fileSize < 16 ifTrue:[
|
41
|
448 |
'WINREADER: short file' errorPrintNL.
|
28
|
449 |
^ nil
|
21
|
450 |
].
|
|
451 |
|
|
452 |
header := ByteArray uninitializedNew:4.
|
41
|
453 |
aStream nextBytes:4 into:header.
|
21
|
454 |
|
|
455 |
(header startsWith:#(66 77)) ifTrue:[ "BM"
|
41
|
456 |
aStream position:1.
|
28
|
457 |
'WINREADER: Win3.x or OS/2 vsn 2 BM format' errorPrintNL.
|
41
|
458 |
^ self fromWindowsBMPStream:aStream
|
21
|
459 |
].
|
|
460 |
(header startsWith:#(66 65)) ifTrue:[ "BA"
|
41
|
461 |
aStream position:1.
|
28
|
462 |
'WINREADER: OS/2 vsn 2 BA format' errorPrintNL.
|
41
|
463 |
^ self fromOS2Stream:aStream
|
21
|
464 |
].
|
|
465 |
(header startsWith:#(73 67)) ifTrue:[ "IC"
|
41
|
466 |
aStream position:1.
|
28
|
467 |
'WINREADER: OS/2 IC format' errorPrintNL.
|
41
|
468 |
^ self fromOS2Stream:aStream
|
21
|
469 |
].
|
|
470 |
(header startsWith:#(80 84)) ifTrue:[ "PT"
|
41
|
471 |
aStream position:1.
|
28
|
472 |
'WINREADER: OS/2 PT format' errorPrintNL.
|
41
|
473 |
^ self fromOS2Stream:aStream
|
21
|
474 |
].
|
103
|
475 |
(header startsWith:#(16r53 16r5A)) ifTrue:[ "SZ"
|
|
476 |
'WINREADER: SZ format not supported:' errorPrintNL.
|
|
477 |
^ nil.
|
|
478 |
aStream position:1.
|
|
479 |
'WINREADER: OS/2 PT format' errorPrintNL.
|
|
480 |
^ self fromOS2Stream:aStream
|
|
481 |
].
|
21
|
482 |
(header startsWith:#(0 0 1 0)) ifTrue:[
|
41
|
483 |
aStream position:1.
|
28
|
484 |
'WINREADER: Win3.x ICO format' errorPrintNL.
|
41
|
485 |
^ self fromWindowsICOStream:aStream
|
21
|
486 |
].
|
103
|
487 |
'WINREADER: format not supported:' errorPrint.
|
|
488 |
((header at:1) printStringRadix:16) errorPrint.
|
|
489 |
' ' errorPrint.
|
|
490 |
((header at:2) printStringRadix:16) errorPrintNL.
|
21
|
491 |
^ nil
|
|
492 |
|
|
493 |
"
|
|
494 |
Image fromFile:'/phys/clam//LocalLibrary/Images/OS2_icons/dos.ico'
|
|
495 |
"
|
103
|
496 |
|
|
497 |
"Modified: 17.9.1995 / 18:59:07 / claus"
|
21
|
498 |
!
|
|
499 |
|
41
|
500 |
fromOS2Stream:aStream
|
21
|
501 |
| header inDepth
|
103
|
502 |
rawMap rMap gMap bMap srcIndex dstIndex inBytesPerRow
|
21
|
503 |
data4 mask tmp bytesPerRow nColors nByte|
|
|
504 |
|
41
|
505 |
inStream := aStream.
|
|
506 |
aStream binary.
|
21
|
507 |
|
0
|
508 |
"read the header"
|
|
509 |
|
3
|
510 |
header := ByteArray uninitializedNew:8r110.
|
41
|
511 |
aStream nextBytes:16 into:header.
|
21
|
512 |
|
0
|
513 |
(header startsWith:#(73 67)) ifTrue:[
|
28
|
514 |
"IC format"
|
41
|
515 |
aStream nextBytes:10 into:header startingAt:17.
|
28
|
516 |
width := header at:7.
|
|
517 |
height := header at:9.
|
|
518 |
inDepth := 2 "header at:11". "where is it"
|
0
|
519 |
] ifFalse:[
|
41
|
520 |
aStream nextBytes:(8r110-16) into:header startingAt:17.
|
28
|
521 |
width := header at:8r101.
|
|
522 |
height := header at:8r103.
|
|
523 |
inDepth := header at:8r107.
|
0
|
524 |
].
|
|
525 |
|
|
526 |
"read the colormap"
|
|
527 |
|
|
528 |
nColors := 1 bitShift:inDepth.
|
|
529 |
|
3
|
530 |
rawMap := ByteArray uninitializedNew:(nColors*3).
|
41
|
531 |
aStream nextBytes:(nColors*3) into:rawMap.
|
0
|
532 |
rMap := Array new:nColors.
|
|
533 |
gMap := Array new:nColors.
|
|
534 |
bMap := Array new:nColors.
|
|
535 |
srcIndex := 1.
|
|
536 |
1 to:nColors do:[:i |
|
28
|
537 |
bMap at:i put:(rawMap at:srcIndex).
|
|
538 |
srcIndex := srcIndex + 1.
|
|
539 |
gMap at:i put:(rawMap at:srcIndex).
|
|
540 |
srcIndex := srcIndex + 1.
|
|
541 |
rMap at:i put:(rawMap at:srcIndex).
|
|
542 |
srcIndex := srcIndex + 1.
|
0
|
543 |
].
|
|
544 |
|
|
545 |
"read mask"
|
|
546 |
|
3
|
547 |
nByte := width * height + 7 // 8.
|
|
548 |
mask := ByteArray uninitializedNew:nByte.
|
41
|
549 |
aStream nextBytes:nByte into:mask.
|
0
|
550 |
|
|
551 |
"what is this"
|
|
552 |
|
41
|
553 |
aStream nextBytes:nByte into:mask.
|
0
|
554 |
|
103
|
555 |
"/ "read the data bits"
|
|
556 |
"/
|
|
557 |
"/ bytesPerRow := width * inDepth + 7 // 8.
|
|
558 |
"/ data4 := ByteArray uninitializedNew:(height * bytesPerRow).
|
|
559 |
"/ inDepth == 8 ifTrue:[
|
|
560 |
"/ ].
|
|
561 |
"/ aStream nextBytes:(height * bytesPerRow) into:data4.
|
|
562 |
"/
|
|
563 |
"/ "stupid: last row first"
|
|
564 |
"/
|
|
565 |
"/ tmp := ByteArray new:(height * bytesPerRow).
|
|
566 |
"/ srcIndex := 1.
|
|
567 |
"/ dstIndex := (height - 1) * bytesPerRow + 1.
|
|
568 |
"/ 1 to:height do:[:row |
|
|
569 |
"/ tmp replaceFrom:dstIndex to:(dstIndex + bytesPerRow - 1)
|
|
570 |
"/ with:data4 startingAt:srcIndex.
|
|
571 |
"/ srcIndex := srcIndex + bytesPerRow.
|
|
572 |
"/ dstIndex := dstIndex - bytesPerRow.
|
|
573 |
"/ ].
|
|
574 |
"/ data4 := tmp.
|
|
575 |
"/
|
|
576 |
"/ "expand into bytes"
|
|
577 |
"/
|
|
578 |
"/ data := ByteArray new:(width * height).
|
|
579 |
"/ data4 expandPixels:inDepth width:width height:height
|
|
580 |
"/ into:data mapping:nil.
|
|
581 |
"/
|
0
|
582 |
|
3
|
583 |
bytesPerRow := width * inDepth + 7 // 8.
|
103
|
584 |
"/ bmp data is always 32bit aligned; if required,
|
|
585 |
inBytesPerRow := ((bytesPerRow + 3) // 4) * 4.
|
0
|
586 |
|
103
|
587 |
data := ByteArray uninitializedNew:(height * width "bytesPerRow").
|
|
588 |
(self loadBMPWidth:width height:height depth:inDepth compression:0 from:aStream into:data) ifFalse:[
|
|
589 |
^ nil
|
0
|
590 |
].
|
|
591 |
photometric := #palette.
|
|
592 |
samplesPerPixel := 1.
|
|
593 |
bitsPerSample := #(8).
|
36
|
594 |
colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
|
0
|
595 |
|
|
596 |
"
|
|
597 |
|i f|
|
|
598 |
i := Image fromFile:'/LocalLibrary/Images/OS2/dos3.ico'.
|
|
599 |
f := i asFormOn:Display.
|
18
|
600 |
v displayOpaqueForm:(f magnifyBy:2@2) x:5 y:5
|
0
|
601 |
"
|
103
|
602 |
|
|
603 |
"Modified: 17.9.1995 / 18:49:24 / claus"
|
0
|
604 |
! !
|