Depth4Image.st
changeset 7499 e482fe94eec6
parent 7321 9c057f59fedc
child 7516 a1842618aa6d
--- a/Depth4Image.st	Mon Aug 08 17:13:04 2016 +0200
+++ b/Depth4Image.st	Mon Aug 08 17:13:07 2016 +0200
@@ -175,7 +175,7 @@
     bestFormat := self bestSupportedImageFormatFor:aDevice.
     usedDeviceDepth := bestFormat at:#depth.
     usedDeviceDepth == 1 ifTrue:[
-	^ self asMonochromeFormOn:aDevice
+        ^ self asMonochromeFormOn:aDevice
     ].
     usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
     usedDevicePadding := bestFormat at:#padding.
@@ -187,310 +187,310 @@
     "/ for now, only support some depths
 
     usedDeviceBitsPerPixel == 16 ifTrue:[
-	"/ 16 bits/pixel
+        "/ 16 bits/pixel
 
-	"/ now, walk over the image and replace
-	"/ colorMap indices by color values in the bits array
+        "/ now, walk over the image and replace
+        "/ colorMap indices by color values in the bits array
 
 %{
-	unsigned char *srcPtr = 0;
-	unsigned char *dstPtr = 0;
-	OBJ _bytes = __INST(bytes);
+        unsigned char *srcPtr = 0;
+        unsigned char *dstPtr = 0;
+        OBJ _bytes = __INST(bytes);
 
-	if (__isByteArrayLike(_bytes)) {
-	    srcPtr = __ByteArrayInstPtr(_bytes)->ba_element;
-	} else {
-	    if (__isExternalBytesLike(_bytes)) {
-		srcPtr = __externalBytesAddress(_bytes);
-	    }
-	}
-	if (__isByteArray(imageBits)) {
-	    dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
-	} else {
-	    if (__isExternalBytesLike(imageBits)) {
-		dstPtr = __externalBytesAddress(imageBits);
-	    }
-	}
+        if (__isByteArrayLike(_bytes)) {
+            srcPtr = __ByteArrayInstPtr(_bytes)->ba_element;
+        } else {
+            if (__isExternalBytesLike(_bytes)) {
+                srcPtr = __externalBytesAddress(_bytes);
+            }
+        }
+        if (__isByteArray(imageBits)) {
+            dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
+        } else {
+            if (__isExternalBytesLike(imageBits)) {
+                dstPtr = __externalBytesAddress(imageBits);
+            }
+        }
 
-	if (__bothSmallInteger(__INST(height), __INST(width))
-	 && __isArrayLike(colorValues)
-	 && srcPtr
-	 && dstPtr) {
-	    int r,p;
-	    int x, y, w, h, nPix;
-	    int byte;
+        if (__bothSmallInteger(__INST(height), __INST(width))
+         && __isArrayLike(colorValues)
+         && srcPtr
+         && dstPtr) {
+            int r,p;
+            int x, y, w, h, nPix;
+            int byte;
 
-	    OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
+            OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
 
-	    w = __intVal(__INST(width));
-	    h = __intVal(__INST(height));
-	    r = 0;
-	    p = __intVal(padd);
-	    nPix = w * h;
-	    while (nPix-- > 0) {
-		unsigned idx, v;
-		OBJ clr;
+            w = __intVal(__INST(width));
+            h = __intVal(__INST(height));
+            r = 0;
+            p = __intVal(padd);
+            nPix = w * h;
+            while (nPix-- > 0) {
+                unsigned idx, v;
+                OBJ clr;
 
-		if (r & 1) {
-		    idx = byte & 0xF;
-		} else {
-		    byte = *srcPtr++;
-		    idx = (byte>>4) & 0xF;
-		}
-		clr = ap[idx];
-		v = __intVal(clr);
+                if (r & 1) {
+                    idx = byte & 0xF;
+                } else {
+                    byte = *srcPtr++;
+                    idx = (byte>>4) & 0xF;
+                }
+                clr = ap[idx];
+                v = __intVal(clr);
 #ifdef __MSBFIRST
-		((short *)dstPtr)[0] = v;
+                ((short *)dstPtr)[0] = v;
 #else
 # ifdef xxSWAP_BYTES
-		SWAP_BYTES(v);
-		((short *)dstPtr)[0] = v;
+                SWAP_BYTES(v);
+                ((short *)dstPtr)[0] = v;
 # else
-		dstPtr[0] = (v>>8) & 0xFF;
-		dstPtr[1] = (v) & 0xFF;
+                dstPtr[0] = (v>>8) & 0xFF;
+                dstPtr[1] = (v) & 0xFF;
 # endif
 #endif
-		dstPtr += 2;
+                dstPtr += 2;
 
-		if (++r == w) {
-		    dstPtr += p;
-		    r = 0;
-		}
-	    }
-	}
+                if (++r == w) {
+                    dstPtr += p;
+                    r = 0;
+                }
+            }
+        }
 %}.
     ] ifFalse:[
-	usedDeviceBitsPerPixel == 32 ifTrue:[
-	    "/ 32 bits/pixel
+        usedDeviceBitsPerPixel == 32 ifTrue:[
+            "/ 32 bits/pixel
 
-	    "/ now, walk over the image and replace
-	    "/ colorMap indices by color values in the bits array
+            "/ now, walk over the image and replace
+            "/ colorMap indices by color values in the bits array
 
 %{
-	    unsigned char *srcPtr = 0;
-	    unsigned char *dstPtr = 0;
-	    OBJ _bytes = __INST(bytes);
+            unsigned char *srcPtr = 0;
+            unsigned char *dstPtr = 0;
+            OBJ _bytes = __INST(bytes);
 
-	    if (__isByteArrayLike(_bytes)) {
-		srcPtr = __ByteArrayInstPtr(_bytes)->ba_element;
-	    } else {
-		if (__isExternalBytesLike(_bytes)) {
-		    srcPtr = __externalBytesAddress(_bytes);
-		}
-	    }
-	    if (__isByteArray(imageBits)) {
-		dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
-	    } else {
-		if (__isExternalBytesLike(imageBits)) {
-		    dstPtr = __externalBytesAddress(imageBits);
-		}
-	    }
+            if (__isByteArrayLike(_bytes)) {
+                srcPtr = __ByteArrayInstPtr(_bytes)->ba_element;
+            } else {
+                if (__isExternalBytesLike(_bytes)) {
+                    srcPtr = __externalBytesAddress(_bytes);
+                }
+            }
+            if (__isByteArray(imageBits)) {
+                dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
+            } else {
+                if (__isExternalBytesLike(imageBits)) {
+                    dstPtr = __externalBytesAddress(imageBits);
+                }
+            }
 
-	    if (__bothSmallInteger(__INST(height), __INST(width))
-	     && __isArrayLike(colorValues)
-	     && srcPtr
-	     && dstPtr) {
-		int x, y, w, h, nPix;
-		int r,p;
-		int byte;
+            if (__bothSmallInteger(__INST(height), __INST(width))
+             && __isArrayLike(colorValues)
+             && srcPtr
+             && dstPtr) {
+                int x, y, w, h, nPix;
+                int r,p;
+                int byte;
 
-		OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
+                OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
 
-		w = __intVal(__INST(width));
-		h = __intVal(__INST(height));
-		r = 0;
-		p = __intVal(padd);
-		nPix = w * h;
-		while (nPix > 0) {
-		    unsigned idx, v;
-		    OBJ clr;
+                w = __intVal(__INST(width));
+                h = __intVal(__INST(height));
+                r = 0;
+                p = __intVal(padd);
+                nPix = w * h;
+                while (nPix > 0) {
+                    unsigned idx, v;
+                    OBJ clr;
 
-		    if (r & 1) {
-			idx = byte & 0xF;
-		    } else {
-			byte = *srcPtr++;
-			idx = (byte>>4) & 0xF;
-		    }
-		    clr = ap[idx];
-		    v = __intVal(clr);
+                    if (r & 1) {
+                        idx = byte & 0xF;
+                    } else {
+                        byte = *srcPtr++;
+                        idx = (byte>>4) & 0xF;
+                    }
+                    clr = ap[idx];
+                    v = __intVal(clr);
 #ifdef __MSBFIRST
-		    ((long *)dstPtr)[0] = v;
+                    ((long *)dstPtr)[0] = v;
 #else
-		    dstPtr[0] = (v>>24) & 0xFF;
-		    dstPtr[1] = (v>>16) & 0xFF;
-		    dstPtr[2] = (v>>8) & 0xFF;
-		    dstPtr[3] = (v) & 0xFF;
+                    dstPtr[0] = (v>>24) & 0xFF;
+                    dstPtr[1] = (v>>16) & 0xFF;
+                    dstPtr[2] = (v>>8) & 0xFF;
+                    dstPtr[3] = (v) & 0xFF;
 #endif
-		    dstPtr += 4;
-		    nPix--;
+                    dstPtr += 4;
+                    nPix--;
 
-		    if (++r == w) {
-			dstPtr += p;
-			r = 0;
-		    }
-		}
-	    }
+                    if (++r == w) {
+                        dstPtr += p;
+                        r = 0;
+                    }
+                }
+            }
 %}.
-	] ifFalse:[
-	    usedDeviceBitsPerPixel == 8 ifTrue:[
-		"/ 8 bits/pixel
+        ] ifFalse:[
+            usedDeviceBitsPerPixel == 8 ifTrue:[
+                "/ 8 bits/pixel
 
-		"/ now, walk over the image and replace
-		"/ colorMap indices by color values in the bits array
+                "/ now, walk over the image and replace
+                "/ colorMap indices by color values in the bits array
 
 %{
-		unsigned char *srcPtr = 0;
-		unsigned char *dstPtr = 0;
-		OBJ _bytes = __INST(bytes);
+                unsigned char *srcPtr = 0;
+                unsigned char *dstPtr = 0;
+                OBJ _bytes = __INST(bytes);
 
-		if (__isByteArrayLike(_bytes)) {
-		    srcPtr = __ByteArrayInstPtr(_bytes)->ba_element;
-		} else {
-		    if (__isExternalBytesLike(_bytes)) {
-			srcPtr = __externalBytesAddress(_bytes);
-		    }
-		}
-		if (__isByteArray(imageBits)) {
-		    dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
-		} else {
-		    if (__isExternalBytesLike(imageBits)) {
-			dstPtr = __externalBytesAddress(imageBits);
-		    }
-		}
+                if (__isByteArrayLike(_bytes)) {
+                    srcPtr = __ByteArrayInstPtr(_bytes)->ba_element;
+                } else {
+                    if (__isExternalBytesLike(_bytes)) {
+                        srcPtr = __externalBytesAddress(_bytes);
+                    }
+                }
+                if (__isByteArray(imageBits)) {
+                    dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
+                } else {
+                    if (__isExternalBytesLike(imageBits)) {
+                        dstPtr = __externalBytesAddress(imageBits);
+                    }
+                }
 
-		if (__bothSmallInteger(__INST(height), __INST(width))
-		 && __isArrayLike(colorValues)
-		 && srcPtr
-		 && dstPtr) {
-		    int x, y, w, h, nPix;
-		    int r,p, byte;
+                if (__bothSmallInteger(__INST(height), __INST(width))
+                 && __isArrayLike(colorValues)
+                 && srcPtr
+                 && dstPtr) {
+                    int x, y, w, h, nPix;
+                    int r,p, byte;
 
-		    OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
+                    OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
 
-		    w = __intVal(__INST(width));
-		    h = __intVal(__INST(height));
-		    r = 0;
-		    p = __intVal(padd);
+                    w = __intVal(__INST(width));
+                    h = __intVal(__INST(height));
+                    r = 0;
+                    p = __intVal(padd);
 
-		    nPix = w * h;
-		    while (nPix > 0) {
-			unsigned idx, v;
-			OBJ clr;
+                    nPix = w * h;
+                    while (nPix > 0) {
+                        unsigned idx, v;
+                        OBJ clr;
 
-			if (r & 1) {
-			    idx = byte & 0xF;
-			} else {
-			    byte = *srcPtr++;
-			    idx = (byte>>4) & 0xF;
-			}
-			clr = ap[idx];
-			v = __intVal(clr);
+                        if (r & 1) {
+                            idx = byte & 0xF;
+                        } else {
+                            byte = *srcPtr++;
+                            idx = (byte>>4) & 0xF;
+                        }
+                        clr = ap[idx];
+                        v = __intVal(clr);
 
-			dstPtr[0] = v;
+                        dstPtr[0] = v;
 
-			dstPtr += 1;
-			nPix--;
+                        dstPtr += 1;
+                        nPix--;
 
-			if (++r == w) {
-			    dstPtr += p;
-			    r = 0;
-			}
-		    }
-		}
+                        if (++r == w) {
+                            dstPtr += p;
+                            r = 0;
+                        }
+                    }
+                }
 %}.
-	    ] ifFalse:[
-		usedDeviceBitsPerPixel == 24 ifTrue:[
-		    "/ 24 bits/pixel
+            ] ifFalse:[
+                usedDeviceBitsPerPixel == 24 ifTrue:[
+                    "/ 24 bits/pixel
 
-		    "/ now, walk over the image and replace
-		    "/ colorMap indices by color values in the bits array
+                    "/ now, walk over the image and replace
+                    "/ colorMap indices by color values in the bits array
 
 %{
-		    unsigned char *srcPtr = 0;
-		    unsigned char *dstPtr = 0;
-		    OBJ _bytes = __INST(bytes);
+                    unsigned char *srcPtr = 0;
+                    unsigned char *dstPtr = 0;
+                    OBJ _bytes = __INST(bytes);
 
-		    if (__isByteArrayLike(_bytes)) {
-			srcPtr = __ByteArrayInstPtr(_bytes)->ba_element;
-		    } else {
-			if (__isExternalBytesLike(_bytes)) {
-			    srcPtr = __externalBytesAddress(_bytes);
-			}
-		    }
-		    if (__isByteArray(imageBits)) {
-			dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
-		    } else {
-			if (__isExternalBytesLike(imageBits)) {
-			    dstPtr = __externalBytesAddress(imageBits);
-			}
-		    }
+                    if (__isByteArrayLike(_bytes)) {
+                        srcPtr = __ByteArrayInstPtr(_bytes)->ba_element;
+                    } else {
+                        if (__isExternalBytesLike(_bytes)) {
+                            srcPtr = __externalBytesAddress(_bytes);
+                        }
+                    }
+                    if (__isByteArray(imageBits)) {
+                        dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
+                    } else {
+                        if (__isExternalBytesLike(imageBits)) {
+                            dstPtr = __externalBytesAddress(imageBits);
+                        }
+                    }
 
-		    if (__bothSmallInteger(__INST(height), __INST(width))
-		     && __isArrayLike(colorValues)
-		     && srcPtr
-		     && dstPtr) {
-			int x, y, w, h, nPix;
-			int r, p, byte;
+                    if (__bothSmallInteger(__INST(height), __INST(width))
+                     && __isArrayLike(colorValues)
+                     && srcPtr
+                     && dstPtr) {
+                        int x, y, w, h, nPix;
+                        int r, p, byte;
 
-			OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
+                        OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
 
-			w = __intVal(__INST(width));
-			h = __intVal(__INST(height));
-			r = 0;
-			p = __intVal(padd);
+                        w = __intVal(__INST(width));
+                        h = __intVal(__INST(height));
+                        r = 0;
+                        p = __intVal(padd);
 
-			nPix = w * h;
-			while (nPix > 0) {
-			    unsigned idx, v;
-			    OBJ clr;
+                        nPix = w * h;
+                        while (nPix > 0) {
+                            unsigned idx, v;
+                            OBJ clr;
 
-			    if (r & 1) {
-				idx = byte & 0xF;
-			    } else {
-				byte = *srcPtr++;
-				idx = (byte>>4) & 0xF;
-			    }
-			    clr = ap[idx];
-			    v = __intVal(clr);
+                            if (r & 1) {
+                                idx = byte & 0xF;
+                            } else {
+                                byte = *srcPtr++;
+                                idx = (byte>>4) & 0xF;
+                            }
+                            clr = ap[idx];
+                            v = __intVal(clr);
 
-			    dstPtr[0] = (v>>16) & 0xFF;
-			    dstPtr[1] = (v>>8) & 0xFF;
-			    dstPtr[2] = (v) & 0xFF;
+                            dstPtr[0] = (v>>16) & 0xFF;
+                            dstPtr[1] = (v>>8) & 0xFF;
+                            dstPtr[2] = (v) & 0xFF;
 
-			    dstPtr += 3;
-			    nPix--;
+                            dstPtr += 3;
+                            nPix--;
 
-			    if (++r == w) {
-				dstPtr += p;
-				r = 0;
-			    }
-			}
-		    }
+                            if (++r == w) {
+                                dstPtr += p;
+                                r = 0;
+                            }
+                        }
+                    }
 %}.
-		] ifFalse:[
-		    'Image [warning]: unimplemented trueColor depth in anyImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR.
-		    ^ nil
-		]
-	    ]
-	]
+                ] ifFalse:[
+                    'Image [warning]: unimplemented trueColor depth in anyImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR.
+                    ^ nil
+                ]
+            ]
+        ]
     ].
 
     imageBits isNil ifTrue:[
-	^ nil
+        ^ nil
     ].
 
-    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
+    form := Form imageForm width:width height:height depth:usedDeviceDepth onDevice:aDevice.
     form isNil ifTrue:[^ nil].
     form initGC.
 
     form
-	copyBitsFrom:imageBits
-	bitsPerPixel:usedDeviceBitsPerPixel
-	depth:usedDeviceDepth
-	padding:usedDevicePadding
-	width:width height:height
-	x:0 y:0
-	toX:0 y:0.
+        copyBitsFrom:imageBits
+        bitsPerPixel:usedDeviceBitsPerPixel
+        depth:usedDeviceDepth
+        padding:usedDevicePadding
+        width:width height:height
+        x:0 y:0
+        toX:0 y:0.
 
     ^ form