diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-04-05 22:34:32 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-04-06 08:40:35 +0200 |
commit | e992f5c53aadbbfdf93a45f4011fc8733315585f (patch) | |
tree | 3f9d085b98465bc932b36db79f8a65343ee3954a /vcl/headless | |
parent | 615ceb107e9faf01b568b0a2440a3f09c8f88ca6 (diff) |
vcl: use PixelFormat enum in SalBitmap interface and backends
This changes all backends to use PixelFormat as the input to
the SalBitmap::Create method (and all the backends). This is the
first part as we need to make sure to also limit the use of
GetBitCount method and also use of it in SalGraphics.
Change-Id: I8d2b6adfcb8fe3dd78010538411f338c9a1c3996
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113603
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/headless')
-rw-r--r-- | vcl/headless/svpbmp.cxx | 44 | ||||
-rw-r--r-- | vcl/headless/svpgdi.cxx | 8 |
2 files changed, 26 insertions, 26 deletions
diff --git a/vcl/headless/svpbmp.cxx b/vcl/headless/svpbmp.cxx index 4524478078ac..29b85a1acf91 100644 --- a/vcl/headless/svpbmp.cxx +++ b/vcl/headless/svpbmp.cxx @@ -48,18 +48,9 @@ SvpSalBitmap::~SvpSalBitmap() static std::unique_ptr<BitmapBuffer> ImplCreateDIB( const Size& rSize, - sal_uInt16 nBitCount, + vcl::PixelFormat ePixelFormat, const BitmapPalette& rPal) { - assert( - (nBitCount == 0 - || nBitCount == 1 - || nBitCount == 4 - || nBitCount == 8 - || nBitCount == 24 - || nBitCount == 32) - && "Unsupported BitCount!"); - if (!rSize.Width() || !rSize.Height()) return nullptr; @@ -74,32 +65,35 @@ static std::unique_ptr<BitmapBuffer> ImplCreateDIB( return nullptr; } - const sal_uInt16 nColors = ( nBitCount <= 8 ) ? ( 1 << nBitCount ) : 0; - - switch (nBitCount) + switch (ePixelFormat) { - case 1: + case vcl::PixelFormat::N1_BPP: pDIB->mnFormat = ScanlineFormat::N1BitLsbPal; break; - case 8: + case vcl::PixelFormat::N8_BPP: pDIB->mnFormat = ScanlineFormat::N8BitPal; break; - case 24: + case vcl::PixelFormat::N24_BPP: pDIB->mnFormat = SVP_24BIT_FORMAT; break; - case 32: + case vcl::PixelFormat::N32_BPP: pDIB->mnFormat = SVP_CAIRO_FORMAT; break; - default: + case vcl::PixelFormat::INVALID: assert(false); pDIB->mnFormat = SVP_CAIRO_FORMAT; + break; } + sal_uInt16 nColors = 0; + if (ePixelFormat <= vcl::PixelFormat::N8_BPP) + nColors = vcl::numberOfColors(ePixelFormat); + pDIB->mnFormat |= ScanlineFormat::TopDown; pDIB->mnWidth = rSize.Width(); pDIB->mnHeight = rSize.Height(); tools::Long nScanlineBase; - bool bFail = o3tl::checked_multiply<tools::Long>(pDIB->mnWidth, nBitCount, nScanlineBase); + bool bFail = o3tl::checked_multiply<tools::Long>(pDIB->mnWidth, vcl::pixelFormatBitCount(ePixelFormat), nScanlineBase); if (bFail) { SAL_WARN("vcl.gdi", "checked multiply failed"); @@ -111,9 +105,9 @@ static std::unique_ptr<BitmapBuffer> ImplCreateDIB( SAL_WARN("vcl.gdi", "scanline calculation wraparound"); return nullptr; } - pDIB->mnBitCount = nBitCount; + pDIB->mnBitCount = vcl::pixelFormatBitCount(ePixelFormat); - if( nColors ) + if (nColors) { pDIB->maPalette = rPal; pDIB->maPalette.SetEntryCount( nColors ); @@ -155,10 +149,10 @@ void SvpSalBitmap::Create(std::unique_ptr<BitmapBuffer> pBuf) mpDIB = std::move(pBuf); } -bool SvpSalBitmap::Create(const Size& rSize, sal_uInt16 nBitCount, const BitmapPalette& rPal) +bool SvpSalBitmap::Create(const Size& rSize, vcl::PixelFormat ePixelFormat, const BitmapPalette& rPal) { Destroy(); - mpDIB = ImplCreateDIB( rSize, nBitCount, rPal ); + mpDIB = ImplCreateDIB(rSize, ePixelFormat, rPal); return mpDIB != nullptr; } @@ -201,8 +195,8 @@ bool SvpSalBitmap::Create( const SalBitmap& /*rSalBmp*/, return false; } -bool SvpSalBitmap::Create( const SalBitmap& /*rSalBmp*/, - sal_uInt16 /*nNewBitCount*/ ) +bool SvpSalBitmap::Create(const SalBitmap& /*rSalBmp*/, + vcl::PixelFormat /*eNewPixelFormat*/) { return false; } diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx index 67f3c9142567..9995d5a3b916 100644 --- a/vcl/headless/svpgdi.cxx +++ b/vcl/headless/svpgdi.cxx @@ -2261,14 +2261,20 @@ std::shared_ptr<SalBitmap> SvpSalGraphics::getBitmap( tools::Long nX, tools::Lon { std::shared_ptr<SvpSalBitmap> pBitmap = std::make_shared<SvpSalBitmap>(); BitmapPalette aPal; + vcl::PixelFormat ePixelFormat = vcl::PixelFormat::INVALID; if (GetBitCount() == 1) { + ePixelFormat = vcl::PixelFormat::N1_BPP; aPal.SetEntryCount(2); aPal[0] = COL_BLACK; aPal[1] = COL_WHITE; } + else + { + ePixelFormat = vcl::PixelFormat::N32_BPP; + } - if (!pBitmap->Create(Size(nWidth, nHeight), GetBitCount(), aPal)) + if (!pBitmap->Create(Size(nWidth, nHeight), ePixelFormat, aPal)) { SAL_WARN("vcl.gdi", "SvpSalGraphics::getBitmap, cannot create bitmap"); return nullptr; |