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

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

Issue 2361713002: Remove some objnum locals with AddIndirectObject (Closed)
Patch Set: Same treatment for arrays Created 4 years, 3 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
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/fpdf_page/include/cpdf_image.h" 7 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 dest_pitch = (BitmapWidth + 7) / 8; 194 dest_pitch = (BitmapWidth + 7) / 8;
195 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { 195 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) {
196 opType = 1; 196 opType = 1;
197 } else { 197 } else {
198 opType = 0; 198 opType = 0;
199 } 199 }
200 } else if (bpp == 8) { 200 } else if (bpp == 8) {
201 int32_t iPalette = pBitmap->GetPaletteSize(); 201 int32_t iPalette = pBitmap->GetPaletteSize();
202 if (iPalette > 0) { 202 if (iPalette > 0) {
203 CPDF_Array* pCS = new CPDF_Array; 203 CPDF_Array* pCS = new CPDF_Array;
204 m_pDocument->AddIndirectObject(pCS);
205 pCS->AddName("Indexed"); 204 pCS->AddName("Indexed");
206 pCS->AddName("DeviceRGB"); 205 pCS->AddName("DeviceRGB");
207 pCS->AddInteger(iPalette - 1); 206 pCS->AddInteger(iPalette - 1);
208 uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3); 207 uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3);
209 uint8_t* ptr = pColorTable; 208 uint8_t* ptr = pColorTable;
210 for (int32_t i = 0; i < iPalette; i++) { 209 for (int32_t i = 0; i < iPalette; i++) {
211 uint32_t argb = pBitmap->GetPaletteArgb(i); 210 uint32_t argb = pBitmap->GetPaletteArgb(i);
212 ptr[0] = (uint8_t)(argb >> 16); 211 ptr[0] = (uint8_t)(argb >> 16);
213 ptr[1] = (uint8_t)(argb >> 8); 212 ptr[1] = (uint8_t)(argb >> 8);
214 ptr[2] = (uint8_t)argb; 213 ptr[2] = (uint8_t)argb;
215 ptr += 3; 214 ptr += 3;
216 } 215 }
217 CPDF_Stream* pCTS = 216 CPDF_Stream* pCTS =
218 new CPDF_Stream(pColorTable, iPalette * 3, new CPDF_Dictionary); 217 new CPDF_Stream(pColorTable, iPalette * 3, new CPDF_Dictionary);
219 m_pDocument->AddIndirectObject(pCTS); 218 pCS->AddReference(m_pDocument, m_pDocument->AddIndirectObject(pCTS));
220 pCS->AddReference(m_pDocument, pCTS); 219 pDict->SetReferenceFor("ColorSpace", m_pDocument,
221 pDict->SetReferenceFor("ColorSpace", m_pDocument, pCS); 220 m_pDocument->AddIndirectObject(pCS));
222 } else { 221 } else {
223 pDict->SetNameFor("ColorSpace", "DeviceGray"); 222 pDict->SetNameFor("ColorSpace", "DeviceGray");
224 } 223 }
225 pDict->SetIntegerFor("BitsPerComponent", 8); 224 pDict->SetIntegerFor("BitsPerComponent", 8);
226 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { 225 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) {
227 dest_pitch = BitmapWidth; 226 dest_pitch = BitmapWidth;
228 opType = 1; 227 opType = 1;
229 } else { 228 } else {
230 opType = 0; 229 opType = 0;
231 } 230 }
(...skipping 30 matching lines...) Expand all
262 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) { 261 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) {
263 } else { 262 } else {
264 mask_buf = FX_Alloc2D(uint8_t, maskHeight, maskWidth); 263 mask_buf = FX_Alloc2D(uint8_t, maskHeight, maskWidth);
265 mask_size = maskHeight * maskWidth; // Safe since checked alloc returned. 264 mask_size = maskHeight * maskWidth; // Safe since checked alloc returned.
266 for (int32_t a = 0; a < maskHeight; a++) { 265 for (int32_t a = 0; a < maskHeight; a++) {
267 FXSYS_memcpy(mask_buf + a * maskWidth, pMaskBitmap->GetScanline(a), 266 FXSYS_memcpy(mask_buf + a * maskWidth, pMaskBitmap->GetScanline(a),
268 maskWidth); 267 maskWidth);
269 } 268 }
270 } 269 }
271 pMaskDict->SetIntegerFor("Length", mask_size); 270 pMaskDict->SetIntegerFor("Length", mask_size);
272 271 pDict->SetReferenceFor("SMask", m_pDocument,
273 CPDF_Stream* pMaskStream = new CPDF_Stream(mask_buf, mask_size, pMaskDict); 272 m_pDocument->AddIndirectObject(new CPDF_Stream(
274 m_pDocument->AddIndirectObject(pMaskStream); 273 mask_buf, mask_size, pMaskDict)));
275 pDict->SetReferenceFor("SMask", m_pDocument, pMaskStream); 274 if (bDeleteMask)
276 if (bDeleteMask) {
277 delete pMaskBitmap; 275 delete pMaskBitmap;
278 }
279 } 276 }
280 if (opType == 0) { 277 if (opType == 0) {
281 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) { 278 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) {
282 } else { 279 } else {
283 if (pBitmap->GetBPP() == 1) { 280 if (pBitmap->GetBPP() == 1) {
284 } else if (pBitmap->GetBPP() >= 8 && pBitmap->GetPalette()) { 281 } else if (pBitmap->GetBPP() >= 8 && pBitmap->GetPalette()) {
285 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap(); 282 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap();
286 pNewBitmap->Copy(pBitmap); 283 pNewBitmap->Copy(pBitmap);
287 pNewBitmap->ConvertFormat(FXDIB_Rgb); 284 pNewBitmap->ConvertFormat(FXDIB_Rgb);
288 SetImage(pNewBitmap, iCompress); 285 SetImage(pNewBitmap, iCompress);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 } 397 }
401 if (!ret) { 398 if (!ret) {
402 delete m_pDIBSource; 399 delete m_pDIBSource;
403 m_pDIBSource = nullptr; 400 m_pDIBSource = nullptr;
404 return FALSE; 401 return FALSE;
405 } 402 }
406 m_pMask = pSource->DetachMask(); 403 m_pMask = pSource->DetachMask();
407 m_MatteColor = pSource->GetMatteColor(); 404 m_MatteColor = pSource->GetMatteColor();
408 return FALSE; 405 return FALSE;
409 } 406 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp ('k') | core/fpdfapi/fpdf_parser/cfdf_document.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698