summaryrefslogtreecommitdiff
path: root/vcl/source/gdi
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-03-27 10:14:13 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-04-02 06:28:39 +0200
commit88a177f827eba204dea92b631032411de8213ee4 (patch)
tree3107896970ac35f9fd1cb3804634efdef78c2313 /vcl/source/gdi
parent465b8b0e9ad4b0c9c7701dee2820a99c5d00b5bf (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/source/gdi')
-rw-r--r--vcl/source/gdi/mtfxmldump.cxx15
-rw-r--r--vcl/source/gdi/pdfextoutdevdata.cxx4
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx53
-rw-r--r--vcl/source/gdi/pdfwriter_impl2.cxx6
-rw-r--r--vcl/source/gdi/print.cxx4
5 files changed, 49 insertions, 33 deletions
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