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