Move a condition check in CStretchEngine to a static function

Move the condition check for whether to manually enable interpolate
bilinear option for smoother image rendering result into a new static
function CStretchEngine::UseInterpolateBilinear() so that this check
can be reused by Skia renderer later.

Bug: pdfium:1857, pdfium:1859
Change-Id: I6818f00d232414f42d6f032a5b9f455462cc5d5f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/97610
Commit-Queue: Nigi <nigi@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/dib/cstretchengine.cpp b/core/fxge/dib/cstretchengine.cpp
index 5c96dcb..2bbecbd 100644
--- a/core/fxge/dib/cstretchengine.cpp
+++ b/core/fxge/dib/cstretchengine.cpp
@@ -28,6 +28,19 @@
     "PixelWeight storage may be re-used without invoking its destructor");
 
 // static
+bool CStretchEngine::UseInterpolateBilinear(
+    const FXDIB_ResampleOptions& options,
+    int dest_width,
+    int dest_height,
+    int src_width,
+    int src_height) {
+  return !options.bInterpolateBilinear && !options.bNoSmoothing &&
+         abs(dest_width) != 0 &&
+         abs(dest_height) / 8 <
+             static_cast<long long>(src_width) * src_height / abs(dest_width);
+}
+
+// static
 size_t CStretchEngine::PixelWeight::TotalBytesForWeightCount(
     size_t weight_count) {
   // Always room for one weight even for empty ranges due to declaration
@@ -192,9 +205,8 @@
   if (options.bNoSmoothing) {
     m_ResampleOptions.bNoSmoothing = true;
   } else {
-    if (!options.bInterpolateBilinear && abs(dest_width) != 0 &&
-        abs(dest_height) / 8 < static_cast<long long>(m_SrcWidth) *
-                                   m_SrcHeight / abs(dest_width)) {
+    if (UseInterpolateBilinear(options, dest_width, dest_height, m_SrcWidth,
+                               m_SrcHeight)) {
       m_ResampleOptions.bInterpolateBilinear = true;
     } else {
       m_ResampleOptions = options;
diff --git a/core/fxge/dib/cstretchengine.h b/core/fxge/dib/cstretchengine.h
index fd7977f..73f21ea 100644
--- a/core/fxge/dib/cstretchengine.h
+++ b/core/fxge/dib/cstretchengine.h
@@ -39,6 +39,14 @@
     return static_cast<uint8_t>(fixed >> kFixedPointBits);
   }
 
+  // Indicates whether to manually set interpolate bilinear option to true to
+  // achieve a smoother rendering results.
+  static bool UseInterpolateBilinear(const FXDIB_ResampleOptions& options,
+                                     int dest_width,
+                                     int dest_height,
+                                     int src_width,
+                                     int src_height);
+
   struct PixelWeight {
     static size_t TotalBytesForWeightCount(size_t weight_count);