Use Fx2DSizeOrDie() in more places inside cfx_dibbase.cpp.
- Calculate once outside of for-loops when possible.
- Use spans in more places.
Change-Id: I680550ebf56824765485b4c2902280770e1ff961
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/103076
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxge/dib/cfx_dibbase.cpp b/core/fxge/dib/cfx_dibbase.cpp
index 4a62575..07c7b74 100644
--- a/core/fxge/dib/cfx_dibbase.cpp
+++ b/core/fxge/dib/cfx_dibbase.cpp
@@ -209,12 +209,13 @@
const RetainPtr<const CFX_DIBBase>& pSrcBitmap,
int src_left,
int src_top) {
- int Bpp = pSrcBitmap->GetBPP() / 8;
+ const int Bpp = pSrcBitmap->GetBPP() / 8;
+ const size_t x_offset = Fx2DSizeOrDie(src_left, Bpp);
for (int row = 0; row < height; ++row) {
uint8_t* dest_scan =
dest_buf.subspan(Fx2DSizeOrDie(row, dest_pitch)).data();
const uint8_t* src_scan =
- pSrcBitmap->GetScanline(src_top + row).subspan(src_left * Bpp).data();
+ pSrcBitmap->GetScanline(src_top + row).subspan(x_offset).data();
for (int col = 0; col < width; ++col) {
*dest_scan++ = FXRGB2GRAY(src_scan[2], src_scan[1], src_scan[0]);
src_scan += Bpp;
@@ -313,12 +314,13 @@
}
int32_t lut_1 = lut - 1;
for (int row = 0; row < height; ++row) {
- const uint8_t* src_scan =
- pSrcBitmap->GetScanline(src_top + row).subspan(src_left).data();
+ pdfium::span<const uint8_t> src_span =
+ pSrcBitmap->GetScanline(src_top + row).subspan(src_left);
uint8_t* dest_scan =
dest_buf.subspan(Fx2DSizeOrDie(row, dest_pitch)).data();
for (int col = 0; col < width; ++col) {
- const uint8_t* src_port = src_scan + Fx2DSizeOrDie(col, bpp);
+ const uint8_t* src_port =
+ src_span.subspan(Fx2DSizeOrDie(col, bpp)).data();
int r = src_port[2] & 0xf0;
int g = src_port[1] & 0xf0;
int b = src_port[0] & 0xf0;
@@ -443,10 +445,12 @@
const RetainPtr<const CFX_DIBBase>& pSrcBitmap,
int src_left,
int src_top) {
+ const size_t x_offset = Fx2DSizeOrDie(src_left, 3);
+ const size_t byte_count = Fx2DSizeOrDie(width, 3);
for (int row = 0; row < height; ++row) {
- fxcrt::spancpy(dest_buf.subspan(Fx2DSizeOrDie(row, dest_pitch)),
- pSrcBitmap->GetScanline(src_top + row)
- .subspan(src_left * 3, width * 3));
+ fxcrt::spancpy(
+ dest_buf.subspan(Fx2DSizeOrDie(row, dest_pitch)),
+ pSrcBitmap->GetScanline(src_top + row).subspan(x_offset, byte_count));
}
}
@@ -458,11 +462,12 @@
const RetainPtr<const CFX_DIBBase>& pSrcBitmap,
int src_left,
int src_top) {
+ const size_t x_offset = Fx2DSizeOrDie(src_left, 4);
for (int row = 0; row < height; ++row) {
uint8_t* dest_scan =
dest_buf.subspan(Fx2DSizeOrDie(row, dest_pitch)).data();
const uint8_t* src_scan =
- pSrcBitmap->GetScanline(src_top + row).subspan(src_left * 4).data();
+ pSrcBitmap->GetScanline(src_top + row).subspan(x_offset).data();
for (int col = 0; col < width; ++col) {
memcpy(dest_scan, src_scan, 3);
dest_scan += 3;
@@ -478,12 +483,13 @@
const RetainPtr<const CFX_DIBBase>& pSrcBitmap,
int src_left,
int src_top) {
- int comps = pSrcBitmap->GetBPP() / 8;
+ const int comps = pSrcBitmap->GetBPP() / 8;
+ const size_t x_offset = Fx2DSizeOrDie(src_left, comps);
for (int row = 0; row < height; ++row) {
uint8_t* dest_scan =
dest_buf.subspan(Fx2DSizeOrDie(row, dest_pitch)).data();
const uint8_t* src_scan =
- pSrcBitmap->GetScanline(src_top + row).subspan(src_left * comps).data();
+ pSrcBitmap->GetScanline(src_top + row).subspan(x_offset).data();
for (int col = 0; col < width; ++col) {
memcpy(dest_scan, src_scan, 3);
dest_scan += 4;