Add struct FX_RGB

Add a way to represent the RGB channels, with easy access to the color
components.

Change-Id: I051482e9e60ac73d3a1b73e6eeaa8b355d6f34be
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/117816
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/dib/cfx_scanlinecompositor.cpp b/core/fxge/dib/cfx_scanlinecompositor.cpp
index 584f6d8..206dc71 100644
--- a/core/fxge/dib/cfx_scanlinecompositor.cpp
+++ b/core/fxge/dib/cfx_scanlinecompositor.cpp
@@ -24,17 +24,11 @@
 
 namespace {
 
-struct RGB {
-  int red;
-  int green;
-  int blue;
-};
-
-int Lum(RGB color) {
+int Lum(FX_RGB<int> color) {
   return (color.red * 30 + color.green * 59 + color.blue * 11) / 100;
 }
 
-RGB ClipColor(RGB color) {
+FX_RGB<int> ClipColor(FX_RGB<int> color) {
   int l = Lum(color);
   int n = std::min(color.red, std::min(color.green, color.blue));
   int x = std::max(color.red, std::max(color.green, color.blue));
@@ -51,7 +45,7 @@
   return color;
 }
 
-RGB SetLum(RGB color, int l) {
+FX_RGB<int> SetLum(FX_RGB<int> color, int l) {
   int d = l - Lum(color);
   color.red += d;
   color.green += d;
@@ -59,16 +53,16 @@
   return ClipColor(color);
 }
 
-int Sat(RGB color) {
+int Sat(FX_RGB<int> color) {
   return std::max(color.red, std::max(color.green, color.blue)) -
          std::min(color.red, std::min(color.green, color.blue));
 }
 
-RGB SetSat(RGB color, int s) {
+FX_RGB<int> SetSat(FX_RGB<int> color, int s) {
   int min = std::min(color.red, std::min(color.green, color.blue));
   int max = std::max(color.red, std::max(color.green, color.blue));
   if (min == max)
-    return {0, 0, 0};
+    return {};
 
   color.red = (color.red - min) * s / (max - min);
   color.green = (color.green - min) * s / (max - min);
@@ -80,15 +74,11 @@
                const uint8_t* src_scan,
                const uint8_t* dest_scan,
                int results[3]) {
-  RGB result = {0, 0, 0};
-  RGB src;
-  src.red = src_scan[2];
-  src.green = src_scan[1];
-  src.blue = src_scan[0];
-  RGB back;
-  back.red = dest_scan[2];
-  back.green = dest_scan[1];
-  back.blue = dest_scan[0];
+  FX_RGB<int> result = {};
+  FX_RGB<int> src = {
+      .red = src_scan[2], .green = src_scan[1], .blue = src_scan[0]};
+  FX_RGB<int> back = {
+      .red = dest_scan[2], .green = dest_scan[1], .blue = dest_scan[0]};
   switch (blend_mode) {
     case BlendMode::kHue:
       result = SetLum(SetSat(src, Sat(back)), Lum(back));
diff --git a/core/fxge/dib/fx_dib.h b/core/fxge/dib/fx_dib.h
index 67bff4f..8163f73 100644
--- a/core/fxge/dib/fx_dib.h
+++ b/core/fxge/dib/fx_dib.h
@@ -37,6 +37,13 @@
 // parts of the codebase use 0xFFFFFFFF as a sentinel value to indicate error.
 using FX_COLORREF = uint32_t;
 
+template <typename T>
+struct FX_RGB {
+  T red;
+  T green;
+  T blue;
+};
+
 struct FXDIB_ResampleOptions {
   FXDIB_ResampleOptions();