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

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