Depth4Image.st
changeset 89 ea2bf46eb669
parent 81 4ba554473294
child 97 dd6116883ac0
--- a/Depth4Image.st	Mon Feb 06 01:30:10 1995 +0100
+++ b/Depth4Image.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/Depth4Image.st,v 1.8 1994-11-17 14:29:11 claus Exp $
+$Header: /cvs/stx/stx/libview/Depth4Image.st,v 1.9 1995-02-06 00:35:57 claus Exp $
 '!
 
 !Depth4Image class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libview/Depth4Image.st,v 1.8 1994-11-17 14:29:11 claus Exp $
+$Header: /cvs/stx/stx/libview/Depth4Image.st,v 1.9 1995-02-06 00:35:57 claus Exp $
 "
 !
 
@@ -55,6 +55,12 @@
 "
 ! !
 
+!Depth4Image class methodsFor:'queries'!
+
+imageDepth
+    ^ 4
+! !
+
 !Depth4Image methodsFor:'queries'!
 
 bitsPerPixel
@@ -92,6 +98,29 @@
     "return the number of samples per pixel in the image."
 
     ^ 1
+!
+
+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'!
@@ -142,9 +171,7 @@
 	self error:'format not supported'.
 	^ nil
     ].
-    ^ Color red:(((colorMap at:1) at:(value + 1)) * 100 / 255) 
-	  green:(((colorMap at:2) at:(value + 1)) * 100 / 255)
-	   blue:(((colorMap at:3) at:(value + 1)) * 100 / 255)
+    ^ colorMap at:(value + 1)
 !
 
 atX:x y:y putValue:aPixelValue
@@ -169,7 +196,7 @@
     bytes at:index put:byte
 ! !
 
-!Depth4Image methodsFor:'enumeration'!
+!Depth4Image methodsFor:'enumerating'!
 
 valueAtY:y from:xLow to:xHigh do:aBlock
     "perform aBlock for each pixelValue from x1 to x2 in row y.
@@ -179,12 +206,12 @@
      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 }"
+    |srcIndex   "{ Class: SmallInteger }"
+     byte       "{ Class: SmallInteger }"
+     shift      "{ Class: SmallInteger }"
+     pixelValue "{ Class: SmallInteger }"
+     x1         "{ Class: SmallInteger }"
+     x2         "{ Class: SmallInteger }"
      |
 
     x1 := xLow.
@@ -226,30 +253,26 @@
      value    "{ Class: SmallInteger }"
      x1       "{ Class: SmallInteger }"
      x2       "{ Class: SmallInteger }"
-     colors|
+     colors p |
 
-    colors := Array new:16.
-    photometric == #whiteIs0 ifTrue:[
+    (p := photometric) == #whiteIs0 ifTrue:[
+	colors := Array new:16.
 	0 to:15 do:[:i |
 	    colors at:(i+1) put:(Color grey:100 - (100 / 15 * i))
 	]
     ] ifFalse:[
-	photometric == #blackIs0 ifTrue:[
+	p == #blackIs0 ifTrue:[
+	    colors := Array new:16.
 	    0 to:15 do:[:i |
 		colors at:(i+1) put:(Color grey:(100 / 15 * i))
 	    ]
 	] ifFalse:[
-	    photometric == #palette ifTrue:[
-		1 to:16 do:[:i |
-		    colors at:i 
-			  put:(Color red:(((colorMap at:1) at:i) * 100 / 255)
-				   green:(((colorMap at:2) at:i) * 100 / 255)
-				    blue:(((colorMap at:3) at:i) * 100 / 255))
-		]
+	    p == #palette ifTrue:[
+		colors := colorMap.
 	    ] ifFalse:[
 		self error:'format not supported'.
 		^ nil
-	     ]
+	    ]
 	]
     ].
 
@@ -283,7 +306,8 @@
 magnifyRowFrom:srcBytes offset:srcStart
 	  into:dstBytes offset:dstStart factor:mX
 
-    "magnify a single pixel row - can only magnify by integer factors"
+    "magnify a single pixel row - can only magnify by integer factors.
+     Specially tuned for factor 2."
 
 %{
     unsigned char *srcP, *dstP;