Depth24Image.st
changeset 7495 c62bd4c05a4d
parent 7278 52a81602e12c
child 7512 f094e73e5bf8
--- a/Depth24Image.st	Mon Aug 08 17:10:30 2016 +0200
+++ b/Depth24Image.st	Mon Aug 08 17:12:37 2016 +0200
@@ -304,8 +304,8 @@
 
     numFix := fixColors size.
     numFix == 256 ifTrue:[
-	"/ algorithm below only handles 255 colors.
-	numFix := 255.
+        "/ algorithm below only handles 255 colors.
+        numFix := 255.
     ].
 
     fixColorArray := fixColors asArray.
@@ -320,9 +320,9 @@
 
     deviceDepth := aDevice depth.
     deviceDepth == 8 ifFalse:[
-	(aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
-	    ^ nil
-	]
+        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
+            ^ nil
+        ]
     ].
 
     idsUsed := ByteArray new:(fixIds size).
@@ -351,131 +351,131 @@
      && __isByteArrayLike(fixRed)
      && __isByteArrayLike(fixGreen)
      && __isByteArrayLike(fixBlue) ) {
-	failed = false;
-
-	srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
-	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
-	idP = __ByteArrayInstPtr(fixIds)->ba_element;
-	usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element;
-	redP = __ByteArrayInstPtr(fixRed)->ba_element;
-	greenP = __ByteArrayInstPtr(fixGreen)->ba_element;
-	blueP = __ByteArrayInstPtr(fixBlue)->ba_element;
-	cacheP = __ByteArrayInstPtr(cache)->ba_element;
-	__numFix = __intVal(numFix);
-
-	for (__y=__intVal(h); __y>0; __y--) {
-	    __eR = __eG = __eB = 0;
-	    for (__x=__w; __x>0; __x--) {
-		int cacheIdx, clrIdx;
-		int __wantR, __wantG, __wantB;
-
-		__wantR = srcP[0] + __eR;
-		if (__wantR > 255) __wantR = 255;
-		else if (__wantR < 0) __wantR = 0;
-
-		__wantG = srcP[1] + __eG;
-		if (__wantG > 255) __wantG = 255;
-		else if (__wantG < 0) __wantG = 0;
-
-		__wantB = srcP[2] + __eB;
-		if (__wantB > 255) __wantB = 255;
-		else if (__wantB < 0) __wantB = 0;
-
-		/*
-		 * compute cache index
-		 */
-		cacheIdx = ((__wantR & 0xF8) >> 3);
-		cacheIdx = (cacheIdx << 5) | ((__wantG & 0xF8) >> 3);
-		cacheIdx = (cacheIdx << 4) | ((__wantB & 0xF0) >> 4);
-
-		clrIdx = cacheP[cacheIdx];
-		if (clrIdx == 0xFF) {   /* invalid slot */
-		    unsigned minErr, minIdx;
-		    int i;
-
-		    /*
-		     * must search ...
-		     */
-		    minErr = 0x7FFFFFF; minIdx = 0;
-		    for (i=0; i<__numFix; i++) {
-			unsigned cR, cG, cB, e;
-			int eR, eG, eB;
-
-			cR = redP[i]; cG = greenP[i]; cB = blueP[i];
-			eR = cR - __wantR;
-			if (eR < 0) eR = -eR;
-
-			eG = cG - __wantG;
-			if (eG < 0) eG = -eG;
-
-			eB = cB - __wantB;
-			if (eB < 0) eB = -eB;
-
-			e = eR + eG + eB;
-			if (e < minErr) {
-			    minErr = e;
-			    minIdx = i;
-			    if (e < 7) {
-				break;
-			    }
-			}
-		    }
-
-		    /*
-		     * minIdx is now index into fixColors
-		     */
-		    cacheP[cacheIdx] = clrIdx = minIdx;
+        failed = false;
+
+        srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
+        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
+        idP = __ByteArrayInstPtr(fixIds)->ba_element;
+        usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element;
+        redP = __ByteArrayInstPtr(fixRed)->ba_element;
+        greenP = __ByteArrayInstPtr(fixGreen)->ba_element;
+        blueP = __ByteArrayInstPtr(fixBlue)->ba_element;
+        cacheP = __ByteArrayInstPtr(cache)->ba_element;
+        __numFix = __intVal(numFix);
+
+        for (__y=__intVal(h); __y>0; __y--) {
+            __eR = __eG = __eB = 0;
+            for (__x=__w; __x>0; __x--) {
+                int cacheIdx, clrIdx;
+                int __wantR, __wantG, __wantB;
+
+                __wantR = srcP[0] + __eR;
+                if (__wantR > 255) __wantR = 255;
+                else if (__wantR < 0) __wantR = 0;
+
+                __wantG = srcP[1] + __eG;
+                if (__wantG > 255) __wantG = 255;
+                else if (__wantG < 0) __wantG = 0;
+
+                __wantB = srcP[2] + __eB;
+                if (__wantB > 255) __wantB = 255;
+                else if (__wantB < 0) __wantB = 0;
+
+                /*
+                 * compute cache index
+                 */
+                cacheIdx = ((__wantR & 0xF8) >> 3);
+                cacheIdx = (cacheIdx << 5) | ((__wantG & 0xF8) >> 3);
+                cacheIdx = (cacheIdx << 4) | ((__wantB & 0xF0) >> 4);
+
+                clrIdx = cacheP[cacheIdx];
+                if (clrIdx == 0xFF) {   /* invalid slot */
+                    unsigned minErr, minIdx;
+                    int i;
+
+                    /*
+                     * must search ...
+                     */
+                    minErr = 0x7FFFFFF; minIdx = 0;
+                    for (i=0; i<__numFix; i++) {
+                        unsigned cR, cG, cB, e;
+                        int eR, eG, eB;
+
+                        cR = redP[i]; cG = greenP[i]; cB = blueP[i];
+                        eR = cR - __wantR;
+                        if (eR < 0) eR = -eR;
+
+                        eG = cG - __wantG;
+                        if (eG < 0) eG = -eG;
+
+                        eB = cB - __wantB;
+                        if (eB < 0) eB = -eB;
+
+                        e = eR + eG + eB;
+                        if (e < minErr) {
+                            minErr = e;
+                            minIdx = i;
+                            if (e < 7) {
+                                break;
+                            }
+                        }
+                    }
+
+                    /*
+                     * minIdx is now index into fixColors
+                     */
+                    cacheP[cacheIdx] = clrIdx = minIdx;
 /*
 console_fprintf(stderr, "want %d/%d/%d best: %d [%d/%d/%d]\n", __wantR, __wantG, __wantB, clrIdx, redP[clrIdx], greenP[clrIdx], blueP[clrIdx]);
 */
-		}
-
-		/*
-		 * store the corresponding dither colorId
-		 */
-		*dstP++ = idP[clrIdx];
-		usedIdP[clrIdx] = 1;
-
-		srcP += 3;
-
-		/*
-		 * the new error:
-		 */
-		__eR = __wantR - redP[clrIdx];
-		__eG = __wantG - greenP[clrIdx];
-		__eB = __wantB - blueP[clrIdx];
-	    }
-	}
+                }
+
+                /*
+                 * store the corresponding dither colorId
+                 */
+                *dstP++ = idP[clrIdx];
+                usedIdP[clrIdx] = 1;
+
+                srcP += 3;
+
+                /*
+                 * the new error:
+                 */
+                __eR = __wantR - redP[clrIdx];
+                __eG = __wantG - greenP[clrIdx];
+                __eB = __wantB - blueP[clrIdx];
+            }
+        }
     }
 %}.
     failed ifTrue:[
-	self primitiveFailed.
-	^ nil
+        self primitiveFailed.
+        ^ nil
     ].
 
     "/ not all colors may be really in use ...
     usedColors := fixColors copy.
     idsUsed keysAndValuesDo:[:idx :flag |
-	flag == 0 ifTrue:[
-	    usedColors at:idx put:nil
-	]
+        flag == 0 ifTrue:[
+            usedColors at:idx put:nil
+        ]
     ].
 
-    f := Form width:width height:height depth:aDevice depth onDevice:aDevice.
+    f := Form imageForm width:width height:height depth:aDevice depth onDevice:aDevice.
     f isNil ifTrue:[^ nil].
     f colorMap:usedColors.
     f initGC.
     aDevice
-	drawBits:pseudoBits
-	bitsPerPixel:8
-	depth:aDevice depth
-	padding:8
-	width:width height:height
-	x:0 y:0
-	into:(f id)
-	x:0 y:0
-	width:width height:height
-	with:(f gcId).
+        drawBits:pseudoBits
+        bitsPerPixel:8
+        depth:aDevice depth
+        padding:8
+        width:width height:height
+        x:0 y:0
+        into:(f id)
+        x:0 y:0
+        width:width height:height
+        with:(f gcId).
     ^ f
 !
 
@@ -506,17 +506,17 @@
     fixB == 0 ifTrue:[ ^ nil].
     "/ simple check
     (fixR * fixG * fixB) ~~ fixColors size ifTrue:[
-	self error:'invalid color array passed'.
-	^ nil
+        self error:'invalid color array passed'.
+        ^ nil
     ].
     fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray.
     idsUsed := ByteArray new:(fixIds size).
 
     deviceDepth := aDevice depth.
     deviceDepth == 8 ifFalse:[
-	(aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
-	    ^ nil
-	]
+        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
+            ^ nil
+        ]
     ].
 
     'Depth24Image [info]: dithering ...' infoPrintCR.
@@ -547,136 +547,136 @@
      && __isByteArrayLike(idsUsed)
      && __bothSmallInteger(fixR, fixG)
      && __isSmallInteger(fixB)) {
-	failed = false;
-
-	srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
-	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
-	idP = __ByteArrayInstPtr(fixIds)->ba_element;
-	usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element;
-	__fR = __intVal(fixR)-1;
-	__fG = __intVal(fixG)-1;
-	__fB = __intVal(fixB)-1;
-
-	__eR = __eG = __eB = 0;
-
-	leftToRight = 1;
-	for (__y=__intVal(h); __y>0; __y--) {
-	    if (leftToRight) {
-		for (__x=__w; __x>0; __x--) {
-		    int __want;
-
-		    /*
-		     * wR, wG and wB is the wanted r/g/b value;
-		     * compute the index into the dId table ..
-		     * values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1
-		     *
-		     * bad kludge: knows how to index into FixColor table
-		     */
-		    __wantR = __want = srcP[0] + __eR;
-
-		    if (__want > 255) __want = 255;
-		    else if (__want < 0) __want = 0;
-
-		    iR = __want * __fR / 128;
-		    iR = (iR / 2) + (iR & 1);
-
-		    __wantG = __want = srcP[1] + __eG;
-		    if (__want > 255) __want = 255;
-		    else if (__want < 0) __want = 0;
-
-		    iG = __want * __fG / 128;
-		    iG = (iG / 2) + (iG & 1);
-
-		    __wantB = __want = srcP[2] + __eB;
-		    if (__want > 255) __want = 255;
-		    else if (__want < 0) __want = 0;
-
-		    iB = __want * __fB / 128;
-		    iB = (iB / 2) + (iB & 1);
-
-		    idx = iR * (__fG+1);
-		    idx = (idx + iG) * (__fB+1);
-		    idx = idx + iB;
-
-		    /*
-		     * store the corresponding dither colorId
-		     */
-		    *dstP++ = idP[idx];
-		    usedIdP[idx] = 1;
-
-		    srcP += 3;
-
-		    /*
-		     * the new error:
-		     */
-		    __eR = __wantR - (iR * 256 / __fR);
-		    __eG = __wantG - (iG * 256 / __fG);
-		    __eB = __wantB - (iB * 256 / __fB);
-		}
-		leftToRight = 0;
-	    } else {
-		srcP += (__w*3);
-		dstP += __w;
-		for (__x=__w; __x>0; __x--) {
-		    int __want;
-
-		    /*
-		     * wR, wG and wB is the wanted r/g/b value;
-		     * compute the index into the dId table ..
-		     * values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1
-		     *
-		     * bad kludge: knows how to index into FixColor table
-		     */
-		    srcP -= 3;
-		    __wantR = __want = srcP[0] + __eR;
-
-		    if (__want > 255) __want = 255;
-		    else if (__want < 0) __want = 0;
-
-		    iR = __want * __fR / 128;
-		    iR = (iR / 2) + (iR & 1);
-
-		    __wantG = __want = srcP[1] + __eG;
-		    if (__want > 255) __want = 255;
-		    else if (__want < 0) __want = 0;
-
-		    iG = __want * __fG / 128;
-		    iG = (iG / 2) + (iG & 1);
-
-		    __wantB = __want = srcP[2] + __eB;
-		    if (__want > 255) __want = 255;
-		    else if (__want < 0) __want = 0;
-
-		    iB = __want * __fB / 128;
-		    iB = (iB / 2) + (iB & 1);
-
-		    idx = iR * (__fG+1);
-		    idx = (idx + iG) * (__fB+1);
-		    idx = idx + iB;
-
-		    /*
-		     * store the corresponding dither colorId
-		     */
-		    *--dstP = idP[idx];
-		    usedIdP[idx] = 1;
-
-		    /*
-		     * the new error:
-		     */
-		    __eR = __wantR - (iR * 256 / __fR);
-		    __eG = __wantG - (iG * 256 / __fG);
-		    __eB = __wantB - (iB * 256 / __fB);
-		}
-		srcP += (__w*3);
-		dstP += __w;
-		leftToRight = 1;
-	    }
-	}
+        failed = false;
+
+        srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
+        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
+        idP = __ByteArrayInstPtr(fixIds)->ba_element;
+        usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element;
+        __fR = __intVal(fixR)-1;
+        __fG = __intVal(fixG)-1;
+        __fB = __intVal(fixB)-1;
+
+        __eR = __eG = __eB = 0;
+
+        leftToRight = 1;
+        for (__y=__intVal(h); __y>0; __y--) {
+            if (leftToRight) {
+                for (__x=__w; __x>0; __x--) {
+                    int __want;
+
+                    /*
+                     * wR, wG and wB is the wanted r/g/b value;
+                     * compute the index into the dId table ..
+                     * values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1
+                     *
+                     * bad kludge: knows how to index into FixColor table
+                     */
+                    __wantR = __want = srcP[0] + __eR;
+
+                    if (__want > 255) __want = 255;
+                    else if (__want < 0) __want = 0;
+
+                    iR = __want * __fR / 128;
+                    iR = (iR / 2) + (iR & 1);
+
+                    __wantG = __want = srcP[1] + __eG;
+                    if (__want > 255) __want = 255;
+                    else if (__want < 0) __want = 0;
+
+                    iG = __want * __fG / 128;
+                    iG = (iG / 2) + (iG & 1);
+
+                    __wantB = __want = srcP[2] + __eB;
+                    if (__want > 255) __want = 255;
+                    else if (__want < 0) __want = 0;
+
+                    iB = __want * __fB / 128;
+                    iB = (iB / 2) + (iB & 1);
+
+                    idx = iR * (__fG+1);
+                    idx = (idx + iG) * (__fB+1);
+                    idx = idx + iB;
+
+                    /*
+                     * store the corresponding dither colorId
+                     */
+                    *dstP++ = idP[idx];
+                    usedIdP[idx] = 1;
+
+                    srcP += 3;
+
+                    /*
+                     * the new error:
+                     */
+                    __eR = __wantR - (iR * 256 / __fR);
+                    __eG = __wantG - (iG * 256 / __fG);
+                    __eB = __wantB - (iB * 256 / __fB);
+                }
+                leftToRight = 0;
+            } else {
+                srcP += (__w*3);
+                dstP += __w;
+                for (__x=__w; __x>0; __x--) {
+                    int __want;
+
+                    /*
+                     * wR, wG and wB is the wanted r/g/b value;
+                     * compute the index into the dId table ..
+                     * values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1
+                     *
+                     * bad kludge: knows how to index into FixColor table
+                     */
+                    srcP -= 3;
+                    __wantR = __want = srcP[0] + __eR;
+
+                    if (__want > 255) __want = 255;
+                    else if (__want < 0) __want = 0;
+
+                    iR = __want * __fR / 128;
+                    iR = (iR / 2) + (iR & 1);
+
+                    __wantG = __want = srcP[1] + __eG;
+                    if (__want > 255) __want = 255;
+                    else if (__want < 0) __want = 0;
+
+                    iG = __want * __fG / 128;
+                    iG = (iG / 2) + (iG & 1);
+
+                    __wantB = __want = srcP[2] + __eB;
+                    if (__want > 255) __want = 255;
+                    else if (__want < 0) __want = 0;
+
+                    iB = __want * __fB / 128;
+                    iB = (iB / 2) + (iB & 1);
+
+                    idx = iR * (__fG+1);
+                    idx = (idx + iG) * (__fB+1);
+                    idx = idx + iB;
+
+                    /*
+                     * store the corresponding dither colorId
+                     */
+                    *--dstP = idP[idx];
+                    usedIdP[idx] = 1;
+
+                    /*
+                     * the new error:
+                     */
+                    __eR = __wantR - (iR * 256 / __fR);
+                    __eG = __wantG - (iG * 256 / __fG);
+                    __eB = __wantB - (iB * 256 / __fB);
+                }
+                srcP += (__w*3);
+                dstP += __w;
+                leftToRight = 1;
+            }
+        }
     }
 %}.
     failed ifTrue:[
-	self primitiveFailed.
-	^ nil
+        self primitiveFailed.
+        ^ nil
 
 "/ for non-C programmers:
 "/     the above code is (roughly) equivalent to:
@@ -731,26 +731,26 @@
     "/ not all colors may be really in use ...
     usedColors := fixColors copy.
     idsUsed keysAndValuesDo:[:idx :flag |
-	flag == 0 ifTrue:[
-	    usedColors at:idx put:nil
-	]
+        flag == 0 ifTrue:[
+            usedColors at:idx put:nil
+        ]
     ].
 
-    f := Form width:width height:height depth:aDevice depth onDevice:aDevice.
+    f := Form imageForm width:width height:height depth:aDevice depth onDevice:aDevice.
     f isNil ifTrue:[^ nil].
     f colorMap:usedColors.
     f initGC.
     aDevice
-	drawBits:pseudoBits
-	bitsPerPixel:8
-	depth:aDevice depth
-	padding:8
-	width:width height:height
-	x:0 y:0
-	into:(f id)
-	x:0 y:0
-	width:width height:height
-	with:(f gcId).
+        drawBits:pseudoBits
+        bitsPerPixel:8
+        depth:aDevice depth
+        padding:8
+        width:width height:height
+        x:0 y:0
+        into:(f id)
+        x:0 y:0
+        width:width height:height
+        with:(f gcId).
     ^ f
 !
 
@@ -779,10 +779,10 @@
      depth nColorCells deep nColorsNeeded bytes|
 
     aDevice fixColors notNil ifTrue:[
-	"/ no need to look for used colors - dithering anyway ...
-
-	f := self rgbImageAsDitheredPseudoFormOn:aDevice.
-	f notNil ifTrue:[^ f].
+        "/ no need to look for used colors - dithering anyway ...
+
+        f := self rgbImageAsDitheredPseudoFormOn:aDevice.
+        f notNil ifTrue:[^ f].
     ].
 
     bytes := self bits.
@@ -803,210 +803,210 @@
     'Depth24Image [info]: allocating colors ...' infoPrintCR.
 
     [fit] whileFalse:[
-	[fitMap] whileFalse:[
-	    srcIndex := 1.
-	    redArray := Array new:256.
-
-	    "
-	     find used colors, build [r][g][b] 3-dimensional array
-	     containing true for used colors
-	    "
-	    nColors := 0.
-	    srcIndex := 1.
-	    dataSize := bytes size.
-	    [(srcIndex < dataSize)
-	     and:[nColors <= nColorCells]] whileTrue:[
+        [fitMap] whileFalse:[
+            srcIndex := 1.
+            redArray := Array new:256.
+
+            "
+             find used colors, build [r][g][b] 3-dimensional array
+             containing true for used colors
+            "
+            nColors := 0.
+            srcIndex := 1.
+            dataSize := bytes size.
+            [(srcIndex < dataSize)
+             and:[nColors <= nColorCells]] whileTrue:[
 %{
-		if (__isByteArrayLike(bytes)) {
-		    int sI = __intVal(srcIndex);
-		    unsigned char *cp = __ByteArrayInstPtr(bytes)->ba_element;
-
-		    r = __MKSMALLINT((cp[sI - 1] & __intVal(rMask)) + 1);
-		    g = __MKSMALLINT((cp[sI]     & __intVal(gMask)) + 1);
-		    b = __MKSMALLINT((cp[sI + 1] & __intVal(bMask)) + 1);
-		    srcIndex = __MKSMALLINT(sI + 3);
-		    fast = true;
-		} else {
-		    fast = false;
-		}
+                if (__isByteArrayLike(bytes)) {
+                    int sI = __intVal(srcIndex);
+                    unsigned char *cp = __ByteArrayInstPtr(bytes)->ba_element;
+
+                    r = __MKSMALLINT((cp[sI - 1] & __intVal(rMask)) + 1);
+                    g = __MKSMALLINT((cp[sI]     & __intVal(gMask)) + 1);
+                    b = __MKSMALLINT((cp[sI + 1] & __intVal(bMask)) + 1);
+                    srcIndex = __MKSMALLINT(sI + 3);
+                    fast = true;
+                } else {
+                    fast = false;
+                }
 %}
 .
-		fast ifFalse:[
-		    r := bytes at:srcIndex.
-		    r := (r bitAnd:rMask) + 1.
-		    srcIndex := srcIndex + 1.
-		    g := bytes at:srcIndex.
-		    g := (g bitAnd:gMask) + 1.
-		    srcIndex := srcIndex + 1.
-		    b := bytes at:srcIndex.
-		    b := (b bitAnd:bMask) + 1.
-		    srcIndex := srcIndex + 1
-		].
-
-		greenArray := redArray at:r.
-		greenArray isNil ifTrue:[
-		    greenArray := Array new:256.
-		    redArray at:r put:greenArray
-		].
-		blueArray := greenArray at:g.
-		blueArray isNil ifTrue:[
-		    deep ifTrue:[blueArray := Array new:256]
-		    ifFalse:[blueArray := ByteArray new:256].
-		    greenArray at:g put:blueArray
-		].
-		(blueArray at:b) == 0 ifTrue:[
-		    blueArray at:b put:1.
-		    nColors := nColors + 1.
-		    (nColors > nColorCells) ifTrue:[
+                fast ifFalse:[
+                    r := bytes at:srcIndex.
+                    r := (r bitAnd:rMask) + 1.
+                    srcIndex := srcIndex + 1.
+                    g := bytes at:srcIndex.
+                    g := (g bitAnd:gMask) + 1.
+                    srcIndex := srcIndex + 1.
+                    b := bytes at:srcIndex.
+                    b := (b bitAnd:bMask) + 1.
+                    srcIndex := srcIndex + 1
+                ].
+
+                greenArray := redArray at:r.
+                greenArray isNil ifTrue:[
+                    greenArray := Array new:256.
+                    redArray at:r put:greenArray
+                ].
+                blueArray := greenArray at:g.
+                blueArray isNil ifTrue:[
+                    deep ifTrue:[blueArray := Array new:256]
+                    ifFalse:[blueArray := ByteArray new:256].
+                    greenArray at:g put:blueArray
+                ].
+                (blueArray at:b) == 0 ifTrue:[
+                    blueArray at:b put:1.
+                    nColors := nColors + 1.
+                    (nColors > nColorCells) ifTrue:[
 "/                        'Depth24Image [info]: more than ' infoPrint. nColorCells infoPrint. ' colors' infoPrintCR.
-			srcIndex := dataSize + 1
-		    ]
-		]
-	    ].
-	    nColorsNeeded isNil ifTrue:[
-		nColorsNeeded := nColors
-	    ].
-
-	    "again with less color bits if it does not fit colormap"
-
-	    (nColors <= nColorCells) ifTrue:[
-		fitMap := true
-	    ] ifFalse:[
-		"/ must try again - cutting off some bits
-		"/ blue bits are snipped off faster.
-		(bMask == 2r11111111) ifTrue:[
-		    bMask := 2r11111100
-		] ifFalse:[
-		    (bMask == 2r11111100) ifTrue:[
-			bMask := 2r11110000
-		    ] ifFalse:[
-			(rMask == 2r11111111) ifTrue:[
-			    rMask := 2r11111100.
-			    gMask := 2r11111100.
-			] ifFalse:[
-			    rMask := (rMask bitShift:1) bitAnd:2r11111111.
-			    gMask := (gMask bitShift:1) bitAnd:2r11111111.
-			    bMask := (bMask bitShift:1) bitAnd:2r11111111
-			]
-		    ]
-		].
+                        srcIndex := dataSize + 1
+                    ]
+                ]
+            ].
+            nColorsNeeded isNil ifTrue:[
+                nColorsNeeded := nColors
+            ].
+
+            "again with less color bits if it does not fit colormap"
+
+            (nColors <= nColorCells) ifTrue:[
+                fitMap := true
+            ] ifFalse:[
+                "/ must try again - cutting off some bits
+                "/ blue bits are snipped off faster.
+                (bMask == 2r11111111) ifTrue:[
+                    bMask := 2r11111100
+                ] ifFalse:[
+                    (bMask == 2r11111100) ifTrue:[
+                        bMask := 2r11110000
+                    ] ifFalse:[
+                        (rMask == 2r11111111) ifTrue:[
+                            rMask := 2r11111100.
+                            gMask := 2r11111100.
+                        ] ifFalse:[
+                            rMask := (rMask bitShift:1) bitAnd:2r11111111.
+                            gMask := (gMask bitShift:1) bitAnd:2r11111111.
+                            bMask := (bMask bitShift:1) bitAnd:2r11111111
+                        ]
+                    ]
+                ].
 "/                'Depth24Image [info]: too many colors; retry with less color resolution' infoPrintCR.
 "
     'masks:' print. rMask print. ' ' print. gMask print. ' ' print.
     bMask printNewline
 "
-	    ]
-	].
+            ]
+        ].
 
 "/        'Depth24Image [info]: ' infoPrint. nColors infoPrint. ' colors used' infoPrintCR.
 
-	colors := Array new:nColors.
-	colorIndex := 1.
-
-	"
-	 now, we have reduced things to the number of colors
-	 which are theoretically supported by the devices colormap.
-	 allocate all used colors in walking over true entries in
-	 the [r][g][b] table - this may still fail,
-	 if we run out of device colors.
-	"
-	fit := true.
-
-	r := 0.
-	redArray do:[:greenArray |
-	    (fit and:[greenArray notNil]) ifTrue:[
-		g := 0.
-		greenArray do:[:blueArray |
-		    (fit and:[blueArray notNil]) ifTrue:[
-			b := 0.
-			blueArray do:[:present |
-			    |id|
-
-			    (fit and:[present ~~ 0]) ifTrue:[
-				color := Color redByte:r
-					     greenByte:g
-					      blueByte:b.
-				color := color onDevice:aDevice.
-				(id := color colorId) isNil ifTrue:[
-				    fit := false
-				] ifFalse:[
-				    colors at:colorIndex put:color.
-				    colorIndex := colorIndex + 1.
-				    blueArray at:(b + 1) put:id
-				]
-			    ].
-			    b := b + 1
-			]
-		    ].
-		    g := g + 1
-		]
-	    ].
-	    r := r + 1
-	].
-
-	"again with less color bits if we did not get all colors"
-
-	fit ifFalse:[
+        colors := Array new:nColors.
+        colorIndex := 1.
+
+        "
+         now, we have reduced things to the number of colors
+         which are theoretically supported by the devices colormap.
+         allocate all used colors in walking over true entries in
+         the [r][g][b] table - this may still fail,
+         if we run out of device colors.
+        "
+        fit := true.
+
+        r := 0.
+        redArray do:[:greenArray |
+            (fit and:[greenArray notNil]) ifTrue:[
+                g := 0.
+                greenArray do:[:blueArray |
+                    (fit and:[blueArray notNil]) ifTrue:[
+                        b := 0.
+                        blueArray do:[:present |
+                            |id|
+
+                            (fit and:[present ~~ 0]) ifTrue:[
+                                color := Color redByte:r
+                                             greenByte:g
+                                              blueByte:b.
+                                color := color onDevice:aDevice.
+                                (id := color colorId) isNil ifTrue:[
+                                    fit := false
+                                ] ifFalse:[
+                                    colors at:colorIndex put:color.
+                                    colorIndex := colorIndex + 1.
+                                    blueArray at:(b + 1) put:id
+                                ]
+                            ].
+                            b := b + 1
+                        ]
+                    ].
+                    g := g + 1
+                ]
+            ].
+            r := r + 1
+        ].
+
+        "again with less color bits if we did not get all colors"
+
+        fit ifFalse:[
 "/            'Depth24Image [info]: could not allocate color(s)' infoPrintCR.
 
-	    "free the allocated colors"
-	    colors atAllPut:nil.
-	    "a kludge - force immediate freeing of colors"
-	    ObjectMemory scavenge; finalize.
-
-	    "cut off one more color-bit - cut off blue first"
-	    (bMask == 2r11111111) ifTrue:[
-		bMask := 2r11111100
-	    ] ifFalse:[
-		(bMask == 2r11111100) ifTrue:[
-		    bMask := 2r11110000
-		] ifFalse:[
-		    (rMask == 2r11111111) ifTrue:[
-			rMask := 2r11111100.
-			gMask := 2r11111100.
-		    ] ifFalse:[
-			rMask := (rMask bitShift:1) bitAnd:2r11111111.
-			gMask := (gMask bitShift:1) bitAnd:2r11111111.
-			bMask := (bMask bitShift:1) bitAnd:2r11111111
-		    ]
-		]
-	    ].
-	    fitMap := false.
-	    redArray := nil
-	]
+            "free the allocated colors"
+            colors atAllPut:nil.
+            "a kludge - force immediate freeing of colors"
+            ObjectMemory scavenge; finalize.
+
+            "cut off one more color-bit - cut off blue first"
+            (bMask == 2r11111111) ifTrue:[
+                bMask := 2r11111100
+            ] ifFalse:[
+                (bMask == 2r11111100) ifTrue:[
+                    bMask := 2r11110000
+                ] ifFalse:[
+                    (rMask == 2r11111111) ifTrue:[
+                        rMask := 2r11111100.
+                        gMask := 2r11111100.
+                    ] ifFalse:[
+                        rMask := (rMask bitShift:1) bitAnd:2r11111111.
+                        gMask := (gMask bitShift:1) bitAnd:2r11111111.
+                        bMask := (bMask bitShift:1) bitAnd:2r11111111
+                    ]
+                ]
+            ].
+            fitMap := false.
+            redArray := nil
+        ]
     ].
 
     (nColors ~~ nColorsNeeded) ifTrue:[
-	"/ mhmh - did not get all colors ...
-	"/ add existing colors and dither.
-
-	'Depth24Image [info]: only got ' infoPrint. nColors infoPrint. ' out of ' infoPrint.
-	nColorsNeeded infoPrint. ' image colors.' infoPrintCR.
-
-	"/
-	"/ dither using those we got ...
-	"/
-	DitherAlgorithm == #floydSteinberg ifTrue:[
-	    colors := colors asNewSet.
+        "/ mhmh - did not get all colors ...
+        "/ add existing colors and dither.
+
+        'Depth24Image [info]: only got ' infoPrint. nColors infoPrint. ' out of ' infoPrint.
+        nColorsNeeded infoPrint. ' image colors.' infoPrintCR.
+
+        "/
+        "/ dither using those we got ...
+        "/
+        DitherAlgorithm == #floydSteinberg ifTrue:[
+            colors := colors asNewSet.
 "/            ditherColors := aDevice availableDitherColors.
 "/            ditherColors notNil ifTrue:[
 "/                colors addAll:ditherColors.
 "/            ].
 "/            colors addAll:aDevice deviceColors.
-	    colors addAll:(aDevice colorMap collect:[:c|c onDevice:aDevice]).
-	    colors := (colors select:[:c | c colorId notNil]) asOrderedCollection.
-	    colors size > 256 ifTrue:[
-		colors := colors copyTo:256
-	    ].
-	    f := self rgbImageAsDitheredPseudoFormOn:aDevice colors:colors.
-	    f notNil ifTrue:[^ f].
-	].
+            colors addAll:(aDevice colorMap collect:[:c|c onDevice:aDevice]).
+            colors := (colors select:[:c | c colorId notNil]) asOrderedCollection.
+            colors size > 256 ifTrue:[
+                colors := colors copyTo:256
+            ].
+            f := self rgbImageAsDitheredPseudoFormOn:aDevice colors:colors.
+            f notNil ifTrue:[^ f].
+        ].
     ].
 
     "/ the device ought to support 8-bit images ...
     (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
-	"/ cannot draw directly
-	^ nil
+        "/ cannot draw directly
+        ^ nil
     ].
 
     "create pseudocolor bits and translate"
@@ -1019,51 +1019,51 @@
     (rMask == 2r11111111
      and:[gMask == 2r11111111
      and:[bMask == 2r11111111]]) ifTrue:[
-	[srcIndex < dataSize] whileTrue:[
-	    r := bytes at:srcIndex.
-	    srcIndex := srcIndex + 1.
-	    g := bytes at:srcIndex.
-	    srcIndex := srcIndex + 1.
-	    b := bytes at:srcIndex.
-	    srcIndex := srcIndex + 1.
-	    greenArray := redArray at:(r + 1).
-	    blueArray := greenArray at:(g + 1).
-	    pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
-	    dstIndex := dstIndex + 1
-	]
+        [srcIndex < dataSize] whileTrue:[
+            r := bytes at:srcIndex.
+            srcIndex := srcIndex + 1.
+            g := bytes at:srcIndex.
+            srcIndex := srcIndex + 1.
+            b := bytes at:srcIndex.
+            srcIndex := srcIndex + 1.
+            greenArray := redArray at:(r + 1).
+            blueArray := greenArray at:(g + 1).
+            pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
+            dstIndex := dstIndex + 1
+        ]
     ] ifFalse:[
-	[srcIndex < dataSize] whileTrue:[
-	    r := bytes at:srcIndex.
-	    r := r bitAnd:rMask.
-	    srcIndex := srcIndex + 1.
-	    g := bytes at:srcIndex.
-	    g := g bitAnd:gMask.
-	    srcIndex := srcIndex + 1.
-	    b := bytes at:srcIndex.
-	    b := b bitAnd:bMask.
-	    srcIndex := srcIndex + 1.
-	    greenArray := redArray at:(r + 1).
-	    blueArray := greenArray at:(g + 1).
-	    pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
-	    dstIndex := dstIndex + 1
-	]
+        [srcIndex < dataSize] whileTrue:[
+            r := bytes at:srcIndex.
+            r := r bitAnd:rMask.
+            srcIndex := srcIndex + 1.
+            g := bytes at:srcIndex.
+            g := g bitAnd:gMask.
+            srcIndex := srcIndex + 1.
+            b := bytes at:srcIndex.
+            b := b bitAnd:bMask.
+            srcIndex := srcIndex + 1.
+            greenArray := redArray at:(r + 1).
+            blueArray := greenArray at:(g + 1).
+            pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
+            dstIndex := dstIndex + 1
+        ]
     ].
 
-    f := Form width:width height:height depth:depth onDevice:aDevice.
+    f := Form imageForm width:width height:height depth:depth onDevice:aDevice.
     f isNil ifTrue:[^ nil].
     f colorMap:colors.
     f initGC.
     aDevice
-	drawBits:pseudoBits
-	bitsPerPixel:8
-	depth:depth
-	padding:8
-	width:width height:height
-	x:0 y:0
-	into:(f id)
-	x:0 y:0
-	width:width height:height
-	with:(f gcId).
+        drawBits:pseudoBits
+        bitsPerPixel:8
+        depth:depth
+        padding:8
+        width:width height:height
+        x:0 y:0
+        into:(f id)
+        x:0 y:0
+        width:width height:height
+        with:(f gcId).
     ^ f
 !
 
@@ -1078,34 +1078,34 @@
     usedDevicePadding := bestFormat at:#padding.
 
     imageBits := self
-		    rgbImageBitsOn:aDevice
-		    bestFormat: bestFormat
-		    returnUsedDevicePattingIn:[:arg | usedDevicePadding := arg].
+                    rgbImageBitsOn:aDevice
+                    bestFormat: bestFormat
+                    returnUsedDevicePattingIn:[:arg | usedDevicePadding := arg].
 
     imageBits isNil ifTrue:[
-	^ self asMonochromeFormOn:aDevice
+        ^ self asMonochromeFormOn:aDevice
     ].
 
-    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
+    form := Form imageForm width:width height:height depth:usedDeviceDepth onDevice:aDevice.
     form isNil ifTrue:[
-	'Depth24Image [warning]: display bitmap creation failed' errorPrintCR.
-	^ nil
+        'Depth24Image [warning]: display bitmap creation failed' errorPrintCR.
+        ^ nil
     ].
     form id isNil ifTrue:[
-	"/ usually happens if the image is too big (out of memory)
-	'Depth24Image [warning]: display bitmap creation failed' errorPrintCR.
-	^ nil
+        "/ usually happens if the image is too big (out of memory)
+        'Depth24Image [warning]: display bitmap creation failed' errorPrintCR.
+        ^ 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