summaryrefslogtreecommitdiff
path: root/include/vcl
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-03-13 12:00:28 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-03-13 12:17:49 +0100
commit68bc6a5dd68006ab86e7ef26f9e5d241cb118879 (patch)
treedebd00d1a05228759974b2d09666dfcccb379ab3 /include/vcl
parenta73f24f47aea2dfa57459424f48b11b2b835e334 (diff)
add PixelFormat enum that replaces bit count in Bitmap/BitmapEx
Bit count for the image is a numeric value (sal_uInt16) but only a handful of values make sense - namely 1,4,8,24 and 32. This replaces the numeric value with an enum, which only accepts those values and checks the correct values are used at compile time. Change-Id: I0fc137c62bce3b0d021f05019a1648da628521bc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112408 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'include/vcl')
-rw-r--r--include/vcl/BitmapTools.hxx4
-rw-r--r--include/vcl/bitmap.hxx8
-rw-r--r--include/vcl/bitmap/BitmapTypes.hxx55
-rw-r--r--include/vcl/bitmapex.hxx13
4 files changed, 73 insertions, 7 deletions
diff --git a/include/vcl/BitmapTools.hxx b/include/vcl/BitmapTools.hxx
index 12cdb1947b2c..d7ce4be9e90f 100644
--- a/include/vcl/BitmapTools.hxx
+++ b/include/vcl/BitmapTools.hxx
@@ -44,9 +44,9 @@ void loadFromSvg(SvStream& rStream, const OUString& sPath, BitmapEx& rBitmapEx,
@param pData
The block of data to copy
@param nStride
- The number of bytes in a scanline, must be >= (width * nBitCount / 8)
+ The number of bytes in a scanline, must be >= (width * bitcount / 8)
*/
-BitmapEx VCL_DLLPUBLIC CreateFromData( sal_uInt8 const *pData, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int32 nStride, sal_uInt16 nBitCount );
+BitmapEx VCL_DLLPUBLIC CreateFromData( sal_uInt8 const *pData, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int32 nStride, vcl::PixelFormat ePixelFormat);
BitmapEx VCL_DLLPUBLIC CreateFromData( RawBitmap && data );
diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx
index d9d6c81d7661..3a2baf9e24c7 100644
--- a/include/vcl/bitmap.hxx
+++ b/include/vcl/bitmap.hxx
@@ -27,6 +27,7 @@
#include <vcl/mapmod.hxx>
#include <vcl/region.hxx>
#include <vcl/scopedbitmapaccess.hxx>
+#include <vcl/bitmap/BitmapTypes.hxx>
#include <o3tl/typed_flags_set.hxx>
@@ -114,7 +115,7 @@ public:
Bitmap();
Bitmap( const Bitmap& rBitmap );
- Bitmap( const Size& rSizePixel, sal_uInt16 nBitCount, const BitmapPalette* pPal = nullptr );
+ Bitmap( const Size& rSizePixel, vcl::PixelFormat ePixelFormat, const BitmapPalette* pPal = nullptr );
explicit Bitmap( std::shared_ptr<SalBitmap> const & xSalBitmap );
virtual ~Bitmap();
@@ -135,6 +136,7 @@ public:
Size GetSizePixel() const;
+ vcl::PixelFormat getPixelFormat() const;
sal_uInt16 GetBitCount() const;
inline sal_Int64 GetColorCount() const;
inline sal_uLong GetSizeBytes() const;
@@ -538,8 +540,8 @@ public:
typedef vcl::ScopedBitmapAccess<BitmapInfoAccess, Bitmap, &Bitmap::AcquireInfoAccess> ScopedInfoAccess;
private:
- SAL_DLLPRIVATE bool ImplConvertUp(sal_uInt16 nBitCount, Color const* pExtColor = nullptr);
- SAL_DLLPRIVATE bool ImplConvertDown(sal_uInt16 nBitCount, Color const* pExtColor = nullptr);
+ SAL_DLLPRIVATE bool ImplConvertUp(vcl::PixelFormat ePixelFormat, Color const* pExtColor = nullptr);
+ SAL_DLLPRIVATE bool ImplConvertDown(vcl::PixelFormat ePixelFormat, Color const* pExtColor = nullptr);
private:
std::shared_ptr<SalBitmap> mxSalBmp;
diff --git a/include/vcl/bitmap/BitmapTypes.hxx b/include/vcl/bitmap/BitmapTypes.hxx
new file mode 100644
index 000000000000..866cf0b2950e
--- /dev/null
+++ b/include/vcl/bitmap/BitmapTypes.hxx
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#pragma once
+
+namespace vcl
+{
+/** Pixel format of the bitmap in bits per pixel */
+enum class PixelFormat
+{
+ INVALID = 0,
+ N1_BPP = 1,
+ N4_BPP = 4,
+ N8_BPP = 8,
+ N24_BPP = 24,
+ N32_BPP = 32
+};
+
+/** Is it a pixel format that forces creation of a palette */
+constexpr bool isPalettePixelFormat(PixelFormat ePixelFormat)
+{
+ assert(ePixelFormat != PixelFormat::INVALID);
+ return sal_uInt16(ePixelFormat) <= 8;
+}
+
+constexpr PixelFormat bitDepthToPixelFormat(sal_uInt16 nBitDepth)
+{
+ switch (nBitDepth)
+ {
+ case 1:
+ return PixelFormat::N1_BPP;
+ case 4:
+ return PixelFormat::N4_BPP;
+ case 8:
+ return PixelFormat::N8_BPP;
+ case 24:
+ return PixelFormat::N24_BPP;
+ case 32:
+ return PixelFormat::N32_BPP;
+ default:
+ break;
+ }
+ return PixelFormat::INVALID;
+}
+
+} // end namespace vcl
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/vcl/bitmapex.hxx b/include/vcl/bitmapex.hxx
index 506901134719..5736e4d38b6a 100644
--- a/include/vcl/bitmapex.hxx
+++ b/include/vcl/bitmapex.hxx
@@ -49,7 +49,7 @@ public:
explicit BitmapEx( const OUString& rIconName );
BitmapEx( const BitmapEx& rBitmapEx );
BitmapEx( const BitmapEx& rBitmapEx, Point aSrc, Size aSize );
- BitmapEx( Size aSize, sal_uInt16 nBitCount );
+ BitmapEx(Size aSize, vcl::PixelFormat ePixelFormat);
explicit BitmapEx( const Bitmap& rBmp );
BitmapEx( const Bitmap& rBmp, const Bitmap& rMask );
BitmapEx( const Bitmap& rBmp, const AlphaMask& rAlphaMask );
@@ -90,7 +90,16 @@ public:
const MapMode& GetPrefMapMode() const { return maBitmap.GetPrefMapMode(); }
void SetPrefMapMode( const MapMode& rPrefMapMode ) { maBitmap.SetPrefMapMode( rPrefMapMode ); }
- sal_uInt16 GetBitCount() const { return maBitmap.GetBitCount(); }
+ sal_uInt16 GetBitCount() const
+ {
+ return maBitmap.GetBitCount();
+ }
+
+ vcl::PixelFormat getPixelFormat() const
+ {
+ return maBitmap.getPixelFormat();
+ }
+
sal_uLong GetSizeBytes() const;
BitmapChecksum GetChecksum() const;