Change CPDF_ImageRenderer to store a float alpha value

With this change, the float value that initially comes from
CPDF_GeneralState::GetFillAlpha() can traverse as-is all the way to the
RenderDeviceDriverIface implementation. Changing when float to integer
conversions happen causes some minor rendering differences in some
corpus tests, so update them via a DEPS roll:

https://pdfium.googlesource.com/pdfium_tests/+log/7c9db8d16747..da0f4435882d

Change-Id: I60e5d775aaf3e2d04ab81400df3d172319f9e543
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/115450
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/DEPS b/DEPS
index 7ab671d..a64ab2f 100644
--- a/DEPS
+++ b/DEPS
@@ -178,7 +178,7 @@
   # Three lines of non-changing comments so that
   # the commit queue can handle CLs rolling pdfium_tests
   # and whatever else without interference from each other.
-  'pdfium_tests_revision': '7c9db8d1674758d3b48b0647e3d0ad5f7667a2c6',
+  'pdfium_tests_revision': 'da0f4435882d0cf8c9e4ebb66db97ecbe2a582bc',
   # Three lines of non-changing comments so that
   # the commit queue can handle CLs rolling resultdb
   # and whatever else without interference from each other.
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp
index 9f38f01..1b6b08b 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.cpp
+++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp
@@ -82,7 +82,7 @@
     return false;
 
   CPDF_GeneralState& state = m_pImageObject->mutable_general_state();
-  m_BitmapAlpha = FXSYS_roundf(255 * state.GetFillAlpha());
+  m_Alpha = state.GetFillAlpha();
   m_pDIBBase = m_pLoader->GetBitmap();
   if (GetRenderOptions().ColorModeIs(CPDF_RenderOptions::kAlpha) &&
       !m_pLoader->GetMask()) {
@@ -135,7 +135,7 @@
   if (m_bPatternColor)
     return DrawPatternImage();
 
-  if (m_BitmapAlpha != 255 || !state.HasRef() || !state.GetFillOP() ||
+  if (m_Alpha != 1.0f || !state.HasRef() || !state.GetFillOP() ||
       state.GetOPMode() != 0 || state.GetBlendType() != BlendMode::kNormal ||
       state.GetStrokeAlpha() != 1.0f || state.GetFillAlpha() != 1.0f) {
     return StartDIBBase();
@@ -195,7 +195,7 @@
                                bool bStdCS) {
   m_pDIBBase = std::move(pDIBBase);
   m_FillArgb = bitmap_argb;
-  m_BitmapAlpha = 255;
+  m_Alpha = 1.0f;
   m_ImageMatrix = mtImage2Device;
   m_ResampleOptions = options;
   m_bStdCS = bStdCS;
@@ -359,13 +359,14 @@
   if (CFX_DefaultRenderDevice::UseSkiaRenderer() &&
       m_pRenderStatus->GetRenderDevice()->SetBitsWithMask(
           bitmap_device1.GetBitmap(), bitmap_device2.GetBitmap(), rect.left,
-          rect.top, m_BitmapAlpha / 255.0f, m_BlendType)) {
+          rect.top, m_Alpha, m_BlendType)) {
     return false;
   }
 #endif
   bitmap_device1.GetBitmap()->MultiplyAlphaMask(bitmap_device2.GetBitmap());
-  if (m_BitmapAlpha < 255)
-    bitmap_device1.GetBitmap()->MultiplyAlpha(m_BitmapAlpha / 255.0f);
+  if (m_Alpha != 1.0f) {
+    bitmap_device1.GetBitmap()->MultiplyAlpha(m_Alpha);
+  }
   m_pRenderStatus->GetRenderDevice()->SetDIBitsWithBlend(
       bitmap_device1.GetBitmap(), rect.left, rect.top, m_BlendType);
   return false;
@@ -386,8 +387,8 @@
     }
   }
   if (m_pRenderStatus->GetRenderDevice()->StartDIBitsWithBlend(
-          m_pDIBBase, m_BitmapAlpha / 255.0f, m_FillArgb, m_ImageMatrix,
-          m_ResampleOptions, &m_DeviceHandle, m_BlendType)) {
+          m_pDIBBase, m_Alpha, m_FillArgb, m_ImageMatrix, m_ResampleOptions,
+          &m_DeviceHandle, m_BlendType)) {
     if (m_DeviceHandle) {
       m_Mode = Mode::kBlend;
       return true;
@@ -427,7 +428,7 @@
     return false;
   }
 
-  if (m_pDIBBase->IsOpaqueImage() && m_BitmapAlpha == 255) {
+  if (m_pDIBBase->IsOpaqueImage() && m_Alpha == 1.0f) {
     if (m_pRenderStatus->GetRenderDevice()->StretchDIBitsWithFlagsAndBlend(
             m_pDIBBase, dest_left, dest_top, dest_width, dest_height,
             m_ResampleOptions, m_BlendType)) {
@@ -435,8 +436,9 @@
     }
   }
   if (m_pDIBBase->IsMaskFormat()) {
-    if (m_BitmapAlpha != 255)
-      m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha);
+    if (m_Alpha != 1.0f) {
+      m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, FXSYS_roundf(m_Alpha * 255));
+    }
     if (m_pRenderStatus->GetRenderDevice()->StretchBitMaskWithFlags(
             m_pDIBBase, dest_left, dest_top, dest_width, dest_height,
             m_FillArgb, m_ResampleOptions)) {
@@ -457,9 +459,9 @@
   RetainPtr<CFX_DIBitmap> pStretched = m_pDIBBase->StretchTo(
       dest_width, dest_height, m_ResampleOptions, &dest_clip);
   if (pStretched) {
-    m_pRenderStatus->CompositeDIBitmap(
-        pStretched, dest_rect.left, dest_rect.top, m_FillArgb,
-        m_BitmapAlpha / 255.0f, m_BlendType, CPDF_Transparency());
+    m_pRenderStatus->CompositeDIBitmap(pStretched, dest_rect.left,
+                                       dest_rect.top, m_FillArgb, m_Alpha,
+                                       m_BlendType, CPDF_Transparency());
   }
   return false;
 }
@@ -469,8 +471,9 @@
     CFX_Path path;
     path.AppendRect(0, 0, 1, 1);
     path.Transform(m_ImageMatrix);
+    const int bitmap_alpha = FXSYS_roundf(m_Alpha * 255);
     uint32_t fill_color =
-        ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha);
+        ArgbEncode(0xff, bitmap_alpha, bitmap_alpha, bitmap_alpha);
     m_pRenderStatus->GetRenderDevice()->DrawPath(
         path, nullptr, nullptr, fill_color, 0,
         CFX_FillRenderOptions::WindingOptions());
@@ -490,9 +493,10 @@
     if (!pTransformed)
       return true;
 
+    const int bitmap_alpha = FXSYS_roundf(m_Alpha * 255);
     m_pRenderStatus->GetRenderDevice()->SetBitMask(
         pTransformed, left, top,
-        ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha));
+        ArgbEncode(0xff, bitmap_alpha, bitmap_alpha, bitmap_alpha));
     return false;
   }
 
@@ -509,9 +513,10 @@
     return false;
   }
 
+  const int bitmap_alpha = FXSYS_roundf(m_Alpha * 255);
   m_pRenderStatus->GetRenderDevice()->StretchBitMask(
       pAlphaMask, left, top, dest_width, dest_height,
-      ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha));
+      ArgbEncode(0xff, bitmap_alpha, bitmap_alpha, bitmap_alpha));
   return false;
 }
 
@@ -555,14 +560,16 @@
     return false;
 
   if (pBitmap->IsMaskFormat()) {
-    if (m_BitmapAlpha != 255)
-      m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha);
+    if (m_Alpha != 1.0f) {
+      m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, FXSYS_roundf(m_Alpha * 255));
+    }
     m_Result = m_pRenderStatus->GetRenderDevice()->SetBitMask(
         pBitmap, m_pTransformer->result().left, m_pTransformer->result().top,
         m_FillArgb);
   } else {
-    if (m_BitmapAlpha != 255)
-      pBitmap->MultiplyAlpha(m_BitmapAlpha / 255.0f);
+    if (m_Alpha != 1.0f) {
+      pBitmap->MultiplyAlpha(m_Alpha);
+    }
     m_Result = m_pRenderStatus->GetRenderDevice()->SetDIBitsWithBlend(
         pBitmap, m_pTransformer->result().left, m_pTransformer->result().top,
         m_BlendType);
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.h b/core/fpdfapi/render/cpdf_imagerenderer.h
index 530ac95..a4203f5 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.h
+++ b/core/fpdfapi/render/cpdf_imagerenderer.h
@@ -88,7 +88,7 @@
   std::unique_ptr<CFX_ImageTransformer> m_pTransformer;
   std::unique_ptr<CFX_ImageRenderer> m_DeviceHandle;
   Mode m_Mode = Mode::kNone;
-  int m_BitmapAlpha = 0;
+  float m_Alpha = 0.0f;
   BlendMode m_BlendType = BlendMode::kNormal;
   FX_ARGB m_FillArgb = 0;
   FXDIB_ResampleOptions m_ResampleOptions;