OLD | NEW |
| 1 |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 2 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 4 // found in the LICENSE file. |
4 | 5 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 6 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 7 |
7 #include "core/include/fxcodec/fx_codec.h" | 8 #include "core/include/fxcodec/fx_codec.h" |
8 | 9 |
9 #include <cmath> | 10 #include <cmath> |
10 | 11 |
11 #include "codec_int.h" | 12 #include "codec_int.h" |
| 13 #include "core/include/fxcrt/fx_ext.h" |
12 #include "core/include/fxcrt/fx_safe_types.h" | 14 #include "core/include/fxcrt/fx_safe_types.h" |
13 #include "third_party/base/logging.h" | 15 #include "third_party/base/logging.h" |
14 | 16 |
15 CCodec_ModuleMgr::CCodec_ModuleMgr() | 17 CCodec_ModuleMgr::CCodec_ModuleMgr() |
16 : m_pBasicModule(new CCodec_BasicModule), | 18 : m_pBasicModule(new CCodec_BasicModule), |
17 m_pFaxModule(new CCodec_FaxModule), | 19 m_pFaxModule(new CCodec_FaxModule), |
18 m_pJpegModule(new CCodec_JpegModule), | 20 m_pJpegModule(new CCodec_JpegModule), |
19 m_pJpxModule(new CCodec_JpxModule), | 21 m_pJpxModule(new CCodec_JpxModule), |
20 m_pJbig2Module(new CCodec_Jbig2Module), | 22 m_pJbig2Module(new CCodec_Jbig2Module), |
21 m_pIccModule(new CCodec_IccModule), | 23 m_pIccModule(new CCodec_IccModule), |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 142 |
141 m_pDataCache = nonstd::move(cache); | 143 m_pDataCache = nonstd::move(cache); |
142 } | 144 } |
143 | 145 |
144 FX_BOOL CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf, | 146 FX_BOOL CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf, |
145 FX_DWORD src_size, | 147 FX_DWORD src_size, |
146 uint8_t*& dest_buf, | 148 uint8_t*& dest_buf, |
147 FX_DWORD& dest_size) { | 149 FX_DWORD& dest_size) { |
148 return FALSE; | 150 return FALSE; |
149 } | 151 } |
| 152 |
| 153 #define EXPONENT_DETECT(ptr) \ |
| 154 for (;; ptr++) { \ |
| 155 if (!std::isdigit(*ptr)) { \ |
| 156 if (endptr) \ |
| 157 *endptr = (char*)ptr; \ |
| 158 break; \ |
| 159 } else { \ |
| 160 exp_ret *= 10; \ |
| 161 exp_ret += FXSYS_toDecimalDigit(*ptr); \ |
| 162 continue; \ |
| 163 } \ |
| 164 } |
| 165 |
150 extern "C" double FXstrtod(const char* nptr, char** endptr) { | 166 extern "C" double FXstrtod(const char* nptr, char** endptr) { |
151 double ret = 0.0; | 167 double ret = 0.0; |
152 const char* ptr = nptr; | 168 const char* ptr = nptr; |
153 const char* exp_ptr = NULL; | 169 const char* exp_ptr = NULL; |
154 int e_number = 0, e_signal = 0, e_point = 0, is_negative = 0; | 170 int e_number = 0, e_signal = 0, e_point = 0, is_negative = 0; |
155 int exp_ret = 0, exp_sig = 1, fra_ret = 0, fra_count = 0, fra_base = 1; | 171 int exp_ret = 0, exp_sig = 1, fra_ret = 0, fra_count = 0, fra_base = 1; |
156 if (nptr == NULL) { | 172 if (nptr == NULL) { |
157 return 0.0; | 173 return 0.0; |
158 } | 174 } |
159 for (;; ptr++) { | 175 for (;; ptr++) { |
160 if (!e_number && !e_point && (*ptr == '\t' || *ptr == ' ')) { | 176 if (!e_number && !e_point && (*ptr == '\t' || *ptr == ' ')) |
161 continue; | 177 continue; |
162 } | 178 |
163 if (*ptr >= '0' && *ptr <= '9') { | 179 if (std::isdigit(*ptr)) { |
164 if (!e_number) { | 180 if (!e_number) |
165 e_number = 1; | 181 e_number = 1; |
166 } | 182 |
167 if (!e_point) { | 183 if (!e_point) { |
168 ret *= 10; | 184 ret *= 10; |
169 ret += (*ptr - '0'); | 185 ret += FXSYS_toDecimalDigit(*ptr); |
170 } else { | 186 } else { |
171 fra_count++; | 187 fra_count++; |
172 fra_ret *= 10; | 188 fra_ret *= 10; |
173 fra_ret += (*ptr - '0'); | 189 fra_ret += FXSYS_toDecimalDigit(*ptr); |
174 } | 190 } |
175 continue; | 191 continue; |
176 } | 192 } |
177 if (!e_point && *ptr == '.') { | 193 if (!e_point && *ptr == '.') { |
178 e_point = 1; | 194 e_point = 1; |
179 continue; | 195 continue; |
180 } | 196 } |
181 if (!e_number && !e_point && !e_signal) { | 197 if (!e_number && !e_point && !e_signal) { |
182 switch (*ptr) { | 198 switch (*ptr) { |
183 case '-': | 199 case '-': |
184 is_negative = 1; | 200 is_negative = 1; |
185 case '+': | 201 case '+': |
186 e_signal = 1; | 202 e_signal = 1; |
187 continue; | 203 continue; |
188 } | 204 } |
189 } | 205 } |
190 if (e_number && (*ptr == 'e' || *ptr == 'E')) { | 206 if (e_number && (*ptr == 'e' || *ptr == 'E')) { |
191 #define EXPONENT_DETECT(ptr) \ | |
192 for (;; ptr++) { \ | |
193 if (*ptr < '0' || *ptr > '9') { \ | |
194 if (endptr) \ | |
195 *endptr = (char*)ptr; \ | |
196 break; \ | |
197 } else { \ | |
198 exp_ret *= 10; \ | |
199 exp_ret += (*ptr - '0'); \ | |
200 continue; \ | |
201 } \ | |
202 } | |
203 exp_ptr = ptr++; | 207 exp_ptr = ptr++; |
204 if (*ptr == '+' || *ptr == '-') { | 208 if (*ptr == '+' || *ptr == '-') { |
205 exp_sig = (*ptr++ == '+') ? 1 : -1; | 209 exp_sig = (*ptr++ == '+') ? 1 : -1; |
206 if (*ptr < '0' || *ptr > '9') { | 210 if (!std::isdigit(*ptr)) { |
207 if (endptr) { | 211 if (endptr) { |
208 *endptr = (char*)exp_ptr; | 212 *endptr = (char*)exp_ptr; |
209 } | 213 } |
210 break; | 214 break; |
211 } | 215 } |
212 EXPONENT_DETECT(ptr); | 216 EXPONENT_DETECT(ptr); |
213 } else if (*ptr >= '0' && *ptr <= '9') { | 217 } else if (std::isdigit(*ptr)) { |
214 EXPONENT_DETECT(ptr); | 218 EXPONENT_DETECT(ptr); |
215 } else { | 219 } else { |
216 if (endptr) { | 220 if (endptr) { |
217 *endptr = (char*)exp_ptr; | 221 *endptr = (char*)exp_ptr; |
218 } | 222 } |
219 break; | 223 break; |
220 } | 224 } |
221 #undef EXPONENT_DETECT | |
222 break; | 225 break; |
223 } | 226 } |
224 if (ptr != nptr && !e_number) { | 227 if (ptr != nptr && !e_number) { |
225 if (endptr) { | 228 if (endptr) { |
226 *endptr = (char*)nptr; | 229 *endptr = (char*)nptr; |
227 } | 230 } |
228 break; | 231 break; |
229 } | 232 } |
230 if (endptr) { | 233 if (endptr) { |
231 *endptr = (char*)ptr; | 234 *endptr = (char*)ptr; |
232 } | 235 } |
233 break; | 236 break; |
234 } | 237 } |
235 while (fra_count--) { | 238 while (fra_count--) { |
236 fra_base *= 10; | 239 fra_base *= 10; |
237 } | 240 } |
238 ret += (double)fra_ret / (double)fra_base; | 241 ret += (double)fra_ret / (double)fra_base; |
239 if (exp_sig == 1) { | 242 if (exp_sig == 1) { |
240 while (exp_ret--) { | 243 while (exp_ret--) { |
241 ret *= 10.0; | 244 ret *= 10.0; |
242 } | 245 } |
243 } else { | 246 } else { |
244 while (exp_ret--) { | 247 while (exp_ret--) { |
245 ret /= 10.0; | 248 ret /= 10.0; |
246 } | 249 } |
247 } | 250 } |
248 return is_negative ? -ret : ret; | 251 return is_negative ? -ret : ret; |
249 } | 252 } |
| 253 #undef EXPONENT_DETECT |
| 254 |
250 FX_BOOL CCodec_BasicModule::A85Encode(const uint8_t* src_buf, | 255 FX_BOOL CCodec_BasicModule::A85Encode(const uint8_t* src_buf, |
251 FX_DWORD src_size, | 256 FX_DWORD src_size, |
252 uint8_t*& dest_buf, | 257 uint8_t*& dest_buf, |
253 FX_DWORD& dest_size) { | 258 FX_DWORD& dest_size) { |
254 return FALSE; | 259 return FALSE; |
255 } | 260 } |
256 class CCodec_RLScanlineDecoder : public CCodec_ScanlineDecoder { | 261 class CCodec_RLScanlineDecoder : public CCodec_ScanlineDecoder { |
257 public: | 262 public: |
258 CCodec_RLScanlineDecoder(); | 263 CCodec_RLScanlineDecoder(); |
259 ~CCodec_RLScanlineDecoder() override; | 264 ~CCodec_RLScanlineDecoder() override; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 int nComps, | 444 int nComps, |
440 int bpc) { | 445 int bpc) { |
441 CCodec_RLScanlineDecoder* pRLScanlineDecoder = new CCodec_RLScanlineDecoder; | 446 CCodec_RLScanlineDecoder* pRLScanlineDecoder = new CCodec_RLScanlineDecoder; |
442 if (!pRLScanlineDecoder->Create(src_buf, src_size, width, height, nComps, | 447 if (!pRLScanlineDecoder->Create(src_buf, src_size, width, height, nComps, |
443 bpc)) { | 448 bpc)) { |
444 delete pRLScanlineDecoder; | 449 delete pRLScanlineDecoder; |
445 return NULL; | 450 return NULL; |
446 } | 451 } |
447 return pRLScanlineDecoder; | 452 return pRLScanlineDecoder; |
448 } | 453 } |
OLD | NEW |