Kaydet (Commit) d148340b authored tarafından Caolán McNamara's avatar Caolán McNamara

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/40453Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 38df569a
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment