| 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 "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" | 7 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" |
| 8 | 8 |
| 9 #include <limits.h> | 9 #include <limits.h> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 for (int i = 0; i < srclen; i++) { | 525 for (int i = 0; i < srclen; i++) { |
| 526 result.AppendChar("0123456789ABCDEF"[src[i] / 16]); | 526 result.AppendChar("0123456789ABCDEF"[src[i] / 16]); |
| 527 result.AppendChar("0123456789ABCDEF"[src[i] % 16]); | 527 result.AppendChar("0123456789ABCDEF"[src[i] % 16]); |
| 528 } | 528 } |
| 529 result.AppendChar('>'); | 529 result.AppendChar('>'); |
| 530 return result.MakeString(); | 530 return result.MakeString(); |
| 531 } | 531 } |
| 532 result.AppendChar('('); | 532 result.AppendChar('('); |
| 533 for (int i = 0; i < srclen; i++) { | 533 for (int i = 0; i < srclen; i++) { |
| 534 uint8_t ch = src[i]; | 534 uint8_t ch = src[i]; |
| 535 if (ch == ')' || ch == '\\' || ch == '(') { | 535 if (ch == 0x0a) { |
| 536 result.AppendChar('\\'); | |
| 537 } else if (ch == 0x0a) { | |
| 538 result << "\\n"; | 536 result << "\\n"; |
| 539 continue; | 537 continue; |
| 540 } else if (ch == 0x0d) { | 538 } |
| 539 if (ch == 0x0d) { |
| 541 result << "\\r"; | 540 result << "\\r"; |
| 542 continue; | 541 continue; |
| 543 } | 542 } |
| 543 if (ch == ')' || ch == '\\' || ch == '(') |
| 544 result.AppendChar('\\'); |
| 544 result.AppendChar(ch); | 545 result.AppendChar(ch); |
| 545 } | 546 } |
| 546 result.AppendChar(')'); | 547 result.AppendChar(')'); |
| 547 return result.MakeString(); | 548 return result.MakeString(); |
| 548 } | 549 } |
| 549 | 550 |
| 550 void FlateEncode(const uint8_t* src_buf, | 551 bool FlateEncode(const uint8_t* src_buf, |
| 551 uint32_t src_size, | 552 uint32_t src_size, |
| 552 uint8_t*& dest_buf, | 553 uint8_t** dest_buf, |
| 553 uint32_t& dest_size) { | 554 uint32_t* dest_size) { |
| 554 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 555 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
| 555 if (pEncoders) { | 556 return pEncoders && |
| 556 pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, dest_size); | 557 pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, |
| 557 } | 558 dest_size); |
| 558 } | 559 } |
| 559 | 560 |
| 560 void FlateEncode(const uint8_t* src_buf, | 561 bool PngEncode(const uint8_t* src_buf, |
| 561 uint32_t src_size, | 562 uint32_t src_size, |
| 562 int predictor, | 563 uint8_t** dest_buf, |
| 563 int Colors, | 564 uint32_t* dest_size) { |
| 564 int BitsPerComponent, | |
| 565 int Columns, | |
| 566 uint8_t*& dest_buf, | |
| 567 uint32_t& dest_size) { | |
| 568 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 565 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
| 569 if (pEncoders) { | 566 return pEncoders && |
| 570 pEncoders->GetFlateModule()->Encode(src_buf, src_size, predictor, Colors, | 567 pEncoders->GetFlateModule()->PngEncode(src_buf, src_size, dest_buf, |
| 571 BitsPerComponent, Columns, dest_buf, | 568 dest_size); |
| 572 dest_size); | |
| 573 } | |
| 574 } | 569 } |
| 575 | 570 |
| 576 uint32_t FlateDecode(const uint8_t* src_buf, | 571 uint32_t FlateDecode(const uint8_t* src_buf, |
| 577 uint32_t src_size, | 572 uint32_t src_size, |
| 578 uint8_t*& dest_buf, | 573 uint8_t*& dest_buf, |
| 579 uint32_t& dest_size) { | 574 uint32_t& dest_size) { |
| 580 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 575 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
| 581 if (pEncoders) { | 576 if (pEncoders) { |
| 582 return pEncoders->GetFlateModule()->FlateOrLZWDecode( | 577 return pEncoders->GetFlateModule()->FlateOrLZWDecode( |
| 583 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); |
| 584 } | 579 } |
| 585 return 0; | 580 return 0; |
| 586 } | 581 } |
| OLD | NEW |