From bdbb0bd92bfca52e574106c4ce5f93d9d34d3373 Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Fri, 31 Mar 2017 15:39:44 -0400 Subject: Split fx_dib part 3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moved CFX_ImageRenderer, CFX_ImageTransformer to their own files. Change-Id: Ic98403f62bea317600a933f79946a2a9bad30eeb Reviewed-on: https://pdfium-review.googlesource.com/3551 Commit-Queue: Nicolás Peña Reviewed-by: Lei Zhang Reviewed-by: Tom Sepez --- BUILD.gn | 5 +- core/fpdfapi/render/cpdf_imagerenderer.cpp | 1 + core/fxge/agg/fx_agg_driver.cpp | 1 + core/fxge/dib/cfx_dibsource.cpp | 1 + core/fxge/dib/cfx_imagerenderer.cpp | 143 +++++ core/fxge/dib/cfx_imagerenderer.h | 59 ++ core/fxge/dib/cfx_imagetransformer.cpp | 766 ++++++++++++++++++++++++++ core/fxge/dib/cfx_imagetransformer.h | 47 ++ core/fxge/dib/fx_dib_main.cpp | 194 +++---- core/fxge/dib/fx_dib_transform.cpp | 827 ----------------------------- core/fxge/fx_dib.h | 64 --- xfa/fxfa/cxfa_ffwidget.cpp | 1 + 12 files changed, 1085 insertions(+), 1024 deletions(-) create mode 100644 core/fxge/dib/cfx_imagerenderer.cpp create mode 100644 core/fxge/dib/cfx_imagerenderer.h create mode 100644 core/fxge/dib/cfx_imagetransformer.cpp create mode 100644 core/fxge/dib/cfx_imagetransformer.h delete mode 100644 core/fxge/dib/fx_dib_transform.cpp diff --git a/BUILD.gn b/BUILD.gn index 6d9e20139b..5b275fccdb 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -869,6 +869,10 @@ static_library("fxge") { "core/fxge/dib/cfx_dibsource.h", "core/fxge/dib/cfx_filtereddib.cpp", "core/fxge/dib/cfx_filtereddib.h", + "core/fxge/dib/cfx_imagerenderer.cpp", + "core/fxge/dib/cfx_imagerenderer.h", + "core/fxge/dib/cfx_imagetransformer.cpp", + "core/fxge/dib/cfx_imagetransformer.h", "core/fxge/dib/cfx_scanlinecompositor.cpp", "core/fxge/dib/cfx_scanlinecompositor.h", "core/fxge/dib/dib_int.h", @@ -876,7 +880,6 @@ static_library("fxge") { "core/fxge/dib/fx_dib_convert.cpp", "core/fxge/dib/fx_dib_engine.cpp", "core/fxge/dib/fx_dib_main.cpp", - "core/fxge/dib/fx_dib_transform.cpp", "core/fxge/fontdata/chromefontdata/FoxitDingbats.cpp", "core/fxge/fontdata/chromefontdata/FoxitFixed.cpp", "core/fxge/fontdata/chromefontdata/FoxitFixedBold.cpp", diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp index 08f9165f8a..46c35d9316 100644 --- a/core/fpdfapi/render/cpdf_imagerenderer.cpp +++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp @@ -29,6 +29,7 @@ #include "core/fxcrt/fx_safe_types.h" #include "core/fxge/cfx_fxgedevice.h" #include "core/fxge/cfx_pathdata.h" +#include "core/fxge/dib/cfx_imagetransformer.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp index ad7d2c4517..a82d3cf51c 100644 --- a/core/fxge/agg/fx_agg_driver.cpp +++ b/core/fxge/agg/fx_agg_driver.cpp @@ -14,6 +14,7 @@ #include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_pathdata.h" +#include "core/fxge/dib/cfx_imagerenderer.h" #include "core/fxge/ge/cfx_cliprgn.h" #include "third_party/agg23/agg_conv_dash.h" #include "third_party/agg23/agg_conv_stroke.h" diff --git a/core/fxge/dib/cfx_dibsource.cpp b/core/fxge/dib/cfx_dibsource.cpp index a3e5c30d5b..f1ea4adfa9 100644 --- a/core/fxge/dib/cfx_dibsource.cpp +++ b/core/fxge/dib/cfx_dibsource.cpp @@ -11,6 +11,7 @@ #include #include "core/fxge/dib/cfx_dibitmap.h" +#include "core/fxge/dib/cfx_imagetransformer.h" #include "core/fxge/ge/cfx_cliprgn.h" #include "third_party/base/ptr_util.h" diff --git a/core/fxge/dib/cfx_imagerenderer.cpp b/core/fxge/dib/cfx_imagerenderer.cpp new file mode 100644 index 0000000000..9eea474352 --- /dev/null +++ b/core/fxge/dib/cfx_imagerenderer.cpp @@ -0,0 +1,143 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fxge/dib/cfx_imagerenderer.h" + +#include + +#include "core/fxge/dib/cfx_imagetransformer.h" +#include "core/fxge/dib/dib_int.h" +#include "core/fxge/ge/cfx_cliprgn.h" +#include "third_party/base/ptr_util.h" + +CFX_ImageRenderer::CFX_ImageRenderer() + : m_Status(0), + m_pIccTransform(nullptr), + m_bRgbByteOrder(false), + m_BlendType(FXDIB_BLEND_NORMAL) {} + +CFX_ImageRenderer::~CFX_ImageRenderer() {} + +bool CFX_ImageRenderer::Start(const CFX_RetainPtr& pDevice, + const CFX_ClipRgn* pClipRgn, + const CFX_RetainPtr& pSource, + int bitmap_alpha, + uint32_t mask_color, + const CFX_Matrix* pMatrix, + uint32_t dib_flags, + bool bRgbByteOrder, + int alpha_flag, + void* pIccTransform, + int blend_type) { + m_Matrix = *pMatrix; + CFX_FloatRect image_rect_f = m_Matrix.GetUnitRect(); + FX_RECT image_rect = image_rect_f.GetOuterRect(); + m_ClipBox = pClipRgn ? pClipRgn->GetBox() : FX_RECT(0, 0, pDevice->GetWidth(), + pDevice->GetHeight()); + m_ClipBox.Intersect(image_rect); + if (m_ClipBox.IsEmpty()) + return false; + + m_pDevice = pDevice; + m_pClipRgn = pClipRgn; + m_MaskColor = mask_color; + m_BitmapAlpha = bitmap_alpha; + m_Matrix = *pMatrix; + m_Flags = dib_flags; + m_AlphaFlag = alpha_flag; + m_pIccTransform = pIccTransform; + m_bRgbByteOrder = bRgbByteOrder; + m_BlendType = blend_type; + + if ((FXSYS_fabs(m_Matrix.b) >= 0.5f || m_Matrix.a == 0) || + (FXSYS_fabs(m_Matrix.c) >= 0.5f || m_Matrix.d == 0)) { + if (FXSYS_fabs(m_Matrix.a) < FXSYS_fabs(m_Matrix.b) / 20 && + FXSYS_fabs(m_Matrix.d) < FXSYS_fabs(m_Matrix.c) / 20 && + FXSYS_fabs(m_Matrix.a) < 0.5f && FXSYS_fabs(m_Matrix.d) < 0.5f) { + int dest_width = image_rect.Width(); + int dest_height = image_rect.Height(); + FX_RECT bitmap_clip = m_ClipBox; + bitmap_clip.Offset(-image_rect.left, -image_rect.top); + bitmap_clip = FXDIB_SwapClipBox(bitmap_clip, dest_width, dest_height, + m_Matrix.c > 0, m_Matrix.b < 0); + m_Composer.Compose(pDevice, pClipRgn, bitmap_alpha, mask_color, m_ClipBox, + true, m_Matrix.c > 0, m_Matrix.b < 0, m_bRgbByteOrder, + alpha_flag, pIccTransform, m_BlendType); + m_Stretcher = pdfium::MakeUnique( + &m_Composer, pSource, dest_height, dest_width, bitmap_clip, + dib_flags); + if (!m_Stretcher->Start()) + return false; + + m_Status = 1; + return true; + } + m_Status = 2; + m_pTransformer = pdfium::MakeUnique( + pSource, &m_Matrix, dib_flags, &m_ClipBox); + m_pTransformer->Start(); + return true; + } + + int dest_width = image_rect.Width(); + if (m_Matrix.a < 0) + dest_width = -dest_width; + + int dest_height = image_rect.Height(); + if (m_Matrix.d > 0) + dest_height = -dest_height; + + if (dest_width == 0 || dest_height == 0) + return false; + + FX_RECT bitmap_clip = m_ClipBox; + bitmap_clip.Offset(-image_rect.left, -image_rect.top); + m_Composer.Compose(pDevice, pClipRgn, bitmap_alpha, mask_color, m_ClipBox, + false, false, false, m_bRgbByteOrder, alpha_flag, + pIccTransform, m_BlendType); + m_Status = 1; + m_Stretcher = pdfium::MakeUnique( + &m_Composer, pSource, dest_width, dest_height, bitmap_clip, dib_flags); + return m_Stretcher->Start(); +} + +bool CFX_ImageRenderer::Continue(IFX_Pause* pPause) { + if (m_Status == 1) + return m_Stretcher->Continue(pPause); + + if (m_Status != 2) + return false; + + if (m_pTransformer->Continue(pPause)) + return true; + + CFX_RetainPtr pBitmap = m_pTransformer->DetachBitmap(); + if (!pBitmap || !pBitmap->GetBuffer()) + return false; + + if (pBitmap->IsAlphaMask()) { + if (m_BitmapAlpha != 255) { + if (m_AlphaFlag >> 8) { + m_AlphaFlag = (((uint8_t)((m_AlphaFlag & 0xff) * m_BitmapAlpha / 255)) | + ((m_AlphaFlag >> 8) << 8)); + } else { + m_MaskColor = FXARGB_MUL_ALPHA(m_MaskColor, m_BitmapAlpha); + } + } + m_pDevice->CompositeMask( + m_pTransformer->result().left, m_pTransformer->result().top, + pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, m_MaskColor, 0, 0, + m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_AlphaFlag, m_pIccTransform); + } else { + if (m_BitmapAlpha != 255) + pBitmap->MultiplyAlpha(m_BitmapAlpha); + m_pDevice->CompositeBitmap( + m_pTransformer->result().left, m_pTransformer->result().top, + pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, 0, 0, m_BlendType, + m_pClipRgn, m_bRgbByteOrder, m_pIccTransform); + } + return false; +} diff --git a/core/fxge/dib/cfx_imagerenderer.h b/core/fxge/dib/cfx_imagerenderer.h new file mode 100644 index 0000000000..7e78bfe752 --- /dev/null +++ b/core/fxge/dib/cfx_imagerenderer.h @@ -0,0 +1,59 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXGE_DIB_CFX_IMAGERENDERER_H_ +#define CORE_FXGE_DIB_CFX_IMAGERENDERER_H_ + +#include + +#include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/fx_coordinates.h" +#include "core/fxge/dib/cfx_dibitmap.h" +#include "core/fxge/dib/cfx_dibsource.h" +#include "core/fxge/fx_dib.h" +#include "third_party/base/stl_util.h" + +class CFX_ImageTransformer; +class CFX_ImageStretcher; + +class CFX_ImageRenderer { + public: + CFX_ImageRenderer(); + ~CFX_ImageRenderer(); + + bool Start(const CFX_RetainPtr& pDevice, + const CFX_ClipRgn* pClipRgn, + const CFX_RetainPtr& pSource, + int bitmap_alpha, + uint32_t mask_color, + const CFX_Matrix* pMatrix, + uint32_t dib_flags, + bool bRgbByteOrder = false, + int alpha_flag = 0, + void* pIccTransform = nullptr, + int blend_type = FXDIB_BLEND_NORMAL); + + bool Continue(IFX_Pause* pPause); + + private: + CFX_RetainPtr m_pDevice; + const CFX_ClipRgn* m_pClipRgn; + int m_BitmapAlpha; + uint32_t m_MaskColor; + CFX_Matrix m_Matrix; + std::unique_ptr m_pTransformer; + std::unique_ptr m_Stretcher; + CFX_BitmapComposer m_Composer; + int m_Status; + FX_RECT m_ClipBox; + uint32_t m_Flags; + int m_AlphaFlag; + void* m_pIccTransform; + bool m_bRgbByteOrder; + int m_BlendType; +}; + +#endif // CORE_FXGE_DIB_CFX_IMAGERENDERER_H_ diff --git a/core/fxge/dib/cfx_imagetransformer.cpp b/core/fxge/dib/cfx_imagetransformer.cpp new file mode 100644 index 0000000000..7a519adebf --- /dev/null +++ b/core/fxge/dib/cfx_imagetransformer.cpp @@ -0,0 +1,766 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fxge/dib/cfx_imagetransformer.h" + +#include +#include + +#include "core/fxge/fx_dib.h" +#include "third_party/base/ptr_util.h" + +namespace { + +uint8_t bilinear_interpol(const uint8_t* buf, + int row_offset_l, + int row_offset_r, + int src_col_l, + int src_col_r, + int res_x, + int res_y, + int bpp, + int c_offset) { + int i_resx = 255 - res_x; + int col_bpp_l = src_col_l * bpp; + int col_bpp_r = src_col_r * bpp; + const uint8_t* buf_u = buf + row_offset_l + c_offset; + const uint8_t* buf_d = buf + row_offset_r + c_offset; + const uint8_t* src_pos0 = buf_u + col_bpp_l; + const uint8_t* src_pos1 = buf_u + col_bpp_r; + const uint8_t* src_pos2 = buf_d + col_bpp_l; + const uint8_t* src_pos3 = buf_d + col_bpp_r; + uint8_t r_pos_0 = (*src_pos0 * i_resx + *src_pos1 * res_x) >> 8; + uint8_t r_pos_1 = (*src_pos2 * i_resx + *src_pos3 * res_x) >> 8; + return (r_pos_0 * (255 - res_y) + r_pos_1 * res_y) >> 8; +} + +uint8_t bicubic_interpol(const uint8_t* buf, + int pitch, + int pos_pixel[], + int u_w[], + int v_w[], + int res_x, + int res_y, + int bpp, + int c_offset) { + int s_result = 0; + for (int i = 0; i < 4; i++) { + int a_result = 0; + for (int j = 0; j < 4; j++) { + a_result += u_w[j] * (*(uint8_t*)(buf + pos_pixel[i + 4] * pitch + + pos_pixel[j] * bpp + c_offset)); + } + s_result += a_result * v_w[i]; + } + s_result >>= 16; + return (uint8_t)(s_result < 0 ? 0 : s_result > 255 ? 255 : s_result); +} + +void bicubic_get_pos_weight(int pos_pixel[], + int u_w[], + int v_w[], + int src_col_l, + int src_row_l, + int res_x, + int res_y, + int stretch_width, + int stretch_height) { + pos_pixel[0] = src_col_l - 1; + pos_pixel[1] = src_col_l; + pos_pixel[2] = src_col_l + 1; + pos_pixel[3] = src_col_l + 2; + pos_pixel[4] = src_row_l - 1; + pos_pixel[5] = src_row_l; + pos_pixel[6] = src_row_l + 1; + pos_pixel[7] = src_row_l + 2; + for (int i = 0; i < 4; i++) { + if (pos_pixel[i] < 0) { + pos_pixel[i] = 0; + } + if (pos_pixel[i] >= stretch_width) { + pos_pixel[i] = stretch_width - 1; + } + if (pos_pixel[i + 4] < 0) { + pos_pixel[i + 4] = 0; + } + if (pos_pixel[i + 4] >= stretch_height) { + pos_pixel[i + 4] = stretch_height - 1; + } + } + u_w[0] = SDP_Table[256 + res_x]; + u_w[1] = SDP_Table[res_x]; + u_w[2] = SDP_Table[256 - res_x]; + u_w[3] = SDP_Table[512 - res_x]; + v_w[0] = SDP_Table[256 + res_y]; + v_w[1] = SDP_Table[res_y]; + v_w[2] = SDP_Table[256 - res_y]; + v_w[3] = SDP_Table[512 - res_y]; +} + +FXDIB_Format GetTransformedFormat(const CFX_RetainPtr& pDrc) { + FXDIB_Format format = pDrc->GetFormat(); + if (pDrc->IsAlphaMask()) { + format = FXDIB_8bppMask; + } else if (format >= 1025) { + format = FXDIB_Cmyka; + } else if (format <= 32 || format == FXDIB_Argb) { + format = FXDIB_Argb; + } else { + format = FXDIB_Rgba; + } + return format; +} + +class CFX_BilinearMatrix : public CPDF_FixedMatrix { + public: + CFX_BilinearMatrix(const CFX_Matrix& src, int bits) + : CPDF_FixedMatrix(src, bits) {} + inline void Transform(int x, + int y, + int& x1, + int& y1, + int& res_x, + int& res_y) { + x1 = a * x + c * y + e + base / 2; + y1 = b * x + d * y + f + base / 2; + res_x = x1 % base; + res_y = y1 % base; + if (res_x < 0 && res_x > -base) { + res_x = base + res_x; + } + if (res_y < 0 && res_x > -base) { + res_y = base + res_y; + } + x1 /= base; + y1 /= base; + } +}; + +#define FIX16_005 0.05f + +} // namespace + +CFX_ImageTransformer::CFX_ImageTransformer( + const CFX_RetainPtr& pSrc, + const CFX_Matrix* pMatrix, + int flags, + const FX_RECT* pClip) + : m_pSrc(pSrc), + m_pMatrix(pMatrix), + m_pClip(pClip), + m_Flags(flags), + m_Status(0) {} + +CFX_ImageTransformer::~CFX_ImageTransformer() {} + +bool CFX_ImageTransformer::Start() { + CFX_FloatRect unit_rect = m_pMatrix->GetUnitRect(); + FX_RECT result_rect = unit_rect.GetClosestRect(); + FX_RECT result_clip = result_rect; + if (m_pClip) + result_clip.Intersect(*m_pClip); + + if (result_clip.IsEmpty()) + return false; + + m_result = result_clip; + if (FXSYS_fabs(m_pMatrix->a) < FXSYS_fabs(m_pMatrix->b) / 20 && + FXSYS_fabs(m_pMatrix->d) < FXSYS_fabs(m_pMatrix->c) / 20 && + FXSYS_fabs(m_pMatrix->a) < 0.5f && FXSYS_fabs(m_pMatrix->d) < 0.5f) { + int dest_width = result_rect.Width(); + int dest_height = result_rect.Height(); + result_clip.Offset(-result_rect.left, -result_rect.top); + result_clip = FXDIB_SwapClipBox(result_clip, dest_width, dest_height, + m_pMatrix->c > 0, m_pMatrix->b < 0); + m_Stretcher = pdfium::MakeUnique( + &m_Storer, m_pSrc, dest_height, dest_width, result_clip, m_Flags); + m_Stretcher->Start(); + m_Status = 1; + return true; + } + if (FXSYS_fabs(m_pMatrix->b) < FIX16_005 && + FXSYS_fabs(m_pMatrix->c) < FIX16_005) { + int dest_width = m_pMatrix->a > 0 ? (int)FXSYS_ceil(m_pMatrix->a) + : (int)FXSYS_floor(m_pMatrix->a); + int dest_height = m_pMatrix->d > 0 ? (int)-FXSYS_ceil(m_pMatrix->d) + : (int)-FXSYS_floor(m_pMatrix->d); + result_clip.Offset(-result_rect.left, -result_rect.top); + m_Stretcher = pdfium::MakeUnique( + &m_Storer, m_pSrc, dest_width, dest_height, result_clip, m_Flags); + m_Stretcher->Start(); + m_Status = 2; + return true; + } + int stretch_width = (int)FXSYS_ceil(FXSYS_sqrt2(m_pMatrix->a, m_pMatrix->b)); + int stretch_height = (int)FXSYS_ceil(FXSYS_sqrt2(m_pMatrix->c, m_pMatrix->d)); + CFX_Matrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, + (float)(stretch_height)); + stretch2dest.Concat( + CFX_Matrix(m_pMatrix->a / stretch_width, m_pMatrix->b / stretch_width, + m_pMatrix->c / stretch_height, m_pMatrix->d / stretch_height, + m_pMatrix->e, m_pMatrix->f)); + m_dest2stretch.SetReverse(stretch2dest); + + CFX_FloatRect clip_rect_f(result_clip); + m_dest2stretch.TransformRect(clip_rect_f); + m_StretchClip = clip_rect_f.GetOuterRect(); + m_StretchClip.Intersect(0, 0, stretch_width, stretch_height); + m_Stretcher = pdfium::MakeUnique( + &m_Storer, m_pSrc, stretch_width, stretch_height, m_StretchClip, m_Flags); + m_Stretcher->Start(); + m_Status = 3; + return true; +} + +bool CFX_ImageTransformer::Continue(IFX_Pause* pPause) { + if (m_Status == 1) { + if (m_Stretcher->Continue(pPause)) + return true; + + if (m_Storer.GetBitmap()) { + m_Storer.Replace( + m_Storer.GetBitmap()->SwapXY(m_pMatrix->c > 0, m_pMatrix->b < 0)); + } + return false; + } + + if (m_Status == 2) + return m_Stretcher->Continue(pPause); + + if (m_Status != 3) + return false; + + if (m_Stretcher->Continue(pPause)) + return true; + + int stretch_width = m_StretchClip.Width(); + int stretch_height = m_StretchClip.Height(); + if (!m_Storer.GetBitmap()) + return false; + + const uint8_t* stretch_buf = m_Storer.GetBitmap()->GetBuffer(); + const uint8_t* stretch_buf_mask = nullptr; + if (m_Storer.GetBitmap()->m_pAlphaMask) + stretch_buf_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetBuffer(); + + int stretch_pitch = m_Storer.GetBitmap()->GetPitch(); + auto pTransformed = pdfium::MakeRetain(); + FXDIB_Format transformF = GetTransformedFormat(m_Stretcher->source()); + if (!pTransformed->Create(m_result.Width(), m_result.Height(), transformF)) + return false; + + pTransformed->Clear(0); + if (pTransformed->m_pAlphaMask) + pTransformed->m_pAlphaMask->Clear(0); + + CFX_Matrix result2stretch(1.0f, 0.0f, 0.0f, 1.0f, (float)(m_result.left), + (float)(m_result.top)); + result2stretch.Concat(m_dest2stretch); + result2stretch.Translate(-m_StretchClip.left, -m_StretchClip.top); + 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 (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { + 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, src_row_l, res_x, res_y; + result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, + res_y); + if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && + src_row_l <= stretch_height) { + if (src_col_l == stretch_width) { + src_col_l--; + } + if (src_row_l == stretch_height) { + src_row_l--; + } + int src_col_r = src_col_l + 1; + int src_row_r = src_row_l + 1; + if (src_col_r == stretch_width) { + src_col_r--; + } + if (src_row_r == stretch_height) { + 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 (m_Flags & FXDIB_BICUBIC_INTERPOL) { + 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, src_row_l, res_x, res_y; + result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, + res_y); + if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && + src_row_l <= stretch_height) { + int pos_pixel[8]; + int u_w[4], v_w[4]; + if (src_col_l == stretch_width) { + src_col_l--; + } + if (src_row_l == stretch_height) { + 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, src_row; + result2stretch_fix.Transform(col, row, src_col, src_row); + if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && + src_row <= stretch_height) { + if (src_col == stretch_width) { + src_col--; + } + if (src_row == stretch_height) { + src_row--; + } + *dest_pos_mask = + stretch_buf_mask[src_row * stretch_pitch_mask + src_col]; + } + dest_pos_mask++; + } + } + } + } + if (m_Storer.GetBitmap()->IsAlphaMask()) { + if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { + CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); + for (int row = 0; row < m_result.Height(); row++) { + uint8_t* dest_scan = (uint8_t*)pTransformed->GetScanline(row); + for (int col = 0; col < m_result.Width(); col++) { + int src_col_l, src_row_l, res_x, res_y; + result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, + res_y); + if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && + src_row_l <= stretch_height) { + if (src_col_l == stretch_width) { + src_col_l--; + } + if (src_row_l == stretch_height) { + src_row_l--; + } + int src_col_r = src_col_l + 1; + int src_row_r = src_row_l + 1; + if (src_col_r == stretch_width) { + src_col_r--; + } + if (src_row_r == stretch_height) { + src_row_r--; + } + int row_offset_l = src_row_l * stretch_pitch; + int row_offset_r = src_row_r * stretch_pitch; + *dest_scan = + bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, + src_col_l, src_col_r, res_x, res_y, 1, 0); + } + dest_scan++; + } + } + } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) { + CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); + for (int row = 0; row < m_result.Height(); row++) { + uint8_t* dest_scan = (uint8_t*)pTransformed->GetScanline(row); + for (int col = 0; col < m_result.Width(); col++) { + int src_col_l, src_row_l, res_x, res_y; + result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, + res_y); + if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && + src_row_l <= stretch_height) { + int pos_pixel[8]; + int u_w[4], v_w[4]; + if (src_col_l == stretch_width) { + src_col_l--; + } + if (src_row_l == stretch_height) { + 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_scan = bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, + u_w, v_w, res_x, res_y, 1, 0); + } + dest_scan++; + } + } + } else { + CPDF_FixedMatrix result2stretch_fix(result2stretch, 8); + for (int row = 0; row < m_result.Height(); row++) { + uint8_t* dest_scan = (uint8_t*)pTransformed->GetScanline(row); + for (int col = 0; col < m_result.Width(); col++) { + int src_col, src_row; + result2stretch_fix.Transform(col, row, src_col, src_row); + if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && + src_row <= stretch_height) { + if (src_col == stretch_width) { + src_col--; + } + if (src_row == stretch_height) { + src_row--; + } + const uint8_t* src_pixel = + stretch_buf + stretch_pitch * src_row + src_col; + *dest_scan = *src_pixel; + } + dest_scan++; + } + } + } + } 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 (!(m_Flags & FXDIB_DOWNSAMPLE) && + !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { + 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, src_row_l, res_x, res_y; + result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, + res_y); + if (src_col_l >= 0 && src_col_l <= stretch_width && + src_row_l >= 0 && src_row_l <= stretch_height) { + if (src_col_l == stretch_width) { + src_col_l--; + } + if (src_row_l == stretch_height) { + src_row_l--; + } + int src_col_r = src_col_l + 1; + int src_row_r = src_row_l + 1; + if (src_col_r == stretch_width) { + src_col_r--; + } + if (src_row_r == stretch_height) { + 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 (m_Flags & FXDIB_BICUBIC_INTERPOL) { + 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, src_row_l, res_x, res_y; + result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, + res_y); + if (src_col_l >= 0 && src_col_l <= stretch_width && + src_row_l >= 0 && src_row_l <= stretch_height) { + int pos_pixel[8]; + int u_w[4], v_w[4]; + if (src_col_l == stretch_width) { + src_col_l--; + } + if (src_row_l == stretch_height) { + 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, src_row; + result2stretch_fix.Transform(col, row, src_col, src_row); + if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && + src_row <= stretch_height) { + if (src_col == stretch_width) { + src_col--; + } + if (src_row == stretch_height) { + 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; + } + } + } + } else { + bool bHasAlpha = m_Storer.GetBitmap()->HasAlpha(); + int destBpp = pTransformed->GetBPP() / 8; + if (!(m_Flags & FXDIB_DOWNSAMPLE) && + !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { + 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, src_row_l, res_x, res_y, r_pos_k_r = 0; + result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, + res_y); + if (src_col_l >= 0 && src_col_l <= stretch_width && + src_row_l >= 0 && src_row_l <= stretch_height) { + if (src_col_l == stretch_width) { + src_col_l--; + } + if (src_row_l == stretch_height) { + src_row_l--; + } + int src_col_r = src_col_l + 1; + int src_row_r = src_row_l + 1; + if (src_col_r == stretch_width) { + src_col_r--; + } + if (src_row_r == stretch_height) { + src_row_r--; + } + int row_offset_l = src_row_l * stretch_pitch; + int row_offset_r = src_row_r * stretch_pitch; + uint8_t r_pos_red_y_r = + bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, + src_col_l, src_col_r, res_x, res_y, Bpp, 2); + uint8_t r_pos_green_m_r = + bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, + src_col_l, src_col_r, res_x, res_y, Bpp, 1); + uint8_t r_pos_blue_c_r = + bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, + src_col_l, src_col_r, res_x, res_y, Bpp, 0); + if (bHasAlpha) { + if (transformF != FXDIB_Argb) { + if (transformF == FXDIB_Rgba) { + dest_pos[0] = r_pos_blue_c_r; + dest_pos[1] = r_pos_green_m_r; + dest_pos[2] = r_pos_red_y_r; + } else { + r_pos_k_r = bilinear_interpol( + stretch_buf, row_offset_l, row_offset_r, src_col_l, + src_col_r, res_x, res_y, Bpp, 3); + *(uint32_t*)dest_pos = + FXCMYK_TODIB(CmykEncode(r_pos_blue_c_r, r_pos_green_m_r, + r_pos_red_y_r, r_pos_k_r)); + } + } else { + uint8_t r_pos_a_r = bilinear_interpol( + stretch_buf, row_offset_l, row_offset_r, src_col_l, + src_col_r, res_x, res_y, Bpp, 3); + *(uint32_t*)dest_pos = FXARGB_TODIB( + FXARGB_MAKE(r_pos_a_r, r_pos_red_y_r, r_pos_green_m_r, + r_pos_blue_c_r)); + } + } else { + r_pos_k_r = 0xff; + if (transformF == FXDIB_Cmyka) { + r_pos_k_r = bilinear_interpol( + stretch_buf, row_offset_l, row_offset_r, src_col_l, + src_col_r, res_x, res_y, Bpp, 3); + *(uint32_t*)dest_pos = + FXCMYK_TODIB(CmykEncode(r_pos_blue_c_r, r_pos_green_m_r, + r_pos_red_y_r, r_pos_k_r)); + } else { + *(uint32_t*)dest_pos = FXARGB_TODIB( + FXARGB_MAKE(r_pos_k_r, r_pos_red_y_r, r_pos_green_m_r, + r_pos_blue_c_r)); + } + } + } + dest_pos += destBpp; + } + } + } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) { + 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, src_row_l, res_x, res_y, r_pos_k_r = 0; + result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, + res_y); + if (src_col_l >= 0 && src_col_l <= stretch_width && + src_row_l >= 0 && src_row_l <= stretch_height) { + int pos_pixel[8]; + int u_w[4], v_w[4]; + if (src_col_l == stretch_width) { + src_col_l--; + } + if (src_row_l == stretch_height) { + 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); + uint8_t r_pos_red_y_r = + bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, u_w, + v_w, res_x, res_y, Bpp, 2); + uint8_t r_pos_green_m_r = + bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, u_w, + v_w, res_x, res_y, Bpp, 1); + uint8_t r_pos_blue_c_r = + bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, u_w, + v_w, res_x, res_y, Bpp, 0); + if (bHasAlpha) { + if (transformF != FXDIB_Argb) { + if (transformF == FXDIB_Rgba) { + dest_pos[0] = r_pos_blue_c_r; + dest_pos[1] = r_pos_green_m_r; + dest_pos[2] = r_pos_red_y_r; + } else { + r_pos_k_r = + bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, + u_w, v_w, res_x, res_y, Bpp, 3); + *(uint32_t*)dest_pos = + FXCMYK_TODIB(CmykEncode(r_pos_blue_c_r, r_pos_green_m_r, + r_pos_red_y_r, r_pos_k_r)); + } + } else { + uint8_t r_pos_a_r = + bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, + u_w, v_w, res_x, res_y, Bpp, 3); + *(uint32_t*)dest_pos = FXARGB_TODIB( + FXARGB_MAKE(r_pos_a_r, r_pos_red_y_r, r_pos_green_m_r, + r_pos_blue_c_r)); + } + } else { + r_pos_k_r = 0xff; + if (transformF == FXDIB_Cmyka) { + r_pos_k_r = + bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, + u_w, v_w, res_x, res_y, Bpp, 3); + *(uint32_t*)dest_pos = + FXCMYK_TODIB(CmykEncode(r_pos_blue_c_r, r_pos_green_m_r, + r_pos_red_y_r, r_pos_k_r)); + } else { + *(uint32_t*)dest_pos = FXARGB_TODIB( + FXARGB_MAKE(r_pos_k_r, r_pos_red_y_r, r_pos_green_m_r, + r_pos_blue_c_r)); + } + } + } + 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, src_row; + result2stretch_fix.Transform(col, row, src_col, src_row); + if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && + src_row <= stretch_height) { + if (src_col == stretch_width) { + src_col--; + } + if (src_row == stretch_height) { + src_row--; + } + const uint8_t* src_pos = + stretch_buf + src_row * stretch_pitch + src_col * Bpp; + if (bHasAlpha) { + if (transformF != FXDIB_Argb) { + if (transformF == 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])); + } + } else { + if (transformF == 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])); + } + } + } + dest_pos += destBpp; + } + } + } + } + } + m_Storer.Replace(std::move(pTransformed)); + return false; +} + +CFX_RetainPtr CFX_ImageTransformer::DetachBitmap() { + return m_Storer.Detach(); +} diff --git a/core/fxge/dib/cfx_imagetransformer.h b/core/fxge/dib/cfx_imagetransformer.h new file mode 100644 index 0000000000..0183a2fab1 --- /dev/null +++ b/core/fxge/dib/cfx_imagetransformer.h @@ -0,0 +1,47 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXGE_DIB_CFX_IMAGETRANSFORMER_H_ +#define CORE_FXGE_DIB_CFX_IMAGETRANSFORMER_H_ + +#include + +#include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/fx_coordinates.h" +#include "core/fxge/dib/cfx_dibitmap.h" +#include "core/fxge/dib/cfx_dibsource.h" +#include "core/fxge/dib/dib_int.h" + +class CFX_ImageStretcher; + +class CFX_ImageTransformer { + public: + CFX_ImageTransformer(const CFX_RetainPtr& pSrc, + const CFX_Matrix* pMatrix, + int flags, + const FX_RECT* pClip); + ~CFX_ImageTransformer(); + + bool Start(); + bool Continue(IFX_Pause* pPause); + + const FX_RECT& result() const { return m_result; } + CFX_RetainPtr DetachBitmap(); + + private: + const CFX_RetainPtr m_pSrc; + const CFX_Matrix* const m_pMatrix; + const FX_RECT* const m_pClip; + FX_RECT m_StretchClip; + FX_RECT m_result; + CFX_Matrix m_dest2stretch; + std::unique_ptr m_Stretcher; + CFX_BitmapStorer m_Storer; + const uint32_t m_Flags; + int m_Status; +}; + +#endif // CORE_FXGE_DIB_CFX_IMAGETRANSFORMER_H_ diff --git a/core/fxge/dib/fx_dib_main.cpp b/core/fxge/dib/fx_dib_main.cpp index 0d9e79c27e..2ea3eeab3e 100644 --- a/core/fxge/dib/fx_dib_main.cpp +++ b/core/fxge/dib/fx_dib_main.cpp @@ -20,6 +20,68 @@ #include "core/fxge/ge/cfx_cliprgn.h" #include "third_party/base/ptr_util.h" +const int16_t SDP_Table[513] = { + 256, 256, 256, 256, 256, 256, 256, 256, 256, 255, 255, 255, 255, 255, 255, + 254, 254, 254, 254, 253, 253, 253, 252, 252, 252, 251, 251, 251, 250, 250, + 249, 249, 249, 248, 248, 247, 247, 246, 246, 245, 244, 244, 243, 243, 242, + 242, 241, 240, 240, 239, 238, 238, 237, 236, 236, 235, 234, 233, 233, 232, + 231, 230, 230, 229, 228, 227, 226, 226, 225, 224, 223, 222, 221, 220, 219, + 218, 218, 217, 216, 215, 214, 213, 212, 211, 210, 209, 208, 207, 206, 205, + 204, 203, 202, 201, 200, 199, 198, 196, 195, 194, 193, 192, 191, 190, 189, + 188, 186, 185, 184, 183, 182, 181, 179, 178, 177, 176, 175, 173, 172, 171, + 170, 169, 167, 166, 165, 164, 162, 161, 160, 159, 157, 156, 155, 154, 152, + 151, 150, 149, 147, 146, 145, 143, 142, 141, 140, 138, 137, 136, 134, 133, + 132, 130, 129, 128, 126, 125, 124, 122, 121, 120, 119, 117, 116, 115, 113, + 112, 111, 109, 108, 107, 105, 104, 103, 101, 100, 99, 97, 96, 95, 93, + 92, 91, 89, 88, 87, 85, 84, 83, 81, 80, 79, 77, 76, 75, 73, + 72, 71, 69, 68, 67, 66, 64, 63, 62, 60, 59, 58, 57, 55, 54, + 53, 52, 50, 49, 48, 47, 45, 44, 43, 42, 40, 39, 38, 37, 36, + 34, 33, 32, 31, 30, 28, 27, 26, 25, 24, 23, 21, 20, 19, 18, + 17, 16, 15, 14, 13, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, + 1, 0, 0, -1, -2, -3, -4, -5, -6, -7, -7, -8, -9, -10, -11, + -12, -12, -13, -14, -15, -15, -16, -17, -17, -18, -19, -19, -20, -21, -21, + -22, -22, -23, -24, -24, -25, -25, -26, -26, -27, -27, -27, -28, -28, -29, + -29, -30, -30, -30, -31, -31, -31, -32, -32, -32, -33, -33, -33, -33, -34, + -34, -34, -34, -35, -35, -35, -35, -35, -36, -36, -36, -36, -36, -36, -36, + -36, -36, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, + -37, -37, -37, -37, -37, -37, -37, -37, -36, -36, -36, -36, -36, -36, -36, + -36, -36, -35, -35, -35, -35, -35, -35, -34, -34, -34, -34, -34, -33, -33, + -33, -33, -33, -32, -32, -32, -32, -31, -31, -31, -31, -30, -30, -30, -30, + -29, -29, -29, -29, -28, -28, -28, -27, -27, -27, -27, -26, -26, -26, -25, + -25, -25, -24, -24, -24, -23, -23, -23, -22, -22, -22, -22, -21, -21, -21, + -20, -20, -20, -19, -19, -19, -18, -18, -18, -17, -17, -17, -16, -16, -16, + -15, -15, -15, -14, -14, -14, -13, -13, -13, -12, -12, -12, -11, -11, -11, + -10, -10, -10, -9, -9, -9, -9, -8, -8, -8, -7, -7, -7, -7, -6, + -6, -6, -6, -5, -5, -5, -5, -4, -4, -4, -4, -3, -3, -3, -3, + -3, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, +}; + +FX_RECT FXDIB_SwapClipBox(FX_RECT& clip, + int width, + int height, + bool bFlipX, + bool bFlipY) { + FX_RECT rect; + if (bFlipY) { + rect.left = height - clip.top; + rect.right = height - clip.bottom; + } else { + rect.left = clip.top; + rect.right = clip.bottom; + } + if (bFlipX) { + rect.top = width - clip.left; + rect.bottom = width - clip.right; + } else { + rect.top = clip.left; + rect.bottom = clip.right; + } + rect.Normalize(); + return rect; +} + void CmykDecode(uint32_t cmyk, int& c, int& m, int& y, int& k) { c = FXSYS_GetCValue(cmyk); m = FXSYS_GetMValue(cmyk); @@ -1083,138 +1145,6 @@ CFX_DIBExtractor::CFX_DIBExtractor(const CFX_RetainPtr& pSrc) { CFX_DIBExtractor::~CFX_DIBExtractor() {} -CFX_ImageRenderer::CFX_ImageRenderer() { - m_Status = 0; - m_pIccTransform = nullptr; - m_bRgbByteOrder = false; - m_BlendType = FXDIB_BLEND_NORMAL; -} - -CFX_ImageRenderer::~CFX_ImageRenderer() {} - -bool CFX_ImageRenderer::Start(const CFX_RetainPtr& pDevice, - const CFX_ClipRgn* pClipRgn, - const CFX_RetainPtr& pSource, - int bitmap_alpha, - uint32_t mask_color, - const CFX_Matrix* pMatrix, - uint32_t dib_flags, - bool bRgbByteOrder, - int alpha_flag, - void* pIccTransform, - int blend_type) { - m_Matrix = *pMatrix; - CFX_FloatRect image_rect_f = m_Matrix.GetUnitRect(); - FX_RECT image_rect = image_rect_f.GetOuterRect(); - m_ClipBox = pClipRgn ? pClipRgn->GetBox() : FX_RECT(0, 0, pDevice->GetWidth(), - pDevice->GetHeight()); - m_ClipBox.Intersect(image_rect); - if (m_ClipBox.IsEmpty()) - return false; - - m_pDevice = pDevice; - m_pClipRgn = pClipRgn; - m_MaskColor = mask_color; - m_BitmapAlpha = bitmap_alpha; - m_Matrix = *pMatrix; - m_Flags = dib_flags; - m_AlphaFlag = alpha_flag; - m_pIccTransform = pIccTransform; - m_bRgbByteOrder = bRgbByteOrder; - m_BlendType = blend_type; - - if ((FXSYS_fabs(m_Matrix.b) >= 0.5f || m_Matrix.a == 0) || - (FXSYS_fabs(m_Matrix.c) >= 0.5f || m_Matrix.d == 0)) { - if (FXSYS_fabs(m_Matrix.a) < FXSYS_fabs(m_Matrix.b) / 20 && - FXSYS_fabs(m_Matrix.d) < FXSYS_fabs(m_Matrix.c) / 20 && - FXSYS_fabs(m_Matrix.a) < 0.5f && FXSYS_fabs(m_Matrix.d) < 0.5f) { - int dest_width = image_rect.Width(); - int dest_height = image_rect.Height(); - FX_RECT bitmap_clip = m_ClipBox; - bitmap_clip.Offset(-image_rect.left, -image_rect.top); - bitmap_clip = FXDIB_SwapClipBox(bitmap_clip, dest_width, dest_height, - m_Matrix.c > 0, m_Matrix.b < 0); - m_Composer.Compose(pDevice, pClipRgn, bitmap_alpha, mask_color, m_ClipBox, - true, m_Matrix.c > 0, m_Matrix.b < 0, m_bRgbByteOrder, - alpha_flag, pIccTransform, m_BlendType); - m_Stretcher = pdfium::MakeUnique( - &m_Composer, pSource, dest_height, dest_width, bitmap_clip, - dib_flags); - if (!m_Stretcher->Start()) - return false; - - m_Status = 1; - return true; - } - m_Status = 2; - m_pTransformer.reset( - new CFX_ImageTransformer(pSource, &m_Matrix, dib_flags, &m_ClipBox)); - m_pTransformer->Start(); - return true; - } - - int dest_width = image_rect.Width(); - if (m_Matrix.a < 0) - dest_width = -dest_width; - - int dest_height = image_rect.Height(); - if (m_Matrix.d > 0) - dest_height = -dest_height; - - if (dest_width == 0 || dest_height == 0) - return false; - - FX_RECT bitmap_clip = m_ClipBox; - bitmap_clip.Offset(-image_rect.left, -image_rect.top); - m_Composer.Compose(pDevice, pClipRgn, bitmap_alpha, mask_color, m_ClipBox, - false, false, false, m_bRgbByteOrder, alpha_flag, - pIccTransform, m_BlendType); - m_Status = 1; - m_Stretcher = pdfium::MakeUnique( - &m_Composer, pSource, dest_width, dest_height, bitmap_clip, dib_flags); - return m_Stretcher->Start(); -} - -bool CFX_ImageRenderer::Continue(IFX_Pause* pPause) { - if (m_Status == 1) - return m_Stretcher->Continue(pPause); - - if (m_Status == 2) { - if (m_pTransformer->Continue(pPause)) - return true; - - CFX_RetainPtr pBitmap = m_pTransformer->DetachBitmap(); - if (!pBitmap || !pBitmap->GetBuffer()) - return false; - - if (pBitmap->IsAlphaMask()) { - if (m_BitmapAlpha != 255) { - if (m_AlphaFlag >> 8) { - m_AlphaFlag = - (((uint8_t)((m_AlphaFlag & 0xff) * m_BitmapAlpha / 255)) | - ((m_AlphaFlag >> 8) << 8)); - } else { - m_MaskColor = FXARGB_MUL_ALPHA(m_MaskColor, m_BitmapAlpha); - } - } - m_pDevice->CompositeMask( - m_pTransformer->result().left, m_pTransformer->result().top, - pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, m_MaskColor, 0, 0, - m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_AlphaFlag, - m_pIccTransform); - } else { - if (m_BitmapAlpha != 255) - pBitmap->MultiplyAlpha(m_BitmapAlpha); - m_pDevice->CompositeBitmap( - m_pTransformer->result().left, m_pTransformer->result().top, - pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, 0, 0, m_BlendType, - m_pClipRgn, m_bRgbByteOrder, m_pIccTransform); - } - return false; - } - return false; -} - CFX_BitmapStorer::CFX_BitmapStorer() { } diff --git a/core/fxge/dib/fx_dib_transform.cpp b/core/fxge/dib/fx_dib_transform.cpp deleted file mode 100644 index 72de148ecb..0000000000 --- a/core/fxge/dib/fx_dib_transform.cpp +++ /dev/null @@ -1,827 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fxge/dib/dib_int.h" - -#include -#include - -#include "core/fxge/fx_dib.h" -#include "third_party/base/ptr_util.h" - -namespace { - -uint8_t bilinear_interpol(const uint8_t* buf, - int row_offset_l, - int row_offset_r, - int src_col_l, - int src_col_r, - int res_x, - int res_y, - int bpp, - int c_offset) { - int i_resx = 255 - res_x; - int col_bpp_l = src_col_l * bpp; - int col_bpp_r = src_col_r * bpp; - const uint8_t* buf_u = buf + row_offset_l + c_offset; - const uint8_t* buf_d = buf + row_offset_r + c_offset; - const uint8_t* src_pos0 = buf_u + col_bpp_l; - const uint8_t* src_pos1 = buf_u + col_bpp_r; - const uint8_t* src_pos2 = buf_d + col_bpp_l; - const uint8_t* src_pos3 = buf_d + col_bpp_r; - uint8_t r_pos_0 = (*src_pos0 * i_resx + *src_pos1 * res_x) >> 8; - uint8_t r_pos_1 = (*src_pos2 * i_resx + *src_pos3 * res_x) >> 8; - return (r_pos_0 * (255 - res_y) + r_pos_1 * res_y) >> 8; -} - -uint8_t bicubic_interpol(const uint8_t* buf, - int pitch, - int pos_pixel[], - int u_w[], - int v_w[], - int res_x, - int res_y, - int bpp, - int c_offset) { - int s_result = 0; - for (int i = 0; i < 4; i++) { - int a_result = 0; - for (int j = 0; j < 4; j++) { - a_result += u_w[j] * (*(uint8_t*)(buf + pos_pixel[i + 4] * pitch + - pos_pixel[j] * bpp + c_offset)); - } - s_result += a_result * v_w[i]; - } - s_result >>= 16; - return (uint8_t)(s_result < 0 ? 0 : s_result > 255 ? 255 : s_result); -} - -void bicubic_get_pos_weight(int pos_pixel[], - int u_w[], - int v_w[], - int src_col_l, - int src_row_l, - int res_x, - int res_y, - int stretch_width, - int stretch_height) { - pos_pixel[0] = src_col_l - 1; - pos_pixel[1] = src_col_l; - pos_pixel[2] = src_col_l + 1; - pos_pixel[3] = src_col_l + 2; - pos_pixel[4] = src_row_l - 1; - pos_pixel[5] = src_row_l; - pos_pixel[6] = src_row_l + 1; - pos_pixel[7] = src_row_l + 2; - for (int i = 0; i < 4; i++) { - if (pos_pixel[i] < 0) { - pos_pixel[i] = 0; - } - if (pos_pixel[i] >= stretch_width) { - pos_pixel[i] = stretch_width - 1; - } - if (pos_pixel[i + 4] < 0) { - pos_pixel[i + 4] = 0; - } - if (pos_pixel[i + 4] >= stretch_height) { - pos_pixel[i + 4] = stretch_height - 1; - } - } - u_w[0] = SDP_Table[256 + res_x]; - u_w[1] = SDP_Table[res_x]; - u_w[2] = SDP_Table[256 - res_x]; - u_w[3] = SDP_Table[512 - res_x]; - v_w[0] = SDP_Table[256 + res_y]; - v_w[1] = SDP_Table[res_y]; - v_w[2] = SDP_Table[256 - res_y]; - v_w[3] = SDP_Table[512 - res_y]; -} - -FXDIB_Format GetTransformedFormat(const CFX_RetainPtr& pDrc) { - FXDIB_Format format = pDrc->GetFormat(); - if (pDrc->IsAlphaMask()) { - format = FXDIB_8bppMask; - } else if (format >= 1025) { - format = FXDIB_Cmyka; - } else if (format <= 32 || format == FXDIB_Argb) { - format = FXDIB_Argb; - } else { - format = FXDIB_Rgba; - } - return format; -} - -} // namespace - -const int16_t SDP_Table[513] = { - 256, 256, 256, 256, 256, 256, 256, 256, 256, 255, 255, 255, 255, 255, 255, - 254, 254, 254, 254, 253, 253, 253, 252, 252, 252, 251, 251, 251, 250, 250, - 249, 249, 249, 248, 248, 247, 247, 246, 246, 245, 244, 244, 243, 243, 242, - 242, 241, 240, 240, 239, 238, 238, 237, 236, 236, 235, 234, 233, 233, 232, - 231, 230, 230, 229, 228, 227, 226, 226, 225, 224, 223, 222, 221, 220, 219, - 218, 218, 217, 216, 215, 214, 213, 212, 211, 210, 209, 208, 207, 206, 205, - 204, 203, 202, 201, 200, 199, 198, 196, 195, 194, 193, 192, 191, 190, 189, - 188, 186, 185, 184, 183, 182, 181, 179, 178, 177, 176, 175, 173, 172, 171, - 170, 169, 167, 166, 165, 164, 162, 161, 160, 159, 157, 156, 155, 154, 152, - 151, 150, 149, 147, 146, 145, 143, 142, 141, 140, 138, 137, 136, 134, 133, - 132, 130, 129, 128, 126, 125, 124, 122, 121, 120, 119, 117, 116, 115, 113, - 112, 111, 109, 108, 107, 105, 104, 103, 101, 100, 99, 97, 96, 95, 93, - 92, 91, 89, 88, 87, 85, 84, 83, 81, 80, 79, 77, 76, 75, 73, - 72, 71, 69, 68, 67, 66, 64, 63, 62, 60, 59, 58, 57, 55, 54, - 53, 52, 50, 49, 48, 47, 45, 44, 43, 42, 40, 39, 38, 37, 36, - 34, 33, 32, 31, 30, 28, 27, 26, 25, 24, 23, 21, 20, 19, 18, - 17, 16, 15, 14, 13, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, - 1, 0, 0, -1, -2, -3, -4, -5, -6, -7, -7, -8, -9, -10, -11, - -12, -12, -13, -14, -15, -15, -16, -17, -17, -18, -19, -19, -20, -21, -21, - -22, -22, -23, -24, -24, -25, -25, -26, -26, -27, -27, -27, -28, -28, -29, - -29, -30, -30, -30, -31, -31, -31, -32, -32, -32, -33, -33, -33, -33, -34, - -34, -34, -34, -35, -35, -35, -35, -35, -36, -36, -36, -36, -36, -36, -36, - -36, -36, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, - -37, -37, -37, -37, -37, -37, -37, -37, -36, -36, -36, -36, -36, -36, -36, - -36, -36, -35, -35, -35, -35, -35, -35, -34, -34, -34, -34, -34, -33, -33, - -33, -33, -33, -32, -32, -32, -32, -31, -31, -31, -31, -30, -30, -30, -30, - -29, -29, -29, -29, -28, -28, -28, -27, -27, -27, -27, -26, -26, -26, -25, - -25, -25, -24, -24, -24, -23, -23, -23, -22, -22, -22, -22, -21, -21, -21, - -20, -20, -20, -19, -19, -19, -18, -18, -18, -17, -17, -17, -16, -16, -16, - -15, -15, -15, -14, -14, -14, -13, -13, -13, -12, -12, -12, -11, -11, -11, - -10, -10, -10, -9, -9, -9, -9, -8, -8, -8, -7, -7, -7, -7, -6, - -6, -6, -6, -5, -5, -5, -5, -4, -4, -4, -4, -3, -3, -3, -3, - -3, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, -}; - -class CFX_BilinearMatrix : public CPDF_FixedMatrix { - public: - CFX_BilinearMatrix(const CFX_Matrix& src, int bits) - : CPDF_FixedMatrix(src, bits) {} - inline void Transform(int x, - int y, - int& x1, - int& y1, - int& res_x, - int& res_y) { - x1 = a * x + c * y + e + base / 2; - y1 = b * x + d * y + f + base / 2; - res_x = x1 % base; - res_y = y1 % base; - if (res_x < 0 && res_x > -base) { - res_x = base + res_x; - } - if (res_y < 0 && res_x > -base) { - res_y = base + res_y; - } - x1 /= base; - y1 /= base; - } -}; - -#define FIX16_005 0.05f -FX_RECT FXDIB_SwapClipBox(FX_RECT& clip, - int width, - int height, - bool bFlipX, - bool bFlipY) { - FX_RECT rect; - if (bFlipY) { - rect.left = height - clip.top; - rect.right = height - clip.bottom; - } else { - rect.left = clip.top; - rect.right = clip.bottom; - } - if (bFlipX) { - rect.top = width - clip.left; - rect.bottom = width - clip.right; - } else { - rect.top = clip.left; - rect.bottom = clip.right; - } - rect.Normalize(); - return rect; -} - -CFX_ImageTransformer::CFX_ImageTransformer( - const CFX_RetainPtr& pSrc, - const CFX_Matrix* pMatrix, - int flags, - const FX_RECT* pClip) - : m_pSrc(pSrc), - m_pMatrix(pMatrix), - m_pClip(pClip), - m_Flags(flags), - m_Status(0) {} - -CFX_ImageTransformer::~CFX_ImageTransformer() {} - -bool CFX_ImageTransformer::Start() { - CFX_FloatRect unit_rect = m_pMatrix->GetUnitRect(); - FX_RECT result_rect = unit_rect.GetClosestRect(); - FX_RECT result_clip = result_rect; - if (m_pClip) - result_clip.Intersect(*m_pClip); - - if (result_clip.IsEmpty()) - return false; - - m_result = result_clip; - if (FXSYS_fabs(m_pMatrix->a) < FXSYS_fabs(m_pMatrix->b) / 20 && - FXSYS_fabs(m_pMatrix->d) < FXSYS_fabs(m_pMatrix->c) / 20 && - FXSYS_fabs(m_pMatrix->a) < 0.5f && FXSYS_fabs(m_pMatrix->d) < 0.5f) { - int dest_width = result_rect.Width(); - int dest_height = result_rect.Height(); - result_clip.Offset(-result_rect.left, -result_rect.top); - result_clip = FXDIB_SwapClipBox(result_clip, dest_width, dest_height, - m_pMatrix->c > 0, m_pMatrix->b < 0); - m_Stretcher = pdfium::MakeUnique( - &m_Storer, m_pSrc, dest_height, dest_width, result_clip, m_Flags); - m_Stretcher->Start(); - m_Status = 1; - return true; - } - if (FXSYS_fabs(m_pMatrix->b) < FIX16_005 && - FXSYS_fabs(m_pMatrix->c) < FIX16_005) { - int dest_width = m_pMatrix->a > 0 ? (int)FXSYS_ceil(m_pMatrix->a) - : (int)FXSYS_floor(m_pMatrix->a); - int dest_height = m_pMatrix->d > 0 ? (int)-FXSYS_ceil(m_pMatrix->d) - : (int)-FXSYS_floor(m_pMatrix->d); - result_clip.Offset(-result_rect.left, -result_rect.top); - m_Stretcher = pdfium::MakeUnique( - &m_Storer, m_pSrc, dest_width, dest_height, result_clip, m_Flags); - m_Stretcher->Start(); - m_Status = 2; - return true; - } - int stretch_width = (int)FXSYS_ceil(FXSYS_sqrt2(m_pMatrix->a, m_pMatrix->b)); - int stretch_height = (int)FXSYS_ceil(FXSYS_sqrt2(m_pMatrix->c, m_pMatrix->d)); - CFX_Matrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, - (float)(stretch_height)); - stretch2dest.Concat( - CFX_Matrix(m_pMatrix->a / stretch_width, m_pMatrix->b / stretch_width, - m_pMatrix->c / stretch_height, m_pMatrix->d / stretch_height, - m_pMatrix->e, m_pMatrix->f)); - m_dest2stretch.SetReverse(stretch2dest); - - CFX_FloatRect clip_rect_f(result_clip); - m_dest2stretch.TransformRect(clip_rect_f); - m_StretchClip = clip_rect_f.GetOuterRect(); - m_StretchClip.Intersect(0, 0, stretch_width, stretch_height); - m_Stretcher = pdfium::MakeUnique( - &m_Storer, m_pSrc, stretch_width, stretch_height, m_StretchClip, m_Flags); - m_Stretcher->Start(); - m_Status = 3; - return true; -} - -bool CFX_ImageTransformer::Continue(IFX_Pause* pPause) { - if (m_Status == 1) { - if (m_Stretcher->Continue(pPause)) - return true; - - if (m_Storer.GetBitmap()) { - m_Storer.Replace( - m_Storer.GetBitmap()->SwapXY(m_pMatrix->c > 0, m_pMatrix->b < 0)); - } - return false; - } - - if (m_Status == 2) - return m_Stretcher->Continue(pPause); - - if (m_Status != 3) - return false; - - if (m_Stretcher->Continue(pPause)) - return true; - - int stretch_width = m_StretchClip.Width(); - int stretch_height = m_StretchClip.Height(); - if (!m_Storer.GetBitmap()) - return false; - - const uint8_t* stretch_buf = m_Storer.GetBitmap()->GetBuffer(); - const uint8_t* stretch_buf_mask = nullptr; - if (m_Storer.GetBitmap()->m_pAlphaMask) - stretch_buf_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetBuffer(); - - int stretch_pitch = m_Storer.GetBitmap()->GetPitch(); - auto pTransformed = pdfium::MakeRetain(); - FXDIB_Format transformF = GetTransformedFormat(m_Stretcher->source()); - if (!pTransformed->Create(m_result.Width(), m_result.Height(), transformF)) - return false; - - pTransformed->Clear(0); - if (pTransformed->m_pAlphaMask) - pTransformed->m_pAlphaMask->Clear(0); - - CFX_Matrix result2stretch(1.0f, 0.0f, 0.0f, 1.0f, (float)(m_result.left), - (float)(m_result.top)); - result2stretch.Concat(m_dest2stretch); - result2stretch.Translate(-m_StretchClip.left, -m_StretchClip.top); - 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 (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { - 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, src_row_l, res_x, res_y; - result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, - res_y); - if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && - src_row_l <= stretch_height) { - if (src_col_l == stretch_width) { - src_col_l--; - } - if (src_row_l == stretch_height) { - src_row_l--; - } - int src_col_r = src_col_l + 1; - int src_row_r = src_row_l + 1; - if (src_col_r == stretch_width) { - src_col_r--; - } - if (src_row_r == stretch_height) { - 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 (m_Flags & FXDIB_BICUBIC_INTERPOL) { - 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, src_row_l, res_x, res_y; - result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, - res_y); - if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && - src_row_l <= stretch_height) { - int pos_pixel[8]; - int u_w[4], v_w[4]; - if (src_col_l == stretch_width) { - src_col_l--; - } - if (src_row_l == stretch_height) { - 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, src_row; - result2stretch_fix.Transform(col, row, src_col, src_row); - if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && - src_row <= stretch_height) { - if (src_col == stretch_width) { - src_col--; - } - if (src_row == stretch_height) { - src_row--; - } - *dest_pos_mask = - stretch_buf_mask[src_row * stretch_pitch_mask + src_col]; - } - dest_pos_mask++; - } - } - } - } - if (m_Storer.GetBitmap()->IsAlphaMask()) { - if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { - CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); - for (int row = 0; row < m_result.Height(); row++) { - uint8_t* dest_scan = (uint8_t*)pTransformed->GetScanline(row); - for (int col = 0; col < m_result.Width(); col++) { - int src_col_l, src_row_l, res_x, res_y; - result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, - res_y); - if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && - src_row_l <= stretch_height) { - if (src_col_l == stretch_width) { - src_col_l--; - } - if (src_row_l == stretch_height) { - src_row_l--; - } - int src_col_r = src_col_l + 1; - int src_row_r = src_row_l + 1; - if (src_col_r == stretch_width) { - src_col_r--; - } - if (src_row_r == stretch_height) { - src_row_r--; - } - int row_offset_l = src_row_l * stretch_pitch; - int row_offset_r = src_row_r * stretch_pitch; - *dest_scan = - bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, - src_col_l, src_col_r, res_x, res_y, 1, 0); - } - dest_scan++; - } - } - } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) { - CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); - for (int row = 0; row < m_result.Height(); row++) { - uint8_t* dest_scan = (uint8_t*)pTransformed->GetScanline(row); - for (int col = 0; col < m_result.Width(); col++) { - int src_col_l, src_row_l, res_x, res_y; - result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, - res_y); - if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && - src_row_l <= stretch_height) { - int pos_pixel[8]; - int u_w[4], v_w[4]; - if (src_col_l == stretch_width) { - src_col_l--; - } - if (src_row_l == stretch_height) { - 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_scan = bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, - u_w, v_w, res_x, res_y, 1, 0); - } - dest_scan++; - } - } - } else { - CPDF_FixedMatrix result2stretch_fix(result2stretch, 8); - for (int row = 0; row < m_result.Height(); row++) { - uint8_t* dest_scan = (uint8_t*)pTransformed->GetScanline(row); - for (int col = 0; col < m_result.Width(); col++) { - int src_col, src_row; - result2stretch_fix.Transform(col, row, src_col, src_row); - if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && - src_row <= stretch_height) { - if (src_col == stretch_width) { - src_col--; - } - if (src_row == stretch_height) { - src_row--; - } - const uint8_t* src_pixel = - stretch_buf + stretch_pitch * src_row + src_col; - *dest_scan = *src_pixel; - } - dest_scan++; - } - } - } - } 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 (!(m_Flags & FXDIB_DOWNSAMPLE) && - !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { - 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, src_row_l, res_x, res_y; - result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, - res_y); - if (src_col_l >= 0 && src_col_l <= stretch_width && - src_row_l >= 0 && src_row_l <= stretch_height) { - if (src_col_l == stretch_width) { - src_col_l--; - } - if (src_row_l == stretch_height) { - src_row_l--; - } - int src_col_r = src_col_l + 1; - int src_row_r = src_row_l + 1; - if (src_col_r == stretch_width) { - src_col_r--; - } - if (src_row_r == stretch_height) { - 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 (m_Flags & FXDIB_BICUBIC_INTERPOL) { - 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, src_row_l, res_x, res_y; - result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, - res_y); - if (src_col_l >= 0 && src_col_l <= stretch_width && - src_row_l >= 0 && src_row_l <= stretch_height) { - int pos_pixel[8]; - int u_w[4], v_w[4]; - if (src_col_l == stretch_width) { - src_col_l--; - } - if (src_row_l == stretch_height) { - 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, src_row; - result2stretch_fix.Transform(col, row, src_col, src_row); - if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && - src_row <= stretch_height) { - if (src_col == stretch_width) { - src_col--; - } - if (src_row == stretch_height) { - 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; - } - } - } - } else { - bool bHasAlpha = m_Storer.GetBitmap()->HasAlpha(); - int destBpp = pTransformed->GetBPP() / 8; - if (!(m_Flags & FXDIB_DOWNSAMPLE) && - !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { - 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, src_row_l, res_x, res_y, r_pos_k_r = 0; - result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, - res_y); - if (src_col_l >= 0 && src_col_l <= stretch_width && - src_row_l >= 0 && src_row_l <= stretch_height) { - if (src_col_l == stretch_width) { - src_col_l--; - } - if (src_row_l == stretch_height) { - src_row_l--; - } - int src_col_r = src_col_l + 1; - int src_row_r = src_row_l + 1; - if (src_col_r == stretch_width) { - src_col_r--; - } - if (src_row_r == stretch_height) { - src_row_r--; - } - int row_offset_l = src_row_l * stretch_pitch; - int row_offset_r = src_row_r * stretch_pitch; - uint8_t r_pos_red_y_r = - bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, - src_col_l, src_col_r, res_x, res_y, Bpp, 2); - uint8_t r_pos_green_m_r = - bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, - src_col_l, src_col_r, res_x, res_y, Bpp, 1); - uint8_t r_pos_blue_c_r = - bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, - src_col_l, src_col_r, res_x, res_y, Bpp, 0); - if (bHasAlpha) { - if (transformF != FXDIB_Argb) { - if (transformF == FXDIB_Rgba) { - dest_pos[0] = r_pos_blue_c_r; - dest_pos[1] = r_pos_green_m_r; - dest_pos[2] = r_pos_red_y_r; - } else { - r_pos_k_r = bilinear_interpol( - stretch_buf, row_offset_l, row_offset_r, src_col_l, - src_col_r, res_x, res_y, Bpp, 3); - *(uint32_t*)dest_pos = - FXCMYK_TODIB(CmykEncode(r_pos_blue_c_r, r_pos_green_m_r, - r_pos_red_y_r, r_pos_k_r)); - } - } else { - uint8_t r_pos_a_r = bilinear_interpol( - stretch_buf, row_offset_l, row_offset_r, src_col_l, - src_col_r, res_x, res_y, Bpp, 3); - *(uint32_t*)dest_pos = FXARGB_TODIB( - FXARGB_MAKE(r_pos_a_r, r_pos_red_y_r, r_pos_green_m_r, - r_pos_blue_c_r)); - } - } else { - r_pos_k_r = 0xff; - if (transformF == FXDIB_Cmyka) { - r_pos_k_r = bilinear_interpol( - stretch_buf, row_offset_l, row_offset_r, src_col_l, - src_col_r, res_x, res_y, Bpp, 3); - *(uint32_t*)dest_pos = - FXCMYK_TODIB(CmykEncode(r_pos_blue_c_r, r_pos_green_m_r, - r_pos_red_y_r, r_pos_k_r)); - } else { - *(uint32_t*)dest_pos = FXARGB_TODIB( - FXARGB_MAKE(r_pos_k_r, r_pos_red_y_r, r_pos_green_m_r, - r_pos_blue_c_r)); - } - } - } - dest_pos += destBpp; - } - } - } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) { - 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, src_row_l, res_x, res_y, r_pos_k_r = 0; - result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, - res_y); - if (src_col_l >= 0 && src_col_l <= stretch_width && - src_row_l >= 0 && src_row_l <= stretch_height) { - int pos_pixel[8]; - int u_w[4], v_w[4]; - if (src_col_l == stretch_width) { - src_col_l--; - } - if (src_row_l == stretch_height) { - 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); - uint8_t r_pos_red_y_r = - bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, u_w, - v_w, res_x, res_y, Bpp, 2); - uint8_t r_pos_green_m_r = - bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, u_w, - v_w, res_x, res_y, Bpp, 1); - uint8_t r_pos_blue_c_r = - bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, u_w, - v_w, res_x, res_y, Bpp, 0); - if (bHasAlpha) { - if (transformF != FXDIB_Argb) { - if (transformF == FXDIB_Rgba) { - dest_pos[0] = r_pos_blue_c_r; - dest_pos[1] = r_pos_green_m_r; - dest_pos[2] = r_pos_red_y_r; - } else { - r_pos_k_r = - bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, - u_w, v_w, res_x, res_y, Bpp, 3); - *(uint32_t*)dest_pos = - FXCMYK_TODIB(CmykEncode(r_pos_blue_c_r, r_pos_green_m_r, - r_pos_red_y_r, r_pos_k_r)); - } - } else { - uint8_t r_pos_a_r = - bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, - u_w, v_w, res_x, res_y, Bpp, 3); - *(uint32_t*)dest_pos = FXARGB_TODIB( - FXARGB_MAKE(r_pos_a_r, r_pos_red_y_r, r_pos_green_m_r, - r_pos_blue_c_r)); - } - } else { - r_pos_k_r = 0xff; - if (transformF == FXDIB_Cmyka) { - r_pos_k_r = - bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, - u_w, v_w, res_x, res_y, Bpp, 3); - *(uint32_t*)dest_pos = - FXCMYK_TODIB(CmykEncode(r_pos_blue_c_r, r_pos_green_m_r, - r_pos_red_y_r, r_pos_k_r)); - } else { - *(uint32_t*)dest_pos = FXARGB_TODIB( - FXARGB_MAKE(r_pos_k_r, r_pos_red_y_r, r_pos_green_m_r, - r_pos_blue_c_r)); - } - } - } - 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, src_row; - result2stretch_fix.Transform(col, row, src_col, src_row); - if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && - src_row <= stretch_height) { - if (src_col == stretch_width) { - src_col--; - } - if (src_row == stretch_height) { - src_row--; - } - const uint8_t* src_pos = - stretch_buf + src_row * stretch_pitch + src_col * Bpp; - if (bHasAlpha) { - if (transformF != FXDIB_Argb) { - if (transformF == 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])); - } - } else { - if (transformF == 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])); - } - } - } - dest_pos += destBpp; - } - } - } - } - } - m_Storer.Replace(std::move(pTransformed)); - return false; -} - -CFX_RetainPtr CFX_ImageTransformer::DetachBitmap() { - return m_Storer.Detach(); -} diff --git a/core/fxge/fx_dib.h b/core/fxge/fx_dib.h index f768afddaa..2a111ac05f 100644 --- a/core/fxge/fx_dib.h +++ b/core/fxge/fx_dib.h @@ -265,68 +265,4 @@ class CFX_ImageStretcher { int m_LineIndex; }; -class CFX_ImageTransformer { - public: - CFX_ImageTransformer(const CFX_RetainPtr& pSrc, - const CFX_Matrix* pMatrix, - int flags, - const FX_RECT* pClip); - ~CFX_ImageTransformer(); - - bool Start(); - bool Continue(IFX_Pause* pPause); - - const FX_RECT& result() const { return m_result; } - CFX_RetainPtr DetachBitmap(); - - private: - const CFX_RetainPtr m_pSrc; - const CFX_Matrix* const m_pMatrix; - const FX_RECT* const m_pClip; - FX_RECT m_StretchClip; - FX_RECT m_result; - CFX_Matrix m_dest2stretch; - std::unique_ptr m_Stretcher; - CFX_BitmapStorer m_Storer; - const uint32_t m_Flags; - int m_Status; -}; - -class CFX_ImageRenderer { - public: - CFX_ImageRenderer(); - ~CFX_ImageRenderer(); - - bool Start(const CFX_RetainPtr& pDevice, - const CFX_ClipRgn* pClipRgn, - const CFX_RetainPtr& pSource, - int bitmap_alpha, - uint32_t mask_color, - const CFX_Matrix* pMatrix, - uint32_t dib_flags, - bool bRgbByteOrder = false, - int alpha_flag = 0, - void* pIccTransform = nullptr, - int blend_type = FXDIB_BLEND_NORMAL); - - bool Continue(IFX_Pause* pPause); - - protected: - CFX_RetainPtr m_pDevice; - const CFX_ClipRgn* m_pClipRgn; - int m_BitmapAlpha; - uint32_t m_MaskColor; - CFX_Matrix m_Matrix; - std::unique_ptr m_pTransformer; - std::unique_ptr m_Stretcher; - CFX_BitmapComposer m_Composer; - int m_Status; - FX_RECT m_ClipBox; - uint32_t m_Flags; - int m_AlphaFlag; - void* m_pIccTransform; - bool m_bRgbByteOrder; - int m_BlendType; -}; - #endif // CORE_FXGE_FX_DIB_H_ diff --git a/xfa/fxfa/cxfa_ffwidget.cpp b/xfa/fxfa/cxfa_ffwidget.cpp index c815e1ccdc..e6f30c0467 100644 --- a/xfa/fxfa/cxfa_ffwidget.cpp +++ b/xfa/fxfa/cxfa_ffwidget.cpp @@ -17,6 +17,7 @@ #include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" +#include "core/fxge/dib/cfx_imagetransformer.h" #include "xfa/fwl/fwl_widgethit.h" #include "xfa/fxfa/app/cxfa_textlayout.h" #include "xfa/fxfa/cxfa_eventparam.h" -- cgit v1.2.3