ImageReader.st
changeset 7926 b83ef852a991
parent 7925 2c80806ec2de
child 7929 576cffea9ac5
--- a/ImageReader.st	Wed Feb 22 10:57:44 2017 +0100
+++ b/ImageReader.st	Wed Feb 22 12:06:32 2017 +0100
@@ -1131,7 +1131,8 @@
 decompressPackBitsFrom:srcBytes at:srcStart to:dstBytes at:dstStart count:outCount
     "decompress until a number of output bytes has been decompressed.
      Used by some mac image formats.
-     Return the number of processed input bytes."
+     Return the number of processed input bytes.
+     This DOES TREAT FF as a noop."
 
     |i b n v dstOffs nRemaining|
 
@@ -1142,6 +1143,8 @@
         b := srcBytes at:i.
         i := i + 1.
 
+        "/ mhmh - other packbits decoders seem to treat FF as a noop
+        "/ here, we do. 
         b ~~ 16rFF ifTrue:[   "/ not a NOP
             b <= 127 ifTrue:[
                 "/ 0..127: 1..128 literal bytes
@@ -1160,11 +1163,57 @@
                 nRemaining := nRemaining - n.
             ].
             dstOffs := dstOffs + n.
-        ]
+        ] ifFalse:[
+            self halt
+        ].    
     ].
     ^ i-srcStart
 
-    "Modified: / 22-02-2017 / 10:37:30 / cg"
+    "Modified: / 22-02-2017 / 12:05:50 / cg"
+!
+
+decompressPackBitsV2From:srcBytes at:srcStart to:dstBytes at:dstStart count:outCount
+    "decompress until a number of output bytes has been decompressed.
+     Used by some mac image formats.
+     Return the number of processed input bytes.
+     This does NOT treat FF as a noop."
+
+    |i b n v dstOffs nRemaining|
+
+    dstOffs := dstStart.
+    i := srcStart.
+    nRemaining := outCount.
+    [nRemaining > 0] whileTrue:[
+        b := srcBytes at:i.
+        i := i + 1.
+
+        "/ mhmh - other packbits decoders seem to treat FF as a noop
+        "/ here, we do not. 
+        true "b ~~ 16rFF" ifTrue:[   "/ not a NOP
+            b <= 127 ifTrue:[
+                "/ 0..127: 1..128 literal bytes
+                n := b + 1.
+                dstBytes replaceFrom:dstOffs to:dstOffs+b with:srcBytes startingAt:i.
+                nRemaining := nRemaining - n.
+                i := i + n.
+            ] ifFalse:[
+                "/ 128..255 a run of length 3..130
+                n := b - 125.
+
+                v := srcBytes at:i.
+                i := i + 1.
+
+                dstBytes from:dstOffs to:dstOffs+n-1 put:v.
+                nRemaining := nRemaining - n.
+            ].
+            dstOffs := dstOffs + n.
+        ] ifFalse:[
+            self halt
+        ].    
+    ].
+    ^ i-srcStart
+
+    "Created: / 22-02-2017 / 12:05:26 / cg"
 !
 
 decompressRLEFrom:srcBytes at:srcStartIndex into:dstBytes at:dstStartIndex increment:dstIncrement