#REFACTORING by stefan
authorStefan Vogel <sv@exept.de>
Tue, 31 Jan 2017 13:47:05 +0100
changeset 7817 b6348d4d7f7f
parent 7816 f818c6ba6334
child 7818 290d8c548544
#REFACTORING by stefan class: Depth24Image changed: #bitsPerSample #floydSteinbergDitheredDepth8BitsColors:map: #floydSteinbergDitheredGrayBitsDepth: #hardMagnifiedBy: #initialize SmallLint refactoring
Depth24Image.st
--- a/Depth24Image.st	Tue Jan 31 13:46:45 2017 +0100
+++ b/Depth24Image.st	Tue Jan 31 13:47:05 2017 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1993 by Claus Gittinger
 	      All Rights Reserved
@@ -1609,61 +1611,61 @@
 
     "/ collect valid ditherColors ...
     aMapOrNil isNil ifTrue:[
-	ditherColors := colors select:[:clr | clr notNil].
+        ditherColors := colors select:[:clr | clr notNil].
     ] ifFalse:[
-	ditherColors := colors
+        ditherColors := colors
     ].
 
     "/ ... and sort by manhatten distance from black
 
     qScramble := #(
-		"/  2rX00X00X00X00
-
-		    2r000000000000    "/ 0
-		    2r000000000100    "/ 1
-		    2r000000100000    "/ 2
-		    2r000000100100    "/ 3
-		    2r000100000000    "/ 4
-		    2r000100000100    "/ 5
-		    2r000100100000    "/ 6
-		    2r000100100100    "/ 7
-		    2r100000000000    "/ 8
-		    2r100000000100    "/ 9
-		    2r100000100000    "/ a
-		    2r100000100100    "/ b
-		    2r100100000000    "/ c
-		    2r100100000100    "/ d
-		    2r100100100000    "/ e
-		    2r100100100100    "/ f
-		  ).
+                "/  2rX00X00X00X00
+
+                    2r000000000000    "/ 0
+                    2r000000000100    "/ 1
+                    2r000000100000    "/ 2
+                    2r000000100100    "/ 3
+                    2r000100000000    "/ 4
+                    2r000100000100    "/ 5
+                    2r000100100000    "/ 6
+                    2r000100100100    "/ 7
+                    2r100000000000    "/ 8
+                    2r100000000100    "/ 9
+                    2r100000100000    "/ a
+                    2r100000100100    "/ b
+                    2r100100000000    "/ c
+                    2r100100000100    "/ d
+                    2r100100100000    "/ e
+                    2r100100100100    "/ f
+                  ).
 
     ditherColors := ditherColors sort:[:a :b |
-				|cr "{Class: SmallInteger }"
-				 cg "{Class: SmallInteger }"
-				 cb "{Class: SmallInteger }"
-				 i1 "{Class: SmallInteger }"
-				 i2 "{Class: SmallInteger }"|
-
-				cr := a redByte.
-				cg := a greenByte.
-				cb := a blueByte.
-				i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
-				i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
-				i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
-
-				cr := b redByte.
-				cg := b greenByte.
-				cb := b blueByte.
-				i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
-				i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
-				i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
-
-				i1 < i2
-		    ].
+                                |cr "{Class: SmallInteger }"
+                                 cg "{Class: SmallInteger }"
+                                 cb "{Class: SmallInteger }"
+                                 i1 "{Class: SmallInteger }"
+                                 i2 "{Class: SmallInteger }"|
+
+                                cr := a redByte.
+                                cg := a greenByte.
+                                cb := a blueByte.
+                                i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
+                                i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
+                                i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
+
+                                cr := b redByte.
+                                cg := b greenByte.
+                                cb := b blueByte.
+                                i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
+                                i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
+                                i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
+
+                                i1 < i2
+                    ].
     aMapOrNil isNil ifTrue:[
-	ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray.
+        ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray.
     ] ifFalse:[
-	ditherIds := aMapOrNil asByteArray
+        ditherIds := aMapOrNil asByteArray
     ].
 
     "/ build an index table, for fast lookup from manhatten-r-g-b distance
@@ -1672,20 +1674,20 @@
     clrLookup := ByteArray new:(4096).
     index := 0.
     ditherColors keysAndValuesDo:[:clrPosition :clr |
-	|r g b i|
-
-	r := clr redByte.
-	g := clr greenByte.
-	b := clr blueByte.
-	i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1.
-	i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
-	i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
-	lookupPos := i.
-
-	[index < lookupPos] whileTrue:[
-	    clrLookup at:(index+1) put:(clrPosition-1-1).
-	    index := index + 1
-	]
+        |r g b i|
+
+        r := clr redByte.
+        g := clr greenByte.
+        b := clr blueByte.
+        i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1.
+        i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
+        i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
+        lookupPos := i.
+
+        index+1 to:lookupPos do:[:idx|
+            clrLookup at:idx put:(clrPosition-1-1).
+        ].
+        index := lookupPos.
     ].
     clrLookup from:index+1 to:4096 put:(ditherColors size - 1).
 
@@ -1701,16 +1703,16 @@
     ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
     index := 1.
     1 to:lastColor do:[:pix |
-	clr := ditherColors at:pix.
-	ditherRGBBytes at:index put:(clr redByte).
-	ditherRGBBytes at:index+1 put:(clr greenByte).
-	ditherRGBBytes at:index+2 put:(clr blueByte).
-	aMapOrNil isNil ifTrue:[
-	    ditherIds at:pix put:clr colorId.
-	] ifFalse:[
-	    ditherIds at:pix put:(aMapOrNil at:pix).
-	].
-	index := index + 3.
+        clr := ditherColors at:pix.
+        ditherRGBBytes at:index put:(clr redByte).
+        ditherRGBBytes at:index+1 put:(clr greenByte).
+        ditherRGBBytes at:index+2 put:(clr blueByte).
+        aMapOrNil isNil ifTrue:[
+            ditherIds at:pix put:clr colorId.
+        ] ifFalse:[
+            ditherIds at:pix put:(aMapOrNil at:pix).
+        ].
+        index := index + 3.
     ].
     pseudoBits := ByteArray uninitializedNew:(width * height).
 
@@ -1732,23 +1734,23 @@
     int __nColors = __intVal(lastColor);
     int __wR = -1, __wG, __wB;
     static int __qScramble[16] = {
-		    0x000 /* 2r000000000000    0 */,
-		    0x004 /* 2r000000000100    1 */,
-		    0x020 /* 2r000000100000    2 */,
-		    0x024 /* 2r000000100100    3 */,
-		    0x100 /* 2r000100000000    4 */,
-		    0x104 /* 2r000100000100    5 */,
-		    0x120 /* 2r000100100000    6 */,
-		    0x124 /* 2r000100100100    7 */,
-		    0x800 /* 2r100000000000    8 */,
-		    0x804 /* 2r100000000100    9 */,
-		    0x820 /* 2r100000100000    a */,
-		    0x824 /* 2r100000100100    b */,
-		    0x900 /* 2r100100000000    c */,
-		    0x904 /* 2r100100000100    d */,
-		    0x920 /* 2r100100100000    e */,
-		    0x924 /* 2r100100100100    f */,
-		  };
+                    0x000 /* 2r000000000000    0 */,
+                    0x004 /* 2r000000000100    1 */,
+                    0x020 /* 2r000000100000    2 */,
+                    0x024 /* 2r000000100100    3 */,
+                    0x100 /* 2r000100000000    4 */,
+                    0x104 /* 2r000100000100    5 */,
+                    0x120 /* 2r000100100000    6 */,
+                    0x124 /* 2r000100100100    7 */,
+                    0x800 /* 2r100000000000    8 */,
+                    0x804 /* 2r100000000100    9 */,
+                    0x820 /* 2r100000100000    a */,
+                    0x824 /* 2r100000100100    b */,
+                    0x900 /* 2r100100000000    c */,
+                    0x904 /* 2r100100000100    d */,
+                    0x920 /* 2r100100100000    e */,
+                    0x924 /* 2r100100100100    f */,
+                  };
 
     if (__isByteArrayLike(__INST(bytes))
      && __isByteArray(pseudoBits)
@@ -1756,54 +1758,54 @@
      && __isByteArray(ditherIds)
      && __isByteArray(clrLookup)
      && __isByteArray(error)) {
-	failed = false;
-
-	srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
-	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
-	idP = __ByteArrayInstPtr(ditherIds)->ba_element;
-	__clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element;
-	errP = (short *) __ByteArrayInstPtr(error)->ba_element;
-
-	/*
-	 * clear error accumulator
-	 */
-	eP = errP;
-	bzero(eP, (__w+2) * 2 * 3);
-
-	for (__y=__h; __y>0; __y--) {
-	    unsigned char *dp;
-	    int __eR, __eG, __eB;
-
-	    __eR = __eG = __eB = 0;
-
-	    eP = &(errP[3]);
-	    __eR = eP[0];
-	    __eG = eP[1];
-	    __eB = eP[2];
-
-	    for (__x=__w; __x>0; __x--) {
-		int __want;
-		int pix;
-		int __wantR, __wantG, __wantB;
-		int idx;
-		int tR, tG, tB;
-		int nR, nG, nB;
-		int dR, dG, dB;
-		int minDelta, bestIdx;
-		int cnt;
-
-		__wantR = srcP[0];
-		__wantG = srcP[1];
-		__wantB = srcP[2];
-		srcP += 3;
-
-		/*
-		 * wI are the wanted r/g/b values;
-		 * eI are the error values;
-		 */
-		__wantR = __wantR + __eR;
-		__wantG = __wantG + __eG;
-		__wantB = __wantB + __eB;
+        failed = false;
+
+        srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
+        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
+        idP = __ByteArrayInstPtr(ditherIds)->ba_element;
+        __clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element;
+        errP = (short *) __ByteArrayInstPtr(error)->ba_element;
+
+        /*
+         * clear error accumulator
+         */
+        eP = errP;
+        bzero(eP, (__w+2) * 2 * 3);
+
+        for (__y=__h; __y>0; __y--) {
+            unsigned char *dp;
+            int __eR, __eG, __eB;
+
+            __eR = __eG = __eB = 0;
+
+            eP = &(errP[3]);
+            __eR = eP[0];
+            __eG = eP[1];
+            __eB = eP[2];
+
+            for (__x=__w; __x>0; __x--) {
+                int __want;
+                int pix;
+                int __wantR, __wantG, __wantB;
+                int idx;
+                int tR, tG, tB;
+                int nR, nG, nB;
+                int dR, dG, dB;
+                int minDelta, bestIdx;
+                int cnt;
+
+                __wantR = srcP[0];
+                __wantG = srcP[1];
+                __wantB = srcP[2];
+                srcP += 3;
+
+                /*
+                 * wI are the wanted r/g/b values;
+                 * eI are the error values;
+                 */
+                __wantR = __wantR + __eR;
+                __wantG = __wantG + __eG;
+                __wantB = __wantB + __eB;
 
 #define RED_SCALE 30
 #define GREEN_SCALE 59
@@ -1815,237 +1817,237 @@
 #define NPROBE 16
 
 #ifndef FAST_LOOKUP
-		if ((__wantR == __wR)
-		 && (__wantG == __wG)
-		 && (__wantB == __wB)) {
-		    /*
-		     * same color again - reuse last bestMatch
-		     */
-		} else
+                if ((__wantR == __wR)
+                 && (__wantG == __wG)
+                 && (__wantB == __wB)) {
+                    /*
+                     * same color again - reuse last bestMatch
+                     */
+                } else
 #endif
-		{
-		    __wR = __wantR;
-		    __wG = __wantG;
-		    __wB = __wantB;
+                {
+                    __wR = __wantR;
+                    __wG = __wantG;
+                    __wB = __wantB;
 
 #ifdef FAST_LOOKUP
-		    if(__wR > 255) __wR = 255;
-		    else if (__wR < 0) __wR = 0;
-		    if(__wG > 255) __wG = 255;
-		    else if (__wG < 0) __wG = 0;
-		    if(__wB > 255) __wB = 255;
-		    else if (__wB < 0) __wB = 0;
-
-		    {
-			int lookupIndex;
-			int idx, idx0;
-			int d, delta;
-			unsigned char *dp0;
-
-			dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
-			lookupIndex =    __qScramble[((__wR & 0xF0)>>4)];
-			lookupIndex |=   __qScramble[((__wG & 0xF0)>>4)] >> 1;
-			lookupIndex |=   __qScramble[((__wB & 0xF0)>>4)] >> 2;
-			idx = bestIdx =__clrLookup[lookupIndex];
-			dp += (idx+idx+idx);
-
-			/* try color at lookupIndex */
-
-			d = dp[0];
-			delta = (__wR - d) * RED_SCALE;
-			if (delta < 0) delta = -delta;
-
-			d = dp[1];
-			if (__wG > d)
-			    delta += (__wG - d) * GREEN_SCALE;
-			else
-			    delta += (d - __wG) * GREEN_SCALE;
-			d = dp[2];
-			if (__wB > d)
-			    delta += (__wB - d) * BLUE_SCALE;
-			else
-			    delta += (d - __wB) * BLUE_SCALE;
-
-			if (delta <= GOOD_DELTA) {
-			    goto foundBest;
-			}
-			minDelta = delta;
+                    if(__wR > 255) __wR = 255;
+                    else if (__wR < 0) __wR = 0;
+                    if(__wG > 255) __wG = 255;
+                    else if (__wG < 0) __wG = 0;
+                    if(__wB > 255) __wB = 255;
+                    else if (__wB < 0) __wB = 0;
+
+                    {
+                        int lookupIndex;
+                        int idx, idx0;
+                        int d, delta;
+                        unsigned char *dp0;
+
+                        dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
+                        lookupIndex =    __qScramble[((__wR & 0xF0)>>4)];
+                        lookupIndex |=   __qScramble[((__wG & 0xF0)>>4)] >> 1;
+                        lookupIndex |=   __qScramble[((__wB & 0xF0)>>4)] >> 2;
+                        idx = bestIdx =__clrLookup[lookupIndex];
+                        dp += (idx+idx+idx);
+
+                        /* try color at lookupIndex */
+
+                        d = dp[0];
+                        delta = (__wR - d) * RED_SCALE;
+                        if (delta < 0) delta = -delta;
+
+                        d = dp[1];
+                        if (__wG > d)
+                            delta += (__wG - d) * GREEN_SCALE;
+                        else
+                            delta += (d - __wG) * GREEN_SCALE;
+                        d = dp[2];
+                        if (__wB > d)
+                            delta += (__wB - d) * BLUE_SCALE;
+                        else
+                            delta += (d - __wB) * BLUE_SCALE;
+
+                        if (delta <= GOOD_DELTA) {
+                            goto foundBest;
+                        }
+                        minDelta = delta;
 # ifndef ONE_SHOT
-			idx0 = idx; dp0 = dp;
-			cnt = 0;
-			while ((++cnt <= NPROBE) && (idx > 0)) {
-			    /* try previous color(s) */
-
-			    idx--; dp -= 3;
-			    d = dp[0];
-			    delta = (__wR - d) * RED_SCALE;
-			    if (delta < 0) delta = -delta;
-			    d = dp[1];
-			    if (__wG > d)
-				delta += (__wG - d) * GREEN_SCALE;
-			    else
-				delta += (d - __wG) * GREEN_SCALE;
-			    d = dp[2];
-			    if (__wB > d)
-				delta += (__wB - d) * BLUE_SCALE;
-			    else
-				delta += (d - __wB) * BLUE_SCALE;
-
-			    if (delta < minDelta) {
-				bestIdx = idx;
-				if (delta <= GOOD_DELTA) {
-				    goto foundBest;
-				}
-				minDelta = delta;
-			    }
-			}
-
-			idx = idx0; dp = dp0;
-			cnt = 0;
-			while ((++cnt <= NPROBE) && (++idx < __nColors)) {
-			    /* try next color */
-
-			    dp += 3;
-			    d = dp[0];
-			    delta = (__wR - d) * RED_SCALE;
-			    if (delta < 0) delta = -delta;
-			    d = dp[1];
-			    if (__wG > d)
-				delta += (__wG - d) * GREEN_SCALE;
-			    else
-				delta += (d - __wG) * GREEN_SCALE;
-			    d = dp[2];
-			    if (__wB > d)
-				delta += (__wB - d) * BLUE_SCALE;
-			    else
-				delta += (d - __wB) * BLUE_SCALE;
-
-			    if (delta < minDelta) {
-				bestIdx = idx;
-				if (delta <= GOOD_DELTA) {
-				    goto foundBest;
-				}
-				minDelta = delta;
-			    }
-			}
+                        idx0 = idx; dp0 = dp;
+                        cnt = 0;
+                        while ((++cnt <= NPROBE) && (idx > 0)) {
+                            /* try previous color(s) */
+
+                            idx--; dp -= 3;
+                            d = dp[0];
+                            delta = (__wR - d) * RED_SCALE;
+                            if (delta < 0) delta = -delta;
+                            d = dp[1];
+                            if (__wG > d)
+                                delta += (__wG - d) * GREEN_SCALE;
+                            else
+                                delta += (d - __wG) * GREEN_SCALE;
+                            d = dp[2];
+                            if (__wB > d)
+                                delta += (__wB - d) * BLUE_SCALE;
+                            else
+                                delta += (d - __wB) * BLUE_SCALE;
+
+                            if (delta < minDelta) {
+                                bestIdx = idx;
+                                if (delta <= GOOD_DELTA) {
+                                    goto foundBest;
+                                }
+                                minDelta = delta;
+                            }
+                        }
+
+                        idx = idx0; dp = dp0;
+                        cnt = 0;
+                        while ((++cnt <= NPROBE) && (++idx < __nColors)) {
+                            /* try next color */
+
+                            dp += 3;
+                            d = dp[0];
+                            delta = (__wR - d) * RED_SCALE;
+                            if (delta < 0) delta = -delta;
+                            d = dp[1];
+                            if (__wG > d)
+                                delta += (__wG - d) * GREEN_SCALE;
+                            else
+                                delta += (d - __wG) * GREEN_SCALE;
+                            d = dp[2];
+                            if (__wB > d)
+                                delta += (__wB - d) * BLUE_SCALE;
+                            else
+                                delta += (d - __wB) * BLUE_SCALE;
+
+                            if (delta < minDelta) {
+                                bestIdx = idx;
+                                if (delta <= GOOD_DELTA) {
+                                    goto foundBest;
+                                }
+                                minDelta = delta;
+                            }
+                        }
 # endif
-		    }
-	foundBest: ;
+                    }
+        foundBest: ;
 #else
 /*
-		    if(__wR > 255) __wR = 255;
-		    else if (__wR < 0) __wR = 0;
-		    if(__wG > 255) __wG = 255;
-		    else if (__wG < 0) __wG = 0;
-		    if(__wB > 255) __wB = 255;
-		    else if (__wB < 0) __wB = 0;
+                    if(__wR > 255) __wR = 255;
+                    else if (__wR < 0) __wR = 0;
+                    if(__wG > 255) __wG = 255;
+                    else if (__wG < 0) __wG = 0;
+                    if(__wB > 255) __wB = 255;
+                    else if (__wB < 0) __wB = 0;
 */
 
-		    /* find the best matching color */
-
-		    minDelta = 99999;
-		    bestIdx = -1;
-		    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
-		    for (idx = 0; idx<__nColors; idx++) {
-			int d, delta;
-
-			d = dp[0];
-			delta = (__wR - d) * RED_SCALE;
-			if (delta < 0) delta = -delta;
-			if (delta < minDelta) {
-			    d = dp[1];
-			    if (__wG > d)
-				delta += (__wG - d) * GREEN_SCALE;
-			    else
-				delta += (d - __wG) * GREEN_SCALE;
-			    if (delta < minDelta) {
-				d = dp[2];
-				if (__wB > d)
-				    delta += (__wB - d) * BLUE_SCALE;
-				else
-				    delta += (d - __wB) * BLUE_SCALE;
-
-				if (delta < minDelta) {
-				    bestIdx = idx;
-				    if (delta <= GOOD_DELTA) {
-					break;
-				    }
-				    minDelta = delta;
-				}
-			    }
-			}
-			dp += 3;
-		    }
+                    /* find the best matching color */
+
+                    minDelta = 99999;
+                    bestIdx = -1;
+                    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
+                    for (idx = 0; idx<__nColors; idx++) {
+                        int d, delta;
+
+                        d = dp[0];
+                        delta = (__wR - d) * RED_SCALE;
+                        if (delta < 0) delta = -delta;
+                        if (delta < minDelta) {
+                            d = dp[1];
+                            if (__wG > d)
+                                delta += (__wG - d) * GREEN_SCALE;
+                            else
+                                delta += (d - __wG) * GREEN_SCALE;
+                            if (delta < minDelta) {
+                                d = dp[2];
+                                if (__wB > d)
+                                    delta += (__wB - d) * BLUE_SCALE;
+                                else
+                                    delta += (d - __wB) * BLUE_SCALE;
+
+                                if (delta < minDelta) {
+                                    bestIdx = idx;
+                                    if (delta <= GOOD_DELTA) {
+                                        break;
+                                    }
+                                    minDelta = delta;
+                                }
+                            }
+                        }
+                        dp += 3;
+                    }
 #endif
-		}
-
-		dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
-		dp += bestIdx * 3;
-		dR = dp[0];
-		dG = dp[1];
-		dB = dp[2];
+                }
+
+                dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
+                dp += bestIdx * 3;
+                dR = dp[0];
+                dG = dp[1];
+                dB = dp[2];
 
 /*
 console_fprintf(stderr, "want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
-		__wantR, __wantG, __wantB,
-		__wR, __wG, __wB,
-		dR, dG, dB);
+                __wantR, __wantG, __wantB,
+                __wR, __wG, __wB,
+                dR, dG, dB);
 */
-		/*
-		 * store the corresponding dither colors colorId
-		 */
-		*dstP++ = idP[bestIdx];
-
-		/*
-		 * the new error & distribute the error
-		 */
-		__eR = __wantR - dR;
-		if (__eR) {
-		    tR = __eR >> 4;  /* 16th of error */
-		    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
-		    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
-		    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
-		    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
-		    __eR = nR;
-		} else {
-		    __eR = eP[3];
-		    eP[0] = eP[-3] = eP[3] = 0;
-		}
-
-		__eG = __wantG - dG;
-		if (__eG) {
-		    tG = __eG >> 4;
-		    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
-		    eP[1] = tG*5;
-		    eP[-2] = tG*3;
-		    eP[4] = __eG - (tG*15);
-		    __eG = nG;
-		} else {
-		    __eG = eP[4];
-		    eP[1] = eP[-2] = eP[4] = 0;
-		}
-
-		__eB = __wantB - dB;
-		if (__eB) {
-		    tB = __eB >> 4;
-		    nB = eP[5] + (tB * 7);
-		    eP[2] = tB*5;
-		    eP[-1] = tB*3;
-		    eP[5] = __eB - (tB*15);
-		    __eB = nB;
-		} else {
-		    __eB = eP[5];
-		    eP[2] = eP[-1] = eP[5] = 0;
-		}
-
-		eP += 3;
-	    }
-	}
+                /*
+                 * store the corresponding dither colors colorId
+                 */
+                *dstP++ = idP[bestIdx];
+
+                /*
+                 * the new error & distribute the error
+                 */
+                __eR = __wantR - dR;
+                if (__eR) {
+                    tR = __eR >> 4;  /* 16th of error */
+                    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
+                    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
+                    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
+                    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
+                    __eR = nR;
+                } else {
+                    __eR = eP[3];
+                    eP[0] = eP[-3] = eP[3] = 0;
+                }
+
+                __eG = __wantG - dG;
+                if (__eG) {
+                    tG = __eG >> 4;
+                    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
+                    eP[1] = tG*5;
+                    eP[-2] = tG*3;
+                    eP[4] = __eG - (tG*15);
+                    __eG = nG;
+                } else {
+                    __eG = eP[4];
+                    eP[1] = eP[-2] = eP[4] = 0;
+                }
+
+                __eB = __wantB - dB;
+                if (__eB) {
+                    tB = __eB >> 4;
+                    nB = eP[5] + (tB * 7);
+                    eP[2] = tB*5;
+                    eP[-1] = tB*3;
+                    eP[5] = __eB - (tB*15);
+                    __eB = nB;
+                } else {
+                    __eB = eP[5];
+                    eP[2] = eP[-1] = eP[5] = 0;
+                }
+
+                eP += 3;
+            }
+        }
     }
 %}.
     failed ifTrue:[
-	self primitiveFailed.
-	^ nil
+        self primitiveFailed.
+        ^ nil
     ].
 
     ^ pseudoBits
@@ -2071,9 +2073,9 @@
      eR eRB eB eLB bytes|
 
     (samplesPerPixel ~~ 3
-    or:[bitsPerSample ~= #(8 8 8)
-    or:[depth > 8]]) ifTrue:[
-	^ super floydSteinbergDitheredGrayBitsDepth:depth
+     or:[(#[8 8 8] isSameSequenceAs:bitsPerSample) not
+     or:[depth > 8]]) ifTrue:[
+        ^ super floydSteinbergDitheredGrayBitsDepth:depth
     ].
 
     bytes := self bits.
@@ -2086,22 +2088,22 @@
     outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
 
     depth ~~ 8 ifTrue:[
-	greyLevels := (1 bitShift:depth) - 1.
-	greyMap1 := Array new:256.
-	greyMap2 := Array new:256.
-	1 to:256 do:[:i |
-	    v := (greyLevels / 255 * (i-1)).
-	    greyMap1 at:i put:v.
-	    greyMap2 at:i put:v.
-	].
-	greyMap1 := (greyMap1 collect:[:b | b truncated]) asByteArray.
-
-	greyMap2 := (greyMap2 collect:[:el |
-					    ((el - el truncated)  "/ the error (0..1)
-						* 255) rounded]) asByteArray.
-
-	errorArray := ByteArray new:(w + 2) * 2.
-	errorArray1 := ByteArray new:(w + 2) * 2.
+        greyLevels := (1 bitShift:depth) - 1.
+        greyMap1 := Array new:256.
+        greyMap2 := Array new:256.
+        1 to:256 do:[:i |
+            v := (greyLevels / 255 * (i-1)).
+            greyMap1 at:i put:v.
+            greyMap2 at:i put:v.
+        ].
+        greyMap1 := (greyMap1 collect:[:b | b truncated]) asByteArray.
+
+        greyMap2 := (greyMap2 collect:[:el |
+                                            ((el - el truncated)  "/ the error (0..1)
+                                                * 255) rounded]) asByteArray.
+
+        errorArray := ByteArray new:(w + 2) * 2.
+        errorArray1 := ByteArray new:(w + 2) * 2.
     ].
 
 %{
@@ -2132,97 +2134,98 @@
     short *__t;
 
     if (__depth == 8) {
-	/*
-	 * special code for destination depth 8
-	 */
-	for (__y=0; __y<__h; __y++) {
-	    __nextDst = __dstIdx + __bytesPerOutRow;
-	    __nextSrc = __srcIdx + __bytesPerRow;
-	    for (__x=0; __x<__w; __x++) {
-		__grey = (__bytes[__srcIdx] * 3)           /* 0.3*r + 0.6*g + b -> 0..2550 */
-			 + (__bytes[__srcIdx+1] * 6)
-			 + __bytes[__srcIdx+2];
-		__pixel = __grey / 10;                      /* 0 .. 255 */
-
-		__srcIdx += 3;
-		__outBits[__dstIdx] = __pixel;
-	       __dstIdx++;
-	    }
-	    __srcIdx = __nextSrc;
-	    __dstIdx = __nextDst;
-	}
+        /*
+         * special code for destination depth 8
+         */
+        for (__y=0; __y<__h; __y++) {
+            __nextDst = __dstIdx + __bytesPerOutRow;
+            __nextSrc = __srcIdx + __bytesPerRow;
+            for (__x=0; __x<__w; __x++) {
+                __grey = (__bytes[__srcIdx] * 3)           /* 0.3*r + 0.6*g + b -> 0..2550 */
+                         + (__bytes[__srcIdx+1] * 6)
+                         + __bytes[__srcIdx+2];
+                __pixel = __grey / 10;                      /* 0 .. 255 */
+
+                __srcIdx += 3;
+                __outBits[__dstIdx] = __pixel;
+               __dstIdx++;
+            }
+            __srcIdx = __nextSrc;
+            __dstIdx = __nextDst;
+        }
     } else {
-	bzero(errorArray1, (__w+2) * 2);
-
-	__bitCnt = 8;
-	for (__y=0; __y<__h; __y++) {
-	    __nextDst = __dstIdx + __bytesPerOutRow;
-	    __nextSrc = __srcIdx + __bytesPerRow;
-
-	    __byte = 0;
-
-	    __t = __errorArray;
-	    __errorArray = __errorArray1;
-	    __errorArray1 = __t;
-	    bzero(errorArray1, (__w+2) * 2);
-
-	    for (__x=0; __x<__w; __x++) {
-		__grey = (__bytes[__srcIdx] * 3)           /* 0.3*r + 0.6*g + b -> 0..2550 */
-			 + (__bytes[__srcIdx+1] * 6)
-			 + __bytes[__srcIdx+2];
-		__grey = __grey / 10;                      /* 0 .. 255 */
-
-		__pixel = __greyMap1[__grey];            /* 0..(greyLevels-1) */
-		__err = __greyMap2[__grey];              /* 0.. 255 - error) */
-		__err += __errorArray[__x+1];
-
-		if (__err > 127) {                        /* dither says: next pixel */
-		   if ( __pixel != __greyLevels)
-			__pixel++;
-		    __err = __err - 255;
-		} else {
-		}
-		if (__err) {
-		    __e16 = __err >> 4;
-		    __eR = __e16 * 7;                    /* 7/16 -> right pixel */
-		    __eRB = __e16 * 1;                   /* 1/16 -> right below */
-		    __eB = __e16 * 5;                    /* 5/16 -> below */
-		    __eLB = __err - __eR - __eRB - __eB; /* 3/16 -> left below */
-
-		    __errorArray [__x+1+1] += __eR;
-		    __errorArray1[__x+1+1] += __eRB;
-		    __errorArray1[__x+1  ] += __eB;
-		    __errorArray1[__x+1-1] += __eLB;
-		}
-
-		__srcIdx += 3;
-
-		__byte = (__byte << __depth) | __pixel;
-
-		__bitCnt = __bitCnt - __depth;
-		if (__bitCnt == 0) {
-		    __outBits[__dstIdx] = __byte;
-		    __dstIdx++;
-		    __byte = 0;
-		    __bitCnt = 8;
-		}
-	    }
-
-	    if (__bitCnt != 8) {
-		__byte = __byte << __bitCnt;
-		__outBits[__dstIdx] = __byte;
-		__bitCnt = 8;
-	    }
-	    __srcIdx = __nextSrc;
-	    __dstIdx = __nextDst;
-	}
+        bzero(errorArray1, (__w+2) * 2);
+
+        __bitCnt = 8;
+        for (__y=0; __y<__h; __y++) {
+            __nextDst = __dstIdx + __bytesPerOutRow;
+            __nextSrc = __srcIdx + __bytesPerRow;
+
+            __byte = 0;
+
+            __t = __errorArray;
+            __errorArray = __errorArray1;
+            __errorArray1 = __t;
+            bzero(errorArray1, (__w+2) * 2);
+
+            for (__x=0; __x<__w; __x++) {
+                __grey = (__bytes[__srcIdx] * 3)           /* 0.3*r + 0.6*g + b -> 0..2550 */
+                         + (__bytes[__srcIdx+1] * 6)
+                         + __bytes[__srcIdx+2];
+                __grey = __grey / 10;                      /* 0 .. 255 */
+
+                __pixel = __greyMap1[__grey];            /* 0..(greyLevels-1) */
+                __err = __greyMap2[__grey];              /* 0.. 255 - error) */
+                __err += __errorArray[__x+1];
+
+                if (__err > 127) {                        /* dither says: next pixel */
+                   if ( __pixel != __greyLevels)
+                        __pixel++;
+                    __err = __err - 255;
+                } else {
+                }
+                if (__err) {
+                    __e16 = __err >> 4;
+                    __eR = __e16 * 7;                    /* 7/16 -> right pixel */
+                    __eRB = __e16 * 1;                   /* 1/16 -> right below */
+                    __eB = __e16 * 5;                    /* 5/16 -> below */
+                    __eLB = __err - __eR - __eRB - __eB; /* 3/16 -> left below */
+
+                    __errorArray [__x+1+1] += __eR;
+                    __errorArray1[__x+1+1] += __eRB;
+                    __errorArray1[__x+1  ] += __eB;
+                    __errorArray1[__x+1-1] += __eLB;
+                }
+
+                __srcIdx += 3;
+
+                __byte = (__byte << __depth) | __pixel;
+
+                __bitCnt = __bitCnt - __depth;
+                if (__bitCnt == 0) {
+                    __outBits[__dstIdx] = __byte;
+                    __dstIdx++;
+                    __byte = 0;
+                    __bitCnt = 8;
+                }
+            }
+
+            if (__bitCnt != 8) {
+                __byte = __byte << __bitCnt;
+                __outBits[__dstIdx] = __byte;
+                __bitCnt = 8;
+            }
+            __srcIdx = __nextSrc;
+            __dstIdx = __nextDst;
+        }
     }
 %}.
 
     ^ outBits
 
-    "Created: 10.6.1996 / 13:28:22 / cg"
-    "Modified: 10.6.1996 / 15:09:07 / cg"
+    "Created: / 10-06-1996 / 13:28:22 / cg"
+    "Modified: / 10-06-1996 / 15:09:07 / cg"
+    "Modified: / 31-01-2017 / 12:39:31 / stefan"
 !
 
 floydSteinbergDitheredMonochromeBits
@@ -2956,9 +2959,10 @@
 initialize
     super initialize.
     samplesPerPixel := 3.
-    bitsPerSample := #(8 8 8).
+    bitsPerSample := #[8 8 8].
 
     "Created: / 27-05-2007 / 14:09:34 / cg"
+    "Modified: / 30-01-2017 / 18:29:01 / stefan"
 ! !
 
 !Depth24Image methodsFor:'magnification'!
@@ -3154,19 +3158,19 @@
     newBytes := ByteArray uninitializedNew:(newWidth * 3 * newHeight).
 
     mask notNil ifTrue:[
-	newMask := (mask magnifiedBy:scalePoint)
+        newMask := (mask magnifiedBy:scalePoint)
     ].
 
     newImage := self species new.
     newImage
-	width:newWidth
-	height:newHeight
-	photometric:photometric
-	samplesPerPixel:samplesPerPixel
-	bitsPerSample:#(8 8 8)
-	colorMap:nil
-	bits:newBytes
-	mask:newMask.
+        width:newWidth
+        height:newHeight
+        photometric:photometric
+        samplesPerPixel:samplesPerPixel
+        bitsPerSample:#[8 8 8]
+        colorMap:nil
+        bits:newBytes
+        mask:newMask.
 
     "walk over destination image fetching pixels from source image"
 
@@ -3184,14 +3188,14 @@
     double _mY = __floatVal(mY);
 
     for (_row = 0; _row <= _h; _row++) {
-	_srcRowP = _srcP + (_width3 * (int)((double)_row / _mY));
-	for (_col = 0; _col <= _w; _col++) {
-	    sP = _srcRowP + (((int)((double)_col / _mX)) * 3);
-	    _dstP[0] = sP[0];
-	    _dstP[1] = sP[1];
-	    _dstP[2] = sP[2];
-	    _dstP += 3;
-	}
+        _srcRowP = _srcP + (_width3 * (int)((double)_row / _mY));
+        for (_col = 0; _col <= _w; _col++) {
+            sP = _srcRowP + (((int)((double)_col / _mX)) * 3);
+            _dstP[0] = sP[0];
+            _dstP[1] = sP[1];
+            _dstP[2] = sP[2];
+            _dstP += 3;
+        }
     }
 %}
 .
@@ -3201,17 +3205,17 @@
     w := newWidth - 1.
     h := newHeight - 1.
     0 to:h do:[:row |
-	srcRowIdx := (width * 3 * (row // mY)) + 1.
-	0 to:w do:[:col |
-	    srcIndex := srcRowIdx + ((col // mX) * 3).
-	    value := bytes at:srcIndex.
-	    newBytes at:dstIndex put:value.
-	    value := bytes at:(srcIndex + 1).
-	    newBytes at:(dstIndex + 1) put:value.
-	    value := bytes at:(srcIndex + 2).
-	    newBytes at:(dstIndex + 2) put:value.
-	    dstIndex := dstIndex + 3
-	]
+        srcRowIdx := (width * 3 * (row // mY)) + 1.
+        0 to:w do:[:col |
+            srcIndex := srcRowIdx + ((col // mX) * 3).
+            value := bytes at:srcIndex.
+            newBytes at:dstIndex put:value.
+            value := bytes at:(srcIndex + 1).
+            newBytes at:(dstIndex + 1) put:value.
+            value := bytes at:(srcIndex + 2).
+            newBytes at:(dstIndex + 2) put:value.
+            dstIndex := dstIndex + 3
+        ]
     ].
 "
     ^ newImage
@@ -3277,9 +3281,10 @@
      The return value is an array of bits-per-plane."
 
     bitsPerSample notNil ifTrue:[^ bitsPerSample].
-    ^ #(8 8 8)
-
-    "Modified: 10.6.1996 / 18:02:33 / cg"
+    ^ #[8 8 8]
+
+    "Modified: / 10-06-1996 / 18:02:33 / cg"
+    "Modified: / 30-01-2017 / 18:27:45 / stefan"
 !
 
 blueBitsOf:pixel