Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(735)

Side by Side Diff: core/src/fxcodec/codec/fx_codec.cpp

Issue 1452673002: Merge to XFA: Reland "Cleanup some numeric code."" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 146
145 m_pDataCache = nonstd::move(cache); 147 m_pDataCache = nonstd::move(cache);
146 } 148 }
147 149
148 FX_BOOL CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf, 150 FX_BOOL CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf,
149 FX_DWORD src_size, 151 FX_DWORD src_size,
150 uint8_t*& dest_buf, 152 uint8_t*& dest_buf,
151 FX_DWORD& dest_size) { 153 FX_DWORD& dest_size) {
152 return FALSE; 154 return FALSE;
153 } 155 }
156
157 #define EXPONENT_DETECT(ptr) \
158 for (;; ptr++) { \
159 if (!std::isdigit(*ptr)) { \
160 if (endptr) \
161 *endptr = (char*)ptr; \
162 break; \
163 } else { \
164 exp_ret *= 10; \
165 exp_ret += FXSYS_toDecimalDigit(*ptr); \
166 continue; \
167 } \
168 }
169
154 extern "C" double FXstrtod(const char* nptr, char** endptr) { 170 extern "C" double FXstrtod(const char* nptr, char** endptr) {
155 double ret = 0.0; 171 double ret = 0.0;
156 const char* ptr = nptr; 172 const char* ptr = nptr;
157 const char* exp_ptr = NULL; 173 const char* exp_ptr = NULL;
158 int e_number = 0, e_signal = 0, e_point = 0, is_negative = 0; 174 int e_number = 0, e_signal = 0, e_point = 0, is_negative = 0;
159 int exp_ret = 0, exp_sig = 1, fra_ret = 0, fra_count = 0, fra_base = 1; 175 int exp_ret = 0, exp_sig = 1, fra_ret = 0, fra_count = 0, fra_base = 1;
160 if (nptr == NULL) { 176 if (nptr == NULL) {
161 return 0.0; 177 return 0.0;
162 } 178 }
163 for (;; ptr++) { 179 for (;; ptr++) {
164 if (!e_number && !e_point && (*ptr == '\t' || *ptr == ' ')) { 180 if (!e_number && !e_point && (*ptr == '\t' || *ptr == ' '))
165 continue; 181 continue;
166 } 182
167 if (*ptr >= '0' && *ptr <= '9') { 183 if (std::isdigit(*ptr)) {
168 if (!e_number) { 184 if (!e_number)
169 e_number = 1; 185 e_number = 1;
170 } 186
171 if (!e_point) { 187 if (!e_point) {
172 ret *= 10; 188 ret *= 10;
173 ret += (*ptr - '0'); 189 ret += FXSYS_toDecimalDigit(*ptr);
174 } else { 190 } else {
175 fra_count++; 191 fra_count++;
176 fra_ret *= 10; 192 fra_ret *= 10;
177 fra_ret += (*ptr - '0'); 193 fra_ret += FXSYS_toDecimalDigit(*ptr);
178 } 194 }
179 continue; 195 continue;
180 } 196 }
181 if (!e_point && *ptr == '.') { 197 if (!e_point && *ptr == '.') {
182 e_point = 1; 198 e_point = 1;
183 continue; 199 continue;
184 } 200 }
185 if (!e_number && !e_point && !e_signal) { 201 if (!e_number && !e_point && !e_signal) {
186 switch (*ptr) { 202 switch (*ptr) {
187 case '-': 203 case '-':
188 is_negative = 1; 204 is_negative = 1;
189 case '+': 205 case '+':
190 e_signal = 1; 206 e_signal = 1;
191 continue; 207 continue;
192 } 208 }
193 } 209 }
194 if (e_number && (*ptr == 'e' || *ptr == 'E')) { 210 if (e_number && (*ptr == 'e' || *ptr == 'E')) {
195 #define EXPONENT_DETECT(ptr) \
196 for (;; ptr++) { \
197 if (*ptr < '0' || *ptr > '9') { \
198 if (endptr) \
199 *endptr = (char*)ptr; \
200 break; \
201 } else { \
202 exp_ret *= 10; \
203 exp_ret += (*ptr - '0'); \
204 continue; \
205 } \
206 }
207 exp_ptr = ptr++; 211 exp_ptr = ptr++;
208 if (*ptr == '+' || *ptr == '-') { 212 if (*ptr == '+' || *ptr == '-') {
209 exp_sig = (*ptr++ == '+') ? 1 : -1; 213 exp_sig = (*ptr++ == '+') ? 1 : -1;
210 if (*ptr < '0' || *ptr > '9') { 214 if (!std::isdigit(*ptr)) {
211 if (endptr) { 215 if (endptr) {
212 *endptr = (char*)exp_ptr; 216 *endptr = (char*)exp_ptr;
213 } 217 }
214 break; 218 break;
215 } 219 }
216 EXPONENT_DETECT(ptr); 220 EXPONENT_DETECT(ptr);
217 } else if (*ptr >= '0' && *ptr <= '9') { 221 } else if (std::isdigit(*ptr)) {
218 EXPONENT_DETECT(ptr); 222 EXPONENT_DETECT(ptr);
219 } else { 223 } else {
220 if (endptr) { 224 if (endptr) {
221 *endptr = (char*)exp_ptr; 225 *endptr = (char*)exp_ptr;
222 } 226 }
223 break; 227 break;
224 } 228 }
225 #undef EXPONENT_DETECT
226 break; 229 break;
227 } 230 }
228 if (ptr != nptr && !e_number) { 231 if (ptr != nptr && !e_number) {
229 if (endptr) { 232 if (endptr) {
230 *endptr = (char*)nptr; 233 *endptr = (char*)nptr;
231 } 234 }
232 break; 235 break;
233 } 236 }
234 if (endptr) { 237 if (endptr) {
235 *endptr = (char*)ptr; 238 *endptr = (char*)ptr;
236 } 239 }
237 break; 240 break;
238 } 241 }
239 while (fra_count--) { 242 while (fra_count--) {
240 fra_base *= 10; 243 fra_base *= 10;
241 } 244 }
242 ret += (double)fra_ret / (double)fra_base; 245 ret += (double)fra_ret / (double)fra_base;
243 if (exp_sig == 1) { 246 if (exp_sig == 1) {
244 while (exp_ret--) { 247 while (exp_ret--) {
245 ret *= 10.0; 248 ret *= 10.0;
246 } 249 }
247 } else { 250 } else {
248 while (exp_ret--) { 251 while (exp_ret--) {
249 ret /= 10.0; 252 ret /= 10.0;
250 } 253 }
251 } 254 }
252 return is_negative ? -ret : ret; 255 return is_negative ? -ret : ret;
253 } 256 }
257 #undef EXPONENT_DETECT
258
254 FX_BOOL CCodec_BasicModule::A85Encode(const uint8_t* src_buf, 259 FX_BOOL CCodec_BasicModule::A85Encode(const uint8_t* src_buf,
255 FX_DWORD src_size, 260 FX_DWORD src_size,
256 uint8_t*& dest_buf, 261 uint8_t*& dest_buf,
257 FX_DWORD& dest_size) { 262 FX_DWORD& dest_size) {
258 return FALSE; 263 return FALSE;
259 } 264 }
260 CFX_DIBAttribute::CFX_DIBAttribute() 265 CFX_DIBAttribute::CFX_DIBAttribute()
261 : m_nXDPI(-1), 266 : m_nXDPI(-1),
262 m_nYDPI(-1), 267 m_nYDPI(-1),
263 m_fAspectRatio(-1.0f), 268 m_fAspectRatio(-1.0f),
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 int nComps, 465 int nComps,
461 int bpc) { 466 int bpc) {
462 CCodec_RLScanlineDecoder* pRLScanlineDecoder = new CCodec_RLScanlineDecoder; 467 CCodec_RLScanlineDecoder* pRLScanlineDecoder = new CCodec_RLScanlineDecoder;
463 if (!pRLScanlineDecoder->Create(src_buf, src_size, width, height, nComps, 468 if (!pRLScanlineDecoder->Create(src_buf, src_size, width, height, nComps,
464 bpc)) { 469 bpc)) {
465 delete pRLScanlineDecoder; 470 delete pRLScanlineDecoder;
466 return NULL; 471 return NULL;
467 } 472 }
468 return pRLScanlineDecoder; 473 return pRLScanlineDecoder;
469 } 474 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698