Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: core/fpdfapi/page/cpdf_image.cpp

Issue 2419173002: Update CPDF_IndirectObjectHolder APIs for unique objects (Closed)
Patch Set: Fix issues Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/page/cpdf_docpagedata.cpp ('k') | core/fpdfapi/parser/cfdf_document.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 pDict->SetIntegerFor("BitsPerComponent", 1); 197 pDict->SetIntegerFor("BitsPerComponent", 1);
198 dest_pitch = (BitmapWidth + 7) / 8; 198 dest_pitch = (BitmapWidth + 7) / 8;
199 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { 199 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) {
200 opType = 1; 200 opType = 1;
201 } else { 201 } else {
202 opType = 0; 202 opType = 0;
203 } 203 }
204 } else if (bpp == 8) { 204 } else if (bpp == 8) {
205 int32_t iPalette = pBitmap->GetPaletteSize(); 205 int32_t iPalette = pBitmap->GetPaletteSize();
206 if (iPalette > 0) { 206 if (iPalette > 0) {
207 CPDF_Array* pCS = new CPDF_Array; 207 UniqueArray pCS(new CPDF_Array);
208 pCS->AddName("Indexed"); 208 pCS->AddName("Indexed");
209 pCS->AddName("DeviceRGB"); 209 pCS->AddName("DeviceRGB");
210 pCS->AddInteger(iPalette - 1); 210 pCS->AddInteger(iPalette - 1);
211 uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3); 211 uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3);
212 uint8_t* ptr = pColorTable; 212 uint8_t* ptr = pColorTable;
213 for (int32_t i = 0; i < iPalette; i++) { 213 for (int32_t i = 0; i < iPalette; i++) {
214 uint32_t argb = pBitmap->GetPaletteArgb(i); 214 uint32_t argb = pBitmap->GetPaletteArgb(i);
215 ptr[0] = (uint8_t)(argb >> 16); 215 ptr[0] = (uint8_t)(argb >> 16);
216 ptr[1] = (uint8_t)(argb >> 8); 216 ptr[1] = (uint8_t)(argb >> 8);
217 ptr[2] = (uint8_t)argb; 217 ptr[2] = (uint8_t)argb;
218 ptr += 3; 218 ptr += 3;
219 } 219 }
220 CPDF_Stream* pCTS = new CPDF_Stream( 220 CPDF_Stream* pCTS = m_pDocument->AddIndirectStream(
221 pColorTable, iPalette * 3, 221 pColorTable, iPalette * 3,
222 new CPDF_Dictionary(m_pDocument->GetByteStringPool())); 222 new CPDF_Dictionary(m_pDocument->GetByteStringPool()));
223 pCS->AddReference(m_pDocument, m_pDocument->AddIndirectObject(pCTS)); 223 pCS->AddReference(m_pDocument, pCTS->GetObjNum());
224 pDict->SetReferenceFor("ColorSpace", m_pDocument, 224 pDict->SetReferenceFor("ColorSpace", m_pDocument,
225 m_pDocument->AddIndirectObject(pCS)); 225 m_pDocument->AddIndirectObject(std::move(pCS)));
226 } else { 226 } else {
227 pDict->SetNameFor("ColorSpace", "DeviceGray"); 227 pDict->SetNameFor("ColorSpace", "DeviceGray");
228 } 228 }
229 pDict->SetIntegerFor("BitsPerComponent", 8); 229 pDict->SetIntegerFor("BitsPerComponent", 8);
230 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { 230 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) {
231 dest_pitch = BitmapWidth; 231 dest_pitch = BitmapWidth;
232 opType = 1; 232 opType = 1;
233 } else { 233 } else {
234 opType = 0; 234 opType = 0;
235 } 235 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) { 267 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) {
268 } else { 268 } else {
269 mask_buf = FX_Alloc2D(uint8_t, maskHeight, maskWidth); 269 mask_buf = FX_Alloc2D(uint8_t, maskHeight, maskWidth);
270 mask_size = maskHeight * maskWidth; // Safe since checked alloc returned. 270 mask_size = maskHeight * maskWidth; // Safe since checked alloc returned.
271 for (int32_t a = 0; a < maskHeight; a++) { 271 for (int32_t a = 0; a < maskHeight; a++) {
272 FXSYS_memcpy(mask_buf + a * maskWidth, pMaskBitmap->GetScanline(a), 272 FXSYS_memcpy(mask_buf + a * maskWidth, pMaskBitmap->GetScanline(a),
273 maskWidth); 273 maskWidth);
274 } 274 }
275 } 275 }
276 pMaskDict->SetIntegerFor("Length", mask_size); 276 pMaskDict->SetIntegerFor("Length", mask_size);
277 pDict->SetReferenceFor("SMask", m_pDocument, 277 pDict->SetReferenceFor(
278 m_pDocument->AddIndirectObject(new CPDF_Stream( 278 "SMask", m_pDocument,
279 mask_buf, mask_size, pMaskDict))); 279 m_pDocument->AddIndirectStream(mask_buf, mask_size, pMaskDict));
280 if (bDeleteMask) 280 if (bDeleteMask)
281 delete pMaskBitmap; 281 delete pMaskBitmap;
282 } 282 }
283 if (opType == 0) { 283 if (opType == 0) {
284 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) { 284 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) {
285 } else { 285 } else {
286 if (pBitmap->GetBPP() == 1) { 286 if (pBitmap->GetBPP() == 1) {
287 } else if (pBitmap->GetBPP() >= 8 && pBitmap->GetPalette()) { 287 } else if (pBitmap->GetBPP() >= 8 && pBitmap->GetPalette()) {
288 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap(); 288 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap();
289 pNewBitmap->Copy(pBitmap); 289 pNewBitmap->Copy(pBitmap);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 } 403 }
404 if (!ret) { 404 if (!ret) {
405 delete m_pDIBSource; 405 delete m_pDIBSource;
406 m_pDIBSource = nullptr; 406 m_pDIBSource = nullptr;
407 return FALSE; 407 return FALSE;
408 } 408 }
409 m_pMask = pSource->DetachMask(); 409 m_pMask = pSource->DetachMask();
410 m_MatteColor = pSource->GetMatteColor(); 410 m_MatteColor = pSource->GetMatteColor();
411 return FALSE; 411 return FALSE;
412 } 412 }
OLDNEW
« no previous file with comments | « core/fpdfapi/page/cpdf_docpagedata.cpp ('k') | core/fpdfapi/parser/cfdf_document.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698