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/page/cpdf_image.h" | 7 #include "core/fpdfapi/page/cpdf_image.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 pImage->m_pDict = m_pDict; | 71 pImage->m_pDict = m_pDict; |
72 } | 72 } |
73 return pImage; | 73 return pImage; |
74 } | 74 } |
75 | 75 |
76 void CPDF_Image::ConvertStreamToIndirectObject() { | 76 void CPDF_Image::ConvertStreamToIndirectObject() { |
77 if (!m_pStream->IsInline()) | 77 if (!m_pStream->IsInline()) |
78 return; | 78 return; |
79 | 79 |
80 ASSERT(m_pOwnedStream); | 80 ASSERT(m_pOwnedStream); |
81 m_pDocument->AddIndirectObject(m_pOwnedStream.release()); | 81 m_pDocument->AddIndirectObject(std::move(m_pOwnedStream)); |
82 } | 82 } |
83 | 83 |
84 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) { | 84 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) { |
85 int32_t width; | 85 int32_t width; |
86 int32_t height; | 86 int32_t height; |
87 int32_t num_comps; | 87 int32_t num_comps; |
88 int32_t bits; | 88 int32_t bits; |
89 bool color_trans; | 89 bool color_trans; |
90 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->LoadInfo( | 90 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->LoadInfo( |
91 pData, size, &width, &height, &num_comps, &bits, &color_trans)) { | 91 pData, size, &width, &height, &num_comps, &bits, &color_trans)) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 pDict->SetIntegerFor("BitsPerComponent", 1); | 205 pDict->SetIntegerFor("BitsPerComponent", 1); |
206 dest_pitch = (BitmapWidth + 7) / 8; | 206 dest_pitch = (BitmapWidth + 7) / 8; |
207 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { | 207 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { |
208 opType = 1; | 208 opType = 1; |
209 } else { | 209 } else { |
210 opType = 0; | 210 opType = 0; |
211 } | 211 } |
212 } else if (bpp == 8) { | 212 } else if (bpp == 8) { |
213 int32_t iPalette = pBitmap->GetPaletteSize(); | 213 int32_t iPalette = pBitmap->GetPaletteSize(); |
214 if (iPalette > 0) { | 214 if (iPalette > 0) { |
215 CPDF_Array* pCS = new CPDF_Array; | 215 CPDF_Array* pCS = m_pDocument->NewIndirect<CPDF_Array>(); |
216 pCS->AddName("Indexed"); | 216 pCS->AddName("Indexed"); |
217 pCS->AddName("DeviceRGB"); | 217 pCS->AddName("DeviceRGB"); |
218 pCS->AddInteger(iPalette - 1); | 218 pCS->AddInteger(iPalette - 1); |
219 uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3); | 219 uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3); |
220 uint8_t* ptr = pColorTable; | 220 uint8_t* ptr = pColorTable; |
221 for (int32_t i = 0; i < iPalette; i++) { | 221 for (int32_t i = 0; i < iPalette; i++) { |
222 uint32_t argb = pBitmap->GetPaletteArgb(i); | 222 uint32_t argb = pBitmap->GetPaletteArgb(i); |
223 ptr[0] = (uint8_t)(argb >> 16); | 223 ptr[0] = (uint8_t)(argb >> 16); |
224 ptr[1] = (uint8_t)(argb >> 8); | 224 ptr[1] = (uint8_t)(argb >> 8); |
225 ptr[2] = (uint8_t)argb; | 225 ptr[2] = (uint8_t)argb; |
226 ptr += 3; | 226 ptr += 3; |
227 } | 227 } |
228 CPDF_Stream* pCTS = new CPDF_Stream( | 228 CPDF_Stream* pCTS = m_pDocument->NewIndirect<CPDF_Stream>( |
229 pColorTable, iPalette * 3, | 229 pColorTable, iPalette * 3, |
230 new CPDF_Dictionary(m_pDocument->GetByteStringPool())); | 230 new CPDF_Dictionary(m_pDocument->GetByteStringPool())); |
231 pCS->AddReference(m_pDocument, m_pDocument->AddIndirectObject(pCTS)); | 231 pCS->AddReference(m_pDocument, pCTS); |
232 pDict->SetReferenceFor("ColorSpace", m_pDocument, | 232 pDict->SetReferenceFor("ColorSpace", m_pDocument, pCS); |
233 m_pDocument->AddIndirectObject(pCS)); | |
234 } else { | 233 } else { |
235 pDict->SetNameFor("ColorSpace", "DeviceGray"); | 234 pDict->SetNameFor("ColorSpace", "DeviceGray"); |
236 } | 235 } |
237 pDict->SetIntegerFor("BitsPerComponent", 8); | 236 pDict->SetIntegerFor("BitsPerComponent", 8); |
238 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { | 237 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { |
239 dest_pitch = BitmapWidth; | 238 dest_pitch = BitmapWidth; |
240 opType = 1; | 239 opType = 1; |
241 } else { | 240 } else { |
242 opType = 0; | 241 opType = 0; |
243 } | 242 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) { | 274 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) { |
276 } else { | 275 } else { |
277 mask_buf = FX_Alloc2D(uint8_t, maskHeight, maskWidth); | 276 mask_buf = FX_Alloc2D(uint8_t, maskHeight, maskWidth); |
278 mask_size = maskHeight * maskWidth; // Safe since checked alloc returned. | 277 mask_size = maskHeight * maskWidth; // Safe since checked alloc returned. |
279 for (int32_t a = 0; a < maskHeight; a++) { | 278 for (int32_t a = 0; a < maskHeight; a++) { |
280 FXSYS_memcpy(mask_buf + a * maskWidth, pMaskBitmap->GetScanline(a), | 279 FXSYS_memcpy(mask_buf + a * maskWidth, pMaskBitmap->GetScanline(a), |
281 maskWidth); | 280 maskWidth); |
282 } | 281 } |
283 } | 282 } |
284 pMaskDict->SetIntegerFor("Length", mask_size); | 283 pMaskDict->SetIntegerFor("Length", mask_size); |
285 pDict->SetReferenceFor("SMask", m_pDocument, | 284 pDict->SetReferenceFor( |
286 m_pDocument->AddIndirectObject(new CPDF_Stream( | 285 "SMask", m_pDocument, |
287 mask_buf, mask_size, pMaskDict))); | 286 m_pDocument->NewIndirect<CPDF_Stream>(mask_buf, mask_size, pMaskDict)); |
288 if (bDeleteMask) | 287 if (bDeleteMask) |
289 delete pMaskBitmap; | 288 delete pMaskBitmap; |
290 } | 289 } |
291 if (opType == 0) { | 290 if (opType == 0) { |
292 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) { | 291 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) { |
293 } else { | 292 } else { |
294 if (pBitmap->GetBPP() == 1) { | 293 if (pBitmap->GetBPP() == 1) { |
295 } else if (pBitmap->GetBPP() >= 8 && pBitmap->GetPalette()) { | 294 } else if (pBitmap->GetBPP() >= 8 && pBitmap->GetPalette()) { |
296 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap(); | 295 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap(); |
297 pNewBitmap->Copy(pBitmap); | 296 pNewBitmap->Copy(pBitmap); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 } | 409 } |
411 if (!ret) { | 410 if (!ret) { |
412 delete m_pDIBSource; | 411 delete m_pDIBSource; |
413 m_pDIBSource = nullptr; | 412 m_pDIBSource = nullptr; |
414 return false; | 413 return false; |
415 } | 414 } |
416 m_pMask = pSource->DetachMask(); | 415 m_pMask = pSource->DetachMask(); |
417 m_MatteColor = pSource->GetMatteColor(); | 416 m_MatteColor = pSource->GetMatteColor(); |
418 return false; | 417 return false; |
419 } | 418 } |
OLD | NEW |