Let {Argb,Cmyk}Decode return tuples

Change-Id: Ic4e766d9417f9a9ece5f9e4269d0f96e1e91639b
Reviewed-on: https://pdfium-review.googlesource.com/4392
Commit-Queue: Nicolás Peña <npm@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index da49fab..2c117fd 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -183,9 +183,10 @@
     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 717e036..70a4cf9 100644
--- a/core/fpdfapi/render/cpdf_renderoptions.cpp
+++ b/core/fpdfapi/render/cpdf_renderoptions.cpp
@@ -36,8 +36,11 @@
   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 b5ec4c5..471fc9b 100644
--- a/core/fxge/agg/fx_agg_driver.cpp
+++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -923,7 +923,7 @@
     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 15d05b0..5151b02 100644
--- a/core/fxge/apple/fx_quartz_device.cpp
+++ b/core/fxge/apple/fx_quartz_device.cpp
@@ -94,8 +94,11 @@
                                  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 760b26f..6f46e1d 100644
--- a/core/fxge/dib/cfx_dibitmap.cpp
+++ b/core/fxge/dib/cfx_dibitmap.cpp
@@ -147,8 +147,11 @@
     }
     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 f52a62d..e0ba750 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 @@
   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 @@
 
   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 @@
   } 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 @@
 
   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 @@
   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 97b1aa7..3ede85c 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 @@
   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 17c7c8f..fa38573 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 @@
   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 46127cc..6a3f9c7 100644
--- a/core/fxge/ge/cfx_renderdevice.cpp
+++ b/core/fxge/ge/cfx_renderdevice.cpp
@@ -1018,7 +1018,7 @@
   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 986839e..de2f6c4 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -137,7 +137,7 @@
   }
   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 @@
 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 @@
 
   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 @@
 
   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 6a3527f..87172ff 100644
--- a/core/fxge/win32/fx_win32_gdipext.cpp
+++ b/core/fxge/win32/fx_win32_gdipext.cpp
@@ -575,8 +575,11 @@
                                         (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 58f00ed..86636b5 100644
--- a/core/fxge/win32/fx_win32_print.cpp
+++ b/core/fxge/win32/fx_win32_print.cpp
@@ -282,7 +282,7 @@
   // 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 c7dc260..8e4b465 100644
--- a/fpdfsdk/javascript/Field.cpp
+++ b/fpdfsdk/javascript/Field.cpp
@@ -2381,7 +2381,7 @@
   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 bdadba7..06de436 100644
--- a/xfa/fxfa/cxfa_ffwidget.cpp
+++ b/xfa/fxfa/cxfa_ffwidget.cpp
@@ -1660,12 +1660,11 @@
       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 8621c3c..8a7969d 100644
--- a/xfa/fxfa/parser/cxfa_fill.cpp
+++ b/xfa/fxfa/parser/cxfa_fill.cpp
@@ -19,8 +19,11 @@
 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 d6d2ece..73fc88d 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -2054,8 +2054,11 @@
   } 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 @@
     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 @@
     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 df11cbe..e81c0ce 100644
--- a/xfa/fxfa/parser/cxfa_stroke.cpp
+++ b/xfa/fxfa/parser/cxfa_stroke.cpp
@@ -67,7 +67,7 @@
   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 7dc8ce3..b099bb9 100644
--- a/xfa/fxgraphics/cfx_shading.cpp
+++ b/xfa/fxgraphics/cfx_shading.cpp
@@ -51,15 +51,15 @@
   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;