Depth1Image.st
changeset 3599 bb5474dfa1c8
parent 3569 38818408ecae
child 3842 e97ae6061e75
--- a/Depth1Image.st	Tue Feb 12 18:10:50 2002 +0100
+++ b/Depth1Image.st	Tue Feb 12 18:12:37 2002 +0100
@@ -253,51 +253,25 @@
     bytes at:index put:byte
 ! !
 
-!Depth1Image methodsFor:'converting greyscale images'!
+!Depth1Image methodsFor:'converting'!
 
 asFormOn:aDevice
     "convert a monochrome image to a device form"
 
-    |f|
-
-    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
-
-    f := Form width:width height:height fromArray:bytes on:aDevice.
-    f notNil ifTrue:[
-        f colorMap:(Array with:(self colorFromValue:0)
-                          with:(self colorFromValue:1)).
-
-        "/ remember deviceForm
-
-        (device isNil or:[deviceForm isNil]) ifTrue:[
-            device := aDevice.
-            deviceForm := f.
-            maskedPixelsAre0 := nil.
-        ]
-    ].
-    ^ f
-
-    "Created: / 14.6.1996 / 15:20:00 / cg"
-    "Modified: / 22.8.1998 / 13:33:49 / cg"
+    ^ self anyImageAsFormOn:aDevice
 !
 
 greyImageAsFormOn:aDevice
     "convert a greyscale image to a device form"
 
-    ^ self asFormOn:aDevice
-
-    "Modified: 14.6.1996 / 15:21:04 / cg"
+    ^ self anyImageAsFormOn:aDevice
 !
 
 greyImageAsMonoFormOn:aDevice
     "convert to a monochrome form - thats easy"
 
-    ^ self asFormOn:aDevice
-
-    "Modified: 14.6.1996 / 15:21:09 / cg"
-! !
-
-!Depth1Image methodsFor:'converting palette images'!
+    ^ self anyImageAsFormOn:aDevice
+!
 
 paletteImageAsMonoFormOn:aDevice
     "convert a palette image to a b&w monochrome device form"
@@ -323,20 +297,12 @@
     "Modified: 24.4.1997 / 17:51:54 / cg"
 !
 
-paletteImageAsPseudoFormOn:aDevice
-    "return a pseudo-deviceForm from the palette image."
-
-    ^ self asFormOn:aDevice
-
-    "Modified: 14.6.1996 / 15:21:33 / cg"
-!
-
 paletteImageAsTrueColorFormOn:aDevice
     "since all devices must support monochrome images, and
      a 2-entry colormap is implemented by ST/X's drawForm methods,
      we can do this on all color devices as a palette image."
 
-    ^ self asFormOn:aDevice
+    ^ self anyImageAsFormOn:aDevice
 
     "
      |i|
@@ -688,6 +654,40 @@
     self primitiveFailed
 ! !
 
+!Depth1Image methodsFor:'private'!
+
+anyImageAsFormOn:aDevice
+    "convert a monochrome image to a device form"
+
+    |f color0 color1|
+
+    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
+
+    color0 := (self colorFromValue:0) exactOn:aDevice.
+    color1 := (self colorFromValue:1) exactOn:aDevice.
+    (color0 notNil and:[(color0 isOnDevice:aDevice) 
+     and:[color1 notNil and:[color1 isOnDevice:aDevice]]]) ifFalse:[
+        "could not allocate colors, do it the hard way ..."
+        ^ self paletteImageAsFormOn:aDevice.
+    ].
+
+    "all colors are available, this is easy now"
+
+    f := Form width:width height:height fromArray:bytes on:aDevice.
+    f notNil ifTrue:[
+        f colorMap:(Array with:color0 with:color1).
+
+        "/ remember deviceForm
+
+        (device isNil or:[deviceForm isNil]) ifTrue:[
+            device := aDevice.
+            deviceForm := f.
+            maskedPixelsAre0 := nil.
+        ]
+    ].
+    ^ f
+! !
+
 !Depth1Image methodsFor:'queries'!
 
 bitsPerPixel
@@ -746,5 +746,5 @@
 !Depth1Image class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.46 2001-12-04 16:45:42 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.47 2002-02-12 17:12:37 stefan Exp $'
 ! !