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

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

Issue 1172793002: Merge to XFA: Use stdint.h types throughout PDFium. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 6 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/common.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(FX_LPBYTE pData, FX_DWORD size) 13 CPDF_Dictionary* CPDF_Image::InitJPEG(FX_LPBYTE pData, FX_DWORD size)
14 { 14 {
15 FX_INT32 width, height, color_trans, num_comps, bits; 15 int32_t width, height, color_trans, num_comps, bits;
16 if (!CPDF_ModuleMgr::Get()->GetJpegModule()-> 16 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->
17 LoadInfo(pData, size, width, height, num_comps, bits, color_trans)) { 17 LoadInfo(pData, size, width, height, num_comps, bits, color_trans)) {
18 return NULL; 18 return NULL;
19 } 19 }
20 CPDF_Dictionary* pDict = new CPDF_Dictionary; 20 CPDF_Dictionary* pDict = new CPDF_Dictionary;
21 pDict->SetAtName("Type", "XObject"); 21 pDict->SetAtName("Type", "XObject");
22 pDict->SetAtName("Subtype", "Image"); 22 pDict->SetAtName("Subtype", "Image");
23 pDict->SetAtInteger("Width", width); 23 pDict->SetAtInteger("Width", width);
24 pDict->SetAtInteger("Height", height); 24 pDict->SetAtInteger("Height", height);
25 FX_LPCSTR csname = NULL; 25 FX_LPCSTR csname = NULL;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 void CPDF_Image::SetJpegImage(IFX_FileRead *pFile) 63 void CPDF_Image::SetJpegImage(IFX_FileRead *pFile)
64 { 64 {
65 FX_DWORD size = (FX_DWORD)pFile->GetSize(); 65 FX_DWORD size = (FX_DWORD)pFile->GetSize();
66 if (!size) { 66 if (!size) {
67 return; 67 return;
68 } 68 }
69 FX_DWORD dwEstimateSize = size; 69 FX_DWORD dwEstimateSize = size;
70 if (dwEstimateSize > 8192) { 70 if (dwEstimateSize > 8192) {
71 dwEstimateSize = 8192; 71 dwEstimateSize = 8192;
72 } 72 }
73 FX_LPBYTE pData = FX_Alloc(FX_BYTE, dwEstimateSize); 73 FX_LPBYTE pData = FX_Alloc(uint8_t, dwEstimateSize);
74 pFile->ReadBlock(pData, 0, dwEstimateSize); 74 pFile->ReadBlock(pData, 0, dwEstimateSize);
75 CPDF_Dictionary *pDict = InitJPEG(pData, dwEstimateSize); 75 CPDF_Dictionary *pDict = InitJPEG(pData, dwEstimateSize);
76 FX_Free(pData); 76 FX_Free(pData);
77 if (!pDict && size > dwEstimateSize) { 77 if (!pDict && size > dwEstimateSize) {
78 pData = FX_Alloc(FX_BYTE, size); 78 pData = FX_Alloc(uint8_t, size);
79 pFile->ReadBlock(pData, 0, size); 79 pFile->ReadBlock(pData, 0, size);
80 pDict = InitJPEG(pData, size); 80 pDict = InitJPEG(pData, size);
81 FX_Free(pData); 81 FX_Free(pData);
82 } 82 }
83 if (!pDict) { 83 if (!pDict) {
84 return; 84 return;
85 } 85 }
86 m_pStream->InitStream(pFile, pDict); 86 m_pStream->InitStream(pFile, pDict);
87 } 87 }
88 void _DCTEncodeBitmap(CPDF_Dictionary *pBitmapDict, const CFX_DIBitmap* pBitmap, int quality, FX_LPBYTE &buf, FX_STRSIZE &size) 88 void _DCTEncodeBitmap(CPDF_Dictionary *pBitmapDict, const CFX_DIBitmap* pBitmap, int quality, FX_LPBYTE &buf, FX_STRSIZE &size)
89 { 89 {
90 } 90 }
91 void _JBIG2EncodeBitmap(CPDF_Dictionary *pBitmapDict, const CFX_DIBitmap *pBitma p, CPDF_Document *pDoc, FX_LPBYTE &buf, FX_STRSIZE &size, FX_BOOL bLossLess) 91 void _JBIG2EncodeBitmap(CPDF_Dictionary *pBitmapDict, const CFX_DIBitmap *pBitma p, CPDF_Document *pDoc, FX_LPBYTE &buf, FX_STRSIZE &size, FX_BOOL bLossLess)
92 { 92 {
93 } 93 }
94 void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, FX_INT32 iCompress, IFX_F ileWrite *pFileWrite, IFX_FileRead *pFileRead, const CFX_DIBitmap* pMask, const CPDF_ImageSetParam* pParam) 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)
95 { 95 {
96 FX_INT32 BitmapWidth = pBitmap->GetWidth(); 96 int32_t BitmapWidth = pBitmap->GetWidth();
97 FX_INT32 BitmapHeight = pBitmap->GetHeight(); 97 int32_t BitmapHeight = pBitmap->GetHeight();
98 if (BitmapWidth < 1 || BitmapHeight < 1) { 98 if (BitmapWidth < 1 || BitmapHeight < 1) {
99 return; 99 return;
100 } 100 }
101 FX_LPBYTE src_buf = pBitmap->GetBuffer(); 101 FX_LPBYTE src_buf = pBitmap->GetBuffer();
102 FX_INT32 src_pitch = pBitmap->GetPitch(); 102 int32_t src_pitch = pBitmap->GetPitch();
103 FX_INT32 bpp = pBitmap->GetBPP(); 103 int32_t bpp = pBitmap->GetBPP();
104 FX_BOOL bUseMatte = pParam && pParam->pMatteColor && (pBitmap->GetFormat() = = FXDIB_Argb); 104 FX_BOOL bUseMatte = pParam && pParam->pMatteColor && (pBitmap->GetFormat() = = FXDIB_Argb);
105 CPDF_Dictionary* pDict = new CPDF_Dictionary; 105 CPDF_Dictionary* pDict = new CPDF_Dictionary;
106 pDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("XObject")); 106 pDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("XObject"));
107 pDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Image")); 107 pDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Image"));
108 pDict->SetAtInteger(FX_BSTRC("Width"), BitmapWidth); 108 pDict->SetAtInteger(FX_BSTRC("Width"), BitmapWidth);
109 pDict->SetAtInteger(FX_BSTRC("Height"), BitmapHeight); 109 pDict->SetAtInteger(FX_BSTRC("Height"), BitmapHeight);
110 FX_LPBYTE dest_buf = NULL; 110 FX_LPBYTE dest_buf = NULL;
111 FX_STRSIZE dest_pitch = 0, dest_size = 0, opType = -1; 111 FX_STRSIZE dest_pitch = 0, dest_size = 0, opType = -1;
112 if (bpp == 1) { 112 if (bpp == 1) {
113 FX_INT32 reset_a = 0, reset_r = 0, reset_g = 0, reset_b = 0; 113 int32_t reset_a = 0, reset_r = 0, reset_g = 0, reset_b = 0;
114 FX_INT32 set_a = 0, set_r = 0, set_g = 0, set_b = 0; 114 int32_t set_a = 0, set_r = 0, set_g = 0, set_b = 0;
115 if (!pBitmap->IsAlphaMask()) { 115 if (!pBitmap->IsAlphaMask()) {
116 ArgbDecode(pBitmap->GetPaletteArgb(0), reset_a, reset_r, reset_g, re set_b); 116 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); 117 ArgbDecode(pBitmap->GetPaletteArgb(1), set_a, set_r, set_g, set_b);
118 } 118 }
119 if (set_a == 0 || reset_a == 0) { 119 if (set_a == 0 || reset_a == 0) {
120 pDict->SetAt(FX_BSTRC("ImageMask"), new CPDF_Boolean(TRUE)); 120 pDict->SetAt(FX_BSTRC("ImageMask"), new CPDF_Boolean(TRUE));
121 if (reset_a == 0) { 121 if (reset_a == 0) {
122 CPDF_Array* pArray = new CPDF_Array; 122 CPDF_Array* pArray = new CPDF_Array;
123 pArray->AddInteger(1); 123 pArray->AddInteger(1);
124 pArray->AddInteger(0); 124 pArray->AddInteger(0);
(...skipping 17 matching lines...) Expand all
142 pDict->SetAt(FX_BSTRC("ColorSpace"), pCS); 142 pDict->SetAt(FX_BSTRC("ColorSpace"), pCS);
143 } 143 }
144 pDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 1); 144 pDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 1);
145 dest_pitch = (BitmapWidth + 7) / 8; 145 dest_pitch = (BitmapWidth + 7) / 8;
146 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { 146 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) {
147 opType = 1; 147 opType = 1;
148 } else { 148 } else {
149 opType = 0; 149 opType = 0;
150 } 150 }
151 } else if (bpp == 8) { 151 } else if (bpp == 8) {
152 FX_INT32 iPalette = pBitmap->GetPaletteSize(); 152 int32_t iPalette = pBitmap->GetPaletteSize();
153 if (iPalette > 0) { 153 if (iPalette > 0) {
154 CPDF_Array* pCS = new CPDF_Array; 154 CPDF_Array* pCS = new CPDF_Array;
155 m_pDocument->AddIndirectObject(pCS); 155 m_pDocument->AddIndirectObject(pCS);
156 pCS->AddName(FX_BSTRC("Indexed")); 156 pCS->AddName(FX_BSTRC("Indexed"));
157 pCS->AddName(FX_BSTRC("DeviceRGB")); 157 pCS->AddName(FX_BSTRC("DeviceRGB"));
158 pCS->AddInteger(iPalette - 1); 158 pCS->AddInteger(iPalette - 1);
159 FX_LPBYTE pColorTable = FX_Alloc2D(FX_BYTE, iPalette, 3); 159 FX_LPBYTE pColorTable = FX_Alloc2D(uint8_t, iPalette, 3);
160 FX_LPBYTE ptr = pColorTable; 160 FX_LPBYTE ptr = pColorTable;
161 for (FX_INT32 i = 0; i < iPalette; i ++) { 161 for (int32_t i = 0; i < iPalette; i ++) {
162 FX_DWORD argb = pBitmap->GetPaletteArgb(i); 162 FX_DWORD argb = pBitmap->GetPaletteArgb(i);
163 ptr[0] = (FX_BYTE)(argb >> 16); 163 ptr[0] = (uint8_t)(argb >> 16);
164 ptr[1] = (FX_BYTE)(argb >> 8); 164 ptr[1] = (uint8_t)(argb >> 8);
165 ptr[2] = (FX_BYTE)argb; 165 ptr[2] = (uint8_t)argb;
166 ptr += 3; 166 ptr += 3;
167 } 167 }
168 CPDF_Stream *pCTS = CPDF_Stream::Create(pColorTable, iPalette * 3, C PDF_Dictionary::Create()); 168 CPDF_Stream *pCTS = CPDF_Stream::Create(pColorTable, iPalette * 3, C PDF_Dictionary::Create());
169 m_pDocument->AddIndirectObject(pCTS); 169 m_pDocument->AddIndirectObject(pCTS);
170 pCS->AddReference(m_pDocument, pCTS); 170 pCS->AddReference(m_pDocument, pCTS);
171 pDict->SetAtReference(FX_BSTRC("ColorSpace"), m_pDocument, pCS); 171 pDict->SetAtReference(FX_BSTRC("ColorSpace"), m_pDocument, pCS);
172 } else { 172 } else {
173 pDict->SetAtName(FX_BSTRC("ColorSpace"), FX_BSTRC("DeviceGray")); 173 pDict->SetAtName(FX_BSTRC("ColorSpace"), FX_BSTRC("DeviceGray"));
174 } 174 }
175 pDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 8); 175 pDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 8);
(...skipping 19 matching lines...) Expand all
195 pMaskBitmap = pBitmap->GetAlphaMask(); 195 pMaskBitmap = pBitmap->GetAlphaMask();
196 bDeleteMask = TRUE; 196 bDeleteMask = TRUE;
197 } 197 }
198 if (!pMaskBitmap && pMask) { 198 if (!pMaskBitmap && pMask) {
199 FXDIB_Format maskFormat = pMask->GetFormat(); 199 FXDIB_Format maskFormat = pMask->GetFormat();
200 if (maskFormat == FXDIB_1bppMask || maskFormat == FXDIB_8bppMask) { 200 if (maskFormat == FXDIB_1bppMask || maskFormat == FXDIB_8bppMask) {
201 pMaskBitmap = pMask; 201 pMaskBitmap = pMask;
202 } 202 }
203 } 203 }
204 if (pMaskBitmap) { 204 if (pMaskBitmap) {
205 FX_INT32 maskWidth = pMaskBitmap->GetWidth(); 205 int32_t maskWidth = pMaskBitmap->GetWidth();
206 FX_INT32 maskHeight = pMaskBitmap->GetHeight(); 206 int32_t maskHeight = pMaskBitmap->GetHeight();
207 FX_LPBYTE mask_buf = NULL; 207 FX_LPBYTE mask_buf = NULL;
208 FX_STRSIZE mask_size; 208 FX_STRSIZE mask_size;
209 CPDF_Dictionary* pMaskDict = new CPDF_Dictionary; 209 CPDF_Dictionary* pMaskDict = new CPDF_Dictionary;
210 pMaskDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("XObject")); 210 pMaskDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("XObject"));
211 pMaskDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Image")); 211 pMaskDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Image"));
212 pMaskDict->SetAtInteger(FX_BSTRC("Width"), maskWidth); 212 pMaskDict->SetAtInteger(FX_BSTRC("Width"), maskWidth);
213 pMaskDict->SetAtInteger(FX_BSTRC("Height"), maskHeight); 213 pMaskDict->SetAtInteger(FX_BSTRC("Height"), maskHeight);
214 pMaskDict->SetAtName(FX_BSTRC("ColorSpace"), FX_BSTRC("DeviceGray")); 214 pMaskDict->SetAtName(FX_BSTRC("ColorSpace"), FX_BSTRC("DeviceGray"));
215 pMaskDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 8); 215 pMaskDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 8);
216 if (pMaskBitmap->GetBPP() == 8 && (iCompress & PDF_IMAGE_MASK_LOSSY_COMP RESS) != 0) { 216 if (pMaskBitmap->GetBPP() == 8 && (iCompress & PDF_IMAGE_MASK_LOSSY_COMP RESS) != 0) {
217 _DCTEncodeBitmap(pMaskDict, pMaskBitmap, pParam ? pParam->nQuality : 75, mask_buf, mask_size); 217 _DCTEncodeBitmap(pMaskDict, pMaskBitmap, pParam ? pParam->nQuality : 75, mask_buf, mask_size);
218 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) { 218 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) {
219 _JBIG2EncodeBitmap(pMaskDict, pMaskBitmap, m_pDocument, mask_buf, ma sk_size, TRUE); 219 _JBIG2EncodeBitmap(pMaskDict, pMaskBitmap, m_pDocument, mask_buf, ma sk_size, TRUE);
220 } else { 220 } else {
221 mask_buf = FX_Alloc2D(FX_BYTE, maskHeight, maskWidth); 221 mask_buf = FX_Alloc2D(uint8_t, maskHeight, maskWidth);
222 mask_size = maskHeight * maskWidth; // Safe since checked alloc ret urned. 222 mask_size = maskHeight * maskWidth; // Safe since checked alloc ret urned.
223 for (FX_INT32 a = 0; a < maskHeight; a ++) { 223 for (int32_t a = 0; a < maskHeight; a ++) {
224 FXSYS_memcpy32(mask_buf + a * maskWidth, pMaskBitmap->GetScanlin e(a), maskWidth); 224 FXSYS_memcpy32(mask_buf + a * maskWidth, pMaskBitmap->GetScanlin e(a), maskWidth);
225 } 225 }
226 } 226 }
227 pMaskDict->SetAtInteger(FX_BSTRC("Length"), mask_size); 227 pMaskDict->SetAtInteger(FX_BSTRC("Length"), mask_size);
228 if (bUseMatte) { 228 if (bUseMatte) {
229 int a, r, g, b; 229 int a, r, g, b;
230 ArgbDecode(*(pParam->pMatteColor), a, r, g, b); 230 ArgbDecode(*(pParam->pMatteColor), a, r, g, b);
231 CPDF_Array* pMatte = new CPDF_Array; 231 CPDF_Array* pMatte = new CPDF_Array;
232 pMatte->AddInteger(r); 232 pMatte->AddInteger(r);
233 pMatte->AddInteger(g); 233 pMatte->AddInteger(g);
(...skipping 30 matching lines...) Expand all
264 dest_buf = NULL; 264 dest_buf = NULL;
265 } 265 }
266 dest_size = 0; 266 dest_size = 0;
267 delete pNewBitmap; 267 delete pNewBitmap;
268 return; 268 return;
269 } else { 269 } else {
270 if (bUseMatte) { 270 if (bUseMatte) {
271 CFX_DIBitmap *pNewBitmap = new CFX_DIBitmap(); 271 CFX_DIBitmap *pNewBitmap = new CFX_DIBitmap();
272 pNewBitmap->Create(BitmapWidth, BitmapHeight, FXDIB_Argb); 272 pNewBitmap->Create(BitmapWidth, BitmapHeight, FXDIB_Argb);
273 FX_LPBYTE dst_buf = pNewBitmap->GetBuffer(); 273 FX_LPBYTE dst_buf = pNewBitmap->GetBuffer();
274 FX_INT32 src_offset = 0; 274 int32_t src_offset = 0;
275 for (FX_INT32 row = 0; row < BitmapHeight; row ++) { 275 for (int32_t row = 0; row < BitmapHeight; row ++) {
276 src_offset = row * src_pitch; 276 src_offset = row * src_pitch;
277 for (FX_INT32 column = 0; column < BitmapWidth; column + +) { 277 for (int32_t column = 0; column < BitmapWidth; column ++ ) {
278 FX_FLOAT alpha = src_buf[src_offset + 3] / 255.0f; 278 FX_FLOAT alpha = src_buf[src_offset + 3] / 255.0f;
279 dst_buf[src_offset] = (FX_BYTE)(src_buf[src_offset] * alpha); 279 dst_buf[src_offset] = (uint8_t)(src_buf[src_offset] * alpha);
280 dst_buf[src_offset + 1] = (FX_BYTE)(src_buf[src_offs et + 1] * alpha); 280 dst_buf[src_offset + 1] = (uint8_t)(src_buf[src_offs et + 1] * alpha);
281 dst_buf[src_offset + 2] = (FX_BYTE)(src_buf[src_offs et + 2] * alpha); 281 dst_buf[src_offset + 2] = (uint8_t)(src_buf[src_offs et + 2] * alpha);
282 dst_buf[src_offset + 3] = (FX_BYTE)(src_buf[src_offs et + 3]); 282 dst_buf[src_offset + 3] = (uint8_t)(src_buf[src_offs et + 3]);
283 src_offset += 4; 283 src_offset += 4;
284 } 284 }
285 } 285 }
286 _DCTEncodeBitmap(pDict, pNewBitmap, pParam ? pParam->nQualit y : 75, dest_buf, dest_size); 286 _DCTEncodeBitmap(pDict, pNewBitmap, pParam ? pParam->nQualit y : 75, dest_buf, dest_size);
287 delete pNewBitmap; 287 delete pNewBitmap;
288 } else { 288 } else {
289 _DCTEncodeBitmap(pDict, pBitmap, pParam ? pParam->nQuality : 75, dest_buf, dest_size); 289 _DCTEncodeBitmap(pDict, pBitmap, pParam ? pParam->nQuality : 75, dest_buf, dest_size);
290 } 290 }
291 } 291 }
292 } 292 }
293 if (bStream) { 293 if (bStream) {
294 pFileWrite->WriteBlock(dest_buf, dest_size); 294 pFileWrite->WriteBlock(dest_buf, dest_size);
295 FX_Free(dest_buf); 295 FX_Free(dest_buf);
296 dest_buf = NULL; 296 dest_buf = NULL;
297 } 297 }
298 } else if (opType == 1) { 298 } else if (opType == 1) {
299 if (!bStream) { 299 if (!bStream) {
300 dest_buf = FX_Alloc2D(FX_BYTE, dest_pitch, BitmapHeight); 300 dest_buf = FX_Alloc2D(uint8_t, dest_pitch, BitmapHeight);
301 dest_size = dest_pitch * BitmapHeight; // Safe since checked alloc returned. 301 dest_size = dest_pitch * BitmapHeight; // Safe since checked alloc returned.
302 } 302 }
303 FX_LPBYTE pDest = dest_buf; 303 FX_LPBYTE pDest = dest_buf;
304 for (FX_INT32 i = 0; i < BitmapHeight; i ++) { 304 for (int32_t i = 0; i < BitmapHeight; i ++) {
305 if (!bStream) { 305 if (!bStream) {
306 FXSYS_memcpy32(pDest, src_buf, dest_pitch); 306 FXSYS_memcpy32(pDest, src_buf, dest_pitch);
307 pDest += dest_pitch; 307 pDest += dest_pitch;
308 } else { 308 } else {
309 pFileWrite->WriteBlock(src_buf, dest_pitch); 309 pFileWrite->WriteBlock(src_buf, dest_pitch);
310 } 310 }
311 src_buf += src_pitch; 311 src_buf += src_pitch;
312 } 312 }
313 } else if (opType == 2) { 313 } else if (opType == 2) {
314 if (!bStream) { 314 if (!bStream) {
315 dest_buf = FX_Alloc2D(FX_BYTE, dest_pitch, BitmapHeight); 315 dest_buf = FX_Alloc2D(uint8_t, dest_pitch, BitmapHeight);
316 dest_size = dest_pitch * BitmapHeight; // Safe since checked alloc returned. 316 dest_size = dest_pitch * BitmapHeight; // Safe since checked alloc returned.
317 } else { 317 } else {
318 dest_buf = FX_Alloc(FX_BYTE, dest_pitch); 318 dest_buf = FX_Alloc(uint8_t, dest_pitch);
319 } 319 }
320 FX_LPBYTE pDest = dest_buf; 320 FX_LPBYTE pDest = dest_buf;
321 FX_INT32 src_offset = 0; 321 int32_t src_offset = 0;
322 FX_INT32 dest_offset = 0; 322 int32_t dest_offset = 0;
323 for (FX_INT32 row = 0; row < BitmapHeight; row ++) { 323 for (int32_t row = 0; row < BitmapHeight; row ++) {
324 src_offset = row * src_pitch; 324 src_offset = row * src_pitch;
325 for (FX_INT32 column = 0; column < BitmapWidth; column ++) { 325 for (int32_t column = 0; column < BitmapWidth; column ++) {
326 FX_FLOAT alpha = bUseMatte ? src_buf[src_offset + 3] / 255.0f : 1; 326 FX_FLOAT alpha = bUseMatte ? src_buf[src_offset + 3] / 255.0f : 1;
327 pDest[dest_offset] = (FX_BYTE)(src_buf[src_offset + 2] * alpha); 327 pDest[dest_offset] = (uint8_t)(src_buf[src_offset + 2] * alpha);
328 pDest[dest_offset + 1] = (FX_BYTE)(src_buf[src_offset + 1] * alp ha); 328 pDest[dest_offset + 1] = (uint8_t)(src_buf[src_offset + 1] * alp ha);
329 pDest[dest_offset + 2] = (FX_BYTE)(src_buf[src_offset] * alpha); 329 pDest[dest_offset + 2] = (uint8_t)(src_buf[src_offset] * alpha);
330 dest_offset += 3; 330 dest_offset += 3;
331 src_offset += bpp == 24 ? 3 : 4; 331 src_offset += bpp == 24 ? 3 : 4;
332 } 332 }
333 if (bStream) { 333 if (bStream) {
334 pFileWrite->WriteBlock(pDest, dest_pitch); 334 pFileWrite->WriteBlock(pDest, dest_pitch);
335 pDest = dest_buf; 335 pDest = dest_buf;
336 } else { 336 } else {
337 pDest += dest_pitch; 337 pDest += dest_pitch;
338 } 338 }
339 dest_offset = 0; 339 dest_offset = 0;
(...skipping 16 matching lines...) Expand all
356 m_Width = BitmapWidth; 356 m_Width = BitmapWidth;
357 m_Height = BitmapHeight; 357 m_Height = BitmapHeight;
358 if (dest_buf) { 358 if (dest_buf) {
359 FX_Free(dest_buf); 359 FX_Free(dest_buf);
360 } 360 }
361 } 361 }
362 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) 362 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap)
363 { 363 {
364 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); 364 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap);
365 } 365 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp ('k') | core/src/fpdfapi/fpdf_font/common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698