--- a/Depth1Image.st Thu Dec 07 11:39:18 1995 +0100
+++ b/Depth1Image.st Thu Dec 07 11:42:19 1995 +0100
@@ -33,10 +33,6 @@
"
!
-version
- ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.14 1995-11-11 15:49:05 cg Exp $'
-!
-
documentation
"
this class represents bilevel (1 bit / pixel) images.
@@ -53,118 +49,8 @@
^ 1
! !
-!Depth1Image methodsFor:'queries'!
-
-bitsPerPixel
- "return the number of bits per pixel"
-
- ^ 1
-!
-
-bitsPerRow
- "return the number of bits in one scanline of the image"
-
- ^ width
-!
-
-bitsPerSample
- "return the number of bits per sample.
- The return value is an array of bits-per-plane."
-
- ^ #(1)
-!
-
-bytesPerRow
- "return the number of bytes in one scanline of the image"
-
- |nbytes|
-
- nbytes := width // 8.
- ((width \\ 8) ~~ 0) ifTrue:[
- ^ nbytes + 1
- ].
- ^ nbytes
-!
-
-samplesPerPixel
- "return the number of samples per pixel in the image."
-
- ^ 1
-!
-
-usedColors
- "return a collection of colors used in the receiver.
- For depth1 images, this is very easy"
-
- photometric ~~ #palette ifTrue:[
- ^ Array with:Color white with:Color black.
- ].
- ^ colorMap
-
- "
- (Image fromFile:'bitmaps/garfield.gif') usedColors
- (Image fromFile:'bitmaps/SBrowser.xbm') usedColors
- "
-!
-
-usedValues
- "return a collection of color values used in the receiver.
- For depth1 images, this is very easy"
-
- ^ #(0 1)
-! !
-
!Depth1Image methodsFor:'accessing'!
-valueAtX: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:)
- Pixels start at 0@0 for upper left pixel, end at
- (width-1)@(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);
- unsigned _byte;
-
- _byte = _ByteArrayInstPtr(b)->ba_element[(_w + 7) / 8 * _y + (_x / 8)];
- RETURN( (_byte & (0x80 >> (_x % 8))) ? _MKSMALLINT(1) : _MKSMALLINT(0) );
- }
-%}.
-
-"/ the above is equivalent to:
-"/ (notice that the code below is evaluated if the bytes-collection is
-"/ not a byteArray, or the arguments are not integers)
-
-"/ 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).
-"/ (byte bitAnd:mask) == 0 ifTrue:[^ 0].
-"/ ^ 1
-
-"/ since that cannot happen, we faile here
- self primitiveFailed.
- ^ 0
-!
-
atX: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
@@ -200,6 +86,46 @@
^ colorMap at:value
!
+atX: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.
+ This method checks, if it is possible to store the color
+ in the image; i.e. for b/w images, the color MUST be black
+ or white; for palette images it must be present in the palette."
+
+ |clr0 clr1|
+
+ photometric == #whiteIs0 ifTrue:[
+ clr0 := Color white.
+ clr1 := Color black.
+ ] ifFalse:[
+ photometric == #blackIs0 ifTrue:[
+ clr0 := Color black.
+ clr1 := Color white.
+ ] ifFalse:[
+ photometric ~~ #palette ifTrue:[
+ self error:'format not supported'.
+ ^ nil
+ ].
+ clr0 := colorMap at:1.
+ clr1 := colorMap at:2.
+ ]
+ ].
+ aColor = clr0 ifTrue:[
+ self atX:x y:y putValue:0.
+ ^ self
+ ].
+ aColor = clr1 ifTrue:[
+ self atX:x y:y putValue:1.
+ ^ self
+ ].
+ "
+ the color to be stored is not in the images colormap
+ "
+ self error:'invalid color'
+!
+
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
@@ -249,99 +175,102 @@
bytes at:index put:byte
!
-atX: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.
- This method checks, if it is possible to store the color
- in the image; i.e. for b/w images, the color MUST be black
- or white; for palette images it must be present in the palette."
+valueAtX: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:)
+ Pixels start at 0@0 for upper left pixel, end at
+ (width-1)@(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);
- |clr0 clr1|
+ if (__isByteArray(b) && __bothSmallInteger(x, y) && __isSmallInteger(w) ) {
+ int _w = _intVal(w);
+ int _y = _intVal(y);
+ int _x = _intVal(x);
+ unsigned _byte;
+
+ _byte = _ByteArrayInstPtr(b)->ba_element[(_w + 7) / 8 * _y + (_x / 8)];
+ RETURN( (_byte & (0x80 >> (_x % 8))) ? _MKSMALLINT(1) : _MKSMALLINT(0) );
+ }
+%}.
+
+"/ the above is equivalent to:
+"/ (notice that the code below is evaluated if the bytes-collection is
+"/ not a byteArray, or the arguments are not integers)
+
+"/ 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).
+"/ (byte bitAnd:mask) == 0 ifTrue:[^ 0].
+"/ ^ 1
- photometric == #whiteIs0 ifTrue:[
- clr0 := Color white.
- clr1 := Color black.
- ] ifFalse:[
- photometric == #blackIs0 ifTrue:[
- clr0 := Color black.
- clr1 := Color white.
- ] ifFalse:[
- photometric ~~ #palette ifTrue:[
- self error:'format not supported'.
- ^ nil
- ].
- clr0 := colorMap at:1.
- clr1 := colorMap at:2.
- ]
+"/ since that cannot happen, we faile here
+ self primitiveFailed.
+ ^ 0
+! !
+
+!Depth1Image methodsFor:'converting greyscale images'!
+
+greyImageAsFormOn:aDevice
+ "convert a greyscale image to a device form"
+
+ |f|
+
+ f := Form width:width height:height fromArray:bytes on:aDevice.
+ photometric == #blackIs0 ifTrue:[
+ f function:#xor.
+ f paint:(Color colorId:1).
+ f fillRectangleX:0 y:0 width:width height:height
].
- aColor = clr0 ifTrue:[
- self atX:x y:y putValue:0.
- ^ self
- ].
- aColor = clr1 ifTrue:[
- self atX:x y:y putValue:1.
- ^ self
- ].
+ ^ f
+!
+
+greyImageAsMonoFormOn:aDevice
+ "convert to a monochrome form - thats easy"
+
+ ^ self greyImageAsFormOn:aDevice
+! !
+
+!Depth1Image methodsFor:'converting palette images'!
+
+paletteImageAsPseudoFormOn:aDevice
+ "return a pseudo-deviceForm from the palette image."
+
+ |f|
+
"
- the color to be stored is not in the images colormap
+ this is easy, since Form already supports colorMaps
"
- self error:'invalid color'
+ f := Form width:width height:height fromArray:bytes.
+ f colorMap:colorMap.
+ ^ f
+!
+
+paletteImageAsTrueColorFormOn:aDevice
+ "since all devices must support monochrome images, and
+ a 2-entry colormap is implemented by ST/X's drawForm methods,
+ we can do this on all color devices as a palette image."
+
+ ^ self paletteImageAsPseudoFormOn:aDevice
! !
!Depth1Image methodsFor:'enumerating'!
-valueAtY:y from:xLow to:xHigh do:aBlock
- "perform aBlock for each pixelValue from x1 to x2 in row y.
- The block is passed the color at each pixel.
- This method allows slighly faster processing of an
- image than using atX:y:, since some processing can be
- avoided when going from pixel to pixel. However, for
- real image processing, specialized methods should be written."
-
- |srcIndex "{ Class: SmallInteger }"
- byte "{ Class: SmallInteger }"
- mask "{ Class: SmallInteger }"
- x1 "{ Class: SmallInteger }"
- x2 "{ Class: SmallInteger }"
- pixelValue|
-
- "this method needs more tuning, if used heavily
- (fetch 8 bits at once, unroll the loop over these 8 pixels)"
-
- x1 := xLow.
- x2 := xHigh.
- srcIndex := (self bytesPerRow * y) + 1.
-
- "left pixel is in high bit"
-
- srcIndex := srcIndex + (x1 // 8).
- mask := #[2r10000000
- 2r01000000
- 2r00100000
- 2r00010000
- 2r00001000
- 2r00000100
- 2r00000010
- 2r00000001] at:((x1 \\ 8) + 1).
-
- x1 to:x2 do:[:x |
- byte := bytes at:srcIndex.
- (byte bitAnd:mask) == 0 ifTrue:[
- pixelValue := 0
- ] ifFalse:[
- pixelValue := 1
- ].
- aBlock value:x value:pixelValue.
-
- mask := mask bitShift:-1.
- mask == 0 ifTrue:[
- mask := 2r10000000.
- srcIndex := srcIndex + 1
- ]
- ]
-!
-
atY:y from:xLow to:xHigh do:aBlock
"perform aBlock for each pixel from x1 to x2 in row y.
The block is passed the color at each pixel.
@@ -406,51 +335,57 @@
srcIndex := srcIndex + 1
]
]
-! !
-
-!Depth1Image methodsFor:'converting greyscale images'!
-
-greyImageAsFormOn:aDevice
- "convert a greyscale image to a device form"
-
- |f|
-
- f := Form width:width height:height fromArray:bytes on:aDevice.
- photometric == #blackIs0 ifTrue:[
- f function:#xor.
- f paint:(Color colorId:1).
- f fillRectangleX:0 y:0 width:width height:height
- ].
- ^ f
!
-greyImageAsMonoFormOn:aDevice
- "convert to a monochrome form - thats easy"
-
- ^ self greyImageAsFormOn:aDevice
-! !
+valueAtY:y from:xLow to:xHigh do:aBlock
+ "perform aBlock for each pixelValue from x1 to x2 in row y.
+ The block is passed the color at each pixel.
+ This method allows slighly faster processing of an
+ image than using atX:y:, since some processing can be
+ avoided when going from pixel to pixel. However, for
+ real image processing, specialized methods should be written."
-!Depth1Image methodsFor:'converting palette images'!
+ |srcIndex "{ Class: SmallInteger }"
+ byte "{ Class: SmallInteger }"
+ mask "{ Class: SmallInteger }"
+ x1 "{ Class: SmallInteger }"
+ x2 "{ Class: SmallInteger }"
+ pixelValue|
-paletteImageAsPseudoFormOn:aDevice
- "return a pseudo-deviceForm from the palette image."
+ "this method needs more tuning, if used heavily
+ (fetch 8 bits at once, unroll the loop over these 8 pixels)"
- |f|
+ x1 := xLow.
+ x2 := xHigh.
+ srcIndex := (self bytesPerRow * y) + 1.
+
+ "left pixel is in high bit"
- "
- this is easy, since Form already supports colorMaps
- "
- f := Form width:width height:height fromArray:bytes.
- f colorMap:colorMap.
- ^ f
-!
+ srcIndex := srcIndex + (x1 // 8).
+ mask := #[2r10000000
+ 2r01000000
+ 2r00100000
+ 2r00010000
+ 2r00001000
+ 2r00000100
+ 2r00000010
+ 2r00000001] at:((x1 \\ 8) + 1).
-paletteImageAsTrueColorFormOn:aDevice
- "since all devices must support monochrome images, and
- a 2-entry colormap is implemented by ST/X's drawForm methods,
- we can do this on all color devices as a palette image."
+ x1 to:x2 do:[:x |
+ byte := bytes at:srcIndex.
+ (byte bitAnd:mask) == 0 ifTrue:[
+ pixelValue := 0
+ ] ifFalse:[
+ pixelValue := 1
+ ].
+ aBlock value:x value:pixelValue.
- ^ self paletteImageAsPseudoFormOn:aDevice
+ mask := mask bitShift:-1.
+ mask == 0 ifTrue:[
+ mask := 2r10000000.
+ srcIndex := srcIndex + 1
+ ]
+ ]
! !
!Depth1Image methodsFor:'magnification'!
@@ -560,3 +495,70 @@
%}.
self primitiveFailed
! !
+
+!Depth1Image methodsFor:'queries'!
+
+bitsPerPixel
+ "return the number of bits per pixel"
+
+ ^ 1
+!
+
+bitsPerRow
+ "return the number of bits in one scanline of the image"
+
+ ^ width
+!
+
+bitsPerSample
+ "return the number of bits per sample.
+ The return value is an array of bits-per-plane."
+
+ ^ #(1)
+!
+
+bytesPerRow
+ "return the number of bytes in one scanline of the image"
+
+ |nbytes|
+
+ nbytes := width // 8.
+ ((width \\ 8) ~~ 0) ifTrue:[
+ ^ nbytes + 1
+ ].
+ ^ nbytes
+!
+
+samplesPerPixel
+ "return the number of samples per pixel in the image."
+
+ ^ 1
+!
+
+usedColors
+ "return a collection of colors used in the receiver.
+ For depth1 images, this is very easy"
+
+ photometric ~~ #palette ifTrue:[
+ ^ Array with:Color white with:Color black.
+ ].
+ ^ colorMap
+
+ "
+ (Image fromFile:'bitmaps/garfield.gif') usedColors
+ (Image fromFile:'bitmaps/SBrowser.xbm') usedColors
+ "
+!
+
+usedValues
+ "return a collection of color values used in the receiver.
+ For depth1 images, this is very easy"
+
+ ^ #(0 1)
+! !
+
+!Depth1Image class methodsFor:'documentation'!
+
+version
+ ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.15 1995-12-07 10:42:19 cg Exp $'
+! !