#DOCUMENTATION by cg
authorClaus Gittinger <cg@exept.de>
Wed, 22 Feb 2017 15:00:04 +0100
changeset 3915 de91d3d26af1
parent 3914 bea1bcf56565
child 3916 c42311c324e6
#DOCUMENTATION by cg class: MacOSXIconReader added: #read_icp4_from: #read_icp5_from: #read_icp6_from: #read_ipc6_from: changed: #readPNGOrJPEGFrom:expectedSize: #read_ipc4_from: #read_ipc5_from: #read_it32_from: #saveAll:onStream:
MacOSXIconReader.st
--- a/MacOSXIconReader.st	Wed Feb 22 14:59:47 2017 +0100
+++ b/MacOSXIconReader.st	Wed Feb 22 15:00:04 2017 +0100
@@ -268,10 +268,10 @@
     (aCollectionOfImages conform:
         [:eachImage |
             (eachImage width = eachImage height)
-            and:[ (#(16 32 128 256 512 1024) includes:eachImage width)]
+            and:[ (#(16 32 64 128 256 512 1024) includes:eachImage width)]
         ]
     ) ifFalse:[
-        ^ self fileFormatError:'unsupported image size (must be square and width 16, 32, 128, 512 or 1024)'.
+        ^ self fileFormatError:'unsupported image size (must be square and width 16, 32, 64, 128, 512 or 1024)'.
     ].
 
     tempStream := ReadWriteStream on:(ByteArray new:1024).
@@ -284,8 +284,8 @@
         data := s contents.
         self assert:data notEmptyOrNil.
 
-        typeCode := #(16 32 128 256 512 1024) 
-                    map: #('ipc4' 'ipc5' 'ic07' 'ic08' 'ic09' 'ic10')
+        typeCode := #(16 32 64 128 256 512 1024) 
+                    map: #('ipc4' 'ipc5' 'ipc6' 'ic07' 'ic08' 'ic09' 'ic10')
                     at:eachImage width ifAbsent:[self error]. 
         tempStream
             nextPutBytes:typeCode;
@@ -319,7 +319,7 @@
          onFile:'test.icns'   
     "
 
-    "Modified (comment): / 22-02-2017 / 01:06:48 / cg"
+    "Modified: / 22-02-2017 / 12:16:07 / cg"
 ! !
 
 !MacOSXIconReader methodsFor:'private'!
@@ -653,6 +653,7 @@
     ].    
     img isNil ifTrue:[
         img := JPEGReader fromStream:(bytes readStream).
+        img isNil ifTrue:[^ nil].
     ].
     expectedSizeOrNil notNil ifTrue:[
         self assert:(img width = expectedSizeOrNil).
@@ -660,7 +661,7 @@
     ].
     ^ img
 
-    "Modified: / 22-02-2017 / 11:01:58 / cg"
+    "Modified: / 22-02-2017 / 13:42:48 / cg"
 !
 
 readPackBitsImageFrom:compressedData offset:offset width:w height:h depth:depth
@@ -956,6 +957,53 @@
     "
 !
 
+read_icp4_from:bytes
+    "read an ipc4 (PNG or JPEG, 16x16) format icon"
+
+    ^ self readPNGOrJPEGFrom:bytes expectedSize:16.
+
+    "
+     self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
+     self fromFile:'test.icns'
+    "
+
+    "Created: / 22-02-2017 / 12:18:02 / cg"
+!
+
+read_icp5_from:bytes
+    "read an ipc5 (PNG or JPEG, 32x32) format icon"
+
+    ^ self readPNGOrJPEGFrom:bytes expectedSize:32.
+
+    "
+     self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
+     self fromFile:'/Applications/TextEdit.app/Contents/Resources/html.icns'
+     self fromFile:'test.icns'
+     
+     '/Applications' asFilename recursiveDirectoryContentsAsFilenamesDo:[:each |
+         (each hasSuffix:'icns') ifTrue:[
+             Transcript showCR:'reading ',each pathName.
+             self fromFile:each.
+         ] 
+     ] 
+    "
+
+    "Created: / 22-02-2017 / 12:18:07 / cg"
+!
+
+read_icp6_from:bytes
+    "read an ipc6 (PNG or JPEG, 64x64) format icon"
+
+    ^ self readPNGOrJPEGFrom:bytes expectedSize:64.
+
+    "
+     self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
+     self fromFile:'test.icns'
+    "
+
+    "Created: / 22-02-2017 / 12:17:52 / cg"
+!
+
 read_ics4_from:bytes
     "read an ics4 format icon.
      128 bytes, 16x16x4bit"
@@ -1026,6 +1074,7 @@
 !
 
 read_ipc4_from:bytes
+    <resource: #obsolete>
     "read an ipc4 (PNG or JPEG, 16x16) format icon"
 
     ^ self readPNGOrJPEGFrom:bytes expectedSize:16.
@@ -1037,6 +1086,7 @@
 !
 
 read_ipc5_from:bytes
+    <resource: #obsolete>
     "read an ipc5 (PNG or JPEG, 32x32) format icon"
 
     ^ self readPNGOrJPEGFrom:bytes expectedSize:32.
@@ -1049,6 +1099,20 @@
     "Modified (comment): / 22-02-2017 / 11:02:44 / cg"
 !
 
+read_ipc6_from:bytes
+    <resource: #obsolete>
+    "read an ipc6 (PNG or JPEG, 64x64) format icon"
+
+    ^ self readPNGOrJPEGFrom:bytes expectedSize:64.
+
+    "
+     self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
+     self fromFile:'test.icns'
+    "
+
+    "Created: / 22-02-2017 / 12:16:33 / cg"
+!
+
 read_is32_from:bytes
     "read an is32 packbits format 16x16x24 icon"
 
@@ -1071,7 +1135,7 @@
 
     offset := 0.
     (bytes from:1 to:4) = #[0 0 0 0] ifTrue:[
-        self halt.
+        "/ self halt.
         offset := 4.
     ].    
     ^ self readPackBitsImageFrom:bytes asByteArray offset:offset width:128 height:128 depth:24.
@@ -1080,7 +1144,7 @@
      self fromFile:'/Applications/TextEdit.app/Contents/Resources/txt.icns'
     "
 
-    "Modified: / 22-02-2017 / 10:32:02 / cg"
+    "Modified: / 22-02-2017 / 12:19:56 / cg"
 !
 
 read_l8mk_from:bytes