monochrome fixes
authorClaus Gittinger <cg@exept.de>
Mon, 21 Apr 1997 11:09:40 +0200
changeset 1621 5b1e6427d5f6
parent 1620 49812898bfe2
child 1622 35706c4ba17f
monochrome fixes
Color.st
--- a/Color.st	Mon Apr 21 11:08:38 1997 +0200
+++ b/Color.st	Mon Apr 21 11:09:40 1997 +0200
@@ -327,8 +327,9 @@
 	    (red isNil or:[red colorId isNil
 	    or:[green isNil or:[green colorId isNil
 	    or:[blue isNil or:[blue colorId isNil]]]]]) ifTrue:[
-	        'Color [warning]: cannot allocate primary color' errorPrintCR.
+	        'Color [warning]: cannot allocate primary color(s)' errorPrintCR.
 		aDevice hasColors:false.
+		aDevice hasGrayscales:false.
 		red := green := blue := nil.
 	    ]
         ].
@@ -364,7 +365,7 @@
                 colors add:((self red:0 green:100 blue:100) exactOn:aDevice).
             ].
 
-            aDevice hasGreyscales ifTrue:[
+            aDevice hasGrayscales ifTrue:[
                 aDevice hasColors ifFalse:[
                     colors := OrderedCollection new.
                     colors add:((self gray:50) exactOn:aDevice).
@@ -379,9 +380,7 @@
 
             colors notNil ifTrue:[  
                 colors := colors select:[:clr | clr notNil and:[clr colorId notNil]].
-		colors size > 2 ifTrue:[
-                    aDevice setDitherColors:(colors asArray).
-		]
+                aDevice setDitherColors:(colors asArray).
             ]
         ]
     ]
@@ -2246,7 +2245,7 @@
                      scaledGreen:g 
                       scaledBlue:b 
                         on:aDevice 
-                        in:aDevice availableDitherColors
+                        in:(aDevice availableDitherColors)
 
     "Created: 14.6.1996 / 20:13:22 / cg"
     "Modified: 11.7.1996 / 18:20:14 / cg"
@@ -2973,7 +2972,7 @@
     "/ if its 'almost' grey, make it grey and round it a bit (1%)
     "/
     greyV := (3 * red) + (6 * green) + (1 * blue).
-    greyV := (greyV / 1000.0) rounded * 10.
+    greyV := (greyV / 1000.0) rounded * 100.
 
     "/ allow an error of 1% in red & green, 2% in blue
 
@@ -3009,7 +3008,7 @@
         "/ none found ? -> do a hard dither using fixColors
 
         (id isNil and:[form isNil]) ifTrue:[
-            (deviceFixColors notNil "and:[aDevice == Display]") ifTrue:[
+            deviceFixColors notNil ifTrue:[
                 self fixDitherRed:rV green:gV blue:bV on:aDevice 
                              into:[:c :f | newColor := c. form := f].
                 newColor notNil ifTrue:[^ newColor].
@@ -3026,7 +3025,7 @@
     ].
 
     (id isNil and:[form isNil]) ifTrue:[
-        "still no result - try greying"
+        "still no result - try graying"
 
         greyV == 0 ifTrue:[
             id := aDevice blackpixel
@@ -3040,6 +3039,20 @@
                                   into:[:c :f | newColor := c. form := f].
                     newColor notNil ifTrue:[^ newColor].
                 ].
+		form isNil ifTrue:[
+		    "/ still none - dither b&w
+		    self monoDitherFor:(greyV / MaxValue)
+			       between:Black 
+			       and:White
+			       on:aDevice 
+                               into:[:c :f | newColor := c. form := f].
+                    newColor notNil ifTrue:[^ newColor].
+		    form isNil ifTrue:[
+			"/ cannot happen
+		        'Color [warning]: monoDither failed' errorPrintCR.
+			^ nil
+		    ]
+		]
             ]
         ].
     ].
@@ -4089,6 +4102,6 @@
 !Color class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Color.st,v 1.95 1997-04-20 10:45:23 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Color.st,v 1.96 1997-04-21 09:09:40 cg Exp $'
 ! !
 Color initialize!