| 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "core/fpdfapi/cpdf_modulemgr.h" | 13 #include "core/fpdfapi/cpdf_modulemgr.h" |
| 14 #include "core/fpdfapi/page/cpdf_docpagedata.h" | 14 #include "core/fpdfapi/page/cpdf_docpagedata.h" |
| 15 #include "core/fpdfapi/page/cpdf_page.h" | 15 #include "core/fpdfapi/page/cpdf_page.h" |
| 16 #include "core/fpdfapi/parser/cpdf_array.h" | 16 #include "core/fpdfapi/parser/cpdf_array.h" |
| 17 #include "core/fpdfapi/parser/cpdf_boolean.h" | 17 #include "core/fpdfapi/parser/cpdf_boolean.h" |
| 18 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 18 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 19 #include "core/fpdfapi/parser/cpdf_document.h" | 19 #include "core/fpdfapi/parser/cpdf_document.h" |
| 20 #include "core/fpdfapi/parser/cpdf_string.h" | 20 #include "core/fpdfapi/parser/cpdf_string.h" |
| 21 #include "core/fpdfapi/render/cpdf_pagerendercache.h" | 21 #include "core/fpdfapi/render/cpdf_pagerendercache.h" |
| 22 #include "core/fpdfapi/render/render_int.h" | 22 #include "core/fpdfapi/render/render_int.h" |
| 23 #include "core/fxcodec/fx_codec.h" | 23 #include "core/fxcodec/fx_codec.h" |
| 24 #include "core/fxge/fx_dib.h" | 24 #include "core/fxge/fx_dib.h" |
| 25 | 25 |
| 26 CPDF_Image::CPDF_Image(CPDF_Document* pDoc) : m_pDocument(pDoc) {} | 26 CPDF_Image::CPDF_Image(CPDF_Document* pDoc) : m_pDocument(pDoc) {} |
| 27 | 27 |
| 28 CPDF_Image::CPDF_Image(CPDF_Document* pDoc, | 28 CPDF_Image::CPDF_Image(CPDF_Document* pDoc, UniqueStream pStream) |
| 29 std::unique_ptr<CPDF_Stream> pStream) | |
| 30 : m_pDocument(pDoc), | 29 : m_pDocument(pDoc), |
| 31 m_pStream(pStream.get()), | 30 m_pStream(pStream.get()), |
| 32 m_pOwnedStream(std::move(pStream)) { | 31 m_pOwnedStream(std::move(pStream)) { |
| 33 if (!m_pStream) | 32 if (!m_pStream) |
| 34 return; | 33 return; |
| 35 | 34 |
| 36 m_pOwnedDict = | 35 m_pOwnedDict = ToDictionary(UniqueObject(m_pStream->GetDict()->Clone())); |
| 37 ToDictionary(std::unique_ptr<CPDF_Object>(m_pStream->GetDict()->Clone())); | |
| 38 m_pDict = m_pOwnedDict.get(); | 36 m_pDict = m_pOwnedDict.get(); |
| 39 FinishInitialization(); | 37 FinishInitialization(); |
| 40 } | 38 } |
| 41 | 39 |
| 42 CPDF_Image::CPDF_Image(CPDF_Document* pDoc, uint32_t dwStreamObjNum) | 40 CPDF_Image::CPDF_Image(CPDF_Document* pDoc, uint32_t dwStreamObjNum) |
| 43 : m_pDocument(pDoc), | 41 : m_pDocument(pDoc), |
| 44 m_pStream(ToStream(pDoc->GetIndirectObject(dwStreamObjNum))) { | 42 m_pStream(ToStream(pDoc->GetIndirectObject(dwStreamObjNum))) { |
| 45 if (!m_pStream) | 43 if (!m_pStream) |
| 46 return; | 44 return; |
| 47 | 45 |
| 48 m_pDict = m_pStream->GetDict(); | 46 m_pDict = m_pStream->GetDict(); |
| 49 FinishInitialization(); | 47 FinishInitialization(); |
| 50 } | 48 } |
| 51 | 49 |
| 52 CPDF_Image::~CPDF_Image() {} | 50 CPDF_Image::~CPDF_Image() {} |
| 53 | 51 |
| 54 void CPDF_Image::FinishInitialization() { | 52 void CPDF_Image::FinishInitialization() { |
| 55 m_pOC = m_pDict->GetDictFor("OC"); | 53 m_pOC = m_pDict->GetDictFor("OC"); |
| 56 m_bIsMask = | 54 m_bIsMask = |
| 57 !m_pDict->KeyExist("ColorSpace") || m_pDict->GetIntegerFor("ImageMask"); | 55 !m_pDict->KeyExist("ColorSpace") || m_pDict->GetIntegerFor("ImageMask"); |
| 58 m_bInterpolate = !!m_pDict->GetIntegerFor("Interpolate"); | 56 m_bInterpolate = !!m_pDict->GetIntegerFor("Interpolate"); |
| 59 m_Height = m_pDict->GetIntegerFor("Height"); | 57 m_Height = m_pDict->GetIntegerFor("Height"); |
| 60 m_Width = m_pDict->GetIntegerFor("Width"); | 58 m_Width = m_pDict->GetIntegerFor("Width"); |
| 61 } | 59 } |
| 62 | 60 |
| 63 CPDF_Image* CPDF_Image::Clone() { | 61 CPDF_Image* CPDF_Image::Clone() { |
| 64 CPDF_Image* pImage = new CPDF_Image(m_pDocument); | 62 CPDF_Image* pImage = new CPDF_Image(m_pDocument); |
| 65 if (m_pOwnedStream) { | 63 if (m_pOwnedStream) { |
| 66 pImage->m_pOwnedStream = | 64 pImage->m_pOwnedStream = ToStream(UniqueObject(m_pOwnedStream->Clone())); |
| 67 ToStream(std::unique_ptr<CPDF_Object>(m_pOwnedStream->Clone())); | |
| 68 pImage->m_pStream = pImage->m_pOwnedStream.get(); | 65 pImage->m_pStream = pImage->m_pOwnedStream.get(); |
| 69 } else { | 66 } else { |
| 70 pImage->m_pStream = m_pStream; | 67 pImage->m_pStream = m_pStream; |
| 71 } | 68 } |
| 72 if (m_pOwnedDict) { | 69 if (m_pOwnedDict) { |
| 73 pImage->m_pOwnedDict = | 70 pImage->m_pOwnedDict = ToDictionary(UniqueObject(m_pOwnedDict->Clone())); |
| 74 ToDictionary(std::unique_ptr<CPDF_Object>(m_pOwnedDict->Clone())); | |
| 75 pImage->m_pDict = pImage->m_pOwnedDict.get(); | 71 pImage->m_pDict = pImage->m_pOwnedDict.get(); |
| 76 } else { | 72 } else { |
| 77 pImage->m_pDict = m_pDict; | 73 pImage->m_pDict = m_pDict; |
| 78 } | 74 } |
| 79 return pImage; | 75 return pImage; |
| 80 } | 76 } |
| 81 | 77 |
| 82 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) { | 78 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) { |
| 83 int32_t width; | 79 int32_t width; |
| 84 int32_t height; | 80 int32_t height; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 } | 282 } |
| 287 if (opType == 0) { | 283 if (opType == 0) { |
| 288 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) { | 284 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) { |
| 289 } else { | 285 } else { |
| 290 if (pBitmap->GetBPP() == 1) { | 286 if (pBitmap->GetBPP() == 1) { |
| 291 } else if (pBitmap->GetBPP() >= 8 && pBitmap->GetPalette()) { | 287 } else if (pBitmap->GetBPP() >= 8 && pBitmap->GetPalette()) { |
| 292 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap(); | 288 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap(); |
| 293 pNewBitmap->Copy(pBitmap); | 289 pNewBitmap->Copy(pBitmap); |
| 294 pNewBitmap->ConvertFormat(FXDIB_Rgb); | 290 pNewBitmap->ConvertFormat(FXDIB_Rgb); |
| 295 SetImage(pNewBitmap, iCompress); | 291 SetImage(pNewBitmap, iCompress); |
| 296 delete pDict; | 292 if (pDict) { |
| 297 pDict = nullptr; | 293 pDict->Release(); |
| 294 pDict = nullptr; |
| 295 } |
| 298 FX_Free(dest_buf); | 296 FX_Free(dest_buf); |
| 299 dest_buf = nullptr; | 297 dest_buf = nullptr; |
| 300 dest_size = 0; | 298 dest_size = 0; |
| 301 delete pNewBitmap; | 299 delete pNewBitmap; |
| 302 return; | 300 return; |
| 303 } | 301 } |
| 304 } | 302 } |
| 305 } else if (opType == 1) { | 303 } else if (opType == 1) { |
| 306 dest_buf = FX_Alloc2D(uint8_t, dest_pitch, BitmapHeight); | 304 dest_buf = FX_Alloc2D(uint8_t, dest_pitch, BitmapHeight); |
| 307 dest_size = dest_pitch * BitmapHeight; // Safe as checked alloc returned. | 305 dest_size = dest_pitch * BitmapHeight; // Safe as checked alloc returned. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 } | 403 } |
| 406 if (!ret) { | 404 if (!ret) { |
| 407 delete m_pDIBSource; | 405 delete m_pDIBSource; |
| 408 m_pDIBSource = nullptr; | 406 m_pDIBSource = nullptr; |
| 409 return false; | 407 return false; |
| 410 } | 408 } |
| 411 m_pMask = pSource->DetachMask(); | 409 m_pMask = pSource->DetachMask(); |
| 412 m_MatteColor = pSource->GetMatteColor(); | 410 m_MatteColor = pSource->GetMatteColor(); |
| 413 return false; | 411 return false; |
| 414 } | 412 } |
| OLD | NEW |