Chromium Code Reviews| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 } | 110 } |
| 111 m_bIsMask = false; | 111 m_bIsMask = false; |
| 112 m_Width = width; | 112 m_Width = width; |
| 113 m_Height = height; | 113 m_Height = height; |
| 114 if (!m_pStream) | 114 if (!m_pStream) |
| 115 m_pStream = pdfium::MakeUnique<CPDF_Stream>(); | 115 m_pStream = pdfium::MakeUnique<CPDF_Stream>(); |
| 116 return pDict; | 116 return pDict; |
| 117 } | 117 } |
| 118 | 118 |
| 119 void CPDF_Image::SetJpegImage( | 119 void CPDF_Image::SetJpegImage( |
| 120 const CFX_RetainPtr<IFX_SeekableReadStream>& pFile) { | 120 const CFX_RetainPtr<IFX_SeekableReadStream>& pFile, |
| 121 bool inlineImage) { | |
|
Wei Li
2016/12/14 19:01:19
|inlineImage| is no longer needed
| |
| 121 uint32_t size = pdfium::base::checked_cast<uint32_t>(pFile->GetSize()); | 122 uint32_t size = pdfium::base::checked_cast<uint32_t>(pFile->GetSize()); |
| 122 if (!size) | 123 if (!size) |
| 123 return; | 124 return; |
| 124 | 125 |
| 125 uint32_t dwEstimateSize = std::min(size, 8192U); | 126 uint32_t dwEstimateSize = std::min(size, 8192U); |
| 126 std::vector<uint8_t> data(dwEstimateSize); | 127 std::vector<uint8_t> data(dwEstimateSize); |
| 127 if (!pFile->ReadBlock(data.data(), 0, dwEstimateSize)) | 128 if (!pFile->ReadBlock(data.data(), 0, dwEstimateSize)) |
| 128 return; | 129 return; |
| 129 | 130 |
| 130 std::unique_ptr<CPDF_Dictionary> pDict = | 131 std::unique_ptr<CPDF_Dictionary> pDict = |
| 131 InitJPEG(data.data(), dwEstimateSize); | 132 InitJPEG(data.data(), dwEstimateSize); |
| 132 if (!pDict && size > dwEstimateSize) { | 133 if (!pDict && size > dwEstimateSize) { |
| 133 data.resize(size); | 134 data.resize(size); |
| 134 pFile->ReadBlock(data.data(), 0, size); | 135 pFile->ReadBlock(data.data(), 0, size); |
| 135 pDict = InitJPEG(data.data(), size); | 136 pDict = InitJPEG(data.data(), size); |
| 136 } | 137 } |
| 137 if (!pDict) | 138 if (!pDict) |
| 138 return; | 139 return; |
| 139 | 140 |
| 140 m_pStream->InitStreamFromFile(pFile, std::move(pDict)); | 141 m_pStream->InitStreamFromFile(pFile, std::move(pDict)); |
| 141 } | 142 } |
| 142 | 143 |
| 144 void CPDF_Image::SetJpegImageInline( | |
| 145 const CFX_RetainPtr<IFX_SeekableReadStream>& pFile) { | |
| 146 uint32_t size = pdfium::base::checked_cast<uint32_t>(pFile->GetSize()); | |
| 147 if (!size) | |
| 148 return; | |
| 149 | |
| 150 std::vector<uint8_t> data(size); | |
| 151 if (!pFile->ReadBlock(data.data(), 0, size)) | |
| 152 return; | |
| 153 | |
| 154 std::unique_ptr<CPDF_Dictionary> pDict = InitJPEG(data.data(), size); | |
| 155 if (!pDict) | |
| 156 return; | |
| 157 | |
| 158 m_pStream->InitStream(&(data[0]), size, std::move(pDict)); | |
| 159 } | |
| 160 | |
| 143 void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) { | 161 void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) { |
| 144 int32_t BitmapWidth = pBitmap->GetWidth(); | 162 int32_t BitmapWidth = pBitmap->GetWidth(); |
| 145 int32_t BitmapHeight = pBitmap->GetHeight(); | 163 int32_t BitmapHeight = pBitmap->GetHeight(); |
| 146 if (BitmapWidth < 1 || BitmapHeight < 1) | 164 if (BitmapWidth < 1 || BitmapHeight < 1) |
| 147 return; | 165 return; |
| 148 | 166 |
| 149 auto pDict = | 167 auto pDict = |
| 150 pdfium::MakeUnique<CPDF_Dictionary>(m_pDocument->GetByteStringPool()); | 168 pdfium::MakeUnique<CPDF_Dictionary>(m_pDocument->GetByteStringPool()); |
| 151 pDict->SetNewFor<CPDF_Name>("Type", "XObject"); | 169 pDict->SetNewFor<CPDF_Name>("Type", "XObject"); |
| 152 pDict->SetNewFor<CPDF_Name>("Subtype", "Image"); | 170 pDict->SetNewFor<CPDF_Name>("Subtype", "Image"); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 } | 380 } |
| 363 if (!ret) { | 381 if (!ret) { |
| 364 delete m_pDIBSource; | 382 delete m_pDIBSource; |
| 365 m_pDIBSource = nullptr; | 383 m_pDIBSource = nullptr; |
| 366 return false; | 384 return false; |
| 367 } | 385 } |
| 368 m_pMask = pSource->DetachMask(); | 386 m_pMask = pSource->DetachMask(); |
| 369 m_MatteColor = pSource->GetMatteColor(); | 387 m_MatteColor = pSource->GetMatteColor(); |
| 370 return false; | 388 return false; |
| 371 } | 389 } |
| OLD | NEW |