#BUGFIX by cg
authorClaus Gittinger <cg@exept.de>
Wed, 23 Aug 2017 17:26:39 +0200
changeset 8095 7d4b25655182
parent 8094 72be8139d8e8
child 8096 42e3303fe2c2
#BUGFIX by cg class: ImageReader changed: #buildMaskFromColor: class: ImageReader class added: #buildMaskFromColor:for:depth:width:height: changed: #buildMaskFromColor:for:width:height:
ImageReader.st
--- a/ImageReader.st	Wed Aug 23 16:16:40 2017 +0200
+++ b/ImageReader.st	Wed Aug 23 17:26:39 2017 +0200
@@ -1617,18 +1617,19 @@
 
 !ImageReader class methodsFor:'image support'!
 
-buildMaskFromColor:maskPixelValue for:pixels width:width height:height
+buildMaskFromColor:maskPixelValue for:pixels depth:depth width:width height:height
     "helper for image formats, where an individual pixel value
      has been defined as a mask-pixel (i.e. GIF).
      Creates a maskImage, with zeros at positions where the image
      has the given pixelValue; all other mask pixels are set to 1."
 
-    |maskArray bytesPerMaskRow mask|
+    |maskArray bytesPerMaskRow mask ok|
 
     bytesPerMaskRow := (width+7) // 8.
 
     maskArray := ByteArray uninitializedNew:bytesPerMaskRow * height.
-
+    ok := false.
+    
 %{
     int __w = __intVal(width);
     int __h = __intVal(height);
@@ -1643,84 +1644,102 @@
 
     if (! __isByteArrayLike(pixels)) goto fail;
     if (! __isByteArray(maskArray)) goto fail;
-
+    if (__intVal(depth) != 8) goto fail;
+    
     __inP = __ByteArrayInstPtr(pixels)->ba_element;
     __outP = __ByteArrayInstPtr(maskArray)->ba_element;
 
 #ifdef DEBUG
     outEnd = __outP + (__byteArraySize(maskArray));
 #endif
-/*
-printf("outP: %x outEnd: %x sz: %d\n", __outP, outEnd, __byteArraySize(maskArray));
-*/
+    //
+    // printf("outP: %x outEnd: %x sz: %d\n", __outP, outEnd, __byteArraySize(maskArray));
+    //
 
     for (__y=__h; __y>0; __y--) {
-	__outBits = 0;
-	__nOut = 8;
-	__nextOutRow = __outP + __bpr;
+        __outBits = 0;
+        __nOut = 8;
+        __nextOutRow = __outP + __bpr;
 
-	for (__x=__w; __x>=8; __x-=8) {
-	    if (__inP[0] != __maskPixel) { __outBits |= 0x80; };
-	    if (__inP[1] != __maskPixel) { __outBits |= 0x40; };
-	    if (__inP[2] != __maskPixel) { __outBits |= 0x20; };
-	    if (__inP[3] != __maskPixel) { __outBits |= 0x10; };
-	    if (__inP[4] != __maskPixel) { __outBits |= 0x08; };
-	    if (__inP[5] != __maskPixel) { __outBits |= 0x04; };
-	    if (__inP[6] != __maskPixel) { __outBits |= 0x02; };
-	    if (__inP[7] != __maskPixel) { __outBits |= 0x01; };
-	    __inP += 8;
-	    *__outP++ = __outBits;
-	    __outBits = 0;
-	}
-	for (; __x>0; __x--) {
-	    __outBits <<= 1;
-	    if (*__inP != __maskPixel) {
-		__outBits |= 1;
-	    }
-	    __inP++;
+        for (__x=__w; __x>=8; __x-=8) {
+            if (__inP[0] != __maskPixel) { __outBits |= 0x80; };
+            if (__inP[1] != __maskPixel) { __outBits |= 0x40; };
+            if (__inP[2] != __maskPixel) { __outBits |= 0x20; };
+            if (__inP[3] != __maskPixel) { __outBits |= 0x10; };
+            if (__inP[4] != __maskPixel) { __outBits |= 0x08; };
+            if (__inP[5] != __maskPixel) { __outBits |= 0x04; };
+            if (__inP[6] != __maskPixel) { __outBits |= 0x02; };
+            if (__inP[7] != __maskPixel) { __outBits |= 0x01; };
+            __inP += 8;
+            *__outP++ = __outBits;
+            __outBits = 0;
+        }
+        for (; __x>0; __x--) {
+            __outBits <<= 1;
+            if (*__inP != __maskPixel) {
+                __outBits |= 1;
+            }
+            __inP++;
 
-/*
- printf("x: %d  bits: %x\n", __x, __outBits);
-*/
-	    if (--__nOut == 0) {
+            //
+            // printf("x: %d  bits: %x\n", __x, __outBits);
+            //
+            if (--__nOut == 0) {
 #ifdef DEBUG
-		if (__outP >= outEnd) {
-		    if (@global(InfoPrinting) == true) {
-			console_fprintf(stderr, "oops %d\n", __LINE__);
-		    }
-		    goto fail;
-		}
+                if (__outP >= outEnd) {
+                    if (@global(InfoPrinting) == true) {
+                        console_fprintf(stderr, "oops %d\n", __LINE__);
+                    }
+                    goto fail;
+                }
 #endif
-		*__outP = __outBits;
+                *__outP = __outBits;
 
-		__outP++;
-		__nOut = 8;
-		__outBits = 0;
-	    }
-	}
+                __outP++;
+                __nOut = 8;
+                __outBits = 0;
+            }
+        }
 
-	if (__nOut != 8) {
-	    __outBits <<= __nOut;
+        if (__nOut != 8) {
+            __outBits <<= __nOut;
 
 #ifdef DEBUG
-	    if (__outP >= outEnd) {
-		if (@global(InfoPrinting) == true) {
-		    console_fprintf(stderr, "oops2 %d\n", __LINE__);
-		}
-		goto fail;
-	    }
+            if (__outP >= outEnd) {
+                if (@global(InfoPrinting) == true) {
+                    console_fprintf(stderr, "oops2 %d\n", __LINE__);
+                }
+                goto fail;
+            }
 #endif
-	    *__outP = __outBits;
+            *__outP = __outBits;
 
-	}
-	__outP = __nextOutRow;
+        }
+        __outP = __nextOutRow;
     }
+    ok = true;
 fail: ;
 %}.
+    ok ifFalse:[
+        "/ slow fallback...
+        self halt.
+    ].    
     mask := ImageMask width:width height:height fromArray:maskArray.
     ^ mask
 
-    "Created: 21.6.1996 / 11:43:47 / cg"
+    "Created: / 23-08-2017 / 17:10:03 / cg"
+!
+
+buildMaskFromColor:maskPixelValue for:pixels width:width height:height
+    "helper for image formats, where an individual pixel value
+     has been defined as a mask-pixel (i.e. GIF).
+     Creates a maskImage, with zeros at positions where the image
+     has the given pixelValue; all other mask pixels are set to 1."
+
+    ^ self buildMaskFromColor:maskPixelValue for:pixels depth:8 width:width height:height
+
+    "Created: / 21-06-1996 / 11:43:47 / cg"
+    "Modified: / 23-08-2017 / 17:13:23 / cg"
 ! !
 
 !ImageReader class methodsFor:'image writing'!
@@ -2160,12 +2179,11 @@
      has the given pixelValue; all other mask pixels are set to 1."
 
     mask := self class
-		buildMaskFromColor:maskPixelValue
-		for:data
-		width:width
-		height:height
+                buildMaskFromColor:maskPixelValue
+                for:data depth:(self bitsPerPixel)
+                width:width height:height
 
-    "Modified: / 14.1.1998 / 14:48:33 / cg"
+    "Modified: / 23-08-2017 / 17:11:51 / cg"
 ! !
 
 !ImageReader methodsFor:'image writing'!