DeviceGraphicsContext.st
changeset 8009 d5e22275f8de
parent 8008 1c39c7155eaa
child 8010 775d6d381f20
--- a/DeviceGraphicsContext.st	Wed Apr 12 10:39:30 2017 +0200
+++ b/DeviceGraphicsContext.st	Wed Apr 12 14:40:28 2017 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1992 by Claus Gittinger
 	      All Rights Reserved
@@ -2390,7 +2392,72 @@
         ].
         "/ draw the pixels (always MSB)
         device 
-            drawBits:dstData msb:true bitsPerPixel:32 depth:24 padding:32 
+            drawBits:dstData bitsPerPixel:32 depth:24 padding:32 
+            width:w height:h x:0 y:0 
+            into:(self drawableId) x:pX y:pY width:w height:h with:gcId.
+        ^ self.
+    ].
+    bppDrawable == 24 ifTrue:[
+        "/ data is coming as bytes in r,g,b order
+        dstRowIndex := 1.
+        imgRowIndex := 1.
+
+        "/ draw "by hand" here
+        0 to:h-1 do:[:y |
+            dstIndex := dstRowIndex.
+            imgIndex := imgRowIndex.
+            0 to:w-1 do:[:x |
+                |rD "{Class: SmallInteger}" 
+                 gD "{Class: SmallInteger}"
+                 bD "{Class: SmallInteger}" 
+                 rI "{Class: SmallInteger}"
+                 gI "{Class: SmallInteger}"
+                 bI "{Class: SmallInteger}"
+                 aI "{Class: SmallInteger}"
+                 aD "{Class: SmallInteger}"
+                 nR "{Class: SmallInteger}"
+                 nG "{Class: SmallInteger}"
+                 nB "{Class: SmallInteger}"|
+
+                rD := dstData at:(dstIndex+2).
+                gD := dstData at:(dstIndex+1).
+                bD := dstData at:(dstIndex+0).
+
+                rI := imgData at:(imgIndex).
+                gI := imgData at:(imgIndex+1).
+                bI := imgData at:(imgIndex+2).
+                aI := imgData at:(imgIndex+3).
+
+                aI == 255 ifTrue:[
+                    nR := rI.
+                    nG := gI.
+                    nB := bI.
+                ] ifFalse:[
+                    aI == 0 ifTrue:[
+                        nR := rD.
+                        nG := gD.
+                        nB := bD.
+                    ] ifFalse:[
+                        aD := 255 - aI.
+
+                        nR := (((rI * aI)+(rD * aD)) // 255).
+                        nG := (((gI * aI)+(gD * aD)) // 255).
+                        nB := (((bI * aI)+(bD * aD)) // 255).
+                    ].
+                ].
+                dstData at:(dstIndex+0) put:nR.
+                dstData at:(dstIndex+1) put:nG.
+                dstData at:(dstIndex+2) put:nB.
+
+                dstIndex := dstIndex + 3.
+                imgIndex := imgIndex + 4.
+            ].
+            dstRowIndex := dstRowIndex + dstBytesPerRow.
+            imgRowIndex := imgRowIndex + imgBytesPerRow.
+        ].
+        "/ draw the pixels (always MSB)
+        device 
+            drawBits:dstData bitsPerPixel:24 depth:24 padding:32 
             width:w height:h x:0 y:0 
             into:(self drawableId) x:pX y:pY width:w height:h with:gcId.
         ^ self.