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

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

Issue 2345063002: Use string pools in some dictionaries (Closed)
Patch Set: Remove default ctor 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 int32_t width; 78 int32_t width;
79 int32_t height; 79 int32_t height;
80 int32_t num_comps; 80 int32_t num_comps;
81 int32_t bits; 81 int32_t bits;
82 bool color_trans; 82 bool color_trans;
83 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->LoadInfo( 83 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->LoadInfo(
84 pData, size, &width, &height, &num_comps, &bits, &color_trans)) { 84 pData, size, &width, &height, &num_comps, &bits, &color_trans)) {
85 return nullptr; 85 return nullptr;
86 } 86 }
87 87
88 CPDF_Dictionary* pDict = new CPDF_Dictionary; 88 CPDF_Dictionary* pDict = new CPDF_Dictionary(m_pDocument);
89 pDict->SetNameFor("Type", "XObject"); 89 pDict->SetNameFor("Type", "XObject");
90 pDict->SetNameFor("Subtype", "Image"); 90 pDict->SetNameFor("Subtype", "Image");
91 pDict->SetIntegerFor("Width", width); 91 pDict->SetIntegerFor("Width", width);
92 pDict->SetIntegerFor("Height", height); 92 pDict->SetIntegerFor("Height", height);
93 const FX_CHAR* csname = nullptr; 93 const FX_CHAR* csname = nullptr;
94 if (num_comps == 1) { 94 if (num_comps == 1) {
95 csname = "DeviceGray"; 95 csname = "DeviceGray";
96 } else if (num_comps == 3) { 96 } else if (num_comps == 3) {
97 csname = "DeviceRGB"; 97 csname = "DeviceRGB";
98 } else if (num_comps == 4) { 98 } else if (num_comps == 4) {
99 csname = "DeviceCMYK"; 99 csname = "DeviceCMYK";
100 CPDF_Array* pDecode = new CPDF_Array; 100 CPDF_Array* pDecode = new CPDF_Array;
101 for (int n = 0; n < 4; n++) { 101 for (int n = 0; n < 4; n++) {
102 pDecode->AddInteger(1); 102 pDecode->AddInteger(1);
103 pDecode->AddInteger(0); 103 pDecode->AddInteger(0);
104 } 104 }
105 pDict->SetFor("Decode", pDecode); 105 pDict->SetFor("Decode", pDecode);
106 } 106 }
107 pDict->SetNameFor("ColorSpace", csname); 107 pDict->SetNameFor("ColorSpace", csname);
108 pDict->SetIntegerFor("BitsPerComponent", bits); 108 pDict->SetIntegerFor("BitsPerComponent", bits);
109 pDict->SetNameFor("Filter", "DCTDecode"); 109 pDict->SetNameFor("Filter", "DCTDecode");
110 if (!color_trans) { 110 if (!color_trans) {
111 CPDF_Dictionary* pParms = new CPDF_Dictionary; 111 CPDF_Dictionary* pParms = new CPDF_Dictionary(m_pDocument);
112 pDict->SetFor("DecodeParms", pParms); 112 pDict->SetFor("DecodeParms", pParms);
113 pParms->SetIntegerFor("ColorTransform", 0); 113 pParms->SetIntegerFor("ColorTransform", 0);
114 } 114 }
115 m_bIsMask = FALSE; 115 m_bIsMask = FALSE;
116 m_Width = width; 116 m_Width = width;
117 m_Height = height; 117 m_Height = height;
118 if (!m_pStream) 118 if (!m_pStream)
119 m_pStream = new CPDF_Stream(nullptr, 0, nullptr); 119 m_pStream = new CPDF_Stream(nullptr, 0, nullptr);
120 return pDict; 120 return pDict;
121 } 121 }
(...skipping 21 matching lines...) Expand all
143 void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) { 143 void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) {
144 int32_t BitmapWidth = pBitmap->GetWidth(); 144 int32_t BitmapWidth = pBitmap->GetWidth();
145 int32_t BitmapHeight = pBitmap->GetHeight(); 145 int32_t BitmapHeight = pBitmap->GetHeight();
146 if (BitmapWidth < 1 || BitmapHeight < 1) { 146 if (BitmapWidth < 1 || BitmapHeight < 1) {
147 return; 147 return;
148 } 148 }
149 uint8_t* src_buf = pBitmap->GetBuffer(); 149 uint8_t* src_buf = pBitmap->GetBuffer();
150 int32_t src_pitch = pBitmap->GetPitch(); 150 int32_t src_pitch = pBitmap->GetPitch();
151 int32_t bpp = pBitmap->GetBPP(); 151 int32_t bpp = pBitmap->GetBPP();
152 152
153 CPDF_Dictionary* pDict = new CPDF_Dictionary; 153 CPDF_Dictionary* pDict = new CPDF_Dictionary(m_pDocument);
154 pDict->SetNameFor("Type", "XObject"); 154 pDict->SetNameFor("Type", "XObject");
155 pDict->SetNameFor("Subtype", "Image"); 155 pDict->SetNameFor("Subtype", "Image");
156 pDict->SetIntegerFor("Width", BitmapWidth); 156 pDict->SetIntegerFor("Width", BitmapWidth);
157 pDict->SetIntegerFor("Height", BitmapHeight); 157 pDict->SetIntegerFor("Height", BitmapHeight);
158 uint8_t* dest_buf = nullptr; 158 uint8_t* dest_buf = nullptr;
159 FX_STRSIZE dest_pitch = 0, dest_size = 0, opType = -1; 159 FX_STRSIZE dest_pitch = 0, dest_size = 0, opType = -1;
160 if (bpp == 1) { 160 if (bpp == 1) {
161 int32_t reset_a = 0, reset_r = 0, reset_g = 0, reset_b = 0; 161 int32_t reset_a = 0, reset_r = 0, reset_g = 0, reset_b = 0;
162 int32_t set_a = 0, set_r = 0, set_g = 0, set_b = 0; 162 int32_t set_a = 0, set_r = 0, set_g = 0, set_b = 0;
163 if (!pBitmap->IsAlphaMask()) { 163 if (!pBitmap->IsAlphaMask()) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 pCS->AddInteger(iPalette - 1); 207 pCS->AddInteger(iPalette - 1);
208 uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3); 208 uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3);
209 uint8_t* ptr = pColorTable; 209 uint8_t* ptr = pColorTable;
210 for (int32_t i = 0; i < iPalette; i++) { 210 for (int32_t i = 0; i < iPalette; i++) {
211 uint32_t argb = pBitmap->GetPaletteArgb(i); 211 uint32_t argb = pBitmap->GetPaletteArgb(i);
212 ptr[0] = (uint8_t)(argb >> 16); 212 ptr[0] = (uint8_t)(argb >> 16);
213 ptr[1] = (uint8_t)(argb >> 8); 213 ptr[1] = (uint8_t)(argb >> 8);
214 ptr[2] = (uint8_t)argb; 214 ptr[2] = (uint8_t)argb;
215 ptr += 3; 215 ptr += 3;
216 } 216 }
217 CPDF_Stream* pCTS = 217 CPDF_Stream* pCTS = new CPDF_Stream(pColorTable, iPalette * 3,
218 new CPDF_Stream(pColorTable, iPalette * 3, new CPDF_Dictionary); 218 new CPDF_Dictionary(m_pDocument));
219 m_pDocument->AddIndirectObject(pCTS); 219 m_pDocument->AddIndirectObject(pCTS);
220 pCS->AddReference(m_pDocument, pCTS); 220 pCS->AddReference(m_pDocument, pCTS);
221 pDict->SetReferenceFor("ColorSpace", m_pDocument, pCS); 221 pDict->SetReferenceFor("ColorSpace", m_pDocument, pCS);
222 } else { 222 } else {
223 pDict->SetNameFor("ColorSpace", "DeviceGray"); 223 pDict->SetNameFor("ColorSpace", "DeviceGray");
224 } 224 }
225 pDict->SetIntegerFor("BitsPerComponent", 8); 225 pDict->SetIntegerFor("BitsPerComponent", 8);
226 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { 226 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) {
227 dest_pitch = BitmapWidth; 227 dest_pitch = BitmapWidth;
228 opType = 1; 228 opType = 1;
(...skipping 14 matching lines...) Expand all
243 FX_BOOL bDeleteMask = FALSE; 243 FX_BOOL bDeleteMask = FALSE;
244 if (pBitmap->HasAlpha()) { 244 if (pBitmap->HasAlpha()) {
245 pMaskBitmap = pBitmap->GetAlphaMask(); 245 pMaskBitmap = pBitmap->GetAlphaMask();
246 bDeleteMask = TRUE; 246 bDeleteMask = TRUE;
247 } 247 }
248 if (pMaskBitmap) { 248 if (pMaskBitmap) {
249 int32_t maskWidth = pMaskBitmap->GetWidth(); 249 int32_t maskWidth = pMaskBitmap->GetWidth();
250 int32_t maskHeight = pMaskBitmap->GetHeight(); 250 int32_t maskHeight = pMaskBitmap->GetHeight();
251 uint8_t* mask_buf = nullptr; 251 uint8_t* mask_buf = nullptr;
252 FX_STRSIZE mask_size = 0; 252 FX_STRSIZE mask_size = 0;
253 CPDF_Dictionary* pMaskDict = new CPDF_Dictionary; 253 CPDF_Dictionary* pMaskDict = new CPDF_Dictionary(m_pDocument);
254 pMaskDict->SetNameFor("Type", "XObject"); 254 pMaskDict->SetNameFor("Type", "XObject");
255 pMaskDict->SetNameFor("Subtype", "Image"); 255 pMaskDict->SetNameFor("Subtype", "Image");
256 pMaskDict->SetIntegerFor("Width", maskWidth); 256 pMaskDict->SetIntegerFor("Width", maskWidth);
257 pMaskDict->SetIntegerFor("Height", maskHeight); 257 pMaskDict->SetIntegerFor("Height", maskHeight);
258 pMaskDict->SetNameFor("ColorSpace", "DeviceGray"); 258 pMaskDict->SetNameFor("ColorSpace", "DeviceGray");
259 pMaskDict->SetIntegerFor("BitsPerComponent", 8); 259 pMaskDict->SetIntegerFor("BitsPerComponent", 8);
260 if (pMaskBitmap->GetBPP() == 8 && 260 if (pMaskBitmap->GetBPP() == 8 &&
261 (iCompress & PDF_IMAGE_MASK_LOSSY_COMPRESS) != 0) { 261 (iCompress & PDF_IMAGE_MASK_LOSSY_COMPRESS) != 0) {
262 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) { 262 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) {
263 } else { 263 } else {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 } 400 }
401 if (!ret) { 401 if (!ret) {
402 delete m_pDIBSource; 402 delete m_pDIBSource;
403 m_pDIBSource = nullptr; 403 m_pDIBSource = nullptr;
404 return FALSE; 404 return FALSE;
405 } 405 }
406 m_pMask = pSource->DetachMask(); 406 m_pMask = pSource->DetachMask();
407 m_MatteColor = pSource->GetMatteColor(); 407 m_MatteColor = pSource->GetMatteColor();
408 return FALSE; 408 return FALSE;
409 } 409 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698