--- a/Depth1Image.st Mon Feb 06 01:30:10 1995 +0100
+++ b/Depth1Image.st Mon Feb 06 01:38:04 1995 +0100
@@ -21,7 +21,7 @@
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.9 1994-11-21 16:43:06 claus Exp $
+$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.10 1995-02-06 00:35:47 claus Exp $
'!
!Depth1Image class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
version
"
-$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.9 1994-11-21 16:43:06 claus Exp $
+$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.10 1995-02-06 00:35:47 claus Exp $
"
!
@@ -56,6 +56,12 @@
"
! !
+!Depth1Image class methodsFor:'queries'!
+
+imageDepth
+ ^ 1
+! !
+
!Depth1Image methodsFor:'queries'!
bitsPerPixel
@@ -93,6 +99,28 @@
"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'!
@@ -123,21 +151,25 @@
}
%}.
- "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)"
+"/ 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).
+"/ 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
- "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
@@ -148,7 +180,8 @@
|lineIndex "{ Class: SmallInteger }"
byte "{ Class: SmallInteger }"
shift "{ Class: SmallInteger }"
- value "{ Class: SmallInteger }"|
+ value "{ Class: SmallInteger }"
+ p|
lineIndex := (self bytesPerRow * y) + 1.
@@ -156,26 +189,22 @@
byte := bytes at:(lineIndex + (x // 8)).
shift := #(-7 -6 -5 -4 -3 -2 -1 0) at:((x \\ 8) + 1).
value := (byte bitShift:shift) bitAnd:1.
- photometric == #whiteIs0 ifTrue:[
- (value == 0) ifTrue:[
- ^ Color white
- ].
- ^ Color black
+ (p := photometric) == #whiteIs0 ifTrue:[
+ value := 1-value.
+ p := #blackIs0
].
- photometric == #blackIs0 ifTrue:[
+ p == #blackIs0 ifTrue:[
(value == 0) ifTrue:[
^ Color black
].
^ Color white
].
- photometric ~~ #palette ifTrue:[
+ p ~~ #palette ifTrue:[
self error:'format not supported'.
^ nil
].
value := value + 1.
- ^ Color red:(((colorMap at:1) at:value) * (100.0 / 255.0))
- green:(((colorMap at:2) at:value) * (100.0 / 255.0))
- blue:(((colorMap at:3) at:value) * (100.0 / 255.0))
+ ^ colorMap at:value
!
atX:x y:y putValue:aPixelValue
@@ -266,7 +295,7 @@
self error:'invalid color'
! !
-!Depth1Image methodsFor:'enumeration'!
+!Depth1Image methodsFor:'enumerating'!
valueAtY:y from:xLow to:xHigh do:aBlock
"perform aBlock for each pixelValue from x1 to x2 in row y.
@@ -349,12 +378,8 @@
color1 := Color white
] ifFalse:[
photometric == #palette ifTrue:[
- color0 := Color red:(((colorMap at:1) at:1) * 100 / 255)
- green:(((colorMap at:2) at:1) * 100 / 255)
- blue:(((colorMap at:3) at:1) * 100 / 255).
- color1 := Color red:(((colorMap at:1) at:2) * 100 / 255)
- green:(((colorMap at:2) at:2) * 100 / 255)
- blue:(((colorMap at:3) at:2) * 100 / 255).
+ color0 := colorMap at:1.
+ color1 := colorMap at:2
] ifFalse:[
self error:'format not supported'.
^ nil
@@ -421,9 +446,7 @@
"
this is easy, since Form already supports colorMaps
"
- f := Form width:width
- height:height
- fromArray:bytes.
+ f := Form width:width height:height fromArray:bytes.
f colorMap:colorMap.
^ f
! !