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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 data.resize(size); | 133 data.resize(size); |
134 pFile->ReadBlock(data.data(), 0, size); | 134 pFile->ReadBlock(data.data(), 0, size); |
135 pDict = InitJPEG(data.data(), size); | 135 pDict = InitJPEG(data.data(), size); |
136 } | 136 } |
137 if (!pDict) | 137 if (!pDict) |
138 return; | 138 return; |
139 | 139 |
140 m_pStream->InitStreamFromFile(pFile, std::move(pDict)); | 140 m_pStream->InitStreamFromFile(pFile, std::move(pDict)); |
141 } | 141 } |
142 | 142 |
| 143 void CPDF_Image::SetJpegImageInline( |
| 144 const CFX_RetainPtr<IFX_SeekableReadStream>& pFile) { |
| 145 uint32_t size = pdfium::base::checked_cast<uint32_t>(pFile->GetSize()); |
| 146 if (!size) |
| 147 return; |
| 148 |
| 149 std::vector<uint8_t> data(size); |
| 150 if (!pFile->ReadBlock(data.data(), 0, size)) |
| 151 return; |
| 152 |
| 153 std::unique_ptr<CPDF_Dictionary> pDict = InitJPEG(data.data(), size); |
| 154 if (!pDict) |
| 155 return; |
| 156 |
| 157 m_pStream->InitStream(&(data[0]), size, std::move(pDict)); |
| 158 } |
| 159 |
143 void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) { | 160 void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) { |
144 int32_t BitmapWidth = pBitmap->GetWidth(); | 161 int32_t BitmapWidth = pBitmap->GetWidth(); |
145 int32_t BitmapHeight = pBitmap->GetHeight(); | 162 int32_t BitmapHeight = pBitmap->GetHeight(); |
146 if (BitmapWidth < 1 || BitmapHeight < 1) | 163 if (BitmapWidth < 1 || BitmapHeight < 1) |
147 return; | 164 return; |
148 | 165 |
149 auto pDict = | 166 auto pDict = |
150 pdfium::MakeUnique<CPDF_Dictionary>(m_pDocument->GetByteStringPool()); | 167 pdfium::MakeUnique<CPDF_Dictionary>(m_pDocument->GetByteStringPool()); |
151 pDict->SetNewFor<CPDF_Name>("Type", "XObject"); | 168 pDict->SetNewFor<CPDF_Name>("Type", "XObject"); |
152 pDict->SetNewFor<CPDF_Name>("Subtype", "Image"); | 169 pDict->SetNewFor<CPDF_Name>("Subtype", "Image"); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 } | 379 } |
363 if (!ret) { | 380 if (!ret) { |
364 delete m_pDIBSource; | 381 delete m_pDIBSource; |
365 m_pDIBSource = nullptr; | 382 m_pDIBSource = nullptr; |
366 return false; | 383 return false; |
367 } | 384 } |
368 m_pMask = pSource->DetachMask(); | 385 m_pMask = pSource->DetachMask(); |
369 m_MatteColor = pSource->GetMatteColor(); | 386 m_MatteColor = pSource->GetMatteColor(); |
370 return false; | 387 return false; |
371 } | 388 } |
OLD | NEW |