--- a/MacOSXIconReader.st Wed Nov 26 13:45:44 2014 +0100
+++ b/MacOSXIconReader.st Wed Nov 26 16:04:42 2014 +0100
@@ -133,9 +133,10 @@
numChunkBytes := numChunkBytes - 4 - 4. "/ type and size are included in count
chunkData := aStream next:numChunkBytes.
- sizeRemaining := sizeRemaining - 4 - numChunkBytes.
+ sizeRemaining := sizeRemaining - 4 - 4 - numChunkBytes.
img := self readSingleIcon:chunkType from:chunkData.
+ "/ unsupported images are skipped...
img notNil ifTrue:[
imageCount == 0 ifTrue:[
firstImage := image := img.
@@ -148,10 +149,6 @@
frame := ImageFrame new image:firstImage.
imageSequence add:frame.
].
- img notNil ifTrue:[
- "/ unsupported images are skipped...
- img imageSequence:imageSequence.
- ].
"/ add frame for this image.
frame := ImageFrame new image:img.
@@ -160,7 +157,8 @@
imageCount := imageCount + 1.
].
].
-self halt.
+ self breakPoint:#cg.
+
"
Image fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
"
@@ -169,14 +167,22 @@
readSingleIcon:iconType from:iconBytes
"read a single image from the inputStream."
- ^ self
- perform:('read_',(iconType copyReplaceAll:$# with:$_),'_from:') asSymbol
- with:iconBytes
- ifNotUnderstood:[
- self breakPoint:#cg.
- ('MacOSXIconReader: unsupported icon format: ',iconType) infoPrintCR.
- ^ self fileFormatError:'unsupported icon format: ',iconType
- ].
+ |img|
+
+ Error handle:[:ex |
+ self fileFormatError:'internal error / unhandled icon format: ',iconType.
+ ] do:[
+ img := self
+ perform:('read_',(iconType copyReplaceAny:#( $# $ ) with:$_),'_from:') asSymbol
+ with:iconBytes
+ ifNotUnderstood:[
+ self breakPoint:#cg.
+ ('MacOSXIconReader: unsupported icon format: ',iconType) infoPrintCR.
+ self fileFormatError:'unsupported icon format: ',iconType.
+ nil
+ ].
+ ].
+ ^ img.
"
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
@@ -656,14 +662,16 @@
!
read_ICN__from:bytes
- "read an ICN# format icon"
+ "read an ICN# format icon.
+ ICN# is 32x32 bit mono with 1-bit mask"
+
+ |pixelData maskData img|
-self halt:'unimplemented'.
- ^ nil
-
- "
- self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
- "
+ pixelData := (ByteArray new:128) replaceBytesFrom:1 to:128 with:bytes startingAt:1; yourself.
+ maskData := (ByteArray new:128) replaceBytesFrom:1 to:128 with:bytes startingAt:128+1; yourself.
+ img := Depth1Image width:32 height:32 fromArray:pixelData.
+ img mask:(Depth1Image width:32 height:32 fromArray:maskData).
+ ^ img
!
read_ICON_from:bytes
@@ -682,6 +690,12 @@
"
!
+read_TOC__from:bytes
+ "read (actually: skip) a table of contents."
+
+ ^ nil
+!
+
read_h8mk_from:bytes
"read an h8mk packbits format mask icon"
@@ -754,6 +768,19 @@
"
!
+read_ich__from:bytes
+ "read an ich# format icon.
+ ich# is 288+288 bytes, 48x48x1 monochrome + mask"
+
+ |pixelData maskData img|
+
+ pixelData := (ByteArray new:288) replaceBytesFrom:1 to:288 with:bytes startingAt:1; yourself.
+ maskData := (ByteArray new:288) replaceBytesFrom:1 to:288 with:bytes startingAt:288+1; yourself.
+ img := Depth1Image width:48 height:48 fromArray:pixelData.
+ img mask:(Depth1Image width:48 height:48 fromArray:maskData).
+ ^ img
+!
+
read_icl4_from:bytes
"read an icl4 format icon;
512 bytes; 32x32x4bit"
@@ -850,15 +877,15 @@
!
read_is32_from:bytes
- "read an is32 packbits format icon"
+ "read an is32 packbits format 16x16x24 icon"
^ self readPackBitsImageFrom:bytes asByteArray offset:0 width:16 height:16 depth:24.
!
read_it32_from:bytes
- "read an it32 packbits format icon"
+ "read an it32 packbits format 128x128x24 icon"
- ^ self readPackBitsImageFrom:bytes asByteArray offset:4 width:64 height:64 depth:24.
+ ^ self readPackBitsImageFrom:bytes asByteArray offset:4 width:128 height:128 depth:24.
"
self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
@@ -886,11 +913,11 @@
!MacOSXIconReader class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/MacOSXIconReader.st,v 1.11 2014-11-10 22:21:31 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/MacOSXIconReader.st,v 1.12 2014-11-26 15:04:42 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libview2/MacOSXIconReader.st,v 1.11 2014-11-10 22:21:31 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/MacOSXIconReader.st,v 1.12 2014-11-26 15:04:42 cg Exp $'
! !