diff options
-rw-r--r-- | core/fpdfapi/page/cpdf_image.cpp | 7 | ||||
-rw-r--r-- | core/fpdfapi/render/cpdf_renderoptions.cpp | 7 | ||||
-rw-r--r-- | core/fxge/agg/fx_agg_driver.cpp | 2 | ||||
-rw-r--r-- | core/fxge/apple/fx_quartz_device.cpp | 7 | ||||
-rw-r--r-- | core/fxge/dib/cfx_dibitmap.cpp | 7 | ||||
-rw-r--r-- | core/fxge/dib/cfx_imagestretcher.cpp | 47 | ||||
-rw-r--r-- | core/fxge/dib/fx_dib_main.cpp | 15 | ||||
-rw-r--r-- | core/fxge/fx_dib.h | 9 | ||||
-rw-r--r-- | core/fxge/ge/cfx_renderdevice.cpp | 2 | ||||
-rw-r--r-- | core/fxge/win32/fx_win32_device.cpp | 8 | ||||
-rw-r--r-- | core/fxge/win32/fx_win32_gdipext.cpp | 7 | ||||
-rw-r--r-- | core/fxge/win32/fx_win32_print.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/javascript/Field.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffwidget.cpp | 7 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_fill.cpp | 7 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 11 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_stroke.cpp | 2 | ||||
-rw-r--r-- | xfa/fxgraphics/cfx_shading.cpp | 6 |
18 files changed, 97 insertions, 58 deletions
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp index da49fab8b1..2c117fdc71 100644 --- a/core/fpdfapi/page/cpdf_image.cpp +++ b/core/fpdfapi/page/cpdf_image.cpp @@ -183,9 +183,10 @@ void CPDF_Image::SetImage(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) { int32_t set_g = 0; int32_t set_b = 0; if (!pBitmap->IsAlphaMask()) { - ArgbDecode(pBitmap->GetPaletteArgb(0), reset_a, reset_r, reset_g, - reset_b); - ArgbDecode(pBitmap->GetPaletteArgb(1), set_a, set_r, set_g, set_b); + std::tie(reset_a, reset_r, reset_g, reset_b) = + ArgbDecode(pBitmap->GetPaletteArgb(0)); + std::tie(set_a, set_r, set_g, set_b) = + ArgbDecode(pBitmap->GetPaletteArgb(1)); } if (set_a == 0 || reset_a == 0) { pDict->SetNewFor<CPDF_Boolean>("ImageMask", true); diff --git a/core/fpdfapi/render/cpdf_renderoptions.cpp b/core/fpdfapi/render/cpdf_renderoptions.cpp index 717e036fea..70a4cf9615 100644 --- a/core/fpdfapi/render/cpdf_renderoptions.cpp +++ b/core/fpdfapi/render/cpdf_renderoptions.cpp @@ -36,8 +36,11 @@ FX_ARGB CPDF_RenderOptions::TranslateColor(FX_ARGB argb) const { if (m_ColorMode == RENDER_COLOR_ALPHA) return argb; - int a, r, g, b; - ArgbDecode(argb, a, r, g, b); + int a; + int r; + int g; + int b; + std::tie(a, r, g, b) = ArgbDecode(argb); int gray = FXRGB2GRAY(r, g, b); if (m_ColorMode == RENDER_COLOR_TWOCOLOR) { int color = (r - gray) * (r - gray) + (g - gray) * (g - gray) + diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp index b5ec4c5096..471fc9bb86 100644 --- a/core/fxge/agg/fx_agg_driver.cpp +++ b/core/fxge/agg/fx_agg_driver.cpp @@ -923,7 +923,7 @@ bool CFX_Renderer::Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice, m_Color = FXARGB_TOBGRORDERDIB(color); else m_Color = FXARGB_TODIB(color); - ArgbDecode(color, m_Alpha, m_Red, m_Green, m_Blue); + std::tie(m_Alpha, m_Red, m_Green, m_Blue) = ArgbDecode(color); if (m_pDevice->GetBPP() == 1) composite_span = &CFX_Renderer::CompositeSpan1bpp; return true; diff --git a/core/fxge/apple/fx_quartz_device.cpp b/core/fxge/apple/fx_quartz_device.cpp index 15d05b0c2a..5151b02d8b 100644 --- a/core/fxge/apple/fx_quartz_device.cpp +++ b/core/fxge/apple/fx_quartz_device.cpp @@ -94,8 +94,11 @@ bool CQuartz2D::drawGraphicsString(void* graphics, matrix->e, matrix->f)); CGContextSetTextMatrix(context, m); } - int32_t a, r, g, b; - ArgbDecode(argb, a, r, g, b); + int32_t a; + int32_t r; + int32_t g; + int32_t b; + std::tie(a, r, g, b) = ArgbDecode(argb); CGContextSetRGBFillColor(context, r / 255.f, g / 255.f, b / 255.f, a / 255.f); CGContextSaveGState(context); #if CGFLOAT_IS_DOUBLE 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 <climits> +#include <tuple> #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<int, int, int, int> 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 <tuple> #include <utility> #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<int, int, int, int> 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<int, FX_COLORREF> 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) { diff --git a/core/fxge/fx_dib.h b/core/fxge/fx_dib.h index 17c7c8fd0a..fa38573df8 100644 --- a/core/fxge/fx_dib.h +++ b/core/fxge/fx_dib.h @@ -7,6 +7,9 @@ #ifndef CORE_FXGE_FX_DIB_H_ #define CORE_FXGE_FX_DIB_H_ +#include <tuple> +#include <utility> + #include "core/fxcrt/fx_coordinates.h" enum FXDIB_Format { @@ -80,8 +83,10 @@ inline FX_CMYK CmykEncode(int c, int m, int y, int k) { return (c << 24) | (m << 16) | (y << 8) | k; } -void ArgbDecode(FX_ARGB argb, int& a, int& r, int& g, int& b); -void ArgbDecode(FX_ARGB argb, int& a, FX_COLORREF& rgb); +// Returns tuple a, r, g, b +std::tuple<int, int, int, int> ArgbDecode(FX_ARGB argb); +// Returns pair a, rgb +std::pair<int, FX_COLORREF> ArgbToColorRef(FX_ARGB argb); inline FX_ARGB ArgbEncode(int a, int r, int g, int b) { return (a << 24) | (r << 16) | (g << 8) | b; } diff --git a/core/fxge/ge/cfx_renderdevice.cpp b/core/fxge/ge/cfx_renderdevice.cpp index 46127ccb07..6a3f9c7f1c 100644 --- a/core/fxge/ge/cfx_renderdevice.cpp +++ b/core/fxge/ge/cfx_renderdevice.cpp @@ -1018,7 +1018,7 @@ bool CFX_RenderDevice::DrawNormalText(int nChars, int g = 0; int b = 0; if (anti_alias == FXFT_RENDER_MODE_LCD) - ArgbDecode(fill_color, a, r, g, b); + std::tie(a, r, g, b) = ArgbDecode(fill_color); for (const FXTEXT_GLYPHPOS& glyph : glyphs) { if (!glyph.m_pGlyph) diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp index 986839ee88..de2f6c4b04 100644 --- a/core/fxge/win32/fx_win32_device.cpp +++ b/core/fxge/win32/fx_win32_device.cpp @@ -137,7 +137,7 @@ HPEN CreatePen(const CFX_GraphStateData* pGraphState, } int a; FX_COLORREF rgb; - ArgbDecode(argb, a, rgb); + std::tie(a, rgb) = ArgbToColorRef(argb); LOGBRUSH lb; lb.lbColor = rgb; lb.lbStyle = BS_SOLID; @@ -160,7 +160,7 @@ HPEN CreatePen(const CFX_GraphStateData* pGraphState, HBRUSH CreateBrush(uint32_t argb) { int a; FX_COLORREF rgb; - ArgbDecode(argb, a, rgb); + std::tie(a, rgb) = ArgbToColorRef(argb); return CreateSolidBrush(rgb); } @@ -1090,7 +1090,7 @@ bool CGdiDeviceDriver::FillRectWithBlend(const FX_RECT* pRect, int alpha; FX_COLORREF rgb; - ArgbDecode(fill_color, alpha, rgb); + std::tie(alpha, rgb) = ArgbToColorRef(fill_color); if (alpha == 0) return true; @@ -1146,7 +1146,7 @@ bool CGdiDeviceDriver::DrawCosmeticLine(float x1, int a; FX_COLORREF rgb; - ArgbDecode(color, a, rgb); + std::tie(a, rgb) = ArgbToColorRef(color); if (a == 0) return true; diff --git a/core/fxge/win32/fx_win32_gdipext.cpp b/core/fxge/win32/fx_win32_gdipext.cpp index 6a3527f393..87172ffff8 100644 --- a/core/fxge/win32/fx_win32_gdipext.cpp +++ b/core/fxge/win32/fx_win32_gdipext.cpp @@ -575,8 +575,11 @@ static void OutputImageMask(GpGraphics* pGraphics, (image_clip.Width() + 3) / 4 * 4, PixelFormat8bppIndexed, pStretched->GetBuffer(), &bitmap); - int a, r, g, b; - ArgbDecode(argb, a, r, g, b); + int a; + int r; + int g; + int b; + std::tie(a, r, g, b) = ArgbDecode(argb); UINT pal[258]; pal[0] = 0; pal[1] = 256; diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp index 58f00ed0fb..86636b5bfa 100644 --- a/core/fxge/win32/fx_win32_print.cpp +++ b/core/fxge/win32/fx_win32_print.cpp @@ -282,7 +282,7 @@ bool CGdiPrinterDriver::DrawDeviceText(int nChars, // Color int iUnusedAlpha; FX_COLORREF rgb; - ArgbDecode(color, iUnusedAlpha, rgb); + std::tie(iUnusedAlpha, rgb) = ArgbToColorRef(color); SetTextColor(m_hDC, rgb); SetBkMode(m_hDC, TRANSPARENT); diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp index c7dc2608ca..8e4b465d5e 100644 --- a/fpdfsdk/javascript/Field.cpp +++ b/fpdfsdk/javascript/Field.cpp @@ -2381,7 +2381,7 @@ bool Field::textColor(CJS_Runtime* pRuntime, int32_t r; int32_t g; int32_t b; - ArgbDecode(color, a, r, g, b); + std::tie(a, r, g, b) = ArgbDecode(color); CPWL_Color crRet = CPWL_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f); diff --git a/xfa/fxfa/cxfa_ffwidget.cpp b/xfa/fxfa/cxfa_ffwidget.cpp index bdadba7c85..06de436e09 100644 --- a/xfa/fxfa/cxfa_ffwidget.cpp +++ b/xfa/fxfa/cxfa_ffwidget.cpp @@ -1660,12 +1660,11 @@ static void XFA_BOX_Fill(CXFA_Box box, FX_ARGB cr; if (eType == XFA_Element::Stipple) { int32_t iRate = fill.GetStipple(cr); - if (iRate == 0) { + if (iRate == 0) iRate = 100; - } - int32_t a = 0; + int32_t a; FX_COLORREF rgb; - ArgbDecode(cr, a, rgb); + std::tie(a, rgb) = ArgbToColorRef(cr); cr = ArgbEncode(iRate * a / 100, rgb); } else { cr = fill.GetColor(); diff --git a/xfa/fxfa/parser/cxfa_fill.cpp b/xfa/fxfa/parser/cxfa_fill.cpp index 8621c3c961..8a7969d5e4 100644 --- a/xfa/fxfa/parser/cxfa_fill.cpp +++ b/xfa/fxfa/parser/cxfa_fill.cpp @@ -19,8 +19,11 @@ int32_t CXFA_Fill::GetPresence() { void CXFA_Fill::SetColor(FX_ARGB color) { CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_Element::Color); CFX_WideString wsColor; - 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); wsColor.Format(L"%d,%d,%d", r, g, b); pNode->SetCData(XFA_ATTRIBUTE_Value, wsColor); } diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index d6d2ece428..73fc88db8f 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -2054,8 +2054,11 @@ void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue, } else { CXFA_Edge edge = border.GetEdge(0); FX_ARGB color = edge.GetColor(); - int32_t a, r, g, b; - ArgbDecode(color, a, r, g, b); + int32_t a; + int32_t r; + int32_t g; + int32_t b; + std::tie(a, r, g, b) = ArgbDecode(color); CFX_WideString strColor; strColor.Format(L"%d,%d,%d", r, g, b); pValue->SetString(strColor.UTF8Encode().AsStringC()); @@ -2113,7 +2116,7 @@ void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue, int32_t r; int32_t g; int32_t b; - ArgbDecode(color, a, r, g, b); + std::tie(a, r, g, b) = ArgbDecode(color); CFX_WideString wsColor; wsColor.Format(L"%d,%d,%d", r, g, b); pValue->SetString(wsColor.UTF8Encode().AsStringC()); @@ -2265,7 +2268,7 @@ void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue, int32_t r; int32_t g; int32_t b; - ArgbDecode(color, a, r, g, b); + std::tie(a, r, g, b) = ArgbDecode(color); CFX_WideString wsColor; wsColor.Format(L"%d,%d,%d", r, g, b); pValue->SetString(wsColor.UTF8Encode().AsStringC()); diff --git a/xfa/fxfa/parser/cxfa_stroke.cpp b/xfa/fxfa/parser/cxfa_stroke.cpp index df11cbee00..e81c0ce591 100644 --- a/xfa/fxfa/parser/cxfa_stroke.cpp +++ b/xfa/fxfa/parser/cxfa_stroke.cpp @@ -67,7 +67,7 @@ void CXFA_Stroke::SetColor(FX_ARGB argb) { int r; int g; int b; - ArgbDecode(argb, a, r, g, b); + std::tie(a, r, g, b) = ArgbDecode(argb); wsColor.Format(L"%d,%d,%d", r, g, b); pNode->SetCData(XFA_ATTRIBUTE_Value, wsColor); } diff --git a/xfa/fxgraphics/cfx_shading.cpp b/xfa/fxgraphics/cfx_shading.cpp index 7dc8ce3412..b099bb97b1 100644 --- a/xfa/fxgraphics/cfx_shading.cpp +++ b/xfa/fxgraphics/cfx_shading.cpp @@ -51,15 +51,15 @@ void CFX_Shading::InitArgbArray() { int32_t r1; int32_t g1; int32_t b1; - ArgbDecode(m_beginArgb, a1, r1, g1, b1); + std::tie(a1, r1, g1, b1) = ArgbDecode(m_beginArgb); int32_t a2; int32_t r2; int32_t g2; int32_t b2; - ArgbDecode(m_endArgb, a2, r2, g2, b2); + std::tie(a2, r2, g2, b2) = ArgbDecode(m_endArgb); - float f = (float)(FX_SHADING_Steps - 1); + float f = static_cast<float>(FX_SHADING_Steps - 1); float aScale = 1.0 * (a2 - a1) / f; float rScale = 1.0 * (r2 - r1) / f; float gScale = 1.0 * (g2 - g1) / f; |