[Libreoffice-commits] core.git: vcl/workben

Michael Meeks michael.meeks at collabora.com
Sun Nov 16 22:39:46 PST 2014


 vcl/workben/vcldemo.cxx |   21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

New commits:
commit 18c50cefd761efe71a5e6957422ed6f153e6ba34
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Mon Nov 17 06:37:06 2014 +0000

    vcldemo: improve my rather trivial inferred alpha maths.
    
    Change-Id: I420628cea2272d6f5af0b13b9c32902627dcf86f

diff --git a/vcl/workben/vcldemo.cxx b/vcl/workben/vcldemo.cxx
index 7ccde7c..94d5492 100644
--- a/vcl/workben/vcldemo.cxx
+++ b/vcl/workben/vcldemo.cxx
@@ -798,16 +798,25 @@ public:
                         // we get the most precision from the largest delta
                         long nInverseAlpha = std::max(nAR, std::max(nAG, nAB)); // (1-a)
                         nInverseAlpha = CLAMP(nInverseAlpha, 0, 255);
+                        long nAlpha = 255 - nInverseAlpha;
 
                         pMaskAcc->SetPixel(y,x,BitmapColor((sal_Int8)CLAMP(nInverseAlpha,0,255)));
                         // now recover the pixels
-                        long n2R = aColW.GetRed() + aColB.GetRed();
-                        long n2G = aColW.GetGreen() + aColB.GetGreen();
-                        long n2B = aColW.GetBlue() + aColB.GetBlue();
+                        long nR = (aColW.GetRed() + aColB.GetRed() - nInverseAlpha) * 128;
+                        long nG = (aColW.GetGreen() + aColB.GetGreen() - nInverseAlpha) * 128;
+                        long nB = (aColW.GetBlue() + aColB.GetBlue() - nInverseAlpha) * 128;
+                        if (nAlpha == 0)
+                        { // doesn't matter what's behind transparency
+                            nR = nG = nB = 0;
+                        }
+                        else
+                        {
+                            nR /= nAlpha; nG /= nAlpha; nB /= nAlpha;
+                        }
                         pRecAcc->SetPixel(y,x,BitmapColor(
-                                                (sal_uInt8)CLAMP((n2R+1)/2-nInverseAlpha,0,255),
-                                                (sal_uInt8)CLAMP((n2G+1)/2-nInverseAlpha,0,255),
-                                                (sal_uInt8)CLAMP((n2B+1)/2-nInverseAlpha,0,255)));
+                                                (sal_uInt8)CLAMP(nR,0,255),
+                                                (sal_uInt8)CLAMP(nG,0,255),
+                                                (sal_uInt8)CLAMP(nB,0,255)));
 #undef CLAMP
                     }
                 }


More information about the Libreoffice-commits mailing list