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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 FX_DWORD& src_size, | 140 FX_DWORD& src_size, |
141 FX_BOOL bEarlyChange) { | 141 FX_BOOL bEarlyChange) { |
142 m_CodeLen = 9; | 142 m_CodeLen = 9; |
143 m_InPos = 0; | 143 m_InPos = 0; |
144 m_OutPos = 0; | 144 m_OutPos = 0; |
145 m_pInput = src_buf; | 145 m_pInput = src_buf; |
146 m_pOutput = dest_buf; | 146 m_pOutput = dest_buf; |
147 m_Early = bEarlyChange ? 1 : 0; | 147 m_Early = bEarlyChange ? 1 : 0; |
148 m_nCodes = 0; | 148 m_nCodes = 0; |
149 FX_DWORD old_code = (FX_DWORD)-1; | 149 FX_DWORD old_code = (FX_DWORD)-1; |
150 uint8_t last_char; | 150 uint8_t last_char = 0; |
151 while (1) { | 151 while (1) { |
152 if (m_InPos + m_CodeLen > src_size * 8) { | 152 if (m_InPos + m_CodeLen > src_size * 8) { |
153 break; | 153 break; |
154 } | 154 } |
155 int byte_pos = m_InPos / 8; | 155 int byte_pos = m_InPos / 8; |
156 int bit_pos = m_InPos % 8, bit_left = m_CodeLen; | 156 int bit_pos = m_InPos % 8, bit_left = m_CodeLen; |
157 FX_DWORD code = 0; | 157 FX_DWORD code = 0; |
158 if (bit_pos) { | 158 if (bit_pos) { |
159 bit_left -= 8 - bit_pos; | 159 bit_left -= 8 - bit_pos; |
160 code = (m_pInput[byte_pos++] & ((1 << (8 - bit_pos)) - 1)) << bit_left; | 160 code = (m_pInput[byte_pos++] & ((1 << (8 - bit_pos)) - 1)) << bit_left; |
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 predictor_type = 1; | 935 predictor_type = 1; |
936 } | 936 } |
937 } | 937 } |
938 if (bLZW) { | 938 if (bLZW) { |
939 { | 939 { |
940 std::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder); | 940 std::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder); |
941 dest_size = (FX_DWORD)-1; | 941 dest_size = (FX_DWORD)-1; |
942 offset = src_size; | 942 offset = src_size; |
943 int err = decoder->Decode(NULL, dest_size, src_buf, offset, bEarlyChange); | 943 int err = decoder->Decode(NULL, dest_size, src_buf, offset, bEarlyChange); |
944 if (err || dest_size == 0 || dest_size + 1 < dest_size) { | 944 if (err || dest_size == 0 || dest_size + 1 < dest_size) { |
945 return -1; | 945 return static_cast<FX_DWORD>(-1); |
946 } | 946 } |
947 } | 947 } |
948 { | 948 { |
949 std::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder); | 949 std::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder); |
950 dest_buf = FX_Alloc(uint8_t, dest_size + 1); | 950 dest_buf = FX_Alloc(uint8_t, dest_size + 1); |
951 dest_buf[dest_size] = '\0'; | 951 dest_buf[dest_size] = '\0'; |
952 decoder->Decode(dest_buf, dest_size, src_buf, offset, bEarlyChange); | 952 decoder->Decode(dest_buf, dest_size, src_buf, offset, bEarlyChange); |
953 } | 953 } |
954 } else { | 954 } else { |
955 FlateUncompress(src_buf, src_size, estimated_size, dest_buf, dest_size, | 955 FlateUncompress(src_buf, src_size, estimated_size, dest_buf, dest_size, |
956 offset); | 956 offset); |
957 } | 957 } |
958 if (predictor_type == 0) { | 958 if (predictor_type == 0) { |
959 return offset; | 959 return offset; |
960 } | 960 } |
961 FX_BOOL ret = TRUE; | 961 FX_BOOL ret = TRUE; |
962 if (predictor_type == 2) { | 962 if (predictor_type == 2) { |
963 ret = PNG_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, Columns); | 963 ret = PNG_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, Columns); |
964 } else if (predictor_type == 1) { | 964 } else if (predictor_type == 1) { |
965 ret = | 965 ret = |
966 TIFF_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, Columns); | 966 TIFF_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, Columns); |
967 } | 967 } |
968 return ret ? offset : -1; | 968 return ret ? offset : static_cast<FX_DWORD>(-1); |
969 } | 969 } |
970 FX_BOOL CCodec_FlateModule::Encode(const uint8_t* src_buf, | 970 FX_BOOL CCodec_FlateModule::Encode(const uint8_t* src_buf, |
971 FX_DWORD src_size, | 971 FX_DWORD src_size, |
972 int predictor, | 972 int predictor, |
973 int Colors, | 973 int Colors, |
974 int BitsPerComponent, | 974 int BitsPerComponent, |
975 int Columns, | 975 int Columns, |
976 uint8_t*& dest_buf, | 976 uint8_t*& dest_buf, |
977 FX_DWORD& dest_size) { | 977 FX_DWORD& dest_size) { |
978 if (predictor != 2 && predictor < 10) { | 978 if (predictor != 2 && predictor < 10) { |
(...skipping 19 matching lines...) Expand all Loading... |
998 FX_DWORD src_size, | 998 FX_DWORD src_size, |
999 uint8_t*& dest_buf, | 999 uint8_t*& dest_buf, |
1000 FX_DWORD& dest_size) { | 1000 FX_DWORD& dest_size) { |
1001 dest_size = src_size + src_size / 1000 + 12; | 1001 dest_size = src_size + src_size / 1000 + 12; |
1002 dest_buf = FX_Alloc(uint8_t, dest_size); | 1002 dest_buf = FX_Alloc(uint8_t, dest_size); |
1003 unsigned long temp_size = dest_size; | 1003 unsigned long temp_size = dest_size; |
1004 FPDFAPI_FlateCompress(dest_buf, &temp_size, src_buf, src_size); | 1004 FPDFAPI_FlateCompress(dest_buf, &temp_size, src_buf, src_size); |
1005 dest_size = (FX_DWORD)temp_size; | 1005 dest_size = (FX_DWORD)temp_size; |
1006 return TRUE; | 1006 return TRUE; |
1007 } | 1007 } |
OLD | NEW |