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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 { | 64 { |
65 FX_DWORD size = (FX_DWORD)pFile->GetSize(); | 65 FX_DWORD size = (FX_DWORD)pFile->GetSize(); |
66 if (!size) { | 66 if (!size) { |
67 return; | 67 return; |
68 } | 68 } |
69 FX_DWORD dwEstimateSize = size; | 69 FX_DWORD dwEstimateSize = size; |
70 if (dwEstimateSize > 8192) { | 70 if (dwEstimateSize > 8192) { |
71 dwEstimateSize = 8192; | 71 dwEstimateSize = 8192; |
72 } | 72 } |
73 FX_LPBYTE pData = FX_Alloc(FX_BYTE, dwEstimateSize); | 73 FX_LPBYTE pData = FX_Alloc(FX_BYTE, dwEstimateSize); |
74 if (!pData) { | |
75 return; | |
76 } | |
77 pFile->ReadBlock(pData, 0, dwEstimateSize); | 74 pFile->ReadBlock(pData, 0, dwEstimateSize); |
78 CPDF_Dictionary *pDict = InitJPEG(pData, dwEstimateSize); | 75 CPDF_Dictionary *pDict = InitJPEG(pData, dwEstimateSize); |
79 FX_Free(pData); | 76 FX_Free(pData); |
80 if (!pDict && size > dwEstimateSize) { | 77 if (!pDict && size > dwEstimateSize) { |
81 pData = FX_Alloc(FX_BYTE, size); | 78 pData = FX_Alloc(FX_BYTE, size); |
82 if (!pData) { | |
83 return; | |
84 } | |
85 pFile->ReadBlock(pData, 0, size); | 79 pFile->ReadBlock(pData, 0, size); |
86 pDict = InitJPEG(pData, size); | 80 pDict = InitJPEG(pData, size); |
87 FX_Free(pData); | 81 FX_Free(pData); |
88 } | 82 } |
89 if (!pDict) { | 83 if (!pDict) { |
90 return; | 84 return; |
91 } | 85 } |
92 m_pStream->InitStream(pFile, pDict); | 86 m_pStream->InitStream(pFile, pDict); |
93 } | 87 } |
94 void _DCTEncodeBitmap(CPDF_Dictionary *pBitmapDict, const CFX_DIBitmap* pBitmap,
int quality, FX_LPBYTE &buf, FX_STRSIZE &size) | 88 void _DCTEncodeBitmap(CPDF_Dictionary *pBitmapDict, const CFX_DIBitmap* pBitmap,
int quality, FX_LPBYTE &buf, FX_STRSIZE &size) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 pMaskDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Image")); | 210 pMaskDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Image")); |
217 pMaskDict->SetAtInteger(FX_BSTRC("Width"), maskWidth); | 211 pMaskDict->SetAtInteger(FX_BSTRC("Width"), maskWidth); |
218 pMaskDict->SetAtInteger(FX_BSTRC("Height"), maskHeight); | 212 pMaskDict->SetAtInteger(FX_BSTRC("Height"), maskHeight); |
219 pMaskDict->SetAtName(FX_BSTRC("ColorSpace"), FX_BSTRC("DeviceGray")); | 213 pMaskDict->SetAtName(FX_BSTRC("ColorSpace"), FX_BSTRC("DeviceGray")); |
220 pMaskDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 8); | 214 pMaskDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 8); |
221 if (pMaskBitmap->GetBPP() == 8 && (iCompress & PDF_IMAGE_MASK_LOSSY_COMP
RESS) != 0) { | 215 if (pMaskBitmap->GetBPP() == 8 && (iCompress & PDF_IMAGE_MASK_LOSSY_COMP
RESS) != 0) { |
222 _DCTEncodeBitmap(pMaskDict, pMaskBitmap, pParam ? pParam->nQuality :
75, mask_buf, mask_size); | 216 _DCTEncodeBitmap(pMaskDict, pMaskBitmap, pParam ? pParam->nQuality :
75, mask_buf, mask_size); |
223 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) { | 217 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) { |
224 _JBIG2EncodeBitmap(pMaskDict, pMaskBitmap, m_pDocument, mask_buf, ma
sk_size, TRUE); | 218 _JBIG2EncodeBitmap(pMaskDict, pMaskBitmap, m_pDocument, mask_buf, ma
sk_size, TRUE); |
225 } else { | 219 } else { |
226 mask_size = maskHeight * maskWidth; | 220 mask_buf = FX_Alloc2D(FX_BYTE, maskHeight, maskWidth); |
227 mask_buf = FX_Alloc(FX_BYTE, mask_size); | 221 mask_size = maskHeight * maskWidth; // Safe since checked alloc ret
urned. |
228 for (FX_INT32 a = 0; a < maskHeight; a ++) { | 222 for (FX_INT32 a = 0; a < maskHeight; a ++) { |
229 FXSYS_memcpy32(mask_buf + a * maskWidth, pMaskBitmap->GetScanlin
e(a), maskWidth); | 223 FXSYS_memcpy32(mask_buf + a * maskWidth, pMaskBitmap->GetScanlin
e(a), maskWidth); |
230 } | 224 } |
231 } | 225 } |
232 if (pMaskDict) { | 226 if (pMaskDict) { |
233 pMaskDict->SetAtInteger(FX_BSTRC("Length"), mask_size); | 227 pMaskDict->SetAtInteger(FX_BSTRC("Length"), mask_size); |
234 CPDF_Stream* pMaskStream = NULL; | 228 CPDF_Stream* pMaskStream = NULL; |
235 if (bUseMatte) { | 229 if (bUseMatte) { |
236 int a, r, g, b; | 230 int a, r, g, b; |
237 ArgbDecode(*(pParam->pMatteColor), a, r, g, b); | 231 ArgbDecode(*(pParam->pMatteColor), a, r, g, b); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 } | 293 } |
300 } | 294 } |
301 } | 295 } |
302 if (bStream) { | 296 if (bStream) { |
303 pFileWrite->WriteBlock(dest_buf, dest_size); | 297 pFileWrite->WriteBlock(dest_buf, dest_size); |
304 FX_Free(dest_buf); | 298 FX_Free(dest_buf); |
305 dest_buf = NULL; | 299 dest_buf = NULL; |
306 } | 300 } |
307 } else if (opType == 1) { | 301 } else if (opType == 1) { |
308 if (!bStream) { | 302 if (!bStream) { |
309 dest_size = dest_pitch * BitmapHeight; | 303 dest_buf = FX_Alloc2D(FX_BYTE, dest_pitch, BitmapHeight); |
310 dest_buf = FX_Alloc(FX_BYTE, dest_size); | 304 dest_size = dest_pitch * BitmapHeight; // Safe since checked alloc
returned. |
311 } | 305 } |
312 FX_LPBYTE pDest = dest_buf; | 306 FX_LPBYTE pDest = dest_buf; |
313 for (FX_INT32 i = 0; i < BitmapHeight; i ++) { | 307 for (FX_INT32 i = 0; i < BitmapHeight; i ++) { |
314 if (!bStream) { | 308 if (!bStream) { |
315 FXSYS_memcpy32(pDest, src_buf, dest_pitch); | 309 FXSYS_memcpy32(pDest, src_buf, dest_pitch); |
316 pDest += dest_pitch; | 310 pDest += dest_pitch; |
317 } else { | 311 } else { |
318 pFileWrite->WriteBlock(src_buf, dest_pitch); | 312 pFileWrite->WriteBlock(src_buf, dest_pitch); |
319 } | 313 } |
320 src_buf += src_pitch; | 314 src_buf += src_pitch; |
321 } | 315 } |
322 } else if (opType == 2) { | 316 } else if (opType == 2) { |
323 if (!bStream) { | 317 if (!bStream) { |
324 dest_size = dest_pitch * BitmapHeight; | 318 dest_buf = FX_Alloc2D(FX_BYTE, dest_pitch, BitmapHeight); |
325 dest_buf = FX_Alloc(FX_BYTE, dest_size); | 319 dest_size = dest_pitch * BitmapHeight; // Safe since checked alloc
returned. |
326 } else { | 320 } else { |
327 dest_buf = FX_Alloc(FX_BYTE, dest_pitch); | 321 dest_buf = FX_Alloc(FX_BYTE, dest_pitch); |
328 } | 322 } |
329 FX_LPBYTE pDest = dest_buf; | 323 FX_LPBYTE pDest = dest_buf; |
330 FX_INT32 src_offset = 0; | 324 FX_INT32 src_offset = 0; |
331 FX_INT32 dest_offset = 0; | 325 FX_INT32 dest_offset = 0; |
332 for (FX_INT32 row = 0; row < BitmapHeight; row ++) { | 326 for (FX_INT32 row = 0; row < BitmapHeight; row ++) { |
333 src_offset = row * src_pitch; | 327 src_offset = row * src_pitch; |
334 for (FX_INT32 column = 0; column < BitmapWidth; column ++) { | 328 for (FX_INT32 column = 0; column < BitmapWidth; column ++) { |
335 FX_FLOAT alpha = bUseMatte ? src_buf[src_offset + 3] / 255.0f :
1; | 329 FX_FLOAT alpha = bUseMatte ? src_buf[src_offset + 3] / 255.0f :
1; |
(...skipping 29 matching lines...) Expand all Loading... |
365 m_Width = BitmapWidth; | 359 m_Width = BitmapWidth; |
366 m_Height = BitmapHeight; | 360 m_Height = BitmapHeight; |
367 if (dest_buf) { | 361 if (dest_buf) { |
368 FX_Free(dest_buf); | 362 FX_Free(dest_buf); |
369 } | 363 } |
370 } | 364 } |
371 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) | 365 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) |
372 { | 366 { |
373 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); | 367 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); |
374 } | 368 } |
OLD | NEW |