summaryrefslogtreecommitdiff
path: root/vcl/source
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2020-06-29 21:50:59 +0200
committerLuboš Luňák <l.lunak@collabora.com>2020-07-01 07:36:15 +0200
commit8663d81828541072999b26451f7d6e6bfcb5f951 (patch)
tree860b25d54b3ffab526dc0c0ff4c24ed5d1934fff /vcl/source
parenteb959d4a964e973ea1cf4b066f6007878c22fcf5 (diff)
remove code duplication for BitmapReadAccess pixel functions
Change-Id: Ib243fea4276cfb86b4fdff8d0c84cea7c4523d82 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97487 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'vcl/source')
-rw-r--r--vcl/source/gdi/bmpacc.cxx167
-rw-r--r--vcl/source/gdi/salmisc.cxx36
2 files changed, 78 insertions, 125 deletions
diff --git a/vcl/source/gdi/bmpacc.cxx b/vcl/source/gdi/bmpacc.cxx
index 70500a8b8723..8b7760772880 100644
--- a/vcl/source/gdi/bmpacc.cxx
+++ b/vcl/source/gdi/bmpacc.cxx
@@ -95,9 +95,10 @@ BitmapReadAccess::BitmapReadAccess( Bitmap& rBitmap, BitmapAccessMode nMode ) :
maColorMask = mpBuffer->maColorMask;
- bool bOk = ImplSetAccessPointers(RemoveScanline(mpBuffer->mnFormat));
+ mFncGetPixel = GetPixelFunction(mpBuffer->mnFormat);
+ mFncSetPixel = SetPixelFunction(mpBuffer->mnFormat);
- if (!bOk)
+ if (!mFncGetPixel || !mFncSetPixel)
{
xImpBmp->ReleaseBuffer( mpBuffer, mnAccessMode );
mpBuffer = nullptr;
@@ -117,129 +118,101 @@ namespace
}
}
-bool BitmapReadAccess::ImplSetAccessPointers( ScanlineFormat nFormat )
+FncGetPixel BitmapReadAccess::GetPixelFunction( ScanlineFormat nFormat )
{
- bool bRet = true;
+ switch( RemoveScanline( nFormat ))
+ {
+ case ScanlineFormat::N1BitMsbPal:
+ return GetPixelForN1BitMsbPal;
+ case ScanlineFormat::N1BitLsbPal:
+ return GetPixelForN1BitLsbPal;
+ case ScanlineFormat::N4BitMsnPal:
+ return GetPixelForN4BitMsnPal;
+ case ScanlineFormat::N4BitLsnPal:
+ return GetPixelForN4BitLsnPal;
+ case ScanlineFormat::N8BitPal:
+ return GetPixelForN8BitPal;
+ case ScanlineFormat::N8BitTcMask:
+ return GetPixelForN8BitTcMask;
+ case ScanlineFormat::N24BitTcBgr:
+ return GetPixelForN24BitTcBgr;
+ case ScanlineFormat::N24BitTcRgb:
+ return GetPixelForN24BitTcRgb;
+ case ScanlineFormat::N32BitTcAbgr:
+ if (Bitmap32IsPreMultipled())
+ return GetPixelForN32BitTcAbgr;
+ else
+ return GetPixelForN32BitTcXbgr;
+ case ScanlineFormat::N32BitTcArgb:
+ if (Bitmap32IsPreMultipled())
+ return GetPixelForN32BitTcArgb;
+ else
+ return GetPixelForN32BitTcXrgb;
+ case ScanlineFormat::N32BitTcBgra:
+ if (Bitmap32IsPreMultipled())
+ return GetPixelForN32BitTcBgra;
+ else
+ return GetPixelForN32BitTcBgrx;
+ case ScanlineFormat::N32BitTcRgba:
+ if (Bitmap32IsPreMultipled())
+ return GetPixelForN32BitTcRgba;
+ else
+ return GetPixelForN32BitTcRgbx;
+ case ScanlineFormat::N32BitTcMask:
+ return GetPixelForN32BitTcMask;
+
+ default:
+ return nullptr;
+ }
+}
- switch( nFormat )
+FncSetPixel BitmapReadAccess::SetPixelFunction( ScanlineFormat nFormat )
+{
+ switch( RemoveScanline( nFormat ))
{
case ScanlineFormat::N1BitMsbPal:
- {
- mFncGetPixel = GetPixelForN1BitMsbPal;
- mFncSetPixel = SetPixelForN1BitMsbPal;
- }
- break;
+ return SetPixelForN1BitMsbPal;
case ScanlineFormat::N1BitLsbPal:
- {
- mFncGetPixel = GetPixelForN1BitLsbPal;
- mFncSetPixel = SetPixelForN1BitLsbPal;
- }
- break;
+ return SetPixelForN1BitLsbPal;
case ScanlineFormat::N4BitMsnPal:
- {
- mFncGetPixel = GetPixelForN4BitMsnPal;
- mFncSetPixel = SetPixelForN4BitMsnPal;
- }
- break;
+ return SetPixelForN4BitMsnPal;
case ScanlineFormat::N4BitLsnPal:
- {
- mFncGetPixel = GetPixelForN4BitLsnPal;
- mFncSetPixel = SetPixelForN4BitLsnPal;
- }
- break;
+ return SetPixelForN4BitLsnPal;
case ScanlineFormat::N8BitPal:
- {
- mFncGetPixel = GetPixelForN8BitPal;
- mFncSetPixel = SetPixelForN8BitPal;
- }
- break;
+ return SetPixelForN8BitPal;
case ScanlineFormat::N8BitTcMask:
- {
- mFncGetPixel = GetPixelForN8BitTcMask;
- mFncSetPixel = SetPixelForN8BitTcMask;
- }
- break;
+ return SetPixelForN8BitTcMask;
case ScanlineFormat::N24BitTcBgr:
- {
- mFncGetPixel = GetPixelForN24BitTcBgr;
- mFncSetPixel = SetPixelForN24BitTcBgr;
- }
- break;
+ return SetPixelForN24BitTcBgr;
case ScanlineFormat::N24BitTcRgb:
- {
- mFncGetPixel = GetPixelForN24BitTcRgb;
- mFncSetPixel = SetPixelForN24BitTcRgb;
- }
- break;
+ return SetPixelForN24BitTcRgb;
case ScanlineFormat::N32BitTcAbgr:
- {
if (Bitmap32IsPreMultipled())
- {
- mFncGetPixel = GetPixelForN32BitTcAbgr;
- mFncSetPixel = SetPixelForN32BitTcAbgr;
- }
+ return SetPixelForN32BitTcAbgr;
else
- {
- mFncGetPixel = GetPixelForN32BitTcXbgr;
- mFncSetPixel = SetPixelForN32BitTcXbgr;
- }
- }
- break;
+ return SetPixelForN32BitTcXbgr;
case ScanlineFormat::N32BitTcArgb:
- {
if (Bitmap32IsPreMultipled())
- {
- mFncGetPixel = GetPixelForN32BitTcArgb;
- mFncSetPixel = SetPixelForN32BitTcArgb;
- }
+ return SetPixelForN32BitTcArgb;
else
- {
- mFncGetPixel = GetPixelForN32BitTcXrgb;
- mFncSetPixel = SetPixelForN32BitTcXrgb;
- }
- }
- break;
+ return SetPixelForN32BitTcXrgb;
case ScanlineFormat::N32BitTcBgra:
- {
if (Bitmap32IsPreMultipled())
- {
- mFncGetPixel = GetPixelForN32BitTcBgra;
- mFncSetPixel = SetPixelForN32BitTcBgra;
- }
+ return SetPixelForN32BitTcBgra;
else
- {
- mFncGetPixel = GetPixelForN32BitTcBgrx;
- mFncSetPixel = SetPixelForN32BitTcBgrx;
- }
- }
- break;
+ return SetPixelForN32BitTcBgrx;
case ScanlineFormat::N32BitTcRgba:
- {
if (Bitmap32IsPreMultipled())
- {
- mFncGetPixel = GetPixelForN32BitTcRgba;
- mFncSetPixel = SetPixelForN32BitTcRgba;
- }
+ return SetPixelForN32BitTcRgba;
else
- {
- mFncGetPixel = GetPixelForN32BitTcRgbx;
- mFncSetPixel = SetPixelForN32BitTcRgbx;
- }
- }
- break;
+ return SetPixelForN32BitTcRgbx;
case ScanlineFormat::N32BitTcMask:
- {
- mFncGetPixel = GetPixelForN32BitTcMask;
- mFncSetPixel = SetPixelForN32BitTcMask;
- }
+ return SetPixelForN32BitTcMask;
break;
default:
- bRet = false;
- break;
+ return nullptr;
}
-
- return bRet;
}
BitmapColor BitmapReadAccess::GetInterpolatedColorWithFallback( double fY, double fX, const BitmapColor& rFallback ) const
diff --git a/vcl/source/gdi/salmisc.cxx b/vcl/source/gdi/salmisc.cxx
index a6a5e36279a2..6f790f727ca6 100644
--- a/vcl/source/gdi/salmisc.cxx
+++ b/vcl/source/gdi/salmisc.cxx
@@ -26,11 +26,6 @@
#include <tools/helpers.hxx>
#include <memory>
-#define IMPL_CASE_GET_FORMAT( Format ) \
-case( ScanlineFormat::Format ): \
- pFncGetPixel = BitmapReadAccess::GetPixelFor##Format; \
-break
-
#define IMPL_CASE_SET_FORMAT( Format, BitCount ) \
case( ScanlineFormat::Format ): \
{ \
@@ -270,29 +265,14 @@ std::unique_ptr<BitmapBuffer> StretchAndConvert(
std::unique_ptr<BitmapBuffer> pDstBuffer(new BitmapBuffer);
// set function for getting pixels
- switch( RemoveScanline( rSrcBuffer.mnFormat ) )
- {
- IMPL_CASE_GET_FORMAT( N1BitMsbPal );
- IMPL_CASE_GET_FORMAT( N1BitLsbPal );
- IMPL_CASE_GET_FORMAT( N4BitMsnPal );
- IMPL_CASE_GET_FORMAT( N4BitLsnPal );
- IMPL_CASE_GET_FORMAT( N8BitPal );
- IMPL_CASE_GET_FORMAT( N8BitTcMask );
- IMPL_CASE_GET_FORMAT( N24BitTcBgr );
- IMPL_CASE_GET_FORMAT( N24BitTcRgb );
- IMPL_CASE_GET_FORMAT( N32BitTcAbgr );
- IMPL_CASE_GET_FORMAT( N32BitTcArgb );
- IMPL_CASE_GET_FORMAT( N32BitTcBgra );
- IMPL_CASE_GET_FORMAT( N32BitTcRgba );
- IMPL_CASE_GET_FORMAT( N32BitTcMask );
-
- default:
- // should never come here
- // initialize pFncGetPixel to something valid that is
- // least likely to crash
- pFncGetPixel = BitmapReadAccess::GetPixelForN1BitMsbPal;
- OSL_FAIL( "unknown read format" );
- break;
+ pFncGetPixel = BitmapReadAccess::GetPixelFunction( rSrcBuffer.mnFormat );
+ if( !pFncGetPixel )
+ {
+ // should never come here
+ // initialize pFncGetPixel to something valid that is
+ // least likely to crash
+ pFncGetPixel = BitmapReadAccess::GetPixelForN1BitMsbPal;
+ OSL_FAIL( "unknown read format" );
}
// set function for setting pixels