From 7a68198438f41e19f21e06e0f3447e525d0b253b Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Wed, 19 Apr 2017 18:02:56 -0400 Subject: Split up CFX_DIBitmap::ConvertColorScale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code is completely separated into CMYK vs RGB cases, so having two separate private methods is better. Change-Id: I67f885ee2f4393b722c6d6e770b230a5aa6b0cb1 Reviewed-on: https://pdfium-review.googlesource.com/4372 Commit-Queue: Nicolás Peña Reviewed-by: dsinclair Reviewed-by: Wei Li --- core/fxge/dib/cfx_dibitmap.cpp | 215 ++++++++++++++++++++--------------------- core/fxge/dib/cfx_dibitmap.h | 4 + 2 files changed, 107 insertions(+), 112 deletions(-) diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp index 61eba3fd74..760b26f23a 100644 --- a/core/fxge/dib/cfx_dibitmap.cpp +++ b/core/fxge/dib/cfx_dibitmap.cpp @@ -686,104 +686,35 @@ void CFX_DIBitmap::DownSampleScanline(int line, } } -// TODO(weili): Split this function into two for handling CMYK and RGB -// colors separately. -bool CFX_DIBitmap::ConvertColorScale(uint32_t forecolor, uint32_t backcolor) { - ASSERT(!IsAlphaMask()); - if (!m_pBuffer || IsAlphaMask()) - return false; - - // Values used for CMYK colors. - int fc = 0; - int fm = 0; - int fy = 0; - int fk = 0; - int bc = 0; - int bm = 0; - int by = 0; - int bk = 0; - // Values used for RGB colors. - int fr = 0; - int fg = 0; - int fb = 0; - int br = 0; - int bg = 0; - int bb = 0; - bool isCmykImage = IsCmykImage(); - if (isCmykImage) { - fc = FXSYS_GetCValue(forecolor); - fm = FXSYS_GetMValue(forecolor); - fy = FXSYS_GetYValue(forecolor); - fk = FXSYS_GetKValue(forecolor); - bc = FXSYS_GetCValue(backcolor); - bm = FXSYS_GetMValue(backcolor); - by = FXSYS_GetYValue(backcolor); - bk = FXSYS_GetKValue(backcolor); - } else { - fr = FXSYS_GetRValue(forecolor); - fg = FXSYS_GetGValue(forecolor); - fb = FXSYS_GetBValue(forecolor); - br = FXSYS_GetRValue(backcolor); - bg = FXSYS_GetGValue(backcolor); - bb = FXSYS_GetBValue(backcolor); - } +void CFX_DIBitmap::ConvertRGBColorScale(uint32_t forecolor, + uint32_t backcolor) { + int fr = FXSYS_GetRValue(forecolor); + int fg = FXSYS_GetGValue(forecolor); + int fb = FXSYS_GetBValue(forecolor); + int br = FXSYS_GetRValue(backcolor); + int bg = FXSYS_GetGValue(backcolor); + int bb = FXSYS_GetBValue(backcolor); if (m_bpp <= 8) { - if (isCmykImage) { - if (forecolor == 0xff && backcolor == 0 && !m_pPalette) { - return true; - } - } else if (forecolor == 0 && backcolor == 0xffffff && !m_pPalette) { - return true; - } - if (!m_pPalette) { + if (forecolor == 0 && backcolor == 0xffffff && !m_pPalette) + return; + if (!m_pPalette) BuildPalette(); - } int size = 1 << m_bpp; - if (isCmykImage) { - for (int i = 0; i < size; i++) { - uint8_t b, g, r; - AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette.get()[i]), - FXSYS_GetMValue(m_pPalette.get()[i]), - FXSYS_GetYValue(m_pPalette.get()[i]), - FXSYS_GetKValue(m_pPalette.get()[i]), r, g, b); - int gray = 255 - FXRGB2GRAY(r, g, b); - m_pPalette.get()[i] = CmykEncode( - bc + (fc - bc) * gray / 255, bm + (fm - bm) * gray / 255, - by + (fy - by) * gray / 255, bk + (fk - bk) * gray / 255); - } - } else { - for (int i = 0; i < size; i++) { - int gray = FXRGB2GRAY(FXARGB_R(m_pPalette.get()[i]), - FXARGB_G(m_pPalette.get()[i]), - FXARGB_B(m_pPalette.get()[i])); - m_pPalette.get()[i] = FXARGB_MAKE(0xff, br + (fr - br) * gray / 255, - bg + (fg - bg) * gray / 255, - bb + (fb - bb) * gray / 255); - } + for (int i = 0; i < size; ++i) { + int gray = FXRGB2GRAY(FXARGB_R(m_pPalette.get()[i]), + FXARGB_G(m_pPalette.get()[i]), + FXARGB_B(m_pPalette.get()[i])); + m_pPalette.get()[i] = + FXARGB_MAKE(0xff, br + (fr - br) * gray / 255, + bg + (fg - bg) * gray / 255, bb + (fb - bb) * gray / 255); } - return true; + return; } - if (isCmykImage) { - if (forecolor == 0xff && backcolor == 0x00) { - for (int row = 0; row < m_Height; row++) { - uint8_t* scanline = m_pBuffer.Get() + row * m_Pitch; - for (int col = 0; col < m_Width; col++) { - uint8_t b, g, r; - AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanline[3], - r, g, b); - *scanline++ = 0; - *scanline++ = 0; - *scanline++ = 0; - *scanline++ = 255 - FXRGB2GRAY(r, g, b); - } - } - return true; - } - } else if (forecolor == 0 && backcolor == 0xffffff) { - for (int row = 0; row < m_Height; row++) { + if (forecolor == 0 && backcolor == 0xffffff) { + for (int row = 0; row < m_Height; ++row) { uint8_t* scanline = m_pBuffer.Get() + row * m_Pitch; int gap = m_bpp / 8 - 2; - for (int col = 0; col < m_Width; col++) { + for (int col = 0; col < m_Width; ++col) { int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]); *scanline++ = gray; *scanline++ = gray; @@ -791,35 +722,95 @@ bool CFX_DIBitmap::ConvertColorScale(uint32_t forecolor, uint32_t backcolor) { scanline += gap; } } - return true; + return; } - if (isCmykImage) { - for (int row = 0; row < m_Height; row++) { + for (int row = 0; row < m_Height; ++row) { + uint8_t* scanline = m_pBuffer.Get() + row * m_Pitch; + int gap = m_bpp / 8 - 2; + for (int col = 0; col < m_Width; ++col) { + int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]); + *scanline++ = bb + (fb - bb) * gray / 255; + *scanline++ = bg + (fg - bg) * gray / 255; + *scanline = br + (fr - br) * gray / 255; + scanline += gap; + } + } +} + +void CFX_DIBitmap::ConvertCMYKColorScale(uint32_t forecolor, + uint32_t backcolor) { + int fc = FXSYS_GetCValue(forecolor); + int fm = FXSYS_GetMValue(forecolor); + int fy = FXSYS_GetYValue(forecolor); + int fk = FXSYS_GetKValue(forecolor); + int bc = FXSYS_GetCValue(backcolor); + int bm = FXSYS_GetMValue(backcolor); + int by = FXSYS_GetYValue(backcolor); + int bk = FXSYS_GetKValue(backcolor); + if (m_bpp <= 8) { + if (forecolor == 0xff && backcolor == 0 && !m_pPalette) + return; + if (!m_pPalette) + BuildPalette(); + int size = 1 << m_bpp; + for (int i = 0; i < size; ++i) { + uint8_t r; + uint8_t g; + uint8_t b; + AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette.get()[i]), + FXSYS_GetMValue(m_pPalette.get()[i]), + FXSYS_GetYValue(m_pPalette.get()[i]), + FXSYS_GetKValue(m_pPalette.get()[i]), r, g, b); + int gray = 255 - FXRGB2GRAY(r, g, b); + m_pPalette.get()[i] = + CmykEncode(bc + (fc - bc) * gray / 255, bm + (fm - bm) * gray / 255, + by + (fy - by) * gray / 255, bk + (fk - bk) * gray / 255); + } + return; + } + if (forecolor == 0xff && backcolor == 0x00) { + for (int row = 0; row < m_Height; ++row) { uint8_t* scanline = m_pBuffer.Get() + row * m_Pitch; - for (int col = 0; col < m_Width; col++) { - uint8_t b, g, r; + for (int col = 0; col < m_Width; ++col) { + uint8_t r; + uint8_t g; + uint8_t b; AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanline[3], r, g, b); - int gray = 255 - FXRGB2GRAY(r, g, b); - *scanline++ = bc + (fc - bc) * gray / 255; - *scanline++ = bm + (fm - bm) * gray / 255; - *scanline++ = by + (fy - by) * gray / 255; - *scanline++ = bk + (fk - bk) * gray / 255; + *scanline++ = 0; + *scanline++ = 0; + *scanline++ = 0; + *scanline++ = 255 - FXRGB2GRAY(r, g, b); } } - } else { - for (int row = 0; row < m_Height; row++) { - uint8_t* scanline = m_pBuffer.Get() + row * m_Pitch; - int gap = m_bpp / 8 - 2; - for (int col = 0; col < m_Width; col++) { - int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]); - *scanline++ = bb + (fb - bb) * gray / 255; - *scanline++ = bg + (fg - bg) * gray / 255; - *scanline = br + (fr - br) * gray / 255; - scanline += gap; - } + return; + } + for (int row = 0; row < m_Height; ++row) { + uint8_t* scanline = m_pBuffer.Get() + row * m_Pitch; + for (int col = 0; col < m_Width; ++col) { + uint8_t r; + uint8_t g; + uint8_t b; + AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanline[3], r, + g, b); + int gray = 255 - FXRGB2GRAY(r, g, b); + *scanline++ = bc + (fc - bc) * gray / 255; + *scanline++ = bm + (fm - bm) * gray / 255; + *scanline++ = by + (fy - by) * gray / 255; + *scanline++ = bk + (fk - bk) * gray / 255; } } +} + +bool CFX_DIBitmap::ConvertColorScale(uint32_t forecolor, uint32_t backcolor) { + ASSERT(!IsAlphaMask()); + if (!m_pBuffer || IsAlphaMask()) + return false; + + if (IsCmykImage()) + ConvertCMYKColorScale(forecolor, backcolor); + else + ConvertRGBColorScale(forecolor, backcolor); return true; } diff --git a/core/fxge/dib/cfx_dibitmap.h b/core/fxge/dib/cfx_dibitmap.h index 6fd4b7c89a..df751db3df 100644 --- a/core/fxge/dib/cfx_dibitmap.h +++ b/core/fxge/dib/cfx_dibitmap.h @@ -115,6 +115,10 @@ class CFX_DIBitmap : public CFX_DIBSource { #if defined _SKIA_SUPPORT_PATHS_ Format m_nFormat; #endif + + private: + void ConvertRGBColorScale(uint32_t forecolor, uint32_t backcolor); + void ConvertCMYKColorScale(uint32_t forecolor, uint32_t backcolor); }; #endif // CORE_FXGE_DIB_CFX_DIBITMAP_H_ -- cgit v1.2.3