summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-12-28 14:09:55 +0900
committerTomaž Vajngerl <quikee@gmail.com>2022-01-04 06:56:16 +0100
commita2eb140692f2671c9b01c2a691ce73575e409a71 (patch)
treefb3bfb5e05370b4819dd28d646f36db9b8790d6e
parent5b185397198171bf8adaa99439931d12f42eff51 (diff)
vcl: move FastConvert24BitRgbTo32BitCairo to CairoCommon
Intermediate step beore moving bitmap related members. Change-Id: Ic0adff8ba8fadd0687ec903460e0caf7507e99b6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127846 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--vcl/headless/CairoCommon.cxx94
-rw-r--r--vcl/headless/svpgdi.cxx81
-rw-r--r--vcl/inc/headless/CairoCommon.hxx3
3 files changed, 97 insertions, 81 deletions
diff --git a/vcl/headless/CairoCommon.cxx b/vcl/headless/CairoCommon.cxx
index af4ee260c1c6..5316b88e699f 100644
--- a/vcl/headless/CairoCommon.cxx
+++ b/vcl/headless/CairoCommon.cxx
@@ -21,6 +21,7 @@
#include <dlfcn.h>
#include <vcl/BitmapTools.hxx>
#include <svdata.hxx>
+#include <tools/helpers.hxx>
#include <basegfx/utils/canvastools.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
@@ -1066,4 +1067,97 @@ cairo_surface_t* CairoCommon::createCairoSurface(const BitmapBuffer* pBuffer)
return target;
}
+std::unique_ptr<BitmapBuffer> FastConvert24BitRgbTo32BitCairo(const BitmapBuffer* pSrc)
+{
+ if (pSrc == nullptr)
+ return nullptr;
+
+ assert(pSrc->mnFormat == SVP_24BIT_FORMAT);
+ const tools::Long nWidth = pSrc->mnWidth;
+ const tools::Long nHeight = pSrc->mnHeight;
+ std::unique_ptr<BitmapBuffer> pDst(new BitmapBuffer);
+ pDst->mnFormat = (ScanlineFormat::N32BitTcArgb | ScanlineFormat::TopDown);
+ pDst->mnWidth = nWidth;
+ pDst->mnHeight = nHeight;
+ pDst->mnBitCount = 32;
+ pDst->maColorMask = pSrc->maColorMask;
+ pDst->maPalette = pSrc->maPalette;
+
+ tools::Long nScanlineBase;
+ const bool bFail = o3tl::checked_multiply<tools::Long>(pDst->mnBitCount, nWidth, nScanlineBase);
+ if (bFail)
+ {
+ SAL_WARN("vcl.gdi", "checked multiply failed");
+ pDst->mpBits = nullptr;
+ return nullptr;
+ }
+
+ pDst->mnScanlineSize = AlignedWidth4Bytes(nScanlineBase);
+ if (pDst->mnScanlineSize < nScanlineBase / 8)
+ {
+ SAL_WARN("vcl.gdi", "scanline calculation wraparound");
+ pDst->mpBits = nullptr;
+ return nullptr;
+ }
+
+ try
+ {
+ pDst->mpBits = new sal_uInt8[pDst->mnScanlineSize * nHeight];
+ }
+ catch (const std::bad_alloc&)
+ {
+ // memory exception, clean up
+ pDst->mpBits = nullptr;
+ return nullptr;
+ }
+
+ for (tools::Long y = 0; y < nHeight; ++y)
+ {
+ sal_uInt8* pS = pSrc->mpBits + y * pSrc->mnScanlineSize;
+ sal_uInt8* pD = pDst->mpBits + y * pDst->mnScanlineSize;
+ for (tools::Long x = 0; x < nWidth; ++x)
+ {
+#if defined(ANDROID) && !HAVE_FEATURE_ANDROID_LOK
+ static_assert((SVP_CAIRO_FORMAT & ~ScanlineFormat::TopDown)
+ == ScanlineFormat::N32BitTcRgba,
+ "Expected SVP_CAIRO_FORMAT set to N32BitTcBgra");
+ static_assert((SVP_24BIT_FORMAT & ~ScanlineFormat::TopDown)
+ == ScanlineFormat::N24BitTcRgb,
+ "Expected SVP_24BIT_FORMAT set to N24BitTcRgb");
+ pD[0] = pS[0];
+ pD[1] = pS[1];
+ pD[2] = pS[2];
+ pD[3] = 0xff; // Alpha
+#elif defined OSL_BIGENDIAN
+ static_assert((SVP_CAIRO_FORMAT & ~ScanlineFormat::TopDown)
+ == ScanlineFormat::N32BitTcArgb,
+ "Expected SVP_CAIRO_FORMAT set to N32BitTcBgra");
+ static_assert((SVP_24BIT_FORMAT & ~ScanlineFormat::TopDown)
+ == ScanlineFormat::N24BitTcRgb,
+ "Expected SVP_24BIT_FORMAT set to N24BitTcRgb");
+ pD[0] = 0xff; // Alpha
+ pD[1] = pS[0];
+ pD[2] = pS[1];
+ pD[3] = pS[2];
+#else
+ static_assert((SVP_CAIRO_FORMAT & ~ScanlineFormat::TopDown)
+ == ScanlineFormat::N32BitTcBgra,
+ "Expected SVP_CAIRO_FORMAT set to N32BitTcBgra");
+ static_assert((SVP_24BIT_FORMAT & ~ScanlineFormat::TopDown)
+ == ScanlineFormat::N24BitTcBgr,
+ "Expected SVP_24BIT_FORMAT set to N24BitTcBgr");
+ pD[0] = pS[0];
+ pD[1] = pS[1];
+ pD[2] = pS[2];
+ pD[3] = 0xff; // Alpha
+#endif
+
+ pS += 3;
+ pD += 4;
+ }
+ }
+
+ return pDst;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx
index 5b685178940b..25f385a8396a 100644
--- a/vcl/headless/svpgdi.cxx
+++ b/vcl/headless/svpgdi.cxx
@@ -72,87 +72,6 @@ namespace
}
}
- std::unique_ptr<BitmapBuffer> FastConvert24BitRgbTo32BitCairo(const BitmapBuffer* pSrc)
- {
- if (pSrc == nullptr)
- return nullptr;
-
- assert(pSrc->mnFormat == SVP_24BIT_FORMAT);
- const tools::Long nWidth = pSrc->mnWidth;
- const tools::Long nHeight = pSrc->mnHeight;
- std::unique_ptr<BitmapBuffer> pDst(new BitmapBuffer);
- pDst->mnFormat = (ScanlineFormat::N32BitTcArgb | ScanlineFormat::TopDown);
- pDst->mnWidth = nWidth;
- pDst->mnHeight = nHeight;
- pDst->mnBitCount = 32;
- pDst->maColorMask = pSrc->maColorMask;
- pDst->maPalette = pSrc->maPalette;
-
- tools::Long nScanlineBase;
- const bool bFail = o3tl::checked_multiply<tools::Long>(pDst->mnBitCount, nWidth, nScanlineBase);
- if (bFail)
- {
- SAL_WARN("vcl.gdi", "checked multiply failed");
- pDst->mpBits = nullptr;
- return nullptr;
- }
-
- pDst->mnScanlineSize = AlignedWidth4Bytes(nScanlineBase);
- if (pDst->mnScanlineSize < nScanlineBase/8)
- {
- SAL_WARN("vcl.gdi", "scanline calculation wraparound");
- pDst->mpBits = nullptr;
- return nullptr;
- }
-
- try
- {
- pDst->mpBits = new sal_uInt8[ pDst->mnScanlineSize * nHeight ];
- }
- catch (const std::bad_alloc&)
- {
- // memory exception, clean up
- pDst->mpBits = nullptr;
- return nullptr;
- }
-
- for (tools::Long y = 0; y < nHeight; ++y)
- {
- sal_uInt8* pS = pSrc->mpBits + y * pSrc->mnScanlineSize;
- sal_uInt8* pD = pDst->mpBits + y * pDst->mnScanlineSize;
- for (tools::Long x = 0; x < nWidth; ++x)
- {
-#if defined(ANDROID) && !HAVE_FEATURE_ANDROID_LOK
- static_assert((SVP_CAIRO_FORMAT & ~ScanlineFormat::TopDown) == ScanlineFormat::N32BitTcRgba, "Expected SVP_CAIRO_FORMAT set to N32BitTcBgra");
- static_assert((SVP_24BIT_FORMAT & ~ScanlineFormat::TopDown) == ScanlineFormat::N24BitTcRgb, "Expected SVP_24BIT_FORMAT set to N24BitTcRgb");
- pD[0] = pS[0];
- pD[1] = pS[1];
- pD[2] = pS[2];
- pD[3] = 0xff; // Alpha
-#elif defined OSL_BIGENDIAN
- static_assert((SVP_CAIRO_FORMAT & ~ScanlineFormat::TopDown) == ScanlineFormat::N32BitTcArgb, "Expected SVP_CAIRO_FORMAT set to N32BitTcBgra");
- static_assert((SVP_24BIT_FORMAT & ~ScanlineFormat::TopDown) == ScanlineFormat::N24BitTcRgb, "Expected SVP_24BIT_FORMAT set to N24BitTcRgb");
- pD[0] = 0xff; // Alpha
- pD[1] = pS[0];
- pD[2] = pS[1];
- pD[3] = pS[2];
-#else
- static_assert((SVP_CAIRO_FORMAT & ~ScanlineFormat::TopDown) == ScanlineFormat::N32BitTcBgra, "Expected SVP_CAIRO_FORMAT set to N32BitTcBgra");
- static_assert((SVP_24BIT_FORMAT & ~ScanlineFormat::TopDown) == ScanlineFormat::N24BitTcBgr, "Expected SVP_24BIT_FORMAT set to N24BitTcBgr");
- pD[0] = pS[0];
- pD[1] = pS[1];
- pD[2] = pS[2];
- pD[3] = 0xff; // Alpha
-#endif
-
- pS += 3;
- pD += 4;
- }
- }
-
- return pDst;
- }
-
// check for env var that decides for using downscale pattern
const char* pDisableDownScale(getenv("SAL_DISABLE_CAIRO_DOWNSCALE"));
bool bDisableDownScale(nullptr != pDisableDownScale);
diff --git a/vcl/inc/headless/CairoCommon.hxx b/vcl/inc/headless/CairoCommon.hxx
index 02dfcfa3ff0b..c79b2297e106 100644
--- a/vcl/inc/headless/CairoCommon.hxx
+++ b/vcl/inc/headless/CairoCommon.hxx
@@ -122,6 +122,9 @@ VCL_DLLPUBLIC void add_polygon_path(cairo_t* cr, const basegfx::B2DPolyPolygon&
VCL_DLLPUBLIC cairo_format_t getCairoFormat(const BitmapBuffer& rBuffer);
+VCL_DLLPUBLIC std::unique_ptr<BitmapBuffer>
+FastConvert24BitRgbTo32BitCairo(const BitmapBuffer* pSrc);
+
enum class PaintMode
{
Over,