MacOSXIconReader.st
changeset 3361 e0a2c0425a2c
parent 3184 de612ee1585e
child 3362 84da5a3c2e27
--- a/MacOSXIconReader.st	Fri Jul 11 15:31:21 2014 +0200
+++ b/MacOSXIconReader.st	Thu Jul 24 19:42:41 2014 +0200
@@ -536,6 +536,30 @@
 
 !MacOSXIconReader methodsFor:'private reading'!
 
+common_read_paletteImage_from:bytes size:size width:w height:h depth:d
+    "read an icl8/icl4/ics4/ics8 icon"
+
+    |pixelData img|
+
+    pixelData := (ByteArray new:size) replaceBytesWith:bytes; yourself.
+    img := (Image implementorForDepth:d) width:w height:h fromArray:pixelData.
+    img photometric:#palette.
+    d == 4 ifTrue:[ 
+        img colorMap:(Colormap rgbBytesVector:self colormap4).
+    ] ifFalse:[ 
+        d == 8 ifTrue:[ 
+            img colorMap:(Colormap rgbBytesVector:self colormap8).
+        ] ifFalse:[ 
+            self error:'unsupported depth'
+        ].
+    ].
+    ^ img
+
+    "
+     self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
+    "
+!
+
 readPNGOrJPEGFrom:bytes expectedSize:expectedSizeOrNil
     "read a PNG or JPEG image.
      Helper for ipc4, ipc5, ic07, ic09, ic10 formats"
@@ -608,11 +632,55 @@
     "
 !
 
-read_icl8_from:bytes
-    "read an icl8 format icon"
+read_ich4_from:bytes
+    "read an ich4 format icon;
+     1152 bytes; 48x48x4bit"
+
+    ^ self common_read_paletteImage_from:bytes size:1152 width:48 height:48 depth:4
+
+    "
+     self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
+    "
+!
+
+read_ich8_from:bytes
+    "read an ich8 format icon;
+     2304 bytes; 48x48x8bit"
+
+    ^ self common_read_paletteImage_from:bytes size:2304 width:48 height:48 depth:8
+
+    "
+     self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
+    "
+!
 
-self halt:'unimplemented'.
-    ^ nil
+read_icl4_from:bytes
+    "read an icl4 format icon;
+     512 bytes; 32x32x4bit"
+
+    ^ self common_read_paletteImage_from:bytes size:512 width:32 height:32 depth:4
+
+    "
+     self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
+    "
+!
+
+read_icl8_from:bytes
+    "read an icl8 format icon;
+     1024 bytes; 32x32x8bit"
+
+    ^ self common_read_paletteImage_from:bytes size:1024 width:32 height:32 depth:8
+
+    "
+     self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
+    "
+!
+
+read_ics4_from:bytes
+    "read an ics4 format icon.
+     128 bytes, 16x16x4bit"
+
+    ^ self common_read_paletteImage_from:bytes size:128 width:16 height:16 depth:4
 
     "
      self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
@@ -621,15 +689,9 @@
 
 read_ics8_from:bytes
     "read an ics8 format icon.
-     ics8 is 256 bytes, 16x16x8bit"
-
-    |pixelData img|
+     256 bytes, 16x16x8bit"
 
-    pixelData := (ByteArray new:256) replaceBytesWith:bytes; yourself.
-    img := Depth8Image width:16 height:16 fromArray:pixelData.
-    img photometric:#palette.
-    img colorMap:(Colormap rgbBytesVector:self colormap8).
-    ^ img
+    ^ self common_read_paletteImage_from:bytes size:256 width:16 height:16 depth:8
 
     "
      self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
@@ -744,11 +806,11 @@
 !MacOSXIconReader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/MacOSXIconReader.st,v 1.7 2013-06-20 22:47:18 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/MacOSXIconReader.st,v 1.8 2014-07-24 17:42:41 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libview2/MacOSXIconReader.st,v 1.7 2013-06-20 22:47:18 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/MacOSXIconReader.st,v 1.8 2014-07-24 17:42:41 cg Exp $'
 ! !