Chromium Code Reviews| 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 21 matching lines...) Expand all Loading... | |
| 32 static void FPDFAPI_FlateCompress(unsigned char* dest_buf, | 32 static void FPDFAPI_FlateCompress(unsigned char* dest_buf, |
| 33 unsigned long* dest_size, | 33 unsigned long* dest_size, |
| 34 const unsigned char* src_buf, | 34 const unsigned char* src_buf, |
| 35 unsigned long src_size) { | 35 unsigned long src_size) { |
| 36 compress(dest_buf, dest_size, src_buf, src_size); | 36 compress(dest_buf, dest_size, src_buf, src_size); |
| 37 } | 37 } |
| 38 void* FPDFAPI_FlateInit(void* (*alloc_func)(void*, unsigned int, unsigned int), | 38 void* FPDFAPI_FlateInit(void* (*alloc_func)(void*, unsigned int, unsigned int), |
| 39 void (*free_func)(void*, void*)) { | 39 void (*free_func)(void*, void*)) { |
| 40 z_stream* p = (z_stream*)alloc_func(0, 1, sizeof(z_stream)); | 40 z_stream* p = (z_stream*)alloc_func(0, 1, sizeof(z_stream)); |
| 41 if (!p) { | 41 if (!p) { |
| 42 return NULL; | 42 return nullptr; |
| 43 } | 43 } |
| 44 FXSYS_memset(p, 0, sizeof(z_stream)); | 44 FXSYS_memset(p, 0, sizeof(z_stream)); |
| 45 p->zalloc = alloc_func; | 45 p->zalloc = alloc_func; |
| 46 p->zfree = free_func; | 46 p->zfree = free_func; |
| 47 inflateInit(p); | 47 inflateInit(p); |
| 48 return p; | 48 return p; |
| 49 } | 49 } |
| 50 void FPDFAPI_FlateInput(void* context, | 50 void FPDFAPI_FlateInput(void* context, |
| 51 const unsigned char* src_buf, | 51 const unsigned char* src_buf, |
| 52 unsigned int src_size) { | 52 unsigned int src_size) { |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 765 uint8_t* m_pPredictRaw; | 765 uint8_t* m_pPredictRaw; |
| 766 int m_Predictor; | 766 int m_Predictor; |
| 767 int m_Colors; | 767 int m_Colors; |
| 768 int m_BitsPerComponent; | 768 int m_BitsPerComponent; |
| 769 int m_Columns; | 769 int m_Columns; |
| 770 uint32_t m_PredictPitch; | 770 uint32_t m_PredictPitch; |
| 771 size_t m_LeftOver; | 771 size_t m_LeftOver; |
| 772 }; | 772 }; |
| 773 | 773 |
| 774 CCodec_FlateScanlineDecoder::CCodec_FlateScanlineDecoder() { | 774 CCodec_FlateScanlineDecoder::CCodec_FlateScanlineDecoder() { |
| 775 m_pFlate = NULL; | 775 m_pFlate = nullptr; |
| 776 m_pScanline = NULL; | 776 m_pScanline = nullptr; |
| 777 m_pLastLine = NULL; | 777 m_pLastLine = nullptr; |
| 778 m_pPredictBuffer = NULL; | 778 m_pPredictBuffer = nullptr; |
| 779 m_pPredictRaw = NULL; | 779 m_pPredictRaw = nullptr; |
| 780 m_LeftOver = 0; | 780 m_LeftOver = 0; |
| 781 } | 781 } |
| 782 CCodec_FlateScanlineDecoder::~CCodec_FlateScanlineDecoder() { | 782 CCodec_FlateScanlineDecoder::~CCodec_FlateScanlineDecoder() { |
| 783 FX_Free(m_pScanline); | 783 FX_Free(m_pScanline); |
| 784 FX_Free(m_pLastLine); | 784 FX_Free(m_pLastLine); |
| 785 FX_Free(m_pPredictBuffer); | 785 FX_Free(m_pPredictBuffer); |
| 786 FX_Free(m_pPredictRaw); | 786 FX_Free(m_pPredictRaw); |
| 787 if (m_pFlate) { | 787 if (m_pFlate) { |
| 788 FPDFAPI_FlateEnd(m_pFlate); | 788 FPDFAPI_FlateEnd(m_pFlate); |
| 789 } | 789 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 916 const uint8_t* src_buf, | 916 const uint8_t* src_buf, |
| 917 uint32_t src_size, | 917 uint32_t src_size, |
| 918 FX_BOOL bEarlyChange, | 918 FX_BOOL bEarlyChange, |
| 919 int predictor, | 919 int predictor, |
| 920 int Colors, | 920 int Colors, |
| 921 int BitsPerComponent, | 921 int BitsPerComponent, |
| 922 int Columns, | 922 int Columns, |
| 923 uint32_t estimated_size, | 923 uint32_t estimated_size, |
| 924 uint8_t*& dest_buf, | 924 uint8_t*& dest_buf, |
| 925 uint32_t& dest_size) { | 925 uint32_t& dest_size) { |
| 926 dest_buf = NULL; | 926 dest_buf = nullptr; |
| 927 uint32_t offset = 0; | 927 uint32_t offset = 0; |
| 928 int predictor_type = 0; | 928 int predictor_type = 0; |
| 929 if (predictor) { | 929 if (predictor) { |
| 930 if (predictor >= 10) { | 930 if (predictor >= 10) { |
| 931 predictor_type = 2; | 931 predictor_type = 2; |
| 932 } else if (predictor == 2) { | 932 } else if (predictor == 2) { |
| 933 predictor_type = 1; | 933 predictor_type = 1; |
| 934 } | 934 } |
| 935 } | 935 } |
| 936 if (bLZW) { | 936 if (bLZW) { |
| 937 { | 937 { |
| 938 std::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder); | 938 std::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder); |
| 939 dest_size = (uint32_t)-1; | 939 dest_size = (uint32_t)-1; |
| 940 offset = src_size; | 940 offset = src_size; |
| 941 int err = decoder->Decode(NULL, dest_size, src_buf, offset, bEarlyChange); | 941 int err = |
| 942 decoder->Decode(nullptr, dest_size, src_buf, offset, bEarlyChange); | |
| 942 if (err || dest_size == 0 || dest_size + 1 < dest_size) { | 943 if (err || dest_size == 0 || dest_size + 1 < dest_size) { |
| 943 return FX_INVALID_OFFSET; | 944 return FX_INVALID_OFFSET; |
| 944 } | 945 } |
| 945 } | 946 } |
| 946 { | 947 { |
| 947 std::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder); | 948 std::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder); |
| 948 dest_buf = FX_Alloc(uint8_t, dest_size + 1); | 949 dest_buf = FX_Alloc(uint8_t, dest_size + 1); |
| 949 dest_buf[dest_size] = '\0'; | 950 dest_buf[dest_size] = '\0'; |
| 950 decoder->Decode(dest_buf, dest_size, src_buf, offset, bEarlyChange); | 951 decoder->Decode(dest_buf, dest_size, src_buf, offset, bEarlyChange); |
| 951 } | 952 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 969 uint32_t src_size, | 970 uint32_t src_size, |
| 970 int predictor, | 971 int predictor, |
| 971 int Colors, | 972 int Colors, |
| 972 int BitsPerComponent, | 973 int BitsPerComponent, |
| 973 int Columns, | 974 int Columns, |
| 974 uint8_t*& dest_buf, | 975 uint8_t*& dest_buf, |
| 975 uint32_t& dest_size) { | 976 uint32_t& dest_size) { |
| 976 if (predictor != 2 && predictor < 10) { | 977 if (predictor != 2 && predictor < 10) { |
| 977 return Encode(src_buf, src_size, dest_buf, dest_size); | 978 return Encode(src_buf, src_size, dest_buf, dest_size); |
| 978 } | 979 } |
| 979 uint8_t* pSrcBuf = NULL; | 980 uint8_t* pSrcBuf = nullptr; |
|
Tom Sepez
2016/06/02 20:09:49
nit: combine with 981
Lei Zhang
2016/06/07 07:33:23
Code is gone.
| |
| 980 pSrcBuf = FX_Alloc(uint8_t, src_size); | 981 pSrcBuf = FX_Alloc(uint8_t, src_size); |
| 981 FXSYS_memcpy(pSrcBuf, src_buf, src_size); | 982 FXSYS_memcpy(pSrcBuf, src_buf, src_size); |
| 982 FX_BOOL ret = TRUE; | 983 FX_BOOL ret = TRUE; |
| 983 if (predictor == 2) { | 984 if (predictor == 2) { |
| 984 ret = TIFF_PredictorEncode(pSrcBuf, src_size, Colors, BitsPerComponent, | 985 ret = TIFF_PredictorEncode(pSrcBuf, src_size, Colors, BitsPerComponent, |
| 985 Columns); | 986 Columns); |
| 986 } else if (predictor >= 10) { | 987 } else if (predictor >= 10) { |
| 987 ret = PNG_PredictorEncode(pSrcBuf, src_size, predictor, Colors, | 988 ret = PNG_PredictorEncode(pSrcBuf, src_size, predictor, Colors, |
| 988 BitsPerComponent, Columns); | 989 BitsPerComponent, Columns); |
| 989 } | 990 } |
| 990 if (ret) | 991 if (ret) |
| 991 ret = Encode(pSrcBuf, src_size, dest_buf, dest_size); | 992 ret = Encode(pSrcBuf, src_size, dest_buf, dest_size); |
| 992 FX_Free(pSrcBuf); | 993 FX_Free(pSrcBuf); |
| 993 return ret; | 994 return ret; |
| 994 } | 995 } |
| 995 FX_BOOL CCodec_FlateModule::Encode(const uint8_t* src_buf, | 996 FX_BOOL CCodec_FlateModule::Encode(const uint8_t* src_buf, |
| 996 uint32_t src_size, | 997 uint32_t src_size, |
| 997 uint8_t*& dest_buf, | 998 uint8_t*& dest_buf, |
| 998 uint32_t& dest_size) { | 999 uint32_t& dest_size) { |
| 999 dest_size = src_size + src_size / 1000 + 12; | 1000 dest_size = src_size + src_size / 1000 + 12; |
| 1000 dest_buf = FX_Alloc(uint8_t, dest_size); | 1001 dest_buf = FX_Alloc(uint8_t, dest_size); |
| 1001 unsigned long temp_size = dest_size; | 1002 unsigned long temp_size = dest_size; |
| 1002 FPDFAPI_FlateCompress(dest_buf, &temp_size, src_buf, src_size); | 1003 FPDFAPI_FlateCompress(dest_buf, &temp_size, src_buf, src_size); |
| 1003 dest_size = (uint32_t)temp_size; | 1004 dest_size = (uint32_t)temp_size; |
| 1004 return TRUE; | 1005 return TRUE; |
| 1005 } | 1006 } |
| OLD | NEW |