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) { | |
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 = size; |
127 if (!inlineImage) | |
128 dwEstimateSize = std::min(size, 8192U); | |
129 | |
126 std::vector<uint8_t> data(dwEstimateSize); | 130 std::vector<uint8_t> data(dwEstimateSize); |
127 if (!pFile->ReadBlock(data.data(), 0, dwEstimateSize)) | 131 if (!pFile->ReadBlock(data.data(), 0, dwEstimateSize)) |
128 return; | 132 return; |
129 | 133 |
130 std::unique_ptr<CPDF_Dictionary> pDict = | 134 std::unique_ptr<CPDF_Dictionary> pDict = |
131 InitJPEG(data.data(), dwEstimateSize); | 135 InitJPEG(data.data(), dwEstimateSize); |
132 if (!pDict && size > dwEstimateSize) { | 136 if (!pDict && size > dwEstimateSize) { |
Wei Li
2016/12/14 17:29:38
Also, if we use this merged function, not change '
rbpotter
2016/12/14 18:03:37
Acknowledged.
| |
133 data.resize(size); | 137 data.resize(size); |
134 pFile->ReadBlock(data.data(), 0, size); | 138 pFile->ReadBlock(data.data(), 0, size); |
135 pDict = InitJPEG(data.data(), size); | 139 pDict = InitJPEG(data.data(), size); |
136 } | 140 } |
137 if (!pDict) | 141 if (!pDict) |
138 return; | 142 return; |
139 | 143 |
140 m_pStream->InitStreamFromFile(pFile, std::move(pDict)); | 144 if (inlineImage) |
145 m_pStream->InitStream(&(data[0]), size, std::move(pDict)); | |
146 else | |
147 m_pStream->InitStreamFromFile(pFile, std::move(pDict)); | |
141 } | 148 } |
142 | 149 |
143 void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) { | 150 void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) { |
144 int32_t BitmapWidth = pBitmap->GetWidth(); | 151 int32_t BitmapWidth = pBitmap->GetWidth(); |
145 int32_t BitmapHeight = pBitmap->GetHeight(); | 152 int32_t BitmapHeight = pBitmap->GetHeight(); |
146 if (BitmapWidth < 1 || BitmapHeight < 1) | 153 if (BitmapWidth < 1 || BitmapHeight < 1) |
147 return; | 154 return; |
148 | 155 |
149 auto pDict = | 156 auto pDict = |
150 pdfium::MakeUnique<CPDF_Dictionary>(m_pDocument->GetByteStringPool()); | 157 pdfium::MakeUnique<CPDF_Dictionary>(m_pDocument->GetByteStringPool()); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 } | 369 } |
363 if (!ret) { | 370 if (!ret) { |
364 delete m_pDIBSource; | 371 delete m_pDIBSource; |
365 m_pDIBSource = nullptr; | 372 m_pDIBSource = nullptr; |
366 return false; | 373 return false; |
367 } | 374 } |
368 m_pMask = pSource->DetachMask(); | 375 m_pMask = pSource->DetachMask(); |
369 m_MatteColor = pSource->GetMatteColor(); | 376 m_MatteColor = pSource->GetMatteColor(); |
370 return false; | 377 return false; |
371 } | 378 } |
OLD | NEW |