Fix FXDIB_Format::kRgb32 handling when drawing with Skia

For bitmaps of format `kRgb32`, PDFium expects the alpha channel to be
ignored. As such, sometimes the alpha value is 0xFF, but not always. On
the other hand, Skia's equivalent would be "kBGR_888x_SkColorType", but
that color type does not exist. Skia only has `kRGB_888x_SkColorType`.
The Skia alternative is to use `kBGRA_8888_SkColorType` with
`kOpaque_SkAlphaType`, but this setup requires the alpha channel to
always be 0xFF. To meet the requirement, change
CFX_DIBBase::RealizeSkImage() to handle `FXDIB_Format::kRgb32` with a
transform that always sets the alpha channel to 0xFF. Then the rest of
the PDFium code can stay the same, without having to find every `kRgb32`
usage and set the alpha channel.

With this fix, the known to be bad test expectation for
transfer_function.in on Mac/Skia can be removed, and rendering this file
with Skia is consistent across platforms.

Bug: 351796783
Change-Id: I9308573c545a55637874450df98b2a79dad0bbe3
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/122350
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Tom Sepez <tsepez@google.com>
diff --git a/core/fxge/skia/cfx_dibbase_skia.cpp b/core/fxge/skia/cfx_dibbase_skia.cpp
index 4824666..5bcace2 100644
--- a/core/fxge/skia/cfx_dibbase_skia.cpp
+++ b/core/fxge/skia/cfx_dibbase_skia.cpp
@@ -115,6 +115,21 @@
   }
 };
 
+template <typename PixelTransform>
+class PixelTransformTraits<32, PixelTransform> {
+ public:
+  using Result =
+      std::invoke_result_t<PixelTransform, uint8_t, uint8_t, uint8_t>;
+
+  static Result Invoke(PixelTransform&& pixel_transform,
+                       pdfium::span<const uint8_t> scanline,
+                       size_t column) {
+    size_t offset = column * 4;
+    return pixel_transform(scanline[offset + 2], scanline[offset + 1],
+                           scanline[offset]);
+  }
+};
+
 void ValidateScanlineSize(pdfium::span<const uint8_t> scanline,
                           size_t min_row_bytes) {
   DCHECK_GE(scanline.size(), min_row_bytes);
@@ -233,6 +248,14 @@
           });
 
     case 32:
+      if (GetFormat() == FXDIB_Format::kRgb32) {
+        return CreateSkiaImageFromTransformedDib</*source_bits_per_pixel=*/32>(
+            *this, kBGRA_8888_SkColorType, kOpaque_SkAlphaType,
+            [](uint8_t red, uint8_t green, uint8_t blue) {
+              return SkPackARGB32(0xFF, red, green, blue);
+            });
+      }
+      CHECK_EQ(GetFormat(), FXDIB_Format::kArgb);
       return CreateSkiaImageFromDib(
           this, kBGRA_8888_SkColorType,
           IsPremultiplied() ? kPremul_SkAlphaType : kUnpremul_SkAlphaType);
diff --git a/testing/resources/pixel/transfer_function_expected_skia_mac.pdf.1.png b/testing/resources/pixel/transfer_function_expected_skia_mac.pdf.1.png
deleted file mode 100644
index 368dff0..0000000
--- a/testing/resources/pixel/transfer_function_expected_skia_mac.pdf.1.png
+++ /dev/null
Binary files differ