Remove ProgressiveDecoder::GetDownScale()

The scale is always 1. Add some CHECKs to ensure this is the case.
Then get rid of then scale parameter in

JpegProgressiveDecoder::StartScanline().
Change-Id: Icd4ca681fb3705b9822e525f477f1d958d526ecd
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/122291
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/fxcodec/jpeg/jpeg_progressive_decoder.cpp b/core/fxcodec/jpeg/jpeg_progressive_decoder.cpp
index 6b41782..7456c76 100644
--- a/core/fxcodec/jpeg/jpeg_progressive_decoder.cpp
+++ b/core/fxcodec/jpeg/jpeg_progressive_decoder.cpp
@@ -153,9 +153,9 @@
 }
 
 // static
-bool JpegProgressiveDecoder::StartScanline(Context* pContext, int down_scale) {
+bool JpegProgressiveDecoder::StartScanline(Context* pContext) {
   auto* ctx = static_cast<CJpegContext*>(pContext);
-  ctx->m_Info.scale_denom = static_cast<unsigned int>(down_scale);
+  ctx->m_Info.scale_denom = 1;
   return !!jpeg_start_decompress(&ctx->m_Info);
 }
 
diff --git a/core/fxcodec/jpeg/jpeg_progressive_decoder.h b/core/fxcodec/jpeg/jpeg_progressive_decoder.h
index a94e33a..34bdf98 100644
--- a/core/fxcodec/jpeg/jpeg_progressive_decoder.h
+++ b/core/fxcodec/jpeg/jpeg_progressive_decoder.h
@@ -34,7 +34,7 @@
                         int* nComps,
                         CFX_DIBAttribute* pAttribute);
 
-  static bool StartScanline(Context* pContext, int down_scale);
+  static bool StartScanline(Context* pContext);
   static bool ReadScanline(Context* pContext, uint8_t* dest_buf);
 
   // ProgressiveDecoderIface:
diff --git a/core/fxcodec/progressive_decoder.cpp b/core/fxcodec/progressive_decoder.cpp
index 3494207..5b909b5 100644
--- a/core/fxcodec/progressive_decoder.cpp
+++ b/core/fxcodec/progressive_decoder.cpp
@@ -923,7 +923,8 @@
 }
 
 FXCODEC_STATUS ProgressiveDecoder::JpegStartDecode() {
-  int down_scale = GetDownScale();
+  CHECK_EQ(m_clipBox.Width(), m_SrcWidth);
+  CHECK_EQ(m_clipBox.Height(), m_SrcHeight);
   // Setting jump marker before calling StartScanLine, since a longjmp to
   // the marker indicates a fatal error.
   if (setjmp(JpegProgressiveDecoder::GetJumpMark(m_pJpegContext.get())) == -1) {
@@ -932,9 +933,9 @@
     return FXCODEC_STATUS::kError;
   }
 
-  bool startStatus =
-      JpegProgressiveDecoder::StartScanline(m_pJpegContext.get(), down_scale);
-  while (!startStatus) {
+  bool start_status =
+      JpegProgressiveDecoder::StartScanline(m_pJpegContext.get());
+  while (!start_status) {
     FXCODEC_STATUS error_status = FXCODEC_STATUS::kError;
     if (!JpegReadMoreData(&error_status)) {
       m_pDeviceBitmap = nullptr;
@@ -943,12 +944,9 @@
       return m_status;
     }
 
-    startStatus =
-        JpegProgressiveDecoder::StartScanline(m_pJpegContext.get(), down_scale);
+    start_status = JpegProgressiveDecoder::StartScanline(m_pJpegContext.get());
   }
-  int scanline_size = (m_SrcWidth + down_scale - 1) / down_scale;
-  scanline_size = FxAlignToBoundary<4>(scanline_size * m_SrcComponents);
-  m_DecodeBuf.resize(scanline_size);
+  m_DecodeBuf.resize(FxAlignToBoundary<4>(m_SrcWidth * m_SrcComponents));
   FXDIB_ResampleOptions options;
   options.bInterpolateBilinear = true;
   m_WeightHorz.CalculateWeights(m_SrcWidth, 0, m_SrcWidth, m_clipBox.Width(), 0,
@@ -1469,29 +1467,6 @@
   return m_status;
 }
 
-int ProgressiveDecoder::GetDownScale() {
-  int down_scale = 1;
-  int ratio_w = m_clipBox.Width() / m_SrcWidth;
-  int ratio_h = m_clipBox.Height() / m_SrcHeight;
-  int ratio = std::min(ratio_w, ratio_h);
-  if (ratio >= 8)
-    down_scale = 8;
-  else if (ratio >= 4)
-    down_scale = 4;
-  else if (ratio >= 2)
-    down_scale = 2;
-
-  m_clipBox.left /= down_scale;
-  m_clipBox.right /= down_scale;
-  m_clipBox.top /= down_scale;
-  m_clipBox.bottom /= down_scale;
-  if (m_clipBox.right == m_clipBox.left)
-    m_clipBox.right = m_clipBox.left + 1;
-  if (m_clipBox.bottom == m_clipBox.top)
-    m_clipBox.bottom = m_clipBox.top + 1;
-  return down_scale;
-}
-
 void ProgressiveDecoder::SetTransMethod() {
   switch (m_pDeviceBitmap->GetFormat()) {
     case FXDIB_Format::kInvalid:
diff --git a/core/fxcodec/progressive_decoder.h b/core/fxcodec/progressive_decoder.h
index 9a404bb..09e973d 100644
--- a/core/fxcodec/progressive_decoder.h
+++ b/core/fxcodec/progressive_decoder.h
@@ -196,7 +196,6 @@
                     ProgressiveDecoderIface::Context* pContext,
                     FXCODEC_STATUS* err_status);
 
-  int GetDownScale();
   void SetTransMethod();
 
   void ResampleScanline(const RetainPtr<CFX_DIBitmap>& pDeviceBitmap,