--- a/Depth2Image.st Thu Dec 07 11:42:19 1995 +0100
+++ b/Depth2Image.st Thu Dec 07 12:17:07 1995 +0100
@@ -33,10 +33,6 @@
"
!
-version
- ^ '$Header: /cvs/stx/stx/libview/Depth2Image.st,v 1.14 1995-11-11 15:49:19 cg Exp $'
-!
-
documentation
"
this class represents four-color (2 bit / pixel) images
@@ -52,87 +48,8 @@
^ 2
! !
-!Depth2Image methodsFor:'queries'!
-
-bitsPerPixel
- "return the number of bits per pixel"
-
- ^ 2
-!
-
-bitsPerRow
- "return the number of bits in one scanline of the image"
-
- ^ width * 2
-!
-
-bitsPerSample
- "return the number of bits per sample.
- The return value is an array of bits-per-plane."
-
- ^ #(2)
-!
-
-bytesPerRow
- "return the number of bytes in one scanline of the image"
-
- |nbytes|
-
- nbytes := width // 4.
- ((width \\ 4) ~~ 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 black
- with:(Color grey:33)
- with:(Color grey:67)
- with:Color black.
- ].
- ^ colorMap
-!
-
-usedValues
- "return a collection of color values used in the receiver."
-
- "actually, this is wrong - we have to look if those are
- really used. However, assume that we dont care for
- those extra colors here ..."
-
- ^ #(0 1 2 3)
-! !
-
!Depth2Image methodsFor:'accessing'!
-valueAtX:x y:y
- "retrieve a pixel at x/y; return a pixel value.
- 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 }"
- shift "{ Class: SmallInteger }" |
-
- lineIndex := (self bytesPerRow * y) + 1.
-
- "left pixel in high bits"
- byte := bytes at:(lineIndex + (x // 4)).
- shift := #(-6 -4 -2 0) at:((x \\ 4) + 1).
- ^ (byte bitShift:shift) bitAnd:3.
-!
-
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
@@ -195,124 +112,23 @@
shift := #(6 4 2 0) at:((x \\ 4) + 1).
byte := (byte bitAnd:(3 bitShift:shift) bitInvert) bitOr:(aPixelValue bitShift:shift).
bytes at:index put:byte
-! !
-
-!Depth2Image 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 x coordinate and the pixelValue at each pixel.
- This method allows slighly faster processing of an
- image than using valueAtX: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 }"
- shift "{ Class: SmallInteger }"
- value "{ Class: SmallInteger }"
- x1 "{ Class: SmallInteger }"
- x2 "{ Class: SmallInteger }"|
-
- "left pixel in high bits"
-
- x1 := xLow.
- x2 := xHigh.
-
- srcIndex := (self bytesPerRow * y) + 1.
- srcIndex := srcIndex + (x1 // 4).
- shift := #(-6 -4 -2 0) at:((x1 \\ 4) + 1).
-
- x1 to:x2 do:[:x |
- byte := bytes at:srcIndex.
- value := (byte bitShift:shift) bitAnd:3.
-
- aBlock value:x value:value.
-
- shift == 0 ifTrue:[
- shift := -6.
- srcIndex := srcIndex + 1
- ] ifFalse:[
- shift := shift + 2.
- ]
- ].
!
-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.
- 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 }"
- shift "{ Class: SmallInteger }"
- value "{ Class: SmallInteger }"
- x1 "{ Class: SmallInteger }"
- x2 "{ Class: SmallInteger }"
- color0 color1 color2 color3 color|
+valueAtX:x y:y
+ "retrieve a pixel at x/y; return a pixel value.
+ Pixels start at x=0 , y=0 for upper left pixel, end at
+ x = width-1, y=height-1 for lower right pixel"
- photometric == #whiteIs0 ifTrue:[
- color0 := Color white.
- color1 := Color grey:67.
- color2 := Color grey:33.
- color3 := Color black
- ] ifFalse:[
- photometric == #blackIs0 ifTrue:[
- color0 := Color black.
- color1 := Color grey:33.
- color2 := Color grey:67.
- color3 := Color white
- ] ifFalse:[
- photometric == #palette ifTrue:[
- color0 := colorMap at:1.
- color1 := colorMap at:2.
- color2 := colorMap at:3.
- color3 := colorMap at:4.
- ] ifFalse:[
- self error:'format not supported'.
- ^ nil
- ]
- ]
- ].
+ |lineIndex "{ Class: SmallInteger }"
+ byte "{ Class: SmallInteger }"
+ shift "{ Class: SmallInteger }" |
+
+ lineIndex := (self bytesPerRow * y) + 1.
"left pixel in high bits"
-
- x1 := xLow.
- x2 := xHigh.
-
- srcIndex := (self bytesPerRow * y) + 1.
- srcIndex := srcIndex + (x1 // 4).
- shift := #(-6 -4 -2 0) at:((x1 \\ 4) + 1).
-
- x1 to:x2 do:[:x |
- byte := bytes at:srcIndex.
- value := (byte bitShift:shift) bitAnd:3.
-
- (value == 0) ifTrue:[
- color := color0
- ] ifFalse:[
- (value == 1) ifTrue:[
- color := color1
- ] ifFalse:[
- (value == 2) ifTrue:[
- color := color2
- ] ifFalse:[
- color := color3
- ]
- ]
- ].
- aBlock value:x value:color.
-
- shift == 0 ifTrue:[
- shift := -6.
- srcIndex := srcIndex + 1
- ] ifFalse:[
- shift := shift + 2.
- ]
- ].
+ byte := bytes at:(lineIndex + (x // 4)).
+ shift := #(-6 -4 -2 0) at:((x \\ 4) + 1).
+ ^ (byte bitShift:shift) bitAnd:3.
! !
!Depth2Image methodsFor:'converting greyscale images'!
@@ -394,6 +210,124 @@
^ Form width:w height:h fromArray:monoData on:aDevice
! !
+!Depth2Image methodsFor:'enumerating'!
+
+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.
+ 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 }"
+ shift "{ Class: SmallInteger }"
+ value "{ Class: SmallInteger }"
+ x1 "{ Class: SmallInteger }"
+ x2 "{ Class: SmallInteger }"
+ color0 color1 color2 color3 color|
+
+ photometric == #whiteIs0 ifTrue:[
+ color0 := Color white.
+ color1 := Color grey:67.
+ color2 := Color grey:33.
+ color3 := Color black
+ ] ifFalse:[
+ photometric == #blackIs0 ifTrue:[
+ color0 := Color black.
+ color1 := Color grey:33.
+ color2 := Color grey:67.
+ color3 := Color white
+ ] ifFalse:[
+ photometric == #palette ifTrue:[
+ color0 := colorMap at:1.
+ color1 := colorMap at:2.
+ color2 := colorMap at:3.
+ color3 := colorMap at:4.
+ ] ifFalse:[
+ self error:'format not supported'.
+ ^ nil
+ ]
+ ]
+ ].
+
+ "left pixel in high bits"
+
+ x1 := xLow.
+ x2 := xHigh.
+
+ srcIndex := (self bytesPerRow * y) + 1.
+ srcIndex := srcIndex + (x1 // 4).
+ shift := #(-6 -4 -2 0) at:((x1 \\ 4) + 1).
+
+ x1 to:x2 do:[:x |
+ byte := bytes at:srcIndex.
+ value := (byte bitShift:shift) bitAnd:3.
+
+ (value == 0) ifTrue:[
+ color := color0
+ ] ifFalse:[
+ (value == 1) ifTrue:[
+ color := color1
+ ] ifFalse:[
+ (value == 2) ifTrue:[
+ color := color2
+ ] ifFalse:[
+ color := color3
+ ]
+ ]
+ ].
+ aBlock value:x value:color.
+
+ shift == 0 ifTrue:[
+ shift := -6.
+ srcIndex := srcIndex + 1
+ ] ifFalse:[
+ shift := shift + 2.
+ ]
+ ].
+!
+
+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 x coordinate and the pixelValue at each pixel.
+ This method allows slighly faster processing of an
+ image than using valueAtX: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 }"
+ shift "{ Class: SmallInteger }"
+ value "{ Class: SmallInteger }"
+ x1 "{ Class: SmallInteger }"
+ x2 "{ Class: SmallInteger }"|
+
+ "left pixel in high bits"
+
+ x1 := xLow.
+ x2 := xHigh.
+
+ srcIndex := (self bytesPerRow * y) + 1.
+ srcIndex := srcIndex + (x1 // 4).
+ shift := #(-6 -4 -2 0) at:((x1 \\ 4) + 1).
+
+ x1 to:x2 do:[:x |
+ byte := bytes at:srcIndex.
+ value := (byte bitShift:shift) bitAnd:3.
+
+ aBlock value:x value:value.
+
+ shift == 0 ifTrue:[
+ shift := -6.
+ srcIndex := srcIndex + 1
+ ] ifFalse:[
+ shift := shift + 2.
+ ]
+ ].
+! !
+
!Depth2Image methodsFor:'magnification'!
magnifyRowFrom:srcBytes offset:srcStart
@@ -473,3 +407,71 @@
.
self primitiveFailed
! !
+
+!Depth2Image methodsFor:'queries'!
+
+bitsPerPixel
+ "return the number of bits per pixel"
+
+ ^ 2
+!
+
+bitsPerRow
+ "return the number of bits in one scanline of the image"
+
+ ^ width * 2
+!
+
+bitsPerSample
+ "return the number of bits per sample.
+ The return value is an array of bits-per-plane."
+
+ ^ #(2)
+!
+
+bytesPerRow
+ "return the number of bytes in one scanline of the image"
+
+ |nbytes|
+
+ nbytes := width // 4.
+ ((width \\ 4) ~~ 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 black
+ with:(Color grey:33)
+ with:(Color grey:67)
+ with:Color black.
+ ].
+ ^ colorMap
+!
+
+usedValues
+ "return a collection of color values used in the receiver."
+
+ "actually, this is wrong - we have to look if those are
+ really used. However, assume that we dont care for
+ those extra colors here ..."
+
+ ^ #(0 1 2 3)
+! !
+
+!Depth2Image class methodsFor:'documentation'!
+
+version
+ ^ '$Header: /cvs/stx/stx/libview/Depth2Image.st,v 1.15 1995-12-07 11:16:18 cg Exp $'
+! !
--- a/Depth4Image.st Thu Dec 07 11:42:19 1995 +0100
+++ b/Depth4Image.st Thu Dec 07 12:17:07 1995 +0100
@@ -33,10 +33,6 @@
"
!
-version
- ^ '$Header: /cvs/stx/stx/libview/Depth4Image.st,v 1.13 1995-11-11 15:49:22 cg Exp $'
-!
-
documentation
"
this class represents 16-color (4 bit / pixel) images.
@@ -52,90 +48,8 @@
^ 4
! !
-!Depth4Image ignoredMethodsFor:'queries'!
-
-bitsPerSample
- "return the number of bits per sample.
- The return value is an array of bits-per-plane."
-
- ^ #(4)
-!
-
-samplesPerPixel
- "return the number of samples per pixel in the image."
-
- ^ 1
-! !
-
-!Depth4Image methodsFor:'queries'!
-
-bitsPerPixel
- "return the number of bits per pixel"
-
- ^ 4
-!
-
-bitsPerRow
- "return the number of bits in one scanline of the image"
-
- ^ width * 4
-!
-
-bytesPerRow
- "return the number of bytes in one scanline of the image"
-
- |nbytes|
-
- nbytes := width // 2.
- width odd ifTrue:[
- ^ nbytes + 1
- ].
- ^ nbytes
-!
-
-usedValues
- "return a collection of color values used in the receiver."
-
- |useFlags usedValues|
-
- useFlags := Array new:16 withAll:false.
- width even ifFalse:[
- 0 to:self height - 1 do:[:y |
- self valueAtY:y from:0 to:self width - 1 do:[:x :pixel |
- useFlags at:(pixel + 1) put:true
- ]
- ].
- ] ifTrue:[
- bytes usedValues do:[:byte |
- useFlags at:(byte bitShift:-4)+1 put:true.
- useFlags at:(byte bitAnd:2r1111)+1 put:true.
- ].
- ].
- usedValues := OrderedCollection new.
- 1 to:16 do:[:i | (useFlags at:i) ifTrue:[usedValues add:(i-1)]].
- ^ usedValues
-! !
-
!Depth4Image methodsFor:'accessing'!
-valueAtX: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
- x = width-1, y=height-1 for lower right pixel"
-
- |lineIndex "{ Class: SmallInteger }"
- byte "{ Class: SmallInteger }" |
-
- lineIndex := (self bytesPerRow * y) + 1.
-
- "left pixel in high bits"
- byte := bytes at:(lineIndex + (x // 2)).
- x even ifTrue:[
- ^ (byte bitShift:-4) bitAnd:16rF.
- ].
- ^ byte bitAnd:16rF.
-!
-
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
@@ -187,51 +101,28 @@
byte := (byte bitAnd:16rF0) bitOr:aPixelValue
].
bytes at:index put:byte
+!
+
+valueAtX: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
+ x = width-1, y=height-1 for lower right pixel"
+
+ |lineIndex "{ Class: SmallInteger }"
+ byte "{ Class: SmallInteger }" |
+
+ lineIndex := (self bytesPerRow * y) + 1.
+
+ "left pixel in high bits"
+ byte := bytes at:(lineIndex + (x // 2)).
+ x even ifTrue:[
+ ^ (byte bitShift:-4) bitAnd:16rF.
+ ].
+ ^ byte bitAnd:16rF.
! !
!Depth4Image 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 pixelValue at each pixel.
- This method allows slighly faster processing of an
- image than using valueAtX: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 }"
- shift "{ Class: SmallInteger }"
- pixelValue "{ Class: SmallInteger }"
- x1 "{ Class: SmallInteger }"
- x2 "{ Class: SmallInteger }"
- |
-
- x1 := xLow.
- x2 := xHigh.
- srcIndex := (self bytesPerRow * y) + 1.
- srcIndex := srcIndex + (x1 // 2).
- x1 even ifTrue:[
- shift := -4
- ] ifFalse:[
- shift := 0
- ].
-
- x1 to:x2 do:[:x |
- shift == 0 ifTrue:[
- byte := bytes at:srcIndex.
- pixelValue := byte bitAnd:16rF.
- shift := -4.
- srcIndex := srcIndex + 1.
- ] ifFalse:[
- byte := bytes at:srcIndex.
- pixelValue := (byte bitShift:-4) bitAnd:16rF.
- shift := 0
- ].
- aBlock value:x value:pixelValue.
- ]
-!
-
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.
@@ -292,6 +183,47 @@
].
aBlock value:x value:(colors at:(value + 1)).
]
+!
+
+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 pixelValue at each pixel.
+ This method allows slighly faster processing of an
+ image than using valueAtX: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 }"
+ shift "{ Class: SmallInteger }"
+ pixelValue "{ Class: SmallInteger }"
+ x1 "{ Class: SmallInteger }"
+ x2 "{ Class: SmallInteger }"
+ |
+
+ x1 := xLow.
+ x2 := xHigh.
+ srcIndex := (self bytesPerRow * y) + 1.
+ srcIndex := srcIndex + (x1 // 2).
+ x1 even ifTrue:[
+ shift := -4
+ ] ifFalse:[
+ shift := 0
+ ].
+
+ x1 to:x2 do:[:x |
+ shift == 0 ifTrue:[
+ byte := bytes at:srcIndex.
+ pixelValue := byte bitAnd:16rF.
+ shift := -4.
+ srcIndex := srcIndex + 1.
+ ] ifFalse:[
+ byte := bytes at:srcIndex.
+ pixelValue := (byte bitShift:-4) bitAnd:16rF.
+ shift := 0
+ ].
+ aBlock value:x value:pixelValue.
+ ]
! !
!Depth4Image methodsFor:'magnification'!
@@ -380,3 +312,58 @@
.
self primitiveFailed
! !
+
+!Depth4Image methodsFor:'queries'!
+
+bitsPerPixel
+ "return the number of bits per pixel"
+
+ ^ 4
+!
+
+bitsPerRow
+ "return the number of bits in one scanline of the image"
+
+ ^ width * 4
+!
+
+bytesPerRow
+ "return the number of bytes in one scanline of the image"
+
+ |nbytes|
+
+ nbytes := width // 2.
+ width odd ifTrue:[
+ ^ nbytes + 1
+ ].
+ ^ nbytes
+!
+
+usedValues
+ "return a collection of color values used in the receiver."
+
+ |useFlags usedValues|
+
+ useFlags := Array new:16 withAll:false.
+ width even ifFalse:[
+ 0 to:self height - 1 do:[:y |
+ self valueAtY:y from:0 to:self width - 1 do:[:x :pixel |
+ useFlags at:(pixel + 1) put:true
+ ]
+ ].
+ ] ifTrue:[
+ bytes usedValues do:[:byte |
+ useFlags at:(byte bitShift:-4)+1 put:true.
+ useFlags at:(byte bitAnd:2r1111)+1 put:true.
+ ].
+ ].
+ usedValues := OrderedCollection new.
+ 1 to:16 do:[:i | (useFlags at:i) ifTrue:[usedValues add:(i-1)]].
+ ^ usedValues
+! !
+
+!Depth4Image class methodsFor:'documentation'!
+
+version
+ ^ '$Header: /cvs/stx/stx/libview/Depth4Image.st,v 1.14 1995-12-07 11:17:07 cg Exp $'
+! !