Remove more dead code in CFX_ScanlineCompositor.

Remove alpha channel span parameters from various CompositeRow functions
when the span is always empty. Then remove dead code in the CompositeRow
functions.

Change-Id: Ib0e05dd0eb2c89f2ff975ae0067c54ddd1e2cdc6
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/101892
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/dib/cfx_scanlinecompositor.cpp b/core/fxge/dib/cfx_scanlinecompositor.cpp
index 70b7936..b8b3ac4 100644
--- a/core/fxge/dib/cfx_scanlinecompositor.cpp
+++ b/core/fxge/dib/cfx_scanlinecompositor.cpp
@@ -264,23 +264,19 @@
                             pdfium::span<const uint8_t> src_span,
                             int pixel_count,
                             BlendMode blend_type,
-                            pdfium::span<const uint8_t> clip_span,
-                            pdfium::span<const uint8_t> src_alpha_span) {
+                            pdfium::span<const uint8_t> clip_span) {
   uint8_t* dest_scan = dest_span.data();
   const uint8_t* src_scan = src_span.data();
   const uint8_t* clip_scan = clip_span.data();
-  const uint8_t* src_alpha_scan = src_alpha_span.data();
-  uint8_t offset = src_alpha_scan ? 3 : 4;
+  constexpr size_t kOffset = 4;
   for (int col = 0; col < pixel_count; ++col) {
-    const uint8_t* alpha_scan =
-        src_alpha_scan ? src_alpha_scan++ : &src_scan[3];
-    int src_alpha = GetAlpha(*alpha_scan, clip_scan, col);
+    int src_alpha = GetAlpha(src_scan[3], clip_scan, col);
     if (src_alpha) {
       uint8_t gray = GetGrayWithBlend(src_scan, dest_scan, blend_type);
       *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
     }
     ++dest_scan;
-    src_scan += offset;
+    src_scan += kOffset;
   }
 }
 
@@ -308,64 +304,34 @@
                             pdfium::span<const uint8_t> src_span,
                             int pixel_count,
                             BlendMode blend_type,
-                            pdfium::span<const uint8_t> clip_span,
-                            pdfium::span<uint8_t> dest_alpha_span,
-                            pdfium::span<const uint8_t> src_alpha_span) {
+                            pdfium::span<const uint8_t> clip_span) {
   uint8_t* dest_scan = dest_span.data();
   const uint8_t* src_scan = src_span.data();
   const uint8_t* clip_scan = clip_span.data();
-  uint8_t* dest_alpha_scan = dest_alpha_span.data();
-  const uint8_t* src_alpha_scan = src_alpha_span.data();
   int blended_colors[3];
-  uint8_t dest_offset = dest_alpha_scan ? 3 : 4;
-  uint8_t src_offset = src_alpha_scan ? 3 : 4;
+  constexpr size_t kOffset = 4;
   bool bNonseparableBlend = IsNonSeparableBlendMode(blend_type);
-  bool has_src = !!src_alpha_scan;
-  bool has_dest = !!dest_alpha_scan;
   for (int col = 0; col < pixel_count; ++col) {
-    uint8_t back_alpha = has_dest ? *dest_alpha_scan : dest_scan[3];
-    const uint8_t* alpha_source = has_src ? src_alpha_scan++ : &src_scan[3];
-    uint8_t src_alpha = GetAlpha(*alpha_source, clip_scan, col);
+    uint8_t back_alpha = dest_scan[3];
+    uint8_t src_alpha = GetAlpha(src_scan[3], clip_scan, col);
     if (back_alpha == 0) {
-      if (!has_dest && !has_src) {
-        if (clip_scan) {
-          FXARGB_SETDIB(dest_scan, (FXARGB_GETDIB(src_scan) & 0xffffff) |
-                                       (src_alpha << 24));
-        } else {
-          memcpy(dest_scan, src_scan, 4);
-        }
-      } else if (has_dest) {
-        *dest_alpha_scan = src_alpha;
-        memcpy(dest_scan, src_scan, 3);
-        dest_scan += 3;
-        src_scan += 3;
-        ++dest_alpha_scan;
-        if (!has_src)
-          ++src_scan;
+      if (clip_scan) {
+        FXARGB_SETDIB(dest_scan,
+                      (FXARGB_GETDIB(src_scan) & 0xffffff) | (src_alpha << 24));
       } else {
-        FXARGB_SETDIB(dest_scan, ArgbEncode((src_alpha << 24), src_scan[2],
-                                            src_scan[1], *src_scan));
+        memcpy(dest_scan, src_scan, 4);
       }
-      if (!has_dest) {
-        dest_scan += dest_offset;
-        src_scan += src_offset;
-      }
+      dest_scan += kOffset;
+      src_scan += kOffset;
       continue;
     }
     if (src_alpha == 0) {
-      dest_scan += dest_offset;
-      src_scan += src_offset;
-      if (has_dest)
-        ++dest_alpha_scan;
+      dest_scan += kOffset;
+      src_scan += kOffset;
       continue;
     }
     uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
-    if (has_dest) {
-      *dest_alpha_scan = dest_alpha;
-      ++dest_alpha_scan;
-    } else {
-      dest_scan[3] = dest_alpha;
-    }
+    dest_scan[3] = dest_alpha;
     int alpha_ratio = src_alpha * 255 / dest_alpha;
     if (bNonseparableBlend)
       RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
@@ -382,10 +348,8 @@
       ++dest_scan;
       ++src_scan;
     }
-    if (!has_dest)
-      ++dest_scan;
-    if (!has_src)
-      ++src_scan;
+    ++dest_scan;
+    ++src_scan;
   }
 }
 
@@ -393,33 +357,23 @@
                                         pdfium::span<const uint8_t> src_span,
                                         int width,
                                         BlendMode blend_type,
-                                        int src_Bpp,
-                                        pdfium::span<uint8_t> dest_alpha_span) {
+                                        int src_Bpp) {
   uint8_t* dest_scan = dest_span.data();
   const uint8_t* src_scan = src_span.data();
-  uint8_t* dest_alpha_scan = dest_alpha_span.data();
   int blended_colors[3];
   bool bNonseparableBlend = IsNonSeparableBlendMode(blend_type);
   int src_gap = src_Bpp - 3;
   for (int col = 0; col < width; ++col) {
-    uint8_t* dest_alpha = dest_alpha_scan ? dest_alpha_scan : &dest_scan[3];
+    uint8_t* dest_alpha = &dest_scan[3];
     uint8_t back_alpha = *dest_alpha;
     if (back_alpha == 0) {
-      if (dest_alpha_scan) {
-        memcpy(dest_scan, src_scan, 3);
-        dest_scan += 3;
-        src_scan += 3;
-        *dest_alpha_scan = 0xff;
-        ++dest_alpha_scan;
+      if (src_Bpp == 4) {
+        FXARGB_SETDIB(dest_scan, 0xff000000 | FXARGB_GETDIB(src_scan));
       } else {
-        if (src_Bpp == 4) {
-          FXARGB_SETDIB(dest_scan, 0xff000000 | FXARGB_GETDIB(src_scan));
-        } else {
-          FXARGB_SETDIB(dest_scan, ArgbEncode(0xff, src_scan[2], src_scan[1],
-                                              src_scan[0]));
-        }
-        dest_scan += 4;
+        FXARGB_SETDIB(dest_scan,
+                      ArgbEncode(0xff, src_scan[2], src_scan[1], src_scan[0]));
       }
+      dest_scan += 4;
       src_scan += src_Bpp;
       continue;
     }
@@ -435,10 +389,7 @@
       ++dest_scan;
       ++src_scan;
     }
-    if (dest_alpha_scan)
-      ++dest_alpha_scan;
-    else
-      ++dest_scan;
+    ++dest_scan;
     src_scan += src_gap;
   }
 }
@@ -448,41 +399,30 @@
                                       int width,
                                       BlendMode blend_type,
                                       int src_Bpp,
-                                      pdfium::span<const uint8_t> clip_span,
-                                      pdfium::span<uint8_t> dest_alpha_span) {
+                                      pdfium::span<const uint8_t> clip_span) {
   uint8_t* dest_scan = dest_span.data();
   const uint8_t* src_scan = src_span.data();
   const uint8_t* clip_scan = clip_span.data();
-  uint8_t* dest_alpha_scan = dest_alpha_span.data();
   int blended_colors[3];
   bool bNonseparableBlend = IsNonSeparableBlendMode(blend_type);
   int src_gap = src_Bpp - 3;
-  bool has_dest = !!dest_alpha_scan;
   for (int col = 0; col < width; ++col) {
     int src_alpha = *clip_scan++;
-    uint8_t back_alpha = has_dest ? *dest_alpha_scan : dest_scan[3];
+    uint8_t back_alpha = dest_scan[3];
     if (back_alpha == 0) {
       memcpy(dest_scan, src_scan, 3);
       dest_scan += 3;
       src_scan += src_Bpp;
-      if (has_dest)
-        dest_alpha_scan++;
-      else
-        dest_scan++;
+      dest_scan++;
       continue;
     }
     if (src_alpha == 0) {
-      dest_scan += has_dest ? 3 : 4;
-      if (has_dest)
-        dest_alpha_scan++;
+      dest_scan += 4;
       src_scan += src_Bpp;
       continue;
     }
     uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
-    if (has_dest)
-      *dest_alpha_scan++ = dest_alpha;
-    else
-      dest_scan[3] = dest_alpha;
+    dest_scan[3] = dest_alpha;
     int alpha_ratio = src_alpha * 255 / dest_alpha;
     if (bNonseparableBlend)
       RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
@@ -497,8 +437,7 @@
       src_scan++;
     }
     src_scan += src_gap;
-    if (!has_dest)
-      dest_scan++;
+    dest_scan++;
   }
 }
 
@@ -506,99 +445,54 @@
                                         pdfium::span<const uint8_t> src_span,
                                         int width,
                                         int src_Bpp,
-                                        pdfium::span<const uint8_t> clip_span,
-                                        pdfium::span<uint8_t> dest_alpha_span) {
+                                        pdfium::span<const uint8_t> clip_span) {
   uint8_t* dest_scan = dest_span.data();
   const uint8_t* src_scan = src_span.data();
   const uint8_t* clip_scan = clip_span.data();
-  uint8_t* dest_alpha_scan = dest_alpha_span.data();
   int src_gap = src_Bpp - 3;
-  if (dest_alpha_scan) {
-    for (int col = 0; col < width; col++) {
-      int src_alpha = clip_scan[col];
-      if (src_alpha == 255) {
-        memcpy(dest_scan, src_scan, 3);
-        dest_scan += 3;
-        src_scan += src_Bpp;
-        *dest_alpha_scan++ = 255;
-        continue;
-      }
-      if (src_alpha == 0) {
-        dest_scan += 3;
-        dest_alpha_scan++;
-        src_scan += src_Bpp;
-        continue;
-      }
-      int back_alpha = *dest_alpha_scan;
-      uint8_t dest_alpha =
-          back_alpha + src_alpha - back_alpha * src_alpha / 255;
-      *dest_alpha_scan++ = dest_alpha;
-      int alpha_ratio = src_alpha * 255 / dest_alpha;
-      for (int color = 0; color < 3; color++) {
-        *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
-        dest_scan++;
-        src_scan++;
-      }
-      src_scan += src_gap;
+  for (int col = 0; col < width; col++) {
+    int src_alpha = clip_scan[col];
+    if (src_alpha == 255) {
+      memcpy(dest_scan, src_scan, 3);
+      dest_scan += 3;
+      *dest_scan++ = 255;
+      src_scan += src_Bpp;
+      continue;
     }
-  } else {
-    for (int col = 0; col < width; col++) {
-      int src_alpha = clip_scan[col];
-      if (src_alpha == 255) {
-        memcpy(dest_scan, src_scan, 3);
-        dest_scan += 3;
-        *dest_scan++ = 255;
-        src_scan += src_Bpp;
-        continue;
-      }
-      if (src_alpha == 0) {
-        dest_scan += 4;
-        src_scan += src_Bpp;
-        continue;
-      }
-      int back_alpha = dest_scan[3];
-      uint8_t dest_alpha =
-          back_alpha + src_alpha - back_alpha * src_alpha / 255;
-      dest_scan[3] = dest_alpha;
-      int alpha_ratio = src_alpha * 255 / dest_alpha;
-      for (int color = 0; color < 3; color++) {
-        *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
-        dest_scan++;
-        src_scan++;
-      }
+    if (src_alpha == 0) {
+      dest_scan += 4;
+      src_scan += src_Bpp;
+      continue;
+    }
+    int back_alpha = dest_scan[3];
+    uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+    dest_scan[3] = dest_alpha;
+    int alpha_ratio = src_alpha * 255 / dest_alpha;
+    for (int color = 0; color < 3; color++) {
+      *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, alpha_ratio);
       dest_scan++;
-      src_scan += src_gap;
+      src_scan++;
     }
+    dest_scan++;
+    src_scan += src_gap;
   }
 }
 
-void CompositeRow_Rgb2Argb_NoBlend_NoClip(
-    pdfium::span<uint8_t> dest_span,
-    pdfium::span<const uint8_t> src_span,
-    int width,
-    int src_Bpp,
-    pdfium::span<uint8_t> dest_alpha_span) {
+void CompositeRow_Rgb2Argb_NoBlend_NoClip(pdfium::span<uint8_t> dest_span,
+                                          pdfium::span<const uint8_t> src_span,
+                                          int width,
+                                          int src_Bpp) {
   uint8_t* dest_scan = dest_span.data();
   const uint8_t* src_scan = src_span.data();
-  uint8_t* dest_alpha_scan = dest_alpha_span.data();
-  if (dest_alpha_scan) {
-    for (int col = 0; col < width; col++) {
-      memcpy(dest_scan, src_scan, 3);
-      dest_scan += 3;
-      src_scan += src_Bpp;
-      *dest_alpha_scan++ = 255;
+  for (int col = 0; col < width; col++) {
+    if (src_Bpp == 4) {
+      FXARGB_SETDIB(dest_scan, 0xff000000 | FXARGB_GETDIB(src_scan));
+    } else {
+      FXARGB_SETDIB(dest_scan,
+                    ArgbEncode(0xff, src_scan[2], src_scan[1], src_scan[0]));
     }
-  } else {
-    for (int col = 0; col < width; col++) {
-      if (src_Bpp == 4) {
-        FXARGB_SETDIB(dest_scan, 0xff000000 | FXARGB_GETDIB(src_scan));
-      } else {
-        FXARGB_SETDIB(dest_scan,
-                      ArgbEncode(0xff, src_scan[2], src_scan[1], src_scan[0]));
-      }
-      dest_scan += 4;
-      src_scan += src_Bpp;
-    }
+    dest_scan += 4;
+    src_scan += src_Bpp;
   }
 }
 
@@ -607,70 +501,39 @@
                                  int width,
                                  BlendMode blend_type,
                                  int dest_Bpp,
-                                 pdfium::span<const uint8_t> clip_span,
-                                 pdfium::span<const uint8_t> src_alpha_span) {
+                                 pdfium::span<const uint8_t> clip_span) {
   uint8_t* dest_scan = dest_span.data();
   const uint8_t* src_scan = src_span.data();
   const uint8_t* clip_scan = clip_span.data();
-  const uint8_t* src_alpha_scan = src_alpha_span.data();
   int blended_colors[3];
   bool bNonseparableBlend = IsNonSeparableBlendMode(blend_type);
   int dest_gap = dest_Bpp - 3;
-  if (src_alpha_scan) {
-    for (int col = 0; col < width; col++) {
-      uint8_t src_alpha;
-      if (clip_scan) {
-        src_alpha = (*src_alpha_scan++) * (*clip_scan++) / 255;
-      } else {
-        src_alpha = *src_alpha_scan++;
-      }
-      if (src_alpha == 0) {
-        dest_scan += dest_Bpp;
-        src_scan += 3;
-        continue;
-      }
-      if (bNonseparableBlend) {
-        RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
-      }
-      for (int color = 0; color < 3; color++) {
-        int back_color = *dest_scan;
-        int blended = bNonseparableBlend
-                          ? blended_colors[color]
-                          : Blend(blend_type, back_color, *src_scan);
-        *dest_scan = FXDIB_ALPHA_MERGE(back_color, blended, src_alpha);
-        dest_scan++;
-        src_scan++;
-      }
-      dest_scan += dest_gap;
+  for (int col = 0; col < width; col++) {
+    uint8_t src_alpha;
+    if (clip_scan) {
+      src_alpha = src_scan[3] * (*clip_scan++) / 255;
+    } else {
+      src_alpha = src_scan[3];
     }
-  } else {
-    for (int col = 0; col < width; col++) {
-      uint8_t src_alpha;
-      if (clip_scan) {
-        src_alpha = src_scan[3] * (*clip_scan++) / 255;
-      } else {
-        src_alpha = src_scan[3];
-      }
-      if (src_alpha == 0) {
-        dest_scan += dest_Bpp;
-        src_scan += 4;
-        continue;
-      }
-      if (bNonseparableBlend) {
-        RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
-      }
-      for (int color = 0; color < 3; color++) {
-        int back_color = *dest_scan;
-        int blended = bNonseparableBlend
-                          ? blended_colors[color]
-                          : Blend(blend_type, back_color, *src_scan);
-        *dest_scan = FXDIB_ALPHA_MERGE(back_color, blended, src_alpha);
-        dest_scan++;
-        src_scan++;
-      }
-      dest_scan += dest_gap;
+    if (src_alpha == 0) {
+      dest_scan += dest_Bpp;
+      src_scan += 4;
+      continue;
+    }
+    if (bNonseparableBlend) {
+      RGB_Blend(blend_type, src_scan, dest_scan, blended_colors);
+    }
+    for (int color = 0; color < 3; color++) {
+      int back_color = *dest_scan;
+      int blended = bNonseparableBlend
+                        ? blended_colors[color]
+                        : Blend(blend_type, back_color, *src_scan);
+      *dest_scan = FXDIB_ALPHA_MERGE(back_color, blended, src_alpha);
+      dest_scan++;
       src_scan++;
     }
+    dest_scan += dest_gap;
+    src_scan++;
   }
 }
 
@@ -678,66 +541,36 @@
                                    pdfium::span<const uint8_t> src_span,
                                    int width,
                                    int dest_Bpp,
-                                   pdfium::span<const uint8_t> clip_span,
-                                   pdfium::span<const uint8_t> src_alpha_span) {
+                                   pdfium::span<const uint8_t> clip_span) {
   uint8_t* dest_scan = dest_span.data();
   const uint8_t* src_scan = src_span.data();
   const uint8_t* clip_scan = clip_span.data();
-  const uint8_t* src_alpha_scan = src_alpha_span.data();
   int dest_gap = dest_Bpp - 3;
-  if (src_alpha_scan) {
-    for (int col = 0; col < width; col++) {
-      uint8_t src_alpha;
-      if (clip_scan) {
-        src_alpha = (*src_alpha_scan++) * (*clip_scan++) / 255;
-      } else {
-        src_alpha = *src_alpha_scan++;
-      }
-      if (src_alpha == 255) {
-        memcpy(dest_scan, src_scan, 3);
-        dest_scan += dest_Bpp;
-        src_scan += 3;
-        continue;
-      }
-      if (src_alpha == 0) {
-        dest_scan += dest_Bpp;
-        src_scan += 3;
-        continue;
-      }
-      for (int color = 0; color < 3; color++) {
-        *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha);
-        dest_scan++;
-        src_scan++;
-      }
-      dest_scan += dest_gap;
+  for (int col = 0; col < width; col++) {
+    uint8_t src_alpha;
+    if (clip_scan) {
+      src_alpha = src_scan[3] * (*clip_scan++) / 255;
+    } else {
+      src_alpha = src_scan[3];
     }
-  } else {
-    for (int col = 0; col < width; col++) {
-      uint8_t src_alpha;
-      if (clip_scan) {
-        src_alpha = src_scan[3] * (*clip_scan++) / 255;
-      } else {
-        src_alpha = src_scan[3];
-      }
-      if (src_alpha == 255) {
-        memcpy(dest_scan, src_scan, 3);
-        dest_scan += dest_Bpp;
-        src_scan += 4;
-        continue;
-      }
-      if (src_alpha == 0) {
-        dest_scan += dest_Bpp;
-        src_scan += 4;
-        continue;
-      }
-      for (int color = 0; color < 3; color++) {
-        *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha);
-        dest_scan++;
-        src_scan++;
-      }
-      dest_scan += dest_gap;
+    if (src_alpha == 255) {
+      memcpy(dest_scan, src_scan, 3);
+      dest_scan += dest_Bpp;
+      src_scan += 4;
+      continue;
+    }
+    if (src_alpha == 0) {
+      dest_scan += dest_Bpp;
+      src_scan += 4;
+      continue;
+    }
+    for (int color = 0; color < 3; color++) {
+      *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, *src_scan, src_alpha);
+      dest_scan++;
       src_scan++;
     }
+    dest_scan += dest_gap;
+    src_scan++;
   }
 }
 
@@ -864,62 +697,19 @@
                                pdfium::span<const uint8_t> palette_span,
                                int pixel_count,
                                BlendMode blend_type,
-                               pdfium::span<const uint8_t> clip_span,
-                               pdfium::span<const uint8_t> src_alpha_span) {
+                               pdfium::span<const uint8_t> clip_span) {
   uint8_t* dest_scan = dest_span.data();
   const uint8_t* src_scan = src_span.data();
   const uint8_t* clip_scan = clip_span.data();
-  const uint8_t* src_alpha_scan = src_alpha_span.data();
   const uint8_t* pPalette = palette_span.data();
-  if (src_alpha_scan) {
-    if (blend_type != BlendMode::kNormal) {
-      bool bNonseparableBlend = IsNonSeparableBlendMode(blend_type);
-      for (int col = 0; col < pixel_count; col++) {
-        uint8_t gray = pPalette[*src_scan];
-        int src_alpha = GetAlpha(*src_alpha_scan++, clip_scan, col);
-        if (bNonseparableBlend)
-          gray = blend_type == BlendMode::kLuminosity ? gray : *dest_scan;
-        else
-          gray = Blend(blend_type, *dest_scan, gray);
-        if (src_alpha)
-          *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
-        else
-          *dest_scan = gray;
-        dest_scan++;
-        src_scan++;
-      }
-      return;
-    }
+  if (blend_type != BlendMode::kNormal) {
+    bool bNonseparableBlend = IsNonSeparableBlendMode(blend_type);
     for (int col = 0; col < pixel_count; col++) {
       uint8_t gray = pPalette[*src_scan];
-      int src_alpha = GetAlpha(*src_alpha_scan++, clip_scan, col);
-      if (src_alpha)
-        *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, src_alpha);
+      if (bNonseparableBlend)
+        gray = blend_type == BlendMode::kLuminosity ? gray : *dest_scan;
       else
-        *dest_scan = gray;
-      dest_scan++;
-      src_scan++;
-    }
-  } else {
-    if (blend_type != BlendMode::kNormal) {
-      bool bNonseparableBlend = IsNonSeparableBlendMode(blend_type);
-      for (int col = 0; col < pixel_count; col++) {
-        uint8_t gray = pPalette[*src_scan];
-        if (bNonseparableBlend)
-          gray = blend_type == BlendMode::kLuminosity ? gray : *dest_scan;
-        else
-          gray = Blend(blend_type, *dest_scan, gray);
-        if (clip_scan && clip_scan[col] < 255)
-          *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
-        else
-          *dest_scan = gray;
-        dest_scan++;
-        src_scan++;
-      }
-      return;
-    }
-    for (int col = 0; col < pixel_count; col++) {
-      uint8_t gray = pPalette[*src_scan];
+        gray = Blend(blend_type, *dest_scan, gray);
       if (clip_scan && clip_scan[col] < 255)
         *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
       else
@@ -927,6 +717,16 @@
       dest_scan++;
       src_scan++;
     }
+    return;
+  }
+  for (int col = 0; col < pixel_count; col++) {
+    uint8_t gray = pPalette[*src_scan];
+    if (clip_scan && clip_scan[col] < 255)
+      *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, clip_scan[col]);
+    else
+      *dest_scan = gray;
+    dest_scan++;
+    src_scan++;
   }
 }
 
@@ -976,77 +776,38 @@
   }
 }
 
-void CompositeRow_8bppRgb2Rgb_NoBlend(
-    pdfium::span<uint8_t> dest_span,
-    pdfium::span<const uint8_t> src_span,
-    pdfium::span<const uint32_t> palette_span,
-    int pixel_count,
-    int DestBpp,
-    pdfium::span<const uint8_t> clip_span,
-    pdfium::span<const uint8_t> src_alpha_span) {
+void CompositeRow_8bppRgb2Rgb_NoBlend(pdfium::span<uint8_t> dest_span,
+                                      pdfium::span<const uint8_t> src_span,
+                                      pdfium::span<const uint32_t> palette_span,
+                                      int pixel_count,
+                                      int DestBpp,
+                                      pdfium::span<const uint8_t> clip_span) {
   uint8_t* dest_scan = dest_span.data();
   const uint8_t* src_scan = src_span.data();
   const uint8_t* clip_scan = clip_span.data();
-  const uint8_t* src_alpha_scan = src_alpha_span.data();
   const uint32_t* pPalette = palette_span.data();
-  if (src_alpha_scan) {
-    int dest_gap = DestBpp - 3;
-    FX_ARGB argb = 0;
-    for (int col = 0; col < pixel_count; col++) {
-      argb = pPalette[*src_scan];
-      int src_r = FXARGB_R(argb);
-      int src_g = FXARGB_G(argb);
-      int src_b = FXARGB_B(argb);
-      src_scan++;
-      uint8_t src_alpha = 0;
-      if (clip_scan) {
-        src_alpha = (*src_alpha_scan++) * (*clip_scan++) / 255;
-      } else {
-        src_alpha = *src_alpha_scan++;
-      }
-      if (src_alpha == 255) {
-        *dest_scan++ = src_b;
-        *dest_scan++ = src_g;
-        *dest_scan++ = src_r;
-        dest_scan += dest_gap;
-        continue;
-      }
-      if (src_alpha == 0) {
-        dest_scan += DestBpp;
-        continue;
-      }
-      *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, src_alpha);
+  FX_ARGB argb = 0;
+  for (int col = 0; col < pixel_count; col++) {
+    argb = pPalette[*src_scan];
+    int src_r = FXARGB_R(argb);
+    int src_g = FXARGB_G(argb);
+    int src_b = FXARGB_B(argb);
+    if (clip_scan && clip_scan[col] < 255) {
+      *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, clip_scan[col]);
       dest_scan++;
-      *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, src_alpha);
+      *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, clip_scan[col]);
       dest_scan++;
-      *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, src_alpha);
+      *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, clip_scan[col]);
       dest_scan++;
-      dest_scan += dest_gap;
+    } else {
+      *dest_scan++ = src_b;
+      *dest_scan++ = src_g;
+      *dest_scan++ = src_r;
     }
-  } else {
-    FX_ARGB argb = 0;
-    for (int col = 0; col < pixel_count; col++) {
-      argb = pPalette[*src_scan];
-      int src_r = FXARGB_R(argb);
-      int src_g = FXARGB_G(argb);
-      int src_b = FXARGB_B(argb);
-      if (clip_scan && clip_scan[col] < 255) {
-        *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, clip_scan[col]);
-        dest_scan++;
-        *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, clip_scan[col]);
-        dest_scan++;
-        *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, clip_scan[col]);
-        dest_scan++;
-      } else {
-        *dest_scan++ = src_b;
-        *dest_scan++ = src_g;
-        *dest_scan++ = src_r;
-      }
-      if (DestBpp == 4) {
-        dest_scan++;
-      }
-      src_scan++;
+    if (DestBpp == 4) {
+      dest_scan++;
     }
+    src_scan++;
   }
 }
 
@@ -1102,85 +863,42 @@
     pdfium::span<const uint8_t> src_span,
     int width,
     pdfium::span<const uint32_t> palette_span,
-    pdfium::span<const uint8_t> clip_span,
-    pdfium::span<const uint8_t> src_alpha_span) {
+    pdfium::span<const uint8_t> clip_span) {
   uint8_t* dest_scan = dest_span.data();
   const uint8_t* src_scan = src_span.data();
   const uint8_t* clip_scan = clip_span.data();
-  const uint8_t* src_alpha_scan = src_alpha_span.data();
   const uint32_t* pPalette = palette_span.data();
-  if (src_alpha_scan) {
-    for (int col = 0; col < width; col++) {
-      FX_ARGB argb = pPalette[*src_scan];
+  for (int col = 0; col < width; col++) {
+    FX_ARGB argb = pPalette[*src_scan];
+    int src_r = FXARGB_R(argb);
+    int src_g = FXARGB_G(argb);
+    int src_b = FXARGB_B(argb);
+    if (!clip_scan || clip_scan[col] == 255) {
+      *dest_scan++ = src_b;
+      *dest_scan++ = src_g;
+      *dest_scan++ = src_r;
+      *dest_scan++ = 255;
       src_scan++;
-      int src_r = FXARGB_R(argb);
-      int src_g = FXARGB_G(argb);
-      int src_b = FXARGB_B(argb);
-      uint8_t back_alpha = dest_scan[3];
-      if (back_alpha == 0) {
-        if (clip_scan) {
-          int src_alpha = clip_scan[col] * (*src_alpha_scan) / 255;
-          FXARGB_SETDIB(dest_scan, ArgbEncode(src_alpha, src_r, src_g, src_b));
-        } else {
-          FXARGB_SETDIB(dest_scan,
-                        ArgbEncode(*src_alpha_scan, src_r, src_g, src_b));
-        }
-        dest_scan += 4;
-        src_alpha_scan++;
-        continue;
-      }
-      uint8_t src_alpha = GetAlpha(*src_alpha_scan, clip_scan, col);
-      ++src_alpha_scan;
-      if (src_alpha == 0) {
-        dest_scan += 4;
-        continue;
-      }
-      uint8_t dest_alpha =
-          back_alpha + src_alpha - back_alpha * src_alpha / 255;
-      dest_scan[3] = dest_alpha;
-      int alpha_ratio = src_alpha * 255 / dest_alpha;
-      *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
-      dest_scan++;
-      *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
-      dest_scan++;
-      *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
-      dest_scan++;
-      dest_scan++;
+      continue;
     }
-  } else {
-    for (int col = 0; col < width; col++) {
-      FX_ARGB argb = pPalette[*src_scan];
-      int src_r = FXARGB_R(argb);
-      int src_g = FXARGB_G(argb);
-      int src_b = FXARGB_B(argb);
-      if (!clip_scan || clip_scan[col] == 255) {
-        *dest_scan++ = src_b;
-        *dest_scan++ = src_g;
-        *dest_scan++ = src_r;
-        *dest_scan++ = 255;
-        src_scan++;
-        continue;
-      }
-      int src_alpha = clip_scan[col];
-      if (src_alpha == 0) {
-        dest_scan += 4;
-        src_scan++;
-        continue;
-      }
-      int back_alpha = dest_scan[3];
-      uint8_t dest_alpha =
-          back_alpha + src_alpha - back_alpha * src_alpha / 255;
-      dest_scan[3] = dest_alpha;
-      int alpha_ratio = src_alpha * 255 / dest_alpha;
-      *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
-      dest_scan++;
-      *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
-      dest_scan++;
-      *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
-      dest_scan++;
-      dest_scan++;
+    int src_alpha = clip_scan[col];
+    if (src_alpha == 0) {
+      dest_scan += 4;
       src_scan++;
+      continue;
     }
+    int back_alpha = dest_scan[3];
+    uint8_t dest_alpha = back_alpha + src_alpha - back_alpha * src_alpha / 255;
+    dest_scan[3] = dest_alpha;
+    int alpha_ratio = src_alpha * 255 / dest_alpha;
+    *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
+    dest_scan++;
+    *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
+    dest_scan++;
+    *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
+    dest_scan++;
+    dest_scan++;
+    src_scan++;
   }
 }
 
@@ -2673,9 +2391,8 @@
   } else if (GetBppFromFormat(m_DestFormat) == 8) {
     DCHECK(!GetIsAlphaFromFormat(m_DestFormat));
     if (GetIsAlphaFromFormat(m_SrcFormat)) {
-      // TODO(thestig): Check if empty span argument is always empty.
-      CompositeRow_Argb2Gray(dest_scan, src_scan, width, m_BlendType, clip_scan,
-                             {});
+      CompositeRow_Argb2Gray(dest_scan, src_scan, width, m_BlendType,
+                             clip_scan);
     } else {
       CompositeRow_Rgb2Gray(dest_scan, src_scan, src_Bpp, width, m_BlendType,
                             clip_scan);
@@ -2686,41 +2403,34 @@
       case 4:
       case 8:
       case 4 + 8: {
-        // TODO(thestig): Check if empty span arguments are always empty.
         CompositeRow_Argb2Argb(dest_scan, src_scan, width, m_BlendType,
-                               clip_scan, {}, {});
+                               clip_scan);
       } break;
       case 1:
-        // TODO(thestig): Check if empty span argument is always empty.
         CompositeRow_Rgb2Argb_Blend_NoClip(dest_scan, src_scan, width,
-                                           m_BlendType, src_Bpp, {});
+                                           m_BlendType, src_Bpp);
         break;
       case 1 + 8:
-        // TODO(thestig): Check if empty span argument is always empty.
         CompositeRow_Rgb2Argb_Blend_Clip(dest_scan, src_scan, width,
-                                         m_BlendType, src_Bpp, clip_scan, {});
+                                         m_BlendType, src_Bpp, clip_scan);
         break;
       case 1 + 4:
-        // TODO(thestig): Check if empty span argument is always empty.
         CompositeRow_Rgb2Argb_NoBlend_NoClip(dest_scan, src_scan, width,
-                                             src_Bpp, {});
+                                             src_Bpp);
         break;
       case 1 + 4 + 8:
-        // TODO(thestig): Check if empty span argument is always empty.
         CompositeRow_Rgb2Argb_NoBlend_Clip(dest_scan, src_scan, width, src_Bpp,
-                                           clip_scan, {});
+                                           clip_scan);
         break;
       case 2:
       case 2 + 8:
-        // TODO(thestig): Check if empty span argument is always empty.
         CompositeRow_Argb2Rgb_Blend(dest_scan, src_scan, width, m_BlendType,
-                                    dest_Bpp, clip_scan, {});
+                                    dest_Bpp, clip_scan);
         break;
       case 2 + 4:
       case 2 + 4 + 8:
-        // TODO(thestig): Check if empty span argument is always empty.
         CompositeRow_Argb2Rgb_NoBlend(dest_scan, src_scan, width, dest_Bpp,
-                                      clip_scan, {});
+                                      clip_scan);
         break;
       case 1 + 2:
         CompositeRow_Rgb2Rgb_Blend_NoClip(dest_scan, src_scan, width,
@@ -2789,18 +2499,16 @@
                                 m_SrcPalette.Get8BitPalette(), width,
                                 m_BlendType, clip_scan);
     } else {
-      // TODO(thestig): Check if empty span argument is always empty.
       CompositeRow_8bppPal2Gray(dest_scan, src_scan,
                                 m_SrcPalette.Get8BitPalette(), width,
-                                m_BlendType, clip_scan, {});
+                                m_BlendType, clip_scan);
     }
   } else {
     switch (m_iTransparency) {
       case 1 + 2:
-        // TODO(thestig): Check if empty span argument is always empty.
         CompositeRow_8bppRgb2Argb_NoBlend(dest_scan, src_scan, width,
                                           m_SrcPalette.Get32BitPalette(),
-                                          clip_scan, {});
+                                          clip_scan);
         break;
       case 1 + 2 + 8:
         CompositeRow_1bppRgb2Argb_NoBlend(dest_scan, src_scan, src_left, width,
@@ -2808,22 +2516,16 @@
                                           clip_scan);
         break;
       case 0:
-        // TODO(thestig): Check if empty span argument is always empty.
+      case 0 + 2:
         CompositeRow_8bppRgb2Rgb_NoBlend(
             dest_scan, src_scan, m_SrcPalette.Get32BitPalette(), width,
-            GetCompsFromFormat(m_DestFormat), clip_scan, {});
+            GetCompsFromFormat(m_DestFormat), clip_scan);
         break;
       case 0 + 8:
         CompositeRow_1bppRgb2Rgb_NoBlend(
             dest_scan, src_scan, src_left, m_SrcPalette.Get32BitPalette(),
             width, GetCompsFromFormat(m_DestFormat), clip_scan);
         break;
-      case 0 + 2:
-        // TODO(thestig): Check if empty span argument is always empty.
-        CompositeRow_8bppRgb2Rgb_NoBlend(
-            dest_scan, src_scan, m_SrcPalette.Get32BitPalette(), width,
-            GetCompsFromFormat(m_DestFormat), clip_scan, {});
-        break;
       case 0 + 2 + 8:
         // TODO(thestig): Check if empty span argument is always empty.
         CompositeRow_1bppRgb2Rgba_NoBlend(dest_scan, src_scan, src_left, width,