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 "../../../include/fpdfapi/fpdf_module.h" | 7 #include "../../../include/fpdfapi/fpdf_module.h" |
8 #include "../../../include/fpdfapi/fpdf_page.h" | 8 #include "../../../include/fpdfapi/fpdf_page.h" |
9 #include "../../../include/fxcodec/fx_codec.h" | 9 #include "../../../include/fxcodec/fx_codec.h" |
10 #include "../../../include/fpdfapi/fpdf_render.h" | 10 #include "../../../include/fpdfapi/fpdf_render.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 pDict->SetAtName(FX_BSTRC("ColorSpace"), FX_BSTRC("DeviceRGB")); | 183 pDict->SetAtName(FX_BSTRC("ColorSpace"), FX_BSTRC("DeviceRGB")); |
184 pDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 8); | 184 pDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 8); |
185 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { | 185 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { |
186 dest_pitch = BitmapWidth * 3; | 186 dest_pitch = BitmapWidth * 3; |
187 opType = 2; | 187 opType = 2; |
188 } else { | 188 } else { |
189 opType = 0; | 189 opType = 0; |
190 } | 190 } |
191 } | 191 } |
192 const CFX_DIBitmap* pMaskBitmap = NULL; | 192 const CFX_DIBitmap* pMaskBitmap = NULL; |
| 193 FX_BOOL bDeleteMask = FALSE; |
193 if (pBitmap->HasAlpha()) { | 194 if (pBitmap->HasAlpha()) { |
194 pMaskBitmap = pBitmap->GetAlphaMask(); | 195 pMaskBitmap = pBitmap->GetAlphaMask(); |
| 196 bDeleteMask = TRUE; |
195 } | 197 } |
196 if (!pMaskBitmap && pMask) { | 198 if (!pMaskBitmap && pMask) { |
197 FXDIB_Format maskFormat = pMask->GetFormat(); | 199 FXDIB_Format maskFormat = pMask->GetFormat(); |
198 if (maskFormat == FXDIB_1bppMask || maskFormat == FXDIB_8bppMask) { | 200 if (maskFormat == FXDIB_1bppMask || maskFormat == FXDIB_8bppMask) { |
199 pMaskBitmap = pMask; | 201 pMaskBitmap = pMask; |
200 } | 202 } |
201 } | 203 } |
202 if (pMaskBitmap) { | 204 if (pMaskBitmap) { |
203 FX_INT32 maskWidth = pMaskBitmap->GetWidth(); | 205 FX_INT32 maskWidth = pMaskBitmap->GetWidth(); |
204 FX_INT32 maskHeight = pMaskBitmap->GetHeight(); | 206 FX_INT32 maskHeight = pMaskBitmap->GetHeight(); |
205 FX_LPBYTE mask_buf = NULL; | 207 FX_LPBYTE mask_buf = NULL; |
206 FX_STRSIZE mask_size; | 208 FX_STRSIZE mask_size; |
207 FX_BOOL bDeleteMask = TRUE; | |
208 CPDF_Dictionary* pMaskDict = new CPDF_Dictionary; | 209 CPDF_Dictionary* pMaskDict = new CPDF_Dictionary; |
209 pMaskDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("XObject")); | 210 pMaskDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("XObject")); |
210 pMaskDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Image")); | 211 pMaskDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Image")); |
211 pMaskDict->SetAtInteger(FX_BSTRC("Width"), maskWidth); | 212 pMaskDict->SetAtInteger(FX_BSTRC("Width"), maskWidth); |
212 pMaskDict->SetAtInteger(FX_BSTRC("Height"), maskHeight); | 213 pMaskDict->SetAtInteger(FX_BSTRC("Height"), maskHeight); |
213 pMaskDict->SetAtName(FX_BSTRC("ColorSpace"), FX_BSTRC("DeviceGray")); | 214 pMaskDict->SetAtName(FX_BSTRC("ColorSpace"), FX_BSTRC("DeviceGray")); |
214 pMaskDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 8); | 215 pMaskDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 8); |
215 if (pMaskBitmap->GetBPP() == 8 && (iCompress & PDF_IMAGE_MASK_LOSSY_COMP
RESS) != 0) { | 216 if (pMaskBitmap->GetBPP() == 8 && (iCompress & PDF_IMAGE_MASK_LOSSY_COMP
RESS) != 0) { |
216 _DCTEncodeBitmap(pMaskDict, pMaskBitmap, pParam ? pParam->nQuality :
75, mask_buf, mask_size); | 217 _DCTEncodeBitmap(pMaskDict, pMaskBitmap, pParam ? pParam->nQuality :
75, mask_buf, mask_size); |
217 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) { | 218 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) { |
218 _JBIG2EncodeBitmap(pMaskDict, pMaskBitmap, m_pDocument, mask_buf, ma
sk_size, TRUE); | 219 _JBIG2EncodeBitmap(pMaskDict, pMaskBitmap, m_pDocument, mask_buf, ma
sk_size, TRUE); |
219 } else { | 220 } else { |
220 mask_buf = FX_Alloc2D(FX_BYTE, maskHeight, maskWidth); | 221 mask_buf = FX_Alloc2D(FX_BYTE, maskHeight, maskWidth); |
221 mask_size = maskHeight * maskWidth; // Safe since checked alloc ret
urned. | 222 mask_size = maskHeight * maskWidth; // Safe since checked alloc ret
urned. |
222 for (FX_INT32 a = 0; a < maskHeight; a ++) { | 223 for (FX_INT32 a = 0; a < maskHeight; a ++) { |
223 FXSYS_memcpy32(mask_buf + a * maskWidth, pMaskBitmap->GetScanlin
e(a), maskWidth); | 224 FXSYS_memcpy32(mask_buf + a * maskWidth, pMaskBitmap->GetScanlin
e(a), maskWidth); |
224 } | 225 } |
225 } | 226 } |
226 if (pMaskDict) { | 227 pMaskDict->SetAtInteger(FX_BSTRC("Length"), mask_size); |
227 pMaskDict->SetAtInteger(FX_BSTRC("Length"), mask_size); | 228 if (bUseMatte) { |
228 CPDF_Stream* pMaskStream = NULL; | 229 int a, r, g, b; |
229 if (bUseMatte) { | 230 ArgbDecode(*(pParam->pMatteColor), a, r, g, b); |
230 int a, r, g, b; | 231 CPDF_Array* pMatte = new CPDF_Array; |
231 ArgbDecode(*(pParam->pMatteColor), a, r, g, b); | 232 pMatte->AddInteger(r); |
232 CPDF_Array* pMatte = new CPDF_Array; | 233 pMatte->AddInteger(g); |
233 pMatte->AddInteger(r); | 234 pMatte->AddInteger(b); |
234 pMatte->AddInteger(g); | 235 pMaskDict->SetAt(FX_BSTRC("Matte"), pMatte); |
235 pMatte->AddInteger(b); | |
236 pMaskDict->SetAt(FX_BSTRC("Matte"), pMatte); | |
237 } | |
238 pMaskStream = new CPDF_Stream(mask_buf, mask_size, pMaskDict); | |
239 m_pDocument->AddIndirectObject(pMaskStream); | |
240 bDeleteMask = FALSE; | |
241 pDict->SetAtReference(FX_BSTRC("SMask"), m_pDocument, pMaskStream); | |
242 } | 236 } |
243 if (pBitmap->HasAlpha()) { | 237 CPDF_Stream* pMaskStream = new CPDF_Stream(mask_buf, mask_size, pMaskDic
t); |
| 238 m_pDocument->AddIndirectObject(pMaskStream); |
| 239 pDict->SetAtReference(FX_BSTRC("SMask"), m_pDocument, pMaskStream); |
| 240 if (bDeleteMask) { |
244 delete pMaskBitmap; | 241 delete pMaskBitmap; |
245 } | 242 } |
246 } | 243 } |
247 FX_BOOL bStream = pFileWrite != NULL && pFileRead != NULL; | 244 FX_BOOL bStream = pFileWrite != NULL && pFileRead != NULL; |
248 if (opType == 0) { | 245 if (opType == 0) { |
249 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) { | 246 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) { |
250 if (pBitmap->GetBPP() == 1) { | 247 if (pBitmap->GetBPP() == 1) { |
251 _JBIG2EncodeBitmap(pDict, pBitmap, m_pDocument, dest_buf, dest_s
ize, TRUE); | 248 _JBIG2EncodeBitmap(pDict, pBitmap, m_pDocument, dest_buf, dest_s
ize, TRUE); |
252 } | 249 } |
253 } else { | 250 } else { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 m_Width = BitmapWidth; | 356 m_Width = BitmapWidth; |
360 m_Height = BitmapHeight; | 357 m_Height = BitmapHeight; |
361 if (dest_buf) { | 358 if (dest_buf) { |
362 FX_Free(dest_buf); | 359 FX_Free(dest_buf); |
363 } | 360 } |
364 } | 361 } |
365 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) | 362 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) |
366 { | 363 { |
367 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); | 364 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); |
368 } | 365 } |
OLD | NEW |