| 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 "core/fpdfapi/fpdf_render/render_int.h" | 7 #include "core/fpdfapi/fpdf_render/render_int.h" |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 bitmap_device2.GetBitmap()->ConvertFormat(FXDIB_8bppMask); | 692 bitmap_device2.GetBitmap()->ConvertFormat(FXDIB_8bppMask); |
| 693 bitmap_device1.GetBitmap()->MultiplyAlpha(bitmap_device2.GetBitmap()); | 693 bitmap_device1.GetBitmap()->MultiplyAlpha(bitmap_device2.GetBitmap()); |
| 694 if (m_BitmapAlpha < 255) { | 694 if (m_BitmapAlpha < 255) { |
| 695 bitmap_device1.GetBitmap()->MultiplyAlpha(m_BitmapAlpha); | 695 bitmap_device1.GetBitmap()->MultiplyAlpha(m_BitmapAlpha); |
| 696 } | 696 } |
| 697 } | 697 } |
| 698 m_pRenderStatus->m_pDevice->SetDIBits(bitmap_device1.GetBitmap(), rect.left, | 698 m_pRenderStatus->m_pDevice->SetDIBits(bitmap_device1.GetBitmap(), rect.left, |
| 699 rect.top, m_BlendType); | 699 rect.top, m_BlendType); |
| 700 return FALSE; | 700 return FALSE; |
| 701 } | 701 } |
| 702 |
| 702 FX_BOOL CPDF_ImageRenderer::StartDIBSource() { | 703 FX_BOOL CPDF_ImageRenderer::StartDIBSource() { |
| 703 if (!(m_Flags & RENDER_FORCE_DOWNSAMPLE) && m_pDIBSource->GetBPP() > 1) { | 704 if (!(m_Flags & RENDER_FORCE_DOWNSAMPLE) && m_pDIBSource->GetBPP() > 1) { |
| 704 int image_size = m_pDIBSource->GetBPP() / 8 * m_pDIBSource->GetWidth() * | 705 int image_size = m_pDIBSource->GetBPP() / 8 * m_pDIBSource->GetWidth() * |
| 705 m_pDIBSource->GetHeight(); | 706 m_pDIBSource->GetHeight(); |
| 706 if (image_size > FPDF_HUGE_IMAGE_SIZE && | 707 if (image_size > FPDF_HUGE_IMAGE_SIZE && |
| 707 !(m_Flags & RENDER_FORCE_HALFTONE)) { | 708 !(m_Flags & RENDER_FORCE_HALFTONE)) { |
| 708 m_Flags |= RENDER_FORCE_DOWNSAMPLE; | 709 m_Flags |= RENDER_FORCE_DOWNSAMPLE; |
| 709 } | 710 } |
| 710 } | 711 } |
| 711 if (m_pRenderStatus->m_pDevice->StartDIBits( | 712 if (m_pRenderStatus->m_pDevice->StartDIBits( |
| 712 m_pDIBSource, m_BitmapAlpha, m_FillArgb, &m_ImageMatrix, m_Flags, | 713 m_pDIBSource, m_BitmapAlpha, m_FillArgb, &m_ImageMatrix, m_Flags, |
| 713 m_DeviceHandle, 0, NULL, m_BlendType)) { | 714 m_DeviceHandle, 0, nullptr, m_BlendType)) { |
| 714 if (m_DeviceHandle) { | 715 if (m_DeviceHandle) { |
| 715 m_Status = 3; | 716 m_Status = 3; |
| 716 return TRUE; | 717 return TRUE; |
| 717 } | 718 } |
| 718 return FALSE; | 719 return FALSE; |
| 719 } | 720 } |
| 720 CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect(); | 721 CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect(); |
| 721 FX_RECT image_rect = image_rect_f.GetOutterRect(); | 722 FX_RECT image_rect = image_rect_f.GetOutterRect(); |
| 722 int dest_width = image_rect.Width(); | 723 int dest_width = image_rect.Width(); |
| 723 int dest_height = image_rect.Height(); | 724 int dest_height = image_rect.Height(); |
| 724 if ((FXSYS_fabs(m_ImageMatrix.b) >= 0.5f || m_ImageMatrix.a == 0) || | 725 if ((FXSYS_fabs(m_ImageMatrix.b) >= 0.5f || m_ImageMatrix.a == 0) || |
| 725 (FXSYS_fabs(m_ImageMatrix.c) >= 0.5f || m_ImageMatrix.d == 0)) { | 726 (FXSYS_fabs(m_ImageMatrix.c) >= 0.5f || m_ImageMatrix.d == 0)) { |
| 726 if (m_pRenderStatus->m_bPrint && | 727 if (m_pRenderStatus->m_bPrint && |
| 727 !(m_pRenderStatus->m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) { | 728 !(m_pRenderStatus->m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) { |
| 728 m_Result = FALSE; | 729 m_Result = FALSE; |
| 729 return FALSE; | 730 return FALSE; |
| 730 } | 731 } |
| 731 FX_RECT clip_box = m_pRenderStatus->m_pDevice->GetClipBox(); | 732 FX_RECT clip_box = m_pRenderStatus->m_pDevice->GetClipBox(); |
| 732 clip_box.Intersect(image_rect); | 733 clip_box.Intersect(image_rect); |
| 733 m_Status = 2; | 734 m_Status = 2; |
| 734 m_pTransformer = new CFX_ImageTransformer; | 735 m_pTransformer = new CFX_ImageTransformer(m_pDIBSource, &m_ImageMatrix, |
| 735 m_pTransformer->Start(m_pDIBSource, &m_ImageMatrix, m_Flags, &clip_box); | 736 m_Flags, &clip_box); |
| 737 m_pTransformer->Start(); |
| 736 return TRUE; | 738 return TRUE; |
| 737 } | 739 } |
| 738 if (m_ImageMatrix.a < 0) { | 740 if (m_ImageMatrix.a < 0) |
| 739 dest_width = -dest_width; | 741 dest_width = -dest_width; |
| 740 } | 742 |
| 741 if (m_ImageMatrix.d > 0) { | 743 if (m_ImageMatrix.d > 0) |
| 742 dest_height = -dest_height; | 744 dest_height = -dest_height; |
| 743 } | 745 |
| 744 int dest_left, dest_top; | 746 int dest_left = dest_width > 0 ? image_rect.left : image_rect.right; |
| 745 dest_left = dest_width > 0 ? image_rect.left : image_rect.right; | 747 int dest_top = dest_height > 0 ? image_rect.top : image_rect.bottom; |
| 746 dest_top = dest_height > 0 ? image_rect.top : image_rect.bottom; | |
| 747 if (m_pDIBSource->IsOpaqueImage() && m_BitmapAlpha == 255) { | 748 if (m_pDIBSource->IsOpaqueImage() && m_BitmapAlpha == 255) { |
| 748 if (m_pRenderStatus->m_pDevice->StretchDIBits( | 749 if (m_pRenderStatus->m_pDevice->StretchDIBits( |
| 749 m_pDIBSource, dest_left, dest_top, dest_width, dest_height, m_Flags, | 750 m_pDIBSource, dest_left, dest_top, dest_width, dest_height, m_Flags, |
| 750 NULL, m_BlendType)) { | 751 nullptr, m_BlendType)) { |
| 751 return FALSE; | 752 return FALSE; |
| 752 } | 753 } |
| 753 } | 754 } |
| 754 if (m_pDIBSource->IsAlphaMask()) { | 755 if (m_pDIBSource->IsAlphaMask()) { |
| 755 if (m_BitmapAlpha != 255) { | 756 if (m_BitmapAlpha != 255) |
| 756 m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha); | 757 m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha); |
| 757 } | |
| 758 if (m_pRenderStatus->m_pDevice->StretchBitMask( | 758 if (m_pRenderStatus->m_pDevice->StretchBitMask( |
| 759 m_pDIBSource, dest_left, dest_top, dest_width, dest_height, | 759 m_pDIBSource, dest_left, dest_top, dest_width, dest_height, |
| 760 m_FillArgb, m_Flags)) { | 760 m_FillArgb, m_Flags)) { |
| 761 return FALSE; | 761 return FALSE; |
| 762 } | 762 } |
| 763 } | 763 } |
| 764 if (m_pRenderStatus->m_bPrint && | 764 if (m_pRenderStatus->m_bPrint && |
| 765 !(m_pRenderStatus->m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) { | 765 !(m_pRenderStatus->m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) { |
| 766 m_Result = FALSE; | 766 m_Result = FALSE; |
| 767 return TRUE; | 767 return TRUE; |
| 768 } | 768 } |
| 769 |
| 769 FX_RECT clip_box = m_pRenderStatus->m_pDevice->GetClipBox(); | 770 FX_RECT clip_box = m_pRenderStatus->m_pDevice->GetClipBox(); |
| 770 FX_RECT dest_rect = clip_box; | 771 FX_RECT dest_rect = clip_box; |
| 771 dest_rect.Intersect(image_rect); | 772 dest_rect.Intersect(image_rect); |
| 772 FX_RECT dest_clip( | 773 FX_RECT dest_clip( |
| 773 dest_rect.left - image_rect.left, dest_rect.top - image_rect.top, | 774 dest_rect.left - image_rect.left, dest_rect.top - image_rect.top, |
| 774 dest_rect.right - image_rect.left, dest_rect.bottom - image_rect.top); | 775 dest_rect.right - image_rect.left, dest_rect.bottom - image_rect.top); |
| 775 std::unique_ptr<CFX_DIBitmap> pStretched( | 776 std::unique_ptr<CFX_DIBitmap> pStretched( |
| 776 m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip)); | 777 m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip)); |
| 777 if (pStretched) { | 778 if (pStretched) { |
| 778 m_pRenderStatus->CompositeDIBitmap(pStretched.get(), dest_rect.left, | 779 m_pRenderStatus->CompositeDIBitmap(pStretched.get(), dest_rect.left, |
| 779 dest_rect.top, m_FillArgb, m_BitmapAlpha, | 780 dest_rect.top, m_FillArgb, m_BitmapAlpha, |
| 780 m_BlendType, FALSE); | 781 m_BlendType, FALSE); |
| 781 } | 782 } |
| 782 return FALSE; | 783 return FALSE; |
| 783 } | 784 } |
| 785 |
| 784 FX_BOOL CPDF_ImageRenderer::StartBitmapAlpha() { | 786 FX_BOOL CPDF_ImageRenderer::StartBitmapAlpha() { |
| 785 if (m_pDIBSource->IsOpaqueImage()) { | 787 if (m_pDIBSource->IsOpaqueImage()) { |
| 786 CFX_PathData path; | 788 CFX_PathData path; |
| 787 path.AppendRect(0, 0, 1, 1); | 789 path.AppendRect(0, 0, 1, 1); |
| 788 path.Transform(&m_ImageMatrix); | 790 path.Transform(&m_ImageMatrix); |
| 789 uint32_t fill_color = | 791 uint32_t fill_color = |
| 790 ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha); | 792 ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha); |
| 791 m_pRenderStatus->m_pDevice->DrawPath(&path, NULL, NULL, fill_color, 0, | 793 m_pRenderStatus->m_pDevice->DrawPath(&path, NULL, NULL, fill_color, 0, |
| 792 FXFILL_WINDING); | 794 FXFILL_WINDING); |
| 793 } else { | 795 } else { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 817 m_pRenderStatus->m_pDevice->StretchBitMask( | 819 m_pRenderStatus->m_pDevice->StretchBitMask( |
| 818 pAlphaMask, left, top, dest_width, dest_height, | 820 pAlphaMask, left, top, dest_width, dest_height, |
| 819 ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha)); | 821 ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha)); |
| 820 } | 822 } |
| 821 if (m_pDIBSource != pAlphaMask) { | 823 if (m_pDIBSource != pAlphaMask) { |
| 822 delete pAlphaMask; | 824 delete pAlphaMask; |
| 823 } | 825 } |
| 824 } | 826 } |
| 825 return FALSE; | 827 return FALSE; |
| 826 } | 828 } |
| 829 |
| 827 FX_BOOL CPDF_ImageRenderer::Continue(IFX_Pause* pPause) { | 830 FX_BOOL CPDF_ImageRenderer::Continue(IFX_Pause* pPause) { |
| 828 if (m_Status == 2) { | 831 if (m_Status == 2) { |
| 829 if (m_pTransformer->Continue(pPause)) { | 832 if (m_pTransformer->Continue(pPause)) |
| 830 return TRUE; | 833 return TRUE; |
| 834 |
| 835 std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap()); |
| 836 if (!pBitmap) |
| 837 return FALSE; |
| 838 |
| 839 if (pBitmap->IsAlphaMask()) { |
| 840 if (m_BitmapAlpha != 255) |
| 841 m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha); |
| 842 m_Result = m_pRenderStatus->m_pDevice->SetBitMask( |
| 843 pBitmap.get(), m_pTransformer->result().left, |
| 844 m_pTransformer->result().top, m_FillArgb); |
| 845 } else { |
| 846 if (m_BitmapAlpha != 255) |
| 847 pBitmap->MultiplyAlpha(m_BitmapAlpha); |
| 848 m_Result = m_pRenderStatus->m_pDevice->SetDIBits( |
| 849 pBitmap.get(), m_pTransformer->result().left, |
| 850 m_pTransformer->result().top, m_BlendType); |
| 831 } | 851 } |
| 832 CFX_DIBitmap* pBitmap = m_pTransformer->m_Storer.Detach(); | |
| 833 if (!pBitmap) { | |
| 834 return FALSE; | |
| 835 } | |
| 836 if (pBitmap->IsAlphaMask()) { | |
| 837 if (m_BitmapAlpha != 255) { | |
| 838 m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha); | |
| 839 } | |
| 840 m_Result = m_pRenderStatus->m_pDevice->SetBitMask( | |
| 841 pBitmap, m_pTransformer->m_ResultLeft, m_pTransformer->m_ResultTop, | |
| 842 m_FillArgb); | |
| 843 } else { | |
| 844 if (m_BitmapAlpha != 255) { | |
| 845 pBitmap->MultiplyAlpha(m_BitmapAlpha); | |
| 846 } | |
| 847 m_Result = m_pRenderStatus->m_pDevice->SetDIBits( | |
| 848 pBitmap, m_pTransformer->m_ResultLeft, m_pTransformer->m_ResultTop, | |
| 849 m_BlendType); | |
| 850 } | |
| 851 delete pBitmap; | |
| 852 return FALSE; | 852 return FALSE; |
| 853 } | 853 } |
| 854 if (m_Status == 3) { | 854 if (m_Status == 3) |
| 855 return m_pRenderStatus->m_pDevice->ContinueDIBits(m_DeviceHandle, pPause); | 855 return m_pRenderStatus->m_pDevice->ContinueDIBits(m_DeviceHandle, pPause); |
| 856 } | 856 |
| 857 if (m_Status == 4) { | 857 if (m_Status == 4) { |
| 858 if (m_Loader.Continue(m_LoadHandle, pPause)) { | 858 if (m_Loader.Continue(m_LoadHandle, pPause)) |
| 859 return TRUE; | 859 return TRUE; |
| 860 } | 860 |
| 861 if (StartRenderDIBSource()) { | 861 if (StartRenderDIBSource()) |
| 862 return Continue(pPause); | 862 return Continue(pPause); |
| 863 } | |
| 864 } | 863 } |
| 865 return FALSE; | 864 return FALSE; |
| 866 } | 865 } |
| 866 |
| 867 CCodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder( | 867 CCodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder( |
| 868 const uint8_t* src_buf, | 868 const uint8_t* src_buf, |
| 869 uint32_t src_size, | 869 uint32_t src_size, |
| 870 int width, | 870 int width, |
| 871 int height, | 871 int height, |
| 872 int nComps, | 872 int nComps, |
| 873 int bpc, | 873 int bpc, |
| 874 const CPDF_Dictionary* pParams); | 874 const CPDF_Dictionary* pParams); |
| 875 CFX_DIBitmap* CPDF_RenderStatus::LoadSMask(CPDF_Dictionary* pSMaskDict, | 875 CFX_DIBitmap* CPDF_RenderStatus::LoadSMask(CPDF_Dictionary* pSMaskDict, |
| 876 FX_RECT* pClipRect, | 876 FX_RECT* pClipRect, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 } else if (pFunc) { | 996 } else if (pFunc) { |
| 997 int size = dest_pitch * height; | 997 int size = dest_pitch * height; |
| 998 for (int i = 0; i < size; i++) { | 998 for (int i = 0; i < size; i++) { |
| 999 dest_buf[i] = transfers[src_buf[i]]; | 999 dest_buf[i] = transfers[src_buf[i]]; |
| 1000 } | 1000 } |
| 1001 } else { | 1001 } else { |
| 1002 FXSYS_memcpy(dest_buf, src_buf, dest_pitch * height); | 1002 FXSYS_memcpy(dest_buf, src_buf, dest_pitch * height); |
| 1003 } | 1003 } |
| 1004 return pMask.release(); | 1004 return pMask.release(); |
| 1005 } | 1005 } |
| OLD | NEW |