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

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

Issue 1177483002: Use stdint.h types throughout PDFium. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 6 months 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
« no previous file with comments | « core/src/fxcodec/codec/codec_int.h ('k') | core/src/fxcodec/codec/fx_codec_fax.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "codec_int.h" 8 #include "codec_int.h"
9 CCodec_ModuleMgr::CCodec_ModuleMgr() 9 CCodec_ModuleMgr::CCodec_ModuleMgr()
10 { 10 {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 dest_height = -dest_height; 112 dest_height = -dest_height;
113 } 113 }
114 v_DownScale(dest_width, dest_height); 114 v_DownScale(dest_width, dest_height);
115 if (m_pDataCache) { 115 if (m_pDataCache) {
116 if (m_pDataCache->m_Height == m_OutputHeight && m_pDataCache->m_Width == m_OutputWidth) { 116 if (m_pDataCache->m_Height == m_OutputHeight && m_pDataCache->m_Width == m_OutputWidth) {
117 return; 117 return;
118 } 118 }
119 FX_Free(m_pDataCache); 119 FX_Free(m_pDataCache);
120 m_pDataCache = NULL; 120 m_pDataCache = NULL;
121 } 121 }
122 m_pDataCache = (CCodec_ImageDataCache*)FX_TryAlloc(FX_BYTE, sizeof(CCodec_Im ageDataCache) + m_Pitch * m_OutputHeight); 122 m_pDataCache = (CCodec_ImageDataCache*)FX_TryAlloc(uint8_t, sizeof(CCodec_Im ageDataCache) + m_Pitch * m_OutputHeight);
123 if (m_pDataCache == NULL) { 123 if (m_pDataCache == NULL) {
124 return; 124 return;
125 } 125 }
126 m_pDataCache->m_Height = m_OutputHeight; 126 m_pDataCache->m_Height = m_OutputHeight;
127 m_pDataCache->m_Width = m_OutputWidth; 127 m_pDataCache->m_Width = m_OutputWidth;
128 m_pDataCache->m_nCachedLines = 0; 128 m_pDataCache->m_nCachedLines = 0;
129 } 129 }
130 FX_BOOL CCodec_BasicModule::RunLengthEncode(const FX_BYTE* src_buf, FX_DWORD src _size, FX_LPBYTE& dest_buf, 130 FX_BOOL CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf, FX_DWORD src _size, FX_LPBYTE& dest_buf,
131 FX_DWORD& dest_size) 131 FX_DWORD& dest_size)
132 { 132 {
133 return FALSE; 133 return FALSE;
134 } 134 }
135 extern "C" double FXstrtod(const char* nptr, char** endptr) 135 extern "C" double FXstrtod(const char* nptr, char** endptr)
136 { 136 {
137 double ret = 0.0; 137 double ret = 0.0;
138 const char* ptr = nptr; 138 const char* ptr = nptr;
139 const char* exp_ptr = NULL; 139 const char* exp_ptr = NULL;
140 int e_number = 0, 140 int e_number = 0,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 while(exp_ret--) { 229 while(exp_ret--) {
230 ret *= 10.0; 230 ret *= 10.0;
231 } 231 }
232 } else { 232 } else {
233 while(exp_ret--) { 233 while(exp_ret--) {
234 ret /= 10.0; 234 ret /= 10.0;
235 } 235 }
236 } 236 }
237 return is_negative ? -ret : ret; 237 return is_negative ? -ret : ret;
238 } 238 }
239 FX_BOOL CCodec_BasicModule::A85Encode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_buf, 239 FX_BOOL CCodec_BasicModule::A85Encode(const uint8_t* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_buf,
240 FX_DWORD& dest_size) 240 FX_DWORD& dest_size)
241 { 241 {
242 return FALSE; 242 return FALSE;
243 } 243 }
244 CCodec_ModuleMgr* CCodec_ModuleMgr::Create() 244 CCodec_ModuleMgr* CCodec_ModuleMgr::Create()
245 { 245 {
246 return new CCodec_ModuleMgr; 246 return new CCodec_ModuleMgr;
247 } 247 }
248 void CCodec_ModuleMgr::Destroy() 248 void CCodec_ModuleMgr::Destroy()
249 { 249 {
250 delete this; 250 delete this;
251 } 251 }
252 class CCodec_RLScanlineDecoder : public CCodec_ScanlineDecoder 252 class CCodec_RLScanlineDecoder : public CCodec_ScanlineDecoder
253 { 253 {
254 public: 254 public:
255 CCodec_RLScanlineDecoder(); 255 CCodec_RLScanlineDecoder();
256 virtual ~CCodec_RLScanlineDecoder(); 256 virtual ~CCodec_RLScanlineDecoder();
257 FX_BOOL Create(FX_LPCBYTE src_buf, FX_DWORD src_ size, int width, int height, int nComps, int bpc); 257 FX_BOOL Create(FX_LPCBYTE src_buf, FX_DWORD src_ size, int width, int height, int nComps, int bpc);
258 virtual void v_DownScale(int dest_width, int dest_height) {} 258 virtual void v_DownScale(int dest_width, int dest_height) {}
259 virtual FX_BOOL v_Rewind(); 259 virtual FX_BOOL v_Rewind();
260 virtual FX_LPBYTE v_GetNextLine(); 260 virtual FX_LPBYTE v_GetNextLine();
261 virtual FX_DWORD GetSrcOffset() 261 virtual FX_DWORD GetSrcOffset()
262 { 262 {
263 return m_SrcOffset; 263 return m_SrcOffset;
264 } 264 }
265 protected: 265 protected:
266 FX_BOOL CheckDestSize(); 266 FX_BOOL CheckDestSize();
267 void GetNextOperator(); 267 void GetNextOperator();
268 void» » » » UpdateOperator(FX_BYTE used_bytes); 268 void» » » » UpdateOperator(uint8_t used_bytes);
269 269
270 FX_LPBYTE m_pScanline; 270 FX_LPBYTE m_pScanline;
271 FX_LPCBYTE m_pSrcBuf; 271 FX_LPCBYTE m_pSrcBuf;
272 FX_DWORD m_SrcSize; 272 FX_DWORD m_SrcSize;
273 FX_DWORD m_dwLineBytes; 273 FX_DWORD m_dwLineBytes;
274 FX_DWORD m_SrcOffset; 274 FX_DWORD m_SrcOffset;
275 FX_BOOL m_bEOD; 275 FX_BOOL m_bEOD;
276 FX_BYTE» » » » m_Operator; 276 uint8_t» » » » m_Operator;
277 }; 277 };
278 CCodec_RLScanlineDecoder::CCodec_RLScanlineDecoder() 278 CCodec_RLScanlineDecoder::CCodec_RLScanlineDecoder()
279 : m_pScanline(NULL) 279 : m_pScanline(NULL)
280 , m_pSrcBuf(NULL) 280 , m_pSrcBuf(NULL)
281 , m_SrcSize(0) 281 , m_SrcSize(0)
282 , m_dwLineBytes(0) 282 , m_dwLineBytes(0)
283 , m_SrcOffset(0) 283 , m_SrcOffset(0)
284 , m_bEOD(FALSE) 284 , m_bEOD(FALSE)
285 , m_Operator(0) 285 , m_Operator(0)
286 { 286 {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 m_pSrcBuf = src_buf; 325 m_pSrcBuf = src_buf;
326 m_SrcSize = src_size; 326 m_SrcSize = src_size;
327 m_OutputWidth = m_OrigWidth = width; 327 m_OutputWidth = m_OrigWidth = width;
328 m_OutputHeight = m_OrigHeight = height; 328 m_OutputHeight = m_OrigHeight = height;
329 m_nComps = nComps; 329 m_nComps = nComps;
330 m_bpc = bpc; 330 m_bpc = bpc;
331 m_bColorTransformed = FALSE; 331 m_bColorTransformed = FALSE;
332 m_DownScale = 1; 332 m_DownScale = 1;
333 m_Pitch = (width * nComps * bpc + 31) / 32 * 4; 333 m_Pitch = (width * nComps * bpc + 31) / 32 * 4;
334 m_dwLineBytes = (width * nComps * bpc + 7) / 8; 334 m_dwLineBytes = (width * nComps * bpc + 7) / 8;
335 m_pScanline = FX_Alloc(FX_BYTE, m_Pitch); 335 m_pScanline = FX_Alloc(uint8_t, m_Pitch);
336 return CheckDestSize(); 336 return CheckDestSize();
337 } 337 }
338 FX_BOOL CCodec_RLScanlineDecoder::v_Rewind() 338 FX_BOOL CCodec_RLScanlineDecoder::v_Rewind()
339 { 339 {
340 FXSYS_memset32(m_pScanline, 0, m_Pitch); 340 FXSYS_memset32(m_pScanline, 0, m_Pitch);
341 m_SrcOffset = 0; 341 m_SrcOffset = 0;
342 m_bEOD = FALSE; 342 m_bEOD = FALSE;
343 m_Operator = 0; 343 m_Operator = 0;
344 return TRUE; 344 return TRUE;
345 } 345 }
(...skipping 15 matching lines...) Expand all
361 if (col_pos + copy_len >= m_dwLineBytes) { 361 if (col_pos + copy_len >= m_dwLineBytes) {
362 copy_len = m_dwLineBytes - col_pos; 362 copy_len = m_dwLineBytes - col_pos;
363 eol = TRUE; 363 eol = TRUE;
364 } 364 }
365 if (copy_len >= m_SrcSize - m_SrcOffset) { 365 if (copy_len >= m_SrcSize - m_SrcOffset) {
366 copy_len = m_SrcSize - m_SrcOffset; 366 copy_len = m_SrcSize - m_SrcOffset;
367 m_bEOD = TRUE; 367 m_bEOD = TRUE;
368 } 368 }
369 FXSYS_memcpy32(m_pScanline + col_pos, m_pSrcBuf + m_SrcOffset, copy_ len); 369 FXSYS_memcpy32(m_pScanline + col_pos, m_pSrcBuf + m_SrcOffset, copy_ len);
370 col_pos += copy_len; 370 col_pos += copy_len;
371 UpdateOperator((FX_BYTE)copy_len); 371 UpdateOperator((uint8_t)copy_len);
372 } else if (m_Operator > 128) { 372 } else if (m_Operator > 128) {
373 int fill = 0; 373 int fill = 0;
374 if (m_SrcOffset - 1 < m_SrcSize - 1) { 374 if (m_SrcOffset - 1 < m_SrcSize - 1) {
375 fill = m_pSrcBuf[m_SrcOffset]; 375 fill = m_pSrcBuf[m_SrcOffset];
376 } 376 }
377 FX_DWORD duplicate_len = 257 - m_Operator; 377 FX_DWORD duplicate_len = 257 - m_Operator;
378 if (col_pos + duplicate_len >= m_dwLineBytes) { 378 if (col_pos + duplicate_len >= m_dwLineBytes) {
379 duplicate_len = m_dwLineBytes - col_pos; 379 duplicate_len = m_dwLineBytes - col_pos;
380 eol = TRUE; 380 eol = TRUE;
381 } 381 }
382 FXSYS_memset8(m_pScanline + col_pos, fill, duplicate_len); 382 FXSYS_memset8(m_pScanline + col_pos, fill, duplicate_len);
383 col_pos += duplicate_len; 383 col_pos += duplicate_len;
384 UpdateOperator((FX_BYTE)duplicate_len); 384 UpdateOperator((uint8_t)duplicate_len);
385 } else { 385 } else {
386 m_bEOD = TRUE; 386 m_bEOD = TRUE;
387 break; 387 break;
388 } 388 }
389 } 389 }
390 return m_pScanline; 390 return m_pScanline;
391 } 391 }
392 void CCodec_RLScanlineDecoder::GetNextOperator() 392 void CCodec_RLScanlineDecoder::GetNextOperator()
393 { 393 {
394 if (m_SrcOffset >= m_SrcSize) { 394 if (m_SrcOffset >= m_SrcSize) {
395 m_Operator = 128; 395 m_Operator = 128;
396 return; 396 return;
397 } 397 }
398 m_Operator = m_pSrcBuf[m_SrcOffset]; 398 m_Operator = m_pSrcBuf[m_SrcOffset];
399 m_SrcOffset ++; 399 m_SrcOffset ++;
400 } 400 }
401 void CCodec_RLScanlineDecoder::UpdateOperator(FX_BYTE used_bytes) 401 void CCodec_RLScanlineDecoder::UpdateOperator(uint8_t used_bytes)
402 { 402 {
403 if (used_bytes == 0) { 403 if (used_bytes == 0) {
404 return; 404 return;
405 } 405 }
406 if (m_Operator < 128) { 406 if (m_Operator < 128) {
407 FXSYS_assert((FX_DWORD)m_Operator + 1 >= used_bytes); 407 FXSYS_assert((FX_DWORD)m_Operator + 1 >= used_bytes);
408 if (used_bytes == m_Operator + 1) { 408 if (used_bytes == m_Operator + 1) {
409 m_SrcOffset += used_bytes; 409 m_SrcOffset += used_bytes;
410 GetNextOperator(); 410 GetNextOperator();
411 return; 411 return;
412 } 412 }
413 m_Operator -= used_bytes; 413 m_Operator -= used_bytes;
414 m_SrcOffset += used_bytes; 414 m_SrcOffset += used_bytes;
415 if (m_SrcOffset >= m_SrcSize) { 415 if (m_SrcOffset >= m_SrcSize) {
416 m_Operator = 128; 416 m_Operator = 128;
417 } 417 }
418 return; 418 return;
419 } 419 }
420 FX_BYTE count = 257 - m_Operator; 420 uint8_t count = 257 - m_Operator;
421 FXSYS_assert((FX_DWORD)count >= used_bytes); 421 FXSYS_assert((FX_DWORD)count >= used_bytes);
422 if (used_bytes == count) { 422 if (used_bytes == count) {
423 m_SrcOffset ++; 423 m_SrcOffset ++;
424 GetNextOperator(); 424 GetNextOperator();
425 return; 425 return;
426 } 426 }
427 count -= used_bytes; 427 count -= used_bytes;
428 m_Operator = 257 - count; 428 m_Operator = 257 - count;
429 } 429 }
430 ICodec_ScanlineDecoder* CCodec_BasicModule::CreateRunLengthDecoder(FX_LPCBYTE sr c_buf, FX_DWORD src_size, int width, int height, 430 ICodec_ScanlineDecoder* CCodec_BasicModule::CreateRunLengthDecoder(FX_LPCBYTE sr c_buf, FX_DWORD src_size, int width, int height,
431 int nComps, int bpc) 431 int nComps, int bpc)
432 { 432 {
433 CCodec_RLScanlineDecoder* pRLScanlineDecoder = new CCodec_RLScanlineDecoder; 433 CCodec_RLScanlineDecoder* pRLScanlineDecoder = new CCodec_RLScanlineDecoder;
434 if (!pRLScanlineDecoder->Create(src_buf, src_size, width, height, nComps, bp c)) { 434 if (!pRLScanlineDecoder->Create(src_buf, src_size, width, height, nComps, bp c)) {
435 delete pRLScanlineDecoder; 435 delete pRLScanlineDecoder;
436 return NULL; 436 return NULL;
437 } 437 }
438 return pRLScanlineDecoder; 438 return pRLScanlineDecoder;
439 } 439 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/codec/codec_int.h ('k') | core/src/fxcodec/codec/fx_codec_fax.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698