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

Side by Side Diff: core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp

Issue 1252613002: FX_BOOL considered harmful. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Manual edits. Created 5 years, 5 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/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp ('k') | core/src/fpdfapi/fpdf_font/font_int.h » ('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 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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 "../../../include/fpdfapi/fpdf_module.h" 7 #include "../../../include/fpdfapi/fpdf_module.h"
8 #include "../../../include/fpdfapi/fpdf_page.h" 8 #include "../../../include/fpdfapi/fpdf_page.h"
9 #include "../../../include/fxcodec/fx_codec.h" 9 #include "../../../include/fxcodec/fx_codec.h"
10 #include "../../../include/fpdfapi/fpdf_render.h" 10 #include "../../../include/fpdfapi/fpdf_render.h"
11 #include "../fpdf_page/pageint.h" 11 #include "../fpdf_page/pageint.h"
12 #include "../fpdf_render/render_int.h" 12 #include "../fpdf_render/render_int.h"
13 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, FX_DWORD size) 13 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, FX_DWORD size)
14 { 14 {
15 int32_t width, height, color_trans, num_comps, bits; 15 int32_t width;
16 int32_t height;
17 int32_t num_comps;
18 int32_t bits;
19 bool color_trans;
16 if (!CPDF_ModuleMgr::Get()->GetJpegModule()-> 20 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->
17 LoadInfo(pData, size, width, height, num_comps, bits, color_trans)) { 21 LoadInfo(pData, size, width, height, num_comps, bits, color_trans)) {
18 return NULL; 22 return NULL;
19 } 23 }
20 CPDF_Dictionary* pDict = new CPDF_Dictionary; 24 CPDF_Dictionary* pDict = new CPDF_Dictionary;
21 pDict->SetAtName("Type", "XObject"); 25 pDict->SetAtName("Type", "XObject");
22 pDict->SetAtName("Subtype", "Image"); 26 pDict->SetAtName("Subtype", "Image");
23 pDict->SetAtInteger("Width", width); 27 pDict->SetAtInteger("Width", width);
24 pDict->SetAtInteger("Height", height); 28 pDict->SetAtInteger("Height", height);
25 const FX_CHAR* csname = NULL; 29 const FX_CHAR* csname = NULL;
(...skipping 11 matching lines...) Expand all
37 pDict->SetAt(FX_BSTRC("Decode"), pDecode); 41 pDict->SetAt(FX_BSTRC("Decode"), pDecode);
38 } 42 }
39 pDict->SetAtName("ColorSpace", csname); 43 pDict->SetAtName("ColorSpace", csname);
40 pDict->SetAtInteger("BitsPerComponent", bits); 44 pDict->SetAtInteger("BitsPerComponent", bits);
41 pDict->SetAtName("Filter", "DCTDecode"); 45 pDict->SetAtName("Filter", "DCTDecode");
42 if (!color_trans) { 46 if (!color_trans) {
43 CPDF_Dictionary* pParms = new CPDF_Dictionary; 47 CPDF_Dictionary* pParms = new CPDF_Dictionary;
44 pDict->SetAt("DecodeParms", pParms); 48 pDict->SetAt("DecodeParms", pParms);
45 pParms->SetAtInteger("ColorTransform", 0); 49 pParms->SetAtInteger("ColorTransform", 0);
46 } 50 }
47 m_bIsMask = FALSE; 51 m_bIsMask = false;
48 m_Width = width; 52 m_Width = width;
49 m_Height = height; 53 m_Height = height;
50 if (m_pStream == NULL) { 54 if (m_pStream == NULL) {
51 m_pStream = new CPDF_Stream(NULL, 0, NULL); 55 m_pStream = new CPDF_Stream(NULL, 0, NULL);
52 } 56 }
53 return pDict; 57 return pDict;
54 } 58 }
55 void CPDF_Image::SetJpegImage(uint8_t* pData, FX_DWORD size) 59 void CPDF_Image::SetJpegImage(uint8_t* pData, FX_DWORD size)
56 { 60 {
57 CPDF_Dictionary *pDict = InitJPEG(pData, size); 61 CPDF_Dictionary *pDict = InitJPEG(pData, size);
(...skipping 23 matching lines...) Expand all
81 FX_Free(pData); 85 FX_Free(pData);
82 } 86 }
83 if (!pDict) { 87 if (!pDict) {
84 return; 88 return;
85 } 89 }
86 m_pStream->InitStream(pFile, pDict); 90 m_pStream->InitStream(pFile, pDict);
87 } 91 }
88 void _DCTEncodeBitmap(CPDF_Dictionary *pBitmapDict, const CFX_DIBitmap* pBitmap, int quality, uint8_t* &buf, FX_STRSIZE &size) 92 void _DCTEncodeBitmap(CPDF_Dictionary *pBitmapDict, const CFX_DIBitmap* pBitmap, int quality, uint8_t* &buf, FX_STRSIZE &size)
89 { 93 {
90 } 94 }
91 void _JBIG2EncodeBitmap(CPDF_Dictionary *pBitmapDict, const CFX_DIBitmap *pBitma p, CPDF_Document *pDoc, uint8_t* &buf, FX_STRSIZE &size, FX_BOOL bLossLess) 95 void _JBIG2EncodeBitmap(CPDF_Dictionary *pBitmapDict, const CFX_DIBitmap *pBitma p, CPDF_Document *pDoc, uint8_t* &buf, FX_STRSIZE &size, bool bLossLess)
92 { 96 {
93 } 97 }
94 void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress, IFX_Fi leWrite *pFileWrite, IFX_FileRead *pFileRead, const CFX_DIBitmap* pMask, const C PDF_ImageSetParam* pParam) 98 void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress, IFX_Fi leWrite *pFileWrite, IFX_FileRead *pFileRead, const CFX_DIBitmap* pMask, const C PDF_ImageSetParam* pParam)
95 { 99 {
96 int32_t BitmapWidth = pBitmap->GetWidth(); 100 int32_t BitmapWidth = pBitmap->GetWidth();
97 int32_t BitmapHeight = pBitmap->GetHeight(); 101 int32_t BitmapHeight = pBitmap->GetHeight();
98 if (BitmapWidth < 1 || BitmapHeight < 1) { 102 if (BitmapWidth < 1 || BitmapHeight < 1) {
99 return; 103 return;
100 } 104 }
101 uint8_t* src_buf = pBitmap->GetBuffer(); 105 uint8_t* src_buf = pBitmap->GetBuffer();
102 int32_t src_pitch = pBitmap->GetPitch(); 106 int32_t src_pitch = pBitmap->GetPitch();
103 int32_t bpp = pBitmap->GetBPP(); 107 int32_t bpp = pBitmap->GetBPP();
104 FX_BOOL bUseMatte = pParam && pParam->pMatteColor && (pBitmap->GetFormat() = = FXDIB_Argb); 108 bool bUseMatte = pParam && pParam->pMatteColor && (pBitmap->GetFormat() == F XDIB_Argb);
105 CPDF_Dictionary* pDict = new CPDF_Dictionary; 109 CPDF_Dictionary* pDict = new CPDF_Dictionary;
106 pDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("XObject")); 110 pDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("XObject"));
107 pDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Image")); 111 pDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Image"));
108 pDict->SetAtInteger(FX_BSTRC("Width"), BitmapWidth); 112 pDict->SetAtInteger(FX_BSTRC("Width"), BitmapWidth);
109 pDict->SetAtInteger(FX_BSTRC("Height"), BitmapHeight); 113 pDict->SetAtInteger(FX_BSTRC("Height"), BitmapHeight);
110 uint8_t* dest_buf = NULL; 114 uint8_t* dest_buf = NULL;
111 FX_STRSIZE dest_pitch = 0, dest_size = 0, opType = -1; 115 FX_STRSIZE dest_pitch = 0, dest_size = 0, opType = -1;
112 if (bpp == 1) { 116 if (bpp == 1) {
113 int32_t reset_a = 0, reset_r = 0, reset_g = 0, reset_b = 0; 117 int32_t reset_a = 0, reset_r = 0, reset_g = 0, reset_b = 0;
114 int32_t set_a = 0, set_r = 0, set_g = 0, set_b = 0; 118 int32_t set_a = 0, set_r = 0, set_g = 0, set_b = 0;
115 if (!pBitmap->IsAlphaMask()) { 119 if (!pBitmap->IsAlphaMask()) {
116 ArgbDecode(pBitmap->GetPaletteArgb(0), reset_a, reset_r, reset_g, re set_b); 120 ArgbDecode(pBitmap->GetPaletteArgb(0), reset_a, reset_r, reset_g, re set_b);
117 ArgbDecode(pBitmap->GetPaletteArgb(1), set_a, set_r, set_g, set_b); 121 ArgbDecode(pBitmap->GetPaletteArgb(1), set_a, set_r, set_g, set_b);
118 } 122 }
119 if (set_a == 0 || reset_a == 0) { 123 if (set_a == 0 || reset_a == 0) {
120 pDict->SetAt(FX_BSTRC("ImageMask"), new CPDF_Boolean(TRUE)); 124 pDict->SetAt(FX_BSTRC("ImageMask"), new CPDF_Boolean(true));
121 if (reset_a == 0) { 125 if (reset_a == 0) {
122 CPDF_Array* pArray = new CPDF_Array; 126 CPDF_Array* pArray = new CPDF_Array;
123 pArray->AddInteger(1); 127 pArray->AddInteger(1);
124 pArray->AddInteger(0); 128 pArray->AddInteger(0);
125 pDict->SetAt(FX_BSTRC("Decode"), pArray); 129 pDict->SetAt(FX_BSTRC("Decode"), pArray);
126 } 130 }
127 } else { 131 } else {
128 CPDF_Array* pCS = new CPDF_Array; 132 CPDF_Array* pCS = new CPDF_Array;
129 pCS->AddName(FX_BSTRC("Indexed")); 133 pCS->AddName(FX_BSTRC("Indexed"));
130 pCS->AddName(FX_BSTRC("DeviceRGB")); 134 pCS->AddName(FX_BSTRC("DeviceRGB"));
131 pCS->AddInteger(1); 135 pCS->AddInteger(1);
132 CFX_ByteString ct; 136 CFX_ByteString ct;
133 FX_CHAR* pBuf = ct.GetBuffer(6); 137 FX_CHAR* pBuf = ct.GetBuffer(6);
134 pBuf[0] = (FX_CHAR)reset_r; 138 pBuf[0] = (FX_CHAR)reset_r;
135 pBuf[1] = (FX_CHAR)reset_g; 139 pBuf[1] = (FX_CHAR)reset_g;
136 pBuf[2] = (FX_CHAR)reset_b; 140 pBuf[2] = (FX_CHAR)reset_b;
137 pBuf[3] = (FX_CHAR)set_r; 141 pBuf[3] = (FX_CHAR)set_r;
138 pBuf[4] = (FX_CHAR)set_g; 142 pBuf[4] = (FX_CHAR)set_g;
139 pBuf[5] = (FX_CHAR)set_b; 143 pBuf[5] = (FX_CHAR)set_b;
140 ct.ReleaseBuffer(6); 144 ct.ReleaseBuffer(6);
141 pCS->Add(CPDF_String::Create(ct, TRUE)); 145 pCS->Add(CPDF_String::Create(ct, true));
142 pDict->SetAt(FX_BSTRC("ColorSpace"), pCS); 146 pDict->SetAt(FX_BSTRC("ColorSpace"), pCS);
143 } 147 }
144 pDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 1); 148 pDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 1);
145 dest_pitch = (BitmapWidth + 7) / 8; 149 dest_pitch = (BitmapWidth + 7) / 8;
146 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { 150 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) {
147 opType = 1; 151 opType = 1;
148 } else { 152 } else {
149 opType = 0; 153 opType = 0;
150 } 154 }
151 } else if (bpp == 8) { 155 } else if (bpp == 8) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 pDict->SetAtName(FX_BSTRC("ColorSpace"), FX_BSTRC("DeviceRGB")); 187 pDict->SetAtName(FX_BSTRC("ColorSpace"), FX_BSTRC("DeviceRGB"));
184 pDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 8); 188 pDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 8);
185 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { 189 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) {
186 dest_pitch = BitmapWidth * 3; 190 dest_pitch = BitmapWidth * 3;
187 opType = 2; 191 opType = 2;
188 } else { 192 } else {
189 opType = 0; 193 opType = 0;
190 } 194 }
191 } 195 }
192 const CFX_DIBitmap* pMaskBitmap = NULL; 196 const CFX_DIBitmap* pMaskBitmap = NULL;
193 FX_BOOL bDeleteMask = FALSE; 197 bool bDeleteMask = false;
194 if (pBitmap->HasAlpha()) { 198 if (pBitmap->HasAlpha()) {
195 pMaskBitmap = pBitmap->GetAlphaMask(); 199 pMaskBitmap = pBitmap->GetAlphaMask();
196 bDeleteMask = TRUE; 200 bDeleteMask = true;
197 } 201 }
198 if (!pMaskBitmap && pMask) { 202 if (!pMaskBitmap && pMask) {
199 FXDIB_Format maskFormat = pMask->GetFormat(); 203 FXDIB_Format maskFormat = pMask->GetFormat();
200 if (maskFormat == FXDIB_1bppMask || maskFormat == FXDIB_8bppMask) { 204 if (maskFormat == FXDIB_1bppMask || maskFormat == FXDIB_8bppMask) {
201 pMaskBitmap = pMask; 205 pMaskBitmap = pMask;
202 } 206 }
203 } 207 }
204 if (pMaskBitmap) { 208 if (pMaskBitmap) {
205 int32_t maskWidth = pMaskBitmap->GetWidth(); 209 int32_t maskWidth = pMaskBitmap->GetWidth();
206 int32_t maskHeight = pMaskBitmap->GetHeight(); 210 int32_t maskHeight = pMaskBitmap->GetHeight();
207 uint8_t* mask_buf = NULL; 211 uint8_t* mask_buf = NULL;
208 FX_STRSIZE mask_size; 212 FX_STRSIZE mask_size;
209 CPDF_Dictionary* pMaskDict = new CPDF_Dictionary; 213 CPDF_Dictionary* pMaskDict = new CPDF_Dictionary;
210 pMaskDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("XObject")); 214 pMaskDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("XObject"));
211 pMaskDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Image")); 215 pMaskDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Image"));
212 pMaskDict->SetAtInteger(FX_BSTRC("Width"), maskWidth); 216 pMaskDict->SetAtInteger(FX_BSTRC("Width"), maskWidth);
213 pMaskDict->SetAtInteger(FX_BSTRC("Height"), maskHeight); 217 pMaskDict->SetAtInteger(FX_BSTRC("Height"), maskHeight);
214 pMaskDict->SetAtName(FX_BSTRC("ColorSpace"), FX_BSTRC("DeviceGray")); 218 pMaskDict->SetAtName(FX_BSTRC("ColorSpace"), FX_BSTRC("DeviceGray"));
215 pMaskDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 8); 219 pMaskDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 8);
216 if (pMaskBitmap->GetBPP() == 8 && (iCompress & PDF_IMAGE_MASK_LOSSY_COMP RESS) != 0) { 220 if (pMaskBitmap->GetBPP() == 8 && (iCompress & PDF_IMAGE_MASK_LOSSY_COMP RESS) != 0) {
217 _DCTEncodeBitmap(pMaskDict, pMaskBitmap, pParam ? pParam->nQuality : 75, mask_buf, mask_size); 221 _DCTEncodeBitmap(pMaskDict, pMaskBitmap, pParam ? pParam->nQuality : 75, mask_buf, mask_size);
218 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) { 222 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) {
219 _JBIG2EncodeBitmap(pMaskDict, pMaskBitmap, m_pDocument, mask_buf, ma sk_size, TRUE); 223 _JBIG2EncodeBitmap(pMaskDict, pMaskBitmap, m_pDocument, mask_buf, ma sk_size, true);
220 } else { 224 } else {
221 mask_buf = FX_Alloc2D(uint8_t, maskHeight, maskWidth); 225 mask_buf = FX_Alloc2D(uint8_t, maskHeight, maskWidth);
222 mask_size = maskHeight * maskWidth; // Safe since checked alloc ret urned. 226 mask_size = maskHeight * maskWidth; // Safe since checked alloc ret urned.
223 for (int32_t a = 0; a < maskHeight; a ++) { 227 for (int32_t a = 0; a < maskHeight; a ++) {
224 FXSYS_memcpy(mask_buf + a * maskWidth, pMaskBitmap->GetScanline( a), maskWidth); 228 FXSYS_memcpy(mask_buf + a * maskWidth, pMaskBitmap->GetScanline( a), maskWidth);
225 } 229 }
226 } 230 }
227 pMaskDict->SetAtInteger(FX_BSTRC("Length"), mask_size); 231 pMaskDict->SetAtInteger(FX_BSTRC("Length"), mask_size);
228 if (bUseMatte) { 232 if (bUseMatte) {
229 int a, r, g, b; 233 int a, r, g, b;
230 ArgbDecode(*(pParam->pMatteColor), a, r, g, b); 234 ArgbDecode(*(pParam->pMatteColor), a, r, g, b);
231 CPDF_Array* pMatte = new CPDF_Array; 235 CPDF_Array* pMatte = new CPDF_Array;
232 pMatte->AddInteger(r); 236 pMatte->AddInteger(r);
233 pMatte->AddInteger(g); 237 pMatte->AddInteger(g);
234 pMatte->AddInteger(b); 238 pMatte->AddInteger(b);
235 pMaskDict->SetAt(FX_BSTRC("Matte"), pMatte); 239 pMaskDict->SetAt(FX_BSTRC("Matte"), pMatte);
236 } 240 }
237 CPDF_Stream* pMaskStream = new CPDF_Stream(mask_buf, mask_size, pMaskDic t); 241 CPDF_Stream* pMaskStream = new CPDF_Stream(mask_buf, mask_size, pMaskDic t);
238 m_pDocument->AddIndirectObject(pMaskStream); 242 m_pDocument->AddIndirectObject(pMaskStream);
239 pDict->SetAtReference(FX_BSTRC("SMask"), m_pDocument, pMaskStream); 243 pDict->SetAtReference(FX_BSTRC("SMask"), m_pDocument, pMaskStream);
240 if (bDeleteMask) { 244 if (bDeleteMask) {
241 delete pMaskBitmap; 245 delete pMaskBitmap;
242 } 246 }
243 } 247 }
244 FX_BOOL bStream = pFileWrite != NULL && pFileRead != NULL; 248 bool bStream = pFileWrite != NULL && pFileRead != NULL;
245 if (opType == 0) { 249 if (opType == 0) {
246 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) { 250 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) {
247 if (pBitmap->GetBPP() == 1) { 251 if (pBitmap->GetBPP() == 1) {
248 _JBIG2EncodeBitmap(pDict, pBitmap, m_pDocument, dest_buf, dest_s ize, TRUE); 252 _JBIG2EncodeBitmap(pDict, pBitmap, m_pDocument, dest_buf, dest_s ize, true);
249 } 253 }
250 } else { 254 } else {
251 if (pBitmap->GetBPP() == 1) { 255 if (pBitmap->GetBPP() == 1) {
252 _JBIG2EncodeBitmap(pDict, pBitmap, m_pDocument, dest_buf, dest_s ize, FALSE); 256 _JBIG2EncodeBitmap(pDict, pBitmap, m_pDocument, dest_buf, dest_s ize, false);
253 } else if (pBitmap->GetBPP() >= 8 && pBitmap->GetPalette() != NULL) { 257 } else if (pBitmap->GetBPP() >= 8 && pBitmap->GetPalette() != NULL) {
254 CFX_DIBitmap *pNewBitmap = new CFX_DIBitmap(); 258 CFX_DIBitmap *pNewBitmap = new CFX_DIBitmap();
255 pNewBitmap->Copy(pBitmap); 259 pNewBitmap->Copy(pBitmap);
256 pNewBitmap->ConvertFormat(FXDIB_Rgb); 260 pNewBitmap->ConvertFormat(FXDIB_Rgb);
257 SetImage(pNewBitmap, iCompress, pFileWrite, pFileRead); 261 SetImage(pNewBitmap, iCompress, pFileWrite, pFileRead);
258 if (pDict) { 262 if (pDict) {
259 pDict->Release(); 263 pDict->Release();
260 pDict = NULL; 264 pDict = NULL;
261 } 265 }
262 if (dest_buf) { 266 if (dest_buf) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 m_Width = BitmapWidth; 360 m_Width = BitmapWidth;
357 m_Height = BitmapHeight; 361 m_Height = BitmapHeight;
358 if (dest_buf) { 362 if (dest_buf) {
359 FX_Free(dest_buf); 363 FX_Free(dest_buf);
360 } 364 }
361 } 365 }
362 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) 366 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap)
363 { 367 {
364 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); 368 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap);
365 } 369 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp ('k') | core/src/fpdfapi/fpdf_font/font_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698