OLD | NEW |
1 // Copyright 2016 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" | 7 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
10 #include "core/fpdfapi/include/cpdf_modulemgr.h" | 10 #include "core/fpdfapi/include/cpdf_modulemgr.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 67 } |
68 m_pOC = pDict->GetDictBy("OC"); | 68 m_pOC = pDict->GetDictBy("OC"); |
69 m_bIsMask = | 69 m_bIsMask = |
70 !pDict->KeyExist("ColorSpace") || pDict->GetIntegerBy("ImageMask"); | 70 !pDict->KeyExist("ColorSpace") || pDict->GetIntegerBy("ImageMask"); |
71 m_bInterpolate = pDict->GetIntegerBy("Interpolate"); | 71 m_bInterpolate = pDict->GetIntegerBy("Interpolate"); |
72 m_Height = pDict->GetIntegerBy("Height"); | 72 m_Height = pDict->GetIntegerBy("Height"); |
73 m_Width = pDict->GetIntegerBy("Width"); | 73 m_Width = pDict->GetIntegerBy("Width"); |
74 return TRUE; | 74 return TRUE; |
75 } | 75 } |
76 | 76 |
77 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, FX_DWORD size) { | 77 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) { |
78 int32_t width; | 78 int32_t width; |
79 int32_t height; | 79 int32_t height; |
80 int32_t num_comps; | 80 int32_t num_comps; |
81 int32_t bits; | 81 int32_t bits; |
82 FX_BOOL color_trans; | 82 FX_BOOL color_trans; |
83 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->LoadInfo( | 83 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->LoadInfo( |
84 pData, size, width, height, num_comps, bits, color_trans)) { | 84 pData, size, width, height, num_comps, bits, color_trans)) { |
85 return NULL; | 85 return NULL; |
86 } | 86 } |
87 CPDF_Dictionary* pDict = new CPDF_Dictionary; | 87 CPDF_Dictionary* pDict = new CPDF_Dictionary; |
(...skipping 25 matching lines...) Expand all Loading... |
113 } | 113 } |
114 m_bIsMask = FALSE; | 114 m_bIsMask = FALSE; |
115 m_Width = width; | 115 m_Width = width; |
116 m_Height = height; | 116 m_Height = height; |
117 if (!m_pStream) { | 117 if (!m_pStream) { |
118 m_pStream = new CPDF_Stream(NULL, 0, NULL); | 118 m_pStream = new CPDF_Stream(NULL, 0, NULL); |
119 } | 119 } |
120 return pDict; | 120 return pDict; |
121 } | 121 } |
122 | 122 |
123 void CPDF_Image::SetJpegImage(uint8_t* pData, FX_DWORD size) { | 123 void CPDF_Image::SetJpegImage(uint8_t* pData, uint32_t size) { |
124 CPDF_Dictionary* pDict = InitJPEG(pData, size); | 124 CPDF_Dictionary* pDict = InitJPEG(pData, size); |
125 if (!pDict) { | 125 if (!pDict) { |
126 return; | 126 return; |
127 } | 127 } |
128 m_pStream->InitStream(pData, size, pDict); | 128 m_pStream->InitStream(pData, size, pDict); |
129 } | 129 } |
130 | 130 |
131 void CPDF_Image::SetJpegImage(IFX_FileRead* pFile) { | 131 void CPDF_Image::SetJpegImage(IFX_FileRead* pFile) { |
132 FX_DWORD size = (FX_DWORD)pFile->GetSize(); | 132 uint32_t size = (uint32_t)pFile->GetSize(); |
133 if (!size) { | 133 if (!size) { |
134 return; | 134 return; |
135 } | 135 } |
136 FX_DWORD dwEstimateSize = size; | 136 uint32_t dwEstimateSize = size; |
137 if (dwEstimateSize > 8192) { | 137 if (dwEstimateSize > 8192) { |
138 dwEstimateSize = 8192; | 138 dwEstimateSize = 8192; |
139 } | 139 } |
140 uint8_t* pData = FX_Alloc(uint8_t, dwEstimateSize); | 140 uint8_t* pData = FX_Alloc(uint8_t, dwEstimateSize); |
141 pFile->ReadBlock(pData, 0, dwEstimateSize); | 141 pFile->ReadBlock(pData, 0, dwEstimateSize); |
142 CPDF_Dictionary* pDict = InitJPEG(pData, dwEstimateSize); | 142 CPDF_Dictionary* pDict = InitJPEG(pData, dwEstimateSize); |
143 FX_Free(pData); | 143 FX_Free(pData); |
144 if (!pDict && size > dwEstimateSize) { | 144 if (!pDict && size > dwEstimateSize) { |
145 pData = FX_Alloc(uint8_t, size); | 145 pData = FX_Alloc(uint8_t, size); |
146 pFile->ReadBlock(pData, 0, size); | 146 pFile->ReadBlock(pData, 0, size); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 int32_t iPalette = pBitmap->GetPaletteSize(); | 214 int32_t iPalette = pBitmap->GetPaletteSize(); |
215 if (iPalette > 0) { | 215 if (iPalette > 0) { |
216 CPDF_Array* pCS = new CPDF_Array; | 216 CPDF_Array* pCS = new CPDF_Array; |
217 m_pDocument->AddIndirectObject(pCS); | 217 m_pDocument->AddIndirectObject(pCS); |
218 pCS->AddName("Indexed"); | 218 pCS->AddName("Indexed"); |
219 pCS->AddName("DeviceRGB"); | 219 pCS->AddName("DeviceRGB"); |
220 pCS->AddInteger(iPalette - 1); | 220 pCS->AddInteger(iPalette - 1); |
221 uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3); | 221 uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3); |
222 uint8_t* ptr = pColorTable; | 222 uint8_t* ptr = pColorTable; |
223 for (int32_t i = 0; i < iPalette; i++) { | 223 for (int32_t i = 0; i < iPalette; i++) { |
224 FX_DWORD argb = pBitmap->GetPaletteArgb(i); | 224 uint32_t argb = pBitmap->GetPaletteArgb(i); |
225 ptr[0] = (uint8_t)(argb >> 16); | 225 ptr[0] = (uint8_t)(argb >> 16); |
226 ptr[1] = (uint8_t)(argb >> 8); | 226 ptr[1] = (uint8_t)(argb >> 8); |
227 ptr[2] = (uint8_t)argb; | 227 ptr[2] = (uint8_t)argb; |
228 ptr += 3; | 228 ptr += 3; |
229 } | 229 } |
230 CPDF_Stream* pCTS = | 230 CPDF_Stream* pCTS = |
231 new CPDF_Stream(pColorTable, iPalette * 3, new CPDF_Dictionary); | 231 new CPDF_Stream(pColorTable, iPalette * 3, new CPDF_Dictionary); |
232 m_pDocument->AddIndirectObject(pCTS); | 232 m_pDocument->AddIndirectObject(pCTS); |
233 pCS->AddReference(m_pDocument, pCTS); | 233 pCS->AddReference(m_pDocument, pCTS); |
234 pDict->SetAtReference("ColorSpace", m_pDocument, pCS); | 234 pDict->SetAtReference("ColorSpace", m_pDocument, pCS); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 m_Width = BitmapWidth; | 350 m_Width = BitmapWidth; |
351 m_Height = BitmapHeight; | 351 m_Height = BitmapHeight; |
352 FX_Free(dest_buf); | 352 FX_Free(dest_buf); |
353 } | 353 } |
354 | 354 |
355 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) { | 355 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) { |
356 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); | 356 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); |
357 } | 357 } |
358 | 358 |
359 CFX_DIBSource* CPDF_Image::LoadDIBSource(CFX_DIBSource** ppMask, | 359 CFX_DIBSource* CPDF_Image::LoadDIBSource(CFX_DIBSource** ppMask, |
360 FX_DWORD* pMatteColor, | 360 uint32_t* pMatteColor, |
361 FX_BOOL bStdCS, | 361 FX_BOOL bStdCS, |
362 FX_DWORD GroupFamily, | 362 uint32_t GroupFamily, |
363 FX_BOOL bLoadMask) const { | 363 FX_BOOL bLoadMask) const { |
364 std::unique_ptr<CPDF_DIBSource> source(new CPDF_DIBSource); | 364 std::unique_ptr<CPDF_DIBSource> source(new CPDF_DIBSource); |
365 if (source->Load(m_pDocument, m_pStream, | 365 if (source->Load(m_pDocument, m_pStream, |
366 reinterpret_cast<CPDF_DIBSource**>(ppMask), pMatteColor, | 366 reinterpret_cast<CPDF_DIBSource**>(ppMask), pMatteColor, |
367 nullptr, nullptr, bStdCS, GroupFamily, bLoadMask)) { | 367 nullptr, nullptr, bStdCS, GroupFamily, bLoadMask)) { |
368 return source.release(); | 368 return source.release(); |
369 } | 369 } |
370 return nullptr; | 370 return nullptr; |
371 } | 371 } |
372 | 372 |
373 CFX_DIBSource* CPDF_Image::DetachBitmap() { | 373 CFX_DIBSource* CPDF_Image::DetachBitmap() { |
374 CFX_DIBSource* pBitmap = m_pDIBSource; | 374 CFX_DIBSource* pBitmap = m_pDIBSource; |
375 m_pDIBSource = nullptr; | 375 m_pDIBSource = nullptr; |
376 return pBitmap; | 376 return pBitmap; |
377 } | 377 } |
378 | 378 |
379 CFX_DIBSource* CPDF_Image::DetachMask() { | 379 CFX_DIBSource* CPDF_Image::DetachMask() { |
380 CFX_DIBSource* pBitmap = m_pMask; | 380 CFX_DIBSource* pBitmap = m_pMask; |
381 m_pMask = nullptr; | 381 m_pMask = nullptr; |
382 return pBitmap; | 382 return pBitmap; |
383 } | 383 } |
384 | 384 |
385 FX_BOOL CPDF_Image::StartLoadDIBSource(CPDF_Dictionary* pFormResource, | 385 FX_BOOL CPDF_Image::StartLoadDIBSource(CPDF_Dictionary* pFormResource, |
386 CPDF_Dictionary* pPageResource, | 386 CPDF_Dictionary* pPageResource, |
387 FX_BOOL bStdCS, | 387 FX_BOOL bStdCS, |
388 FX_DWORD GroupFamily, | 388 uint32_t GroupFamily, |
389 FX_BOOL bLoadMask) { | 389 FX_BOOL bLoadMask) { |
390 std::unique_ptr<CPDF_DIBSource> source(new CPDF_DIBSource); | 390 std::unique_ptr<CPDF_DIBSource> source(new CPDF_DIBSource); |
391 int ret = | 391 int ret = |
392 source->StartLoadDIBSource(m_pDocument, m_pStream, TRUE, pFormResource, | 392 source->StartLoadDIBSource(m_pDocument, m_pStream, TRUE, pFormResource, |
393 pPageResource, bStdCS, GroupFamily, bLoadMask); | 393 pPageResource, bStdCS, GroupFamily, bLoadMask); |
394 if (ret == 2) { | 394 if (ret == 2) { |
395 m_pDIBSource = source.release(); | 395 m_pDIBSource = source.release(); |
396 return TRUE; | 396 return TRUE; |
397 } | 397 } |
398 if (!ret) { | 398 if (!ret) { |
(...skipping 14 matching lines...) Expand all Loading... |
413 } | 413 } |
414 if (!ret) { | 414 if (!ret) { |
415 delete m_pDIBSource; | 415 delete m_pDIBSource; |
416 m_pDIBSource = nullptr; | 416 m_pDIBSource = nullptr; |
417 return FALSE; | 417 return FALSE; |
418 } | 418 } |
419 m_pMask = pSource->DetachMask(); | 419 m_pMask = pSource->DetachMask(); |
420 m_MatteColor = pSource->GetMatteColor(); | 420 m_MatteColor = pSource->GetMatteColor(); |
421 return FALSE; | 421 return FALSE; |
422 } | 422 } |
OLD | NEW |