Depth8Image.st
changeset 4764 80e412455815
parent 4724 f7db00bce050
child 4783 717a41ef31e4
--- a/Depth8Image.st	Tue May 29 12:16:46 2007 +0200
+++ b/Depth8Image.st	Tue May 29 19:19:59 2007 +0200
@@ -9,7 +9,6 @@
  other person.  No title to or ownership of the software is
  hereby transferred.
 "
-
 "{ Package: 'stx:libview' }"
 
 Image subclass:#Depth8Image
@@ -602,7 +601,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.
@@ -614,349 +613,349 @@
     "/ 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 (__isByteArray(_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 (__isByteArray(_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;
-	    unsigned short pixels[256];
+        if (__bothSmallInteger(_INST(height), _INST(width))
+         && __isArrayLike(colorValues)
+         && srcPtr
+         && dstPtr) {
+            int r,p;
+            int x, y, w, h, nPix;
+            unsigned short pixels[256];
 
-	    OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
+            OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
 
-	    nPix = __arraySize(colorValues);
-	    for (p=0; p<nPix; p++) {
-		pixels[p] = __intVal(ap[p]);
-	    }
+            nPix = __arraySize(colorValues);
+            for (p=0; p<nPix; p++) {
+                pixels[p] = __intVal(ap[p]);
+            }
 
-	    w = __intVal(_INST(width));
-	    h = __intVal(_INST(height));
-	    r = w;
-	    p = __intVal(padd);
-	    nPix = w * h;
+            w = __intVal(_INST(width));
+            h = __intVal(_INST(height));
+            r = w;
+            p = __intVal(padd);
+            nPix = w * h;
 
-	    while (nPix > 0) {
-		unsigned idx, v;
+            while (nPix > 0) {
+                unsigned idx, v;
 
-		if (((unsigned INT)srcPtr & 3) == 0) {
-		    unsigned INT idx4;
+                if (((unsigned INT)srcPtr & 3) == 0) {
+                    unsigned INT idx4;
 
-		    while (r > 4) {
+                    while (r > 4) {
 #ifdef __MSBFIRST
-			idx4 = ((unsigned int *)srcPtr)[0];
-			v = pixels[(idx4 >> 24) & 0xFF];
-			((short *)dstPtr)[0] = v;
-			v = pixels[(idx4 >> 16) & 0xFF];
-			((short *)dstPtr)[1] = v;
-			v = pixels[(idx4 >> 8) & 0xFF];
-			((short *)dstPtr)[2] = v;
-			v = pixels[idx4 & 0xFF];
-			((short *)dstPtr)[3] = v;
+                        idx4 = ((unsigned int *)srcPtr)[0];
+                        v = pixels[(idx4 >> 24) & 0xFF];
+                        ((short *)dstPtr)[0] = v;
+                        v = pixels[(idx4 >> 16) & 0xFF];
+                        ((short *)dstPtr)[1] = v;
+                        v = pixels[(idx4 >> 8) & 0xFF];
+                        ((short *)dstPtr)[2] = v;
+                        v = pixels[idx4 & 0xFF];
+                        ((short *)dstPtr)[3] = v;
 #else
 # ifdef __LSBFIRST
-			idx4 = ((unsigned int *)srcPtr)[0];
-			v = pixels[idx4 & 0xFF];
-			dstPtr[0] = (v>>8) & 0xFF;
-			dstPtr[1] = (v) & 0xFF;
+                        idx4 = ((unsigned int *)srcPtr)[0];
+                        v = pixels[idx4 & 0xFF];
+                        dstPtr[0] = (v>>8) & 0xFF;
+                        dstPtr[1] = (v) & 0xFF;
 
-			v = pixels[(idx4 >> 8) & 0xFF];
-			dstPtr[2] = (v>>8) & 0xFF;
-			dstPtr[3] = (v) & 0xFF;
+                        v = pixels[(idx4 >> 8) & 0xFF];
+                        dstPtr[2] = (v>>8) & 0xFF;
+                        dstPtr[3] = (v) & 0xFF;
 
-			v = pixels[(idx4 >> 16) & 0xFF];
-			dstPtr[4] = (v>>8) & 0xFF;
-			dstPtr[5] = (v) & 0xFF;
+                        v = pixels[(idx4 >> 16) & 0xFF];
+                        dstPtr[4] = (v>>8) & 0xFF;
+                        dstPtr[5] = (v) & 0xFF;
 
-			v = pixels[(idx4 >> 24) & 0xFF];
-			dstPtr[6] = (v>>8) & 0xFF;
-			dstPtr[7] = (v) & 0xFF;
+                        v = pixels[(idx4 >> 24) & 0xFF];
+                        dstPtr[6] = (v>>8) & 0xFF;
+                        dstPtr[7] = (v) & 0xFF;
 # else /* unknown/unspecified - code below works on any machine */
-			idx = srcPtr[0];
-			v = pixels[idx];
-			dstPtr[0] = (v>>8) & 0xFF;
-			dstPtr[1] = (v) & 0xFF;
+                        idx = srcPtr[0];
+                        v = pixels[idx];
+                        dstPtr[0] = (v>>8) & 0xFF;
+                        dstPtr[1] = (v) & 0xFF;
 
-			idx = srcPtr[1];
-			v = pixels[idx];
-			dstPtr[2] = (v>>8) & 0xFF;
-			dstPtr[3] = (v) & 0xFF;
+                        idx = srcPtr[1];
+                        v = pixels[idx];
+                        dstPtr[2] = (v>>8) & 0xFF;
+                        dstPtr[3] = (v) & 0xFF;
 
-			idx = srcPtr[2];
-			v = pixels[idx];
-			dstPtr[4] = (v>>8) & 0xFF;
-			dstPtr[5] = (v) & 0xFF;
+                        idx = srcPtr[2];
+                        v = pixels[idx];
+                        dstPtr[4] = (v>>8) & 0xFF;
+                        dstPtr[5] = (v) & 0xFF;
 
-			idx = srcPtr[3];
-			v = pixels[idx];
-			dstPtr[6] = (v>>8) & 0xFF;
-			dstPtr[7] = (v) & 0xFF;
+                        idx = srcPtr[3];
+                        v = pixels[idx];
+                        dstPtr[6] = (v>>8) & 0xFF;
+                        dstPtr[7] = (v) & 0xFF;
 # endif
 #endif
-			r -= 4;
-			dstPtr += 8;
-			nPix -= 4;
-			srcPtr +=4;
-		    }
-		}
+                        r -= 4;
+                        dstPtr += 8;
+                        nPix -= 4;
+                        srcPtr +=4;
+                    }
+                }
 
-		nPix--;
+                nPix--;
 
-		idx = *srcPtr++;
-		v = pixels[idx];
+                idx = *srcPtr++;
+                v = pixels[idx];
 #ifdef __MSBFIRST
-		((short *)dstPtr)[0] = 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
-		dstPtr += 2;
+                dstPtr += 2;
 
-		if (--r == 0) {
-		    dstPtr += p;
-		    r = w;
-		}
-	    }
-	}
+                if (--r == 0) {
+                    dstPtr += p;
+                    r = w;
+                }
+            }
+        }
 %}.
     ] 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 (__isByteArray(_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 (__isByteArray(_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;
+            if (__bothSmallInteger(_INST(height), _INST(width))
+             && __isArrayLike(colorValues)
+             && srcPtr
+             && dstPtr) {
+                int x, y, w, h, nPix;
 
-		OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
+                OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
 
-		w = __intVal(_INST(width));
-		h = __intVal(_INST(height));
-		nPix = w * h;
-		while (nPix > 0) {
-		    unsigned idx, v;
-		    OBJ clr;
+                w = __intVal(_INST(width));
+                h = __intVal(_INST(height));
+                nPix = w * h;
+                while (nPix > 0) {
+                    unsigned idx, v;
+                    OBJ clr;
 
-		    idx = *srcPtr;
-		    clr = ap[idx];
-		    v = __intVal(clr);
+                    idx = *srcPtr;
+                    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;
-		    srcPtr += 1;
-		    nPix--;
-		}
-	    }
+                    dstPtr += 4;
+                    srcPtr += 1;
+                    nPix--;
+                }
+            }
 %}.
-	] 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 (__isByteArray(_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 (__isByteArray(_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;
+                if (__bothSmallInteger(_INST(height), _INST(width))
+                 && __isArrayLike(colorValues)
+                 && srcPtr
+                 && dstPtr) {
+                    int x, y, w, h, nPix;
+                    int r,p;
 
-		    OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
+                    OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
 
-		    w = __intVal(_INST(width));
-		    h = __intVal(_INST(height));
-		    r = w;
-		    p = __intVal(padd);
+                    w = __intVal(_INST(width));
+                    h = __intVal(_INST(height));
+                    r = w;
+                    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;
 
-			idx = *srcPtr;
-			clr = ap[idx];
-			v = __intVal(clr);
+                        idx = *srcPtr;
+                        clr = ap[idx];
+                        v = __intVal(clr);
 
-			dstPtr[0] = v;
+                        dstPtr[0] = v;
 
-			dstPtr += 1;
-			srcPtr += 1;
-			nPix--;
+                        dstPtr += 1;
+                        srcPtr += 1;
+                        nPix--;
 
-			if (--r == 0) {
-			  dstPtr += p;
-			  r = w;
-			}
+                        if (--r == 0) {
+                          dstPtr += p;
+                          r = w;
+                        }
 
-		    }
-		}
+                    }
+                }
 %}.
-	    ] 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 (__isByteArray(_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 (__isByteArray(_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;
+                    if (__bothSmallInteger(_INST(height), _INST(width))
+                     && __isArrayLike(colorValues)
+                     && srcPtr
+                     && dstPtr) {
+                        int x, y, w, h, nPix;
+                        int r,p;
 
-			OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
+                        OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
 
-			w = __intVal(_INST(width));
-			h = __intVal(_INST(height));
-			r = w;
-			p = __intVal(padd);
+                        w = __intVal(_INST(width));
+                        h = __intVal(_INST(height));
+                        r = w;
+                        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;
 
-			    idx = *srcPtr;
-			    clr = ap[idx];
-			    v = __intVal(clr);
+                            idx = *srcPtr;
+                            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;
-			    srcPtr += 1;
-			    nPix--;
-			    if (--r == 0) {
-			      dstPtr += p;
-			      r = w;
-			    }
-			}
-		    }
+                            dstPtr += 3;
+                            srcPtr += 1;
+                            nPix--;
+                            if (--r == 0) {
+                              dstPtr += p;
+                              r = w;
+                            }
+                        }
+                    }
 %}.
-		]
-	    ]
-	]
+                ]
+            ]
+        ]
     ].
 
     imageBits isNil ifTrue:[
-	'Image [warning]: unimplemented trueColor depth in paletteImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR.
-	^ self asMonochromeFormOn:aDevice
+        'Image [warning]: unimplemented trueColor depth in paletteImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR.
+        ^ self asMonochromeFormOn:aDevice
     ].
 
-    form := Form width:width height:height depth:usedDeviceDepth on:aDevice.
+    form := Form 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
 
-    "Created: 20.10.1995 / 22:05:10 / cg"
-    "Modified: 21.10.1995 / 19:30:26 / cg"
+    "Created: / 20-10-1995 / 22:05:10 / cg"
+    "Modified: / 29-05-2007 / 19:22:06 / cg"
 !
 
 asGray8FormOn:aDevice
@@ -2444,5 +2443,5 @@
 !Depth8Image class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Depth8Image.st,v 1.109 2007-02-22 15:14:23 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Depth8Image.st,v 1.110 2007-05-29 17:19:59 cg Exp $'
 ! !