diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2017-12-09 16:28:42 -0500 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2017-12-18 11:23:46 +0100 |
commit | 31c044e2501b9d4a0917e4e09133660bbe2a24dc (patch) | |
tree | 7891b2d9509a584c750cecf6e501c3bb785885f5 /vcl | |
parent | dc3f0bde0bdef2a1e94055be146b433cb9fc54ba (diff) |
vcl-svp: add 24-bit (3-byte) RGB surface support to Cairo
Change-Id: I7707219eae4c2d6d40c8dc957207b63d3049a75f
(cherry picked from commit e8ba02b1d56dc7b59a4f0a7373995b28653a0597)
Reviewed-on: https://gerrit.libreoffice.org/46681
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/headless/svpgdi.cxx | 42 | ||||
-rw-r--r-- | vcl/inc/headless/svpgdi.hxx | 7 |
2 files changed, 35 insertions, 14 deletions
diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx index cd546ab5fdb1..e928961055c3 100644 --- a/vcl/headless/svpgdi.cxx +++ b/vcl/headless/svpgdi.cxx @@ -37,9 +37,9 @@ #include <cairo.h> #if ENABLE_CAIRO_CANVAS -#if defined CAIRO_VERSION && CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 10, 0) -# define CAIRO_OPERATOR_DIFFERENCE (static_cast<cairo_operator_t>(23)) -#endif +# if defined CAIRO_VERSION && CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 10, 0) +# define CAIRO_OPERATOR_DIFFERENCE (static_cast<cairo_operator_t>(23)) +# endif #endif namespace @@ -103,9 +103,18 @@ namespace cairo_format_t getCairoFormat(const BitmapBuffer& rBuffer) { cairo_format_t nFormat; +#ifdef HAVE_CAIRO_FORMAT_RGB24_888 + assert(rBuffer.mnBitCount == 32 || rBuffer.mnBitCount == 24 || rBuffer.mnBitCount == 1); +#else assert(rBuffer.mnBitCount == 32 || rBuffer.mnBitCount == 1); +#endif + if (rBuffer.mnBitCount == 32) nFormat = CAIRO_FORMAT_ARGB32; +#ifdef HAVE_CAIRO_FORMAT_RGB24_888 + else if (rBuffer.mnBitCount == 24) + nFormat = CAIRO_FORMAT_RGB24_888; +#endif else nFormat = CAIRO_FORMAT_A1; return nFormat; @@ -179,6 +188,15 @@ namespace { if ((SVP_CAIRO_FORMAT & ~ScanlineFormat::TopDown) == ScanlineFormat::N32BitTcRgba) { + assert((SVP_24BIT_FORMAT & ~ScanlineFormat::TopDown) == ScanlineFormat::N24BitTcRgb); + pD[0] = pS[0]; + pD[1] = pS[1]; + pD[2] = pS[2]; + pD[3] = 0xff; // Alpha + } + else if ((SVP_CAIRO_FORMAT & ~ScanlineFormat::TopDown) == ScanlineFormat::N32BitTcBgra) + { + assert((SVP_24BIT_FORMAT & ~ScanlineFormat::TopDown) == ScanlineFormat::N24BitTcBgr); pD[0] = pS[0]; pD[1] = pS[1]; pD[2] = pS[2]; @@ -186,18 +204,12 @@ namespace } else if ((SVP_CAIRO_FORMAT & ~ScanlineFormat::TopDown) == ScanlineFormat::N32BitTcArgb) { + assert((SVP_24BIT_FORMAT & ~ScanlineFormat::TopDown) == ScanlineFormat::N24BitTcRgb); pD[0] = 0xff; // Alpha pD[1] = pS[0]; pD[2] = pS[1]; pD[3] = pS[2]; } - else if ((SVP_CAIRO_FORMAT & ~ScanlineFormat::TopDown) == ScanlineFormat::N32BitTcBgra) - { - pD[0] = pS[2]; - pD[1] = pS[1]; - pD[2] = pS[0]; - pD[3] = 0xff; // Alpha - } else { assert(!"Unsupported SVP_CAIRO_FORMAT!"); @@ -217,7 +229,11 @@ namespace explicit SourceHelper(const SalBitmap& rSourceBitmap) { const SvpSalBitmap& rSrcBmp = static_cast<const SvpSalBitmap&>(rSourceBitmap); +#ifdef HAVE_CAIRO_FORMAT_RGB24_888 + if (rSrcBmp.GetBitCount() != 32 && rSrcBmp.GetBitCount() != 24) +#else if (rSrcBmp.GetBitCount() != 32) +#endif { //big stupid copy here static bool bWarnedOnce = false; @@ -1439,8 +1455,12 @@ namespace if (!pBuffer) return false; - // Cairo doesn't support 24-bit RGB; only ARGB with the alpha ignored. + // We use Cairo that supports 24-bit RGB. +#ifdef HAVE_CAIRO_FORMAT_RGB24_888 + if (pBuffer->mnBitCount != 32 && pBuffer->mnBitCount != 24 && pBuffer->mnBitCount != 1) +#else if (pBuffer->mnBitCount != 32 && pBuffer->mnBitCount != 1) +#endif return false; cairo_format_t nFormat = getCairoFormat(*pBuffer); diff --git a/vcl/inc/headless/svpgdi.hxx b/vcl/inc/headless/svpgdi.hxx index f092b0375822..27ebad049d16 100644 --- a/vcl/inc/headless/svpgdi.hxx +++ b/vcl/inc/headless/svpgdi.hxx @@ -38,19 +38,23 @@ //which is internal in that case, to swap the rgb components so that //cairo then matches the OpenGL GL_RGBA format so we can use it there //where we don't have GL_BGRA support. +// SVP_24BIT_FORMAT is used to store 24-bit images in 3-byte pixels to conserve memory. #if defined ANDROID +# define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcRgb | ScanlineFormat::TopDown) # define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcRgba | ScanlineFormat::TopDown) # define SVP_CAIRO_BLUE 1 # define SVP_CAIRO_GREEN 2 # define SVP_CAIRO_RED 0 # define SVP_CAIRO_ALPHA 3 #elif defined OSL_BIGENDIAN +# define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcRgb | ScanlineFormat::TopDown) # define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcArgb | ScanlineFormat::TopDown) # define SVP_CAIRO_BLUE 3 # define SVP_CAIRO_GREEN 2 # define SVP_CAIRO_RED 1 # define SVP_CAIRO_ALPHA 0 #else +# define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcBgr | ScanlineFormat::TopDown) # define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcBgra | ScanlineFormat::TopDown) # define SVP_CAIRO_BLUE 0 # define SVP_CAIRO_GREEN 1 @@ -58,9 +62,6 @@ # define SVP_CAIRO_ALPHA 3 #endif -// Used to store 24-bit images in 3-byte pixels to conserve memory. -#define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcRgb | ScanlineFormat::TopDown) - struct BitmapBuffer; class GlyphCache; class FreetypeFont; |