if a deep image has a mask, care for it (stamp out & or-in)
authorClaus Gittinger <cg@exept.de>
Fri, 21 Jun 1996 13:32:40 +0200
changeset 895 0d49372cded9
parent 894 1041c0edbd35
child 896 26cea84f134d
if a deep image has a mask, care for it (stamp out & or-in)
DevGC.st
DeviceGraphicsContext.st
--- a/DevGC.st	Fri Jun 21 11:55:50 1996 +0200
+++ b/DevGC.st	Fri Jun 21 13:32:40 1996 +0200
@@ -1836,7 +1836,8 @@
      noColor or allColor)."
 
     |id w h easy paintDither tmpForm 
-     fgId noColor allColor allBits pX pY|
+     fgId noColor allColor allBits pX pY
+     mask maskId|
 
     w := aForm width.
     h := aForm height.
@@ -1863,6 +1864,87 @@
      a deep form ignores paint/bgPaint settings
     "
     (aForm depth ~~ 1) ifTrue:[
+        (mask := aForm mask) notNil ifTrue:[
+            mask depth == 1 ifFalse:[
+                'DEVGC: alpha channel not yet supported' errorPrintCR.
+            ] ifTrue:[
+                maskId := (mask on:device) id.
+                maskId notNil ifTrue:[
+                    "
+                     create temp-form;
+                    "
+                    tmpForm := Form width:w height:h depth:device depth on:device.
+                    tmpForm initGC.
+
+                    "
+                     fill tempform with image
+                    "
+                    device
+                        copyFromId:id
+                                 x:0 y:0
+                                to:tmpForm id
+                                 x:0 y:0 
+                             width:w 
+                            height:h 
+                              with:tmpForm gcId.
+
+                    allColor := Color allColor.
+                    allBits := allColor colorId.
+
+                    "
+                     stamp out mask in temp form
+                    "
+                    device setForeground:allBits background:0 in:tmpForm gcId.
+                    device setFunction:#and in:tmpForm gcId.
+                    device
+                        copyPlaneFromId:maskId
+                                      x:0 y:0
+                                     to:tmpForm id
+                                      x:0 y:0
+                                  width:w 
+                                 height:h 
+                                   with:tmpForm gcId.
+
+
+                    "
+                     stamp out mask in destination
+                    "
+                    device setForeground:0 background:allBits in:gcId.
+                    device setFunction:#and in:gcId.
+                    device
+                        copyPlaneFromId:maskId
+                                      x:0 y:0
+                                     to:drawableId
+                                      x:pX y:pY
+                                  width:w 
+                                 height:h 
+                                   with:gcId.
+    "/ Delay waitForSeconds:3.
+                    "
+                     or-in tempform-bits ...
+                    "
+                    device setFunction:#or in:gcId.
+                    device
+                        copyFromId:tmpForm id
+                                 x:0 y:0
+                                to:drawableId
+                                 x:pX y:pY 
+                             width:w 
+                            height:h 
+                              with:gcId.
+
+                    foreground notNil ifTrue:[
+                        self device setForeground:foreground colorId in:gcId.
+                    ].
+                    background notNil ifTrue:[
+                        self device setBackground:background colorId in:gcId.
+                    ].
+                    device setFunction:function in:gcId.
+                    ^ self
+                ]
+            ]
+        ].
+
         device
             copyFromId:id
                      x:0 y:0
@@ -2008,7 +2090,7 @@
     background := nil.
     device setFunction:function in:gcId.
 
-    "Modified: 15.6.1996 / 15:36:18 / cg"
+    "Modified: 21.6.1996 / 13:26:10 / cg"
 !
 
 displayDeviceLineFromX:x0 y:y0 toX:x1 y:y1
@@ -2036,6 +2118,22 @@
      fgId bgId noColor allColor allBits dx dy
      pX pY deviceDepth|
 
+    "
+     a deep form ignores paint/bgPaint settings
+     and is always drawn opaque.
+    "
+    (aForm depth ~~ 1) ifTrue:[
+        device
+            copyFromId:id
+                     x:0 y:0
+                    to:drawableId
+                     x:pX y:pY 
+                 width:w 
+                height:h 
+                  with:gcId.
+        ^ self
+    ].
+
     bgPaint isNil ifTrue:[
         self displayDeviceForm:aForm x:x y:y.
         ^ self
@@ -2063,21 +2161,6 @@
         self initGC
     ].
 
-    "
-     a deep form ignores paint/bgPaint settings
-    "
-    (aForm depth ~~ 1) ifTrue:[
-        device
-            copyFromId:id
-                     x:0 y:0
-                    to:drawableId
-                     x:pX y:pY 
-                 width:w 
-                height:h 
-                  with:gcId.
-        ^ self
-    ].
-
     "the following code is somewhat complicated, since it has to deal
      with dithered fg/bg colors, which cannot be done directly on most
      devices (actually, a test for the devices capabilities has to be added here)
@@ -2311,7 +2394,7 @@
     foreground := nil.
     background := nil.
 
-    "Modified: 15.6.1996 / 15:36:09 / cg"
+    "Modified: 21.6.1996 / 13:31:06 / cg"
 !
 
 displayDeviceOpaqueString:aString from:index1 to:index2 in:font x:x y:y
@@ -3304,6 +3387,6 @@
 !DeviceGraphicsContext class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Attic/DevGC.st,v 1.9 1996-06-15 13:37:05 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Attic/DevGC.st,v 1.10 1996-06-21 11:32:40 cg Exp $'
 ! !
 DeviceGraphicsContext initialize!
--- a/DeviceGraphicsContext.st	Fri Jun 21 11:55:50 1996 +0200
+++ b/DeviceGraphicsContext.st	Fri Jun 21 13:32:40 1996 +0200
@@ -1836,7 +1836,8 @@
      noColor or allColor)."
 
     |id w h easy paintDither tmpForm 
-     fgId noColor allColor allBits pX pY|
+     fgId noColor allColor allBits pX pY
+     mask maskId|
 
     w := aForm width.
     h := aForm height.
@@ -1863,6 +1864,87 @@
      a deep form ignores paint/bgPaint settings
     "
     (aForm depth ~~ 1) ifTrue:[
+        (mask := aForm mask) notNil ifTrue:[
+            mask depth == 1 ifFalse:[
+                'DEVGC: alpha channel not yet supported' errorPrintCR.
+            ] ifTrue:[
+                maskId := (mask on:device) id.
+                maskId notNil ifTrue:[
+                    "
+                     create temp-form;
+                    "
+                    tmpForm := Form width:w height:h depth:device depth on:device.
+                    tmpForm initGC.
+
+                    "
+                     fill tempform with image
+                    "
+                    device
+                        copyFromId:id
+                                 x:0 y:0
+                                to:tmpForm id
+                                 x:0 y:0 
+                             width:w 
+                            height:h 
+                              with:tmpForm gcId.
+
+                    allColor := Color allColor.
+                    allBits := allColor colorId.
+
+                    "
+                     stamp out mask in temp form
+                    "
+                    device setForeground:allBits background:0 in:tmpForm gcId.
+                    device setFunction:#and in:tmpForm gcId.
+                    device
+                        copyPlaneFromId:maskId
+                                      x:0 y:0
+                                     to:tmpForm id
+                                      x:0 y:0
+                                  width:w 
+                                 height:h 
+                                   with:tmpForm gcId.
+
+
+                    "
+                     stamp out mask in destination
+                    "
+                    device setForeground:0 background:allBits in:gcId.
+                    device setFunction:#and in:gcId.
+                    device
+                        copyPlaneFromId:maskId
+                                      x:0 y:0
+                                     to:drawableId
+                                      x:pX y:pY
+                                  width:w 
+                                 height:h 
+                                   with:gcId.
+    "/ Delay waitForSeconds:3.
+                    "
+                     or-in tempform-bits ...
+                    "
+                    device setFunction:#or in:gcId.
+                    device
+                        copyFromId:tmpForm id
+                                 x:0 y:0
+                                to:drawableId
+                                 x:pX y:pY 
+                             width:w 
+                            height:h 
+                              with:gcId.
+
+                    foreground notNil ifTrue:[
+                        self device setForeground:foreground colorId in:gcId.
+                    ].
+                    background notNil ifTrue:[
+                        self device setBackground:background colorId in:gcId.
+                    ].
+                    device setFunction:function in:gcId.
+                    ^ self
+                ]
+            ]
+        ].
+
         device
             copyFromId:id
                      x:0 y:0
@@ -2008,7 +2090,7 @@
     background := nil.
     device setFunction:function in:gcId.
 
-    "Modified: 15.6.1996 / 15:36:18 / cg"
+    "Modified: 21.6.1996 / 13:26:10 / cg"
 !
 
 displayDeviceLineFromX:x0 y:y0 toX:x1 y:y1
@@ -2036,6 +2118,22 @@
      fgId bgId noColor allColor allBits dx dy
      pX pY deviceDepth|
 
+    "
+     a deep form ignores paint/bgPaint settings
+     and is always drawn opaque.
+    "
+    (aForm depth ~~ 1) ifTrue:[
+        device
+            copyFromId:id
+                     x:0 y:0
+                    to:drawableId
+                     x:pX y:pY 
+                 width:w 
+                height:h 
+                  with:gcId.
+        ^ self
+    ].
+
     bgPaint isNil ifTrue:[
         self displayDeviceForm:aForm x:x y:y.
         ^ self
@@ -2063,21 +2161,6 @@
         self initGC
     ].
 
-    "
-     a deep form ignores paint/bgPaint settings
-    "
-    (aForm depth ~~ 1) ifTrue:[
-        device
-            copyFromId:id
-                     x:0 y:0
-                    to:drawableId
-                     x:pX y:pY 
-                 width:w 
-                height:h 
-                  with:gcId.
-        ^ self
-    ].
-
     "the following code is somewhat complicated, since it has to deal
      with dithered fg/bg colors, which cannot be done directly on most
      devices (actually, a test for the devices capabilities has to be added here)
@@ -2311,7 +2394,7 @@
     foreground := nil.
     background := nil.
 
-    "Modified: 15.6.1996 / 15:36:09 / cg"
+    "Modified: 21.6.1996 / 13:31:06 / cg"
 !
 
 displayDeviceOpaqueString:aString from:index1 to:index2 in:font x:x y:y
@@ -3304,6 +3387,6 @@
 !DeviceGraphicsContext class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/DeviceGraphicsContext.st,v 1.9 1996-06-15 13:37:05 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/DeviceGraphicsContext.st,v 1.10 1996-06-21 11:32:40 cg Exp $'
 ! !
 DeviceGraphicsContext initialize!