| OLD | NEW |
| 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 | 8 |
| 9 #include "core/include/fpdfapi/fpdf_module.h" | 9 #include "core/include/fpdfapi/fpdf_module.h" |
| 10 #include "core/include/fpdfapi/fpdf_parser.h" | 10 #include "core/include/fpdfapi/fpdf_parser.h" |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 | 328 |
| 329 { | 329 { |
| 330 CPDF_Object* pDecoder = | 330 CPDF_Object* pDecoder = |
| 331 pDict ? pDict->GetElementValue(FX_BSTRC("Filter")) : nullptr; | 331 pDict ? pDict->GetElementValue(FX_BSTRC("Filter")) : nullptr; |
| 332 if (!pDecoder || (!pDecoder->IsArray() && !pDecoder->IsName())) | 332 if (!pDecoder || (!pDecoder->IsArray() && !pDecoder->IsName())) |
| 333 return FALSE; | 333 return FALSE; |
| 334 | 334 |
| 335 CPDF_Object* pParams = | 335 CPDF_Object* pParams = |
| 336 pDict ? pDict->GetElementValue(FX_BSTRC("DecodeParms")) : nullptr; | 336 pDict ? pDict->GetElementValue(FX_BSTRC("DecodeParms")) : nullptr; |
| 337 CFX_ByteStringArray DecoderList; | 337 CFX_ByteStringArray DecoderList; |
| 338 CFX_PtrArray ParamList; | 338 CFX_ArrayTemplate<CPDF_Object*> ParamList; |
| 339 if (CPDF_Array* pDecoders = pDecoder->AsArray()) { | 339 if (CPDF_Array* pDecoders = pDecoder->AsArray()) { |
| 340 CPDF_Array* pParamsArray = ToArray(pParams); | 340 CPDF_Array* pParamsArray = ToArray(pParams); |
| 341 if (!pParamsArray) | 341 if (!pParamsArray) |
| 342 pParams = nullptr; | 342 pParams = nullptr; |
| 343 | 343 |
| 344 for (FX_DWORD i = 0; i < pDecoders->GetCount(); i++) { | 344 for (FX_DWORD i = 0; i < pDecoders->GetCount(); i++) { |
| 345 CFX_ByteStringC str = pDecoders->GetConstString(i); | 345 CFX_ByteStringC str = pDecoders->GetConstString(i); |
| 346 DecoderList.Add(str); | 346 DecoderList.Add(str); |
| 347 ParamList.Add(pParams ? pParamsArray->GetDict(i) : nullptr); | 347 ParamList.Add(pParams ? pParamsArray->GetDict(i) : nullptr); |
| 348 } | 348 } |
| 349 } else { | 349 } else { |
| 350 DecoderList.Add(pDecoder->GetConstString()); | 350 DecoderList.Add(pDecoder->GetConstString()); |
| 351 ParamList.Add(pParams ? pParams->GetDict() : nullptr); | 351 ParamList.Add(pParams ? pParams->GetDict() : nullptr); |
| 352 } | 352 } |
| 353 uint8_t* last_buf = (uint8_t*)src_buf; | 353 uint8_t* last_buf = (uint8_t*)src_buf; |
| 354 FX_DWORD last_size = src_size; | 354 FX_DWORD last_size = src_size; |
| 355 for (int i = 0; i < DecoderList.GetSize(); i++) { | 355 for (int i = 0; i < DecoderList.GetSize(); i++) { |
| 356 int estimated_size = | 356 int estimated_size = |
| 357 i == DecoderList.GetSize() - 1 ? last_estimated_size : 0; | 357 i == DecoderList.GetSize() - 1 ? last_estimated_size : 0; |
| 358 CFX_ByteString decoder = DecoderList[i]; | 358 CFX_ByteString decoder = DecoderList[i]; |
| 359 // Use ToDictionary here because we can push NULL into the ParamList. | 359 // Use ToDictionary here because we can push NULL into the ParamList. |
| 360 CPDF_Dictionary* pParam = | 360 CPDF_Dictionary* pParam = ToDictionary(ParamList[i]); |
| 361 ToDictionary(static_cast<CPDF_Object*>(ParamList[i])); | |
| 362 uint8_t* new_buf = nullptr; | 361 uint8_t* new_buf = nullptr; |
| 363 FX_DWORD new_size = (FX_DWORD)-1; | 362 FX_DWORD new_size = (FX_DWORD)-1; |
| 364 int offset = -1; | 363 int offset = -1; |
| 365 if (decoder == FX_BSTRC("FlateDecode") || decoder == FX_BSTRC("Fl")) { | 364 if (decoder == FX_BSTRC("FlateDecode") || decoder == FX_BSTRC("Fl")) { |
| 366 if (bImageAcc && i == DecoderList.GetSize() - 1) { | 365 if (bImageAcc && i == DecoderList.GetSize() - 1) { |
| 367 ImageEncoding = FX_BSTRC("FlateDecode"); | 366 ImageEncoding = FX_BSTRC("FlateDecode"); |
| 368 dest_buf = (uint8_t*)last_buf; | 367 dest_buf = (uint8_t*)last_buf; |
| 369 dest_size = last_size; | 368 dest_size = last_size; |
| 370 pImageParms = pParam; | 369 pImageParms = pParam; |
| 371 return TRUE; | 370 return TRUE; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 FX_DWORD src_size, | 572 FX_DWORD src_size, |
| 574 uint8_t*& dest_buf, | 573 uint8_t*& dest_buf, |
| 575 FX_DWORD& dest_size) { | 574 FX_DWORD& dest_size) { |
| 576 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 575 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
| 577 if (pEncoders) { | 576 if (pEncoders) { |
| 578 return pEncoders->GetFlateModule()->FlateOrLZWDecode( | 577 return pEncoders->GetFlateModule()->FlateOrLZWDecode( |
| 579 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); | 578 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); |
| 580 } | 579 } |
| 581 return 0; | 580 return 0; |
| 582 } | 581 } |
| OLD | NEW |