Simplify pitch calculation in CFX_DIBitmap::CalculatePitchAndSize()
Use the existing CalculatePitch32() utility function instead of
duplicating it.
Change-Id: I98146336445f1d2a525a3a7648799e7415109295
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/105430
Reviewed-by: Nigi <nigi@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp
index e14560f..7233089 100644
--- a/core/fxge/dib/cfx_dibitmap.cpp
+++ b/core/fxge/dib/cfx_dibitmap.cpp
@@ -670,16 +670,12 @@
uint32_t actual_pitch = pitch;
if (actual_pitch == 0) {
- FX_SAFE_UINT32 safe_pitch = width;
- safe_pitch *= bpp;
- safe_pitch += 31;
- // Note: This is not the same as /8 due to truncation.
- safe_pitch /= 32;
- safe_pitch *= 4;
- if (!safe_pitch.IsValid())
+ absl::optional<uint32_t> pitch32 = fxge::CalculatePitch32(bpp, width);
+ if (!pitch32.has_value()) {
return absl::nullopt;
+ }
- actual_pitch = safe_pitch.ValueOrDie();
+ actual_pitch = pitch32.value();
}
FX_SAFE_UINT32 safe_size = actual_pitch;