Depth24Image.st
changeset 3866 c01473a90934
parent 3851 34637f468b2a
child 3868 e47cf114c824
--- a/Depth24Image.st	Mon Apr 28 12:15:34 2003 +0200
+++ b/Depth24Image.st	Tue Apr 29 20:45:23 2003 +0200
@@ -81,13 +81,15 @@
     |index "{ Class: SmallInteger }"
      rVal gVal bVal|
 
+    photometric ~~ #rgb ifTrue:[^ super colorAtX:x y:y].
+
     index := 1 + (((width * y) + x) * 3).
     rVal := bytes at:(index).
     gVal := bytes at:(index + 1).
     bVal := bytes at:(index + 2).
 
     photometric ~~ #rgb ifTrue:[
-	^ super colorAtX:x y:y
+        ^ super colorAtX:x y:y
     ].
     ^ Color redByte:rVal greenByte:gVal blueByte:bVal
 
@@ -102,6 +104,8 @@
 
     |index "{ Class: SmallInteger }"|
 
+    photometric ~~ #rgb ifTrue:[^ super colorAtX:x y:y put:aColor].
+
     index := 1 + (((width * y) + x) * 3).
     bytes at:(index) put:(aColor redByte).
     bytes at:(index + 1) put:(aColor greenByte).
@@ -152,15 +156,16 @@
     "replace a single rows bits from bits in the pixelArray argument;
      Notice: row indexing starts at 0."
 
-    |dstIdx pixel|
-
+    |bytes dstIdx pixel|
+
+    bytes := self bits.
     dstIdx := (rowIndex * self bytesPerRow) + 1.
     1 to:width do:[:col |
-	pixel := pixelArray at:col.
-	bytes at:dstIdx put:((pixel bitShift:-16) bitAnd:16rFF).
-	bytes at:dstIdx+1 put:((pixel bitShift:-8) bitAnd:16rFF).
-	bytes at:dstIdx+2 put:(pixel bitAnd:16rFF).
-	dstIdx := dstIdx + 3.
+        pixel := pixelArray at:col.
+        bytes at:dstIdx put:((pixel bitShift:-16) bitAnd:16rFF).
+        bytes at:dstIdx+1 put:((pixel bitShift:-8) bitAnd:16rFF).
+        bytes at:dstIdx+2 put:(pixel bitAnd:16rFF).
+        dstIdx := dstIdx + 3.
     ].
     ^ pixelArray
 
@@ -172,15 +177,16 @@
      Return the pixelArray.
      Notice: row indexing starts at 0."
 
-    |dstIdx pixel|
-
+    |bytes dstIdx pixel|
+
+    bytes := self bits.
     dstIdx := (rowIndex * self bytesPerRow) + 1.
     1 to:width do:[:col |
-	pixel := pixelArray at:(startIndex + col).
-	bytes at:dstIdx put:((pixel bitShift:-16) bitAnd:16rFF).
-	bytes at:dstIdx+1 put:((pixel bitShift:-8) bitAnd:16rFF).
-	bytes at:dstIdx+2 put:(pixel bitAnd:16rFF).
-	dstIdx := dstIdx + 3.
+        pixel := pixelArray at:(startIndex + col).
+        bytes at:dstIdx put:((pixel bitShift:-16) bitAnd:16rFF).
+        bytes at:dstIdx+1 put:((pixel bitShift:-8) bitAnd:16rFF).
+        bytes at:dstIdx+2 put:(pixel bitAnd:16rFF).
+        dstIdx := dstIdx + 3.
     ].
     ^ pixelArray
 
@@ -771,7 +777,7 @@
      fit fitMap colors color ditherColors
      fast
      colorIndex "{ Class: SmallInteger }"
-     depth nColorCells deep nColorsNeeded|
+     depth nColorCells deep nColorsNeeded bytes|
 
     aDevice fixColors notNil ifTrue:[
         "/ no need to look for used colors - dithering anyway ...
@@ -780,6 +786,8 @@
         f notNil ifTrue:[^ f].
     ].
 
+    bytes := self bits.
+
     "find used colors; build color-tree"
 
     fit := false.                       
@@ -810,9 +818,9 @@
             [(srcIndex < dataSize)
              and:[nColors <= nColorCells]] whileTrue:[
 %{
-                if (__isByteArray(_INST(bytes))) {
+                if (__isByteArray(bytes)) {
                     int sI = __intVal(srcIndex);
-                    unsigned char *cp = __ByteArrayInstPtr(_INST(bytes))->ba_element;
+                    unsigned char *cp = __ByteArrayInstPtr(bytes)->ba_element;
 
                     r = __MKSMALLINT((cp[sI - 1] & __intVal(rMask)) + 1);
                     g = __MKSMALLINT((cp[sI]     & __intVal(gMask)) + 1);
@@ -1064,10 +1072,12 @@
 rgbImageAsTrueColorFormOn:aDevice
     "return a truecolor form from the rgb-picture."
 
-    |bestFormat usedDeviceDepth usedDeviceBitsPerPixel usedDevicePadding 
+    |bytes bestFormat usedDeviceDepth usedDeviceBitsPerPixel usedDevicePadding 
      myDepth form imageBits padd
      rightShiftR rightShiftG rightShiftB shiftRed shiftGreen shiftBlue|
 
+    bytes := self bits.
+
     bestFormat := self bestSupportedImageFormatFor:aDevice.
     usedDeviceDepth := bestFormat at:#depth.
     usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
@@ -1102,13 +1112,12 @@
 %{
             unsigned char *srcPtr = 0;
             unsigned char *dstPtr = 0;
-            OBJ _bytes = __INST(bytes);
-
-            if (__isByteArray(_bytes)) {
-                srcPtr = _ByteArrayInstPtr(_bytes)->ba_element;
+
+            if (__isByteArray(bytes)) {
+                srcPtr = _ByteArrayInstPtr(bytes)->ba_element;
             } else {
-                if (__isExternalBytesLike(_bytes)) {
-                    srcPtr = __externalBytesAddress(_bytes);
+                if (__isExternalBytesLike(bytes)) {
+                    srcPtr = __externalBytesAddress(bytes);
                 }
             }
             if (__isByteArray(imageBits)) {
@@ -1196,13 +1205,12 @@
 %{
             unsigned char *srcPtr = 0;
             unsigned char *dstPtr = 0;
-            OBJ _bytes = __INST(bytes);
-
-            if (__isByteArray(_bytes)) {
-                srcPtr = _ByteArrayInstPtr(_bytes)->ba_element;
+
+            if (__isByteArray(bytes)) {
+                srcPtr = _ByteArrayInstPtr(bytes)->ba_element;
             } else {
-                if (__isExternalBytesLike(_bytes)) {
-                    srcPtr = __externalBytesAddress(_bytes);
+                if (__isExternalBytesLike(bytes)) {
+                    srcPtr = __externalBytesAddress(bytes);
                 }
             }
             if (__isByteArray(imageBits)) {
@@ -1345,13 +1353,12 @@
 %{       
                 unsigned char *srcPtr = 0;
                 unsigned char *dstPtr = 0;
-                OBJ _bytes = __INST(bytes);
-
-                if (__isByteArray(_bytes)) {
-                    srcPtr = _ByteArrayInstPtr(_bytes)->ba_element;
+
+                if (__isByteArray(bytes)) {
+                    srcPtr = _ByteArrayInstPtr(bytes)->ba_element;
                 } else {
-                    if (__isExternalBytesLike(_bytes)) {
-                        srcPtr = __externalBytesAddress(_bytes);
+                    if (__isExternalBytesLike(bytes)) {
+                        srcPtr = __externalBytesAddress(bytes);
                     }
                 }
                 if (__isByteArray(imageBits)) {
@@ -1436,13 +1443,12 @@
 %{              
                     unsigned char *srcPtr = 0;
                     unsigned char *dstPtr = 0;
-                    OBJ _bytes = __INST(bytes);
-
-                    if (__isByteArray(_bytes)) {
-                        srcPtr = _ByteArrayInstPtr(_bytes)->ba_element;
+
+                    if (__isByteArray(bytes)) {
+                        srcPtr = _ByteArrayInstPtr(bytes)->ba_element;
                     } else {
-                        if (__isExternalBytesLike(_bytes)) {
-                            srcPtr = __externalBytesAddress(_bytes);
+                        if (__isExternalBytesLike(bytes)) {
+                            srcPtr = __externalBytesAddress(bytes);
                         }
                     }
                     if (__isByteArray(imageBits)) {
@@ -1553,41 +1559,40 @@
      bitCnt          "{Class: SmallInteger }"
      byte            "{Class: SmallInteger }" 
      grey dT 
-     eR eRB eB eLB |
+     eR eRB eB eLB bytes|
 
     (samplesPerPixel ~~ 3
     or:[bitsPerSample ~= #(8 8 8)
     or:[depth > 8]]) ifTrue:[
-	^ super floydSteinbergDitheredGrayBitsDepth:depth
+        ^ super floydSteinbergDitheredGrayBitsDepth:depth
     ].
 
+    bytes := self bits.
+    bytes isNil ifTrue:[ self error. ^ nil].
     w := width.
     h := height.
 
     bytesPerRow := self bytesPerRow.
     bytesPerOutRow := ((w * depth) + 7) // 8.
     outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
-    (outBits isNil or:[bytes isNil]) ifTrue:[
-	^ nil
-    ].
 
     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.
     ].
 
 %{
@@ -1610,7 +1615,7 @@
     int __greyLevels = __intVal(greyLevels);
 
     unsigned char *__outBits = __ByteArrayInstPtr(outBits)->ba_element;
-    unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
+    unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element;
     unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element;
     unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element;
     short *__errorArray = (short *)(__ByteArrayInstPtr(errorArray)->ba_element);
@@ -1618,90 +1623,90 @@
     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 */
+        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;
-	}
+                    __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;
+        }
     }
 %}.
 
@@ -1709,7 +1714,6 @@
 
     "Created: 10.6.1996 / 13:28:22 / cg"
     "Modified: 10.6.1996 / 15:09:07 / cg"
-
 !
 
 floydSteinbergDitheredMonochromeBits
@@ -1727,7 +1731,7 @@
      with a constant ditherMatrix, this can be used for thresholding.
      Redefined to make use of knowing that pixels are 24-bit values."
 
-    |f dH nDither v range  
+    |dH nDither v range bytes 
      greyMap1 greyMap2 greyLevels outBits
      bytesPerOutRow  "{Class: SmallInteger }"
      bytesPerRow     "{Class: SmallInteger }"
@@ -1735,13 +1739,14 @@
      h               "{Class: SmallInteger }"|
 
     photometric ~~ #rgb ifTrue:[
-	self error:'invalid format'.
-	^ nil
+        self error:'invalid format'.
+        ^ nil
     ].
 
     nDither := ditherMatrix size.
     dH := nDither / dW.
 
+    bytes := self bits.
     w := width.
     h := height.
 
@@ -1750,33 +1755,31 @@
 
     bytesPerOutRow := (w * depth + 7) // 8.
     outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
-    (outBits isNil or:[bytes isNil]) ifTrue:[
-	^ nil
-    ].
+    (outBits isNil or:[bytes isNil]) ifTrue:[ self error. ^ nil].
 
     greyMap1 := Array new:256.
     greyMap2 := Array new:256.
     range := greyLevels-1.
     1 to:256 do:[:i |
-	v := (range / 255 * (i-1)).
-	greyMap1 at:i put:v.
-	greyMap2 at:i put:v.
+        v := (range / 255 * (i-1)).
+        greyMap1 at:i put:v.
+        greyMap2 at:i put:v.
     ].
 
     greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[
-					    0
-					] ifFalse:[
-					    b truncated
-					]
-				  ]) asByteArray.      
+                                            0
+                                        ] ifFalse:[
+                                            b truncated
+                                        ]
+                                  ]) asByteArray.      
 
     greyMap2 := (greyMap2 collect:[:el | 
-					el isNil ifTrue:[
-					    0
-					] ifFalse:[
-					    ((el - el truncated)  "/ the error (0..1)
-					    * nDither) rounded
-					]]) asByteArray.
+                                        el isNil ifTrue:[
+                                            0
+                                        ] ifFalse:[
+                                            ((el - el truncated)  "/ the error (0..1)
+                                            * nDither) rounded
+                                        ]]) asByteArray.
 %{
     int __dW = __intVal(dW);
     int __dH = __intVal(dH);
@@ -1801,62 +1804,62 @@
 
     unsigned char *__outBits = __ByteArrayInstPtr(outBits)->ba_element;
     unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element;
-    unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
+    unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element;
     unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element;
     unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element;
 
     __oY = __dY = 0;
     for (__y=0; __y<__h; __y++) {
-	__nextDst = __dstIdx + __bytesPerOutRow;
-	__nextSrc = __srcIdx + __bytesPerRow;
-
-	__byte = 0;
-	__bitCnt = 8;
-
-	__oX = 0;
-
-	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) */
-	    __dO    = __greyMap2[__grey];            /* 0.. nDither-1) */
-	    __dT = __ditherMatrix[__dY + __oX];
-
-	    if (__dO > __dT)                         /* dither says: next pixel */
-		__pixel++;
-
-	    __srcIdx += 3;
-
-	    __oX++;
-	    if (__oX == __dW) __oX = 0;
-
-	    __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;
-	}
-
-	__oY++; __dY += __dW;
-	if (__oY == __dH) {
-	    __oY = 0;
-	    __dY = 0;
-	}
-
-	__srcIdx = __nextSrc;
-	__dstIdx = __nextDst;
+        __nextDst = __dstIdx + __bytesPerOutRow;
+        __nextSrc = __srcIdx + __bytesPerRow;
+
+        __byte = 0;
+        __bitCnt = 8;
+
+        __oX = 0;
+
+        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) */
+            __dO    = __greyMap2[__grey];            /* 0.. nDither-1) */
+            __dT = __ditherMatrix[__dY + __oX];
+
+            if (__dO > __dT)                         /* dither says: next pixel */
+                __pixel++;
+
+            __srcIdx += 3;
+
+            __oX++;
+            if (__oX == __dW) __oX = 0;
+
+            __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;
+        }
+
+        __oY++; __dY += __dW;
+        if (__oY == __dH) {
+            __oY = 0;
+            __dY = 0;
+        }
+
+        __srcIdx = __nextSrc;
+        __dstIdx = __nextDst;
     }
 %}.
 
@@ -1881,21 +1884,22 @@
      with a constant ditherMatrix, this can be used for thresholding.
      Redefined to make use of knowing that pixels are 24-bit values."
 
-    |f dH nDither   
-     greyMap monoBits
+    |dH nDither bytes 
+     monoBits
      bytesPerMonoRow "{Class: SmallInteger }"
      bytesPerRow     "{Class: SmallInteger }"
      w               "{Class: SmallInteger }"
      h               "{Class: SmallInteger }"|
 
     photometric ~~ #rgb ifTrue:[
-	self error:'invalid format'.
-	^ nil
+        self error:'invalid format'.
+        ^ nil
     ].
 
     nDither := ditherMatrix size.
     dH := nDither / dW.
 
+    bytes := self bits.
     w := width.
     h := height.
 
@@ -1903,9 +1907,7 @@
 
     bytesPerMonoRow := w + 7 // 8.
     monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
-    (monoBits isNil or:[bytes isNil]) ifTrue:[
-	^ nil
-    ].
+    (monoBits isNil or:[bytes isNil]) ifTrue:[ self error. ^ nil].
 
 %{
     int __dW = __intVal(dW);
@@ -1929,57 +1931,57 @@
 
     unsigned char *__monoBits = __ByteArrayInstPtr(monoBits)->ba_element;
     unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element;
-    unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
+    unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element;
 
     __oY = __dY = 0;
     for (__y=0; __y<__h; __y++) {
-	__nextDst = __dstIdx + __bytesPerMonoRow;
-	__nextSrc = __srcIdx + __bytesPerRow;
-
-	__byte = 0;
-	__bitCnt = 8;
-
-	__oX = 0;
-
-	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 * (__nDither+1) / 2550;    /* 0 .. nDither+1 */
-	    __srcIdx += 3;
-
-	    __dT = __ditherMatrix[__dY + __oX];
-
-	    __oX++;
-	    if (__oX == __dW) __oX = 0;
-
-	    __byte = __byte << 1;
-	    if (__grey > __dT) {
-		__byte = __byte | 1;                   /* white */
-	    }
-
-	    __bitCnt--;
-	    if (__bitCnt == 0) {
-		__monoBits[__dstIdx] = __byte;
-		__dstIdx++;
-		__byte = 0;
-		__bitCnt = 8;
-	    }
-	}
-
-	if (__bitCnt != 8) {
-	    __byte = __byte << __bitCnt;
-	    __monoBits[__dstIdx] = __byte;
-	}
-
-	__oY++; __dY += __dW;
-	if (__oY == __dH) {
-	    __oY = 0;
-	    __dY = 0;
-	}
-
-	__srcIdx = __nextSrc;
-	__dstIdx = __nextDst;
+        __nextDst = __dstIdx + __bytesPerMonoRow;
+        __nextSrc = __srcIdx + __bytesPerRow;
+
+        __byte = 0;
+        __bitCnt = 8;
+
+        __oX = 0;
+
+        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 * (__nDither+1) / 2550;    /* 0 .. nDither+1 */
+            __srcIdx += 3;
+
+            __dT = __ditherMatrix[__dY + __oX];
+
+            __oX++;
+            if (__oX == __dW) __oX = 0;
+
+            __byte = __byte << 1;
+            if (__grey > __dT) {
+                __byte = __byte | 1;                   /* white */
+            }
+
+            __bitCnt--;
+            if (__bitCnt == 0) {
+                __monoBits[__dstIdx] = __byte;
+                __dstIdx++;
+                __byte = 0;
+                __bitCnt = 8;
+            }
+        }
+
+        if (__bitCnt != 8) {
+            __byte = __byte << __bitCnt;
+            __monoBits[__dstIdx] = __byte;
+        }
+
+        __oY++; __dY += __dW;
+        if (__oY == __dH) {
+            __oY = 0;
+            __dY = 0;
+        }
+
+        __srcIdx = __nextSrc;
+        __dstIdx = __nextDst;
     }
 %}.
 
@@ -2047,30 +2049,32 @@
      rVal     "{ Class: SmallInteger }"
      gVal     "{ Class: SmallInteger }"
      bVal     "{ Class: SmallInteger }"
-     lastR lastG lastB lastColor|
+     lastR lastG lastB lastColor bytes|
 
     photometric ~~ #rgb ifTrue:[
-	^ super colorsAtY:y from:xLow to:xHigh do:aBlock.
+        ^ super colorsAtY:y from:xLow to:xHigh do:aBlock.
     ].
 
+    bytes := self bits.
+
     x1 := xLow.
     x2 := xHigh.
 
     srcIndex := 1 + (((width * y) + x1) * 3).
 
     x1 to:x2 do:[:x |
-	rVal := bytes at:(srcIndex).
-	gVal := bytes at:(srcIndex + 1).
-	bVal := bytes at:(srcIndex + 2).
-	srcIndex := srcIndex + 3.
-
-	(rVal == lastR and:[gVal == lastG and:[bVal == lastB]]) ifFalse:[
-	    lastColor := Color redByte:rVal greenByte:gVal blueByte:bVal.
-	    lastR := rVal.
-	    lastG := gVal.
-	    lastB := bVal.
-	].
-	aBlock value:x value:lastColor
+        rVal := bytes at:(srcIndex).
+        gVal := bytes at:(srcIndex + 1).
+        bVal := bytes at:(srcIndex + 2).
+        srcIndex := srcIndex + 3.
+
+        (rVal == lastR and:[gVal == lastG and:[bVal == lastB]]) ifFalse:[
+            lastColor := Color redByte:rVal greenByte:gVal blueByte:bVal.
+            lastR := rVal.
+            lastG := gVal.
+            lastB := bVal.
+        ].
+        aBlock value:x value:lastColor
     ]
 
     "Created: / 7.6.1996 / 19:12:28 / cg"
@@ -2092,19 +2096,21 @@
      x2       "{ Class: SmallInteger }"
      r        "{ Class: SmallInteger }"
      g        "{ Class: SmallInteger }"
-     b        "{ Class: SmallInteger }"|
-
+     b        "{ Class: SmallInteger }"
+     bytes|
+
+    bytes := self bits.
     x1 := xLow.
     x2 := xHigh.
 
     srcIndex := 1 + (((width * y) + x1) * 3).
 
     x1 to:x2 do:[:x |
-	r := bytes at:(srcIndex).
-	g := bytes at:(srcIndex + 1).
-	b := bytes at:(srcIndex + 2).
-	srcIndex := srcIndex + 3.
-	aBlock value:x value:(((r bitShift:16) bitOr:(g bitShift:8)) bitOr:b)
+        r := bytes at:(srcIndex).
+        g := bytes at:(srcIndex + 1).
+        b := bytes at:(srcIndex + 2).
+        srcIndex := srcIndex + 3.
+        aBlock value:x value:(((r bitShift:16) bitOr:(g bitShift:8)) bitOr:b)
     ]
 
     "Created: 7.6.1996 / 19:09:40 / cg"
@@ -2113,25 +2119,27 @@
 !Depth24Image methodsFor:'image manipulations'!
 
 negative
-    |index newImage newBytes nBytes r g b|
+    |bytes index newImage newBytes nBytes r g b|
 
     photometric ~~ #rgb ifTrue:[
-	^ super negative.
+        ^ super negative.
     ].
+    bytes := self bits.
+
     newImage := self copy.
     nBytes := bytes size.
     newImage bits:(newBytes := ByteArray new:nBytes).
     index := 1.
     [index < nBytes] whileTrue:[
-	r := bytes at:index.
-	newBytes at:index put:(255-r).
-	index := index + 1.
-	g := bytes at:index.
-	newBytes at:index put:(255-g).
-	index := index + 1.
-	b := bytes at:index.
-	newBytes at:index put:(255-b).
-	index := index + 1.
+        r := bytes at:index.
+        newBytes at:index put:(255-r).
+        index := index + 1.
+        g := bytes at:index.
+        newBytes at:index put:(255-g).
+        index := index + 1.
+        b := bytes at:index.
+        newBytes at:index put:(255-b).
+        index := index + 1.
     ].
     ^ newImage
 
@@ -2569,5 +2577,5 @@
 !Depth24Image class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.77 2003-04-11 00:09:00 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.78 2003-04-29 18:45:23 cg Exp $'
 ! !