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