OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/fpdfapi/render/cpdf_imagerenderer.h" | 7 #include "core/fpdfapi/render/cpdf_imagerenderer.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "core/fpdfapi/page/cpdf_docpagedata.h" | 12 #include "core/fpdfapi/page/cpdf_docpagedata.h" |
13 #include "core/fpdfapi/page/cpdf_image.h" | 13 #include "core/fpdfapi/page/cpdf_image.h" |
14 #include "core/fpdfapi/page/cpdf_imageobject.h" | 14 #include "core/fpdfapi/page/cpdf_imageobject.h" |
15 #include "core/fpdfapi/page/cpdf_page.h" | 15 #include "core/fpdfapi/page/cpdf_page.h" |
16 #include "core/fpdfapi/page/cpdf_pageobject.h" | 16 #include "core/fpdfapi/page/cpdf_pageobject.h" |
17 #include "core/fpdfapi/page/cpdf_shadingpattern.h" | 17 #include "core/fpdfapi/page/cpdf_shadingpattern.h" |
18 #include "core/fpdfapi/page/cpdf_tilingpattern.h" | 18 #include "core/fpdfapi/page/cpdf_tilingpattern.h" |
19 #include "core/fpdfapi/parser/cpdf_array.h" | 19 #include "core/fpdfapi/parser/cpdf_array.h" |
20 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 20 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
21 #include "core/fpdfapi/parser/cpdf_document.h" | 21 #include "core/fpdfapi/parser/cpdf_document.h" |
22 #include "core/fpdfapi/render/cpdf_pagerendercache.h" | 22 #include "core/fpdfapi/render/cpdf_pagerendercache.h" |
23 #include "core/fpdfapi/render/cpdf_rendercontext.h" | 23 #include "core/fpdfapi/render/cpdf_rendercontext.h" |
24 #include "core/fpdfapi/render/cpdf_renderstatus.h" | 24 #include "core/fpdfapi/render/cpdf_renderstatus.h" |
25 #include "core/fpdfapi/render/cpdf_transferfunc.h" | 25 #include "core/fpdfapi/render/cpdf_transferfunc.h" |
26 #include "core/fpdfapi/render/render_int.h" | 26 #include "core/fpdfapi/render/render_int.h" |
27 #include "core/fpdfdoc/cpdf_occontext.h" | 27 #include "core/fpdfdoc/cpdf_occontext.h" |
| 28 #include "core/fxcrt/cfx_maybe_owned.h" |
28 #include "core/fxcrt/fx_safe_types.h" | 29 #include "core/fxcrt/fx_safe_types.h" |
29 #include "core/fxge/cfx_fxgedevice.h" | 30 #include "core/fxge/cfx_fxgedevice.h" |
30 #include "core/fxge/cfx_pathdata.h" | 31 #include "core/fxge/cfx_pathdata.h" |
31 #include "third_party/base/ptr_util.h" | 32 #include "third_party/base/ptr_util.h" |
32 | 33 |
33 #ifdef _SKIA_SUPPORT_ | 34 #ifdef _SKIA_SUPPORT_ |
34 #include "core/fxge/skia/fx_skia_device.h" | 35 #include "core/fxge/skia/fx_skia_device.h" |
35 #endif | 36 #endif |
36 | 37 |
37 CPDF_ImageRenderer::CPDF_ImageRenderer() { | 38 CPDF_ImageRenderer::CPDF_ImageRenderer() { |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 if (m_pDIBSource->IsOpaqueImage()) { | 493 if (m_pDIBSource->IsOpaqueImage()) { |
493 CFX_PathData path; | 494 CFX_PathData path; |
494 path.AppendRect(0, 0, 1, 1); | 495 path.AppendRect(0, 0, 1, 1); |
495 path.Transform(&m_ImageMatrix); | 496 path.Transform(&m_ImageMatrix); |
496 uint32_t fill_color = | 497 uint32_t fill_color = |
497 ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha); | 498 ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha); |
498 m_pRenderStatus->m_pDevice->DrawPath(&path, nullptr, nullptr, fill_color, 0, | 499 m_pRenderStatus->m_pDevice->DrawPath(&path, nullptr, nullptr, fill_color, 0, |
499 FXFILL_WINDING); | 500 FXFILL_WINDING); |
500 return false; | 501 return false; |
501 } | 502 } |
502 const CFX_DIBSource* pAlphaMask = | 503 CFX_MaybeOwned<CFX_DIBSource> pAlphaMask; |
503 m_pDIBSource->IsAlphaMask() ? m_pDIBSource : m_pDIBSource->GetAlphaMask(); | 504 if (m_pDIBSource->IsAlphaMask()) |
| 505 pAlphaMask = const_cast<CFX_DIBSource*>(m_pDIBSource); |
| 506 else |
| 507 pAlphaMask = m_pDIBSource->CloneAlphaMask(); |
| 508 |
504 if (FXSYS_fabs(m_ImageMatrix.b) >= 0.5f || | 509 if (FXSYS_fabs(m_ImageMatrix.b) >= 0.5f || |
505 FXSYS_fabs(m_ImageMatrix.c) >= 0.5f) { | 510 FXSYS_fabs(m_ImageMatrix.c) >= 0.5f) { |
506 int left, top; | 511 int left; |
507 std::unique_ptr<CFX_DIBitmap> pTransformed( | 512 int top; |
508 pAlphaMask->TransformTo(&m_ImageMatrix, left, top)); | 513 std::unique_ptr<CFX_DIBitmap> pTransformed = |
| 514 pAlphaMask->TransformTo(&m_ImageMatrix, left, top); |
509 if (!pTransformed) | 515 if (!pTransformed) |
510 return true; | 516 return true; |
511 | 517 |
512 m_pRenderStatus->m_pDevice->SetBitMask( | 518 m_pRenderStatus->m_pDevice->SetBitMask( |
513 pTransformed.get(), left, top, | 519 pTransformed.get(), left, top, |
514 ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha)); | 520 ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha)); |
515 } else { | 521 return false; |
516 CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect(); | |
517 FX_RECT image_rect = image_rect_f.GetOuterRect(); | |
518 int dest_width = | |
519 m_ImageMatrix.a > 0 ? image_rect.Width() : -image_rect.Width(); | |
520 int dest_height = | |
521 m_ImageMatrix.d > 0 ? -image_rect.Height() : image_rect.Height(); | |
522 int left = dest_width > 0 ? image_rect.left : image_rect.right; | |
523 int top = dest_height > 0 ? image_rect.top : image_rect.bottom; | |
524 m_pRenderStatus->m_pDevice->StretchBitMask( | |
525 pAlphaMask, left, top, dest_width, dest_height, | |
526 ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha)); | |
527 } | 522 } |
528 if (m_pDIBSource != pAlphaMask) | 523 CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect(); |
529 delete pAlphaMask; | 524 FX_RECT image_rect = image_rect_f.GetOuterRect(); |
| 525 int dest_width = |
| 526 m_ImageMatrix.a > 0 ? image_rect.Width() : -image_rect.Width(); |
| 527 int dest_height = |
| 528 m_ImageMatrix.d > 0 ? -image_rect.Height() : image_rect.Height(); |
| 529 int left = dest_width > 0 ? image_rect.left : image_rect.right; |
| 530 int top = dest_height > 0 ? image_rect.top : image_rect.bottom; |
| 531 m_pRenderStatus->m_pDevice->StretchBitMask( |
| 532 pAlphaMask.Get(), left, top, dest_width, dest_height, |
| 533 ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha)); |
530 return false; | 534 return false; |
531 } | 535 } |
532 | 536 |
533 bool CPDF_ImageRenderer::Continue(IFX_Pause* pPause) { | 537 bool CPDF_ImageRenderer::Continue(IFX_Pause* pPause) { |
534 if (m_Status == 2) { | 538 if (m_Status == 2) { |
535 if (m_pTransformer->Continue(pPause)) | 539 if (m_pTransformer->Continue(pPause)) |
536 return true; | 540 return true; |
537 | 541 |
538 std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap()); | 542 std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap()); |
539 if (!pBitmap) | 543 if (!pBitmap) |
(...skipping 19 matching lines...) Expand all Loading... |
559 | 563 |
560 if (m_Status == 4) { | 564 if (m_Status == 4) { |
561 if (m_Loader.Continue(pPause)) | 565 if (m_Loader.Continue(pPause)) |
562 return true; | 566 return true; |
563 | 567 |
564 if (StartRenderDIBSource()) | 568 if (StartRenderDIBSource()) |
565 return Continue(pPause); | 569 return Continue(pPause); |
566 } | 570 } |
567 return false; | 571 return false; |
568 } | 572 } |
OLD | NEW |