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/fxcodec/codec/codec_int.h" | 7 #include "core/fxcodec/codec/codec_int.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 uint8_t* m_pPredictRaw; | 641 uint8_t* m_pPredictRaw; |
642 int m_Predictor; | 642 int m_Predictor; |
643 int m_Colors; | 643 int m_Colors; |
644 int m_BitsPerComponent; | 644 int m_BitsPerComponent; |
645 int m_Columns; | 645 int m_Columns; |
646 uint32_t m_PredictPitch; | 646 uint32_t m_PredictPitch; |
647 size_t m_LeftOver; | 647 size_t m_LeftOver; |
648 }; | 648 }; |
649 | 649 |
650 CCodec_FlateScanlineDecoder::CCodec_FlateScanlineDecoder() { | 650 CCodec_FlateScanlineDecoder::CCodec_FlateScanlineDecoder() { |
651 m_pFlate = NULL; | 651 m_pFlate = nullptr; |
652 m_pScanline = NULL; | 652 m_pScanline = nullptr; |
653 m_pLastLine = NULL; | 653 m_pLastLine = nullptr; |
654 m_pPredictBuffer = NULL; | 654 m_pPredictBuffer = nullptr; |
655 m_pPredictRaw = NULL; | 655 m_pPredictRaw = nullptr; |
656 m_LeftOver = 0; | 656 m_LeftOver = 0; |
657 } | 657 } |
658 CCodec_FlateScanlineDecoder::~CCodec_FlateScanlineDecoder() { | 658 CCodec_FlateScanlineDecoder::~CCodec_FlateScanlineDecoder() { |
659 FX_Free(m_pScanline); | 659 FX_Free(m_pScanline); |
660 FX_Free(m_pLastLine); | 660 FX_Free(m_pLastLine); |
661 FX_Free(m_pPredictBuffer); | 661 FX_Free(m_pPredictBuffer); |
662 FX_Free(m_pPredictRaw); | 662 FX_Free(m_pPredictRaw); |
663 if (m_pFlate) { | 663 if (m_pFlate) { |
664 FPDFAPI_FlateEnd(m_pFlate); | 664 FPDFAPI_FlateEnd(m_pFlate); |
665 } | 665 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 const uint8_t* src_buf, | 792 const uint8_t* src_buf, |
793 uint32_t src_size, | 793 uint32_t src_size, |
794 FX_BOOL bEarlyChange, | 794 FX_BOOL bEarlyChange, |
795 int predictor, | 795 int predictor, |
796 int Colors, | 796 int Colors, |
797 int BitsPerComponent, | 797 int BitsPerComponent, |
798 int Columns, | 798 int Columns, |
799 uint32_t estimated_size, | 799 uint32_t estimated_size, |
800 uint8_t*& dest_buf, | 800 uint8_t*& dest_buf, |
801 uint32_t& dest_size) { | 801 uint32_t& dest_size) { |
802 dest_buf = NULL; | 802 dest_buf = nullptr; |
803 uint32_t offset = 0; | 803 uint32_t offset = 0; |
804 int predictor_type = 0; | 804 int predictor_type = 0; |
805 if (predictor) { | 805 if (predictor) { |
806 if (predictor >= 10) { | 806 if (predictor >= 10) { |
807 predictor_type = 2; | 807 predictor_type = 2; |
808 } else if (predictor == 2) { | 808 } else if (predictor == 2) { |
809 predictor_type = 1; | 809 predictor_type = 1; |
810 } | 810 } |
811 } | 811 } |
812 if (bLZW) { | 812 if (bLZW) { |
813 { | 813 { |
814 std::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder); | 814 std::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder); |
815 dest_size = (uint32_t)-1; | 815 dest_size = (uint32_t)-1; |
816 offset = src_size; | 816 offset = src_size; |
817 int err = decoder->Decode(NULL, dest_size, src_buf, offset, bEarlyChange); | 817 int err = |
| 818 decoder->Decode(nullptr, dest_size, src_buf, offset, bEarlyChange); |
818 if (err || dest_size == 0 || dest_size + 1 < dest_size) { | 819 if (err || dest_size == 0 || dest_size + 1 < dest_size) { |
819 return FX_INVALID_OFFSET; | 820 return FX_INVALID_OFFSET; |
820 } | 821 } |
821 } | 822 } |
822 { | 823 { |
823 std::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder); | 824 std::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder); |
824 dest_buf = FX_Alloc(uint8_t, dest_size + 1); | 825 dest_buf = FX_Alloc(uint8_t, dest_size + 1); |
825 dest_buf[dest_size] = '\0'; | 826 dest_buf[dest_size] = '\0'; |
826 decoder->Decode(dest_buf, dest_size, src_buf, offset, bEarlyChange); | 827 decoder->Decode(dest_buf, dest_size, src_buf, offset, bEarlyChange); |
827 } | 828 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 uint32_t src_size, | 861 uint32_t src_size, |
861 uint8_t** dest_buf, | 862 uint8_t** dest_buf, |
862 uint32_t* dest_size) { | 863 uint32_t* dest_size) { |
863 uint8_t* pSrcBuf = FX_Alloc(uint8_t, src_size); | 864 uint8_t* pSrcBuf = FX_Alloc(uint8_t, src_size); |
864 FXSYS_memcpy(pSrcBuf, src_buf, src_size); | 865 FXSYS_memcpy(pSrcBuf, src_buf, src_size); |
865 PNG_PredictorEncode(&pSrcBuf, &src_size); | 866 PNG_PredictorEncode(&pSrcBuf, &src_size); |
866 bool ret = Encode(pSrcBuf, src_size, dest_buf, dest_size); | 867 bool ret = Encode(pSrcBuf, src_size, dest_buf, dest_size); |
867 FX_Free(pSrcBuf); | 868 FX_Free(pSrcBuf); |
868 return ret; | 869 return ret; |
869 } | 870 } |
OLD | NEW |