summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vcl/headless/svpbmp.cxx44
-rw-r--r--vcl/headless/svpgdi.cxx8
-rw-r--r--vcl/inc/headless/svpbmp.hxx10
-rw-r--r--vcl/inc/qt5/Qt5Bitmap.hxx4
-rw-r--r--vcl/inc/qt5/Qt5Tools.hxx13
-rw-r--r--vcl/inc/quartz/salbmp.h4
-rw-r--r--vcl/inc/salbmp.hxx5
-rw-r--r--vcl/inc/skia/salbmp.hxx4
-rw-r--r--vcl/inc/unx/salbmp.h6
-rw-r--r--vcl/inc/win/salbmp.h6
-rw-r--r--vcl/qa/cppunit/skia/skia.cxx2
-rw-r--r--vcl/qt5/Qt5Bitmap.cxx24
-rw-r--r--vcl/quartz/salbmp.cxx29
-rw-r--r--vcl/skia/salbmp.cxx27
-rw-r--r--vcl/source/bitmap/BitmapInfoAccess.cxx2
-rw-r--r--vcl/source/bitmap/bitmap.cxx4
-rw-r--r--vcl/unx/generic/gdi/gdiimpl.cxx9
-rw-r--r--vcl/unx/generic/gdi/salbmp.cxx44
-rw-r--r--vcl/win/gdi/gdiimpl.cxx2
-rw-r--r--vcl/win/gdi/salbmp.cxx33
-rw-r--r--vcl/win/gdi/salgdi2.cxx2
21 files changed, 147 insertions, 135 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;
diff --git a/vcl/inc/headless/svpbmp.hxx b/vcl/inc/headless/svpbmp.hxx
index 1551fc844a82..2c347372a4d4 100644
--- a/vcl/inc/headless/svpbmp.hxx
+++ b/vcl/inc/headless/svpbmp.hxx
@@ -33,14 +33,14 @@ public:
virtual ~SvpSalBitmap() override;
// SalBitmap
- virtual bool Create( const Size& rSize,
- sal_uInt16 nBitCount,
- const BitmapPalette& rPal ) override;
+ virtual bool Create(const Size& rSize,
+ vcl::PixelFormat ePixelFormat,
+ const BitmapPalette& rPalette) override;
virtual bool Create( const SalBitmap& rSalBmp ) override;
virtual bool Create( const SalBitmap& rSalBmp,
SalGraphics* pGraphics ) override;
- virtual bool Create( const SalBitmap& rSalBmp,
- sal_uInt16 nNewBitCount ) override;
+ virtual bool Create(const SalBitmap& rSalBmp,
+ vcl::PixelFormat eNewPixelFormat) override;
virtual bool Create( const css::uno::Reference< css::rendering::XBitmapCanvas >& rBitmapCanvas,
Size& rSize,
bool bMask = false ) override;
diff --git a/vcl/inc/qt5/Qt5Bitmap.hxx b/vcl/inc/qt5/Qt5Bitmap.hxx
index 201742ef39cd..d01966dab85b 100644
--- a/vcl/inc/qt5/Qt5Bitmap.hxx
+++ b/vcl/inc/qt5/Qt5Bitmap.hxx
@@ -37,11 +37,11 @@ public:
const QImage* GetQImage() const { return m_pImage.get(); }
- virtual bool Create(const Size& rSize, sal_uInt16 nBitCount,
+ virtual bool Create(const Size& rSize, vcl::PixelFormat ePixelFormat,
const BitmapPalette& rPal) override;
virtual bool Create(const SalBitmap& rSalBmp) override;
virtual bool Create(const SalBitmap& rSalBmp, SalGraphics* pGraphics) override;
- virtual bool Create(const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount) override;
+ virtual bool Create(const SalBitmap& rSalBmp, vcl::PixelFormat eNewPixelFormat) override;
virtual bool Create(const css::uno::Reference<css::rendering::XBitmapCanvas>& rBitmapCanvas,
Size& rSize, bool bMask = false) override;
virtual void Destroy() final override;
diff --git a/vcl/inc/qt5/Qt5Tools.hxx b/vcl/inc/qt5/Qt5Tools.hxx
index b7e4089e6f52..f9b73b30c7c7 100644
--- a/vcl/inc/qt5/Qt5Tools.hxx
+++ b/vcl/inc/qt5/Qt5Tools.hxx
@@ -29,6 +29,7 @@
#include <rtl/ustring.hxx>
#include <tools/color.hxx>
#include <tools/gen.hxx>
+#include <vcl/bitmap/BitmapTypes.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
@@ -99,17 +100,17 @@ inline QList<int> toQList(const css::uno::Sequence<sal_Int32>& aSequence)
constexpr QImage::Format Qt5_DefaultFormat32 = QImage::Format_ARGB32;
-inline QImage::Format getBitFormat(sal_uInt16 nBitCount)
+inline QImage::Format getBitFormat(vcl::PixelFormat ePixelFormat)
{
- switch (nBitCount)
+ switch (ePixelFormat)
{
- case 1:
+ case vcl::PixelFormat::N1_BPP:
return QImage::Format_Mono;
- case 8:
+ case vcl::PixelFormat::N8_BPP:
return QImage::Format_Indexed8;
- case 24:
+ case vcl::PixelFormat::N24_BPP:
return QImage::Format_RGB888;
- case 32:
+ case vcl::PixelFormat::N32_BPP:
return Qt5_DefaultFormat32;
default:
std::abort();
diff --git a/vcl/inc/quartz/salbmp.h b/vcl/inc/quartz/salbmp.h
index 87929249f787..8a9e94d043cc 100644
--- a/vcl/inc/quartz/salbmp.h
+++ b/vcl/inc/quartz/salbmp.h
@@ -57,10 +57,10 @@ public:
public:
// SalBitmap methods
- bool Create( const Size& rSize, sal_uInt16 nBitCount, const BitmapPalette& rPal ) override;
+ bool Create( const Size& rSize, vcl::PixelFormat ePixelFormat, const BitmapPalette& rPal ) override;
bool Create( const SalBitmap& rSalBmp ) override;
bool Create( const SalBitmap& rSalBmp, SalGraphics* pGraphics ) override;
- bool Create( const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount ) override;
+ bool Create( const SalBitmap& rSalBmp, vcl::PixelFormat eNewPixelFormat) override;
virtual bool Create( const css::uno::Reference< css::rendering::XBitmapCanvas >& rBitmapCanvas,
Size& rSize,
bool bMask = false ) override;
diff --git a/vcl/inc/salbmp.hxx b/vcl/inc/salbmp.hxx
index adbf70e5c17f..78d553b5194c 100644
--- a/vcl/inc/salbmp.hxx
+++ b/vcl/inc/salbmp.hxx
@@ -25,6 +25,7 @@
#include <vcl/checksum.hxx>
#include <vcl/BitmapAccessMode.hxx>
#include <vcl/BitmapBuffer.hxx>
+#include <vcl/bitmap/BitmapTypes.hxx>
#include <com/sun/star/rendering/XBitmapCanvas.hpp>
struct BitmapBuffer;
@@ -53,13 +54,13 @@ public:
virtual ~SalBitmap();
virtual bool Create( const Size& rSize,
- sal_uInt16 nBitCount,
+ vcl::PixelFormat ePixelFormat,
const BitmapPalette& rPal ) = 0;
virtual bool Create( const SalBitmap& rSalBmp ) = 0;
virtual bool Create( const SalBitmap& rSalBmp,
SalGraphics* pGraphics ) = 0;
virtual bool Create( const SalBitmap& rSalBmp,
- sal_uInt16 nNewBitCount ) = 0;
+ vcl::PixelFormat eNewPixelFormat) = 0;
virtual bool Create( const css::uno::Reference< css::rendering::XBitmapCanvas >& rBitmapCanvas,
Size& rSize,
bool bMask = false ) = 0;
diff --git a/vcl/inc/skia/salbmp.hxx b/vcl/inc/skia/salbmp.hxx
index 012594169132..bb8ae16f1c2e 100644
--- a/vcl/inc/skia/salbmp.hxx
+++ b/vcl/inc/skia/salbmp.hxx
@@ -36,11 +36,11 @@ public:
virtual ~SkiaSalBitmap() override;
// SalBitmap methods
- virtual bool Create(const Size& rSize, sal_uInt16 nBitCount,
+ virtual bool Create(const Size& rSize, vcl::PixelFormat ePixelFormat,
const BitmapPalette& rPal) override;
virtual bool Create(const SalBitmap& rSalBmp) override;
virtual bool Create(const SalBitmap& rSalBmp, SalGraphics* pGraphics) override;
- virtual bool Create(const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount) override;
+ virtual bool Create(const SalBitmap& rSalBmp, vcl::PixelFormat eNewPixelFormat) override;
virtual bool Create(const css::uno::Reference<css::rendering::XBitmapCanvas>& rBitmapCanvas,
Size& rSize, bool bMask = false) override;
diff --git a/vcl/inc/unx/salbmp.h b/vcl/inc/unx/salbmp.h
index 7f9f239d57b0..8b9e7c1cfc9f 100644
--- a/vcl/inc/unx/salbmp.h
+++ b/vcl/inc/unx/salbmp.h
@@ -41,7 +41,7 @@ private:
static std::unique_ptr<BitmapBuffer>
ImplCreateDIB(
const Size& rSize,
- sal_uInt16 nBitCount,
+ vcl::PixelFormat ePixelFormat,
const BitmapPalette& rPal
);
@@ -114,7 +114,7 @@ public:
// override pure virtual methods
virtual bool Create(
const Size& rSize,
- sal_uInt16 nBitCount,
+ vcl::PixelFormat ePixelFormat,
const BitmapPalette& rPal
) override;
@@ -126,7 +126,7 @@ public:
virtual bool Create(
const SalBitmap& rSalBmp,
- sal_uInt16 nNewBitCount
+ vcl::PixelFormat ePixelFormat
) override;
virtual bool Create(
diff --git a/vcl/inc/win/salbmp.h b/vcl/inc/win/salbmp.h
index bb589cc4b2f8..5167a7e4a939 100644
--- a/vcl/inc/win/salbmp.h
+++ b/vcl/inc/win/salbmp.h
@@ -52,7 +52,7 @@ public:
std::shared_ptr< Gdiplus::Bitmap > ImplGetGdiPlusBitmap(const WinSalBitmap* pAlphaSource = nullptr) const;
- static HGLOBAL ImplCreateDIB( const Size& rSize, sal_uInt16 nBitCount, const BitmapPalette& rPal );
+ static HGLOBAL ImplCreateDIB( const Size& rSize, vcl::PixelFormat ePixelFormat, const BitmapPalette& rPal );
static HANDLE ImplCopyDIBOrDDB( HANDLE hHdl, bool bDIB );
static sal_uInt16 ImplGetDIBColorCount( HGLOBAL hDIB );
static void ImplDecodeRLEBuffer( const BYTE* pSrcBuf, BYTE* pDstBuf,
@@ -66,10 +66,10 @@ public:
public:
bool Create( HANDLE hBitmap, bool bDIB, bool bCopyHandle );
- virtual bool Create( const Size& rSize, sal_uInt16 nBitCount, const BitmapPalette& rPal ) override;
+ virtual bool Create( const Size& rSize, vcl::PixelFormat ePixelFormat, const BitmapPalette& rPal ) override;
virtual bool Create( const SalBitmap& rSalBmpImpl ) override;
virtual bool Create( const SalBitmap& rSalBmpImpl, SalGraphics* pGraphics ) override;
- virtual bool Create( const SalBitmap& rSalBmpImpl, sal_uInt16 nNewBitCount ) override;
+ virtual bool Create( const SalBitmap& rSalBmpImpl, vcl::PixelFormat eNewPixelFormat ) override;
virtual bool Create( const css::uno::Reference< css::rendering::XBitmapCanvas >& rBitmapCanvas,
Size& rSize,
bool bMask = false ) override;
diff --git a/vcl/qa/cppunit/skia/skia.cxx b/vcl/qa/cppunit/skia/skia.cxx
index 67c1b4f274ef..549b7de7b16f 100644
--- a/vcl/qa/cppunit/skia/skia.cxx
+++ b/vcl/qa/cppunit/skia/skia.cxx
@@ -283,7 +283,7 @@ void SkiaTest::testBitmapCopyOnWrite()
if (!SkiaHelper::isVCLSkiaEnabled())
return;
SkiaSalBitmap bitmap;
- CPPUNIT_ASSERT(bitmap.Create(Size(10, 10), 24, BitmapPalette()));
+ CPPUNIT_ASSERT(bitmap.Create(Size(10, 10), vcl::PixelFormat::N24_BPP, BitmapPalette()));
bitmap.GetSkImage();
bitmap.GetAlphaSkImage();
CPPUNIT_ASSERT(bitmap.unittestHasBuffer());
diff --git a/vcl/qt5/Qt5Bitmap.cxx b/vcl/qt5/Qt5Bitmap.cxx
index a9ea1f707431..6e8921294def 100644
--- a/vcl/qt5/Qt5Bitmap.cxx
+++ b/vcl/qt5/Qt5Bitmap.cxx
@@ -33,23 +33,22 @@ Qt5Bitmap::Qt5Bitmap() {}
Qt5Bitmap::Qt5Bitmap(const QImage& rImage) { m_pImage.reset(new QImage(rImage)); }
-bool Qt5Bitmap::Create(const Size& rSize, sal_uInt16 nBitCount, const BitmapPalette& rPal)
+bool Qt5Bitmap::Create(const Size& rSize, vcl::PixelFormat ePixelFormat, const BitmapPalette& rPal)
{
- assert(
- (nBitCount == 1 || nBitCount == 4 || nBitCount == 8 || nBitCount == 24 || nBitCount == 32)
- && "Unsupported BitCount!");
+ if (ePixelFormat == vcl::PixelFormat::INVALID)
+ return false;
- if (nBitCount == 1)
+ if (ePixelFormat == vcl::PixelFormat::N1_BPP)
assert(2 >= rPal.GetEntryCount());
- if (nBitCount == 8)
+ if (ePixelFormat == vcl::PixelFormat::N8_BPP)
assert(256 >= rPal.GetEntryCount());
- m_pImage.reset(new QImage(toQSize(rSize), getBitFormat(nBitCount)));
+ m_pImage.reset(new QImage(toQSize(rSize), getBitFormat(ePixelFormat)));
m_pImage->fill(Qt::transparent);
m_aPalette = rPal;
auto count = rPal.GetEntryCount();
- if (nBitCount != 4 && count && m_pImage)
+ if (count && m_pImage)
{
QVector<QRgb> aColorTable(count);
for (unsigned i = 0; i < count; ++i)
@@ -76,13 +75,12 @@ bool Qt5Bitmap::Create(const SalBitmap& rSalBmp, SalGraphics* pSalGraphics)
return true;
}
-bool Qt5Bitmap::Create(const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount)
+bool Qt5Bitmap::Create(const SalBitmap& rSalBmp, vcl::PixelFormat eNewPixelFormat)
{
- assert((nNewBitCount == 1 || nNewBitCount == 8 || nNewBitCount == 24 || nNewBitCount == 32)
- && "Unsupported BitCount!");
-
+ if (eNewPixelFormat == vcl::PixelFormat::INVALID)
+ return false;
const Qt5Bitmap* pBitmap = static_cast<const Qt5Bitmap*>(&rSalBmp);
- m_pImage.reset(new QImage(pBitmap->m_pImage->convertToFormat(getBitFormat(nNewBitCount))));
+ m_pImage.reset(new QImage(pBitmap->m_pImage->convertToFormat(getBitFormat(eNewPixelFormat))));
return true;
}
diff --git a/vcl/quartz/salbmp.cxx b/vcl/quartz/salbmp.cxx
index 1b9a777616de..72c0b8d5634f 100644
--- a/vcl/quartz/salbmp.cxx
+++ b/vcl/quartz/salbmp.cxx
@@ -48,12 +48,6 @@ const unsigned long k32BitRedColorMask = 0x00ff0000;
const unsigned long k32BitGreenColorMask = 0x0000ff00;
const unsigned long k32BitBlueColorMask = 0x000000ff;
-static bool isValidBitCount( sal_uInt16 nBitCount )
-{
- return (nBitCount == 1) || (nBitCount == 4) || (nBitCount == 8) ||
- (nBitCount == 24) || (nBitCount == 32);
-}
-
QuartzSalBitmap::QuartzSalBitmap()
: mxCachedImage( nullptr )
, mnBits(0)
@@ -68,13 +62,13 @@ QuartzSalBitmap::~QuartzSalBitmap()
doDestroy();
}
-bool QuartzSalBitmap::Create( const Size& rSize, sal_uInt16 nBits, const BitmapPalette& rBitmapPalette )
+bool QuartzSalBitmap::Create( const Size& rSize, vcl::PixelFormat ePixelFormat, const BitmapPalette& rBitmapPalette )
{
- if( !isValidBitCount( nBits ) )
+ if (ePixelFormat == vcl::PixelFormat::INVALID)
return false;
maPalette = rBitmapPalette;
- mnBits = nBits;
+ mnBits = vcl::pixelFormatBitCount(ePixelFormat);
mnWidth = rSize.Width();
mnHeight = rSize.Height();
return AllocateUserData();
@@ -82,21 +76,28 @@ bool QuartzSalBitmap::Create( const Size& rSize, sal_uInt16 nBits, const BitmapP
bool QuartzSalBitmap::Create( const SalBitmap& rSalBmp )
{
- return Create( rSalBmp, rSalBmp.GetBitCount() );
+ vcl::PixelFormat ePixelFormat = vcl::bitDepthToPixelFormat(rSalBmp.GetBitCount());
+ return Create( rSalBmp, ePixelFormat);
}
bool QuartzSalBitmap::Create( const SalBitmap& rSalBmp, SalGraphics* pGraphics )
{
- return Create( rSalBmp, pGraphics ? pGraphics->GetBitCount() : rSalBmp.GetBitCount() );
+ vcl::PixelFormat ePixelFormat = vcl::PixelFormat::INVALID;
+ if (pGraphics)
+ ePixelFormat = vcl::bitDepthToPixelFormat(pGraphics->GetBitCount());
+ else
+ ePixelFormat = vcl::bitDepthToPixelFormat(rSalBmp.GetBitCount());
+
+ return Create( rSalBmp, ePixelFormat);
}
-bool QuartzSalBitmap::Create( const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount )
+bool QuartzSalBitmap::Create( const SalBitmap& rSalBmp, vcl::PixelFormat eNewPixelFormat )
{
const QuartzSalBitmap& rSourceBitmap = static_cast<const QuartzSalBitmap&>(rSalBmp);
- if (isValidBitCount(nNewBitCount) && rSourceBitmap.m_pUserBuffer)
+ if (eNewPixelFormat != vcl::PixelFormat::INVALID && rSourceBitmap.m_pUserBuffer)
{
- mnBits = nNewBitCount;
+ mnBits = vcl::pixelFormatBitCount(eNewPixelFormat);
mnWidth = rSourceBitmap.mnWidth;
mnHeight = rSourceBitmap.mnHeight;
maPalette = rSourceBitmap.maPalette;
diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx
index f9e17eed1b79..1302a3532afb 100644
--- a/vcl/skia/salbmp.cxx
+++ b/vcl/skia/salbmp.cxx
@@ -56,12 +56,6 @@ SkiaSalBitmap::SkiaSalBitmap() {}
SkiaSalBitmap::~SkiaSalBitmap() {}
-static bool isValidBitCount(sal_uInt16 nBitCount)
-{
- return (nBitCount == 1) || (nBitCount == 4) || (nBitCount == 8) || (nBitCount == 24)
- || (nBitCount == 32);
-}
-
SkiaSalBitmap::SkiaSalBitmap(const sk_sp<SkImage>& image)
{
ResetAllData();
@@ -77,14 +71,15 @@ SkiaSalBitmap::SkiaSalBitmap(const sk_sp<SkImage>& image)
SAL_INFO("vcl.skia.trace", "bitmapfromimage(" << this << ")");
}
-bool SkiaSalBitmap::Create(const Size& rSize, sal_uInt16 nBitCount, const BitmapPalette& rPal)
+bool SkiaSalBitmap::Create(const Size& rSize, vcl::PixelFormat ePixelFormat,
+ const BitmapPalette& rPal)
{
assert(mAnyAccessCount == 0);
ResetAllData();
- if (!isValidBitCount(nBitCount))
+ if (ePixelFormat == vcl::PixelFormat::INVALID)
return false;
mPalette = rPal;
- mBitCount = nBitCount;
+ mBitCount = vcl::pixelFormatBitCount(ePixelFormat);
mSize = rSize;
ResetPendingScaling();
if (!ComputeScanlineSize())
@@ -142,15 +137,21 @@ void SkiaSalBitmap::CreateBitmapData()
bool SkiaSalBitmap::Create(const SalBitmap& rSalBmp)
{
- return Create(rSalBmp, rSalBmp.GetBitCount());
+ return Create(rSalBmp, vcl::bitDepthToPixelFormat(rSalBmp.GetBitCount()));
}
bool SkiaSalBitmap::Create(const SalBitmap& rSalBmp, SalGraphics* pGraphics)
{
- return Create(rSalBmp, pGraphics ? pGraphics->GetBitCount() : rSalBmp.GetBitCount());
+ auto ePixelFormat = vcl::PixelFormat::INVALID;
+ if (pGraphics)
+ ePixelFormat = vcl::bitDepthToPixelFormat(pGraphics->GetBitCount());
+ else
+ ePixelFormat = vcl::bitDepthToPixelFormat(rSalBmp.GetBitCount());
+
+ return Create(rSalBmp, ePixelFormat);
}
-bool SkiaSalBitmap::Create(const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount)
+bool SkiaSalBitmap::Create(const SalBitmap& rSalBmp, vcl::PixelFormat eNewPixelFormat)
{
assert(mAnyAccessCount == 0);
const SkiaSalBitmap& src = static_cast<const SkiaSalBitmap&>(rSalBmp);
@@ -165,7 +166,7 @@ bool SkiaSalBitmap::Create(const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount)
mScaleQuality = src.mScaleQuality;
mEraseColorSet = src.mEraseColorSet;
mEraseColor = src.mEraseColor;
- if (nNewBitCount != src.GetBitCount())
+ if (vcl::pixelFormatBitCount(eNewPixelFormat) != src.GetBitCount())
{
// This appears to be unused(?). Implement this just in case, but be lazy
// about it and rely on EnsureBitmapData() doing the conversion from mImage
diff --git a/vcl/source/bitmap/BitmapInfoAccess.cxx b/vcl/source/bitmap/BitmapInfoAccess.cxx
index 1914755cc692..595d5cbbbcc5 100644
--- a/vcl/source/bitmap/BitmapInfoAccess.cxx
+++ b/vcl/source/bitmap/BitmapInfoAccess.cxx
@@ -49,7 +49,7 @@ BitmapInfoAccess::BitmapInfoAccess(Bitmap& rBitmap, BitmapAccessMode nMode)
if (!mpBuffer)
{
std::shared_ptr<SalBitmap> xNewImpBmp(ImplGetSVData()->mpDefInst->CreateSalBitmap());
- if (xNewImpBmp->Create(*xImpBmp, vcl::pixelFormatBitCount(rBitmap.getPixelFormat())))
+ if (xNewImpBmp->Create(*xImpBmp, rBitmap.getPixelFormat()))
{
xImpBmp = xNewImpBmp;
rBitmap.ImplSetSalBitmap(xImpBmp);
diff --git a/vcl/source/bitmap/bitmap.cxx b/vcl/source/bitmap/bitmap.cxx
index 592ae0b213fe..656e9bd15528 100644
--- a/vcl/source/bitmap/bitmap.cxx
+++ b/vcl/source/bitmap/bitmap.cxx
@@ -132,7 +132,7 @@ Bitmap::Bitmap( const Size& rSizePixel, vcl::PixelFormat ePixelFormat, const Bit
}
mxSalBmp = ImplGetSVData()->mpDefInst->CreateSalBitmap();
- mxSalBmp->Create( rSizePixel, sal_uInt16(ePixelFormat), pRealPal ? *pRealPal : aPal );
+ mxSalBmp->Create(rSizePixel, ePixelFormat, pRealPal ? *pRealPal : aPal);
}
#ifdef DBG_UTIL
@@ -380,7 +380,7 @@ BitmapChecksum Bitmap::GetChecksum() const
// so, we need to update the imp bitmap for this bitmap instance
// as we do in BitmapInfoAccess::ImplCreate
std::shared_ptr<SalBitmap> xNewImpBmp(ImplGetSVData()->mpDefInst->CreateSalBitmap());
- if (xNewImpBmp->Create(*mxSalBmp, vcl::pixelFormatBitCount(getPixelFormat())))
+ if (xNewImpBmp->Create(*mxSalBmp, getPixelFormat()))
{
Bitmap* pThis = const_cast<Bitmap*>(this);
pThis->mxSalBmp = xNewImpBmp;
diff --git a/vcl/unx/generic/gdi/gdiimpl.cxx b/vcl/unx/generic/gdi/gdiimpl.cxx
index 5838c1aef978..60cadef1ba0d 100644
--- a/vcl/unx/generic/gdi/gdiimpl.cxx
+++ b/vcl/unx/generic/gdi/gdiimpl.cxx
@@ -1945,14 +1945,21 @@ std::shared_ptr<SalBitmap> X11SalGraphicsImpl::getBitmap( tools::Long nX, tools:
std::shared_ptr<X11SalBitmap> pSalBitmap = std::make_shared<X11SalBitmap>();
sal_uInt16 nBitCount = GetBitCount();
+ vcl::PixelFormat ePixelFormat = vcl::bitDepthToPixelFormat(nBitCount);
if( &mrParent.GetDisplay()->GetColormap( mrParent.m_nXScreen ) != &mrParent.GetColormap() )
+ {
+ ePixelFormat = vcl::PixelFormat::N1_BPP;
nBitCount = 1;
+ }
+
+ if (nBitCount > 8)
+ ePixelFormat = vcl::PixelFormat::N24_BPP;
if( ! bFakeWindowBG )
pSalBitmap->ImplCreateFromDrawable( mrParent.GetDrawable(), mrParent.m_nXScreen, nBitCount, nX, nY, nDX, nDY );
else
- pSalBitmap->Create( Size( nDX, nDY ), (nBitCount > 8) ? 24 : nBitCount, BitmapPalette( nBitCount > 8 ? nBitCount : 0 ) );
+ pSalBitmap->Create( Size( nDX, nDY ), ePixelFormat, BitmapPalette( nBitCount > 8 ? nBitCount : 0 ) );
return pSalBitmap;
}
diff --git a/vcl/unx/generic/gdi/salbmp.cxx b/vcl/unx/generic/gdi/salbmp.cxx
index 4579fcfe7bdf..c73b40146eee 100644
--- a/vcl/unx/generic/gdi/salbmp.cxx
+++ b/vcl/unx/generic/gdi/salbmp.cxx
@@ -119,17 +119,9 @@ namespace
std::unique_ptr<BitmapBuffer> X11SalBitmap::ImplCreateDIB(
const Size& rSize,
- sal_uInt16 nBitCount,
+ vcl::PixelFormat ePixelFormat,
const BitmapPalette& rPal)
{
- DBG_ASSERT(
- nBitCount == 1
- || nBitCount == 4
- || nBitCount == 8
- || nBitCount == 24
- , "Unsupported BitCount!"
- );
-
std::unique_ptr<BitmapBuffer> pDIB;
if( !rSize.Width() || !rSize.Height() )
@@ -144,27 +136,35 @@ std::unique_ptr<BitmapBuffer> X11SalBitmap::ImplCreateDIB(
return nullptr;
}
- const sal_uInt16 nColors = ( nBitCount <= 8 ) ? ( 1 << nBitCount ) : 0;
-
pDIB->mnFormat = ScanlineFormat::NONE;
- switch( nBitCount )
+ switch(ePixelFormat)
{
- case 1: pDIB->mnFormat |= ScanlineFormat::N1BitMsbPal; break;
- case 8: pDIB->mnFormat |= ScanlineFormat::N8BitPal; break;
- case 24: pDIB->mnFormat |= ScanlineFormat::N24BitTcBgr; break;
- case 4: assert(false); break;
+ case vcl::PixelFormat::N1_BPP:
+ pDIB->mnFormat |= ScanlineFormat::N1BitMsbPal;
+ break;
+ case vcl::PixelFormat::N8_BPP:
+ pDIB->mnFormat |= ScanlineFormat::N8BitPal;
+ break;
+ case vcl::PixelFormat::N24_BPP:
+ pDIB->mnFormat |= ScanlineFormat::N24BitTcBgr;
+ break;
+ case vcl::PixelFormat::N32_BPP:
default:
SAL_WARN("vcl.gdi", "32-bit images not supported, converting to 24-bit");
- nBitCount = 24;
+ ePixelFormat = vcl::PixelFormat::N24_BPP;
pDIB->mnFormat |= ScanlineFormat::N24BitTcBgr;
break;
}
+ sal_uInt16 nColors = 0;
+ if (ePixelFormat <= vcl::PixelFormat::N8_BPP)
+ nColors = vcl::numberOfColors(ePixelFormat);
+
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");
@@ -176,7 +176,7 @@ std::unique_ptr<BitmapBuffer> X11SalBitmap::ImplCreateDIB(
SAL_WARN("vcl.gdi", "scanline calculation wraparound");
return nullptr;
}
- pDIB->mnBitCount = nBitCount;
+ pDIB->mnBitCount = vcl::pixelFormatBitCount(ePixelFormat);
if( nColors )
{
@@ -616,10 +616,10 @@ void X11SalBitmap::ImplDraw(
mpDDB->ImplDraw( aDrawable, rTwoRect, rGC );
}
-bool X11SalBitmap::Create( const Size& rSize, sal_uInt16 nBitCount, const BitmapPalette& rPal )
+bool X11SalBitmap::Create( const Size& rSize, vcl::PixelFormat ePixelFormat, const BitmapPalette& rPal )
{
Destroy();
- mpDIB = ImplCreateDIB( rSize, nBitCount, rPal );
+ mpDIB = ImplCreateDIB( rSize, ePixelFormat, rPal );
return( mpDIB != nullptr );
}
@@ -670,7 +670,7 @@ bool X11SalBitmap::Create( const SalBitmap&, SalGraphics* )
return false;
}
-bool X11SalBitmap::Create( const SalBitmap&, sal_uInt16 )
+bool X11SalBitmap::Create(const SalBitmap&, vcl::PixelFormat /*eNewPixelFormat*/)
{
return false;
}
diff --git a/vcl/win/gdi/gdiimpl.cxx b/vcl/win/gdi/gdiimpl.cxx
index 2da6be7d6847..d67e04be765f 100644
--- a/vcl/win/gdi/gdiimpl.cxx
+++ b/vcl/win/gdi/gdiimpl.cxx
@@ -546,7 +546,7 @@ void ImplDrawBitmap( HDC hDC, const SalTwoRect& rPosAry, const WinSalBitmap& rSa
if( bPrintDDB )
{
xTmpSalBmp.reset(new WinSalBitmap);
- xTmpSalBmp->Create( rSalBitmap, rSalBitmap.GetBitCount() );
+ xTmpSalBmp->Create(rSalBitmap, vcl::bitDepthToPixelFormat(rSalBitmap.GetBitCount()));
hDrawDIB = xTmpSalBmp->ImplGethDIB();
}
else
diff --git a/vcl/win/gdi/salbmp.cxx b/vcl/win/gdi/salbmp.cxx
index 67ce7b381536..387a2e6e2d99 100644
--- a/vcl/win/gdi/salbmp.cxx
+++ b/vcl/win/gdi/salbmp.cxx
@@ -243,7 +243,7 @@ std::shared_ptr<Gdiplus::Bitmap> WinSalBitmap::ImplCreateGdiPlusBitmap()
{
// we need DIB for success with AcquireBuffer, create a replacement WinSalBitmap
pExtraWinSalRGB.reset(new WinSalBitmap());
- pExtraWinSalRGB->Create(*pSalRGB, pSalRGB->GetBitCount());
+ pExtraWinSalRGB->Create(*pSalRGB, vcl::bitDepthToPixelFormat(pSalRGB->GetBitCount()));
pSalRGB = pExtraWinSalRGB.get();
}
@@ -325,7 +325,7 @@ std::shared_ptr<Gdiplus::Bitmap> WinSalBitmap::ImplCreateGdiPlusBitmap(const Win
{
// we need DIB for success with AcquireBuffer, create a replacement WinSalBitmap
pExtraWinSalRGB.reset(new WinSalBitmap());
- pExtraWinSalRGB->Create(*pSalRGB, pSalRGB->GetBitCount());
+ pExtraWinSalRGB->Create(*pSalRGB, vcl::bitDepthToPixelFormat(pSalRGB->GetBitCount()));
pSalRGB = pExtraWinSalRGB.get();
}
@@ -352,7 +352,7 @@ std::shared_ptr<Gdiplus::Bitmap> WinSalBitmap::ImplCreateGdiPlusBitmap(const Win
{
// we need DIB for success with AcquireBuffer, create a replacement WinSalBitmap
pExtraWinSalA.reset(new WinSalBitmap());
- pExtraWinSalA->Create(*pSalA, pSalA->GetBitCount());
+ pExtraWinSalA->Create(*pSalA, vcl::bitDepthToPixelFormat(pSalA->GetBitCount()));
pSalA = pExtraWinSalA.get();
}
@@ -508,16 +508,16 @@ bool WinSalBitmap::Create( HANDLE hBitmap, bool bDIB, bool bCopyHandle )
return bRet;
}
-bool WinSalBitmap::Create( const Size& rSize, sal_uInt16 nBitCount, const BitmapPalette& rPal )
+bool WinSalBitmap::Create(const Size& rSize, vcl::PixelFormat ePixelFormat, const BitmapPalette& rPal)
{
bool bRet = false;
- mhDIB = ImplCreateDIB( rSize, nBitCount, rPal );
+ mhDIB = ImplCreateDIB(rSize, ePixelFormat, rPal);
if( mhDIB )
{
maSize = rSize;
- mnBitCount = nBitCount;
+ mnBitCount = vcl::pixelFormatBitCount(ePixelFormat);
bRet = true;
}
@@ -594,7 +594,7 @@ bool WinSalBitmap::Create( const SalBitmap& rSSalBmp, SalGraphics* pSGraphics )
return bRet;
}
-bool WinSalBitmap::Create( const SalBitmap& rSSalBmp, sal_uInt16 nNewBitCount )
+bool WinSalBitmap::Create(const SalBitmap& rSSalBmp, vcl::PixelFormat eNewPixelFormat)
{
bool bRet = false;
@@ -602,7 +602,7 @@ bool WinSalBitmap::Create( const SalBitmap& rSSalBmp, sal_uInt16 nNewBitCount )
if( rSalBmp.mhDDB )
{
- mhDIB = ImplCreateDIB( rSalBmp.maSize, nNewBitCount, BitmapPalette() );
+ mhDIB = ImplCreateDIB( rSalBmp.maSize, eNewPixelFormat, BitmapPalette() );
if( mhDIB )
{
@@ -624,7 +624,7 @@ bool WinSalBitmap::Create( const SalBitmap& rSSalBmp, sal_uInt16 nNewBitCount )
{
GlobalUnlock( mhDIB );
maSize = rSalBmp.maSize;
- mnBitCount = nNewBitCount;
+ mnBitCount = vcl::pixelFormatBitCount(eNewPixelFormat);
bRet = true;
}
else
@@ -690,24 +690,27 @@ sal_uInt16 WinSalBitmap::ImplGetDIBColorCount( HGLOBAL hDIB )
return nColors;
}
-HGLOBAL WinSalBitmap::ImplCreateDIB( const Size& rSize, sal_uInt16 nBits, const BitmapPalette& rPal )
+HGLOBAL WinSalBitmap::ImplCreateDIB(const Size& rSize, vcl::PixelFormat ePixelFormat, const BitmapPalette& rPal)
{
- SAL_WARN_IF( nBits != 1 && nBits != 4 && nBits != 8 && nBits != 24, "vcl", "Unsupported BitCount!" );
-
HGLOBAL hDIB = nullptr;
if( rSize.IsEmpty() )
return hDIB;
+ const auto nBits = vcl::pixelFormatBitCount(ePixelFormat);
+
// calculate bitmap size in Bytes
- const sal_uLong nAlignedWidth4Bytes = AlignedWidth4Bytes( nBits * rSize.Width() );
+ const sal_uLong nAlignedWidth4Bytes = AlignedWidth4Bytes(nBits * rSize.Width());
const sal_uLong nImageSize = nAlignedWidth4Bytes * rSize.Height();
bool bOverflow = (nImageSize / nAlignedWidth4Bytes) != static_cast<sal_uLong>(rSize.Height());
if( bOverflow )
return hDIB;
// allocate bitmap memory including header and palette
- const sal_uInt16 nColors = (nBits <= 8) ? (1 << nBits) : 0;
+ sal_uInt16 nColors = 0;
+ if (ePixelFormat <= vcl::PixelFormat::N8_BPP)
+ nColors = vcl::numberOfColors(ePixelFormat);
+
const sal_uLong nHeaderSize = sizeof( BITMAPINFOHEADER ) + nColors * sizeof( RGBQUAD );
bOverflow = (nHeaderSize + nImageSize) < nImageSize;
if( bOverflow )
@@ -801,7 +804,7 @@ BitmapBuffer* WinSalBitmap::AcquireBuffer( BitmapAccessMode /*nMode*/ )
if( ( pBIH->biCompression == BI_RLE4 ) || ( pBIH->biCompression == BI_RLE8 ) )
{
Size aSizePix( pBIH->biWidth, pBIH->biHeight );
- HGLOBAL hNewDIB = ImplCreateDIB( aSizePix, pBIH->biBitCount, BitmapPalette() );
+ HGLOBAL hNewDIB = ImplCreateDIB(aSizePix, vcl::bitDepthToPixelFormat(pBIH->biBitCount), BitmapPalette());
if( hNewDIB )
{
diff --git a/vcl/win/gdi/salgdi2.cxx b/vcl/win/gdi/salgdi2.cxx
index 1d2c03526dbc..409fcc74bd82 100644
--- a/vcl/win/gdi/salgdi2.cxx
+++ b/vcl/win/gdi/salgdi2.cxx
@@ -113,7 +113,7 @@ void convertToWinSalBitmap(SalBitmap& rSalBitmap, WinSalBitmap& rWinSalBitmap)
BitmapBuffer* pRead = rSalBitmap.AcquireBuffer(BitmapAccessMode::Read);
- rWinSalBitmap.Create(rSalBitmap.GetSize(), rSalBitmap.GetBitCount(), aBitmapPalette);
+ rWinSalBitmap.Create(rSalBitmap.GetSize(), vcl::bitDepthToPixelFormat(rSalBitmap.GetBitCount()), aBitmapPalette);
BitmapBuffer* pWrite = rWinSalBitmap.AcquireBuffer(BitmapAccessMode::Write);
sal_uInt8* pSource(pRead->mpBits);