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

Side by Side Diff: core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp

Issue 966013002: Merge to XFA: Cleanup parts of fpdf_render_loadimage.cpp. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 9 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 | « no previous file | core/src/fpdfapi/fpdf_render/render_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/fxge/fx_ge.h" 7 #include "../../../include/fxge/fx_ge.h"
8 #include "../../../include/fxcodec/fx_codec.h" 8 #include "../../../include/fxcodec/fx_codec.h"
9 #include "../../../include/fpdfapi/fpdf_module.h" 9 #include "../../../include/fpdfapi/fpdf_module.h"
10 #include "../../../include/fpdfapi/fpdf_render.h" 10 #include "../../../include/fpdfapi/fpdf_render.h"
11 #include "../../../include/fpdfapi/fpdf_pageobj.h" 11 #include "../../../include/fpdfapi/fpdf_pageobj.h"
12 #include "../../../src/fxcrt/fx_safe_types.h" 12 #include "../../../src/fxcrt/fx_safe_types.h"
13 #include "../fpdf_page/pageint.h" 13 #include "../fpdf_page/pageint.h"
14 #include "render_int.h" 14 #include "render_int.h"
15 15
16 static unsigned int _GetBits8(FX_LPCBYTE pData, int bitpos, int nbits) 16 namespace {
17
18 unsigned int _GetBits8(FX_LPCBYTE pData, int bitpos, int nbits)
17 { 19 {
18 unsigned int byte = pData[bitpos / 8]; 20 unsigned int byte = pData[bitpos / 8];
19 if (nbits == 8) { 21 if (nbits == 8) {
20 return byte; 22 return byte;
21 } else if (nbits == 4) { 23 } else if (nbits == 4) {
22 return (bitpos % 8) ? (byte & 0x0f) : (byte >> 4); 24 return (bitpos % 8) ? (byte & 0x0f) : (byte >> 4);
23 } else if (nbits == 2) { 25 } else if (nbits == 2) {
24 return (byte >> (6 - bitpos % 8)) & 0x03; 26 return (byte >> (6 - bitpos % 8)) & 0x03;
25 } else if (nbits == 1) { 27 } else if (nbits == 1) {
26 return (byte >> (7 - bitpos % 8)) & 0x01; 28 return (byte >> (7 - bitpos % 8)) & 0x01;
27 } else if (nbits == 16) { 29 } else if (nbits == 16) {
28 return byte * 256 + pData[bitpos / 8 + 1]; 30 return byte * 256 + pData[bitpos / 8 + 1];
29 } 31 }
30 return 0; 32 return 0;
31 } 33 }
34
35 FX_SAFE_DWORD CalculatePitch8(FX_DWORD bpc,
36 FX_DWORD components,
37 int width,
38 int height)
39 {
40 FX_SAFE_DWORD pitch = bpc;
41 pitch *= components;
42 pitch *= width;
43 pitch += 7;
44 pitch /= 8;
45 pitch *= height;
46 return pitch;
47 }
48
49 FX_SAFE_DWORD CalculatePitch32(int bpp, int width)
50 {
51 FX_SAFE_DWORD pitch = bpp;
52 pitch *= width;
53 pitch += 31;
54 pitch /= 8;
55 return pitch;
56 }
57
58 } // namespace
59
32 CFX_DIBSource* CPDF_Image::LoadDIBSource(CFX_DIBSource** ppMask, FX_DWORD* pMatt eColor, FX_BOOL bStdCS, FX_DWORD GroupFamily, FX_BOOL bLoadMask) const 60 CFX_DIBSource* CPDF_Image::LoadDIBSource(CFX_DIBSource** ppMask, FX_DWORD* pMatt eColor, FX_BOOL bStdCS, FX_DWORD GroupFamily, FX_BOOL bLoadMask) const
33 { 61 {
34 CPDF_DIBSource* pSource = FX_NEW CPDF_DIBSource; 62 CPDF_DIBSource* pSource = FX_NEW CPDF_DIBSource;
35 if (pSource->Load(m_pDocument, m_pStream, (CPDF_DIBSource**)ppMask, pMatteCo lor, NULL, NULL, bStdCS, GroupFamily, bLoadMask)) { 63 if (pSource->Load(m_pDocument, m_pStream, (CPDF_DIBSource**)ppMask, pMatteCo lor, NULL, NULL, bStdCS, GroupFamily, bLoadMask)) {
36 return pSource; 64 return pSource;
37 } 65 }
38 delete pSource; 66 delete pSource;
39 return NULL; 67 return NULL;
40 } 68 }
41 CFX_DIBSource* CPDF_Image::DetachBitmap() 69 CFX_DIBSource* CPDF_Image::DetachBitmap()
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 m_MatteColor = 0; 133 m_MatteColor = 0;
106 m_pJbig2Context = NULL; 134 m_pJbig2Context = NULL;
107 m_pGlobalStream = NULL; 135 m_pGlobalStream = NULL;
108 m_bStdCS = FALSE; 136 m_bStdCS = FALSE;
109 m_pMaskStream = NULL; 137 m_pMaskStream = NULL;
110 m_Status = 0; 138 m_Status = 0;
111 m_bHasMask = FALSE; 139 m_bHasMask = FALSE;
112 } 140 }
113 CPDF_DIBSource::~CPDF_DIBSource() 141 CPDF_DIBSource::~CPDF_DIBSource()
114 { 142 {
115 if (m_pStreamAcc) { 143 delete m_pStreamAcc;
116 delete m_pStreamAcc;
117 }
118 if (m_pMaskedLine) { 144 if (m_pMaskedLine) {
119 FX_Free(m_pMaskedLine); 145 FX_Free(m_pMaskedLine);
120 } 146 }
121 if (m_pLineBuf) { 147 if (m_pLineBuf) {
122 FX_Free(m_pLineBuf); 148 FX_Free(m_pLineBuf);
123 } 149 }
124 if (m_pCachedBitmap) { 150 delete m_pCachedBitmap;
125 delete m_pCachedBitmap; 151 delete m_pDecoder;
126 }
127 if (m_pDecoder) {
128 delete m_pDecoder;
129 }
130 if (m_pCompData) { 152 if (m_pCompData) {
131 FX_Free(m_pCompData); 153 FX_Free(m_pCompData);
132 } 154 }
133 CPDF_ColorSpace* pCS = m_pColorSpace; 155 CPDF_ColorSpace* pCS = m_pColorSpace;
134 if (pCS && m_pDocument) { 156 if (pCS && m_pDocument) {
135 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray()); 157 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray());
136 } 158 }
137 if (m_pJbig2Context) { 159 if (m_pJbig2Context) {
138 ICodec_Jbig2Module* pJbig2Moudle = CPDF_ModuleMgr::Get()->GetJbig2Module (); 160 ICodec_Jbig2Module* pJbig2Moudle = CPDF_ModuleMgr::Get()->GetJbig2Module ();
139 pJbig2Moudle->DestroyJbig2Context(m_pJbig2Context); 161 pJbig2Moudle->DestroyJbig2Context(m_pJbig2Context);
140 m_pJbig2Context = NULL;
141 } 162 }
142 if (m_pGlobalStream) { 163 delete m_pGlobalStream;
143 delete m_pGlobalStream;
144 }
145 m_pGlobalStream = NULL;
146 } 164 }
147 CFX_DIBitmap* CPDF_DIBSource::GetBitmap() const 165 CFX_DIBitmap* CPDF_DIBSource::GetBitmap() const
148 { 166 {
149 if (m_pCachedBitmap) { 167 if (m_pCachedBitmap) {
150 return m_pCachedBitmap; 168 return m_pCachedBitmap;
151 } 169 }
152 return Clone(); 170 return Clone();
153 } 171 }
154 void CPDF_DIBSource::ReleaseBitmap(CFX_DIBitmap* pBitmap) const 172 void CPDF_DIBSource::ReleaseBitmap(CFX_DIBitmap* pBitmap) const
155 { 173 {
(...skipping 19 matching lines...) Expand all
175 return FALSE; 193 return FALSE;
176 } 194 }
177 m_GroupFamily = GroupFamily; 195 m_GroupFamily = GroupFamily;
178 m_bLoadMask = bLoadMask; 196 m_bLoadMask = bLoadMask;
179 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag eResources)) { 197 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag eResources)) {
180 return FALSE; 198 return FALSE;
181 } 199 }
182 if (m_bpc == 0 || m_nComponents == 0) { 200 if (m_bpc == 0 || m_nComponents == 0) {
183 return FALSE; 201 return FALSE;
184 } 202 }
185 FX_SAFE_DWORD src_pitch = m_bpc; 203 FX_SAFE_DWORD src_pitch =
186 src_pitch *= m_nComponents; 204 CalculatePitch8(m_bpc, m_nComponents, m_Width, m_Height);
187 src_pitch *= m_Width;
188 src_pitch += 7;
189 src_pitch /= 8;
190 src_pitch *= m_Height;
191 if (!src_pitch.IsValid()) { 205 if (!src_pitch.IsValid()) {
192 return FALSE; 206 return FALSE;
193 } 207 }
194 m_pStreamAcc = FX_NEW CPDF_StreamAcc; 208 m_pStreamAcc = FX_NEW CPDF_StreamAcc;
195 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE); 209 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE);
196 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { 210 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) {
197 return FALSE; 211 return FALSE;
198 } 212 }
199 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); 213 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder();
200 if (!decoder.IsEmpty() && decoder == FX_BSTRC("CCITTFaxDecode")) { 214 if (!decoder.IsEmpty() && decoder == FX_BSTRC("CCITTFaxDecode")) {
201 m_bpc = 1; 215 m_bpc = 1;
202 } 216 }
203 if (!CreateDecoder()) { 217 if (!CreateDecoder()) {
204 return FALSE; 218 return FALSE;
205 } 219 }
206 if (m_bImageMask) { 220 if (m_bImageMask) {
207 m_bpp = 1; 221 m_bpp = 1;
208 m_bpc = 1; 222 m_bpc = 1;
209 m_nComponents = 1; 223 m_nComponents = 1;
210 m_AlphaFlag = 1; 224 m_AlphaFlag = 1;
211 } else if (m_bpc * m_nComponents == 1) { 225 } else if (m_bpc * m_nComponents == 1) {
212 m_bpp = 1; 226 m_bpp = 1;
213 } else if (m_bpc * m_nComponents <= 8) { 227 } else if (m_bpc * m_nComponents <= 8) {
214 m_bpp = 8; 228 m_bpp = 8;
215 } else { 229 } else {
216 m_bpp = 24; 230 m_bpp = 24;
217 } 231 }
218 FX_SAFE_DWORD pitch = m_Width; 232 FX_SAFE_DWORD pitch = CalculatePitch32(m_bpp, m_Width);
219 pitch *= m_bpp;
220 pitch += 31;
221 pitch /= 8;
222 if (!pitch.IsValid()) { 233 if (!pitch.IsValid()) {
223 return FALSE; 234 return FALSE;
224 } 235 }
225 m_pLineBuf = FX_Alloc(FX_BYTE, pitch.ValueOrDie()); 236 m_pLineBuf = FX_Alloc(FX_BYTE, pitch.ValueOrDie());
226 if (m_pColorSpace && bStdCS) { 237 if (m_pColorSpace && bStdCS) {
227 m_pColorSpace->EnableStdConversion(TRUE); 238 m_pColorSpace->EnableStdConversion(TRUE);
228 } 239 }
229 LoadPalette(); 240 LoadPalette();
230 if (m_bColorKey) { 241 if (m_bColorKey) {
231 m_bpp = 32; 242 m_bpp = 32;
232 m_AlphaFlag = 2; 243 m_AlphaFlag = 2;
233 pitch = m_Width; 244 FX_SAFE_DWORD pitch = CalculatePitch32(m_bpp, m_Width);
234 pitch *= m_bpp;
235 pitch += 31;
236 pitch /= 8;
237 if (!pitch.IsValid()) { 245 if (!pitch.IsValid()) {
238 return FALSE; 246 return FALSE;
239 } 247 }
240 m_pMaskedLine = FX_Alloc(FX_BYTE, pitch.ValueOrDie()); 248 m_pMaskedLine = FX_Alloc(FX_BYTE, pitch.ValueOrDie());
241 } 249 }
242 m_Pitch = pitch.ValueOrDie(); 250 m_Pitch = pitch.ValueOrDie();
243 if (ppMask) { 251 if (ppMask) {
244 *ppMask = LoadMask(*pMatteColor); 252 *ppMask = LoadMask(*pMatteColor);
245 } 253 }
246 if (m_pColorSpace && bStdCS) { 254 if (m_pColorSpace && bStdCS) {
(...skipping 11 matching lines...) Expand all
258 } else if (m_bpc * m_nComponents == 1) { 266 } else if (m_bpc * m_nComponents == 1) {
259 m_bpp = 1; 267 m_bpp = 1;
260 } else if (m_bpc * m_nComponents <= 8) { 268 } else if (m_bpc * m_nComponents <= 8) {
261 m_bpp = 8; 269 m_bpp = 8;
262 } else { 270 } else {
263 m_bpp = 24; 271 m_bpp = 24;
264 } 272 }
265 if (!m_bpc || !m_nComponents) { 273 if (!m_bpc || !m_nComponents) {
266 return 0; 274 return 0;
267 } 275 }
268 FX_SAFE_DWORD pitch = m_Width; 276 FX_SAFE_DWORD pitch = CalculatePitch32(m_bpp, m_Width);
269 pitch *= m_bpp;
270 pitch += 31;
271 pitch /= 8;
272 if (!pitch.IsValid()) { 277 if (!pitch.IsValid()) {
273 return 0; 278 return 0;
274 } 279 }
275 m_pLineBuf = FX_Alloc(FX_BYTE, pitch.ValueOrDie()); 280 m_pLineBuf = FX_Alloc(FX_BYTE, pitch.ValueOrDie());
276 if (m_pColorSpace && m_bStdCS) { 281 if (m_pColorSpace && m_bStdCS) {
277 m_pColorSpace->EnableStdConversion(TRUE); 282 m_pColorSpace->EnableStdConversion(TRUE);
278 } 283 }
279 LoadPalette(); 284 LoadPalette();
280 if (m_bColorKey) { 285 if (m_bColorKey) {
281 m_bpp = 32; 286 m_bpp = 32;
282 m_AlphaFlag = 2; 287 m_AlphaFlag = 2;
283 pitch = m_Width; 288 FX_SAFE_DWORD pitch = CalculatePitch32(m_bpp, m_Width);
284 pitch *= m_bpp;
285 pitch += 31;
286 pitch /= 8;
287 if (!pitch.IsValid()) { 289 if (!pitch.IsValid()) {
288 return 0; 290 return 0;
289 } 291 }
290 m_pMaskedLine = FX_Alloc(FX_BYTE, pitch.ValueOrDie()); 292 m_pMaskedLine = FX_Alloc(FX_BYTE, pitch.ValueOrDie());
291 } 293 }
292 m_Pitch = pitch.ValueOrDie(); 294 m_Pitch = pitch.ValueOrDie();
293 return 1; 295 return 1;
294 } 296 }
295 int CPDF_DIBSource::StartLoadDIBSource(CPDF_Document* pDoc, const CPDF_Strea m* pStream, FX_BOOL bHasMask, 297 int CPDF_DIBSource::StartLoadDIBSource(CPDF_Document* pDoc, const CPDF_Strea m* pStream, FX_BOOL bHasMask,
296 CPDF_Dictionary* pFormResources, CPDF_Dic tionary* pPageResources, 298 CPDF_Dictionary* pFormResources, CPDF_Dic tionary* pPageResources,
(...skipping 13 matching lines...) Expand all
310 return 0; 312 return 0;
311 } 313 }
312 m_GroupFamily = GroupFamily; 314 m_GroupFamily = GroupFamily;
313 m_bLoadMask = bLoadMask; 315 m_bLoadMask = bLoadMask;
314 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag eResources)) { 316 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag eResources)) {
315 return 0; 317 return 0;
316 } 318 }
317 if (m_bpc == 0 || m_nComponents == 0) { 319 if (m_bpc == 0 || m_nComponents == 0) {
318 return 0; 320 return 0;
319 } 321 }
320 FX_SAFE_DWORD src_pitch = m_bpc; 322 FX_SAFE_DWORD src_pitch =
321 src_pitch *= m_nComponents; 323 CalculatePitch8(m_bpc, m_nComponents, m_Width, m_Height);
322 src_pitch *= m_Width;
323 src_pitch += 7;
324 src_pitch /= 8;
325 src_pitch *= m_Height;
326 if (!src_pitch.IsValid()) { 324 if (!src_pitch.IsValid()) {
327 return 0; 325 return 0;
328 } 326 }
329 m_pStreamAcc = FX_NEW CPDF_StreamAcc; 327 m_pStreamAcc = FX_NEW CPDF_StreamAcc;
330 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE); 328 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE);
331 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { 329 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) {
332 return 0; 330 return 0;
333 } 331 }
334 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); 332 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder();
335 int ret = CreateDecoder(); 333 int ret = CreateDecoder();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 m_pGlobalStream = FX_NEW CPDF_StreamAcc; 374 m_pGlobalStream = FX_NEW CPDF_StreamAcc;
377 m_pGlobalStream->LoadAllData(pGlobals, FALSE); 375 m_pGlobalStream->LoadAllData(pGlobals, FALSE);
378 } 376 }
379 } 377 }
380 ret = pJbig2Moudle->StartDecode(m_pJbig2Context, m_Width, m_Height, m_pStreamAcc->GetData(), m_pStreamAcc->GetSize(), 378 ret = pJbig2Moudle->StartDecode(m_pJbig2Context, m_Width, m_Height, m_pStreamAcc->GetData(), m_pStreamAcc->GetSize(),
381 m_pGlobalStream ? m_pGlobalStream->G etData() : NULL, m_pGlobalStream ? m_pGlobalStream->GetSize() : 0, m_pCachedBitm ap->GetBuffer(), 379 m_pGlobalStream ? m_pGlobalStream->G etData() : NULL, m_pGlobalStream ? m_pGlobalStream->GetSize() : 0, m_pCachedBitm ap->GetBuffer(),
382 m_pCachedBitmap->GetPitch(), pPause) ; 380 m_pCachedBitmap->GetPitch(), pPause) ;
383 if (ret < 0) { 381 if (ret < 0) {
384 delete m_pCachedBitmap; 382 delete m_pCachedBitmap;
385 m_pCachedBitmap = NULL; 383 m_pCachedBitmap = NULL;
386 if (m_pGlobalStream) { 384 delete m_pGlobalStream;
387 delete m_pGlobalStream;
388 }
389 m_pGlobalStream = NULL; 385 m_pGlobalStream = NULL;
390 pJbig2Moudle->DestroyJbig2Context(m_pJbig2Context); 386 pJbig2Moudle->DestroyJbig2Context(m_pJbig2Context);
391 m_pJbig2Context = NULL; 387 m_pJbig2Context = NULL;
392 return 0; 388 return 0;
393 } 389 }
394 if (ret == FXCODEC_STATUS_DECODE_TOBECONTINUE) { 390 if (ret == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
395 return 2; 391 return 2;
396 } 392 }
397 int ret1 = 1; 393 int ret1 = 1;
398 if (m_bHasMask) { 394 if (m_bHasMask) {
399 ret1 = ContinueLoadMaskDIB(pPause); 395 ret1 = ContinueLoadMaskDIB(pPause);
400 m_Status = 2; 396 m_Status = 2;
401 } 397 }
402 if (ret1 == 2) { 398 if (ret1 == 2) {
403 return ret1; 399 return ret1;
404 } 400 }
405 if (m_pColorSpace && m_bStdCS) { 401 if (m_pColorSpace && m_bStdCS) {
406 m_pColorSpace->EnableStdConversion(FALSE); 402 m_pColorSpace->EnableStdConversion(FALSE);
407 } 403 }
408 return ret1; 404 return ret1;
409 } 405 }
410 FXCODEC_STATUS ret = pJbig2Moudle->ContinueDecode(m_pJbig2Context, pPaus e); 406 FXCODEC_STATUS ret = pJbig2Moudle->ContinueDecode(m_pJbig2Context, pPaus e);
411 if (ret < 0) { 407 if (ret < 0) {
412 delete m_pCachedBitmap; 408 delete m_pCachedBitmap;
413 m_pCachedBitmap = NULL; 409 m_pCachedBitmap = NULL;
414 if (m_pGlobalStream) { 410 delete m_pGlobalStream;
415 delete m_pGlobalStream;
416 }
417 m_pGlobalStream = NULL; 411 m_pGlobalStream = NULL;
418 pJbig2Moudle->DestroyJbig2Context(m_pJbig2Context); 412 pJbig2Moudle->DestroyJbig2Context(m_pJbig2Context);
419 m_pJbig2Context = NULL; 413 m_pJbig2Context = NULL;
420 return 0; 414 return 0;
421 } 415 }
422 if (ret == FXCODEC_STATUS_DECODE_TOBECONTINUE) { 416 if (ret == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
423 return 2; 417 return 2;
424 } 418 }
425 int ret1 = 1; 419 int ret1 = 1;
426 if (m_bHasMask) { 420 if (m_bHasMask) {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 return 0; 565 return 0;
572 } 566 }
573 FX_LPCBYTE src_data = m_pStreamAcc->GetData(); 567 FX_LPCBYTE src_data = m_pStreamAcc->GetData();
574 FX_DWORD src_size = m_pStreamAcc->GetSize(); 568 FX_DWORD src_size = m_pStreamAcc->GetSize();
575 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam(); 569 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam();
576 if (decoder == FX_BSTRC("CCITTFaxDecode")) { 570 if (decoder == FX_BSTRC("CCITTFaxDecode")) {
577 m_pDecoder = FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, m_Hei ght, pParams); 571 m_pDecoder = FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, m_Hei ght, pParams);
578 } else if (decoder == FX_BSTRC("DCTDecode")) { 572 } else if (decoder == FX_BSTRC("DCTDecode")) {
579 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(src_d ata, src_size, m_Width, m_Height, 573 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(src_d ata, src_size, m_Width, m_Height,
580 m_nComponents, pParams ? pParams->GetInteger(FX_BSTR("Color Transform"), 1) : 1); 574 m_nComponents, pParams ? pParams->GetInteger(FX_BSTR("Color Transform"), 1) : 1);
581 if (NULL == m_pDecoder) { 575 if (!m_pDecoder) {
582 FX_BOOL bTransform = FALSE; 576 FX_BOOL bTransform = FALSE;
583 int comps, bpc; 577 int comps, bpc;
584 ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModul e(); 578 ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModul e();
585 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, com ps, bpc, bTransform)) { 579 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, com ps, bpc, bTransform)) {
586 if (m_nComponents != comps) { 580 if (m_nComponents != comps) {
587 FX_Free(m_pCompData); 581 FX_Free(m_pCompData);
588 m_nComponents = comps; 582 m_nComponents = comps;
589 if (m_Family == PDFCS_LAB && m_nComponents != 3) { 583 if (m_Family == PDFCS_LAB && m_nComponents != 3) {
590 m_pCompData = NULL; 584 m_pCompData = NULL;
591 return 0; 585 return 0;
(...skipping 18 matching lines...) Expand all
610 if (!m_pCachedBitmap->Create(m_Width, m_Height, m_bImageMask ? FXDIB_1bp pMask : FXDIB_1bppRgb)) { 604 if (!m_pCachedBitmap->Create(m_Width, m_Height, m_bImageMask ? FXDIB_1bp pMask : FXDIB_1bppRgb)) {
611 delete m_pCachedBitmap; 605 delete m_pCachedBitmap;
612 m_pCachedBitmap = NULL; 606 m_pCachedBitmap = NULL;
613 return 0; 607 return 0;
614 } 608 }
615 m_Status = 1; 609 m_Status = 1;
616 return 2; 610 return 2;
617 } else if (decoder == FX_BSTRC("RunLengthDecode")) { 611 } else if (decoder == FX_BSTRC("RunLengthDecode")) {
618 m_pDecoder = CPDF_ModuleMgr::Get()->GetCodecModule()->GetBasicModule()-> CreateRunLengthDecoder(src_data, src_size, m_Width, m_Height, m_nComponents, m_b pc); 612 m_pDecoder = CPDF_ModuleMgr::Get()->GetCodecModule()->GetBasicModule()-> CreateRunLengthDecoder(src_data, src_size, m_Width, m_Height, m_nComponents, m_b pc);
619 } 613 }
620 if (m_pDecoder) { 614 if (!m_pDecoder)
621 FX_SAFE_DWORD requested_pitch = m_bpc; 615 return 0;
622 requested_pitch *= m_nComponents; 616
623 requested_pitch *= m_Width; 617 FX_SAFE_DWORD requested_pitch =
624 requested_pitch += 7; 618 CalculatePitch8(m_bpc, m_nComponents, m_Width, 1);
625 requested_pitch /= 8; 619 if (!requested_pitch.IsValid()) {
626 if (!requested_pitch.IsValid()) { 620 return 0;
627 return 0;
628 }
629 FX_SAFE_DWORD provided_pitch = m_pDecoder->GetBPC();
630 provided_pitch *= m_pDecoder->CountComps();
631 provided_pitch *= m_pDecoder->GetWidth();
632 provided_pitch += 7;
633 provided_pitch /= 8;
634 if (!provided_pitch.IsValid()) {
635 return 0;
636 }
637 if (provided_pitch.ValueOrDie() < requested_pitch.ValueOrDie()) {
638 return 0;
639 }
640 return 1;
641 } 621 }
642 return 0; 622 FX_SAFE_DWORD provided_pitch = CalculatePitch8(m_pDecoder->GetBPC(),
623 m_pDecoder->CountComps(),
624 m_pDecoder->GetWidth(),
625 1);
626 if (!provided_pitch.IsValid()) {
627 return 0;
628 }
629 if (provided_pitch.ValueOrDie() < requested_pitch.ValueOrDie()) {
630 return 0;
631 }
632 return 1;
643 } 633 }
644 void CPDF_DIBSource::LoadJpxBitmap() 634 void CPDF_DIBSource::LoadJpxBitmap()
645 { 635 {
646 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule(); 636 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule();
647 if (pJpxModule == NULL) { 637 if (pJpxModule == NULL) {
648 return; 638 return;
649 } 639 }
650 FX_LPVOID ctx = pJpxModule->CreateDecoder(m_pStreamAcc->GetData(), m_pStream Acc->GetSize(), m_pColorSpace != NULL); 640 FX_LPVOID ctx = pJpxModule->CreateDecoder(m_pStreamAcc->GetData(), m_pStream Acc->GetSize(), m_pColorSpace != NULL);
651 if (ctx == NULL) { 641 if (ctx == NULL) {
652 return; 642 return;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 for (FX_DWORD row = 0; row < height; row ++) { 712 for (FX_DWORD row = 0; row < height; row ++) {
723 FX_LPBYTE scanline = (FX_LPBYTE)m_pCachedBitmap->GetScanline(row); 713 FX_LPBYTE scanline = (FX_LPBYTE)m_pCachedBitmap->GetScanline(row);
724 for (FX_DWORD col = 0; col < width; col ++) { 714 for (FX_DWORD col = 0; col < width; col ++) {
725 *scanline = (*scanline) >> scale; 715 *scanline = (*scanline) >> scale;
726 scanline++; 716 scanline++;
727 } 717 }
728 } 718 }
729 } 719 }
730 m_bpc = 8; 720 m_bpc = 8;
731 } 721 }
732 void CPDF_DIBSource::LoadJbig2Bitmap()
733 {
734 ICodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module();
735 if (pJbig2Module == NULL) {
736 return;
737 }
738 CPDF_StreamAcc* pGlobalStream = NULL;
739 if (m_pStreamAcc->GetImageParam()) {
740 CPDF_Stream* pGlobals = m_pStreamAcc->GetImageParam()->GetStream(FX_BSTR C("JBIG2Globals"));
741 if (pGlobals) {
742 pGlobalStream = FX_NEW CPDF_StreamAcc;
743 pGlobalStream->LoadAllData(pGlobals, FALSE);
744 }
745 }
746 m_pCachedBitmap = FX_NEW CFX_DIBitmap;
747 if (!m_pCachedBitmap->Create(m_Width, m_Height, m_bImageMask ? FXDIB_1bppMas k : FXDIB_1bppRgb)) {
748 return;
749 }
750 int ret = pJbig2Module->Decode(m_Width, m_Height, m_pStreamAcc->GetData(), m _pStreamAcc->GetSize(),
751 pGlobalStream ? pGlobalStream->GetData() : NU LL, pGlobalStream ? pGlobalStream->GetSize() : 0,
752 m_pCachedBitmap->GetBuffer(), m_pCachedBitmap ->GetPitch());
753 if (ret < 0) {
754 delete m_pCachedBitmap;
755 m_pCachedBitmap = NULL;
756 }
757 if (pGlobalStream) {
758 delete pGlobalStream;
759 }
760 m_bpc = 1;
761 m_nComponents = 1;
762 }
763 CPDF_DIBSource* CPDF_DIBSource::LoadMask(FX_DWORD& MatteColor) 722 CPDF_DIBSource* CPDF_DIBSource::LoadMask(FX_DWORD& MatteColor)
764 { 723 {
765 MatteColor = 0xffffffff; 724 MatteColor = 0xffffffff;
766 CPDF_Stream* pSoftMask = m_pDict->GetStream(FX_BSTRC("SMask")); 725 CPDF_Stream* pSoftMask = m_pDict->GetStream(FX_BSTRC("SMask"));
767 if (pSoftMask) { 726 if (pSoftMask) {
768 CPDF_Array* pMatte = pSoftMask->GetDict()->GetArray(FX_BSTRC("Matte")); 727 CPDF_Array* pMatte = pSoftMask->GetDict()->GetArray(FX_BSTRC("Matte"));
769 if (pMatte != NULL && m_pColorSpace && (FX_DWORD)m_pColorSpace->CountCom ponents() <= m_nComponents) { 728 if (pMatte != NULL && m_pColorSpace && (FX_DWORD)m_pColorSpace->CountCom ponents() <= m_nComponents) {
770 FX_FLOAT* pColor = FX_Alloc(FX_FLOAT, m_nComponents); 729 FX_FLOAT* pColor = FX_Alloc(FX_FLOAT, m_nComponents);
771 for (FX_DWORD i = 0; i < m_nComponents; i ++) { 730 for (FX_DWORD i = 0; i < m_nComponents; i ++) {
772 pColor[i] = pMatte->GetFloat(i); 731 pColor[i] = pMatte->GetFloat(i);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 if (m_pCachedBitmap) { 1035 if (m_pCachedBitmap) {
1077 return m_pCachedBitmap->GetBuffer(); 1036 return m_pCachedBitmap->GetBuffer();
1078 } 1037 }
1079 return NULL; 1038 return NULL;
1080 } 1039 }
1081 FX_LPCBYTE CPDF_DIBSource::GetScanline(int line) const 1040 FX_LPCBYTE CPDF_DIBSource::GetScanline(int line) const
1082 { 1041 {
1083 if (m_bpc == 0) { 1042 if (m_bpc == 0) {
1084 return NULL; 1043 return NULL;
1085 } 1044 }
1086 FX_SAFE_DWORD src_pitch = m_Width; 1045 FX_SAFE_DWORD src_pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width, 1);
1087 src_pitch *= m_bpc;
1088 src_pitch *= m_nComponents;
1089 src_pitch += 7;
1090 src_pitch /= 8;
1091 if (!src_pitch.IsValid()) 1046 if (!src_pitch.IsValid())
1092 return NULL; 1047 return NULL;
1093 FX_DWORD src_pitch_value = src_pitch.ValueOrDie(); 1048 FX_DWORD src_pitch_value = src_pitch.ValueOrDie();
1094 FX_LPCBYTE pSrcLine = NULL; 1049 FX_LPCBYTE pSrcLine = NULL;
1095 if (m_pCachedBitmap) { 1050 if (m_pCachedBitmap) {
1096 if (line >= m_pCachedBitmap->GetHeight()) { 1051 if (line >= m_pCachedBitmap->GetHeight()) {
1097 line = m_pCachedBitmap->GetHeight() - 1; 1052 line = m_pCachedBitmap->GetHeight() - 1;
1098 } 1053 }
1099 pSrcLine = m_pCachedBitmap->GetScanline(line); 1054 pSrcLine = m_pCachedBitmap->GetScanline(line);
1100 } else if (m_pDecoder) { 1055 } else if (m_pDecoder) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 } 1171 }
1217 void CPDF_DIBSource::DownSampleScanline(int line, FX_LPBYTE dest_scan, int dest_ bpp, 1172 void CPDF_DIBSource::DownSampleScanline(int line, FX_LPBYTE dest_scan, int dest_ bpp,
1218 int dest_width, FX_BOOL bFlipX, int clip _left, int clip_width) const 1173 int dest_width, FX_BOOL bFlipX, int clip _left, int clip_width) const
1219 { 1174 {
1220 if (line < 0 || dest_scan == NULL || dest_bpp <= 0 || 1175 if (line < 0 || dest_scan == NULL || dest_bpp <= 0 ||
1221 dest_width <= 0 || clip_left < 0 || clip_width <= 0) { 1176 dest_width <= 0 || clip_left < 0 || clip_width <= 0) {
1222 return; 1177 return;
1223 } 1178 }
1224 1179
1225 FX_DWORD src_width = m_Width; 1180 FX_DWORD src_width = m_Width;
1226 FX_SAFE_DWORD pitch = src_width; 1181 FX_SAFE_DWORD pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width, 1);
1227 pitch *= m_bpc; 1182 if (!pitch.IsValid()) {
1228 pitch *= m_nComponents;
1229 pitch += 7;
1230 pitch /= 8;
1231 if (!pitch.IsValid()) {
1232 return; 1183 return;
1233 } 1184 }
1234 1185
1235 FX_LPCBYTE pSrcLine = NULL; 1186 FX_LPCBYTE pSrcLine = NULL;
1236 if (m_pCachedBitmap) { 1187 if (m_pCachedBitmap) {
1237 pSrcLine = m_pCachedBitmap->GetScanline(line); 1188 pSrcLine = m_pCachedBitmap->GetScanline(line);
1238 } else if (m_pDecoder) { 1189 } else if (m_pDecoder) {
1239 pSrcLine = m_pDecoder->GetScanline(line); 1190 pSrcLine = m_pDecoder->GetScanline(line);
1240 } else { 1191 } else {
1241 FX_DWORD src_pitch = pitch.ValueOrDie(); 1192 FX_DWORD src_pitch = pitch.ValueOrDie();
1242 pitch *= (line+1); 1193 pitch *= (line+1);
1243 if (!pitch.IsValid()) { 1194 if (!pitch.IsValid()) {
1244 return; 1195 return;
1245 } 1196 }
1246 1197
1247 if (m_pStreamAcc->GetSize() >= pitch.ValueOrDie()) { 1198 if (m_pStreamAcc->GetSize() >= pitch.ValueOrDie()) {
1248 pSrcLine = m_pStreamAcc->GetData() + line * src_pitch; 1199 pSrcLine = m_pStreamAcc->GetData() + line * src_pitch;
1249 } 1200 }
1250 } 1201 }
1251 int orig_Bpp = m_bpc * m_nComponents / 8; 1202 int orig_Bpp = m_bpc * m_nComponents / 8;
1252 int dest_Bpp = dest_bpp / 8; 1203 int dest_Bpp = dest_bpp / 8;
1253 if (pSrcLine == NULL) { 1204 if (pSrcLine == NULL) {
1254 FXSYS_memset32(dest_scan, 0xff, dest_Bpp * clip_width); 1205 FXSYS_memset32(dest_scan, 0xff, dest_Bpp * clip_width);
1255 return; 1206 return;
1256 } 1207 }
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 } 1425 }
1475 } 1426 }
1476 CPDF_ProgressiveImageLoaderHandle::CPDF_ProgressiveImageLoaderHandle() 1427 CPDF_ProgressiveImageLoaderHandle::CPDF_ProgressiveImageLoaderHandle()
1477 { 1428 {
1478 m_pImageLoader = NULL; 1429 m_pImageLoader = NULL;
1479 m_pCache = NULL; 1430 m_pCache = NULL;
1480 m_pImage = NULL; 1431 m_pImage = NULL;
1481 } 1432 }
1482 CPDF_ProgressiveImageLoaderHandle::~CPDF_ProgressiveImageLoaderHandle() 1433 CPDF_ProgressiveImageLoaderHandle::~CPDF_ProgressiveImageLoaderHandle()
1483 { 1434 {
1484 m_pImageLoader = NULL;
1485 m_pCache = NULL;
1486 m_pImage = NULL;
1487 } 1435 }
1488 FX_BOOL CPDF_ProgressiveImageLoaderHandle::Start(CPDF_ImageLoader* pImageLoader, const CPDF_ImageObject* pImage, CPDF_PageRenderCache* pCache, FX_BOOL bStdCS, F X_DWORD GroupFamily, FX_BOOL bLoadMask, CPDF_RenderStatus* pRenderStatus, FX_INT 32 nDownsampleWidth, FX_INT32 nDownsampleHeight) 1436 FX_BOOL CPDF_ProgressiveImageLoaderHandle::Start(CPDF_ImageLoader* pImageLoader, const CPDF_ImageObject* pImage, CPDF_PageRenderCache* pCache, FX_BOOL bStdCS, F X_DWORD GroupFamily, FX_BOOL bLoadMask, CPDF_RenderStatus* pRenderStatus, FX_INT 32 nDownsampleWidth, FX_INT32 nDownsampleHeight)
1489 { 1437 {
1490 m_pImageLoader = pImageLoader; 1438 m_pImageLoader = pImageLoader;
1491 m_pCache = pCache; 1439 m_pCache = pCache;
1492 m_pImage = (CPDF_ImageObject*)pImage; 1440 m_pImage = (CPDF_ImageObject*)pImage;
1493 m_nDownsampleWidth = nDownsampleWidth; 1441 m_nDownsampleWidth = nDownsampleWidth;
1494 m_nDownsampleHeight = nDownsampleHeight; 1442 m_nDownsampleHeight = nDownsampleHeight;
1495 FX_BOOL ret; 1443 FX_BOOL ret;
1496 if (pCache) { 1444 if (pCache) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 LoadHandle = pLoaderHandle; 1506 LoadHandle = pLoaderHandle;
1559 return ret; 1507 return ret;
1560 } 1508 }
1561 FX_BOOL CPDF_ImageLoader::Continue(FX_LPVOID LoadHandle, IFX_Pause* pPause) 1509 FX_BOOL CPDF_ImageLoader::Continue(FX_LPVOID LoadHandle, IFX_Pause* pPause)
1562 { 1510 {
1563 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause); 1511 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause);
1564 } 1512 }
1565 CPDF_ImageLoader::~CPDF_ImageLoader() 1513 CPDF_ImageLoader::~CPDF_ImageLoader()
1566 { 1514 {
1567 if (!m_bCached) { 1515 if (!m_bCached) {
1568 if (m_pBitmap) { 1516 delete m_pBitmap;
1569 delete m_pBitmap; 1517 delete m_pMask;
1570 m_pBitmap = NULL;
1571 }
1572 if (m_pMask) {
1573 delete m_pMask;
1574 }
1575 } 1518 }
1576 } 1519 }
OLDNEW
« no previous file with comments | « no previous file | core/src/fpdfapi/fpdf_render/render_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698