summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2017-07-26 14:37:40 +0100
committerCaolán McNamara <caolanm@redhat.com>2017-07-26 17:58:47 +0200
commitd148340babf6c973f7d463909d7a51e16c953248 (patch)
tree50e0196392d19c51704ade91d1f99924d9df70bb
parent38df569a66fb038b10c3d1d9890863592c0c29cc (diff)
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@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--vcl/headless/svpgdi.cxx54
1 files changed, 38 insertions, 16 deletions
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)