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

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp

Issue 1410343003: [Merge to XFA] Revert "Revert "Add type cast definitions for CPDF_Dictionary."" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Rebase to origin/xfa Created 5 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 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 <limits.h> 7 #include <limits.h>
8 #include "../../../include/fpdfapi/fpdf_parser.h" 8 #include "../../../include/fpdfapi/fpdf_parser.h"
9 #include "../../../include/fpdfapi/fpdf_module.h" 9 #include "../../../include/fpdfapi/fpdf_module.h"
10 #include "../../../include/fxcodec/fx_codec.h" 10 #include "../../../include/fxcodec/fx_codec.h"
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 const uint8_t* src_buf, 276 const uint8_t* src_buf,
277 FX_DWORD src_size, 277 FX_DWORD src_size,
278 int width, 278 int width,
279 int height, 279 int height,
280 int nComps, 280 int nComps,
281 int bpc, 281 int bpc,
282 const CPDF_Dictionary* pParams) { 282 const CPDF_Dictionary* pParams) {
283 int predictor = 0; 283 int predictor = 0;
284 int Colors = 0, BitsPerComponent = 0, Columns = 0; 284 int Colors = 0, BitsPerComponent = 0, Columns = 0;
285 if (pParams) { 285 if (pParams) {
286 predictor = ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("Predictor")); 286 predictor = pParams->GetInteger(FX_BSTRC("Predictor"));
287 Colors = pParams->GetInteger(FX_BSTRC("Colors"), 1); 287 Colors = pParams->GetInteger(FX_BSTRC("Colors"), 1);
288 BitsPerComponent = pParams->GetInteger(FX_BSTRC("BitsPerComponent"), 8); 288 BitsPerComponent = pParams->GetInteger(FX_BSTRC("BitsPerComponent"), 8);
289 Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1); 289 Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1);
290 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) { 290 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) {
291 return NULL; 291 return NULL;
292 } 292 }
293 } 293 }
294 return CPDF_ModuleMgr::Get()->GetFlateModule()->CreateDecoder( 294 return CPDF_ModuleMgr::Get()->GetFlateModule()->CreateDecoder(
295 src_buf, src_size, width, height, nComps, bpc, predictor, Colors, 295 src_buf, src_size, width, height, nComps, bpc, predictor, Colors,
296 BitsPerComponent, Columns); 296 BitsPerComponent, Columns);
297 } 297 }
298 FX_DWORD FPDFAPI_FlateOrLZWDecode(FX_BOOL bLZW, 298 FX_DWORD FPDFAPI_FlateOrLZWDecode(FX_BOOL bLZW,
299 const uint8_t* src_buf, 299 const uint8_t* src_buf,
300 FX_DWORD src_size, 300 FX_DWORD src_size,
301 CPDF_Dictionary* pParams, 301 CPDF_Dictionary* pParams,
302 FX_DWORD estimated_size, 302 FX_DWORD estimated_size,
303 uint8_t*& dest_buf, 303 uint8_t*& dest_buf,
304 FX_DWORD& dest_size) { 304 FX_DWORD& dest_size) {
305 int predictor = 0; 305 int predictor = 0;
306 FX_BOOL bEarlyChange = TRUE; 306 FX_BOOL bEarlyChange = TRUE;
307 int Colors = 0, BitsPerComponent = 0, Columns = 0; 307 int Colors = 0, BitsPerComponent = 0, Columns = 0;
308 if (pParams) { 308 if (pParams) {
309 predictor = ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("Predictor")); 309 predictor = pParams->GetInteger(FX_BSTRC("Predictor"));
310 bEarlyChange = 310 bEarlyChange = pParams->GetInteger(FX_BSTRC("EarlyChange"), 1);
311 ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("EarlyChange"), 1);
312 Colors = pParams->GetInteger(FX_BSTRC("Colors"), 1); 311 Colors = pParams->GetInteger(FX_BSTRC("Colors"), 1);
313 BitsPerComponent = pParams->GetInteger(FX_BSTRC("BitsPerComponent"), 8); 312 BitsPerComponent = pParams->GetInteger(FX_BSTRC("BitsPerComponent"), 8);
314 Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1); 313 Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1);
315 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) { 314 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) {
316 return (FX_DWORD)-1; 315 return (FX_DWORD)-1;
317 } 316 }
318 } 317 }
319 return CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode( 318 return CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode(
320 bLZW, src_buf, src_size, bEarlyChange, predictor, Colors, 319 bLZW, src_buf, src_size, bEarlyChange, predictor, Colors,
321 BitsPerComponent, Columns, estimated_size, dest_buf, dest_size); 320 BitsPerComponent, Columns, estimated_size, dest_buf, dest_size);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } else { 357 } else {
359 DecoderList.Add(pDecoder->GetConstString()); 358 DecoderList.Add(pDecoder->GetConstString());
360 ParamList.Add(pParams ? pParams->GetDict() : NULL); 359 ParamList.Add(pParams ? pParams->GetDict() : NULL);
361 } 360 }
362 uint8_t* last_buf = (uint8_t*)src_buf; 361 uint8_t* last_buf = (uint8_t*)src_buf;
363 FX_DWORD last_size = src_size; 362 FX_DWORD last_size = src_size;
364 for (int i = 0; i < DecoderList.GetSize(); i++) { 363 for (int i = 0; i < DecoderList.GetSize(); i++) {
365 int estimated_size = 364 int estimated_size =
366 i == DecoderList.GetSize() - 1 ? last_estimated_size : 0; 365 i == DecoderList.GetSize() - 1 ? last_estimated_size : 0;
367 CFX_ByteString decoder = DecoderList[i]; 366 CFX_ByteString decoder = DecoderList[i];
368 CPDF_Dictionary* pParam = (CPDF_Dictionary*)ParamList[i]; 367 // Use ToDictionary here because we can push NULL into the ParamList.
368 CPDF_Dictionary* pParam =
369 ToDictionary(static_cast<CPDF_Object*>(ParamList[i]));
369 uint8_t* new_buf = NULL; 370 uint8_t* new_buf = NULL;
370 FX_DWORD new_size = (FX_DWORD)-1; 371 FX_DWORD new_size = (FX_DWORD)-1;
371 int offset = -1; 372 int offset = -1;
372 if (decoder == FX_BSTRC("FlateDecode") || decoder == FX_BSTRC("Fl")) { 373 if (decoder == FX_BSTRC("FlateDecode") || decoder == FX_BSTRC("Fl")) {
373 if (bImageAcc && i == DecoderList.GetSize() - 1) { 374 if (bImageAcc && i == DecoderList.GetSize() - 1) {
374 ImageEncoding = FX_BSTRC("FlateDecode"); 375 ImageEncoding = FX_BSTRC("FlateDecode");
375 dest_buf = (uint8_t*)last_buf; 376 dest_buf = (uint8_t*)last_buf;
376 dest_size = last_size; 377 dest_size = last_size;
377 pImageParms = pParam; 378 pImageParms = pParam;
378 return TRUE; 379 return TRUE;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 FX_DWORD src_size, 578 FX_DWORD src_size,
578 uint8_t*& dest_buf, 579 uint8_t*& dest_buf,
579 FX_DWORD& dest_size) { 580 FX_DWORD& dest_size) {
580 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); 581 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule();
581 if (pEncoders) { 582 if (pEncoders) {
582 return pEncoders->GetFlateModule()->FlateOrLZWDecode( 583 return pEncoders->GetFlateModule()->FlateOrLZWDecode(
583 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); 584 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size);
584 } 585 }
585 return 0; 586 return 0;
586 } 587 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698