Blame SOURCES/0001-Resolves-rhbz-1467512-mask-not-created-as-1-bit-dept.patch

91334d
From 97406f8816b0c10d73f6070e07c8181242dc1596 Mon Sep 17 00:00:00 2001
91334d
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
91334d
Date: Fri, 7 Jul 2017 13:59:27 +0100
91334d
Subject: [PATCH] Resolves: rhbz#1467512 mask not created as 1 bit depth
91334d
MIME-Version: 1.0
91334d
Content-Type: text/plain; charset=UTF-8
91334d
Content-Transfer-Encoding: 8bit
91334d
91334d
Change-Id: Ib5bdd594efd41eb881dfc4e2454b72e4739ffd56
91334d
91334d
Resolves: tdf#104141 CAIRO_FORMAT_A1 vs N1BitLsbPal
91334d
91334d
where vcl transparency is the opposite of cairo's so we've been switching the
91334d
source color to the opposite for drawing on CAIRO_FORMAT_A1 and then sucking
91334d
out the bits "as-is" to give the right results.
91334d
91334d
Now instead use the right source color and toggle CAIRO_FORMAT_A1 bitmaps to
91334d
N1BitLsbPal in getBitmap.
91334d
91334d
Then additionally toggle all N1BitLsbPal bitmaps input to drawBitmap to
91334d
CAIRO_FORMAT_A1 when making a cairo surface from them.
91334d
91334d
Change-Id: I45c6d4f3894c6a22a07a3bd65950cd8070e8eaff
91334d
Reviewed-on: https://gerrit.libreoffice.org/40453
91334d
Tested-by: Jenkins <ci@libreoffice.org>
91334d
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
91334d
Tested-by: Caolán McNamara <caolanm@redhat.com>
91334d
91334d
Resolves: tdf#111483 1 bit bitmaps with non-standard black/white indexes
91334d
91334d
can be left "untoggled" when converted to cairo A1
91334d
91334d
Change-Id: I18f3e2109cd4b57bce584545090e26c931de1200
91334d
Reviewed-on: https://gerrit.libreoffice.org/41895
91334d
Tested-by: Jenkins <ci@libreoffice.org>
91334d
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
91334d
Tested-by: Caolán McNamara <caolanm@redhat.com>
91334d
91334d
Resolves: tdf#111073 incorrect gif background color
91334d
91334d
a) set correct palette entries for the 1bit bitmap returned
91334d
b) only use a BITMASK for the mask (like its AnimatedGraphicPrimitive2D
91334d
brother in drawinglayer does)
91334d
91334d
Change-Id: I704997de554dc4d0e523458d45ab329815b5046a
91334d
---
91334d
 slideshow/source/engine/shapes/gdimtftools.cxx |  2 +-
91334d
 vcl/headless/svpgdi.cxx                        | 76 +++++++++++++++++++-------
91334d
 2 files changed, 56 insertions(+), 22 deletions(-)
91334d
91334d
diff --git a/slideshow/source/engine/shapes/gdimtftools.cxx b/slideshow/source/engine/shapes/gdimtftools.cxx
91334d
index 6cd569e..efa4303 100644
91334d
--- a/slideshow/source/engine/shapes/gdimtftools.cxx
91334d
+++ b/slideshow/source/engine/shapes/gdimtftools.cxx
91334d
@@ -287,7 +287,7 @@ bool getAnimationFromGraphic( VectorOfMtfAnimationFrames&   o_rFrames,
91334d
     pVDev->EnableMapMode( false );
91334d
 
91334d
     // setup mask VDev (alpha VDev is currently rather slow)
91334d
-    ScopedVclPtrInstance< VirtualDevice > pVDevMask;
91334d
+    ScopedVclPtrInstance<VirtualDevice> pVDevMask(DeviceFormat::BITMASK);
91334d
     pVDevMask->SetOutputSizePixel( aAnimSize );
91334d
     pVDevMask->EnableMapMode( false );
91334d
 
91334d
diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx
91334d
index 1b49133..c40aad1 100644
91334d
--- a/vcl/headless/svpgdi.cxx
91334d
+++ b/vcl/headless/svpgdi.cxx
91334d
@@ -99,6 +99,30 @@ bool SvpSalGraphics::blendAlphaBitmap( const SalTwoRect&, const SalBitmap&, cons
91334d
 
91334d
 namespace
91334d
 {
91334d
+    cairo_format_t getCairoFormat(const BitmapBuffer& rBuffer)
91334d
+    {
91334d
+        cairo_format_t nFormat;
91334d
+        assert(rBuffer.mnBitCount == 32 || rBuffer.mnBitCount == 1);
91334d
+        if (rBuffer.mnBitCount == 32)
91334d
+            nFormat = CAIRO_FORMAT_ARGB32;
91334d
+        else
91334d
+            nFormat = CAIRO_FORMAT_A1;
91334d
+        return nFormat;
91334d
+    }
91334d
+
91334d
+    void Toggle1BitTransparency(const BitmapBuffer& rBuf)
91334d
+    {
91334d
+        assert(rBuf.maPalette.GetBestIndex(BitmapColor(Color(COL_BLACK))) == 0);
91334d
+        // TODO: make upper layers use standard alpha
91334d
+        if (getCairoFormat(rBuf) == CAIRO_FORMAT_A1)
91334d
+        {
91334d
+            const int nImageSize = rBuf.mnHeight * rBuf.mnScanlineSize;
91334d
+            unsigned char* pDst = rBuf.mpBits;
91334d
+            for (int i = nImageSize; --i >= 0; ++pDst)
91334d
+                *pDst = ~*pDst;
91334d
+        }
91334d
+    }
91334d
+
91334d
     class SourceHelper
91334d
     {
91334d
     public:
91334d
@@ -176,10 +200,14 @@ namespace
91334d
                 pAlphaBits = new unsigned char[nImageSize];
91334d
                 memcpy(pAlphaBits, pMaskBuf->mpBits, nImageSize);
91334d
 
91334d
-                // TODO: make upper layers use standard alpha
91334d
-                unsigned char* pDst = pAlphaBits;
91334d
-                for (int i = nImageSize; --i >= 0; ++pDst)
91334d
-                    *pDst = ~*pDst;
91334d
+                const sal_Int32 nBlackIndex = pMaskBuf->maPalette.GetBestIndex(BitmapColor(Color(COL_BLACK)));
91334d
+                if (nBlackIndex == 0)
91334d
+                {
91334d
+                    // TODO: make upper layers use standard alpha
91334d
+                    unsigned char* pDst = pAlphaBits;
91334d
+                    for (int i = nImageSize; --i >= 0; ++pDst)
91334d
+                        *pDst = ~*pDst;
91334d
+                }
91334d
 
91334d
                 mask = cairo_image_surface_create_for_data(pAlphaBits,
91334d
                                                 CAIRO_FORMAT_A1,
91334d
@@ -894,7 +922,7 @@ void SvpSalGraphics::applyColor(cairo_t *cr, SalColor aColor)
91334d
     }
91334d
     else
91334d
     {
91334d
-        double fSet = aColor == COL_BLACK ? 0.0 : 1.0;
91334d
+        double fSet = aColor == COL_BLACK ? 1.0 : 0.0;
91334d
         cairo_set_source_rgba(cr, 1, 1, 1, fSet);
91334d
         cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
91334d
     }
91334d
@@ -951,8 +979,12 @@ static basegfx::B2DRange renderSource(cairo_t* cr, const SalTwoRect& rTR,
91334d
     if (rTR.mnSrcWidth != 0 && rTR.mnSrcHeight != 0) {
91334d
         cairo_scale(cr, (double)(rTR.mnDestWidth)/rTR.mnSrcWidth, ((double)rTR.mnDestHeight)/rTR.mnSrcHeight);
91334d
     }
91334d
+
91334d
+    cairo_save(cr);
91334d
     cairo_set_source_surface(cr, source, -rTR.mnSrcX, -rTR.mnSrcY);
91334d
+    cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
91334d
     cairo_paint(cr);
91334d
+    cairo_restore(cr);
91334d
 
91334d
     return extents;
91334d
 }
91334d
@@ -1016,12 +1048,16 @@ void SvpSalGraphics::copyBits( const SalTwoRect& rTR,
91334d
 
91334d
 void SvpSalGraphics::drawBitmap(const SalTwoRect& rTR, const SalBitmap& rSourceBitmap)
91334d
 {
91334d
-    SourceHelper aSurface(rSourceBitmap);
91334d
-    cairo_surface_t* source = aSurface.getSurface();
91334d
-    if (!source)
91334d
+    if (rSourceBitmap.GetBitCount() == 1)
91334d
     {
91334d
-        SAL_WARN("vcl.gdi", "unsupported SvpSalGraphics::drawBitmap case");
91334d
+        MaskHelper aMask(rSourceBitmap);
91334d
+        cairo_surface_t* source = aMask.getMask();
91334d
+        copySource(rTR, source);
91334d
+        return;
91334d
     }
91334d
+
91334d
+    SourceHelper aSurface(rSourceBitmap);
91334d
+    cairo_surface_t* source = aSurface.getSurface();
91334d
     copySource(rTR, source);
91334d
 }
91334d
 
91334d
@@ -1107,7 +1143,14 @@ void SvpSalGraphics::drawMask( const SalTwoRect& rTR,
91334d
 SalBitmap* SvpSalGraphics::getBitmap( long nX, long nY, long nWidth, long nHeight )
91334d
 {
91334d
     SvpSalBitmap* pBitmap = new SvpSalBitmap();
91334d
-    pBitmap->Create(Size(nWidth, nHeight), 32, BitmapPalette());
91334d
+    BitmapPalette aPal;
91334d
+    if (GetBitCount() == 1)
91334d
+    {
91334d
+        aPal.SetEntryCount(2);
91334d
+        aPal[0] = Color(COL_BLACK);
91334d
+        aPal[1] = Color(COL_WHITE);
91334d
+    }
91334d
+    pBitmap->Create(Size(nWidth, nHeight), GetBitCount(), aPal);
91334d
 
91334d
     cairo_surface_t* target = SvpSalGraphics::createCairoSurface(pBitmap->GetBuffer());
91334d
     cairo_t* cr = cairo_create(target);
91334d
@@ -1118,6 +1161,8 @@ SalBitmap* SvpSalGraphics::getBitmap( long nX, long nY, long nWidth, long nHeigh
91334d
     cairo_destroy(cr);
91334d
     cairo_surface_destroy(target);
91334d
 
91334d
+    Toggle1BitTransparency(*pBitmap->GetBuffer());
91334d
+
91334d
     return pBitmap;
91334d
 }
91334d
 
91334d
@@ -1230,17 +1275,6 @@ bool SvpSalGraphics::drawEPS( long, long, long, long, void*, sal_uLong )
91334d
 
91334d
 namespace
91334d
 {
91334d
-    cairo_format_t getCairoFormat(const BitmapBuffer& rBuffer)
91334d
-    {
91334d
-        cairo_format_t nFormat;
91334d
-        assert(rBuffer.mnBitCount == 32 || rBuffer.mnBitCount == 1);
91334d
-        if (rBuffer.mnBitCount == 32)
91334d
-            nFormat = CAIRO_FORMAT_ARGB32;
91334d
-        else
91334d
-            nFormat = CAIRO_FORMAT_A1;
91334d
-        return nFormat;
91334d
-    }
91334d
-
91334d
     bool isCairoCompatible(const BitmapBuffer* pBuffer)
91334d
     {
91334d
         if (!pBuffer)
91334d
-- 
91334d
2.9.4
91334d