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

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

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

Powered by Google App Engine
This is Rietveld 408576698