diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-03-27 10:14:13 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-04-02 06:28:39 +0200 |
commit | 88a177f827eba204dea92b631032411de8213ee4 (patch) | |
tree | 3107896970ac35f9fd1cb3804634efdef78c2313 /vcl | |
parent | 465b8b0e9ad4b0c9c7701dee2820a99c5d00b5bf (diff) |
vcl: remove GetBitCount and GetColorCount from Bitmap{Ex}
We can cast the PixelFormat enum to int for the same information
and we can use the enum to reduce ambiguity when possible.
Change-Id: I6ea648139465568cdeb12e5f5f75c7b609365bf4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113188
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl')
30 files changed, 142 insertions, 150 deletions
diff --git a/vcl/qa/cppunit/BitmapFilterTest.cxx b/vcl/qa/cppunit/BitmapFilterTest.cxx index 4bf651855937..a2aa37ceb900 100644 --- a/vcl/qa/cppunit/BitmapFilterTest.cxx +++ b/vcl/qa/cppunit/BitmapFilterTest.cxx @@ -80,7 +80,7 @@ void BitmapFilterTest::testBlurCorrectness() Bitmap aBitmap24Bit(aSize, vcl::PixelFormat::N24_BPP); ScanlineFormat scanlineFormat = ScanlineFormat::NONE; - sal_uInt16 nBPP = aBitmap24Bit.GetBitCount(); + auto ePixelFormat = aBitmap24Bit.getPixelFormat(); { tools::Long aMargin1 = 1; @@ -124,7 +124,7 @@ void BitmapFilterTest::testBlurCorrectness() CPPUNIT_ASSERT_EQUAL(static_cast<tools::Long>(41), aBitmap24Bit.GetSizePixel().Width()); CPPUNIT_ASSERT_EQUAL(static_cast<tools::Long>(31), aBitmap24Bit.GetSizePixel().Height()); - CPPUNIT_ASSERT_EQUAL(nBPP, aBitmap24Bit.GetBitCount()); + CPPUNIT_ASSERT_EQUAL(ePixelFormat, aBitmap24Bit.getPixelFormat()); // Check that the bitmap is horizontally and vertically symmetrical CPPUNIT_ASSERT(BitmapSymmetryCheck::check(aBitmap24Bit)); diff --git a/vcl/qa/cppunit/BitmapScaleTest.cxx b/vcl/qa/cppunit/BitmapScaleTest.cxx index c6da34c6d2c6..0cf65ca798da 100644 --- a/vcl/qa/cppunit/BitmapScaleTest.cxx +++ b/vcl/qa/cppunit/BitmapScaleTest.cxx @@ -203,7 +203,7 @@ void BitmapScaleTest::testScale2() const bool bExportBitmap(false); Bitmap aBitmap24Bit(Size(4096, 4096), vcl::PixelFormat::N24_BPP); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(24), aBitmap24Bit.GetBitCount()); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N24_BPP, aBitmap24Bit.getPixelFormat()); Color aBitmapColor = COL_YELLOW; { BitmapScopedWriteAccess aWriteAccess(aBitmap24Bit); @@ -274,7 +274,7 @@ void BitmapScaleTest::testScaleSymmetry() const bool bExportBitmap(false); Bitmap aBitmap24Bit(Size(10, 10), vcl::PixelFormat::N24_BPP); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(24), aBitmap24Bit.GetBitCount()); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N24_BPP, aBitmap24Bit.getPixelFormat()); { BitmapScopedWriteAccess aWriteAccess(aBitmap24Bit); diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx index 655e76dc21fc..962b06e8e977 100644 --- a/vcl/qa/cppunit/BitmapTest.cxx +++ b/vcl/qa/cppunit/BitmapTest.cxx @@ -89,9 +89,8 @@ void BitmapTest::testCreation() CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong height", static_cast<tools::Long>(0), aSize.Height()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pref size", Size(), aBmp.GetPrefSize()); CPPUNIT_ASSERT_MESSAGE("Not empty", aBmp.IsEmpty()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong bit count", static_cast<sal_uInt16>(0), - aBmp.GetBitCount()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong color count", sal_Int64(1), aBmp.GetColorCount()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pixel format", vcl::PixelFormat::INVALID, + aBmp.getPixelFormat()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong byte size", static_cast<sal_uLong>(0), aBmp.GetSizeBytes()); } @@ -103,9 +102,8 @@ void BitmapTest::testCreation() CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong height", static_cast<tools::Long>(10), aSize.Height()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pref size", Size(), aBmp.GetPrefSize()); CPPUNIT_ASSERT_MESSAGE("Empty bitmap", !aBmp.IsEmpty()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong bit count", static_cast<sal_uInt16>(1), - aBmp.GetBitCount()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong color count", sal_Int64(2), aBmp.GetColorCount()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pixel format", vcl::PixelFormat::N1_BPP, + aBmp.getPixelFormat()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong byte size", static_cast<sal_uLong>(12), aBmp.GetSizeBytes()); } @@ -117,9 +115,8 @@ void BitmapTest::testCreation() CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong height", static_cast<tools::Long>(10), aSize.Height()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pref size", Size(), aBmp.GetPrefSize()); CPPUNIT_ASSERT_MESSAGE("Empty bitmap", !aBmp.IsEmpty()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong bit count", static_cast<sal_uInt16>(8), - aBmp.GetBitCount()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong color count", sal_Int64(256), aBmp.GetColorCount()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pixel format", vcl::PixelFormat::N8_BPP, + aBmp.getPixelFormat()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong byte size", static_cast<sal_uLong>(100), aBmp.GetSizeBytes()); } @@ -131,10 +128,8 @@ void BitmapTest::testCreation() CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong height", static_cast<tools::Long>(10), aSize.Height()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pref size", Size(), aBmp.GetPrefSize()); CPPUNIT_ASSERT_MESSAGE("Empty bitmap", !aBmp.IsEmpty()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong bit count", static_cast<sal_uInt16>(24), - aBmp.GetBitCount()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong color count", sal_Int64(16777216), - aBmp.GetColorCount()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pixel format", vcl::PixelFormat::N24_BPP, + aBmp.getPixelFormat()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong byte size", static_cast<sal_uLong>(300), aBmp.GetSizeBytes()); } @@ -150,10 +145,8 @@ void BitmapTest::testCreation() CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong height", static_cast<tools::Long>(10), aSize.Height()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pref size", Size(), aBmp.GetPrefSize()); CPPUNIT_ASSERT_MESSAGE("Empty bitmap", !aBmp.IsEmpty()); - - CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong bit count", sal_uInt16(32), aBmp.GetBitCount()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong color count", sal_Int64(4294967296ull), - aBmp.GetColorCount()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pixel format", vcl::PixelFormat::N32_BPP, + aBmp.getPixelFormat()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong byte size", sal_uLong(400), aBmp.GetSizeBytes()); } } @@ -292,7 +285,7 @@ void BitmapTest::testConvert() aBitmap.Erase(COL_LIGHTGRAYBLUE); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(8), aBitmap.GetBitCount()); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, aBitmap.getPixelFormat()); { Bitmap::ScopedReadAccess pReadAccess(aBitmap); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(8), pReadAccess->GetBitCount()); @@ -312,7 +305,7 @@ void BitmapTest::testConvert() aBitmap.Convert(BmpConversion::N24Bit); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(24), aBitmap.GetBitCount()); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N24_BPP, aBitmap.getPixelFormat()); { Bitmap::ScopedReadAccess pReadAccess(aBitmap); // 24 bit Bitmap on SVP backend can now use 24bit RGB everywhere. diff --git a/vcl/qa/cppunit/XpmFilterTest.cxx b/vcl/qa/cppunit/XpmFilterTest.cxx index 20a272b7a6ce..1c24de1e131e 100644 --- a/vcl/qa/cppunit/XpmFilterTest.cxx +++ b/vcl/qa/cppunit/XpmFilterTest.cxx @@ -36,7 +36,7 @@ CPPUNIT_TEST_FIXTURE(XpmFilterTest, testXPM_8bit) auto aBitmap = aGraphic.GetBitmapEx(); CPPUNIT_ASSERT_EQUAL(tools::Long(4), aBitmap.GetSizePixel().Width()); CPPUNIT_ASSERT_EQUAL(tools::Long(4), aBitmap.GetSizePixel().Height()); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(8), aBitmap.GetBitCount()); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, aBitmap.getPixelFormat()); CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE, aBitmap.GetPixelColor(0, 0)); CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aBitmap.GetPixelColor(2, 0)); CPPUNIT_ASSERT_EQUAL(COL_YELLOW, aBitmap.GetPixelColor(0, 2)); @@ -51,7 +51,7 @@ CPPUNIT_TEST_FIXTURE(XpmFilterTest, testXPM_4bit) auto aBitmap = aGraphic.GetBitmapEx(); CPPUNIT_ASSERT_EQUAL(tools::Long(4), aBitmap.GetSizePixel().Width()); CPPUNIT_ASSERT_EQUAL(tools::Long(4), aBitmap.GetSizePixel().Height()); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(8), aBitmap.GetBitCount()); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, aBitmap.getPixelFormat()); CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE, aBitmap.GetPixelColor(0, 0)); CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, aBitmap.GetPixelColor(2, 0)); CPPUNIT_ASSERT_EQUAL(COL_YELLOW, aBitmap.GetPixelColor(0, 2)); @@ -66,7 +66,7 @@ CPPUNIT_TEST_FIXTURE(XpmFilterTest, testXPM_1bit) auto aBitmap = aGraphic.GetBitmapEx(); CPPUNIT_ASSERT_EQUAL(tools::Long(10), aBitmap.GetSizePixel().Width()); CPPUNIT_ASSERT_EQUAL(tools::Long(10), aBitmap.GetSizePixel().Height()); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), aBitmap.GetBitCount()); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N1_BPP, aBitmap.getPixelFormat()); CPPUNIT_ASSERT_EQUAL(Color(0xffffff), aBitmap.GetPixelColor(0, 0)); CPPUNIT_ASSERT_EQUAL(Color(0x72d1c8), aBitmap.GetPixelColor(1, 1)); CPPUNIT_ASSERT_EQUAL(Color(0x72d1c8), aBitmap.GetPixelColor(8, 8)); diff --git a/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx b/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx index 5da8cb643849..d4cb8ed1532b 100644 --- a/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx +++ b/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx @@ -147,13 +147,13 @@ void BitmapRenderTest::testDrawAlphaBitmapEx() auto pBackendCapabilities = ImplGetSVData()->mpDefInst->GetBackendCapabilities(); if (pBackendCapabilities->mbSupportsBitmap32) { - CPPUNIT_ASSERT_EQUAL(sal_uInt16(32), aBitmapEx.GetBitmap().GetBitCount()); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N32_BPP, aBitmapEx.GetBitmap().getPixelFormat()); } else { - CPPUNIT_ASSERT_EQUAL(sal_uInt16(24), aBitmapEx.GetBitmap().GetBitCount()); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N24_BPP, aBitmapEx.GetBitmap().getPixelFormat()); CPPUNIT_ASSERT_EQUAL(true, aBitmapEx.IsAlpha()); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(8), aBitmapEx.GetAlpha().GetBitCount()); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, aBitmapEx.GetAlpha().getPixelFormat()); } // Check the bitmap has pixels we expect diff --git a/vcl/qa/cppunit/canvasbitmaptest.cxx b/vcl/qa/cppunit/canvasbitmaptest.cxx index cfa6b418c958..a1185ab1f7ad 100644 --- a/vcl/qa/cppunit/canvasbitmaptest.cxx +++ b/vcl/qa/cppunit/canvasbitmaptest.cxx @@ -723,8 +723,8 @@ void CanvasBitmapTest::runTest() !aBmp.IsTransparent()); CPPUNIT_ASSERT_EQUAL_MESSAGE( "Bitmap does not have size (10,10)", Size(10,10), aBmp.GetSizePixel()); - CPPUNIT_ASSERT_EQUAL_MESSAGE( "Bitmap does not have bitcount of 8", - static_cast<sal_uInt16>(8), aBmp.GetBitCount()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Bitmap does not have the expected pixel format", + vcl::PixelFormat::N8_BPP, aBmp.getPixelFormat()); { Bitmap aBitmap = aBmp.GetBitmap(); BitmapReadAccess* pBmpAcc = aBitmap.AcquireReadAccess(); @@ -751,8 +751,8 @@ void CanvasBitmapTest::runTest() aBmp.IsAlpha()); CPPUNIT_ASSERT_EQUAL_MESSAGE( "Bitmap does not have size (10,10)", Size(10,10), aBmp.GetSizePixel()); - CPPUNIT_ASSERT_EQUAL_MESSAGE( "Bitmap has bitcount of 24", - static_cast<sal_uInt16>(24), aBmp.GetBitCount()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Bitmap does not have the expected pixel format", + vcl::PixelFormat::N24_BPP, aBmp.getPixelFormat()); { Bitmap aBitmap = aBmp.GetBitmap(); BitmapReadAccess* pBmpAcc = aBitmap.AcquireReadAccess(); diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index 75832ec20324..8e089ded9d95 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -1804,7 +1804,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf121615) BitmapEx aBitmap = aGraphic.GetBitmapEx(); CPPUNIT_ASSERT_EQUAL(tools::Long(200), aBitmap.GetSizePixel().Width()); CPPUNIT_ASSERT_EQUAL(tools::Long(300), aBitmap.GetSizePixel().Height()); - CPPUNIT_ASSERT_EQUAL(8, int(aBitmap.GetBitCount())); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, aBitmap.getPixelFormat()); // tdf#121615 was caused by broken handling of data width with 8bit color, // so the test image has some black in the bottomright corner, check it's there CPPUNIT_ASSERT_EQUAL(COL_WHITE, aBitmap.GetPixelColor(0, 0)); @@ -1853,7 +1853,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf141171) Size aSize = aBitmap.GetSizePixel(); CPPUNIT_ASSERT_EQUAL(tools::Long(878), aSize.Width()); CPPUNIT_ASSERT_EQUAL(tools::Long(127), aSize.Height()); - CPPUNIT_ASSERT_EQUAL(8, int(aBitmap.GetBitCount())); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, aBitmap.getPixelFormat()); for (tools::Long nX = 0; nX < aSize.Width(); ++nX) { @@ -1908,7 +1908,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf129085) BitmapEx aBitmap = aGraphic.GetBitmapEx(); CPPUNIT_ASSERT_EQUAL(tools::Long(884), aBitmap.GetSizePixel().Width()); CPPUNIT_ASSERT_EQUAL(tools::Long(925), aBitmap.GetSizePixel().Height()); - CPPUNIT_ASSERT_EQUAL(24, int(aBitmap.GetBitCount())); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N24_BPP, aBitmap.getPixelFormat()); } CPPUNIT_TEST_FIXTURE(PdfExportTest, testTocLink) diff --git a/vcl/qa/cppunit/skia/skia.cxx b/vcl/qa/cppunit/skia/skia.cxx index 2ca53bbdc2a9..67c1b4f274ef 100644 --- a/vcl/qa/cppunit/skia/skia.cxx +++ b/vcl/qa/cppunit/skia/skia.cxx @@ -197,11 +197,11 @@ void SkiaTest::testInterpretAs8Bit() bitmap.Erase(Color(33, 33, 33)); SkiaSalBitmap* skiaBitmap = dynamic_cast<SkiaSalBitmap*>(bitmap.ImplGetSalBitmap().get()); CPPUNIT_ASSERT(skiaBitmap->unittestHasEraseColor()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(24), bitmap.GetBitCount()); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N24_BPP, bitmap.getPixelFormat()); bitmap.Convert(BmpConversion::N8BitNoConversion); skiaBitmap = dynamic_cast<SkiaSalBitmap*>(bitmap.ImplGetSalBitmap().get()); CPPUNIT_ASSERT(skiaBitmap->unittestHasEraseColor()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(8), bitmap.GetBitCount()); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, bitmap.getPixelFormat()); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(33), BitmapReadAccess(bitmap).GetPixelIndex(0, 0)); // Test with image. @@ -212,11 +212,11 @@ void SkiaTest::testInterpretAs8Bit() skiaBitmap->GetSkImage(); CPPUNIT_ASSERT(!skiaBitmap->unittestHasEraseColor()); CPPUNIT_ASSERT(skiaBitmap->unittestHasImage()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(24), bitmap.GetBitCount()); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N24_BPP, bitmap.getPixelFormat()); bitmap.Convert(BmpConversion::N8BitNoConversion); skiaBitmap = dynamic_cast<SkiaSalBitmap*>(bitmap.ImplGetSalBitmap().get()); CPPUNIT_ASSERT(skiaBitmap->unittestHasImage()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(8), bitmap.GetBitCount()); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, bitmap.getPixelFormat()); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(34), BitmapReadAccess(bitmap).GetPixelIndex(0, 0)); } @@ -236,7 +236,7 @@ void SkiaTest::testAlphaBlendWith() alpha.BlendWith(bitmap); skiaAlpha = dynamic_cast<SkiaSalBitmap*>(alpha.ImplGetSalBitmap().get()); CPPUNIT_ASSERT(skiaAlpha->unittestHasEraseColor()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(8), alpha.GetBitCount()); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, alpha.getPixelFormat()); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(112), AlphaMask::ScopedReadAccess(alpha)->GetPixelIndex(0, 0)); @@ -256,7 +256,7 @@ void SkiaTest::testAlphaBlendWith() alpha.BlendWith(bitmap); skiaAlpha = dynamic_cast<SkiaSalBitmap*>(alpha.ImplGetSalBitmap().get()); CPPUNIT_ASSERT(skiaAlpha->unittestHasImage()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(8), alpha.GetBitCount()); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, alpha.getPixelFormat()); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(112), AlphaMask::ScopedReadAccess(alpha)->GetPixelIndex(0, 0)); @@ -273,7 +273,7 @@ void SkiaTest::testAlphaBlendWith() alpha.BlendWith(bitmap); skiaAlpha = dynamic_cast<SkiaSalBitmap*>(alpha.ImplGetSalBitmap().get()); CPPUNIT_ASSERT(skiaAlpha->unittestHasImage()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(8), alpha.GetBitCount()); + CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, alpha.getPixelFormat()); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(112), AlphaMask::ScopedReadAccess(alpha)->GetPixelIndex(0, 0)); } diff --git a/vcl/source/bitmap/BitmapColorQuantizationFilter.cxx b/vcl/source/bitmap/BitmapColorQuantizationFilter.cxx index 2205f1ca98f0..faafd64b81b9 100644 --- a/vcl/source/bitmap/BitmapColorQuantizationFilter.cxx +++ b/vcl/source/bitmap/BitmapColorQuantizationFilter.cxx @@ -25,7 +25,7 @@ BitmapEx BitmapColorQuantizationFilter::execute(BitmapEx const& aBitmapEx) const bool bRet = false; - if (aBitmap.GetColorCount() <= sal_Int64(mnNewColorCount)) + if (vcl::numberOfColors(aBitmap.getPixelFormat()) <= sal_Int64(mnNewColorCount)) { bRet = true; } diff --git a/vcl/source/bitmap/BitmapEx.cxx b/vcl/source/bitmap/BitmapEx.cxx index 0464cbd47f8a..2aa41de865ba 100644 --- a/vcl/source/bitmap/BitmapEx.cxx +++ b/vcl/source/bitmap/BitmapEx.cxx @@ -127,7 +127,8 @@ BitmapEx::BitmapEx( const Bitmap& rBmp, const Bitmap& rMask ) : { // Ensure a mask is exactly one bit deep, // alternatively also allow 8bpp masks. - if( !maMask.IsEmpty() && maMask.GetBitCount() != 1 && !(maMask.GetBitCount() == 8 && maMask.HasGreyPalette8Bit())) + if (!maMask.IsEmpty() && maMask.getPixelFormat() != vcl::PixelFormat::N1_BPP + && !(maMask.getPixelFormat() == vcl::PixelFormat::N8_BPP && maMask.HasGreyPalette8Bit())) { SAL_WARN( "vcl", "BitmapEx: forced mask to monochrome"); BitmapEx aMaskEx(maMask); @@ -665,7 +666,7 @@ sal_uInt8 BitmapEx::GetAlpha(sal_Int32 nX, sal_Int32 nY) const if (nX < 0 || nX >= GetSizePixel().Width() || nY < 0 || nY >= GetSizePixel().Height()) return 0; - if (maBitmap.GetBitCount() == 32) + if (maBitmap.getPixelFormat() == vcl::PixelFormat::N32_BPP) return GetPixelColor(nX, nY).GetAlpha(); sal_uInt8 nAlpha(0); @@ -722,7 +723,7 @@ Color BitmapEx::GetPixelColor(sal_Int32 nX, sal_Int32 nY) const AlphaMask::ScopedReadAccess pAlphaReadAccess(aAlpha); aColor.SetAlpha(255 - pAlphaReadAccess->GetPixel(nY, nX).GetIndex()); } - else if (maBitmap.GetBitCount() != 32) + else if (maBitmap.getPixelFormat() != vcl::PixelFormat::N32_BPP) { aColor.SetAlpha(255); } @@ -992,7 +993,7 @@ BitmapEx BitmapEx::ModifyBitmapEx(const basegfx::BColorModifierStack& rBColorMod if(IsTransparent()) { // clear bitmap with dest color - if(aChangedBitmap.GetBitCount() <= 8) + if (vcl::isPalettePixelFormat(aChangedBitmap.getPixelFormat())) { // For e.g. 8bit Bitmaps, the nearest color to the given erase color is // determined and used -> this may be different from what is wanted here. diff --git a/vcl/source/bitmap/BitmapInfoAccess.cxx b/vcl/source/bitmap/BitmapInfoAccess.cxx index 8c90e8fb8d25..1914755cc692 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, rBitmap.GetBitCount())) + if (xNewImpBmp->Create(*xImpBmp, vcl::pixelFormatBitCount(rBitmap.getPixelFormat()))) { xImpBmp = xNewImpBmp; rBitmap.ImplSetSalBitmap(xImpBmp); diff --git a/vcl/source/bitmap/BitmapMosaicFilter.cxx b/vcl/source/bitmap/BitmapMosaicFilter.cxx index d04321c0bcee..8dfa4519e05a 100644 --- a/vcl/source/bitmap/BitmapMosaicFilter.cxx +++ b/vcl/source/bitmap/BitmapMosaicFilter.cxx @@ -26,7 +26,7 @@ BitmapEx BitmapMosaicFilter::execute(BitmapEx const& rBitmapEx) const BitmapReadAccess* pReadAcc; BitmapWriteAccess* pWriteAcc; - if (aBitmap.GetBitCount() > 8) + if (!isPalettePixelFormat(aBitmap.getPixelFormat())) { pReadAcc = pWriteAcc = aBitmap.AcquireWriteAccess(); } diff --git a/vcl/source/bitmap/BitmapPopArtFilter.cxx b/vcl/source/bitmap/BitmapPopArtFilter.cxx index 54e0aa2d2f15..81a3d22c76f0 100644 --- a/vcl/source/bitmap/BitmapPopArtFilter.cxx +++ b/vcl/source/bitmap/BitmapPopArtFilter.cxx @@ -18,7 +18,8 @@ BitmapEx BitmapPopArtFilter::execute(BitmapEx const& rBitmapEx) const { Bitmap aBitmap(rBitmapEx.GetBitmap()); - bool bRet = (aBitmap.GetBitCount() <= 8) || aBitmap.Convert(BmpConversion::N8BitColors); + bool bRet = isPalettePixelFormat(aBitmap.getPixelFormat()) + || aBitmap.Convert(BmpConversion::N8BitColors); if (bRet) { diff --git a/vcl/source/bitmap/BitmapSimpleColorQuantizationFilter.cxx b/vcl/source/bitmap/BitmapSimpleColorQuantizationFilter.cxx index 281a2d066fd5..b44c7daba85f 100644 --- a/vcl/source/bitmap/BitmapSimpleColorQuantizationFilter.cxx +++ b/vcl/source/bitmap/BitmapSimpleColorQuantizationFilter.cxx @@ -21,7 +21,7 @@ BitmapEx BitmapSimpleColorQuantizationFilter::execute(BitmapEx const& aBitmapEx) bool bRet = false; - if (aBitmap.GetColorCount() <= sal_Int64(mnNewColorCount)) + if (vcl::numberOfColors(aBitmap.getPixelFormat()) <= sal_Int64(mnNewColorCount)) { bRet = true; } diff --git a/vcl/source/bitmap/BitmapTools.cxx b/vcl/source/bitmap/BitmapTools.cxx index 89d97c953886..8bd24f1d5706 100644 --- a/vcl/source/bitmap/BitmapTools.cxx +++ b/vcl/source/bitmap/BitmapTools.cxx @@ -1008,7 +1008,7 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un if(8 == aBitmap.GetSizePixel().Width() && 8 == aBitmap.GetSizePixel().Height()) { - if(2 == aBitmap.GetColorCount()) + if (aBitmap.getPixelFormat() == vcl::PixelFormat::N1_BPP) { BitmapReadAccess* pRead = aBitmap.AcquireReadAccess(); @@ -1080,7 +1080,7 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un bool convertBitmap32To24Plus8(BitmapEx const & rInput, BitmapEx & rResult) { Bitmap aBitmap(rInput.GetBitmap()); - if (aBitmap.GetBitCount() != 32) + if (aBitmap.getPixelFormat() != vcl::PixelFormat::N32_BPP) return false; Size aSize = aBitmap.GetSizePixel(); diff --git a/vcl/source/bitmap/alpha.cxx b/vcl/source/bitmap/alpha.cxx index aee39e63c329..0f0547166a3b 100644 --- a/vcl/source/bitmap/alpha.cxx +++ b/vcl/source/bitmap/alpha.cxx @@ -65,7 +65,7 @@ const Bitmap& AlphaMask::ImplGetBitmap() const void AlphaMask::ImplSetBitmap( const Bitmap& rBitmap ) { - SAL_WARN_IF( 8 != rBitmap.GetBitCount(), "vcl.gdi", "Bitmap should be 8bpp, not " << rBitmap.GetBitCount() << "bpp" ); + SAL_WARN_IF(rBitmap.getPixelFormat() != vcl::PixelFormat::N8_BPP, "vcl.gdi", "Bitmap should be 8bpp, not " << vcl::pixelFormatBitCount(rBitmap.getPixelFormat()) << "bpp" ); SAL_WARN_IF( !rBitmap.HasGreyPalette8Bit(), "vcl.gdi", "Bitmap isn't greyscale" ); *static_cast<Bitmap*>(this) = rBitmap; } diff --git a/vcl/source/bitmap/bitmap.cxx b/vcl/source/bitmap/bitmap.cxx index e9bf5554169c..592ae0b213fe 100644 --- a/vcl/source/bitmap/bitmap.cxx +++ b/vcl/source/bitmap/bitmap.cxx @@ -322,42 +322,25 @@ Size Bitmap::GetSizePixel() const vcl::PixelFormat Bitmap::getPixelFormat() const { - switch (GetBitCount()) - { - case 1: return vcl::PixelFormat::N1_BPP; - case 4: assert(false); break; - case 8: return vcl::PixelFormat::N8_BPP; - case 24: return vcl::PixelFormat::N24_BPP; - case 32: return vcl::PixelFormat::N32_BPP; - default: - break; - } - return vcl::PixelFormat::INVALID; -} - -sal_uInt16 Bitmap::GetBitCount() const -{ if (!mxSalBmp) - return 0; + return vcl::PixelFormat::INVALID; sal_uInt16 nBitCount = mxSalBmp->GetBitCount(); if (nBitCount <= 1) - return 1; - if (nBitCount <= 4) - return 4; + return vcl::PixelFormat::N1_BPP; if (nBitCount <= 8) - return 8; + return vcl::PixelFormat::N8_BPP; if (nBitCount <= 24) - return 24; + return vcl::PixelFormat::N24_BPP; if (nBitCount <= 32) - return 32; - return 0; + return vcl::PixelFormat::N32_BPP; + + return vcl::PixelFormat::INVALID; } bool Bitmap::HasGreyPaletteAny() const { - const sal_uInt16 nBitCount = GetBitCount(); - bool bRet = nBitCount == 1; + bool bRet = getPixelFormat() == vcl::PixelFormat::N1_BPP; ScopedInfoAccess pIAcc(const_cast<Bitmap&>(*this)); @@ -397,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, GetBitCount())) + if (xNewImpBmp->Create(*mxSalBmp, vcl::pixelFormatBitCount(getPixelFormat()))) { Bitmap* pThis = const_cast<Bitmap*>(this); pThis->mxSalBmp = xNewImpBmp; @@ -551,8 +534,8 @@ bool Bitmap::CopyPixel( const tools::Rectangle& rRectDst, Bitmap* pSrc = const_cast<Bitmap*>(pBmpSrc); const Size aCopySizePix( pSrc->GetSizePixel() ); tools::Rectangle aRectSrc( rRectSrc ); - const sal_uInt16 nSrcBitCount = pBmpSrc->GetBitCount(); - const sal_uInt16 nDstBitCount = GetBitCount(); + const sal_uInt16 nSrcBitCount = vcl::pixelFormatBitCount(pBmpSrc->getPixelFormat()); + const sal_uInt16 nDstBitCount = vcl::pixelFormatBitCount(getPixelFormat()); if( nSrcBitCount > nDstBitCount ) { @@ -983,7 +966,7 @@ bool Bitmap::Convert( BmpConversion eConversion ) } } - const sal_uInt16 nBitCount = GetBitCount (); + const sal_uInt16 nBitCount = vcl::pixelFormatBitCount(getPixelFormat()); bool bRet = false; switch( eConversion ) @@ -1168,7 +1151,7 @@ bool Bitmap::ImplMakeGreyscales() bool Bitmap::ImplConvertUp(vcl::PixelFormat ePixelFormat, Color const * pExtColor) { - SAL_WARN_IF(sal_Int32(ePixelFormat) <= GetBitCount(), "vcl", "New BitCount must be greater!" ); + SAL_WARN_IF(ePixelFormat <= getPixelFormat(), "vcl", "New pixel format must be greater!" ); Bitmap::ScopedReadAccess pReadAcc(*this); bool bRet = false; @@ -1188,9 +1171,9 @@ bool Bitmap::ImplConvertUp(vcl::PixelFormat ePixelFormat, Color const * pExtColo { const BitmapPalette& rOldPalette = pReadAcc->GetPalette(); const sal_uInt16 nOldCount = rOldPalette.GetEntryCount(); - assert(nOldCount <= (1 << GetBitCount())); - sal_Int16 nNewBitCount = sal_Int16(ePixelFormat); - aPalette.SetEntryCount(1 << nNewBitCount); + assert(nOldCount <= (1 << vcl::pixelFormatBitCount(getPixelFormat()))); + + aPalette.SetEntryCount(1 << vcl::pixelFormatBitCount(ePixelFormat)); for (sal_uInt16 i = 0; i < nOldCount; i++) aPalette[i] = rOldPalette[i]; @@ -1257,7 +1240,7 @@ bool Bitmap::ImplConvertUp(vcl::PixelFormat ePixelFormat, Color const * pExtColo bool Bitmap::ImplConvertDown(vcl::PixelFormat ePixelFormat, Color const * pExtColor) { - SAL_WARN_IF(sal_Int32(ePixelFormat) > GetBitCount(), "vcl", "New BitCount must be lower ( or equal when pExtColor is set )!"); + SAL_WARN_IF(ePixelFormat > getPixelFormat(), "vcl", "New pixelformat must be lower ( or equal when pExtColor is set )!"); Bitmap::ScopedReadAccess pReadAcc(*this); bool bRet = false; @@ -1397,7 +1380,7 @@ bool Bitmap::Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag n return true; } - const sal_uInt16 nStartCount(GetBitCount()); + const auto eStartPixelFormat = getPixelFormat(); if (mxSalBmp && mxSalBmp->ScalingSupported()) { @@ -1426,7 +1409,7 @@ bool Bitmap::Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag n // just use the fast scale rather than attempting to count unique colors in // the other converters and pass all the info down through // Bitmap::MakeMonochrome - if (nStartCount == 1) + if (eStartPixelFormat == vcl::PixelFormat::N1_BPP) nScaleFlag = BmpScaleFlag::Fast; BitmapEx aBmpEx(*this); @@ -1470,7 +1453,7 @@ bool Bitmap::Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag n if (bRetval) *this = aBmpEx.GetBitmap(); - OSL_ENSURE(!bRetval || nStartCount == GetBitCount(), "Bitmap::Scale has changed the ColorDepth, this should *not* happen (!)"); + OSL_ENSURE(!bRetval || eStartPixelFormat == getPixelFormat(), "Bitmap::Scale has changed the ColorDepth, this should *not* happen (!)"); return bRetval; } @@ -1503,22 +1486,17 @@ bool Bitmap::HasFastScale() void Bitmap::AdaptBitCount(Bitmap& rNew) const { // aNew is the result of some operation; adapt it's BitCount to the original (this) - if(GetBitCount() == rNew.GetBitCount()) + if (getPixelFormat() == rNew.getPixelFormat()) return; - switch(GetBitCount()) + switch (getPixelFormat()) { - case 1: + case vcl::PixelFormat::N1_BPP: { rNew.Convert(BmpConversion::N1BitThreshold); break; } - case 4: - { - assert(false); - break; - } - case 8: + case vcl::PixelFormat::N8_BPP: { if(HasGreyPaletteAny()) { @@ -1530,19 +1508,19 @@ void Bitmap::AdaptBitCount(Bitmap& rNew) const } break; } - case 24: + case vcl::PixelFormat::N24_BPP: { rNew.Convert(BmpConversion::N24Bit); break; } - case 32: + case vcl::PixelFormat::N32_BPP: { rNew.Convert(BmpConversion::N32Bit); break; } - default: + case vcl::PixelFormat::INVALID: { - SAL_WARN("vcl", "BitDepth adaptation failed, from " << rNew.GetBitCount() << " to " << GetBitCount()); + SAL_WARN("vcl", "Can't adapt the pixelformat as it is invalid."); break; } } diff --git a/vcl/source/bitmap/bitmappaint.cxx b/vcl/source/bitmap/bitmappaint.cxx index 201f05e74a79..e8a2a03c57b1 100644 --- a/vcl/source/bitmap/bitmappaint.cxx +++ b/vcl/source/bitmap/bitmappaint.cxx @@ -888,7 +888,7 @@ bool Bitmap::Replace(const Color& rSearchColor, const Color& rReplaceColor, sal_ // Bitmaps with 1 bit color depth can cause problems if they have other entries than black/white // in their palette - if (GetBitCount() == 1) + if (getPixelFormat() == vcl::PixelFormat::N1_BPP) Convert(BmpConversion::N8BitColors); BitmapScopedWriteAccess pAcc(*this); @@ -951,7 +951,7 @@ bool Bitmap::Replace(const Color* pSearchColors, const Color* pReplaceColors, si { // Bitmaps with 1 bit color depth can cause problems if they have other entries than black/white // in their palette - if (GetBitCount() == 1) + if (getPixelFormat() == vcl::PixelFormat::N1_BPP) Convert(BmpConversion::N8BitColors); BitmapScopedWriteAccess pAcc(*this); @@ -1124,7 +1124,7 @@ bool Bitmap::Blend(const AlphaMask& rAlpha, const Color& rBackgroundColor) { // Convert to a truecolor bitmap, if we're a paletted one. There's room for tradeoff decision here, // maybe later for an overload (or a flag) - if (GetBitCount() <= 8) + if (vcl::isPalettePixelFormat(getPixelFormat())) Convert(BmpConversion::N24Bit); AlphaMask::ScopedReadAccess pAlphaAcc(const_cast<AlphaMask&>(rAlpha)); diff --git a/vcl/source/bitmap/dibtools.cxx b/vcl/source/bitmap/dibtools.cxx index 94341bad56f6..f583ca0b332e 100644 --- a/vcl/source/bitmap/dibtools.cxx +++ b/vcl/source/bitmap/dibtools.cxx @@ -1748,7 +1748,7 @@ bool ReadDIBBitmapEx( if(!aMask.IsEmpty()) { // do we have an alpha mask? - if((8 == aMask.GetBitCount()) && aMask.HasGreyPalette8Bit()) + if (aMask.getPixelFormat() == vcl::PixelFormat::N8_BPP && aMask.HasGreyPalette8Bit()) { AlphaMask aAlpha; diff --git a/vcl/source/filter/etiff/etiff.cxx b/vcl/source/filter/etiff/etiff.cxx index 65a90cd160da..ca5b7934ab84 100644 --- a/vcl/source/filter/etiff/etiff.cxx +++ b/vcl/source/filter/etiff/etiff.cxx @@ -183,7 +183,7 @@ bool TIFFWriter::WriteTIFF( const Graphic& rGraphic, FilterConfigItem const * pF mpAcc = aBmp.AcquireReadAccess(); if ( mpAcc ) { - mnBitsPerPixel = aBmp.GetBitCount(); + mnBitsPerPixel = vcl::pixelFormatBitCount(aBmp.getPixelFormat()); // export code below only handles four discrete cases mnBitsPerPixel = diff --git a/vcl/source/filter/png/pngwrite.cxx b/vcl/source/filter/png/pngwrite.cxx index 092629b686e9..379c805f313b 100644 --- a/vcl/source/filter/png/pngwrite.cxx +++ b/vcl/source/filter/png/pngwrite.cxx @@ -112,7 +112,7 @@ PNGWriterImpl::PNGWriterImpl(const BitmapEx& rBitmapEx, BitmapEx aBitmapEx; - if (rBitmapEx.GetBitmap().GetBitCount() == 32) + if (rBitmapEx.GetBitmap().getPixelFormat() == vcl::PixelFormat::N32_BPP) { if (!vcl::bitmap::convertBitmap32To24Plus8(rBitmapEx, aBitmapEx)) return; @@ -142,7 +142,7 @@ PNGWriterImpl::PNGWriterImpl(const BitmapEx& rBitmapEx, } } } - mnBitsPerPixel = static_cast<sal_uInt8>(aBmp.GetBitCount()); + mnBitsPerPixel = sal_uInt8(vcl::pixelFormatBitCount(aBmp.getPixelFormat())); if (aBitmapEx.IsTransparent()) { diff --git a/vcl/source/gdi/mtfxmldump.cxx b/vcl/source/gdi/mtfxmldump.cxx index 8b1fa773eb27..d920724cde32 100644 --- a/vcl/source/gdi/mtfxmldump.cxx +++ b/vcl/source/gdi/mtfxmldump.cxx @@ -421,6 +421,19 @@ OUString convertWallpaperStyleToString(WallpaperStyle eWallpaperStyle) return OUString(); } +OUString convertPixelFormatToString(vcl::PixelFormat ePixelFormat) +{ + switch (ePixelFormat) + { + case vcl::PixelFormat::INVALID: return "INVALID"; + case vcl::PixelFormat::N1_BPP: return "1BPP"; + case vcl::PixelFormat::N8_BPP: return "8BPP"; + case vcl::PixelFormat::N24_BPP: return "24BPP"; + case vcl::PixelFormat::N32_BPP: return "32BPP"; + } + return OUString(); +} + OUString hex32(sal_uInt32 nNumber) { std::stringstream ss; @@ -990,7 +1003,7 @@ void MetafileXmlDump::writeXml(const GDIMetaFile& rMetaFile, tools::XmlWriter& r BitmapEx const & rBitmapEx = rWallpaper.GetBitmap(); rWriter.attribute("crc", hex32(rBitmapEx.GetChecksum())); rWriter.attribute("transparenttype", convertBitmapExTransparentType(rBitmapEx.GetTransparentType())); - rWriter.attribute("bitcount", hex32(rBitmapEx.GetBitmap().GetBitCount())); + rWriter.attribute("pixelformat", convertPixelFormatToString(rBitmapEx.GetBitmap().getPixelFormat())); rWriter.attribute("width", hex32(rBitmapEx.GetSizePixel().Width())); rWriter.attribute("height", hex32(rBitmapEx.GetSizePixel().Height())); rWriter.endElement(); diff --git a/vcl/source/gdi/pdfextoutdevdata.cxx b/vcl/source/gdi/pdfextoutdevdata.cxx index 8ba808e21579..fc431c7e65a2 100644 --- a/vcl/source/gdi/pdfextoutdevdata.cxx +++ b/vcl/source/gdi/pdfextoutdevdata.cxx @@ -482,8 +482,8 @@ bool PageSyncData::PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rCurGDIMtfAc aOutputRect.SetSize(pA->GetSize()); } } - - rWriter.DrawJPGBitmap( aTmp, aGraphic.GetBitmapEx().GetBitCount() > 8, aGraphic.GetSizePixel(), aOutputRect, aMask, aGraphic ); + auto ePixelFormat = aGraphic.GetBitmapEx().getPixelFormat(); + rWriter.DrawJPGBitmap(aTmp, ePixelFormat > vcl::PixelFormat::N8_BPP, aGraphic.GetSizePixel(), aOutputRect, aMask, aGraphic); } if ( bClippingNeeded ) diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 2142aeac8808..ad9c1e0935e4 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -8370,9 +8370,10 @@ void PDFWriterImpl::writeJPG( JPGEmit& rObject ) sal_Int32 nMaskObject = 0; if( !rObject.m_aMask.IsEmpty() ) { - if( rObject.m_aMask.GetBitCount() == 1 || - ( rObject.m_aMask.GetBitCount() == 8 && m_aContext.Version >= PDFWriter::PDFVersion::PDF_1_4 && !m_bIsPDF_A1 ) - ) + if (rObject.m_aMask.getPixelFormat() == vcl::PixelFormat::N1_BPP + || (rObject.m_aMask.getPixelFormat() == vcl::PixelFormat::N8_BPP + && m_aContext.Version >= PDFWriter::PDFVersion::PDF_1_4 + && !m_bIsPDF_A1)) { nMaskObject = createObject(); } @@ -8403,7 +8404,7 @@ void PDFWriterImpl::writeJPG( JPGEmit& rObject ) aLine.append( nLength ); if( nMaskObject ) { - aLine.append( rObject.m_aMask.GetBitCount() == 1 ? " /Mask " : " /SMask " ); + aLine.append(rObject.m_aMask.getPixelFormat() == vcl::PixelFormat::N1_BPP ? " /Mask " : " /SMask "); aLine.append( nMaskObject ); aLine.append( " 0 R " ); } @@ -8422,9 +8423,9 @@ void PDFWriterImpl::writeJPG( JPGEmit& rObject ) { BitmapEmit aEmit; aEmit.m_nObject = nMaskObject; - if( rObject.m_aMask.GetBitCount() == 1 ) + if (rObject.m_aMask.getPixelFormat() == vcl::PixelFormat::N1_BPP) aEmit.m_aBitmap = BitmapEx( rObject.m_aMask, rObject.m_aMask ); - else if( rObject.m_aMask.GetBitCount() == 8 ) + else if(rObject.m_aMask.getPixelFormat() == vcl::PixelFormat::N8_BPP) aEmit.m_aBitmap = BitmapEx( rObject.m_aMask, AlphaMask( rObject.m_aMask ) ); writeBitmapObject( aEmit, true ); } @@ -8725,33 +8726,35 @@ bool PDFWriterImpl::writeBitmapObject( BitmapEmit& rObject, bool bMask ) { aBitmap = getExportBitmap(rObject.m_aBitmap.GetMask()); aBitmap.Convert( BmpConversion::N1BitThreshold ); - SAL_WARN_IF( aBitmap.GetBitCount() != 1, "vcl.pdfwriter", "mask conversion failed" ); + SAL_WARN_IF(aBitmap.getPixelFormat() != vcl::PixelFormat::N1_BPP, "vcl.pdfwriter", "mask conversion failed" ); } - else if( aBitmap.GetBitCount() != 8 ) + else if (aBitmap.getPixelFormat() != vcl::PixelFormat::N8_BPP) { aBitmap = getExportBitmap(rObject.m_aBitmap.GetAlpha().GetBitmap()); aBitmap.Convert( BmpConversion::N8BitGreys ); - SAL_WARN_IF( aBitmap.GetBitCount() != 8, "vcl.pdfwriter", "alpha mask conversion failed" ); + SAL_WARN_IF(aBitmap.getPixelFormat() != vcl::PixelFormat::N8_BPP, "vcl.pdfwriter", "alpha mask conversion failed" ); } } Bitmap::ScopedReadAccess pAccess(aBitmap); - bool bTrueColor; - sal_Int32 nBitsPerComponent; - switch( aBitmap.GetBitCount() ) + bool bTrueColor = true; + sal_Int32 nBitsPerComponent = 0; + auto const ePixelFormat = aBitmap.getPixelFormat(); + switch (ePixelFormat) { - case 1: - case 2: - case 4: - case 8: + case vcl::PixelFormat::N1_BPP: + case vcl::PixelFormat::N8_BPP: bTrueColor = false; - nBitsPerComponent = aBitmap.GetBitCount(); + nBitsPerComponent = vcl::pixelFormatBitCount(ePixelFormat); break; - default: + case vcl::PixelFormat::N24_BPP: + case vcl::PixelFormat::N32_BPP: bTrueColor = true; nBitsPerComponent = 8; break; + case vcl::PixelFormat::INVALID: + return false; } sal_Int32 nStreamLengthObject = createObject(); @@ -8794,7 +8797,7 @@ bool PDFWriterImpl::writeBitmapObject( BitmapEmit& rObject, bool bMask ) else if( aBitmap.HasGreyPaletteAny() ) { aLine.append( "/DeviceGray\n" ); - if( aBitmap.GetBitCount() == 1 ) + if (aBitmap.getPixelFormat() == vcl::PixelFormat::N1_BPP) { // #i47395# 1 bit bitmaps occasionally have an inverted grey palette sal_uInt16 nBlackIndex = pAccess->GetBestPaletteIndex( BitmapColor( COL_BLACK ) ); @@ -8867,7 +8870,7 @@ bool PDFWriterImpl::writeBitmapObject( BitmapEmit& rObject, bool bMask ) } else { - if( aBitmap.GetBitCount() == 1 ) + if (aBitmap.getPixelFormat() == vcl::PixelFormat::N1_BPP) { aLine.append( "/ImageMask true\n" ); sal_Int32 nBlackIndex = pAccess->GetBestPaletteIndex( BitmapColor( COL_BLACK ) ); @@ -8877,7 +8880,7 @@ bool PDFWriterImpl::writeBitmapObject( BitmapEmit& rObject, bool bMask ) else aLine.append( "/Decode[ 0 1 ]\n" ); } - else if( aBitmap.GetBitCount() == 8 ) + else if (aBitmap.getPixelFormat() == vcl::PixelFormat::N8_BPP) { aLine.append( "/ColorSpace/DeviceGray\n" "/Decode [ 1 0 ]\n" ); @@ -9124,15 +9127,15 @@ void PDFWriterImpl::drawBitmap( const Point& rDestPoint, const Size& rDestSize, const BitmapEmit& PDFWriterImpl::createBitmapEmit( const BitmapEx& i_rBitmap, const Graphic& rGraphic ) { BitmapEx aBitmap( i_rBitmap ); + auto ePixelFormat = aBitmap.GetBitmap().getPixelFormat(); if( m_aContext.ColorMode == PDFWriter::DrawGreyscale ) { - int nDepth = aBitmap.GetBitmap().GetBitCount(); - if( nDepth > 1 ) - aBitmap.Convert( BmpConversion::N8BitGreys ); + if (ePixelFormat != vcl::PixelFormat::N1_BPP) + aBitmap.Convert(BmpConversion::N8BitGreys); } BitmapID aID; aID.m_aPixelSize = aBitmap.GetSizePixel(); - aID.m_nSize = aBitmap.GetBitCount(); + aID.m_nSize = vcl::pixelFormatBitCount(ePixelFormat); aID.m_nChecksum = aBitmap.GetBitmap().GetChecksum(); aID.m_nMaskChecksum = 0; if( aBitmap.IsAlpha() ) diff --git a/vcl/source/gdi/pdfwriter_impl2.cxx b/vcl/source/gdi/pdfwriter_impl2.cxx index 1aacbce99934..a0a4fb828995 100644 --- a/vcl/source/gdi/pdfwriter_impl2.cxx +++ b/vcl/source/gdi/pdfwriter_impl2.cxx @@ -163,9 +163,9 @@ void PDFWriterImpl::implWriteBitmapEx( const Point& i_rPoint, const Size& i_rSiz if( m_aContext.ColorMode == PDFWriter::DrawGreyscale ) { - int nDepth = aBitmapEx.GetBitmap().GetBitCount(); - if( nDepth > 1 ) - aBitmapEx.Convert( BmpConversion::N8BitGreys ); + auto ePixelFormat = aBitmapEx.GetBitmap().getPixelFormat(); + if (ePixelFormat != vcl::PixelFormat::N1_BPP) + aBitmapEx.Convert(BmpConversion::N8BitGreys); } bool bUseJPGCompression = !i_rContext.m_bOnlyLosslessCompression; if ( bIsPng || ( aSizePixel.Width() < 32 ) || ( aSizePixel.Height() < 32 ) ) diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx index c5e29a47cd74..e88592f225a5 100644 --- a/vcl/source/gdi/print.cxx +++ b/vcl/source/gdi/print.cxx @@ -197,7 +197,7 @@ void Printer::ImplPrintTransparent( const Bitmap& rBmp, const Bitmap& rMask, Bitmap aPaint( rBmp ), aMask( rMask ); BmpMirrorFlags nMirrFlags = BmpMirrorFlags::NONE; - if( aMask.GetBitCount() > 1 ) + if (aMask.getPixelFormat() > vcl::PixelFormat::N1_BPP) aMask.Convert( BmpConversion::N1BitThreshold ); // mirrored horizontally @@ -792,7 +792,7 @@ void Printer::DrawDeviceMask( const Bitmap& rMask, const Color& rMaskColor, Bitmap aMask( rMask ); BmpMirrorFlags nMirrFlags = BmpMirrorFlags::NONE; - if( aMask.GetBitCount() > 1 ) + if (aMask.getPixelFormat() > vcl::PixelFormat::N1_BPP) aMask.Convert( BmpConversion::N1BitThreshold ); // mirrored horizontally diff --git a/vcl/source/graphic/UnoGraphicDescriptor.cxx b/vcl/source/graphic/UnoGraphicDescriptor.cxx index 6f65828fe992..eabb64a41ca5 100644 --- a/vcl/source/graphic/UnoGraphicDescriptor.cxx +++ b/vcl/source/graphic/UnoGraphicDescriptor.cxx @@ -370,7 +370,10 @@ void GraphicDescriptor::_getPropertyValues( const comphelper::PropertyMapEntry** if( mpGraphic ) { if( mpGraphic->GetType() == GraphicType::Bitmap ) - nBitsPerPixel = mpGraphic->GetBitmapEx().GetBitmap().GetBitCount(); + { + auto ePixelFormat = mpGraphic->GetBitmapEx().GetBitmap().getPixelFormat(); + nBitsPerPixel = vcl::pixelFormatBitCount(ePixelFormat); + } } else nBitsPerPixel = mnBitsPerPixel; diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx index 20c5998c185e..db73c38dabdf 100644 --- a/vcl/source/outdev/bitmap.cxx +++ b/vcl/source/outdev/bitmap.cxx @@ -496,7 +496,7 @@ BitmapEx OutputDevice::GetBitmapEx( const Point& rSrcPt, const Size& rSize ) con Bitmap aAlphaBitmap( mpAlphaVDev->GetBitmap( rSrcPt, rSize ) ); // ensure 8 bit alpha - if( aAlphaBitmap.GetBitCount() > 8 ) + if (aAlphaBitmap.getPixelFormat() > vcl::PixelFormat::N8_BPP) aAlphaBitmap.Convert( BmpConversion::N8BitNoConversion ); return BitmapEx(GetBitmap( rSrcPt, rSize ), AlphaMask( aAlphaBitmap ) ); diff --git a/vcl/source/outdev/transparent.cxx b/vcl/source/outdev/transparent.cxx index a9712a22ee2d..415e3f1597a9 100644 --- a/vcl/source/outdev/transparent.cxx +++ b/vcl/source/outdev/transparent.cxx @@ -418,7 +418,7 @@ void OutputDevice::EmulateDrawTransparent ( const tools::PolyPolygon& rPolyPoly, const tools::Long nB = aFillCol.GetBlue(); tools::Long nX, nY; - if( aPaint.GetBitCount() <= 8 ) + if (vcl::isPalettePixelFormat(aPaint.getPixelFormat())) { const BitmapPalette& rPal = pW->GetPalette(); const sal_uInt16 nCount = rPal.GetEntryCount(); diff --git a/vcl/unx/generic/dtrans/bmp.cxx b/vcl/unx/generic/dtrans/bmp.cxx index 0b5f6f85c236..87328c8712f0 100644 --- a/vcl/unx/generic/dtrans/bmp.cxx +++ b/vcl/unx/generic/dtrans/bmp.cxx @@ -748,10 +748,10 @@ css::uno::Sequence<sal_Int8> x11::convertBitmapDepth( StreamMode::READ); Bitmap bm; ReadDIB(bm, in, true); - if (bm.GetBitCount() == 24 && depth <= 8) { + if (bm.getPixelFormat() == vcl::PixelFormat::N24_BPP && depth <= 8) { bm.Dither(); } - if (bm.GetBitCount() != depth) { + if (vcl::pixelFormatBitCount(bm.getPixelFormat()) != depth) { switch (depth) { case 1: bm.Convert(BmpConversion::N1BitThreshold); |