From aff8471dbffdd6d26e63533d7ffa8ddea6b2396b Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Thu, 21 May 2020 15:02:37 +0000 Subject: convert properly SkiaSalBitmap to WinSalBitmap (tdf#133152) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code didn't account for topdown bitmaps. Change-Id: Ia326834cfd6d2d022579fdde24828f7e0a8d8b3e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94643 Tested-by: Jenkins Reviewed-by: Luboš Luňák --- vcl/inc/skia/salbmp.hxx | 1 + vcl/win/gdi/salgdi2.cxx | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/vcl/inc/skia/salbmp.hxx b/vcl/inc/skia/salbmp.hxx index 7eb2a8eb72a6..0761217d4eb9 100644 --- a/vcl/inc/skia/salbmp.hxx +++ b/vcl/inc/skia/salbmp.hxx @@ -60,6 +60,7 @@ public: virtual bool InterpretAs8Bit() override; virtual bool ConvertToGreyscale() override; + const BitmapPalette& Palette() const { return mPalette; } // Returns the contents as SkImage (possibly GPU-backed). const sk_sp& GetSkImage() const; diff --git a/vcl/win/gdi/salgdi2.cxx b/vcl/win/gdi/salgdi2.cxx index 6ccf3140c169..fdac864d0f32 100644 --- a/vcl/win/gdi/salgdi2.cxx +++ b/vcl/win/gdi/salgdi2.cxx @@ -43,6 +43,7 @@ #include #if HAVE_FEATURE_SKIA #include +#include #endif @@ -113,6 +114,10 @@ void convertToWinSalBitmap(SalBitmap& rSalBitmap, WinSalBitmap& rWinSalBitmap) { aBitmapPalette = pGLSalBitmap->GetBitmapPalette(); } +#if HAVE_FEATURE_SKIA + if(SkiaSalBitmap* pSkiaSalBitmap = dynamic_cast(&rSalBitmap)) + aBitmapPalette = pSkiaSalBitmap->Palette(); +#endif BitmapBuffer* pRead = rSalBitmap.AcquireBuffer(BitmapAccessMode::Read); @@ -121,13 +126,19 @@ void convertToWinSalBitmap(SalBitmap& rSalBitmap, WinSalBitmap& rWinSalBitmap) sal_uInt8* pSource(pRead->mpBits); sal_uInt8* pDestination(pWrite->mpBits); + long readRowChange = pRead->mnScanlineSize; + if(pRead->mnFormat & ScanlineFormat::TopDown) + { + pSource += pRead->mnScanlineSize * (pRead->mnHeight - 1); + readRowChange = -readRowChange; + } std::unique_ptr pConverter; - if (pRead->mnFormat == ScanlineFormat::N24BitTcRgb) + if (RemoveScanline(pRead->mnFormat) == ScanlineFormat::N24BitTcRgb) pConverter.reset(new ColorScanlineConverter(ScanlineFormat::N24BitTcRgb, 3, pRead->mnScanlineSize)); - else if (pRead->mnFormat == ScanlineFormat::N32BitTcRgba) + else if (RemoveScanline(pRead->mnFormat) == ScanlineFormat::N32BitTcRgba) pConverter.reset(new ColorScanlineConverter(ScanlineFormat::N32BitTcRgba, 4, pRead->mnScanlineSize)); if (pConverter) @@ -135,7 +146,7 @@ void convertToWinSalBitmap(SalBitmap& rSalBitmap, WinSalBitmap& rWinSalBitmap) for (long y = 0; y < pRead->mnHeight; y++) { pConverter->convertScanline(pSource, pDestination); - pSource += pRead->mnScanlineSize; + pSource += readRowChange; pDestination += pWrite->mnScanlineSize; } } @@ -144,7 +155,7 @@ void convertToWinSalBitmap(SalBitmap& rSalBitmap, WinSalBitmap& rWinSalBitmap) for (long y = 0; y < pRead->mnHeight; y++) { memcpy(pDestination, pSource, pRead->mnScanlineSize); - pSource += pRead->mnScanlineSize; + pSource += readRowChange; pDestination += pWrite->mnScanlineSize; } } -- cgit