| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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_page/include/cpdf_image.h" |
| 8 |
| 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 10 #include "core/fpdfapi/include/cpdf_modulemgr.h" |
| 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 12 #include "core/include/fxge/fx_dib.h" |
| 13 #include "core/fpdfapi/fpdf_page/pageint.h" |
| 14 #include "core/include/fxcodec/fx_codec.h" |
| 15 #include "core/fpdfapi/fpdf_parser/cpdf_boolean.h" |
| 16 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" |
| 7 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | 17 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
| 8 #include "core/fpdfapi/fpdf_page/pageint.h" | |
| 9 #include "core/fpdfapi/fpdf_parser/cpdf_boolean.h" | |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | |
| 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | |
| 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | |
| 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" | |
| 14 #include "core/fpdfapi/fpdf_render/cpdf_pagerendercache.h" | 18 #include "core/fpdfapi/fpdf_render/cpdf_pagerendercache.h" |
| 15 #include "core/fpdfapi/fpdf_render/render_int.h" | 19 #include "core/fpdfapi/fpdf_render/render_int.h" |
| 16 #include "core/fpdfapi/include/cpdf_modulemgr.h" | |
| 17 #include "core/include/fxcodec/fx_codec.h" | |
| 18 | 20 |
| 19 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, FX_DWORD size) { | 21 CPDF_Image::CPDF_Image(CPDF_Document* pDoc) |
| 22 : m_pDIBSource(nullptr), |
| 23 m_pMask(nullptr), |
| 24 m_MatteColor(0), |
| 25 m_pStream(nullptr), |
| 26 m_bInline(FALSE), |
| 27 m_pInlineDict(nullptr), |
| 28 m_pDocument(pDoc), |
| 29 m_pOC(nullptr) { |
| 30 } |
| 31 |
| 32 CPDF_Image::~CPDF_Image() { |
| 33 if (m_bInline) { |
| 34 if (m_pStream) |
| 35 m_pStream->Release(); |
| 36 if (m_pInlineDict) |
| 37 m_pInlineDict->Release(); |
| 38 } |
| 39 } |
| 40 |
| 41 void CPDF_Image::Release() { |
| 42 if (m_bInline || (m_pStream && m_pStream->GetObjNum() == 0)) |
| 43 delete this; |
| 44 } |
| 45 |
| 46 CPDF_Image* CPDF_Image::Clone() { |
| 47 if (m_pStream->GetObjNum()) |
| 48 return m_pDocument->GetPageData()->GetImage(m_pStream); |
| 49 |
| 50 CPDF_Image* pImage = new CPDF_Image(m_pDocument); |
| 51 pImage->LoadImageF(ToStream(m_pStream->Clone()), m_bInline); |
| 52 if (m_bInline) |
| 53 pImage->SetInlineDict(ToDictionary(m_pInlineDict->Clone(TRUE))); |
| 54 |
| 55 return pImage; |
| 56 } |
| 57 |
| 58 FX_BOOL CPDF_Image::LoadImageF(CPDF_Stream * pStream, FX_BOOL bInline) { |
| 59 m_pStream = pStream; |
| 60 if (m_bInline && m_pInlineDict) { |
| 61 m_pInlineDict->Release(); |
| 62 m_pInlineDict = NULL; |
| 63 } |
| 64 m_bInline = bInline; |
| 65 CPDF_Dictionary* pDict = pStream->GetDict(); |
| 66 if (m_bInline) { |
| 67 m_pInlineDict = ToDictionary(pDict->Clone()); |
| 68 } |
| 69 m_pOC = pDict->GetDictBy("OC"); |
| 70 m_bIsMask = |
| 71 !pDict->KeyExist("ColorSpace") || pDict->GetIntegerBy("ImageMask"); |
| 72 m_bInterpolate = pDict->GetIntegerBy("Interpolate"); |
| 73 m_Height = pDict->GetIntegerBy("Height"); |
| 74 m_Width = pDict->GetIntegerBy("Width"); |
| 75 return TRUE; |
| 76 } |
| 77 |
| 78 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t * pData, FX_DWORD size) { |
| 20 int32_t width; | 79 int32_t width; |
| 21 int32_t height; | 80 int32_t height; |
| 22 int32_t num_comps; | 81 int32_t num_comps; |
| 23 int32_t bits; | 82 int32_t bits; |
| 24 FX_BOOL color_trans; | 83 FX_BOOL color_trans; |
| 25 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->LoadInfo( | 84 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->LoadInfo( |
| 26 pData, size, width, height, num_comps, bits, color_trans)) { | 85 pData, size, width, height, num_comps, bits, color_trans)) { |
| 27 return NULL; | 86 return NULL; |
| 28 } | 87 } |
| 29 CPDF_Dictionary* pDict = new CPDF_Dictionary; | 88 CPDF_Dictionary* pDict = new CPDF_Dictionary; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 54 pParms->SetAtInteger("ColorTransform", 0); | 113 pParms->SetAtInteger("ColorTransform", 0); |
| 55 } | 114 } |
| 56 m_bIsMask = FALSE; | 115 m_bIsMask = FALSE; |
| 57 m_Width = width; | 116 m_Width = width; |
| 58 m_Height = height; | 117 m_Height = height; |
| 59 if (!m_pStream) { | 118 if (!m_pStream) { |
| 60 m_pStream = new CPDF_Stream(NULL, 0, NULL); | 119 m_pStream = new CPDF_Stream(NULL, 0, NULL); |
| 61 } | 120 } |
| 62 return pDict; | 121 return pDict; |
| 63 } | 122 } |
| 64 void CPDF_Image::SetJpegImage(uint8_t* pData, FX_DWORD size) { | 123 |
| 124 void CPDF_Image::SetJpegImage(uint8_t * pData, FX_DWORD size) { |
| 65 CPDF_Dictionary* pDict = InitJPEG(pData, size); | 125 CPDF_Dictionary* pDict = InitJPEG(pData, size); |
| 66 if (!pDict) { | 126 if (!pDict) { |
| 67 return; | 127 return; |
| 68 } | 128 } |
| 69 m_pStream->InitStream(pData, size, pDict); | 129 m_pStream->InitStream(pData, size, pDict); |
| 70 } | 130 } |
| 71 void CPDF_Image::SetJpegImage(IFX_FileRead* pFile) { | 131 |
| 132 void CPDF_Image::SetJpegImage(IFX_FileRead * pFile) { |
| 72 FX_DWORD size = (FX_DWORD)pFile->GetSize(); | 133 FX_DWORD size = (FX_DWORD)pFile->GetSize(); |
| 73 if (!size) { | 134 if (!size) { |
| 74 return; | 135 return; |
| 75 } | 136 } |
| 76 FX_DWORD dwEstimateSize = size; | 137 FX_DWORD dwEstimateSize = size; |
| 77 if (dwEstimateSize > 8192) { | 138 if (dwEstimateSize > 8192) { |
| 78 dwEstimateSize = 8192; | 139 dwEstimateSize = 8192; |
| 79 } | 140 } |
| 80 uint8_t* pData = FX_Alloc(uint8_t, dwEstimateSize); | 141 uint8_t* pData = FX_Alloc(uint8_t, dwEstimateSize); |
| 81 pFile->ReadBlock(pData, 0, dwEstimateSize); | 142 pFile->ReadBlock(pData, 0, dwEstimateSize); |
| 82 CPDF_Dictionary* pDict = InitJPEG(pData, dwEstimateSize); | 143 CPDF_Dictionary* pDict = InitJPEG(pData, dwEstimateSize); |
| 83 FX_Free(pData); | 144 FX_Free(pData); |
| 84 if (!pDict && size > dwEstimateSize) { | 145 if (!pDict && size > dwEstimateSize) { |
| 85 pData = FX_Alloc(uint8_t, size); | 146 pData = FX_Alloc(uint8_t, size); |
| 86 pFile->ReadBlock(pData, 0, size); | 147 pFile->ReadBlock(pData, 0, size); |
| 87 pDict = InitJPEG(pData, size); | 148 pDict = InitJPEG(pData, size); |
| 88 FX_Free(pData); | 149 FX_Free(pData); |
| 89 } | 150 } |
| 90 if (!pDict) { | 151 if (!pDict) { |
| 91 return; | 152 return; |
| 92 } | 153 } |
| 93 m_pStream->InitStreamFromFile(pFile, pDict); | 154 m_pStream->InitStreamFromFile(pFile, pDict); |
| 94 } | 155 } |
| 95 void _DCTEncodeBitmap(CPDF_Dictionary* pBitmapDict, | 156 |
| 96 const CFX_DIBitmap* pBitmap, | 157 void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress, |
| 97 int quality, | 158 IFX_FileWrite* pFileWrite, IFX_FileRead* pFileRead, |
| 98 uint8_t*& buf, | 159 const CFX_DIBitmap* pMask) { |
| 99 FX_STRSIZE& size) {} | |
| 100 void _JBIG2EncodeBitmap(CPDF_Dictionary* pBitmapDict, | |
| 101 const CFX_DIBitmap* pBitmap, | |
| 102 CPDF_Document* pDoc, | |
| 103 uint8_t*& buf, | |
| 104 FX_STRSIZE& size, | |
| 105 FX_BOOL bLossLess) {} | |
| 106 void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, | |
| 107 int32_t iCompress, | |
| 108 IFX_FileWrite* pFileWrite, | |
| 109 IFX_FileRead* pFileRead, | |
| 110 const CFX_DIBitmap* pMask, | |
| 111 const CPDF_ImageSetParam* pParam) { | |
| 112 int32_t BitmapWidth = pBitmap->GetWidth(); | 160 int32_t BitmapWidth = pBitmap->GetWidth(); |
| 113 int32_t BitmapHeight = pBitmap->GetHeight(); | 161 int32_t BitmapHeight = pBitmap->GetHeight(); |
| 114 if (BitmapWidth < 1 || BitmapHeight < 1) { | 162 if (BitmapWidth < 1 || BitmapHeight < 1) { |
| 115 return; | 163 return; |
| 116 } | 164 } |
| 117 uint8_t* src_buf = pBitmap->GetBuffer(); | 165 uint8_t* src_buf = pBitmap->GetBuffer(); |
| 118 int32_t src_pitch = pBitmap->GetPitch(); | 166 int32_t src_pitch = pBitmap->GetPitch(); |
| 119 int32_t bpp = pBitmap->GetBPP(); | 167 int32_t bpp = pBitmap->GetBPP(); |
| 120 FX_BOOL bUseMatte = | 168 |
| 121 pParam && pParam->pMatteColor && (pBitmap->GetFormat() == FXDIB_Argb); | |
| 122 CPDF_Dictionary* pDict = new CPDF_Dictionary; | 169 CPDF_Dictionary* pDict = new CPDF_Dictionary; |
| 123 pDict->SetAtName("Type", "XObject"); | 170 pDict->SetAtName("Type", "XObject"); |
| 124 pDict->SetAtName("Subtype", "Image"); | 171 pDict->SetAtName("Subtype", "Image"); |
| 125 pDict->SetAtInteger("Width", BitmapWidth); | 172 pDict->SetAtInteger("Width", BitmapWidth); |
| 126 pDict->SetAtInteger("Height", BitmapHeight); | 173 pDict->SetAtInteger("Height", BitmapHeight); |
| 127 uint8_t* dest_buf = NULL; | 174 uint8_t* dest_buf = NULL; |
| 128 FX_STRSIZE dest_pitch = 0, dest_size = 0, opType = -1; | 175 FX_STRSIZE dest_pitch = 0, dest_size = 0, opType = -1; |
| 129 if (bpp == 1) { | 176 if (bpp == 1) { |
| 130 int32_t reset_a = 0, reset_r = 0, reset_g = 0, reset_b = 0; | 177 int32_t reset_a = 0, reset_r = 0, reset_g = 0, reset_b = 0; |
| 131 int32_t set_a = 0, set_r = 0, set_g = 0, set_b = 0; | 178 int32_t set_a = 0, set_r = 0, set_g = 0, set_b = 0; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 FX_STRSIZE mask_size = 0; | 274 FX_STRSIZE mask_size = 0; |
| 228 CPDF_Dictionary* pMaskDict = new CPDF_Dictionary; | 275 CPDF_Dictionary* pMaskDict = new CPDF_Dictionary; |
| 229 pMaskDict->SetAtName("Type", "XObject"); | 276 pMaskDict->SetAtName("Type", "XObject"); |
| 230 pMaskDict->SetAtName("Subtype", "Image"); | 277 pMaskDict->SetAtName("Subtype", "Image"); |
| 231 pMaskDict->SetAtInteger("Width", maskWidth); | 278 pMaskDict->SetAtInteger("Width", maskWidth); |
| 232 pMaskDict->SetAtInteger("Height", maskHeight); | 279 pMaskDict->SetAtInteger("Height", maskHeight); |
| 233 pMaskDict->SetAtName("ColorSpace", "DeviceGray"); | 280 pMaskDict->SetAtName("ColorSpace", "DeviceGray"); |
| 234 pMaskDict->SetAtInteger("BitsPerComponent", 8); | 281 pMaskDict->SetAtInteger("BitsPerComponent", 8); |
| 235 if (pMaskBitmap->GetBPP() == 8 && | 282 if (pMaskBitmap->GetBPP() == 8 && |
| 236 (iCompress & PDF_IMAGE_MASK_LOSSY_COMPRESS) != 0) { | 283 (iCompress & PDF_IMAGE_MASK_LOSSY_COMPRESS) != 0) { |
| 237 _DCTEncodeBitmap(pMaskDict, pMaskBitmap, pParam ? pParam->nQuality : 75, | |
| 238 mask_buf, mask_size); | |
| 239 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) { | 284 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) { |
| 240 _JBIG2EncodeBitmap(pMaskDict, pMaskBitmap, m_pDocument, mask_buf, | |
| 241 mask_size, TRUE); | |
| 242 } else { | 285 } else { |
| 243 mask_buf = FX_Alloc2D(uint8_t, maskHeight, maskWidth); | 286 mask_buf = FX_Alloc2D(uint8_t, maskHeight, maskWidth); |
| 244 mask_size = maskHeight * maskWidth; // Safe since checked alloc returned. | 287 mask_size = maskHeight * maskWidth; // Safe since checked alloc returned. |
| 245 for (int32_t a = 0; a < maskHeight; a++) { | 288 for (int32_t a = 0; a < maskHeight; a++) { |
| 246 FXSYS_memcpy(mask_buf + a * maskWidth, pMaskBitmap->GetScanline(a), | 289 FXSYS_memcpy(mask_buf + a * maskWidth, pMaskBitmap->GetScanline(a), |
| 247 maskWidth); | 290 maskWidth); |
| 248 } | 291 } |
| 249 } | 292 } |
| 250 pMaskDict->SetAtInteger("Length", mask_size); | 293 pMaskDict->SetAtInteger("Length", mask_size); |
| 251 if (bUseMatte) { | 294 |
| 252 int a, r, g, b; | |
| 253 ArgbDecode(*(pParam->pMatteColor), a, r, g, b); | |
| 254 CPDF_Array* pMatte = new CPDF_Array; | |
| 255 pMatte->AddInteger(r); | |
| 256 pMatte->AddInteger(g); | |
| 257 pMatte->AddInteger(b); | |
| 258 pMaskDict->SetAt("Matte", pMatte); | |
| 259 } | |
| 260 CPDF_Stream* pMaskStream = new CPDF_Stream(mask_buf, mask_size, pMaskDict); | 295 CPDF_Stream* pMaskStream = new CPDF_Stream(mask_buf, mask_size, pMaskDict); |
| 261 m_pDocument->AddIndirectObject(pMaskStream); | 296 m_pDocument->AddIndirectObject(pMaskStream); |
| 262 pDict->SetAtReference("SMask", m_pDocument, pMaskStream); | 297 pDict->SetAtReference("SMask", m_pDocument, pMaskStream); |
| 263 if (bDeleteMask) { | 298 if (bDeleteMask) { |
| 264 delete pMaskBitmap; | 299 delete pMaskBitmap; |
| 265 } | 300 } |
| 266 } | 301 } |
| 267 FX_BOOL bStream = pFileWrite && pFileRead; | 302 FX_BOOL bStream = pFileWrite && pFileRead; |
| 268 if (opType == 0) { | 303 if (opType == 0) { |
| 269 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) { | 304 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) { |
| 270 if (pBitmap->GetBPP() == 1) { | |
| 271 _JBIG2EncodeBitmap(pDict, pBitmap, m_pDocument, dest_buf, dest_size, | |
| 272 TRUE); | |
| 273 } | |
| 274 } else { | 305 } else { |
| 275 if (pBitmap->GetBPP() == 1) { | 306 if (pBitmap->GetBPP() == 1) { |
| 276 _JBIG2EncodeBitmap(pDict, pBitmap, m_pDocument, dest_buf, dest_size, | |
| 277 FALSE); | |
| 278 } else if (pBitmap->GetBPP() >= 8 && pBitmap->GetPalette()) { | 307 } else if (pBitmap->GetBPP() >= 8 && pBitmap->GetPalette()) { |
| 279 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap(); | 308 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap(); |
| 280 pNewBitmap->Copy(pBitmap); | 309 pNewBitmap->Copy(pBitmap); |
| 281 pNewBitmap->ConvertFormat(FXDIB_Rgb); | 310 pNewBitmap->ConvertFormat(FXDIB_Rgb); |
| 282 SetImage(pNewBitmap, iCompress, pFileWrite, pFileRead); | 311 SetImage(pNewBitmap, iCompress, pFileWrite, pFileRead); |
| 283 if (pDict) { | 312 if (pDict) { |
| 284 pDict->Release(); | 313 pDict->Release(); |
| 285 pDict = NULL; | 314 pDict = NULL; |
| 286 } | 315 } |
| 287 FX_Free(dest_buf); | 316 FX_Free(dest_buf); |
| 288 dest_buf = NULL; | 317 dest_buf = NULL; |
| 289 dest_size = 0; | 318 dest_size = 0; |
| 290 delete pNewBitmap; | 319 delete pNewBitmap; |
| 291 return; | 320 return; |
| 292 } else { | |
| 293 if (bUseMatte) { | |
| 294 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap(); | |
| 295 pNewBitmap->Create(BitmapWidth, BitmapHeight, FXDIB_Argb); | |
| 296 uint8_t* dst_buf = pNewBitmap->GetBuffer(); | |
| 297 int32_t src_offset = 0; | |
| 298 for (int32_t row = 0; row < BitmapHeight; row++) { | |
| 299 src_offset = row * src_pitch; | |
| 300 for (int32_t column = 0; column < BitmapWidth; column++) { | |
| 301 FX_FLOAT alpha = src_buf[src_offset + 3] / 255.0f; | |
| 302 dst_buf[src_offset] = (uint8_t)(src_buf[src_offset] * alpha); | |
| 303 dst_buf[src_offset + 1] = | |
| 304 (uint8_t)(src_buf[src_offset + 1] * alpha); | |
| 305 dst_buf[src_offset + 2] = | |
| 306 (uint8_t)(src_buf[src_offset + 2] * alpha); | |
| 307 dst_buf[src_offset + 3] = (uint8_t)(src_buf[src_offset + 3]); | |
| 308 src_offset += 4; | |
| 309 } | |
| 310 } | |
| 311 _DCTEncodeBitmap(pDict, pNewBitmap, pParam ? pParam->nQuality : 75, | |
| 312 dest_buf, dest_size); | |
| 313 delete pNewBitmap; | |
| 314 } else { | |
| 315 _DCTEncodeBitmap(pDict, pBitmap, pParam ? pParam->nQuality : 75, | |
| 316 dest_buf, dest_size); | |
| 317 } | |
| 318 } | 321 } |
| 319 } | 322 } |
| 320 if (bStream) { | 323 if (bStream) { |
| 321 pFileWrite->WriteBlock(dest_buf, dest_size); | 324 pFileWrite->WriteBlock(dest_buf, dest_size); |
| 322 FX_Free(dest_buf); | 325 FX_Free(dest_buf); |
| 323 dest_buf = NULL; | 326 dest_buf = NULL; |
| 324 } | 327 } |
| 325 } else if (opType == 1) { | 328 } else if (opType == 1) { |
| 326 if (!bStream) { | 329 if (!bStream) { |
| 327 dest_buf = FX_Alloc2D(uint8_t, dest_pitch, BitmapHeight); | 330 dest_buf = FX_Alloc2D(uint8_t, dest_pitch, BitmapHeight); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 345 dest_pitch * BitmapHeight; // Safe since checked alloc returned. | 348 dest_pitch * BitmapHeight; // Safe since checked alloc returned. |
| 346 } else { | 349 } else { |
| 347 dest_buf = FX_Alloc(uint8_t, dest_pitch); | 350 dest_buf = FX_Alloc(uint8_t, dest_pitch); |
| 348 } | 351 } |
| 349 uint8_t* pDest = dest_buf; | 352 uint8_t* pDest = dest_buf; |
| 350 int32_t src_offset = 0; | 353 int32_t src_offset = 0; |
| 351 int32_t dest_offset = 0; | 354 int32_t dest_offset = 0; |
| 352 for (int32_t row = 0; row < BitmapHeight; row++) { | 355 for (int32_t row = 0; row < BitmapHeight; row++) { |
| 353 src_offset = row * src_pitch; | 356 src_offset = row * src_pitch; |
| 354 for (int32_t column = 0; column < BitmapWidth; column++) { | 357 for (int32_t column = 0; column < BitmapWidth; column++) { |
| 355 FX_FLOAT alpha = bUseMatte ? src_buf[src_offset + 3] / 255.0f : 1; | 358 FX_FLOAT alpha = 1; |
| 356 pDest[dest_offset] = (uint8_t)(src_buf[src_offset + 2] * alpha); | 359 pDest[dest_offset] = (uint8_t)(src_buf[src_offset + 2] * alpha); |
| 357 pDest[dest_offset + 1] = (uint8_t)(src_buf[src_offset + 1] * alpha); | 360 pDest[dest_offset + 1] = (uint8_t)(src_buf[src_offset + 1] * alpha); |
| 358 pDest[dest_offset + 2] = (uint8_t)(src_buf[src_offset] * alpha); | 361 pDest[dest_offset + 2] = (uint8_t)(src_buf[src_offset] * alpha); |
| 359 dest_offset += 3; | 362 dest_offset += 3; |
| 360 src_offset += bpp == 24 ? 3 : 4; | 363 src_offset += bpp == 24 ? 3 : 4; |
| 361 } | 364 } |
| 362 if (bStream) { | 365 if (bStream) { |
| 363 pFileWrite->WriteBlock(pDest, dest_pitch); | 366 pFileWrite->WriteBlock(pDest, dest_pitch); |
| 364 pDest = dest_buf; | 367 pDest = dest_buf; |
| 365 } else { | 368 } else { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 379 m_pStream->InitStream(dest_buf, dest_size, pDict); | 382 m_pStream->InitStream(dest_buf, dest_size, pDict); |
| 380 } else { | 383 } else { |
| 381 pFileWrite->Flush(); | 384 pFileWrite->Flush(); |
| 382 m_pStream->InitStreamFromFile(pFileRead, pDict); | 385 m_pStream->InitStreamFromFile(pFileRead, pDict); |
| 383 } | 386 } |
| 384 m_bIsMask = pBitmap->IsAlphaMask(); | 387 m_bIsMask = pBitmap->IsAlphaMask(); |
| 385 m_Width = BitmapWidth; | 388 m_Width = BitmapWidth; |
| 386 m_Height = BitmapHeight; | 389 m_Height = BitmapHeight; |
| 387 FX_Free(dest_buf); | 390 FX_Free(dest_buf); |
| 388 } | 391 } |
| 389 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) { | 392 |
| 393 void CPDF_Image::ResetCache(CPDF_Page * pPage, const CFX_DIBitmap* pBitmap) { |
| 390 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); | 394 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); |
| 391 } | 395 } |
| 396 |
| 397 CFX_DIBSource* CPDF_Image::LoadDIBSource( |
| 398 CFX_DIBSource * *ppMask, FX_DWORD * pMatteColor, FX_BOOL bStdCS, |
| 399 FX_DWORD GroupFamily, FX_BOOL bLoadMask) const { |
| 400 std::unique_ptr<CPDF_DIBSource> source(new CPDF_DIBSource); |
| 401 if (source->Load(m_pDocument, m_pStream, |
| 402 reinterpret_cast<CPDF_DIBSource**>(ppMask), pMatteColor, |
| 403 nullptr, nullptr, bStdCS, GroupFamily, bLoadMask)) { |
| 404 return source.release(); |
| 405 } |
| 406 return nullptr; |
| 407 } |
| 408 |
| 409 CFX_DIBSource* CPDF_Image::DetachBitmap() { |
| 410 CFX_DIBSource* pBitmap = m_pDIBSource; |
| 411 m_pDIBSource = nullptr; |
| 412 return pBitmap; |
| 413 } |
| 414 |
| 415 CFX_DIBSource* CPDF_Image::DetachMask() { |
| 416 CFX_DIBSource* pBitmap = m_pMask; |
| 417 m_pMask = nullptr; |
| 418 return pBitmap; |
| 419 } |
| 420 |
| 421 FX_BOOL CPDF_Image::StartLoadDIBSource( |
| 422 CPDF_Dictionary * pFormResource, CPDF_Dictionary * pPageResource, |
| 423 FX_BOOL bStdCS, FX_DWORD GroupFamily, FX_BOOL bLoadMask) { |
| 424 std::unique_ptr<CPDF_DIBSource> source(new CPDF_DIBSource); |
| 425 int ret = |
| 426 source->StartLoadDIBSource(m_pDocument, m_pStream, TRUE, pFormResource, |
| 427 pPageResource, bStdCS, GroupFamily, bLoadMask); |
| 428 if (ret == 2) { |
| 429 m_pDIBSource = source.release(); |
| 430 return TRUE; |
| 431 } |
| 432 if (!ret) { |
| 433 m_pDIBSource = nullptr; |
| 434 return FALSE; |
| 435 } |
| 436 m_pMask = source->DetachMask(); |
| 437 m_MatteColor = source->GetMatteColor(); |
| 438 m_pDIBSource = source.release(); |
| 439 return FALSE; |
| 440 } |
| 441 |
| 442 FX_BOOL CPDF_Image::Continue(IFX_Pause * pPause) { |
| 443 CPDF_DIBSource* pSource = static_cast<CPDF_DIBSource*>(m_pDIBSource); |
| 444 int ret = pSource->ContinueLoadDIBSource(pPause); |
| 445 if (ret == 2) { |
| 446 return TRUE; |
| 447 } |
| 448 if (!ret) { |
| 449 delete m_pDIBSource; |
| 450 m_pDIBSource = nullptr; |
| 451 return FALSE; |
| 452 } |
| 453 m_pMask = pSource->DetachMask(); |
| 454 m_MatteColor = pSource->GetMatteColor(); |
| 455 return FALSE; |
| 456 } |
| OLD | NEW |