diff options
author | Lei Zhang <thestig@chromium.org> | 2017-12-04 16:48:05 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-12-04 16:48:05 +0000 |
commit | 08ed48ae2e96146b38f862d1a915c25da2bbb8ef (patch) | |
tree | 79e69fbb13b8ff42581916d04f202235e4cd4b86 /core | |
parent | a6bc91192be6e64a4ff615aba3bd057b3a810e67 (diff) | |
download | pdfium-08ed48ae2e96146b38f862d1a915c25da2bbb8ef.tar.xz |
Break out CFX_ImageTransformer mono calculations.
Change-Id: Ibd9ca20e902bbd2b62af12d25836497413912b1b
Reviewed-on: https://pdfium-review.googlesource.com/20254
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/fxge/dib/cfx_imagetransformer.cpp | 223 | ||||
-rw-r--r-- | core/fxge/dib/cfx_imagetransformer.h | 1 |
2 files changed, 115 insertions, 109 deletions
diff --git a/core/fxge/dib/cfx_imagetransformer.cpp b/core/fxge/dib/cfx_imagetransformer.cpp index 7d42e1ec48..00ac0e3032 100644 --- a/core/fxge/dib/cfx_imagetransformer.cpp +++ b/core/fxge/dib/cfx_imagetransformer.cpp @@ -295,120 +295,16 @@ bool CFX_ImageTransformer::Continue(IFX_PauseIndicator* pPause) { }; CalcMask(cdata); } + + CalcData cdata = {pTransformed.Get(), result2stretch, + m_Storer.GetBitmap()->GetBuffer(), + m_Storer.GetBitmap()->GetPitch()}; if (m_Storer.GetBitmap()->IsAlphaMask()) { - CalcData cdata = {pTransformed.Get(), result2stretch, - m_Storer.GetBitmap()->GetBuffer(), - m_Storer.GetBitmap()->GetPitch()}; CalcAlpha(cdata); } else { int Bpp = m_Storer.GetBitmap()->GetBPP() / 8; if (Bpp == 1) { - uint32_t argb[256]; - FX_ARGB* pPal = m_Storer.GetBitmap()->GetPalette(); - if (pPal) { - for (int i = 0; i < 256; i++) { - argb[i] = pPal[i]; - } - } else { - if (m_Storer.GetBitmap()->IsCmykImage()) { - for (int i = 0; i < 256; i++) { - argb[i] = 255 - i; - } - } else { - for (int i = 0; i < 256; i++) { - argb[i] = 0xff000000 | (i * 0x010101); - } - } - } - int destBpp = pTransformed->GetBPP() / 8; - if (IsBilinear()) { - CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); - for (int row = 0; row < m_result.Height(); row++) { - uint8_t* dest_pos = (uint8_t*)pTransformed->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; - int row_offset_r = src_row_r * stretch_pitch; - uint32_t r_bgra_cmyk = argb[bilinear_interpol( - stretch_buf, row_offset_l, row_offset_r, src_col_l, src_col_r, - res_x, res_y, 1, 0)]; - if (transformF == 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; - } - } - } else if (IsBiCubic()) { - CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); - for (int row = 0; row < m_result.Height(); row++) { - uint8_t* dest_pos = (uint8_t*)pTransformed->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); - uint32_t r_bgra_cmyk = - argb[bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, - u_w, v_w, res_x, res_y, 1, 0)]; - if (transformF == 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; - } - } - } else { - CPDF_FixedMatrix result2stretch_fix(result2stretch, 8); - for (int row = 0; row < m_result.Height(); row++) { - uint8_t* dest_pos = (uint8_t*)pTransformed->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[stretch_buf[src_row * stretch_pitch + src_col]]; - if (transformF == 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; - } - } - } + CalcMono(cdata, transformF); } else { bool bHasAlpha = m_Storer.GetBitmap()->HasAlpha(); int destBpp = pTransformed->GetBPP() / 8; @@ -738,6 +634,115 @@ void CFX_ImageTransformer::CalcAlpha(const CalcData& cdata) { } } +void CFX_ImageTransformer::CalcMono(const CalcData& cdata, + FXDIB_Format format) { + uint32_t argb[256]; + FX_ARGB* pPal = m_Storer.GetBitmap()->GetPalette(); + if (pPal) { + for (int i = 0; i < 256; i++) { + argb[i] = pPal[i]; + } + } else { + if (m_Storer.GetBitmap()->IsCmykImage()) { + for (int i = 0; i < 256; i++) { + argb[i] = 255 - i; + } + } else { + for (int i = 0; i < 256; i++) { + argb[i] = 0xff000000 | (i * 0x010101); + } + } + } + int destBpp = cdata.bitmap->GetBPP() / 8; + if (IsBilinear()) { + CFX_BilinearMatrix 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_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; + uint32_t r_bgra_cmyk = + argb[bilinear_interpol(cdata.buf, row_offset_l, row_offset_r, + src_col_l, src_col_r, res_x, res_y, 1, 0)]; + 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; + } + } + } else if (IsBiCubic()) { + CFX_BilinearMatrix 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_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()); + uint32_t r_bgra_cmyk = argb[bicubic_interpol( + cdata.buf, cdata.pitch, pos_pixel, u_w, v_w, res_x, res_y, 1, 0)]; + 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; + } + } + } 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; + } + } + } +} + 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 4e13f62d6c..2d7993ec5c 100644 --- a/core/fxge/dib/cfx_imagetransformer.h +++ b/core/fxge/dib/cfx_imagetransformer.h @@ -41,6 +41,7 @@ class CFX_ImageTransformer { void CalcMask(const CalcData& cdata); void CalcAlpha(const CalcData& cdata); + void CalcMono(const CalcData& cdata, FXDIB_Format format); bool IsBilinear() const { return !(m_Flags & FXDIB_DOWNSAMPLE) && !IsBiCubic(); |