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

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

Issue 2345063002: Use string pools in some dictionaries (Closed)
Patch Set: windows compile 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
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 pCS->AddInteger(iPalette - 1); 209 pCS->AddInteger(iPalette - 1);
207 uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3); 210 uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3);
208 uint8_t* ptr = pColorTable; 211 uint8_t* ptr = pColorTable;
209 for (int32_t i = 0; i < iPalette; i++) { 212 for (int32_t i = 0; i < iPalette; i++) {
210 uint32_t argb = pBitmap->GetPaletteArgb(i); 213 uint32_t argb = pBitmap->GetPaletteArgb(i);
211 ptr[0] = (uint8_t)(argb >> 16); 214 ptr[0] = (uint8_t)(argb >> 16);
212 ptr[1] = (uint8_t)(argb >> 8); 215 ptr[1] = (uint8_t)(argb >> 8);
213 ptr[2] = (uint8_t)argb; 216 ptr[2] = (uint8_t)argb;
214 ptr += 3; 217 ptr += 3;
215 } 218 }
216 CPDF_Stream* pCTS = 219 CPDF_Stream* pCTS = new CPDF_Stream(
217 new CPDF_Stream(pColorTable, iPalette * 3, new CPDF_Dictionary); 220 pColorTable, iPalette * 3,
221 new CPDF_Dictionary(m_pDocument->GetByteStringPool()));
218 pCS->AddReference(m_pDocument, m_pDocument->AddIndirectObject(pCTS)); 222 pCS->AddReference(m_pDocument, m_pDocument->AddIndirectObject(pCTS));
219 pDict->SetReferenceFor("ColorSpace", m_pDocument, 223 pDict->SetReferenceFor("ColorSpace", m_pDocument,
220 m_pDocument->AddIndirectObject(pCS)); 224 m_pDocument->AddIndirectObject(pCS));
221 } else { 225 } else {
222 pDict->SetNameFor("ColorSpace", "DeviceGray"); 226 pDict->SetNameFor("ColorSpace", "DeviceGray");
223 } 227 }
224 pDict->SetIntegerFor("BitsPerComponent", 8); 228 pDict->SetIntegerFor("BitsPerComponent", 8);
225 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { 229 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) {
226 dest_pitch = BitmapWidth; 230 dest_pitch = BitmapWidth;
227 opType = 1; 231 opType = 1;
(...skipping 14 matching lines...) Expand all
242 FX_BOOL bDeleteMask = FALSE; 246 FX_BOOL bDeleteMask = FALSE;
243 if (pBitmap->HasAlpha()) { 247 if (pBitmap->HasAlpha()) {
244 pMaskBitmap = pBitmap->GetAlphaMask(); 248 pMaskBitmap = pBitmap->GetAlphaMask();
245 bDeleteMask = TRUE; 249 bDeleteMask = TRUE;
246 } 250 }
247 if (pMaskBitmap) { 251 if (pMaskBitmap) {
248 int32_t maskWidth = pMaskBitmap->GetWidth(); 252 int32_t maskWidth = pMaskBitmap->GetWidth();
249 int32_t maskHeight = pMaskBitmap->GetHeight(); 253 int32_t maskHeight = pMaskBitmap->GetHeight();
250 uint8_t* mask_buf = nullptr; 254 uint8_t* mask_buf = nullptr;
251 FX_STRSIZE mask_size = 0; 255 FX_STRSIZE mask_size = 0;
252 CPDF_Dictionary* pMaskDict = new CPDF_Dictionary; 256 CPDF_Dictionary* pMaskDict =
257 new CPDF_Dictionary(m_pDocument->GetByteStringPool());
253 pMaskDict->SetNameFor("Type", "XObject"); 258 pMaskDict->SetNameFor("Type", "XObject");
254 pMaskDict->SetNameFor("Subtype", "Image"); 259 pMaskDict->SetNameFor("Subtype", "Image");
255 pMaskDict->SetIntegerFor("Width", maskWidth); 260 pMaskDict->SetIntegerFor("Width", maskWidth);
256 pMaskDict->SetIntegerFor("Height", maskHeight); 261 pMaskDict->SetIntegerFor("Height", maskHeight);
257 pMaskDict->SetNameFor("ColorSpace", "DeviceGray"); 262 pMaskDict->SetNameFor("ColorSpace", "DeviceGray");
258 pMaskDict->SetIntegerFor("BitsPerComponent", 8); 263 pMaskDict->SetIntegerFor("BitsPerComponent", 8);
259 if (pMaskBitmap->GetBPP() == 8 && 264 if (pMaskBitmap->GetBPP() == 8 &&
260 (iCompress & PDF_IMAGE_MASK_LOSSY_COMPRESS) != 0) { 265 (iCompress & PDF_IMAGE_MASK_LOSSY_COMPRESS) != 0) {
261 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) { 266 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) {
262 } else { 267 } else {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 } 402 }
398 if (!ret) { 403 if (!ret) {
399 delete m_pDIBSource; 404 delete m_pDIBSource;
400 m_pDIBSource = nullptr; 405 m_pDIBSource = nullptr;
401 return FALSE; 406 return FALSE;
402 } 407 }
403 m_pMask = pSource->DetachMask(); 408 m_pMask = pSource->DetachMask();
404 m_MatteColor = pSource->GetMatteColor(); 409 m_MatteColor = pSource->GetMatteColor();
405 return FALSE; 410 return FALSE;
406 } 411 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h ('k') | core/fpdfapi/fpdf_page/fpdf_page_doc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698