Use uint32_t for PixelWeights weight array.

These should never be negative. This potentially allows for the
use of more fractional bits in the image stretcher without causing
an overflow into a sign bit.

-- combine no-op assignments in two places.
-- use uint32_t instead of unsigned long in two places.

Change-Id: Icc9e8829e6b28425406962d5e7789261b11bda92
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/81830
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcodec/progressive_decoder.cpp b/core/fxcodec/progressive_decoder.cpp
index 764e5fa..20844e2 100644
--- a/core/fxcodec/progressive_decoder.cpp
+++ b/core/fxcodec/progressive_decoder.cpp
@@ -657,7 +657,7 @@
           if (pDeviceBitmap->HasPalette())
             return;
 
-          int dest_g = 0;
+          uint32_t dest_g = 0;
           dest_g += pWeight->m_Weights[0] * (*scan_src1++);
           dest_g += pWeight->m_Weights[1] * (*scan_src2++);
           *scan_des++ = (uint8_t)(dest_g >> 16);
@@ -932,7 +932,7 @@
           if (pDeviceBitmap->HasPalette())
             return;
 
-          int dest_g = 0;
+          uint32_t dest_g = 0;
           dest_g += pWeight->m_Weights[0] * (*scan_src1++);
           dest_g += pWeight->m_Weights[1] * (*scan_src2++);
           *scan_des++ = (uint8_t)(dest_g >> 16);
@@ -1154,8 +1154,7 @@
         uint32_t dest_b = 0;
         uint32_t dest_g = 0;
         uint32_t dest_r = 0;
-        const uint8_t* p = src_scan;
-        p = src_scan + pPixelWeights->m_SrcStart * src_Bpp;
+        const uint8_t* p = src_scan + pPixelWeights->m_SrcStart * src_Bpp;
         dest_b += pPixelWeights->m_Weights[0] * (*p++);
         dest_g += pPixelWeights->m_Weights[0] * (*p++);
         dest_r += pPixelWeights->m_Weights[0] * (*p);
@@ -1173,8 +1172,7 @@
         uint32_t dest_b = 0;
         uint32_t dest_g = 0;
         uint32_t dest_r = 0;
-        const uint8_t* p = src_scan;
-        p = src_scan + pPixelWeights->m_SrcStart * src_Bpp;
+        const uint8_t* p = src_scan + pPixelWeights->m_SrcStart * src_Bpp;
         dest_b += pPixelWeights->m_Weights[0] * (*p++);
         dest_g += pPixelWeights->m_Weights[0] * (*p++);
         dest_r += pPixelWeights->m_Weights[0] * (*p++);
@@ -1773,21 +1771,21 @@
         uint32_t dest_g = 0;
         for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
              j++) {
-          int pixel_weight =
+          uint32_t pixel_weight =
               pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
           dest_g += pixel_weight * src_scan[j];
         }
         *dest_scan++ = (uint8_t)(dest_g >> 16);
       } break;
       case 3: {
-        int dest_r = 0;
-        int dest_g = 0;
-        int dest_b = 0;
+        uint32_t dest_r = 0;
+        uint32_t dest_g = 0;
+        uint32_t dest_b = 0;
         for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
              j++) {
-          int pixel_weight =
+          uint32_t pixel_weight =
               pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
-          unsigned long argb = m_pSrcPalette.get()[src_scan[j]];
+          uint32_t argb = m_pSrcPalette.get()[src_scan[j]];
           dest_r += pixel_weight * FXARGB_R(argb);
           dest_g += pixel_weight * FXARGB_G(argb);
           dest_b += pixel_weight * FXARGB_B(argb);
@@ -1801,7 +1799,7 @@
         uint32_t dest_r = 0;
         for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
              j++) {
-          int pixel_weight =
+          uint32_t pixel_weight =
               pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
           const uint8_t* src_pixel = src_scan + j * src_bytes_per_pixel;
           dest_b += pixel_weight * (*src_pixel++);
@@ -1817,7 +1815,7 @@
         uint32_t dest_r = 0;
         for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
              j++) {
-          int pixel_weight =
+          uint32_t pixel_weight =
               pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
           const uint8_t* src_pixel = src_scan + j * src_bytes_per_pixel;
           uint8_t src_b = 0;
@@ -1839,7 +1837,7 @@
         uint32_t dest_g = 0;
         for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
              j++) {
-          int pixel_weight =
+          uint32_t pixel_weight =
               pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
           dest_g += pixel_weight * src_scan[j];
         }
@@ -1847,14 +1845,14 @@
         dest_scan += dest_bytes_per_pixel;
       } break;
       case 8: {
-        int dest_r = 0;
-        int dest_g = 0;
-        int dest_b = 0;
+        uint32_t dest_r = 0;
+        uint32_t dest_g = 0;
+        uint32_t dest_b = 0;
         for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
              j++) {
-          int pixel_weight =
+          uint32_t pixel_weight =
               pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
-          unsigned long argb = m_pSrcPalette.get()[src_scan[j]];
+          uint32_t argb = m_pSrcPalette.get()[src_scan[j]];
           dest_r += pixel_weight * FXARGB_R(argb);
           dest_g += pixel_weight * FXARGB_G(argb);
           dest_b += pixel_weight * FXARGB_B(argb);
@@ -1867,14 +1865,14 @@
       case 12: {
 #ifdef PDF_ENABLE_XFA_BMP
         if (m_pBmpContext) {
-          int dest_r = 0;
-          int dest_g = 0;
-          int dest_b = 0;
+          uint32_t dest_r = 0;
+          uint32_t dest_g = 0;
+          uint32_t dest_b = 0;
           for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
                j++) {
-            int pixel_weight =
+            uint32_t pixel_weight =
                 pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
-            unsigned long argb = m_pSrcPalette.get()[src_scan[j]];
+            uint32_t argb = m_pSrcPalette.get()[src_scan[j]];
             dest_r += pixel_weight * FXARGB_R(argb);
             dest_g += pixel_weight * FXARGB_G(argb);
             dest_b += pixel_weight * FXARGB_B(argb);
@@ -1886,13 +1884,13 @@
           break;
         }
 #endif  // PDF_ENABLE_XFA_BMP
-        int dest_a = 0;
-        int dest_r = 0;
-        int dest_g = 0;
-        int dest_b = 0;
+        uint32_t dest_a = 0;
+        uint32_t dest_r = 0;
+        uint32_t dest_g = 0;
+        uint32_t dest_b = 0;
         for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
              j++) {
-          int pixel_weight =
+          uint32_t pixel_weight =
               pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
           unsigned long argb = m_pSrcPalette.get()[src_scan[j]];
           dest_a += pixel_weight * FXARGB_A(argb);
@@ -1911,7 +1909,7 @@
         uint32_t dest_r = 0;
         for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
              j++) {
-          int pixel_weight =
+          uint32_t pixel_weight =
               pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
           const uint8_t* src_pixel = src_scan + j * src_bytes_per_pixel;
           dest_b += pixel_weight * (*src_pixel++);
@@ -1929,7 +1927,7 @@
         uint32_t dest_r = 0;
         for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
              j++) {
-          int pixel_weight =
+          uint32_t pixel_weight =
               pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
           const uint8_t* src_pixel = src_scan + j * src_bytes_per_pixel;
           uint8_t src_b = 0;
@@ -1954,7 +1952,7 @@
         uint32_t dest_b = 0;
         for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
              j++) {
-          int pixel_weight =
+          uint32_t pixel_weight =
               pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart];
           const uint8_t* src_pixel = src_scan + j * src_bytes_per_pixel;
           pixel_weight = pixel_weight * src_pixel[3] / 255;
@@ -2019,7 +2017,7 @@
           if (pDeviceBitmap->HasPalette())
             return;
 
-          int dest_g = 0;
+          uint32_t dest_g = 0;
           dest_g += pWeight->m_Weights[0] * (*scan_src1++);
           dest_g += pWeight->m_Weights[1] * (*scan_src2++);
           *scan_des++ = (uint8_t)(dest_g >> 16);
diff --git a/core/fxge/dib/cstretchengine.cpp b/core/fxge/dib/cstretchengine.cpp
index 640efc9..d20c2a0 100644
--- a/core/fxge/dib/cstretchengine.cpp
+++ b/core/fxge/dib/cstretchengine.cpp
@@ -148,8 +148,9 @@
       &m_WeightTables[(pixel - m_DestMin) * m_ItemSizeBytes]);
 }
 
-int CStretchEngine::CWeightTable::GetValueFromPixelWeight(PixelWeight* pWeight,
-                                                          int index) const {
+uint32_t CStretchEngine::CWeightTable::GetValueFromPixelWeight(
+    PixelWeight* pWeight,
+    int index) const {
   if (index < pWeight->m_SrcStart)
     return 0;
 
@@ -312,9 +313,9 @@
       case TransformMethod::k1BppToManyBpp: {
         for (int col = m_DestClip.left; col < m_DestClip.right; ++col) {
           PixelWeight* pWeights = m_WeightTable.GetPixelWeight(col);
-          int dest_a = 0;
+          uint32_t dest_a = 0;
           for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
-            int pixel_weight =
+            uint32_t pixel_weight =
                 m_WeightTable.GetValueFromPixelWeight(pWeights, j);
             if (src_scan[j / 8] & (1 << (7 - j % 8)))
               dest_a += pixel_weight * 255;
@@ -326,9 +327,9 @@
       case TransformMethod::k8BppTo8Bpp: {
         for (int col = m_DestClip.left; col < m_DestClip.right; ++col) {
           PixelWeight* pWeights = m_WeightTable.GetPixelWeight(col);
-          int dest_a = 0;
+          uint32_t dest_a = 0;
           for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
-            int pixel_weight =
+            uint32_t pixel_weight =
                 m_WeightTable.GetValueFromPixelWeight(pWeights, j);
             dest_a += pixel_weight * src_scan[j];
           }
@@ -339,10 +340,10 @@
       case TransformMethod::k8BppTo8BppWithAlpha: {
         for (int col = m_DestClip.left; col < m_DestClip.right; ++col) {
           PixelWeight* pWeights = m_WeightTable.GetPixelWeight(col);
-          int dest_a = 0;
-          int dest_r = 0;
+          uint32_t dest_a = 0;
+          uint32_t dest_r = 0;
           for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
-            int pixel_weight =
+            uint32_t pixel_weight =
                 m_WeightTable.GetValueFromPixelWeight(pWeights, j);
             pixel_weight = pixel_weight * src_scan_mask[j] / 255;
             dest_r += pixel_weight * src_scan[j];
@@ -357,11 +358,11 @@
       case TransformMethod::k8BppToManyBpp: {
         for (int col = m_DestClip.left; col < m_DestClip.right; ++col) {
           PixelWeight* pWeights = m_WeightTable.GetPixelWeight(col);
-          int dest_r = 0;
-          int dest_g = 0;
-          int dest_b = 0;
+          uint32_t dest_r = 0;
+          uint32_t dest_g = 0;
+          uint32_t dest_b = 0;
           for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
-            int pixel_weight =
+            uint32_t pixel_weight =
                 m_WeightTable.GetValueFromPixelWeight(pWeights, j);
             unsigned long argb = m_pSrcPalette[src_scan[j]];
             if (m_DestFormat == FXDIB_Format::kRgb) {
@@ -383,12 +384,12 @@
       case TransformMethod::k8BppToManyBppWithAlpha: {
         for (int col = m_DestClip.left; col < m_DestClip.right; ++col) {
           PixelWeight* pWeights = m_WeightTable.GetPixelWeight(col);
-          int dest_a = 0;
-          int dest_r = 0;
-          int dest_g = 0;
-          int dest_b = 0;
+          uint32_t dest_a = 0;
+          uint32_t dest_r = 0;
+          uint32_t dest_g = 0;
+          uint32_t dest_b = 0;
           for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
-            int pixel_weight =
+            uint32_t pixel_weight =
                 m_WeightTable.GetValueFromPixelWeight(pWeights, j);
             pixel_weight = pixel_weight * src_scan_mask[j] / 255;
             unsigned long argb = m_pSrcPalette[src_scan[j]];
@@ -408,11 +409,11 @@
       case TransformMethod::kManyBpptoManyBpp: {
         for (int col = m_DestClip.left; col < m_DestClip.right; ++col) {
           PixelWeight* pWeights = m_WeightTable.GetPixelWeight(col);
-          int dest_r = 0;
-          int dest_g = 0;
-          int dest_b = 0;
+          uint32_t dest_r = 0;
+          uint32_t dest_g = 0;
+          uint32_t dest_b = 0;
           for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
-            int pixel_weight =
+            uint32_t pixel_weight =
                 m_WeightTable.GetValueFromPixelWeight(pWeights, j);
             const uint8_t* src_pixel = src_scan + j * Bpp;
             dest_b += pixel_weight * (*src_pixel++);
@@ -429,12 +430,12 @@
       case TransformMethod::kManyBpptoManyBppWithAlpha: {
         for (int col = m_DestClip.left; col < m_DestClip.right; ++col) {
           PixelWeight* pWeights = m_WeightTable.GetPixelWeight(col);
-          int dest_a = 0;
-          int dest_r = 0;
-          int dest_g = 0;
-          int dest_b = 0;
+          uint32_t dest_a = 0;
+          uint32_t dest_r = 0;
+          uint32_t dest_g = 0;
+          uint32_t dest_b = 0;
           for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
-            int pixel_weight =
+            uint32_t pixel_weight =
                 m_WeightTable.GetValueFromPixelWeight(pWeights, j);
             const uint8_t* src_pixel = src_scan + j * Bpp;
             if (m_DestFormat == FXDIB_Format::kArgb) {
@@ -489,9 +490,9 @@
         for (int col = m_DestClip.left; col < m_DestClip.right; ++col) {
           unsigned char* src_scan =
               m_InterBuf.data() + (col - m_DestClip.left) * DestBpp;
-          int dest_a = 0;
+          uint32_t dest_a = 0;
           for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
-            int pixel_weight = table.GetValueFromPixelWeight(pWeights, j);
+            uint32_t pixel_weight = table.GetValueFromPixelWeight(pWeights, j);
             dest_a +=
                 pixel_weight * src_scan[(j - m_SrcClip.top) * m_InterPitch];
           }
@@ -506,10 +507,10 @@
               m_InterBuf.data() + (col - m_DestClip.left) * DestBpp;
           unsigned char* src_scan_mask =
               m_ExtraAlphaBuf.data() + (col - m_DestClip.left);
-          int dest_a = 0;
-          int dest_k = 0;
+          uint32_t dest_a = 0;
+          uint32_t dest_k = 0;
           for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
-            int pixel_weight = table.GetValueFromPixelWeight(pWeights, j);
+            uint32_t pixel_weight = table.GetValueFromPixelWeight(pWeights, j);
             dest_k +=
                 pixel_weight * src_scan[(j - m_SrcClip.top) * m_InterPitch];
             dest_a += pixel_weight *
@@ -526,11 +527,11 @@
         for (int col = m_DestClip.left; col < m_DestClip.right; ++col) {
           unsigned char* src_scan =
               m_InterBuf.data() + (col - m_DestClip.left) * DestBpp;
-          int dest_r = 0;
-          int dest_g = 0;
-          int dest_b = 0;
+          uint32_t dest_r = 0;
+          uint32_t dest_g = 0;
+          uint32_t dest_b = 0;
           for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
-            int pixel_weight = table.GetValueFromPixelWeight(pWeights, j);
+            uint32_t pixel_weight = table.GetValueFromPixelWeight(pWeights, j);
             const uint8_t* src_pixel =
                 src_scan + (j - m_SrcClip.top) * m_InterPitch;
             dest_b += pixel_weight * (*src_pixel++);
@@ -552,12 +553,12 @@
           unsigned char* src_scan_mask = nullptr;
           if (m_DestFormat != FXDIB_Format::kArgb)
             src_scan_mask = m_ExtraAlphaBuf.data() + (col - m_DestClip.left);
-          int dest_a = 0;
-          int dest_r = 0;
-          int dest_g = 0;
-          int dest_b = 0;
+          uint32_t dest_a = 0;
+          uint32_t dest_r = 0;
+          uint32_t dest_g = 0;
+          uint32_t dest_b = 0;
           for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
-            int pixel_weight = table.GetValueFromPixelWeight(pWeights, j);
+            uint32_t pixel_weight = table.GetValueFromPixelWeight(pWeights, j);
             const uint8_t* src_pixel =
                 src_scan + (j - m_SrcClip.top) * m_InterPitch;
             int mask_v = 255;
diff --git a/core/fxge/dib/cstretchengine.h b/core/fxge/dib/cstretchengine.h
index d67e8bf..87153bc 100644
--- a/core/fxge/dib/cstretchengine.h
+++ b/core/fxge/dib/cstretchengine.h
@@ -60,7 +60,7 @@
           static_cast<const CWeightTable*>(this)->GetPixelWeight(pixel));
     }
 
-    int GetValueFromPixelWeight(PixelWeight* pWeight, int index) const;
+    uint32_t GetValueFromPixelWeight(PixelWeight* pWeight, int index) const;
     size_t GetPixelWeightCount() const;
 
    private:
diff --git a/core/fxge/dib/fx_dib.h b/core/fxge/dib/fx_dib.h
index d88bd79..4485176 100644
--- a/core/fxge/dib/fx_dib.h
+++ b/core/fxge/dib/fx_dib.h
@@ -35,7 +35,7 @@
 
   int m_SrcStart;
   int m_SrcEnd;
-  int m_Weights[1];  // Not really 1, variable size.
+  uint32_t m_Weights[1];  // Not really 1, variable size.
 };
 
 using FX_ARGB = uint32_t;