| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "dib_int.h" | 7 #include "dib_int.h" |
| 8 | 8 |
| 9 #include "core/include/fxge/fx_dib.h" | 9 #include "core/include/fxge/fx_dib.h" |
| 10 | 10 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 -15, -15, -15, -14, -14, -14, -13, -13, -13, -12, -12, -12, -11, -11, -11, | 145 -15, -15, -15, -14, -14, -14, -13, -13, -13, -12, -12, -12, -11, -11, -11, |
| 146 -10, -10, -10, -9, -9, -9, -9, -8, -8, -8, -7, -7, -7, -7, -6, | 146 -10, -10, -10, -9, -9, -9, -9, -8, -8, -8, -7, -7, -7, -7, -6, |
| 147 -6, -6, -6, -5, -5, -5, -5, -4, -4, -4, -4, -3, -3, -3, -3, | 147 -6, -6, -6, -5, -5, -5, -5, -4, -4, -4, -4, -3, -3, -3, -3, |
| 148 -3, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, 0, 0, 0, | 148 -3, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, 0, 0, 0, |
| 149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 150 0, 0, 0, | 150 0, 0, 0, |
| 151 }; | 151 }; |
| 152 | 152 |
| 153 class CFX_BilinearMatrix : public CPDF_FixedMatrix { | 153 class CFX_BilinearMatrix : public CPDF_FixedMatrix { |
| 154 public: | 154 public: |
| 155 CFX_BilinearMatrix(const CFX_AffineMatrix& src, int bits) | 155 CFX_BilinearMatrix(const CFX_Matrix& src, int bits) |
| 156 : CPDF_FixedMatrix(src, bits) {} | 156 : CPDF_FixedMatrix(src, bits) {} |
| 157 inline void Transform(int x, | 157 inline void Transform(int x, |
| 158 int y, | 158 int y, |
| 159 int& x1, | 159 int& x1, |
| 160 int& y1, | 160 int& y1, |
| 161 int& res_x, | 161 int& res_x, |
| 162 int& res_y) { | 162 int& res_y) { |
| 163 x1 = a * x + c * y + e + base / 2; | 163 x1 = a * x + c * y + e + base / 2; |
| 164 y1 = b * x + d * y + f + base / 2; | 164 y1 = b * x + d * y + f + base / 2; |
| 165 res_x = x1 % base; | 165 res_x = x1 % base; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 if (bFlipX) { | 289 if (bFlipX) { |
| 290 rect.top = width - clip.left; | 290 rect.top = width - clip.left; |
| 291 rect.bottom = width - clip.right; | 291 rect.bottom = width - clip.right; |
| 292 } else { | 292 } else { |
| 293 rect.top = clip.left; | 293 rect.top = clip.left; |
| 294 rect.bottom = clip.right; | 294 rect.bottom = clip.right; |
| 295 } | 295 } |
| 296 rect.Normalize(); | 296 rect.Normalize(); |
| 297 return rect; | 297 return rect; |
| 298 } | 298 } |
| 299 CFX_DIBitmap* CFX_DIBSource::TransformTo(const CFX_AffineMatrix* pDestMatrix, | 299 CFX_DIBitmap* CFX_DIBSource::TransformTo(const CFX_Matrix* pDestMatrix, |
| 300 int& result_left, | 300 int& result_left, |
| 301 int& result_top, | 301 int& result_top, |
| 302 FX_DWORD flags, | 302 FX_DWORD flags, |
| 303 const FX_RECT* pDestClip) const { | 303 const FX_RECT* pDestClip) const { |
| 304 CFX_ImageTransformer transformer; | 304 CFX_ImageTransformer transformer; |
| 305 transformer.Start(this, pDestMatrix, flags, pDestClip); | 305 transformer.Start(this, pDestMatrix, flags, pDestClip); |
| 306 transformer.Continue(NULL); | 306 transformer.Continue(NULL); |
| 307 result_left = transformer.m_ResultLeft; | 307 result_left = transformer.m_ResultLeft; |
| 308 result_top = transformer.m_ResultTop; | 308 result_top = transformer.m_ResultTop; |
| 309 CFX_DIBitmap* pTransformed = transformer.m_Storer.Detach(); | 309 CFX_DIBitmap* pTransformed = transformer.m_Storer.Detach(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 330 stretcher.Continue(NULL); | 330 stretcher.Continue(NULL); |
| 331 } | 331 } |
| 332 return storer.Detach(); | 332 return storer.Detach(); |
| 333 } | 333 } |
| 334 CFX_ImageTransformer::CFX_ImageTransformer() { | 334 CFX_ImageTransformer::CFX_ImageTransformer() { |
| 335 m_Status = 0; | 335 m_Status = 0; |
| 336 m_pMatrix = NULL; | 336 m_pMatrix = NULL; |
| 337 } | 337 } |
| 338 CFX_ImageTransformer::~CFX_ImageTransformer() {} | 338 CFX_ImageTransformer::~CFX_ImageTransformer() {} |
| 339 FX_BOOL CFX_ImageTransformer::Start(const CFX_DIBSource* pSrc, | 339 FX_BOOL CFX_ImageTransformer::Start(const CFX_DIBSource* pSrc, |
| 340 const CFX_AffineMatrix* pDestMatrix, | 340 const CFX_Matrix* pDestMatrix, |
| 341 int flags, | 341 int flags, |
| 342 const FX_RECT* pDestClip) { | 342 const FX_RECT* pDestClip) { |
| 343 m_pMatrix = (CFX_AffineMatrix*)pDestMatrix; | 343 m_pMatrix = (CFX_Matrix*)pDestMatrix; |
| 344 CFX_FloatRect unit_rect = pDestMatrix->GetUnitRect(); | 344 CFX_FloatRect unit_rect = pDestMatrix->GetUnitRect(); |
| 345 FX_RECT result_rect = unit_rect.GetClosestRect(); | 345 FX_RECT result_rect = unit_rect.GetClosestRect(); |
| 346 FX_RECT result_clip = result_rect; | 346 FX_RECT result_clip = result_rect; |
| 347 if (pDestClip) { | 347 if (pDestClip) { |
| 348 result_clip.Intersect(*pDestClip); | 348 result_clip.Intersect(*pDestClip); |
| 349 } | 349 } |
| 350 if (result_clip.IsEmpty()) { | 350 if (result_clip.IsEmpty()) { |
| 351 return FALSE; | 351 return FALSE; |
| 352 } | 352 } |
| 353 m_ResultLeft = result_clip.left; | 353 m_ResultLeft = result_clip.left; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 377 result_clip.Offset(-result_rect.left, -result_rect.top); | 377 result_clip.Offset(-result_rect.left, -result_rect.top); |
| 378 m_Stretcher.Start(&m_Storer, pSrc, dest_width, dest_height, result_clip, | 378 m_Stretcher.Start(&m_Storer, pSrc, dest_width, dest_height, result_clip, |
| 379 flags); | 379 flags); |
| 380 m_Status = 2; | 380 m_Status = 2; |
| 381 return TRUE; | 381 return TRUE; |
| 382 } | 382 } |
| 383 int stretch_width = | 383 int stretch_width = |
| 384 (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->a, pDestMatrix->b)); | 384 (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->a, pDestMatrix->b)); |
| 385 int stretch_height = | 385 int stretch_height = |
| 386 (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->c, pDestMatrix->d)); | 386 (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->c, pDestMatrix->d)); |
| 387 CFX_AffineMatrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, | 387 CFX_Matrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, |
| 388 (FX_FLOAT)(stretch_height)); | 388 (FX_FLOAT)(stretch_height)); |
| 389 stretch2dest.Concat( | 389 stretch2dest.Concat( |
| 390 pDestMatrix->a / stretch_width, pDestMatrix->b / stretch_width, | 390 pDestMatrix->a / stretch_width, pDestMatrix->b / stretch_width, |
| 391 pDestMatrix->c / stretch_height, pDestMatrix->d / stretch_height, | 391 pDestMatrix->c / stretch_height, pDestMatrix->d / stretch_height, |
| 392 pDestMatrix->e, pDestMatrix->f); | 392 pDestMatrix->e, pDestMatrix->f); |
| 393 m_dest2stretch.SetReverse(stretch2dest); | 393 m_dest2stretch.SetReverse(stretch2dest); |
| 394 CFX_FloatRect clip_rect_f(result_clip); | 394 CFX_FloatRect clip_rect_f(result_clip); |
| 395 clip_rect_f.Transform(&m_dest2stretch); | 395 clip_rect_f.Transform(&m_dest2stretch); |
| 396 m_StretchClip = clip_rect_f.GetOutterRect(); | 396 m_StretchClip = clip_rect_f.GetOutterRect(); |
| 397 m_StretchClip.Intersect(0, 0, stretch_width, stretch_height); | 397 m_StretchClip.Intersect(0, 0, stretch_width, stretch_height); |
| 398 m_Stretcher.Start(&m_Storer, pSrc, stretch_width, stretch_height, | 398 m_Stretcher.Start(&m_Storer, pSrc, stretch_width, stretch_height, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 CFX_DIBitmap* pTransformed = new CFX_DIBitmap; | 435 CFX_DIBitmap* pTransformed = new CFX_DIBitmap; |
| 436 FXDIB_Format transformF = GetTransformedFormat(m_Stretcher.m_pSource); | 436 FXDIB_Format transformF = GetTransformedFormat(m_Stretcher.m_pSource); |
| 437 if (!pTransformed->Create(m_ResultWidth, m_ResultHeight, transformF)) { | 437 if (!pTransformed->Create(m_ResultWidth, m_ResultHeight, transformF)) { |
| 438 delete pTransformed; | 438 delete pTransformed; |
| 439 return FALSE; | 439 return FALSE; |
| 440 } | 440 } |
| 441 pTransformed->Clear(0); | 441 pTransformed->Clear(0); |
| 442 if (pTransformed->m_pAlphaMask) { | 442 if (pTransformed->m_pAlphaMask) { |
| 443 pTransformed->m_pAlphaMask->Clear(0); | 443 pTransformed->m_pAlphaMask->Clear(0); |
| 444 } | 444 } |
| 445 CFX_AffineMatrix result2stretch(1.0f, 0.0f, 0.0f, 1.0f, | 445 CFX_Matrix result2stretch(1.0f, 0.0f, 0.0f, 1.0f, (FX_FLOAT)(m_ResultLeft), |
| 446 (FX_FLOAT)(m_ResultLeft), | 446 (FX_FLOAT)(m_ResultTop)); |
| 447 (FX_FLOAT)(m_ResultTop)); | |
| 448 result2stretch.Concat(m_dest2stretch); | 447 result2stretch.Concat(m_dest2stretch); |
| 449 result2stretch.TranslateI(-m_StretchClip.left, -m_StretchClip.top); | 448 result2stretch.TranslateI(-m_StretchClip.left, -m_StretchClip.top); |
| 450 if (stretch_buf_mask == NULL && pTransformed->m_pAlphaMask) { | 449 if (stretch_buf_mask == NULL && pTransformed->m_pAlphaMask) { |
| 451 pTransformed->m_pAlphaMask->Clear(0xff000000); | 450 pTransformed->m_pAlphaMask->Clear(0xff000000); |
| 452 } else if (pTransformed->m_pAlphaMask) { | 451 } else if (pTransformed->m_pAlphaMask) { |
| 453 int stretch_pitch_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetPitch(); | 452 int stretch_pitch_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetPitch(); |
| 454 if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { | 453 if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { |
| 455 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); | 454 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); |
| 456 for (int row = 0; row < m_ResultHeight; row++) { | 455 for (int row = 0; row < m_ResultHeight; row++) { |
| 457 uint8_t* dest_pos_mask = | 456 uint8_t* dest_pos_mask = |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 } | 939 } |
| 941 dest_pos += destBpp; | 940 dest_pos += destBpp; |
| 942 } | 941 } |
| 943 } | 942 } |
| 944 } | 943 } |
| 945 } | 944 } |
| 946 } | 945 } |
| 947 m_Storer.Replace(pTransformed); | 946 m_Storer.Replace(pTransformed); |
| 948 return FALSE; | 947 return FALSE; |
| 949 } | 948 } |
| OLD | NEW |