From ddfc3dcce42ad1dc805f29102f7d056a5809d489 Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Thu, 20 Apr 2017 15:29:25 -0400 Subject: Let {Argb,Cmyk}Decode return tuples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ic4e766d9417f9a9ece5f9e4269d0f96e1e91639b Reviewed-on: https://pdfium-review.googlesource.com/4392 Commit-Queue: Nicolás Peña Reviewed-by: Tom Sepez --- core/fxge/dib/cfx_dibitmap.cpp | 7 ++++-- core/fxge/dib/cfx_imagestretcher.cpp | 47 ++++++++++++++++++++++++------------ core/fxge/dib/fx_dib_main.cpp | 15 ++++++------ 3 files changed, 44 insertions(+), 25 deletions(-) (limited to 'core/fxge/dib') diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp index 760b26f23a..6f46e1d57e 100644 --- a/core/fxge/dib/cfx_dibitmap.cpp +++ b/core/fxge/dib/cfx_dibitmap.cpp @@ -147,8 +147,11 @@ void CFX_DIBitmap::Clear(uint32_t color) { } case FXDIB_Rgb: case FXDIB_Rgba: { - int a, r, g, b; - ArgbDecode(color, a, r, g, b); + int a; + int r; + int g; + int b; + std::tie(a, r, g, b) = ArgbDecode(color); if (r == g && g == b) { memset(pBuffer, r, m_Pitch * m_Height); } else { diff --git a/core/fxge/dib/cfx_imagestretcher.cpp b/core/fxge/dib/cfx_imagestretcher.cpp index f52a62d529..e0ba750c3c 100644 --- a/core/fxge/dib/cfx_imagestretcher.cpp +++ b/core/fxge/dib/cfx_imagestretcher.cpp @@ -7,6 +7,7 @@ #include "core/fxge/dib/cfx_imagestretcher.h" #include +#include #include "core/fxge/dib/cfx_dibitmap.h" #include "core/fxge/dib/cfx_dibsource.h" @@ -16,8 +17,9 @@ namespace { +const int kMaxProgressiveStretchPixels = 1000000; + bool SourceSizeWithinLimit(int width, int height) { - const int kMaxProgressiveStretchPixels = 1000000; return !height || width < kMaxProgressiveStretchPixels / height; } @@ -32,11 +34,10 @@ FXDIB_Format GetStretchedFormat(const CFX_DIBSource& src) { return format; } -void CmykDecode(uint32_t cmyk, int& c, int& m, int& y, int& k) { - c = FXSYS_GetCValue(cmyk); - m = FXSYS_GetMValue(cmyk); - y = FXSYS_GetYValue(cmyk); - k = FXSYS_GetKValue(cmyk); +// Returns tuple c, m, y, k +std::tuple CmykDecode(const uint32_t cmyk) { + return std::make_tuple(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk), + FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk)); } } // namespace @@ -68,10 +69,17 @@ bool CFX_ImageStretcher::Start() { if (m_pSource->GetFormat() == FXDIB_1bppRgb && m_pSource->GetPalette()) { FX_ARGB pal[256]; - int a0, r0, g0, b0, a1, r1, g1, b1; - ArgbDecode(m_pSource->GetPaletteEntry(0), a0, r0, g0, b0); - ArgbDecode(m_pSource->GetPaletteEntry(1), a1, r1, g1, b1); - for (int i = 0; i < 256; i++) { + int a0; + int r0; + int g0; + int b0; + std::tie(a0, r0, g0, b0) = ArgbDecode(m_pSource->GetPaletteEntry(0)); + int a1; + int r1; + int g1; + int b1; + std::tie(a1, r1, g1, b1) = ArgbDecode(m_pSource->GetPaletteEntry(1)); + for (int i = 0; i < 256; ++i) { int a = a0 + (a1 - a0) * i / 255; int r = r0 + (r1 - r0) * i / 255; int g = g0 + (g1 - g0) * i / 255; @@ -85,10 +93,17 @@ bool CFX_ImageStretcher::Start() { } else if (m_pSource->GetFormat() == FXDIB_1bppCmyk && m_pSource->GetPalette()) { FX_CMYK pal[256]; - int c0, m0, y0, k0, c1, m1, y1, k1; - CmykDecode(m_pSource->GetPaletteEntry(0), c0, m0, y0, k0); - CmykDecode(m_pSource->GetPaletteEntry(1), c1, m1, y1, k1); - for (int i = 0; i < 256; i++) { + int c0; + int m0; + int y0; + int k0; + std::tie(c0, m0, y0, k0) = CmykDecode(m_pSource->GetPaletteEntry(0)); + int c1; + int m1; + int y1; + int k1; + std::tie(c1, m1, y1, k1) = CmykDecode(m_pSource->GetPaletteEntry(1)); + for (int i = 0; i < 256; ++i) { int c = c0 + (c1 - c0) * i / 255; int m = m0 + (m1 - m0) * i / 255; int y = y0 + (y1 - y0) * i / 255; @@ -106,12 +121,14 @@ bool CFX_ImageStretcher::Start() { if (m_Flags & FXDIB_DOWNSAMPLE) return StartQuickStretch(); + return StartStretch(); } bool CFX_ImageStretcher::Continue(IFX_Pause* pPause) { if (m_Flags & FXDIB_DOWNSAMPLE) return ContinueQuickStretch(pPause); + return ContinueStretch(pPause); } @@ -163,7 +180,7 @@ bool CFX_ImageStretcher::ContinueQuickStretch(IFX_Pause* pPause) { int result_width = m_ClipRect.Width(); int result_height = m_ClipRect.Height(); int src_height = m_pSource->GetHeight(); - for (; m_LineIndex < result_height; m_LineIndex++) { + for (; m_LineIndex < result_height; ++m_LineIndex) { int dest_y; int src_y; if (m_bFlipY) { diff --git a/core/fxge/dib/fx_dib_main.cpp b/core/fxge/dib/fx_dib_main.cpp index 97b1aa7cca..3ede85c480 100644 --- a/core/fxge/dib/fx_dib_main.cpp +++ b/core/fxge/dib/fx_dib_main.cpp @@ -6,6 +6,7 @@ #include "core/fxge/fx_dib.h" +#include #include #include "third_party/base/ptr_util.h" @@ -72,16 +73,14 @@ FX_RECT FXDIB_SwapClipBox(FX_RECT& clip, return rect; } -void ArgbDecode(uint32_t argb, int& a, int& r, int& g, int& b) { - a = FXARGB_A(argb); - r = FXARGB_R(argb); - g = FXARGB_G(argb); - b = FXARGB_B(argb); +std::tuple ArgbDecode(FX_ARGB argb) { + return std::make_tuple(FXARGB_A(argb), FXARGB_R(argb), FXARGB_G(argb), + FXARGB_B(argb)); } -void ArgbDecode(uint32_t argb, int& a, FX_COLORREF& rgb) { - a = FXARGB_A(argb); - rgb = FXSYS_RGB(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb)); +std::pair ArgbToColorRef(FX_ARGB argb) { + return {FXARGB_A(argb), + FXSYS_RGB(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb))}; } uint32_t ArgbEncode(int a, FX_COLORREF rgb) { -- cgit v1.2.3