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