summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-12-04 19:43:45 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-12-04 19:43:45 +0000
commit6bbab051f9d0fd2fbacd9c3b1326f3dd2036ecb1 (patch)
tree58473e6b2e958cd787e6408a636b5890506d35ac
parent8b27918d4ecb326efb19584cd0c2daeb4a71f7db (diff)
downloadpdfium-6bbab051f9d0fd2fbacd9c3b1326f3dd2036ecb1.tar.xz
Refactor CFX_ImageTransformer down sample calculations.
Change-Id: Ib3aa0b6ce2fa7b2a643068cb9ffcaca9fe18d3de Reviewed-on: https://pdfium-review.googlesource.com/20258 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r--core/fxge/dib/cfx_imagetransformer.cpp157
-rw-r--r--core/fxge/dib/cfx_imagetransformer.h9
2 files changed, 80 insertions, 86 deletions
diff --git a/core/fxge/dib/cfx_imagetransformer.cpp b/core/fxge/dib/cfx_imagetransformer.cpp
index d1edf093ee..e7f60c4991 100644
--- a/core/fxge/dib/cfx_imagetransformer.cpp
+++ b/core/fxge/dib/cfx_imagetransformer.cpp
@@ -333,20 +333,10 @@ void CFX_ImageTransformer::CalcMask(const CalcData& cdata) {
};
DoBicubicLoop(cdata, 1, func);
} else {
- CPDF_FixedMatrix result2stretch_fix(cdata.matrix, 8);
- for (int row = 0; row < m_result.Height(); row++) {
- uint8_t* dest_pos_mask = (uint8_t*)cdata.bitmap->GetScanline(row);
- for (int col = 0; col < m_result.Width(); col++) {
- int src_col = 0;
- int src_row = 0;
- result2stretch_fix.Transform(col, row, &src_col, &src_row);
- if (InStretchBounds(src_col, src_row)) {
- AdjustCoords(&src_col, &src_row);
- *dest_pos_mask = cdata.buf[src_row * cdata.pitch + src_col];
- }
- dest_pos_mask++;
- }
- }
+ auto func = [&cdata](const DownSampleData& data, uint8_t* dest) {
+ *dest = cdata.buf[data.src_row * cdata.pitch + data.src_col];
+ };
+ DoDownSampleLoop(cdata, 1, func);
}
}
@@ -365,22 +355,12 @@ void CFX_ImageTransformer::CalcAlpha(const CalcData& cdata) {
};
DoBicubicLoop(cdata, 1, func);
} else {
- CPDF_FixedMatrix result2stretch_fix(cdata.matrix, 8);
- for (int row = 0; row < m_result.Height(); row++) {
- uint8_t* dest_scan = (uint8_t*)cdata.bitmap->GetScanline(row);
- for (int col = 0; col < m_result.Width(); col++) {
- int src_col = 0;
- int src_row = 0;
- result2stretch_fix.Transform(col, row, &src_col, &src_row);
- if (InStretchBounds(src_col, src_row)) {
- AdjustCoords(&src_col, &src_row);
- const uint8_t* src_pixel =
- cdata.buf + cdata.pitch * src_row + src_col;
- *dest_scan = *src_pixel;
- }
- dest_scan++;
- }
- }
+ auto func = [&cdata](const DownSampleData& data, uint8_t* dest) {
+ const uint8_t* src_pixel =
+ cdata.buf + cdata.pitch * data.src_row + data.src_col;
+ *dest = *src_pixel;
+ };
+ DoDownSampleLoop(cdata, 1, func);
}
}
@@ -436,28 +416,19 @@ void CFX_ImageTransformer::CalcMono(const CalcData& cdata,
};
DoBicubicLoop(cdata, destBpp, func);
} else {
- CPDF_FixedMatrix result2stretch_fix(cdata.matrix, 8);
- for (int row = 0; row < m_result.Height(); row++) {
- uint8_t* dest_pos = (uint8_t*)cdata.bitmap->GetScanline(row);
- for (int col = 0; col < m_result.Width(); col++) {
- int src_col = 0;
- int src_row = 0;
- result2stretch_fix.Transform(col, row, &src_col, &src_row);
- if (InStretchBounds(src_col, src_row)) {
- AdjustCoords(&src_col, &src_row);
- uint32_t r_bgra_cmyk =
- argb[cdata.buf[src_row * cdata.pitch + src_col]];
- if (format == FXDIB_Rgba) {
- dest_pos[0] = (uint8_t)(r_bgra_cmyk >> 24);
- dest_pos[1] = (uint8_t)(r_bgra_cmyk >> 16);
- dest_pos[2] = (uint8_t)(r_bgra_cmyk >> 8);
- } else {
- *(uint32_t*)dest_pos = r_bgra_cmyk;
- }
- }
- dest_pos += destBpp;
+ auto func = [&cdata, format, &argb](const DownSampleData& data,
+ uint8_t* dest) {
+ uint32_t r_bgra_cmyk =
+ argb[cdata.buf[data.src_row * cdata.pitch + data.src_col]];
+ if (format == FXDIB_Rgba) {
+ dest[0] = (uint8_t)(r_bgra_cmyk >> 24);
+ dest[1] = (uint8_t)(r_bgra_cmyk >> 16);
+ dest[2] = (uint8_t)(r_bgra_cmyk >> 8);
+ } else {
+ *(uint32_t*)dest = r_bgra_cmyk;
}
- }
+ };
+ DoDownSampleLoop(cdata, destBpp, func);
}
}
@@ -575,45 +546,38 @@ void CFX_ImageTransformer::CalcColorDownSample(const CalcData& cdata,
FXDIB_Format format,
int Bpp) {
bool bHasAlpha = m_Storer.GetBitmap()->HasAlpha();
- int destBpp = cdata.bitmap->GetBPP() / 8;
- CPDF_FixedMatrix result2stretch_fix(cdata.matrix, 8);
- for (int row = 0; row < m_result.Height(); row++) {
- uint8_t* dest_pos = (uint8_t*)cdata.bitmap->GetScanline(row);
- for (int col = 0; col < m_result.Width(); col++) {
- int src_col = 0;
- int src_row = 0;
- result2stretch_fix.Transform(col, row, &src_col, &src_row);
- if (InStretchBounds(src_col, src_row)) {
- AdjustCoords(&src_col, &src_row);
- const uint8_t* src_pos =
- cdata.buf + src_row * cdata.pitch + src_col * Bpp;
- if (bHasAlpha) {
- if (format != FXDIB_Argb) {
- if (format == FXDIB_Rgba) {
- dest_pos[0] = src_pos[0];
- dest_pos[1] = src_pos[1];
- dest_pos[2] = src_pos[2];
- } else {
- *(uint32_t*)dest_pos = FXCMYK_TODIB(
- CmykEncode(src_pos[0], src_pos[1], src_pos[2], src_pos[3]));
- }
- } else {
- *(uint32_t*)dest_pos = FXARGB_TODIB(
- FXARGB_MAKE(src_pos[3], src_pos[2], src_pos[1], src_pos[0]));
- }
+ auto func = [&cdata, format, bHasAlpha, Bpp](const DownSampleData& data,
+ uint8_t* dest) {
+ const uint8_t* src_pos =
+ cdata.buf + data.src_row * cdata.pitch + data.src_col * Bpp;
+ uint32_t* dest32 = (uint32_t*)dest;
+ if (bHasAlpha) {
+ if (format != FXDIB_Argb) {
+ if (format == FXDIB_Rgba) {
+ dest[0] = src_pos[0];
+ dest[1] = src_pos[1];
+ dest[2] = src_pos[2];
} else {
- if (format == FXDIB_Cmyka) {
- *(uint32_t*)dest_pos = FXCMYK_TODIB(
- CmykEncode(src_pos[0], src_pos[1], src_pos[2], src_pos[3]));
- } else {
- *(uint32_t*)dest_pos = FXARGB_TODIB(
- FXARGB_MAKE(0xff, src_pos[2], src_pos[1], src_pos[0]));
- }
+ *dest32 = FXCMYK_TODIB(
+ CmykEncode(src_pos[0], src_pos[1], src_pos[2], src_pos[3]));
}
+ } else {
+ *dest32 = FXARGB_TODIB(
+ FXARGB_MAKE(src_pos[3], src_pos[2], src_pos[1], src_pos[0]));
+ }
+ } else {
+ if (format == FXDIB_Cmyka) {
+ *dest32 = FXCMYK_TODIB(
+ CmykEncode(src_pos[0], src_pos[1], src_pos[2], src_pos[3]));
+ } else {
+ *dest32 =
+ FXARGB_TODIB(FXARGB_MAKE(0xff, src_pos[2], src_pos[1], src_pos[0]));
}
- dest_pos += destBpp;
}
- }
+ };
+
+ int destBpp = cdata.bitmap->GetBPP() / 8;
+ DoDownSampleLoop(cdata, destBpp, func);
}
void CFX_ImageTransformer::AdjustCoords(int* col, int* row) const {
@@ -680,3 +644,24 @@ void CFX_ImageTransformer::DoBicubicLoop(
}
}
}
+
+void CFX_ImageTransformer::DoDownSampleLoop(
+ const CalcData& cdata,
+ int increment,
+ std::function<void(const DownSampleData&, uint8_t*)> func) {
+ CPDF_FixedMatrix matrix_fix(cdata.matrix, 8);
+ for (int row = 0; row < m_result.Height(); row++) {
+ uint8_t* dest = (uint8_t*)cdata.bitmap->GetScanline(row);
+ for (int col = 0; col < m_result.Width(); col++) {
+ DownSampleData d;
+ d.src_col = 0;
+ d.src_row = 0;
+ matrix_fix.Transform(col, row, &d.src_col, &d.src_row);
+ if (InStretchBounds(d.src_col, d.src_row)) {
+ AdjustCoords(&d.src_col, &d.src_row);
+ func(d, dest);
+ }
+ dest += increment;
+ }
+ }
+}
diff --git a/core/fxge/dib/cfx_imagetransformer.h b/core/fxge/dib/cfx_imagetransformer.h
index 6df50d7801..2a54ae1841 100644
--- a/core/fxge/dib/cfx_imagetransformer.h
+++ b/core/fxge/dib/cfx_imagetransformer.h
@@ -55,6 +55,11 @@ class CFX_ImageTransformer {
int v_w[4];
};
+ struct DownSampleData {
+ int src_col;
+ int src_row;
+ };
+
struct CalcData {
const CFX_DIBitmap* bitmap;
const CFX_Matrix& matrix;
@@ -90,6 +95,10 @@ class CFX_ImageTransformer {
void DoBicubicLoop(const CalcData& cdata,
int increment,
std::function<void(const BicubicData&, uint8_t*)> func);
+ void DoDownSampleLoop(
+ const CalcData& cdata,
+ int increment,
+ std::function<void(const DownSampleData&, uint8_t*)> func);
const RetainPtr<CFX_DIBSource> m_pSrc;
UnownedPtr<const CFX_Matrix> const m_pMatrix;