summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-12-04 15:08:05 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-12-04 15:08:05 +0000
commit703b6f08a23a1e1d87c41266f92827ae28bf994d (patch)
treef1e9ce49993701cdb677c3cdbd53977d33d513ab /core
parentc5bfeec86aa70c2ec573c183bd3a8390a3d903e6 (diff)
downloadpdfium-703b6f08a23a1e1d87c41266f92827ae28bf994d.tar.xz
Break out CFX_ImageTransformer mask calculations.
Change-Id: Iab7ff29c2ce9ed56715b5897e89da2d9d693583c Reviewed-on: https://pdfium-review.googlesource.com/20252 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fxge/dib/cfx_imagetransformer.cpp143
-rw-r--r--core/fxge/dib/cfx_imagetransformer.h9
2 files changed, 82 insertions, 70 deletions
diff --git a/core/fxge/dib/cfx_imagetransformer.cpp b/core/fxge/dib/cfx_imagetransformer.cpp
index 3be1dbe463..7d3d0a2a37 100644
--- a/core/fxge/dib/cfx_imagetransformer.cpp
+++ b/core/fxge/dib/cfx_imagetransformer.cpp
@@ -289,76 +289,11 @@ bool CFX_ImageTransformer::Continue(IFX_PauseIndicator* pPause) {
if (!stretch_buf_mask && pTransformed->m_pAlphaMask) {
pTransformed->m_pAlphaMask->Clear(0xff000000);
} else if (pTransformed->m_pAlphaMask) {
- int stretch_pitch_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetPitch();
- if (IsBilinear()) {
- CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
- for (int row = 0; row < m_result.Height(); row++) {
- uint8_t* dest_pos_mask =
- (uint8_t*)pTransformed->m_pAlphaMask->GetScanline(row);
- for (int col = 0; col < m_result.Width(); col++) {
- int src_col_l = 0;
- int src_row_l = 0;
- int res_x = 0;
- int res_y = 0;
- result2stretch_fix.Transform(col, row, &src_col_l, &src_row_l, &res_x,
- &res_y);
- if (InStretchBounds(src_col_l, src_row_l)) {
- AdjustCoords(&src_col_l, &src_row_l);
- int src_col_r = src_col_l + 1;
- int src_row_r = src_row_l + 1;
- AdjustCoords(&src_col_r, &src_row_r);
- int row_offset_l = src_row_l * stretch_pitch_mask;
- int row_offset_r = src_row_r * stretch_pitch_mask;
- *dest_pos_mask =
- bilinear_interpol(stretch_buf_mask, row_offset_l, row_offset_r,
- src_col_l, src_col_r, res_x, res_y, 1, 0);
- }
- dest_pos_mask++;
- }
- }
- } else if (IsBiCubic()) {
- CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
- for (int row = 0; row < m_result.Height(); row++) {
- uint8_t* dest_pos_mask =
- (uint8_t*)pTransformed->m_pAlphaMask->GetScanline(row);
- for (int col = 0; col < m_result.Width(); col++) {
- int src_col_l = 0;
- int src_row_l = 0;
- int res_x = 0;
- int res_y = 0;
- result2stretch_fix.Transform(col, row, &src_col_l, &src_row_l, &res_x,
- &res_y);
- if (InStretchBounds(src_col_l, src_row_l)) {
- int pos_pixel[8];
- int u_w[4], v_w[4];
- AdjustCoords(&src_col_l, &src_row_l);
- bicubic_get_pos_weight(pos_pixel, u_w, v_w, src_col_l, src_row_l,
- res_x, res_y, stretch_width, stretch_height);
- *dest_pos_mask =
- bicubic_interpol(stretch_buf_mask, stretch_pitch_mask,
- pos_pixel, u_w, v_w, res_x, res_y, 1, 0);
- }
- dest_pos_mask++;
- }
- }
- } else {
- CPDF_FixedMatrix result2stretch_fix(result2stretch, 8);
- for (int row = 0; row < m_result.Height(); row++) {
- uint8_t* dest_pos_mask =
- (uint8_t*)pTransformed->m_pAlphaMask->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 =
- stretch_buf_mask[src_row * stretch_pitch_mask + src_col];
- }
- dest_pos_mask++;
- }
- }
- }
+ CalcData cdata = {
+ pTransformed->m_pAlphaMask.Get(), result2stretch, stretch_buf_mask,
+ m_Storer.GetBitmap()->m_pAlphaMask->GetPitch(),
+ };
+ CalcMask(cdata);
}
if (m_Storer.GetBitmap()->IsAlphaMask()) {
if (IsBilinear()) {
@@ -727,6 +662,74 @@ RetainPtr<CFX_DIBitmap> CFX_ImageTransformer::DetachBitmap() {
return m_Storer.Detach();
}
+void CFX_ImageTransformer::CalcMask(const CalcData& cdata) {
+ if (IsBilinear()) {
+ CFX_BilinearMatrix 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_l = 0;
+ int src_row_l = 0;
+ int res_x = 0;
+ int res_y = 0;
+ result2stretch_fix.Transform(col, row, &src_col_l, &src_row_l, &res_x,
+ &res_y);
+ if (InStretchBounds(src_col_l, src_row_l)) {
+ AdjustCoords(&src_col_l, &src_row_l);
+ int src_col_r = src_col_l + 1;
+ int src_row_r = src_row_l + 1;
+ AdjustCoords(&src_col_r, &src_row_r);
+ int row_offset_l = src_row_l * cdata.pitch;
+ int row_offset_r = src_row_r * cdata.pitch;
+ *dest_pos_mask =
+ bilinear_interpol(cdata.buf, row_offset_l, row_offset_r,
+ src_col_l, src_col_r, res_x, res_y, 1, 0);
+ }
+ dest_pos_mask++;
+ }
+ }
+ } else if (IsBiCubic()) {
+ CFX_BilinearMatrix 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_l = 0;
+ int src_row_l = 0;
+ int res_x = 0;
+ int res_y = 0;
+ result2stretch_fix.Transform(col, row, &src_col_l, &src_row_l, &res_x,
+ &res_y);
+ if (InStretchBounds(src_col_l, src_row_l)) {
+ int pos_pixel[8];
+ int u_w[4], v_w[4];
+ AdjustCoords(&src_col_l, &src_row_l);
+ bicubic_get_pos_weight(pos_pixel, u_w, v_w, src_col_l, src_row_l,
+ res_x, res_y, stretch_width(),
+ stretch_height());
+ *dest_pos_mask = bicubic_interpol(cdata.buf, cdata.pitch, pos_pixel,
+ u_w, v_w, res_x, res_y, 1, 0);
+ }
+ dest_pos_mask++;
+ }
+ }
+ } 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++;
+ }
+ }
+ }
+}
+
void CFX_ImageTransformer::AdjustCoords(int* col, int* row) const {
int& src_col = *col;
int& src_row = *row;
diff --git a/core/fxge/dib/cfx_imagetransformer.h b/core/fxge/dib/cfx_imagetransformer.h
index dcda687d42..47b1513499 100644
--- a/core/fxge/dib/cfx_imagetransformer.h
+++ b/core/fxge/dib/cfx_imagetransformer.h
@@ -32,6 +32,15 @@ class CFX_ImageTransformer {
RetainPtr<CFX_DIBitmap> DetachBitmap();
private:
+ struct CalcData {
+ const CFX_DIBitmap* bitmap;
+ const CFX_Matrix& matrix;
+ const uint8_t* buf;
+ int pitch;
+ };
+
+ void CalcMask(const CalcData& cdata);
+
bool IsBilinear() const {
return !(m_Flags & FXDIB_DOWNSAMPLE) && !IsBiCubic();
}