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