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

Caolán McNamara caolanm at redhat.com
Wed Jul 26 15:59:29 UTC 2017


 vcl/headless/svpgdi.cxx |   54 +++++++++++++++++++++++++++++++++---------------
 1 file changed, 38 insertions(+), 16 deletions(-)

New commits:
commit d148340babf6c973f7d463909d7a51e16c953248
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed Jul 26 14:37:40 2017 +0100

    Resolves: tdf#104141 CAIRO_FORMAT_A1 vs N1BitLsbPal
    
    where vcl transparency is the opposite of cairo's so we've been switching the
    source color to the opposite for drawing on CAIRO_FORMAT_A1 and then sucking
    out the bits "as-is" to give the right results.
    
    Now instead use the right source color and toggle CAIRO_FORMAT_A1 bitmaps to
    N1BitLsbPal in getBitmap.
    
    Then additionally toggle all N1BitLsbPal bitmaps input to drawBitmap to
    CAIRO_FORMAT_A1 when making a cairo surface from them.
    
    Change-Id: I45c6d4f3894c6a22a07a3bd65950cd8070e8eaff
    Reviewed-on: https://gerrit.libreoffice.org/40453
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx
index f72797cd5835..98af7f417062 100644
--- a/vcl/headless/svpgdi.cxx
+++ b/vcl/headless/svpgdi.cxx
@@ -100,6 +100,29 @@ bool SvpSalGraphics::blendAlphaBitmap( const SalTwoRect&, const SalBitmap&, cons
 
 namespace
 {
+    cairo_format_t getCairoFormat(const BitmapBuffer& rBuffer)
+    {
+        cairo_format_t nFormat;
+        assert(rBuffer.mnBitCount == 32 || rBuffer.mnBitCount == 1);
+        if (rBuffer.mnBitCount == 32)
+            nFormat = CAIRO_FORMAT_ARGB32;
+        else
+            nFormat = CAIRO_FORMAT_A1;
+        return nFormat;
+    }
+
+    void Toggle1BitTransparency(const BitmapBuffer& rBuf)
+    {
+        // TODO: make upper layers use standard alpha
+        if (getCairoFormat(rBuf) == CAIRO_FORMAT_A1)
+        {
+            const int nImageSize = rBuf.mnHeight * rBuf.mnScanlineSize;
+            unsigned char* pDst = rBuf.mpBits;
+            for (int i = nImageSize; --i >= 0; ++pDst)
+                *pDst = ~*pDst;
+        }
+    }
+
     class SourceHelper
     {
     public:
@@ -911,7 +934,7 @@ void SvpSalGraphics::applyColor(cairo_t *cr, SalColor aColor)
     }
     else
     {
-        double fSet = aColor == COL_BLACK ? 0.0 : 1.0;
+        double fSet = aColor == COL_BLACK ? 1.0 : 0.0;
         cairo_set_source_rgba(cr, 1, 1, 1, fSet);
         cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
     }
@@ -968,8 +991,12 @@ static basegfx::B2DRange renderSource(cairo_t* cr, const SalTwoRect& rTR,
     if (rTR.mnSrcWidth != 0 && rTR.mnSrcHeight != 0) {
         cairo_scale(cr, (double)(rTR.mnDestWidth)/rTR.mnSrcWidth, ((double)rTR.mnDestHeight)/rTR.mnSrcHeight);
     }
+
+    cairo_save(cr);
     cairo_set_source_surface(cr, source, -rTR.mnSrcX, -rTR.mnSrcY);
+    cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
     cairo_paint(cr);
+    cairo_restore(cr);
 
     return extents;
 }
@@ -1026,12 +1053,16 @@ void SvpSalGraphics::copyBits( const SalTwoRect& rTR,
 
 void SvpSalGraphics::drawBitmap(const SalTwoRect& rTR, const SalBitmap& rSourceBitmap)
 {
-    SourceHelper aSurface(rSourceBitmap);
-    cairo_surface_t* source = aSurface.getSurface();
-    if (!source)
+    if (rSourceBitmap.GetBitCount() == 1)
     {
-        SAL_WARN("vcl.gdi", "unsupported SvpSalGraphics::drawBitmap case");
+        MaskHelper aMask(rSourceBitmap);
+        cairo_surface_t* source = aMask.getMask();
+        copySource(rTR, source);
+        return;
     }
+
+    SourceHelper aSurface(rSourceBitmap);
+    cairo_surface_t* source = aSurface.getSurface();
     copySource(rTR, source);
 }
 
@@ -1120,6 +1151,8 @@ SalBitmap* SvpSalGraphics::getBitmap( long nX, long nY, long nWidth, long nHeigh
     cairo_destroy(cr);
     cairo_surface_destroy(target);
 
+    Toggle1BitTransparency(*pBitmap->GetBuffer());
+
     return pBitmap;
 }
 
@@ -1255,17 +1288,6 @@ bool SvpSalGraphics::drawEPS( long, long, long, long, void*, sal_uLong )
 
 namespace
 {
-    cairo_format_t getCairoFormat(const BitmapBuffer& rBuffer)
-    {
-        cairo_format_t nFormat;
-        assert(rBuffer.mnBitCount == 32 || rBuffer.mnBitCount == 1);
-        if (rBuffer.mnBitCount == 32)
-            nFormat = CAIRO_FORMAT_ARGB32;
-        else
-            nFormat = CAIRO_FORMAT_A1;
-        return nFormat;
-    }
-
     bool isCairoCompatible(const BitmapBuffer* pBuffer)
     {
         if (!pBuffer)


More information about the Libreoffice-commits mailing list