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 "render_int.h" | 7 #include "render_int.h" |
8 | 8 |
9 #include "../fpdf_page/pageint.h" | 9 #include "../fpdf_page/pageint.h" |
10 #include "core/include/fpdfapi/fpdf_module.h" | 10 #include "core/include/fpdfapi/fpdf_module.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 97 } |
98 if (bClone) { | 98 if (bClone) { |
99 delete pClone; | 99 delete pClone; |
100 } | 100 } |
101 } | 101 } |
102 return; | 102 return; |
103 } | 103 } |
104 int back_left, back_top; | 104 int back_left, back_top; |
105 FX_RECT rect(left, top, left + pDIBitmap->GetWidth(), | 105 FX_RECT rect(left, top, left + pDIBitmap->GetWidth(), |
106 top + pDIBitmap->GetHeight()); | 106 top + pDIBitmap->GetHeight()); |
107 CFX_DIBitmap* pBackdrop = | 107 nonstd::unique_ptr<CFX_DIBitmap> pBackdrop( |
108 GetBackdrop(m_pCurObj, rect, back_left, back_top, | 108 GetBackdrop(m_pCurObj, rect, back_left, back_top, |
109 blend_mode > FXDIB_BLEND_NORMAL && bIsolated); | 109 blend_mode > FXDIB_BLEND_NORMAL && bIsolated)); |
110 if (!pBackdrop) { | 110 if (!pBackdrop) |
111 return; | 111 return; |
112 } | 112 |
113 if (!pDIBitmap->IsAlphaMask()) | 113 if (!pDIBitmap->IsAlphaMask()) { |
114 pBackdrop->CompositeBitmap(left - back_left, top - back_top, | 114 pBackdrop->CompositeBitmap(left - back_left, top - back_top, |
115 pDIBitmap->GetWidth(), pDIBitmap->GetHeight(), | 115 pDIBitmap->GetWidth(), pDIBitmap->GetHeight(), |
116 pDIBitmap, 0, 0, blend_mode); | 116 pDIBitmap, 0, 0, blend_mode); |
117 else | 117 } else { |
118 pBackdrop->CompositeMask(left - back_left, top - back_top, | 118 pBackdrop->CompositeMask(left - back_left, top - back_top, |
119 pDIBitmap->GetWidth(), pDIBitmap->GetHeight(), | 119 pDIBitmap->GetWidth(), pDIBitmap->GetHeight(), |
120 pDIBitmap, mask_argb, 0, 0, blend_mode); | 120 pDIBitmap, mask_argb, 0, 0, blend_mode); |
121 CFX_DIBitmap* pBackdrop1 = new CFX_DIBitmap; | 121 } |
| 122 |
| 123 nonstd::unique_ptr<CFX_DIBitmap> pBackdrop1(new CFX_DIBitmap); |
122 pBackdrop1->Create(pBackdrop->GetWidth(), pBackdrop->GetHeight(), | 124 pBackdrop1->Create(pBackdrop->GetWidth(), pBackdrop->GetHeight(), |
123 FXDIB_Rgb32); | 125 FXDIB_Rgb32); |
124 pBackdrop1->Clear((FX_DWORD)-1); | 126 pBackdrop1->Clear((FX_DWORD)-1); |
125 pBackdrop1->CompositeBitmap(0, 0, pBackdrop->GetWidth(), | 127 pBackdrop1->CompositeBitmap(0, 0, pBackdrop->GetWidth(), |
126 pBackdrop->GetHeight(), pBackdrop, 0, 0); | 128 pBackdrop->GetHeight(), pBackdrop.get(), 0, 0); |
127 delete pBackdrop; | 129 pBackdrop = nonstd::move(pBackdrop1); |
128 pBackdrop = pBackdrop1; | 130 m_pDevice->SetDIBits(pBackdrop.get(), back_left, back_top); |
129 m_pDevice->SetDIBits(pBackdrop, back_left, back_top); | |
130 delete pBackdrop; | |
131 } | 131 } |
132 FX_COLORREF CPDF_TransferFunc::TranslateColor(FX_COLORREF rgb) { | 132 |
| 133 CPDF_TransferFunc::CPDF_TransferFunc(CPDF_Document* pDoc) : m_pPDFDoc(pDoc) {} |
| 134 |
| 135 FX_COLORREF CPDF_TransferFunc::TranslateColor(FX_COLORREF rgb) const { |
133 return FXSYS_RGB(m_Samples[FXSYS_GetRValue(rgb)], | 136 return FXSYS_RGB(m_Samples[FXSYS_GetRValue(rgb)], |
134 m_Samples[256 + FXSYS_GetGValue(rgb)], | 137 m_Samples[256 + FXSYS_GetGValue(rgb)], |
135 m_Samples[512 + FXSYS_GetBValue(rgb)]); | 138 m_Samples[512 + FXSYS_GetBValue(rgb)]); |
136 } | 139 } |
| 140 |
137 CFX_DIBSource* CPDF_TransferFunc::TranslateImage(const CFX_DIBSource* pSrc, | 141 CFX_DIBSource* CPDF_TransferFunc::TranslateImage(const CFX_DIBSource* pSrc, |
138 FX_BOOL bAutoDropSrc) { | 142 FX_BOOL bAutoDropSrc) { |
139 CPDF_DIBTransferFunc* pDest = new CPDF_DIBTransferFunc(this); | 143 CPDF_DIBTransferFunc* pDest = new CPDF_DIBTransferFunc(this); |
140 pDest->LoadSrc(pSrc, bAutoDropSrc); | 144 pDest->LoadSrc(pSrc, bAutoDropSrc); |
141 return pDest; | 145 return pDest; |
142 } | 146 } |
143 | 147 |
144 CPDF_DIBTransferFunc::~CPDF_DIBTransferFunc() { | 148 CPDF_DIBTransferFunc::~CPDF_DIBTransferFunc() { |
145 } | 149 } |
146 | 150 |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 !(m_pRenderStatus->m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) { | 767 !(m_pRenderStatus->m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) { |
764 m_Result = FALSE; | 768 m_Result = FALSE; |
765 return TRUE; | 769 return TRUE; |
766 } | 770 } |
767 FX_RECT clip_box = m_pRenderStatus->m_pDevice->GetClipBox(); | 771 FX_RECT clip_box = m_pRenderStatus->m_pDevice->GetClipBox(); |
768 FX_RECT dest_rect = clip_box; | 772 FX_RECT dest_rect = clip_box; |
769 dest_rect.Intersect(image_rect); | 773 dest_rect.Intersect(image_rect); |
770 FX_RECT dest_clip( | 774 FX_RECT dest_clip( |
771 dest_rect.left - image_rect.left, dest_rect.top - image_rect.top, | 775 dest_rect.left - image_rect.left, dest_rect.top - image_rect.top, |
772 dest_rect.right - image_rect.left, dest_rect.bottom - image_rect.top); | 776 dest_rect.right - image_rect.left, dest_rect.bottom - image_rect.top); |
773 CFX_DIBitmap* pStretched = | 777 nonstd::unique_ptr<CFX_DIBitmap> pStretched( |
774 m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip); | 778 m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip)); |
775 if (pStretched) { | 779 if (pStretched) { |
776 m_pRenderStatus->CompositeDIBitmap(pStretched, dest_rect.left, | 780 m_pRenderStatus->CompositeDIBitmap(pStretched.get(), dest_rect.left, |
777 dest_rect.top, m_FillArgb, m_BitmapAlpha, | 781 dest_rect.top, m_FillArgb, m_BitmapAlpha, |
778 m_BlendType, FALSE); | 782 m_BlendType, FALSE); |
779 delete pStretched; | |
780 pStretched = NULL; | |
781 } | 783 } |
782 return FALSE; | 784 return FALSE; |
783 } | 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 FX_DWORD fill_color = | 791 FX_DWORD 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 { |
794 const CFX_DIBSource* pAlphaMask = m_pDIBSource->IsAlphaMask() | 796 const CFX_DIBSource* pAlphaMask = m_pDIBSource->IsAlphaMask() |
795 ? m_pDIBSource | 797 ? m_pDIBSource |
796 : m_pDIBSource->GetAlphaMask(); | 798 : m_pDIBSource->GetAlphaMask(); |
797 if (FXSYS_fabs(m_ImageMatrix.b) >= 0.5f || | 799 if (FXSYS_fabs(m_ImageMatrix.b) >= 0.5f || |
798 FXSYS_fabs(m_ImageMatrix.c) >= 0.5f) { | 800 FXSYS_fabs(m_ImageMatrix.c) >= 0.5f) { |
799 int left, top; | 801 int left, top; |
800 CFX_DIBitmap* pTransformed = | 802 nonstd::unique_ptr<CFX_DIBitmap> pTransformed( |
801 pAlphaMask->TransformTo(&m_ImageMatrix, left, top); | 803 pAlphaMask->TransformTo(&m_ImageMatrix, left, top)); |
802 if (pTransformed == NULL) { | 804 if (!pTransformed) |
803 return TRUE; | 805 return TRUE; |
804 } | 806 |
805 m_pRenderStatus->m_pDevice->SetBitMask( | 807 m_pRenderStatus->m_pDevice->SetBitMask( |
806 pTransformed, left, top, | 808 pTransformed.get(), left, top, |
807 ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha)); | 809 ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha)); |
808 delete pTransformed; | |
809 } else { | 810 } else { |
810 CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect(); | 811 CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect(); |
811 FX_RECT image_rect = image_rect_f.GetOutterRect(); | 812 FX_RECT image_rect = image_rect_f.GetOutterRect(); |
812 int dest_width = | 813 int dest_width = |
813 m_ImageMatrix.a > 0 ? image_rect.Width() : -image_rect.Width(); | 814 m_ImageMatrix.a > 0 ? image_rect.Width() : -image_rect.Width(); |
814 int dest_height = | 815 int dest_height = |
815 m_ImageMatrix.d > 0 ? -image_rect.Height() : image_rect.Height(); | 816 m_ImageMatrix.d > 0 ? -image_rect.Height() : image_rect.Height(); |
816 int left = dest_width > 0 ? image_rect.left : image_rect.right; | 817 int left = dest_width > 0 ? image_rect.left : image_rect.right; |
817 int top = dest_height > 0 ? image_rect.top : image_rect.bottom; | 818 int top = dest_height > 0 ? image_rect.top : image_rect.bottom; |
818 m_pRenderStatus->m_pDevice->StretchBitMask( | 819 m_pRenderStatus->m_pDevice->StretchBitMask( |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 } | 1039 } |
1039 } | 1040 } |
1040 return FALSE; | 1041 return FALSE; |
1041 } | 1042 } |
1042 CFX_DIBitmap* CPDF_RenderStatus::LoadSMask(CPDF_Dictionary* pSMaskDict, | 1043 CFX_DIBitmap* CPDF_RenderStatus::LoadSMask(CPDF_Dictionary* pSMaskDict, |
1043 FX_RECT* pClipRect, | 1044 FX_RECT* pClipRect, |
1044 const CFX_AffineMatrix* pMatrix) { | 1045 const CFX_AffineMatrix* pMatrix) { |
1045 if (pSMaskDict == NULL) { | 1046 if (pSMaskDict == NULL) { |
1046 return NULL; | 1047 return NULL; |
1047 } | 1048 } |
1048 CFX_DIBitmap* pMask = NULL; | |
1049 int width = pClipRect->right - pClipRect->left; | 1049 int width = pClipRect->right - pClipRect->left; |
1050 int height = pClipRect->bottom - pClipRect->top; | 1050 int height = pClipRect->bottom - pClipRect->top; |
1051 FX_BOOL bLuminosity = FALSE; | 1051 FX_BOOL bLuminosity = FALSE; |
1052 bLuminosity = pSMaskDict->GetConstString(FX_BSTRC("S")) != FX_BSTRC("Alpha"); | 1052 bLuminosity = pSMaskDict->GetConstString(FX_BSTRC("S")) != FX_BSTRC("Alpha"); |
1053 CPDF_Stream* pGroup = pSMaskDict->GetStream(FX_BSTRC("G")); | 1053 CPDF_Stream* pGroup = pSMaskDict->GetStream(FX_BSTRC("G")); |
1054 if (pGroup == NULL) { | 1054 if (pGroup == NULL) { |
1055 return NULL; | 1055 return NULL; |
1056 } | 1056 } |
1057 CPDF_Function* pFunc = NULL; | 1057 nonstd::unique_ptr<CPDF_Function> pFunc; |
1058 CPDF_Object* pFuncObj = pSMaskDict->GetElementValue(FX_BSTRC("TR")); | 1058 CPDF_Object* pFuncObj = pSMaskDict->GetElementValue(FX_BSTRC("TR")); |
1059 if (pFuncObj && (pFuncObj->IsDictionary() || pFuncObj->IsStream())) | 1059 if (pFuncObj && (pFuncObj->IsDictionary() || pFuncObj->IsStream())) |
1060 pFunc = CPDF_Function::Load(pFuncObj); | 1060 pFunc.reset(CPDF_Function::Load(pFuncObj)); |
1061 | 1061 |
1062 CFX_AffineMatrix matrix = *pMatrix; | 1062 CFX_AffineMatrix matrix = *pMatrix; |
1063 matrix.TranslateI(-pClipRect->left, -pClipRect->top); | 1063 matrix.TranslateI(-pClipRect->left, -pClipRect->top); |
1064 CPDF_Form form(m_pContext->m_pDocument, m_pContext->m_pPageResources, pGroup); | 1064 CPDF_Form form(m_pContext->m_pDocument, m_pContext->m_pPageResources, pGroup); |
1065 form.ParseContent(NULL, NULL, NULL, NULL); | 1065 form.ParseContent(NULL, NULL, NULL, NULL); |
1066 CFX_FxgeDevice bitmap_device; | 1066 CFX_FxgeDevice bitmap_device; |
1067 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 1067 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
1068 if (!bitmap_device.Create(width, height, | 1068 if (!bitmap_device.Create(width, height, |
1069 bLuminosity ? FXDIB_Rgb32 : FXDIB_8bppMask)) { | 1069 bLuminosity ? FXDIB_Rgb32 : FXDIB_8bppMask)) { |
1070 return NULL; | 1070 return NULL; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 if (form.m_pFormDict) { | 1121 if (form.m_pFormDict) { |
1122 pFormResource = form.m_pFormDict->GetDict(FX_BSTRC("Resources")); | 1122 pFormResource = form.m_pFormDict->GetDict(FX_BSTRC("Resources")); |
1123 } | 1123 } |
1124 CPDF_RenderOptions options; | 1124 CPDF_RenderOptions options; |
1125 options.m_ColorMode = bLuminosity ? RENDER_COLOR_NORMAL : RENDER_COLOR_ALPHA; | 1125 options.m_ColorMode = bLuminosity ? RENDER_COLOR_NORMAL : RENDER_COLOR_ALPHA; |
1126 CPDF_RenderStatus status; | 1126 CPDF_RenderStatus status; |
1127 status.Initialize(m_pContext, &bitmap_device, NULL, NULL, NULL, NULL, | 1127 status.Initialize(m_pContext, &bitmap_device, NULL, NULL, NULL, NULL, |
1128 &options, 0, m_bDropObjects, pFormResource, TRUE, NULL, 0, | 1128 &options, 0, m_bDropObjects, pFormResource, TRUE, NULL, 0, |
1129 pCS ? pCS->GetFamily() : 0, bLuminosity); | 1129 pCS ? pCS->GetFamily() : 0, bLuminosity); |
1130 status.RenderObjectList(&form, &matrix); | 1130 status.RenderObjectList(&form, &matrix); |
1131 pMask = new CFX_DIBitmap; | 1131 nonstd::unique_ptr<CFX_DIBitmap> pMask(new CFX_DIBitmap); |
1132 if (!pMask->Create(width, height, FXDIB_8bppMask)) { | 1132 if (!pMask->Create(width, height, FXDIB_8bppMask)) |
1133 delete pMask; | 1133 return nullptr; |
1134 return NULL; | 1134 |
1135 } | |
1136 uint8_t* dest_buf = pMask->GetBuffer(); | 1135 uint8_t* dest_buf = pMask->GetBuffer(); |
1137 int dest_pitch = pMask->GetPitch(); | 1136 int dest_pitch = pMask->GetPitch(); |
1138 uint8_t* src_buf = bitmap.GetBuffer(); | 1137 uint8_t* src_buf = bitmap.GetBuffer(); |
1139 int src_pitch = bitmap.GetPitch(); | 1138 int src_pitch = bitmap.GetPitch(); |
1140 uint8_t* pTransfer = FX_Alloc(uint8_t, 256); | 1139 std::vector<uint8_t> transfers(256); |
1141 if (pFunc) { | 1140 if (pFunc) { |
1142 CFX_FixedBufGrow<FX_FLOAT, 16> results(pFunc->CountOutputs()); | 1141 CFX_FixedBufGrow<FX_FLOAT, 16> results(pFunc->CountOutputs()); |
1143 for (int i = 0; i < 256; i++) { | 1142 for (int i = 0; i < 256; i++) { |
1144 FX_FLOAT input = (FX_FLOAT)i / 255.0f; | 1143 FX_FLOAT input = (FX_FLOAT)i / 255.0f; |
1145 int nresult; | 1144 int nresult; |
1146 pFunc->Call(&input, 1, results, nresult); | 1145 pFunc->Call(&input, 1, results, nresult); |
1147 pTransfer[i] = FXSYS_round(results[0] * 255); | 1146 transfers[i] = FXSYS_round(results[0] * 255); |
1148 } | 1147 } |
1149 } else { | 1148 } else { |
1150 for (int i = 0; i < 256; i++) { | 1149 for (int i = 0; i < 256; i++) { |
1151 pTransfer[i] = i; | 1150 transfers[i] = i; |
1152 } | 1151 } |
1153 } | 1152 } |
1154 if (bLuminosity) { | 1153 if (bLuminosity) { |
1155 int Bpp = bitmap.GetBPP() / 8; | 1154 int Bpp = bitmap.GetBPP() / 8; |
1156 for (int row = 0; row < height; row++) { | 1155 for (int row = 0; row < height; row++) { |
1157 uint8_t* dest_pos = dest_buf + row * dest_pitch; | 1156 uint8_t* dest_pos = dest_buf + row * dest_pitch; |
1158 uint8_t* src_pos = src_buf + row * src_pitch; | 1157 uint8_t* src_pos = src_buf + row * src_pitch; |
1159 for (int col = 0; col < width; col++) { | 1158 for (int col = 0; col < width; col++) { |
1160 *dest_pos++ = pTransfer[FXRGB2GRAY(src_pos[2], src_pos[1], *src_pos)]; | 1159 *dest_pos++ = transfers[FXRGB2GRAY(src_pos[2], src_pos[1], *src_pos)]; |
1161 src_pos += Bpp; | 1160 src_pos += Bpp; |
1162 } | 1161 } |
1163 } | 1162 } |
1164 } else if (pFunc) { | 1163 } else if (pFunc) { |
1165 int size = dest_pitch * height; | 1164 int size = dest_pitch * height; |
1166 for (int i = 0; i < size; i++) { | 1165 for (int i = 0; i < size; i++) { |
1167 dest_buf[i] = pTransfer[src_buf[i]]; | 1166 dest_buf[i] = transfers[src_buf[i]]; |
1168 } | 1167 } |
1169 } else { | 1168 } else { |
1170 FXSYS_memcpy(dest_buf, src_buf, dest_pitch * height); | 1169 FXSYS_memcpy(dest_buf, src_buf, dest_pitch * height); |
1171 } | 1170 } |
1172 delete pFunc; | 1171 return pMask.release(); |
1173 FX_Free(pTransfer); | |
1174 return pMask; | |
1175 } | 1172 } |
OLD | NEW |