From fa2dd2ba03f8be1f148dca8f6164daaf7bbf7d96 Mon Sep 17 00:00:00 2001 From: Chris Sherlock Date: Sat, 24 Feb 2018 18:00:29 +1100 Subject: vcl: consolidate ColorOf() and GrayOf() functions Change-Id: Ic80dda409ceaff89be5f249cf906abbb40679f3c Reviewed-on: https://gerrit.libreoffice.org/50272 Reviewed-by: Noel Grandin Tested-by: Noel Grandin --- vcl/unx/generic/print/genpspgraphics.cxx | 66 ++++++++++++++------------------ 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/vcl/unx/generic/print/genpspgraphics.cxx b/vcl/unx/generic/print/genpspgraphics.cxx index 3f9b12257fee..e0556e2d8fd2 100644 --- a/vcl/unx/generic/print/genpspgraphics.cxx +++ b/vcl/unx/generic/print/genpspgraphics.cxx @@ -69,18 +69,15 @@ private: Scanline mpScanAccess; sal_PtrDiff mnScanOffset; - sal_uInt32 ColorOf (BitmapColor const & rColor) const; - sal_uInt8 GrayOf (BitmapColor const & rColor) const; - - public: - - explicit SalPrinterBmp (BitmapBuffer* pBitmap); - virtual sal_uInt32 GetPaletteColor (sal_uInt32 nIdx) const override; - virtual sal_uInt32 GetPaletteEntryCount () const override; - virtual sal_uInt32 GetPixelRGB (sal_uInt32 nRow, sal_uInt32 nColumn) const override; - virtual sal_uInt8 GetPixelGray (sal_uInt32 nRow, sal_uInt32 nColumn) const override; - virtual sal_uInt8 GetPixelIdx (sal_uInt32 nRow, sal_uInt32 nColumn) const override; - virtual sal_uInt32 GetDepth () const override; +public: + explicit SalPrinterBmp (BitmapBuffer* pBitmap); + + virtual sal_uInt32 GetPaletteColor (sal_uInt32 nIdx) const override; + virtual sal_uInt32 GetPaletteEntryCount () const override; + virtual sal_uInt32 GetPixelRGB (sal_uInt32 nRow, sal_uInt32 nColumn) const override; + virtual sal_uInt8 GetPixelGray (sal_uInt32 nRow, sal_uInt32 nColumn) const override; + virtual sal_uInt8 GetPixelIdx (sal_uInt32 nRow, sal_uInt32 nColumn) const override; + virtual sal_uInt32 GetDepth () const override; }; SalPrinterBmp::SalPrinterBmp (BitmapBuffer* pBuffer) @@ -173,28 +170,6 @@ SalPrinterBmp::GetDepth () const return nDepth; } -sal_uInt32 -SalPrinterBmp::ColorOf (BitmapColor const & rColor) const -{ - if (rColor.IsIndex()) - return ColorOf (mpBmpBuffer->maPalette[rColor.GetIndex()]); - else - return ((rColor.GetBlue()) & 0x000000ff) - | ((rColor.GetGreen() << 8) & 0x0000ff00) - | ((rColor.GetRed() << 16) & 0x00ff0000); -} - -sal_uInt8 -SalPrinterBmp::GrayOf (BitmapColor const & rColor) const -{ - if (rColor.IsIndex()) - return GrayOf (mpBmpBuffer->maPalette[rColor.GetIndex()]); - else - return ( rColor.GetBlue() * 28UL - + rColor.GetGreen() * 151UL - + rColor.GetRed() * 77UL ) >> 8; -} - sal_uInt32 SalPrinterBmp::GetPaletteEntryCount () const { @@ -202,9 +177,13 @@ SalPrinterBmp::GetPaletteEntryCount () const } sal_uInt32 -SalPrinterBmp::GetPaletteColor (sal_uInt32 nIdx) const +SalPrinterBmp::GetPaletteColor(sal_uInt32 nIdx) const { - return ColorOf (mpBmpBuffer->maPalette[nIdx]); + BitmapColor aColor(mpBmpBuffer->maPalette[nIdx]); + + return ((aColor.GetBlue()) & 0x000000ff) + | ((aColor.GetGreen() << 8) & 0x0000ff00) + | ((aColor.GetRed() << 16) & 0x00ff0000); } sal_uInt32 @@ -213,7 +192,12 @@ SalPrinterBmp::GetPixelRGB (sal_uInt32 nRow, sal_uInt32 nColumn) const Scanline pScan = mpScanAccess + nRow * mnScanOffset; BitmapColor aColor = mpFncGetPixel (pScan, nColumn, mpBmpBuffer->maColorMask); - return ColorOf (aColor); + if (aColor.IsIndex()) + GetPaletteColor(aColor.GetIndex()); + + return ((aColor.GetBlue()) & 0x000000ff) + | ((aColor.GetGreen() << 8) & 0x0000ff00) + | ((aColor.GetRed() << 16) & 0x00ff0000); } sal_uInt8 @@ -222,7 +206,13 @@ SalPrinterBmp::GetPixelGray (sal_uInt32 nRow, sal_uInt32 nColumn) const Scanline pScan = mpScanAccess + nRow * mnScanOffset; BitmapColor aColor = mpFncGetPixel (pScan, nColumn, mpBmpBuffer->maColorMask); - return GrayOf (aColor); + if (aColor.IsIndex()) + aColor = mpBmpBuffer->maPalette[aColor.GetIndex()]; + + return ( aColor.GetBlue() * 28UL + + aColor.GetGreen() * 151UL + + aColor.GetRed() * 77UL ) >> 8; + } sal_uInt8 -- cgit