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