| 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 12 matching lines...) Expand all Loading... |
| 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, |
| 29 std::unique_ptr<CPDF_Stream> pStream) | 29 std::unique_ptr<CPDF_Stream> pStream) |
| 30 : m_pDocument(pDoc), | 30 : m_pDocument(pDoc), |
| 31 m_pStream(pStream.get()), | 31 m_pStream(pStream.get()), |
| 32 m_pOwnedStream(std::move(pStream)) { | 32 m_pOwnedStream(std::move(pStream)) { |
| 33 if (!m_pStream) | |
| 34 return; | |
| 35 | |
| 36 m_pOwnedDict = | 33 m_pOwnedDict = |
| 37 ToDictionary(std::unique_ptr<CPDF_Object>(m_pStream->GetDict()->Clone())); | 34 ToDictionary(std::unique_ptr<CPDF_Object>(m_pStream->GetDict()->Clone())); |
| 38 m_pDict = m_pOwnedDict.get(); | 35 m_pDict = m_pOwnedDict.get(); |
| 39 FinishInitialization(); | 36 FinishInitialization(); |
| 40 } | 37 } |
| 41 | 38 |
| 42 CPDF_Image::CPDF_Image(CPDF_Document* pDoc, uint32_t dwStreamObjNum) | 39 CPDF_Image::CPDF_Image(CPDF_Document* pDoc, uint32_t dwStreamObjNum) |
| 43 : m_pDocument(pDoc), | 40 : m_pDocument(pDoc), |
| 44 m_pStream(ToStream(pDoc->GetIndirectObject(dwStreamObjNum))) { | 41 m_pStream(ToStream(pDoc->GetIndirectObject(dwStreamObjNum))) { |
| 45 if (!m_pStream) | |
| 46 return; | |
| 47 | |
| 48 m_pDict = m_pStream->GetDict(); | 42 m_pDict = m_pStream->GetDict(); |
| 49 FinishInitialization(); | 43 FinishInitialization(); |
| 50 } | 44 } |
| 51 | 45 |
| 52 CPDF_Image::~CPDF_Image() {} | 46 CPDF_Image::~CPDF_Image() {} |
| 53 | 47 |
| 54 void CPDF_Image::FinishInitialization() { | 48 void CPDF_Image::FinishInitialization() { |
| 55 m_pOC = m_pDict->GetDictFor("OC"); | 49 m_pOC = m_pDict->GetDictFor("OC"); |
| 56 m_bIsMask = | 50 m_bIsMask = |
| 57 !m_pDict->KeyExist("ColorSpace") || m_pDict->GetIntegerFor("ImageMask"); | 51 !m_pDict->KeyExist("ColorSpace") || m_pDict->GetIntegerFor("ImageMask"); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 72 if (m_pOwnedDict) { | 66 if (m_pOwnedDict) { |
| 73 pImage->m_pOwnedDict = | 67 pImage->m_pOwnedDict = |
| 74 ToDictionary(std::unique_ptr<CPDF_Object>(m_pOwnedDict->Clone())); | 68 ToDictionary(std::unique_ptr<CPDF_Object>(m_pOwnedDict->Clone())); |
| 75 pImage->m_pDict = pImage->m_pOwnedDict.get(); | 69 pImage->m_pDict = pImage->m_pOwnedDict.get(); |
| 76 } else { | 70 } else { |
| 77 pImage->m_pDict = m_pDict; | 71 pImage->m_pDict = m_pDict; |
| 78 } | 72 } |
| 79 return pImage; | 73 return pImage; |
| 80 } | 74 } |
| 81 | 75 |
| 76 void CPDF_Image::ConvertStreamToIndirectObject() { |
| 77 if (!m_pStream->IsInline()) |
| 78 return; |
| 79 |
| 80 ASSERT(m_pOwnedStream); |
| 81 m_pDocument->AddIndirectObject(m_pOwnedStream.release()); |
| 82 } |
| 83 |
| 82 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) { | 84 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) { |
| 83 int32_t width; | 85 int32_t width; |
| 84 int32_t height; | 86 int32_t height; |
| 85 int32_t num_comps; | 87 int32_t num_comps; |
| 86 int32_t bits; | 88 int32_t bits; |
| 87 bool color_trans; | 89 bool color_trans; |
| 88 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->LoadInfo( | 90 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->LoadInfo( |
| 89 pData, size, &width, &height, &num_comps, &bits, &color_trans)) { | 91 pData, size, &width, &height, &num_comps, &bits, &color_trans)) { |
| 90 return nullptr; | 92 return nullptr; |
| 91 } | 93 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 115 pDict->SetNameFor("Filter", "DCTDecode"); | 117 pDict->SetNameFor("Filter", "DCTDecode"); |
| 116 if (!color_trans) { | 118 if (!color_trans) { |
| 117 CPDF_Dictionary* pParms = | 119 CPDF_Dictionary* pParms = |
| 118 new CPDF_Dictionary(m_pDocument->GetByteStringPool()); | 120 new CPDF_Dictionary(m_pDocument->GetByteStringPool()); |
| 119 pDict->SetFor("DecodeParms", pParms); | 121 pDict->SetFor("DecodeParms", pParms); |
| 120 pParms->SetIntegerFor("ColorTransform", 0); | 122 pParms->SetIntegerFor("ColorTransform", 0); |
| 121 } | 123 } |
| 122 m_bIsMask = false; | 124 m_bIsMask = false; |
| 123 m_Width = width; | 125 m_Width = width; |
| 124 m_Height = height; | 126 m_Height = height; |
| 125 if (!m_pStream) | 127 if (!m_pStream) { |
| 126 m_pStream = new CPDF_Stream; | 128 m_pOwnedStream = pdfium::MakeUnique<CPDF_Stream>(); |
| 129 m_pStream = m_pOwnedStream.get(); |
| 130 } |
| 127 return pDict; | 131 return pDict; |
| 128 } | 132 } |
| 129 | 133 |
| 130 void CPDF_Image::SetJpegImage(IFX_SeekableReadStream* pFile) { | 134 void CPDF_Image::SetJpegImage(IFX_SeekableReadStream* pFile) { |
| 131 uint32_t size = (uint32_t)pFile->GetSize(); | 135 uint32_t size = (uint32_t)pFile->GetSize(); |
| 132 if (!size) | 136 if (!size) |
| 133 return; | 137 return; |
| 134 | 138 |
| 135 uint32_t dwEstimateSize = std::min(size, 8192U); | 139 uint32_t dwEstimateSize = std::min(size, 8192U); |
| 136 std::vector<uint8_t> data(dwEstimateSize); | 140 std::vector<uint8_t> data(dwEstimateSize); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 pDest[dest_offset + 1] = (uint8_t)(src_buf[src_offset + 1] * alpha); | 331 pDest[dest_offset + 1] = (uint8_t)(src_buf[src_offset + 1] * alpha); |
| 328 pDest[dest_offset + 2] = (uint8_t)(src_buf[src_offset] * alpha); | 332 pDest[dest_offset + 2] = (uint8_t)(src_buf[src_offset] * alpha); |
| 329 dest_offset += 3; | 333 dest_offset += 3; |
| 330 src_offset += bpp == 24 ? 3 : 4; | 334 src_offset += bpp == 24 ? 3 : 4; |
| 331 } | 335 } |
| 332 | 336 |
| 333 pDest += dest_pitch; | 337 pDest += dest_pitch; |
| 334 dest_offset = 0; | 338 dest_offset = 0; |
| 335 } | 339 } |
| 336 } | 340 } |
| 337 if (!m_pStream) | 341 if (!m_pStream) { |
| 338 m_pStream = new CPDF_Stream; | 342 m_pOwnedStream = pdfium::MakeUnique<CPDF_Stream>(); |
| 339 | 343 m_pStream = m_pOwnedStream.get(); |
| 344 } |
| 340 m_pStream->InitStream(dest_buf, dest_size, pDict); | 345 m_pStream->InitStream(dest_buf, dest_size, pDict); |
| 341 m_bIsMask = pBitmap->IsAlphaMask(); | 346 m_bIsMask = pBitmap->IsAlphaMask(); |
| 342 m_Width = BitmapWidth; | 347 m_Width = BitmapWidth; |
| 343 m_Height = BitmapHeight; | 348 m_Height = BitmapHeight; |
| 344 FX_Free(dest_buf); | 349 FX_Free(dest_buf); |
| 345 } | 350 } |
| 346 | 351 |
| 347 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) { | 352 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) { |
| 348 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); | 353 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); |
| 349 } | 354 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 } | 410 } |
| 406 if (!ret) { | 411 if (!ret) { |
| 407 delete m_pDIBSource; | 412 delete m_pDIBSource; |
| 408 m_pDIBSource = nullptr; | 413 m_pDIBSource = nullptr; |
| 409 return false; | 414 return false; |
| 410 } | 415 } |
| 411 m_pMask = pSource->DetachMask(); | 416 m_pMask = pSource->DetachMask(); |
| 412 m_MatteColor = pSource->GetMatteColor(); | 417 m_MatteColor = pSource->GetMatteColor(); |
| 413 return false; | 418 return false; |
| 414 } | 419 } |
| OLD | NEW |