pixel accessing methods cleaned up
authorClaus Gittinger <cg@exept.de>
Thu, 24 Apr 1997 17:53:42 +0200
changeset 1655 eec658000092
parent 1654 93c6430368d7
child 1656 ebcad6911ddb
pixel accessing methods cleaned up
Depth1Image.st
--- a/Depth1Image.st	Thu Apr 24 16:04:44 1997 +0200
+++ b/Depth1Image.st	Thu Apr 24 17:53:42 1997 +0200
@@ -63,9 +63,9 @@
     "Modified: 20.4.1996 / 23:40:06 / cg"
 ! !
 
-!Depth1Image methodsFor:'accessing'!
+!Depth1Image methodsFor:'accessing - pixels'!
 
-atX:x y:y
+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"
@@ -100,9 +100,10 @@
     ^ colorMap at:value
 
     "Modified: 8.6.1996 / 10:52:15 / cg"
+    "Created: 24.4.1997 / 17:33:17 / cg"
 !
 
-atX:x y:y put:aColor
+colorAtX:x y:y put:aColor
     "set the pixel at x/y to aColor.
      Pixels start at x=0 , y=0 for upper left pixel, end at
      x = width-1, y=height-1 for lower right pixel.
@@ -129,73 +130,24 @@
         ]
     ].
     aColor = clr0 ifTrue:[
-        self atX:x y:y putValue:0.
+        self pixelAtX:x y:y put:0.
         ^ self
     ].
     aColor = clr1 ifTrue:[
-        self atX:x y:y putValue:1.
+        self pixelAtX:x y:y put:1.
         ^ self
     ].
+
     "
      the color to be stored is not in the images colormap
     "
     self error:'invalid color - not in colorMap'
 
-    "Modified: 7.6.1996 / 19:17:08 / cg"
+    "Modified: 24.4.1997 / 17:16:38 / cg"
+    "Created: 24.4.1997 / 17:33:23 / cg"
 !
 
-atX:x y:y putValue:aPixelValue
-    "set a pixels value at x/y to aPixelValue.
-     Pixels start at x=0 , y=0 for upper left pixel, end at
-     x = width-1, y=height-1 for lower right pixel"
-
-    |bytesPerRow "{Class: SmallInteger}"
-     index       "{Class: SmallInteger}"
-     byte        "{Class: SmallInteger}"
-     mask        "{Class: SmallInteger}"|
-
-%{  /* NOCONTEXT */
-
-    OBJ b = _INST(bytes);
-    OBJ w = _INST(width);
-
-    if (__isByteArray(b) && __bothSmallInteger(x, y) && __isSmallInteger(w) ) {
-        int _w = _intVal(w);
-        int _y = _intVal(y);
-        int _x = _intVal(x);
-        int _idx;
-
-        _idx = ((_w + 7) >> 3) * _y + (_x >> 3);
-        if ((unsigned)_idx < __byteArraySize(b)) {
-            if (aPixelValue == __MKSMALLINT(0)) {
-                _ByteArrayInstPtr(b)->ba_element[_idx] &= ~(0x80 >> (_x & 7));
-            } else {
-                _ByteArrayInstPtr(b)->ba_element[_idx] |= (0x80 >> (_x & 7));
-            }
-            RETURN( self );
-        }
-    }
-%}.
-    "fall back code for nonByteArray or nonInteger arguments"
-
-    bytesPerRow := width // 8.
-    ((width \\ 8) ~~ 0) ifTrue:[
-        bytesPerRow := bytesPerRow + 1
-    ].
-    index := (bytesPerRow * y) + 1 + (x // 8).
-
-    "left pixel is in high bit"
-    byte := bytes at:index.
-    mask := #(16r80 16r40 16r20 16r10 16r08 16r04 16r02 16r01) at:((x \\ 8) + 1).
-    aPixelValue == 0 ifTrue:[
-        byte := byte bitAnd:(mask bitInvert)
-    ] ifFalse:[
-        byte := byte bitOr:mask
-    ].
-    bytes at:index put:byte
-!
-
-valueAtX:x y:y
+pixelAtX:x y:y
     "retrieve a pixelValue at x/y; return a number.
      The interpretation of the returned value depends on the photometric
      and the colormap. See also Image>>atX:y:)
@@ -246,12 +198,63 @@
 "/ since that cannot happen, we faile here
     self primitiveFailed.
     ^ 0
+!
+
+pixelAtX:x y:y put:aPixelValue
+    "set a pixels value at x/y to aPixelValue.
+     Pixels start at x=0 , y=0 for upper left pixel, end at
+     x = width-1, y=height-1 for lower right pixel"
+
+    |bytesPerRow "{Class: SmallInteger}"
+     index       "{Class: SmallInteger}"
+     byte        "{Class: SmallInteger}"
+     mask        "{Class: SmallInteger}"|
+
+%{  /* NOCONTEXT */
+
+    OBJ b = _INST(bytes);
+    OBJ w = _INST(width);
+
+    if (__isByteArray(b) && __bothSmallInteger(x, y) && __isSmallInteger(w) ) {
+        int _w = _intVal(w);
+        int _y = _intVal(y);
+        int _x = _intVal(x);
+        int _idx;
+
+        _idx = ((_w + 7) >> 3) * _y + (_x >> 3);
+        if ((unsigned)_idx < __byteArraySize(b)) {
+            if (aPixelValue == __MKSMALLINT(0)) {
+                _ByteArrayInstPtr(b)->ba_element[_idx] &= ~(0x80 >> (_x & 7));
+            } else {
+                _ByteArrayInstPtr(b)->ba_element[_idx] |= (0x80 >> (_x & 7));
+            }
+            RETURN( self );
+        }
+    }
+%}.
+    "fall back code for nonByteArray or nonInteger arguments"
+
+    bytesPerRow := width // 8.
+    ((width \\ 8) ~~ 0) ifTrue:[
+        bytesPerRow := bytesPerRow + 1
+    ].
+    index := (bytesPerRow * y) + 1 + (x // 8).
+
+    "left pixel is in high bit"
+    byte := bytes at:index.
+    mask := #(16r80 16r40 16r20 16r10 16r08 16r04 16r02 16r01) at:((x \\ 8) + 1).
+    aPixelValue == 0 ifTrue:[
+        byte := byte bitAnd:(mask bitInvert)
+    ] ifFalse:[
+        byte := byte bitOr:mask
+    ].
+    bytes at:index put:byte
 ! !
 
 !Depth1Image methodsFor:'converting greyscale images'!
 
 asFormOn:aDevice
-    "convert a greyscale image to a device form"
+    "convert a monochrome image to a device form"
 
     |f|
 
@@ -261,17 +264,11 @@
     f notNil ifTrue:[
         f colorMap:(Array with:(self colorFromValue:0)
                           with:(self colorFromValue:1)).
-
-"/        photometric == #blackIs0 ifTrue:[
-"/            f function:#xor.
-"/            f paint:(Color colorId:1).
-"/            f fillRectangleX:0 y:0 width:width height:height
-"/        ]
     ].
     ^ f
 
     "Created: 14.6.1996 / 15:20:00 / cg"
-    "Modified: 15.6.1996 / 14:44:21 / cg"
+    "Modified: 24.4.1997 / 17:50:43 / cg"
 !
 
 greyImageAsFormOn:aDevice
@@ -293,7 +290,7 @@
 !Depth1Image methodsFor:'converting palette images'!
 
 paletteImageAsMonoFormOn:aDevice
-    "convert a palette image to a monochrome device form"
+    "convert a palette image to a b&w monochrome device form"
 
     |f c0 c1|
 
@@ -313,8 +310,7 @@
     f colorMap:(Array with:c0 with:c1).
     ^ f
 
-    "Created: 20.2.1996 / 16:26:15 / cg"
-    "Modified: 10.6.1996 / 14:26:50 / cg"
+    "Modified: 24.4.1997 / 17:51:54 / cg"
 !
 
 paletteImageAsPseudoFormOn:aDevice
@@ -740,5 +736,5 @@
 !Depth1Image class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.30 1997-04-22 19:13:08 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.31 1997-04-24 15:53:42 cg Exp $'
 ! !