Depth4Image.st
changeset 3866 c01473a90934
parent 3851 34637f468b2a
child 3868 e47cf114c824
--- a/Depth4Image.st	Mon Apr 28 12:15:34 2003 +0200
+++ b/Depth4Image.st	Tue Apr 29 20:45:23 2003 +0200
@@ -64,39 +64,6 @@
 
 !Depth4Image methodsFor:'accessing-pixels'!
 
-colorAtX:x y:y
-    "retrieve a pixel at x/y; return a color.
-     Pixels start at x=0 , y=0 for upper left pixel, end at
-     x = width-1, y=height-1 for lower right pixel"
-
-    |lineIndex "{ Class: SmallInteger }"
-     byte      "{ Class: SmallInteger }"
-     value     "{ Class: SmallInteger }" |
-
-    lineIndex := (self bytesPerRow * y) + 1.
-
-    "left pixel in high bits"
-    byte := bytes at:(lineIndex + (x // 2)).
-    x even ifTrue:[
-        value := (byte bitShift:-4) bitAnd:16rF.
-    ] ifFalse:[
-        value := byte bitAnd:16rF.
-    ].
-    photometric == #whiteIs0 ifTrue:[
-        ^ Color gray:100 - (100 / 15 * value)
-    ].
-    photometric == #blackIs0 ifTrue:[
-        ^ Color gray:(100 / 15 * value)
-    ].
-    photometric ~~ #palette ifTrue:[
-        ^ self colorFromValue:value
-    ].
-    ^ colorMap at:(value + 1)
-
-    "Modified: 8.6.1996 / 10:52:43 / cg"
-    "Created: 24.4.1997 / 17:33:51 / cg"
-!
-
 pixelAtX:x y:y
     "retrieve a pixel at x/y; return a pixelValue.
      Pixels start at x=0 , y=0 for upper left pixel, end at
@@ -148,8 +115,9 @@
     |lineIndex "{ Class: SmallInteger }"
      byte      "{ Class: SmallInteger }" 
      w         "{ Class: SmallInteger }" 
-     pixel dstIdx|
+     pixel dstIdx bytes|
 
+    bytes := self bits.
     dstIdx := 1.
     w := width - 1.
     lineIndex := (self bytesPerRow * rowIndex).
@@ -558,7 +526,7 @@
      with a constant ditherMatrix, this can be used for thresholding.
      Redefined to make use of knowing that pixels are 4-bit values."
 
-    |dH nDither   
+    |dH nDither bytes  
      greyLevels greyMap1 greyMap2
      bytesPerRow  "{Class: SmallInteger }"
      bytesPerOutRow  "{Class: SmallInteger }"
@@ -570,6 +538,7 @@
     nDither := ditherMatrix size.
     dH := nDither / dW.
 
+    bytes := self bits.
     w := width.
     h := height.
 
@@ -624,7 +593,7 @@
 
     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;
 
@@ -685,7 +654,6 @@
     }
 %}.
     ^ outBits
-
 !
 
 orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW
@@ -693,7 +661,7 @@
      with a constant ditherMatrix, this can be used for thresholding.
      Redefined to make use of knowing that pixels are 4-bit values."
 
-    |f dH nDither   
+    |dH nDither bytes  
      greyMap monoBits
      bytesPerMonoRow "{Class: SmallInteger }"
      bytesPerRow     "{Class: SmallInteger }"
@@ -705,6 +673,7 @@
 
     w := width.
     h := height.
+    bytes := self bits.
 
     bytesPerRow := self bytesPerRow.
 
@@ -738,7 +707,7 @@
 
     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;
     unsigned char *__greyMap = __ByteArrayInstPtr(greyMap)->ba_element;
 
     __oY = __dY = 0;
@@ -816,8 +785,9 @@
      value    "{ Class: SmallInteger }"
      x1       "{ Class: SmallInteger }"
      x2       "{ Class: SmallInteger }"
-     colorArray|
+     colorArray bytes|
 
+    bytes := self bits.
     colorArray := ((0 to:15) collect:[:i | self colorFromValue:i]) asArray.
 
     x1 := xLow.
@@ -863,7 +833,9 @@
      pixelValue "{ Class: SmallInteger }"
      x1         "{ Class: SmallInteger }"
      x2         "{ Class: SmallInteger }"
-     |
+     bytes|
+
+    bytes := self bits.
 
     x1 := xLow.
     x2 := xHigh.
@@ -1009,6 +981,22 @@
     ^ nbytes
 !
 
+colorFromValue:pixelValue
+    "given a pixel value, return the corresponding color.
+     Pixel values start with 0."
+
+    photometric == #whiteIs0 ifTrue:[
+        ^ Color gray:100 - (100 / 15 * pixelValue)
+    ].
+    photometric == #blackIs0 ifTrue:[
+        ^ Color gray:(100 / 15 * pixelValue)
+    ].
+    photometric == #palette ifTrue:[
+        ^ colorMap at:(pixelValue + 1)
+    ].
+    ^ self colorFromValue:pixelValue
+!
+
 usedValues
     "return a collection of color values used in the receiver."
 
@@ -1022,7 +1010,7 @@
             ]
         ].
     ] ifTrue:[
-        bytes usedValues do:[:byte |
+        self bits usedValues do:[:byte |
             useFlags at:(byte bitShift:-4)+1 put:true.
             useFlags at:(byte bitAnd:2r1111)+1 put:true.
         ].
@@ -1039,5 +1027,5 @@
 !Depth4Image class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Depth4Image.st,v 1.42 2003-04-11 00:09:05 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Depth4Image.st,v 1.43 2003-04-29 18:44:54 cg Exp $'
 ! !