3121
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2013 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
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 |
"{ Package: 'stx:libview2' }"
|
|
13 |
|
|
14 |
ImageReader subclass:#MacOSXIconReader
|
|
15 |
instanceVariableNames:'image'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Graphics-Images-Readers'
|
|
19 |
!
|
|
20 |
|
|
21 |
!MacOSXIconReader class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 2013 by Claus Gittinger
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
!
|
|
36 |
|
|
37 |
documentation
|
|
38 |
"
|
|
39 |
Reader for mac osx icon files.
|
|
40 |
|
|
41 |
These files are actually bundles of a sequence of icons (in possibly different resolutions,
|
|
42 |
colors and sizes).
|
|
43 |
When such a file is read, I return the first image as usual,
|
|
44 |
and all images as an imagesequence.
|
|
45 |
|
3133
|
46 |
Only a subset of the supported image formats are supported by the writer
|
|
47 |
(i.e. JPEG and PNG based image encodings only).
|
|
48 |
This means, that only 10.8-and later icon files are really generated.
|
|
49 |
|
|
50 |
caveat:
|
|
51 |
only a subset of the possibly formats are supported when reading.
|
3121
|
52 |
|
|
53 |
[See also:]
|
|
54 |
Image Form Icon
|
|
55 |
GIFReader JPEGReader PNGReader TIFFReader WindowsIconReader
|
3132
|
56 |
http://en.wikipedia.org/wiki/Apple_Icon_Image_format
|
3121
|
57 |
"
|
|
58 |
! !
|
|
59 |
|
|
60 |
!MacOSXIconReader class methodsFor:'initialization'!
|
|
61 |
|
|
62 |
initialize
|
|
63 |
"install myself in the Image classes fileFormat table
|
|
64 |
for the `.icns' extension."
|
|
65 |
|
|
66 |
"/ MIMETypes defineImageType:'image/x-icns' suffix:'icns' reader:self.
|
|
67 |
MIMETypes defineImageType:nil suffix:'icns' reader:self.
|
|
68 |
! !
|
|
69 |
|
|
70 |
!MacOSXIconReader class methodsFor:'testing'!
|
|
71 |
|
|
72 |
canRepresent:anImage
|
|
73 |
"return true, if anImage can be represented in my file format.
|
|
74 |
Assuming that we store in PNG format, delegate that decision."
|
|
75 |
|
|
76 |
^ PNGReader canRepresent:anImage
|
|
77 |
!
|
|
78 |
|
|
79 |
isValidImageFile:aFileName
|
|
80 |
"return true, if aFileName is an apple osx icon file"
|
|
81 |
|
|
82 |
|id inStream|
|
|
83 |
|
|
84 |
inStream := self streamReadingFile:aFileName.
|
|
85 |
inStream isNil ifTrue:[^ false].
|
|
86 |
|
|
87 |
inStream text.
|
|
88 |
|
|
89 |
id := String new:4.
|
|
90 |
inStream nextBytes:4 into:id.
|
|
91 |
inStream close.
|
|
92 |
|
|
93 |
^ (id = 'icns')
|
|
94 |
! !
|
|
95 |
|
|
96 |
!MacOSXIconReader methodsFor:'image reading'!
|
|
97 |
|
|
98 |
fromStream:aStream
|
|
99 |
"read a stream containing an icon image (or a collection of images).
|
|
100 |
Leave image description in instance variables."
|
|
101 |
|
|
102 |
|sizeRemaining id img firstImage frame imageCount chunkType numChunkBytes chunkData|
|
|
103 |
|
|
104 |
inStream := aStream.
|
|
105 |
aStream text.
|
|
106 |
|
|
107 |
"icon-files are always msb"
|
|
108 |
byteOrder := #msb.
|
|
109 |
|
|
110 |
id := aStream nextBytes:4.
|
|
111 |
id size ~~ 4 ifTrue:[
|
|
112 |
^ self fileFormatError:'not an icns file (short read)'.
|
|
113 |
].
|
|
114 |
id := id asString.
|
3133
|
115 |
sizeRemaining := aStream nextUnsignedLongMSB:true.
|
|
116 |
sizeRemaining := sizeRemaining - 4 - 4. "/ file magic and size are included in count
|
3121
|
117 |
|
|
118 |
(id ~= 'icns') ifTrue:[
|
3133
|
119 |
chunkData := aStream next:sizeRemaining.
|
|
120 |
image := self readSingleIcon:chunkType from:chunkData.
|
|
121 |
^ self
|
3121
|
122 |
].
|
|
123 |
|
|
124 |
imageCount := 0.
|
|
125 |
[ sizeRemaining > 0 ] whileTrue:[
|
|
126 |
chunkType := aStream nextBytes:4.
|
|
127 |
chunkType size ~~ 4 ifTrue:[
|
|
128 |
^ self fileFormatError:'not an icns file (short read on icon type)'.
|
|
129 |
].
|
|
130 |
chunkType := chunkType asString.
|
|
131 |
|
|
132 |
numChunkBytes := aStream nextUnsignedLongMSB:true.
|
|
133 |
numChunkBytes := numChunkBytes - 4 - 4. "/ type and size are included in count
|
|
134 |
|
|
135 |
chunkData := aStream next:numChunkBytes.
|
|
136 |
sizeRemaining := sizeRemaining - 4 - numChunkBytes.
|
|
137 |
|
|
138 |
img := self readSingleIcon:chunkType from:chunkData.
|
3381
|
139 |
img notNil ifTrue:[
|
|
140 |
imageCount == 0 ifTrue:[
|
|
141 |
firstImage := image := img.
|
|
142 |
] ifFalse:[
|
|
143 |
imageCount == 1 ifTrue:[
|
|
144 |
imageSequence := ImageSequence new.
|
|
145 |
img imageSequence:imageSequence.
|
3121
|
146 |
|
3381
|
147 |
"/ add frame for first image.
|
|
148 |
frame := ImageFrame new image:firstImage.
|
|
149 |
imageSequence add:frame.
|
|
150 |
].
|
|
151 |
img notNil ifTrue:[
|
|
152 |
"/ unsupported images are skipped...
|
|
153 |
img imageSequence:imageSequence.
|
|
154 |
].
|
|
155 |
|
|
156 |
"/ add frame for this image.
|
|
157 |
frame := ImageFrame new image:img.
|
3121
|
158 |
imageSequence add:frame.
|
3133
|
159 |
].
|
3381
|
160 |
imageCount := imageCount + 1.
|
3121
|
161 |
].
|
|
162 |
].
|
3381
|
163 |
self halt.
|
3121
|
164 |
"
|
|
165 |
Image fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
166 |
"
|
|
167 |
!
|
|
168 |
|
|
169 |
readSingleIcon:iconType from:iconBytes
|
|
170 |
"read a single image from the inputStream."
|
|
171 |
|
|
172 |
^ self
|
|
173 |
perform:('read_',(iconType copyReplaceAll:$# with:$_),'_from:') asSymbol
|
|
174 |
with:iconBytes
|
|
175 |
ifNotUnderstood:[
|
|
176 |
self breakPoint:#cg.
|
|
177 |
('MacOSXIconReader: unsupported icon format: ',iconType) infoPrintCR.
|
|
178 |
^ self fileFormatError:'unsupported icon format: ',iconType
|
|
179 |
].
|
|
180 |
|
|
181 |
"
|
|
182 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
183 |
self fromFile:'test.icns'
|
|
184 |
"
|
|
185 |
! !
|
|
186 |
|
|
187 |
!MacOSXIconReader methodsFor:'image writing'!
|
|
188 |
|
|
189 |
save:anImage onStream:aStream
|
|
190 |
"save an icon to aStream."
|
|
191 |
|
|
192 |
self saveAll:(Array with:anImage) onStream:aStream.
|
|
193 |
|
|
194 |
"
|
|
195 |
self
|
|
196 |
save:(Image fromScreen:(0@0 corner:16@16))
|
|
197 |
onFile:'test.icns'
|
|
198 |
"
|
|
199 |
!
|
|
200 |
|
|
201 |
saveAll:aCollectionOfImages onStream:aStream
|
|
202 |
"save a number of images to aStream."
|
|
203 |
|
|
204 |
|tempFile tempFileStream|
|
|
205 |
|
|
206 |
(aCollectionOfImages conform:
|
|
207 |
[:eachImage |
|
|
208 |
(eachImage width = eachImage height)
|
|
209 |
and:[ (#(16 32 128 256 512 1024) includes:eachImage width)]
|
|
210 |
]
|
|
211 |
) ifFalse:[
|
|
212 |
^ self fileFormatError:'unsupported image size (must be square and width 16, 32, 128, 512 or 1024)'.
|
|
213 |
].
|
|
214 |
|
3157
|
215 |
tempFile := AutoDeletedFilename newTemporary.
|
3121
|
216 |
tempFileStream := tempFile writeStream.
|
|
217 |
tempFileStream binary.
|
|
218 |
|
|
219 |
aCollectionOfImages do:[:eachImage |
|
|
220 |
|typeCode s data|
|
|
221 |
|
|
222 |
s := WriteStream on:(ByteArray new:1024).
|
|
223 |
PNGReader save:eachImage onStream:s.
|
|
224 |
data := s contents.
|
|
225 |
self assert:data notEmptyOrNil.
|
|
226 |
|
|
227 |
typeCode := #(16 32 128 256 512 1024)
|
|
228 |
map: #('ipc4' 'ipc5' 'ic07' 'ic08' 'ic09' 'ic10')
|
|
229 |
at:eachImage width ifAbsent:[self error].
|
|
230 |
tempFileStream nextPutBytes:typeCode.
|
|
231 |
tempFileStream nextPutLong:(data size + 4 + 4) MSB:true.
|
|
232 |
tempFileStream nextPutAll:data.
|
|
233 |
].
|
|
234 |
tempFileStream close.
|
|
235 |
|
|
236 |
aStream binary.
|
|
237 |
aStream nextPutBytes:'icns'.
|
|
238 |
aStream nextPutLong:(tempFile fileSize + 4 + 4) MSB:true.
|
|
239 |
aStream nextPutAll:(tempFile binaryContentsOfEntireFile).
|
|
240 |
tempFile delete.
|
|
241 |
|
|
242 |
"
|
|
243 |
self
|
|
244 |
save:(Image fromScreen:(0@0 corner:16@16))
|
|
245 |
onFile:'test.icns'
|
|
246 |
"
|
|
247 |
! !
|
|
248 |
|
|
249 |
!MacOSXIconReader methodsFor:'private'!
|
|
250 |
|
3133
|
251 |
colormap4
|
3135
|
252 |
^ #[
|
3134
|
253 |
16rFF 16rFF 16rFF
|
|
254 |
16rFC 16rF3 16r05
|
|
255 |
16rFF 16r64 16r02
|
|
256 |
16rDD 16r08 16r06
|
|
257 |
16rF2 16r08 16r84
|
|
258 |
16r46 16r00 16rA5
|
|
259 |
16r00 16r00 16rD4
|
|
260 |
16r02 16rAB 16rEA
|
|
261 |
16r1F 16rB7 16r14
|
|
262 |
16r00 16r64 16r11
|
|
263 |
16r56 16r2C 16r05
|
|
264 |
16r90 16r71 16r3A
|
|
265 |
16rC0 16rC0 16rC0
|
|
266 |
16r80 16r80 16r80
|
|
267 |
16r40 16r40 16r40
|
3135
|
268 |
16r00 16r00 16r00
|
|
269 |
]
|
3133
|
270 |
!
|
|
271 |
|
|
272 |
colormap8
|
3135
|
273 |
^ #[
|
3134
|
274 |
16rFF 16rFF 16rFF
|
|
275 |
16rFF 16rFF 16rCC
|
|
276 |
16rFF 16rFF 16r99
|
|
277 |
16rFF 16rFF 16r66
|
|
278 |
16rFF 16rFF 16r33
|
|
279 |
16rFF 16rFF 16r00
|
|
280 |
16rFF 16rCC 16rFF
|
|
281 |
16rFF 16rCC 16rCC
|
|
282 |
16rFF 16rCC 16r99
|
|
283 |
16rFF 16rCC 16r66
|
|
284 |
16rFF 16rCC 16r33
|
|
285 |
16rFF 16rCC 16r00
|
|
286 |
16rFF 16r99 16rFF
|
|
287 |
16rFF 16r99 16rCC
|
|
288 |
16rFF 16r99 16r99
|
|
289 |
16rFF 16r99 16r66
|
|
290 |
16rFF 16r99 16r33
|
|
291 |
16rFF 16r99 16r00
|
|
292 |
16rFF 16r66 16rFF
|
|
293 |
16rFF 16r66 16rCC
|
|
294 |
16rFF 16r66 16r99
|
|
295 |
16rFF 16r66 16r66
|
|
296 |
16rFF 16r66 16r33
|
|
297 |
16rFF 16r66 16r00
|
|
298 |
16rFF 16r33 16rFF
|
|
299 |
16rFF 16r33 16rCC
|
|
300 |
16rFF 16r33 16r99
|
|
301 |
16rFF 16r33 16r66
|
|
302 |
16rFF 16r33 16r33
|
|
303 |
16rFF 16r33 16r00
|
|
304 |
16rFF 16r00 16rFF
|
|
305 |
16rFF 16r00 16rCC
|
|
306 |
16rFF 16r00 16r99
|
|
307 |
16rFF 16r00 16r66
|
|
308 |
16rFF 16r00 16r33
|
|
309 |
16rFF 16r00 16r00
|
|
310 |
16rCC 16rFF 16rFF
|
|
311 |
16rCC 16rFF 16rCC
|
|
312 |
16rCC 16rFF 16r99
|
|
313 |
16rCC 16rFF 16r66
|
|
314 |
16rCC 16rFF 16r33
|
|
315 |
16rCC 16rFF 16r00
|
|
316 |
16rCC 16rCC 16rFF
|
|
317 |
16rCC 16rCC 16rCC
|
|
318 |
16rCC 16rCC 16r99
|
|
319 |
16rCC 16rCC 16r66
|
|
320 |
16rCC 16rCC 16r33
|
|
321 |
16rCC 16rCC 16r00
|
|
322 |
16rCC 16r99 16rFF
|
|
323 |
16rCC 16r99 16rCC
|
|
324 |
16rCC 16r99 16r99
|
|
325 |
16rCC 16r99 16r66
|
|
326 |
16rCC 16r99 16r33
|
|
327 |
16rCC 16r99 16r00
|
|
328 |
16rCC 16r66 16rFF
|
|
329 |
16rCC 16r66 16rCC
|
|
330 |
16rCC 16r66 16r99
|
|
331 |
16rCC 16r66 16r66
|
|
332 |
16rCC 16r66 16r33
|
|
333 |
16rCC 16r66 16r00
|
|
334 |
16rCC 16r33 16rFF
|
|
335 |
16rCC 16r33 16rCC
|
|
336 |
16rCC 16r33 16r99
|
|
337 |
16rCC 16r33 16r66
|
|
338 |
16rCC 16r33 16r33
|
|
339 |
16rCC 16r33 16r00
|
|
340 |
16rCC 16r00 16rFF
|
|
341 |
16rCC 16r00 16rCC
|
|
342 |
16rCC 16r00 16r99
|
|
343 |
16rCC 16r00 16r66
|
|
344 |
16rCC 16r00 16r33
|
|
345 |
16rCC 16r00 16r00
|
|
346 |
16r99 16rFF 16rFF
|
|
347 |
16r99 16rFF 16rCC
|
|
348 |
16r99 16rFF 16r99
|
|
349 |
16r99 16rFF 16r66
|
|
350 |
16r99 16rFF 16r33
|
|
351 |
16r99 16rFF 16r00
|
|
352 |
16r99 16rCC 16rFF
|
|
353 |
16r99 16rCC 16rCC
|
|
354 |
16r99 16rCC 16r99
|
|
355 |
16r99 16rCC 16r66
|
|
356 |
16r99 16rCC 16r33
|
|
357 |
16r99 16rCC 16r00
|
|
358 |
16r99 16r99 16rFF
|
|
359 |
16r99 16r99 16rCC
|
|
360 |
16r99 16r99 16r99
|
|
361 |
16r99 16r99 16r66
|
|
362 |
16r99 16r99 16r33
|
|
363 |
16r99 16r99 16r00
|
|
364 |
16r99 16r66 16rFF
|
|
365 |
16r99 16r66 16rCC
|
|
366 |
16r99 16r66 16r99
|
|
367 |
16r99 16r66 16r66
|
|
368 |
16r99 16r66 16r33
|
|
369 |
16r99 16r66 16r00
|
|
370 |
16r99 16r33 16rFF
|
|
371 |
16r99 16r33 16rCC
|
|
372 |
16r99 16r33 16r99
|
|
373 |
16r99 16r33 16r66
|
|
374 |
16r99 16r33 16r33
|
|
375 |
16r99 16r33 16r00
|
|
376 |
16r99 16r00 16rFF
|
|
377 |
16r99 16r00 16rCC
|
|
378 |
16r99 16r00 16r99
|
|
379 |
16r99 16r00 16r66
|
|
380 |
16r99 16r00 16r33
|
|
381 |
16r99 16r00 16r00
|
|
382 |
16r66 16rFF 16rFF
|
|
383 |
16r66 16rFF 16rCC
|
|
384 |
16r66 16rFF 16r99
|
|
385 |
16r66 16rFF 16r66
|
|
386 |
16r66 16rFF 16r33
|
|
387 |
16r66 16rFF 16r00
|
|
388 |
16r66 16rCC 16rFF
|
|
389 |
16r66 16rCC 16rCC
|
|
390 |
16r66 16rCC 16r99
|
|
391 |
16r66 16rCC 16r66
|
|
392 |
16r66 16rCC 16r33
|
|
393 |
16r66 16rCC 16r00
|
|
394 |
16r66 16r99 16rFF
|
|
395 |
16r66 16r99 16rCC
|
|
396 |
16r66 16r99 16r99
|
|
397 |
16r66 16r99 16r66
|
|
398 |
16r66 16r99 16r33
|
|
399 |
16r66 16r99 16r00
|
|
400 |
16r66 16r66 16rFF
|
|
401 |
16r66 16r66 16rCC
|
|
402 |
16r66 16r66 16r99
|
|
403 |
16r66 16r66 16r66
|
|
404 |
16r66 16r66 16r33
|
|
405 |
16r66 16r66 16r00
|
|
406 |
16r66 16r33 16rFF
|
|
407 |
16r66 16r33 16rCC
|
|
408 |
16r66 16r33 16r99
|
|
409 |
16r66 16r33 16r66
|
|
410 |
16r66 16r33 16r33
|
|
411 |
16r66 16r33 16r00
|
|
412 |
16r66 16r00 16rFF
|
|
413 |
16r66 16r00 16rCC
|
|
414 |
16r66 16r00 16r99
|
|
415 |
16r66 16r00 16r66
|
|
416 |
16r66 16r00 16r33
|
|
417 |
16r66 16r00 16r00
|
|
418 |
16r33 16rFF 16rFF
|
|
419 |
16r33 16rFF 16rCC
|
|
420 |
16r33 16rFF 16r99
|
|
421 |
16r33 16rFF 16r66
|
|
422 |
16r33 16rFF 16r33
|
|
423 |
16r33 16rFF 16r00
|
|
424 |
16r33 16rCC 16rFF
|
|
425 |
16r33 16rCC 16rCC
|
|
426 |
16r33 16rCC 16r99
|
|
427 |
16r33 16rCC 16r66
|
|
428 |
16r33 16rCC 16r33
|
|
429 |
16r33 16rCC 16r00
|
|
430 |
16r33 16r99 16rFF
|
|
431 |
16r33 16r99 16rCC
|
|
432 |
16r33 16r99 16r99
|
|
433 |
16r33 16r99 16r66
|
|
434 |
16r33 16r99 16r33
|
|
435 |
16r33 16r99 16r00
|
|
436 |
16r33 16r66 16rFF
|
|
437 |
16r33 16r66 16rCC
|
|
438 |
16r33 16r66 16r99
|
|
439 |
16r33 16r66 16r66
|
|
440 |
16r33 16r66 16r33
|
|
441 |
16r33 16r66 16r00
|
|
442 |
16r33 16r33 16rFF
|
|
443 |
16r33 16r33 16rCC
|
|
444 |
16r33 16r33 16r99
|
|
445 |
16r33 16r33 16r66
|
|
446 |
16r33 16r33 16r33
|
|
447 |
16r33 16r33 16r00
|
|
448 |
16r33 16r00 16rFF
|
|
449 |
16r33 16r00 16rCC
|
|
450 |
16r33 16r00 16r99
|
|
451 |
16r33 16r00 16r66
|
|
452 |
16r33 16r00 16r33
|
|
453 |
16r33 16r00 16r00
|
|
454 |
16r00 16rFF 16rFF
|
|
455 |
16r00 16rFF 16rCC
|
|
456 |
16r00 16rFF 16r99
|
|
457 |
16r00 16rFF 16r66
|
|
458 |
16r00 16rFF 16r33
|
|
459 |
16r00 16rFF 16r00
|
|
460 |
16r00 16rCC 16rFF
|
|
461 |
16r00 16rCC 16rCC
|
|
462 |
16r00 16rCC 16r99
|
|
463 |
16r00 16rCC 16r66
|
|
464 |
16r00 16rCC 16r33
|
|
465 |
16r00 16rCC 16r00
|
|
466 |
16r00 16r99 16rFF
|
|
467 |
16r00 16r99 16rCC
|
|
468 |
16r00 16r99 16r99
|
|
469 |
16r00 16r99 16r66
|
|
470 |
16r00 16r99 16r33
|
|
471 |
16r00 16r99 16r00
|
|
472 |
16r00 16r66 16rFF
|
|
473 |
16r00 16r66 16rCC
|
|
474 |
16r00 16r66 16r99
|
|
475 |
16r00 16r66 16r66
|
|
476 |
16r00 16r66 16r33
|
|
477 |
16r00 16r66 16r00
|
|
478 |
16r00 16r33 16rFF
|
|
479 |
16r00 16r33 16rCC
|
|
480 |
16r00 16r33 16r99
|
|
481 |
16r00 16r33 16r66
|
|
482 |
16r00 16r33 16r33
|
|
483 |
16r00 16r33 16r00
|
|
484 |
16r00 16r00 16rFF
|
|
485 |
16r00 16r00 16rCC
|
|
486 |
16r00 16r00 16r99
|
|
487 |
16r00 16r00 16r66
|
|
488 |
16r00 16r00 16r33
|
|
489 |
16rEE 16r00 16r00
|
|
490 |
16rDD 16r00 16r00
|
|
491 |
16rBB 16r00 16r00
|
|
492 |
16rAA 16r00 16r00
|
|
493 |
16r88 16r00 16r00
|
|
494 |
16r77 16r00 16r00
|
|
495 |
16r55 16r00 16r00
|
|
496 |
16r44 16r00 16r00
|
|
497 |
16r22 16r00 16r00
|
|
498 |
16r11 16r00 16r00
|
|
499 |
16r00 16rEE 16r00
|
|
500 |
16r00 16rDD 16r00
|
|
501 |
16r00 16rBB 16r00
|
|
502 |
16r00 16rAA 16r00
|
|
503 |
16r00 16r88 16r00
|
|
504 |
16r00 16r77 16r00
|
|
505 |
16r00 16r55 16r00
|
|
506 |
16r00 16r44 16r00
|
|
507 |
16r00 16r22 16r00
|
|
508 |
16r00 16r11 16r00
|
|
509 |
16r00 16r00 16rEE
|
|
510 |
16r00 16r00 16rDD
|
|
511 |
16r00 16r00 16rBB
|
|
512 |
16r00 16r00 16rAA
|
|
513 |
16r00 16r00 16r88
|
|
514 |
16r00 16r00 16r77
|
|
515 |
16r00 16r00 16r55
|
|
516 |
16r00 16r00 16r44
|
|
517 |
16r00 16r00 16r22
|
|
518 |
16r00 16r00 16r11
|
|
519 |
16rEE 16rEE 16rEE
|
|
520 |
16rDD 16rDD 16rDD
|
|
521 |
16rBB 16rBB 16rBB
|
|
522 |
16rAA 16rAA 16rAA
|
|
523 |
16r88 16r88 16r88
|
|
524 |
16r77 16r77 16r77
|
|
525 |
16r55 16r55 16r55
|
|
526 |
16r44 16r44 16r44
|
|
527 |
16r22 16r22 16r22
|
|
528 |
16r11 16r11 16r11
|
3135
|
529 |
16r00 16r00 16r00
|
|
530 |
]
|
3133
|
531 |
!
|
|
532 |
|
3121
|
533 |
makeImage
|
|
534 |
"image is already made"
|
|
535 |
|
|
536 |
^ image
|
|
537 |
! !
|
|
538 |
|
|
539 |
!MacOSXIconReader methodsFor:'private reading'!
|
|
540 |
|
3361
|
541 |
common_read_paletteImage_from:bytes size:size width:w height:h depth:d
|
|
542 |
"read an icl8/icl4/ics4/ics8 icon"
|
|
543 |
|
|
544 |
|pixelData img|
|
|
545 |
|
|
546 |
pixelData := (ByteArray new:size) replaceBytesWith:bytes; yourself.
|
|
547 |
img := (Image implementorForDepth:d) width:w height:h fromArray:pixelData.
|
|
548 |
img photometric:#palette.
|
|
549 |
d == 4 ifTrue:[
|
|
550 |
img colorMap:(Colormap rgbBytesVector:self colormap4).
|
|
551 |
] ifFalse:[
|
|
552 |
d == 8 ifTrue:[
|
|
553 |
img colorMap:(Colormap rgbBytesVector:self colormap8).
|
|
554 |
] ifFalse:[
|
|
555 |
self error:'unsupported depth'
|
|
556 |
].
|
|
557 |
].
|
|
558 |
^ img
|
|
559 |
|
|
560 |
"
|
|
561 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
562 |
"
|
|
563 |
!
|
|
564 |
|
3121
|
565 |
readPNGOrJPEGFrom:bytes expectedSize:expectedSizeOrNil
|
|
566 |
"read a PNG or JPEG image.
|
|
567 |
Helper for ipc4, ipc5, ic07, ic09, ic10 formats"
|
|
568 |
|
|
569 |
|img|
|
|
570 |
|
|
571 |
img := PNGReader fromStream:(bytes readStream).
|
|
572 |
img isNil ifTrue:[
|
|
573 |
img := JPEGReader fromStream:(bytes readStream).
|
|
574 |
].
|
|
575 |
expectedSizeOrNil notNil ifTrue:[
|
|
576 |
self assert:(img width = expectedSizeOrNil).
|
|
577 |
self assert:(img height = expectedSizeOrNil).
|
|
578 |
].
|
|
579 |
^ img
|
|
580 |
!
|
|
581 |
|
3381
|
582 |
readPackBitsImageFrom:compressedData offset:offset width:w height:h depth:depth
|
|
583 |
|redData greenData blueData bytesPerRow bytesPerChannel n srcStart rowStart|
|
|
584 |
|
|
585 |
depth == 24 ifTrue:[
|
|
586 |
"/ rgb channels separate
|
|
587 |
bytesPerRow := w.
|
|
588 |
bytesPerChannel := bytesPerRow * h.
|
|
589 |
|
|
590 |
redData := ByteArray new:bytesPerChannel.
|
|
591 |
greenData := ByteArray new:bytesPerChannel.
|
|
592 |
blueData := ByteArray new:bytesPerChannel.
|
|
593 |
srcStart := 1+offset.
|
|
594 |
n := self class
|
|
595 |
decompressPackBitsFrom:compressedData at:srcStart to:redData at:1 count:bytesPerChannel.
|
|
596 |
srcStart := srcStart + n.
|
|
597 |
n := self class
|
|
598 |
decompressPackBitsFrom:compressedData at:srcStart to:greenData at:1 count:bytesPerChannel.
|
|
599 |
srcStart := srcStart + n.
|
|
600 |
n := self class
|
|
601 |
decompressPackBitsFrom:compressedData at:srcStart to:blueData at:1 count:bytesPerChannel.
|
|
602 |
photometric := #rgb.
|
|
603 |
bitsPerSample := #(8 8 8).
|
|
604 |
samplesPerPixel := 3.
|
|
605 |
width := w.
|
|
606 |
height := h.
|
|
607 |
data := ByteArray new:(self bytesPerRow * h).
|
|
608 |
|
|
609 |
rowStart := 1.
|
|
610 |
1 to:height do:[:r |
|
|
611 |
|ci|
|
|
612 |
|
|
613 |
ci := rowStart.
|
|
614 |
1 to:width do:[:c |
|
|
615 |
data at:ci put:(redData at:c).
|
|
616 |
data at:ci+1 put:(greenData at:c).
|
|
617 |
data at:ci+2 put:(blueData at:c).
|
|
618 |
ci := ci + 3.
|
|
619 |
].
|
|
620 |
rowStart := rowStart + self bytesPerRow.
|
|
621 |
].
|
|
622 |
^ Depth24Image new
|
|
623 |
width:width
|
|
624 |
height:height
|
|
625 |
photometric:photometric
|
|
626 |
samplesPerPixel:samplesPerPixel
|
|
627 |
bitsPerSample:bitsPerSample
|
|
628 |
colorMap:nil
|
|
629 |
bits:data
|
|
630 |
mask:nil.
|
|
631 |
].
|
|
632 |
depth == 8 ifTrue:[
|
|
633 |
"/ 8bit single channel
|
|
634 |
bytesPerRow := w.
|
|
635 |
bytesPerChannel := bytesPerRow * h.
|
|
636 |
|
|
637 |
compressedData size == bytesPerChannel ifTrue:[
|
|
638 |
data := compressedData.
|
|
639 |
] ifFalse:[
|
|
640 |
data := ByteArray new:bytesPerChannel.
|
|
641 |
n := self class
|
|
642 |
decompressPackBitsFrom:compressedData at:1+offset to:data at:1 count:bytesPerChannel.
|
|
643 |
].
|
|
644 |
^ Depth8Image new
|
|
645 |
width:width
|
|
646 |
height:height
|
|
647 |
photometric:#blackIs0
|
|
648 |
samplesPerPixel:1
|
|
649 |
bitsPerSample:#(8)
|
|
650 |
colorMap:nil
|
|
651 |
bits:data
|
|
652 |
mask:nil.
|
|
653 |
].
|
|
654 |
self halt.
|
|
655 |
^ nil
|
|
656 |
!
|
|
657 |
|
3121
|
658 |
read_ICN__from:bytes
|
|
659 |
"read an ICN# format icon"
|
|
660 |
|
3184
|
661 |
self halt:'unimplemented'.
|
3121
|
662 |
^ nil
|
|
663 |
|
|
664 |
"
|
|
665 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
666 |
"
|
|
667 |
!
|
|
668 |
|
3362
|
669 |
read_ICON_from:bytes
|
|
670 |
"read an ICON format icon.
|
|
671 |
128 bytes, 32x32x1 monochrome"
|
|
672 |
|
|
673 |
|pixelData img|
|
|
674 |
|
|
675 |
pixelData := (ByteArray new:128) replaceBytesFrom:1 to:128 with:bytes startingAt:1; yourself.
|
|
676 |
img := Depth1Image width:32 height:32 fromArray:pixelData.
|
3363
|
677 |
img photometric:#whiteIs0.
|
3362
|
678 |
^ img
|
|
679 |
|
|
680 |
"
|
|
681 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
682 |
"
|
|
683 |
!
|
|
684 |
|
3381
|
685 |
read_h8mk_from:bytes
|
|
686 |
"read an h8mk packbits format mask icon"
|
|
687 |
|
|
688 |
^ self readPackBitsImageFrom:bytes asByteArray offset:0 width:48 height:48 depth:8.
|
|
689 |
!
|
|
690 |
|
3121
|
691 |
read_ic07_from:bytes
|
|
692 |
"read an ic07 (PNG or JPEG, 128) format icon"
|
|
693 |
|
|
694 |
^ self readPNGOrJPEGFrom:bytes expectedSize:128.
|
|
695 |
|
|
696 |
"
|
|
697 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
698 |
self fromFile:'test.icns'
|
|
699 |
"
|
|
700 |
!
|
|
701 |
|
|
702 |
read_ic08_from:bytes
|
|
703 |
"read an ic08 (PNG or JPEG, 256) format icon"
|
|
704 |
|
|
705 |
^ self readPNGOrJPEGFrom:bytes expectedSize:256.
|
|
706 |
|
|
707 |
"
|
|
708 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
709 |
self fromFile:'test.icns'
|
|
710 |
"
|
|
711 |
!
|
|
712 |
|
|
713 |
read_ic09_from:bytes
|
|
714 |
"read an ic09 (PNG or JPEG, 512) format icon"
|
|
715 |
|
|
716 |
^ self readPNGOrJPEGFrom:bytes expectedSize:512.
|
|
717 |
|
|
718 |
"
|
|
719 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
720 |
self fromFile:'test.icns'
|
|
721 |
"
|
|
722 |
!
|
|
723 |
|
|
724 |
read_ic10_from:bytes
|
|
725 |
"read an ic10 (PNG or JPEG, 1024) format icon"
|
|
726 |
|
|
727 |
^ self readPNGOrJPEGFrom:bytes expectedSize:1024.
|
|
728 |
|
|
729 |
"
|
|
730 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
731 |
self fromFile:'test.icns'
|
|
732 |
"
|
|
733 |
!
|
|
734 |
|
3361
|
735 |
read_ich4_from:bytes
|
|
736 |
"read an ich4 format icon;
|
|
737 |
1152 bytes; 48x48x4bit"
|
|
738 |
|
|
739 |
^ self common_read_paletteImage_from:bytes size:1152 width:48 height:48 depth:4
|
|
740 |
|
|
741 |
"
|
|
742 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
743 |
"
|
|
744 |
!
|
|
745 |
|
|
746 |
read_ich8_from:bytes
|
|
747 |
"read an ich8 format icon;
|
|
748 |
2304 bytes; 48x48x8bit"
|
|
749 |
|
|
750 |
^ self common_read_paletteImage_from:bytes size:2304 width:48 height:48 depth:8
|
|
751 |
|
|
752 |
"
|
|
753 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
754 |
"
|
|
755 |
!
|
3121
|
756 |
|
3361
|
757 |
read_icl4_from:bytes
|
|
758 |
"read an icl4 format icon;
|
|
759 |
512 bytes; 32x32x4bit"
|
|
760 |
|
|
761 |
^ self common_read_paletteImage_from:bytes size:512 width:32 height:32 depth:4
|
|
762 |
|
|
763 |
"
|
|
764 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
765 |
"
|
|
766 |
!
|
|
767 |
|
|
768 |
read_icl8_from:bytes
|
|
769 |
"read an icl8 format icon;
|
|
770 |
1024 bytes; 32x32x8bit"
|
|
771 |
|
|
772 |
^ self common_read_paletteImage_from:bytes size:1024 width:32 height:32 depth:8
|
|
773 |
|
|
774 |
"
|
|
775 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
776 |
"
|
|
777 |
!
|
|
778 |
|
|
779 |
read_ics4_from:bytes
|
|
780 |
"read an ics4 format icon.
|
|
781 |
128 bytes, 16x16x4bit"
|
|
782 |
|
|
783 |
^ self common_read_paletteImage_from:bytes size:128 width:16 height:16 depth:4
|
3121
|
784 |
|
|
785 |
"
|
|
786 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
787 |
"
|
|
788 |
!
|
|
789 |
|
|
790 |
read_ics8_from:bytes
|
3133
|
791 |
"read an ics8 format icon.
|
3361
|
792 |
256 bytes, 16x16x8bit"
|
3121
|
793 |
|
3361
|
794 |
^ self common_read_paletteImage_from:bytes size:256 width:16 height:16 depth:8
|
3121
|
795 |
|
|
796 |
"
|
|
797 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
798 |
"
|
|
799 |
!
|
|
800 |
|
|
801 |
read_ics__from:bytes
|
3133
|
802 |
"read an ics# format icon.
|
|
803 |
ics# is 64 bytes, 16x16x1 monochrome + mask"
|
|
804 |
|
|
805 |
|pixelData maskData img|
|
3121
|
806 |
|
3133
|
807 |
pixelData := (ByteArray new:32) replaceBytesFrom:1 to:32 with:bytes startingAt:1; yourself.
|
|
808 |
maskData := (ByteArray new:32) replaceBytesFrom:1 to:32 with:bytes startingAt:32+1; yourself.
|
|
809 |
img := Depth1Image width:16 height:16 fromArray:pixelData.
|
|
810 |
img mask:(Depth1Image width:16 height:16 fromArray:maskData).
|
|
811 |
^ img
|
3121
|
812 |
|
|
813 |
"
|
|
814 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
815 |
"
|
|
816 |
!
|
|
817 |
|
3381
|
818 |
read_ih32_from:bytes
|
|
819 |
"read an ih32 packbits format icon"
|
3121
|
820 |
|
3381
|
821 |
^ self readPackBitsImageFrom:bytes asByteArray offset:0 width:48 height:48 depth:24.
|
|
822 |
!
|
3121
|
823 |
|
3381
|
824 |
read_il32_from:bytes
|
|
825 |
"read an il32 packbits format icon"
|
|
826 |
|
|
827 |
^ self readPackBitsImageFrom:bytes asByteArray offset:0 width:32 height:32 depth:24.
|
3121
|
828 |
!
|
|
829 |
|
|
830 |
read_ipc4_from:bytes
|
|
831 |
"read an ipc4 (PNG or JPEG, 16x16) format icon"
|
|
832 |
|
|
833 |
^ self readPNGOrJPEGFrom:bytes expectedSize:16.
|
|
834 |
|
|
835 |
"
|
|
836 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
837 |
self fromFile:'test.icns'
|
|
838 |
"
|
|
839 |
!
|
|
840 |
|
|
841 |
read_ipc5_from:bytes
|
|
842 |
"read an ipc5 (PNG or JPEG, 32) format icon"
|
|
843 |
|
|
844 |
^ self readPNGOrJPEGFrom:bytes expectedSize:32.
|
|
845 |
|
|
846 |
"
|
|
847 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
848 |
self fromFile:'test.icns'
|
|
849 |
"
|
|
850 |
!
|
|
851 |
|
|
852 |
read_is32_from:bytes
|
3381
|
853 |
"read an is32 packbits format icon"
|
3121
|
854 |
|
3381
|
855 |
^ self readPackBitsImageFrom:bytes asByteArray offset:0 width:16 height:16 depth:24.
|
3121
|
856 |
!
|
|
857 |
|
|
858 |
read_it32_from:bytes
|
3381
|
859 |
"read an it32 packbits format icon"
|
3121
|
860 |
|
3381
|
861 |
^ self readPackBitsImageFrom:bytes asByteArray offset:4 width:64 height:64 depth:24.
|
3121
|
862 |
|
|
863 |
"
|
|
864 |
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
|
|
865 |
"
|
|
866 |
!
|
|
867 |
|
|
868 |
read_l8mk_from:bytes
|
3381
|
869 |
"read an l8mk packbits format mask icon"
|
3121
|
870 |
|
3381
|
871 |
^ self readPackBitsImageFrom:bytes asByteArray offset:0 width:32 height:32 depth:8.
|
3121
|
872 |
!
|
|
873 |
|
|
874 |
read_s8mk_from:bytes
|
3381
|
875 |
"read an s8mk packbits format mask icon"
|
3121
|
876 |
|
3381
|
877 |
^ self readPackBitsImageFrom:bytes asByteArray offset:0 width:16 height:16 depth:8.
|
3121
|
878 |
!
|
|
879 |
|
|
880 |
read_t8mk_from:bytes
|
3381
|
881 |
"read an t8mk packbits format mask icon"
|
3121
|
882 |
|
3381
|
883 |
^ self readPackBitsImageFrom:bytes asByteArray offset:0 width:64 height:64 depth:8.
|
3121
|
884 |
! !
|
|
885 |
|
|
886 |
!MacOSXIconReader class methodsFor:'documentation'!
|
|
887 |
|
|
888 |
version
|
3381
|
889 |
^ '$Header: /cvs/stx/stx/libview2/MacOSXIconReader.st,v 1.11 2014-11-10 22:21:31 cg Exp $'
|
3121
|
890 |
!
|
|
891 |
|
|
892 |
version_CVS
|
3381
|
893 |
^ '$Header: /cvs/stx/stx/libview2/MacOSXIconReader.st,v 1.11 2014-11-10 22:21:31 cg Exp $'
|
3121
|
894 |
! !
|
|
895 |
|
|
896 |
|
|
897 |
MacOSXIconReader initialize!
|