Depth1Image.st
changeset 4419 a7b3e60e4f0a
parent 4117 eedeb5ed8e91
child 4767 61d7b2ee4939
--- a/Depth1Image.st	Fri Aug 05 14:24:10 2005 +0200
+++ b/Depth1Image.st	Fri Aug 05 14:45:17 2005 +0200
@@ -716,13 +716,22 @@
 !
 
 usedValues
-    "return a collection of color values used in the receiver.
-     For depth1 images, we assume both 1- and 0-pixels are present ...
-     ... which is not really true - it could be all-white or all-black"
+    "return a collection of color values used in the receiver."
+
+    |bits first|
+
+    bits := self bits.
+    bits isEmptyOrNil ifTrue:[^ #() ].
 
-    ^ #(0 1)
+    first := bits at:1.
+    ((first == 0) or:[(first == 2r11111111)]) ifFalse:[ ^ #(0 1) ].
 
-    "Modified: / 28.7.1998 / 22:22:43 / cg"
+    bits do:[:eachByte |
+        (first bitXor:eachByte) ~~ 0 ifTrue:[
+            ^ #(0 1)
+        ].
+    ].
+    ^ first == 0 ifTrue:[ #(0) ] ifFalse:[ #(1) ].
 !
 
 valueFromColor:aColor
@@ -762,5 +771,5 @@
 !Depth1Image class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.53 2004-03-20 13:28:14 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.54 2005-08-05 12:45:17 cg Exp $'
 ! !