| OLD | NEW |
| 1 | 1 |
| 2 // Copyright 2014 PDFium Authors. All rights reserved. | 2 // Copyright 2014 PDFium Authors. All rights reserved. |
| 3 // 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 |
| 4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
| 5 | 5 |
| 6 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 6 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 7 | 7 |
| 8 #include "core/include/fxcodec/fx_codec.h" | 8 #include "core/include/fxcodec/fx_codec.h" |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 135 } |
| 136 | 136 |
| 137 nonstd::unique_ptr<ImageDataCache> cache( | 137 nonstd::unique_ptr<ImageDataCache> cache( |
| 138 new ImageDataCache(m_OutputWidth, m_OutputHeight, m_Pitch)); | 138 new ImageDataCache(m_OutputWidth, m_OutputHeight, m_Pitch)); |
| 139 if (!cache->AllocateCache()) | 139 if (!cache->AllocateCache()) |
| 140 return; | 140 return; |
| 141 | 141 |
| 142 m_pDataCache = nonstd::move(cache); | 142 m_pDataCache = nonstd::move(cache); |
| 143 } | 143 } |
| 144 | 144 |
| 145 FX_BOOL CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf, |
| 146 FX_DWORD src_size, |
| 147 uint8_t*& dest_buf, |
| 148 FX_DWORD& dest_size) { |
| 149 return FALSE; |
| 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 |
| 165 extern "C" double FXstrtod(const char* nptr, char** endptr) { |
| 166 double ret = 0.0; |
| 167 const char* ptr = nptr; |
| 168 const char* exp_ptr = NULL; |
| 169 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; |
| 171 if (!nptr) { |
| 172 return 0.0; |
| 173 } |
| 174 for (;; ptr++) { |
| 175 if (!e_number && !e_point && (*ptr == '\t' || *ptr == ' ')) |
| 176 continue; |
| 177 |
| 178 if (std::isdigit(*ptr)) { |
| 179 if (!e_number) |
| 180 e_number = 1; |
| 181 |
| 182 if (!e_point) { |
| 183 ret *= 10; |
| 184 ret += FXSYS_toDecimalDigit(*ptr); |
| 185 } else { |
| 186 fra_count++; |
| 187 fra_ret *= 10; |
| 188 fra_ret += FXSYS_toDecimalDigit(*ptr); |
| 189 } |
| 190 continue; |
| 191 } |
| 192 if (!e_point && *ptr == '.') { |
| 193 e_point = 1; |
| 194 continue; |
| 195 } |
| 196 if (!e_number && !e_point && !e_signal) { |
| 197 switch (*ptr) { |
| 198 case '-': |
| 199 is_negative = 1; |
| 200 case '+': |
| 201 e_signal = 1; |
| 202 continue; |
| 203 } |
| 204 } |
| 205 if (e_number && (*ptr == 'e' || *ptr == 'E')) { |
| 206 exp_ptr = ptr++; |
| 207 if (*ptr == '+' || *ptr == '-') { |
| 208 exp_sig = (*ptr++ == '+') ? 1 : -1; |
| 209 if (!std::isdigit(*ptr)) { |
| 210 if (endptr) { |
| 211 *endptr = (char*)exp_ptr; |
| 212 } |
| 213 break; |
| 214 } |
| 215 EXPONENT_DETECT(ptr); |
| 216 } else if (std::isdigit(*ptr)) { |
| 217 EXPONENT_DETECT(ptr); |
| 218 } else { |
| 219 if (endptr) { |
| 220 *endptr = (char*)exp_ptr; |
| 221 } |
| 222 break; |
| 223 } |
| 224 break; |
| 225 } |
| 226 if (ptr != nptr && !e_number) { |
| 227 if (endptr) { |
| 228 *endptr = (char*)nptr; |
| 229 } |
| 230 break; |
| 231 } |
| 232 if (endptr) { |
| 233 *endptr = (char*)ptr; |
| 234 } |
| 235 break; |
| 236 } |
| 237 while (fra_count--) { |
| 238 fra_base *= 10; |
| 239 } |
| 240 ret += (double)fra_ret / (double)fra_base; |
| 241 if (exp_sig == 1) { |
| 242 while (exp_ret--) { |
| 243 ret *= 10.0; |
| 244 } |
| 245 } else { |
| 246 while (exp_ret--) { |
| 247 ret /= 10.0; |
| 248 } |
| 249 } |
| 250 return is_negative ? -ret : ret; |
| 251 } |
| 252 #undef EXPONENT_DETECT |
| 253 |
| 254 FX_BOOL CCodec_BasicModule::A85Encode(const uint8_t* src_buf, |
| 255 FX_DWORD src_size, |
| 256 uint8_t*& dest_buf, |
| 257 FX_DWORD& dest_size) { |
| 258 return FALSE; |
| 259 } |
| 145 class CCodec_RLScanlineDecoder : public CCodec_ScanlineDecoder { | 260 class CCodec_RLScanlineDecoder : public CCodec_ScanlineDecoder { |
| 146 public: | 261 public: |
| 147 CCodec_RLScanlineDecoder(); | 262 CCodec_RLScanlineDecoder(); |
| 148 ~CCodec_RLScanlineDecoder() override; | 263 ~CCodec_RLScanlineDecoder() override; |
| 149 | 264 |
| 150 FX_BOOL Create(const uint8_t* src_buf, | 265 FX_BOOL Create(const uint8_t* src_buf, |
| 151 FX_DWORD src_size, | 266 FX_DWORD src_size, |
| 152 int width, | 267 int width, |
| 153 int height, | 268 int height, |
| 154 int nComps, | 269 int nComps, |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 int nComps, | 454 int nComps, |
| 340 int bpc) { | 455 int bpc) { |
| 341 CCodec_RLScanlineDecoder* pRLScanlineDecoder = new CCodec_RLScanlineDecoder; | 456 CCodec_RLScanlineDecoder* pRLScanlineDecoder = new CCodec_RLScanlineDecoder; |
| 342 if (!pRLScanlineDecoder->Create(src_buf, src_size, width, height, nComps, | 457 if (!pRLScanlineDecoder->Create(src_buf, src_size, width, height, nComps, |
| 343 bpc)) { | 458 bpc)) { |
| 344 delete pRLScanlineDecoder; | 459 delete pRLScanlineDecoder; |
| 345 return NULL; | 460 return NULL; |
| 346 } | 461 } |
| 347 return pRLScanlineDecoder; | 462 return pRLScanlineDecoder; |
| 348 } | 463 } |
| OLD | NEW |