[Libreoffice-commits] core.git: Branch 'feature/nativealpha' - 2 commits - vcl/headless

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Mon Jun 20 05:57:08 UTC 2016


 vcl/headless/svpgdi.cxx |   68 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 56 insertions(+), 12 deletions(-)

New commits:
commit 85acef1463185d99fb4cb4af78c61dcf596eac19
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Sun Jun 19 10:19:17 2016 +0800

    don't use AA in SVP backend when getAntiAliasB2DDraw is false
    
    Change-Id: Icea880a824f57ca74eb9e22820893faf6cbf7945

diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx
index aa7b1f5..fac9736 100644
--- a/vcl/headless/svpgdi.cxx
+++ b/vcl/headless/svpgdi.cxx
@@ -734,7 +734,10 @@ void SvpSalGraphics::drawLine( long nX1, long nY1, long nX2, long nY2 )
     cairo_t* cr = getCairoContext(false);
     clipRegion(cr);
 
-    AddPolygonToPath(cr, aPoly, aPoly.isClosed(), !getAntiAliasB2DDraw(), true);
+    bool bAA = getAntiAliasB2DDraw();
+
+    cairo_set_antialias(cr, bAA ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE);
+    AddPolygonToPath(cr, aPoly, aPoly.isClosed(), !bAA, true);
 
     applyColor(cr, m_aLineColor);
 
@@ -816,6 +819,7 @@ bool SvpSalGraphics::drawPolyLine(
     cairo_set_line_width(cr, rLineWidths.getX());
     cairo_set_miter_limit(cr, fMiterLimit);
 
+    cairo_set_antialias(cr, getAntiAliasB2DDraw() ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE);
 
     basegfx::B2DRange extents(0, 0, 0, 0);
 
commit 03b43e9d4d2f9688decdb80f923cb56d30e7f7a5
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Sun Jun 19 10:13:28 2016 +0800

    svp: premultiply the buffer when drawing a 32-bit bitmap
    
    Cairo uses premultiplied alpha for RGBA bitmap buffers. As our
    bitmap buffer doesn't currently do this, we have to do it just
    before we draw a bitmap.
    
    Change-Id: I551ba6d589b7339b2e081452c2720b39e7278b68

diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx
index de3a16b..aa7b1f5 100644
--- a/vcl/headless/svpgdi.cxx
+++ b/vcl/headless/svpgdi.cxx
@@ -85,6 +85,16 @@ namespace
         aDamageRect.intersect(getClipBox(cr));
         return aDamageRect;
     }
+
+    static sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a)
+    {
+        return (a > 0) ? (c * 255 + a / 2) / a : 0;
+    }
+
+    static sal_uInt8 premultiply(sal_uInt8 c, sal_uInt8 a)
+    {
+        return (c * a + 127) / 255;
+    }
 }
 
 #ifndef IOS
@@ -103,6 +113,28 @@ bool SvpSalGraphics::blendAlphaBitmap( const SalTwoRect&, const SalBitmap&, cons
 
 namespace
 {
+    void premultiplyBuffer(int width, int height, int stride, unsigned char* data)
+    {
+        for (int y = 0; y < height; ++y)
+        {
+            unsigned int* row = reinterpret_cast<unsigned int*>(data + y * stride);
+            for (int x = 0; x < width; ++x)
+            {
+                unsigned int px = row[x];
+                unsigned char a = (px & 0xff000000) >> 24;
+                unsigned char r = (px & 0x00ff0000) >> 16;
+                unsigned char g = (px & 0x0000ff00) >> 8;
+                unsigned char b = (px & 0x000000ff);
+
+                r = premultiply(r, a);
+                g = premultiply(g, a);
+                b = premultiply(b, a);
+
+                row[x] = (a << 24) | (r << 16) | (g << 8) | b;
+            }
+        }
+    }
+
     class SourceHelper
     {
     public:
@@ -127,7 +159,25 @@ namespace
                 source = SvpSalGraphics::createCairoSurface(aTmpBmp.GetBuffer());
             }
             else
-                source = SvpSalGraphics::createCairoSurface(rSrcBmp.GetBuffer());
+            {
+                const BitmapBuffer* pSrc = rSrcBmp.GetBuffer();
+                if (pSrc->mnColorChannelBitCount == 32)
+                {
+                    aTmpBmp.Create(rSrcBmp);
+                    source = SvpSalGraphics::createCairoSurface(aTmpBmp.GetBuffer());
+                    cairo_surface_flush(source);
+                    int w = cairo_image_surface_get_width(source);
+                    int h = cairo_image_surface_get_height(source);
+                    int stride = cairo_image_surface_get_stride(source);
+                    unsigned char* data = cairo_image_surface_get_data(source);
+                    premultiplyBuffer(w, h, stride, data);
+                    cairo_surface_mark_dirty(source);
+                }
+                else
+                {
+                    source = SvpSalGraphics::createCairoSurface(rSrcBmp.GetBuffer());
+                }
+            }
         }
         ~SourceHelper()
         {
@@ -1026,16 +1076,6 @@ void SvpSalGraphics::drawBitmap( const SalTwoRect& rTR,
     drawAlphaBitmap(rTR, rSourceBitmap, rTransparentBitmap);
 }
 
-static sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a)
-{
-    return (a > 0) ? (c * 255 + a / 2) / a : 0;
-}
-
-static sal_uInt8 premultiply(sal_uInt8 c, sal_uInt8 a)
-{
-    return (c * a + 127) / 255;
-}
-
 void SvpSalGraphics::drawMask( const SalTwoRect& rTR,
                                const SalBitmap& rSalBitmap,
                                SalColor nMaskColor )


More information about the Libreoffice-commits mailing list