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 #include "codec_int.h" | 8 #include "codec_int.h" |
9 CCodec_ModuleMgr::CCodec_ModuleMgr() | 9 CCodec_ModuleMgr::CCodec_ModuleMgr() |
10 : m_pBasicModule(new CCodec_BasicModule), | 10 : m_pBasicModule(new CCodec_BasicModule), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 m_NextLine = 0; | 42 m_NextLine = 0; |
43 } | 43 } |
44 while (m_NextLine < line) { | 44 while (m_NextLine < line) { |
45 ReadNextLine(); | 45 ReadNextLine(); |
46 m_NextLine ++; | 46 m_NextLine ++; |
47 } | 47 } |
48 m_pLastScanline = ReadNextLine(); | 48 m_pLastScanline = ReadNextLine(); |
49 m_NextLine ++; | 49 m_NextLine ++; |
50 return m_pLastScanline; | 50 return m_pLastScanline; |
51 } | 51 } |
52 FX_BOOL CCodec_ScanlineDecoder::SkipToScanline(int line, IFX_Pause* pPause) | 52 bool CCodec_ScanlineDecoder::SkipToScanline(int line, IFX_Pause* pPause) |
53 { | 53 { |
54 if (m_pDataCache && line < m_pDataCache->m_nCachedLines) { | 54 if (m_pDataCache && line < m_pDataCache->m_nCachedLines) { |
55 return FALSE; | 55 return false; |
56 } | 56 } |
57 if (m_NextLine == line || m_NextLine == line + 1) { | 57 if (m_NextLine == line || m_NextLine == line + 1) { |
58 return FALSE; | 58 return false; |
59 } | 59 } |
60 if (m_NextLine < 0 || m_NextLine > line) { | 60 if (m_NextLine < 0 || m_NextLine > line) { |
61 v_Rewind(); | 61 v_Rewind(); |
62 m_NextLine = 0; | 62 m_NextLine = 0; |
63 } | 63 } |
64 m_pLastScanline = NULL; | 64 m_pLastScanline = NULL; |
65 while (m_NextLine < line) { | 65 while (m_NextLine < line) { |
66 m_pLastScanline = ReadNextLine(); | 66 m_pLastScanline = ReadNextLine(); |
67 m_NextLine ++; | 67 m_NextLine ++; |
68 if (pPause && pPause->NeedToPauseNow()) { | 68 if (pPause && pPause->NeedToPauseNow()) { |
69 return TRUE; | 69 return true; |
70 } | 70 } |
71 } | 71 } |
72 return FALSE; | 72 return false; |
73 } | 73 } |
74 uint8_t* CCodec_ScanlineDecoder::ReadNextLine() | 74 uint8_t* CCodec_ScanlineDecoder::ReadNextLine() |
75 { | 75 { |
76 uint8_t* pLine = v_GetNextLine(); | 76 uint8_t* pLine = v_GetNextLine(); |
77 if (pLine == NULL) { | 77 if (pLine == NULL) { |
78 return NULL; | 78 return NULL; |
79 } | 79 } |
80 if (m_pDataCache && m_NextLine == m_pDataCache->m_nCachedLines) { | 80 if (m_pDataCache && m_NextLine == m_pDataCache->m_nCachedLines) { |
81 FXSYS_memcpy(&m_pDataCache->m_Data + m_NextLine * m_Pitch, pLine, m_Pitc
h); | 81 FXSYS_memcpy(&m_pDataCache->m_Data + m_NextLine * m_Pitch, pLine, m_Pitc
h); |
82 m_pDataCache->m_nCachedLines ++; | 82 m_pDataCache->m_nCachedLines ++; |
(...skipping 17 matching lines...) Expand all Loading... |
100 m_pDataCache = NULL; | 100 m_pDataCache = NULL; |
101 } | 101 } |
102 m_pDataCache = (CCodec_ImageDataCache*)FX_TryAlloc(uint8_t, sizeof(CCodec_Im
ageDataCache) + m_Pitch * m_OutputHeight); | 102 m_pDataCache = (CCodec_ImageDataCache*)FX_TryAlloc(uint8_t, sizeof(CCodec_Im
ageDataCache) + m_Pitch * m_OutputHeight); |
103 if (m_pDataCache == NULL) { | 103 if (m_pDataCache == NULL) { |
104 return; | 104 return; |
105 } | 105 } |
106 m_pDataCache->m_Height = m_OutputHeight; | 106 m_pDataCache->m_Height = m_OutputHeight; |
107 m_pDataCache->m_Width = m_OutputWidth; | 107 m_pDataCache->m_Width = m_OutputWidth; |
108 m_pDataCache->m_nCachedLines = 0; | 108 m_pDataCache->m_nCachedLines = 0; |
109 } | 109 } |
110 FX_BOOL CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf, FX_DWORD src
_size, uint8_t*& dest_buf, | 110 bool CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf, FX_DWORD src_si
ze, uint8_t*& dest_buf, |
111 FX_DWORD& dest_size) | 111 FX_DWORD& dest_size) |
112 { | 112 { |
113 return FALSE; | 113 return false; |
114 } | 114 } |
115 extern "C" double FXstrtod(const char* nptr, char** endptr) | 115 extern "C" double FXstrtod(const char* nptr, char** endptr) |
116 { | 116 { |
117 double ret = 0.0; | 117 double ret = 0.0; |
118 const char* ptr = nptr; | 118 const char* ptr = nptr; |
119 const char* exp_ptr = NULL; | 119 const char* exp_ptr = NULL; |
120 int e_number = 0, | 120 int e_number = 0, |
121 e_signal = 0, | 121 e_signal = 0, |
122 e_point = 0, | 122 e_point = 0, |
123 is_negative = 0; | 123 is_negative = 0; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 while(exp_ret--) { | 209 while(exp_ret--) { |
210 ret *= 10.0; | 210 ret *= 10.0; |
211 } | 211 } |
212 } else { | 212 } else { |
213 while(exp_ret--) { | 213 while(exp_ret--) { |
214 ret /= 10.0; | 214 ret /= 10.0; |
215 } | 215 } |
216 } | 216 } |
217 return is_negative ? -ret : ret; | 217 return is_negative ? -ret : ret; |
218 } | 218 } |
219 FX_BOOL CCodec_BasicModule::A85Encode(const uint8_t* src_buf, FX_DWORD src_size,
uint8_t*& dest_buf, | 219 bool CCodec_BasicModule::A85Encode(const uint8_t* src_buf, FX_DWORD src_size, ui
nt8_t*& dest_buf, |
220 FX_DWORD& dest_size) | 220 FX_DWORD& dest_size) |
221 { | 221 { |
222 return FALSE; | 222 return false; |
223 } | 223 } |
224 class CCodec_RLScanlineDecoder : public CCodec_ScanlineDecoder | 224 class CCodec_RLScanlineDecoder : public CCodec_ScanlineDecoder |
225 { | 225 { |
226 public: | 226 public: |
227 CCodec_RLScanlineDecoder(); | 227 CCodec_RLScanlineDecoder(); |
228 virtual ~CCodec_RLScanlineDecoder(); | 228 virtual ~CCodec_RLScanlineDecoder(); |
229 FX_BOOL» » » » Create(const uint8_t* src_buf, FX_DWORD
src_size, int width, int height, int nComps, int bpc); | 229 bool» » » » Create(const uint8_t* src_buf, FX_DWORD
src_size, int width, int height, int nComps, int bpc); |
230 virtual void v_DownScale(int dest_width, int dest_height) {} | 230 virtual void v_DownScale(int dest_width, int dest_height) {} |
231 virtual FX_BOOL» » v_Rewind(); | 231 virtual bool» » v_Rewind(); |
232 virtual uint8_t* v_GetNextLine(); | 232 virtual uint8_t* v_GetNextLine(); |
233 virtual FX_DWORD GetSrcOffset() | 233 virtual FX_DWORD GetSrcOffset() |
234 { | 234 { |
235 return m_SrcOffset; | 235 return m_SrcOffset; |
236 } | 236 } |
237 protected: | 237 protected: |
238 FX_BOOL» » » » CheckDestSize(); | 238 bool» » » » CheckDestSize(); |
239 void GetNextOperator(); | 239 void GetNextOperator(); |
240 void UpdateOperator(uint8_t used_bytes); | 240 void UpdateOperator(uint8_t used_bytes); |
241 | 241 |
242 uint8_t* m_pScanline; | 242 uint8_t* m_pScanline; |
243 const uint8_t* m_pSrcBuf; | 243 const uint8_t* m_pSrcBuf; |
244 FX_DWORD m_SrcSize; | 244 FX_DWORD m_SrcSize; |
245 FX_DWORD m_dwLineBytes; | 245 FX_DWORD m_dwLineBytes; |
246 FX_DWORD m_SrcOffset; | 246 FX_DWORD m_SrcOffset; |
247 FX_BOOL» » » » m_bEOD; | 247 bool» » » » m_bEOD; |
248 uint8_t m_Operator; | 248 uint8_t m_Operator; |
249 }; | 249 }; |
250 CCodec_RLScanlineDecoder::CCodec_RLScanlineDecoder() | 250 CCodec_RLScanlineDecoder::CCodec_RLScanlineDecoder() |
251 : m_pScanline(NULL) | 251 : m_pScanline(NULL) |
252 , m_pSrcBuf(NULL) | 252 , m_pSrcBuf(NULL) |
253 , m_SrcSize(0) | 253 , m_SrcSize(0) |
254 , m_dwLineBytes(0) | 254 , m_dwLineBytes(0) |
255 , m_SrcOffset(0) | 255 , m_SrcOffset(0) |
256 , m_bEOD(FALSE) | 256 , m_bEOD(false) |
257 , m_Operator(0) | 257 , m_Operator(0) |
258 { | 258 { |
259 } | 259 } |
260 CCodec_RLScanlineDecoder::~CCodec_RLScanlineDecoder() | 260 CCodec_RLScanlineDecoder::~CCodec_RLScanlineDecoder() |
261 { | 261 { |
262 if (m_pScanline) { | 262 if (m_pScanline) { |
263 FX_Free(m_pScanline); | 263 FX_Free(m_pScanline); |
264 } | 264 } |
265 } | 265 } |
266 FX_BOOL CCodec_RLScanlineDecoder::CheckDestSize() | 266 bool CCodec_RLScanlineDecoder::CheckDestSize() |
267 { | 267 { |
268 FX_DWORD i = 0; | 268 FX_DWORD i = 0; |
269 FX_DWORD old_size = 0; | 269 FX_DWORD old_size = 0; |
270 FX_DWORD dest_size = 0; | 270 FX_DWORD dest_size = 0; |
271 while (i < m_SrcSize) { | 271 while (i < m_SrcSize) { |
272 if (m_pSrcBuf[i] < 128) { | 272 if (m_pSrcBuf[i] < 128) { |
273 old_size = dest_size; | 273 old_size = dest_size; |
274 dest_size += m_pSrcBuf[i] + 1; | 274 dest_size += m_pSrcBuf[i] + 1; |
275 if (dest_size < old_size) { | 275 if (dest_size < old_size) { |
276 return FALSE; | 276 return false; |
277 } | 277 } |
278 i += m_pSrcBuf[i] + 2; | 278 i += m_pSrcBuf[i] + 2; |
279 } else if (m_pSrcBuf[i] > 128) { | 279 } else if (m_pSrcBuf[i] > 128) { |
280 old_size = dest_size; | 280 old_size = dest_size; |
281 dest_size += 257 - m_pSrcBuf[i]; | 281 dest_size += 257 - m_pSrcBuf[i]; |
282 if (dest_size < old_size) { | 282 if (dest_size < old_size) { |
283 return FALSE; | 283 return false; |
284 } | 284 } |
285 i += 2; | 285 i += 2; |
286 } else { | 286 } else { |
287 break; | 287 break; |
288 } | 288 } |
289 } | 289 } |
290 if (((FX_DWORD)m_OrigWidth * m_nComps * m_bpc * m_OrigHeight + 7) / 8 > dest
_size) { | 290 if (((FX_DWORD)m_OrigWidth * m_nComps * m_bpc * m_OrigHeight + 7) / 8 > dest
_size) { |
291 return FALSE; | 291 return false; |
292 } | 292 } |
293 return TRUE; | 293 return true; |
294 } | 294 } |
295 FX_BOOL CCodec_RLScanlineDecoder::Create(const uint8_t* src_buf, FX_DWORD src_si
ze, int width, int height, int nComps, int bpc) | 295 bool CCodec_RLScanlineDecoder::Create(const uint8_t* src_buf, FX_DWORD src_size,
int width, int height, int nComps, int bpc) |
296 { | 296 { |
297 m_pSrcBuf = src_buf; | 297 m_pSrcBuf = src_buf; |
298 m_SrcSize = src_size; | 298 m_SrcSize = src_size; |
299 m_OutputWidth = m_OrigWidth = width; | 299 m_OutputWidth = m_OrigWidth = width; |
300 m_OutputHeight = m_OrigHeight = height; | 300 m_OutputHeight = m_OrigHeight = height; |
301 m_nComps = nComps; | 301 m_nComps = nComps; |
302 m_bpc = bpc; | 302 m_bpc = bpc; |
303 m_bColorTransformed = FALSE; | 303 m_bColorTransformed = false; |
304 m_DownScale = 1; | 304 m_DownScale = 1; |
305 m_Pitch = (width * nComps * bpc + 31) / 32 * 4; | 305 m_Pitch = (width * nComps * bpc + 31) / 32 * 4; |
306 m_dwLineBytes = (width * nComps * bpc + 7) / 8; | 306 m_dwLineBytes = (width * nComps * bpc + 7) / 8; |
307 m_pScanline = FX_Alloc(uint8_t, m_Pitch); | 307 m_pScanline = FX_Alloc(uint8_t, m_Pitch); |
308 return CheckDestSize(); | 308 return CheckDestSize(); |
309 } | 309 } |
310 FX_BOOL CCodec_RLScanlineDecoder::v_Rewind() | 310 bool CCodec_RLScanlineDecoder::v_Rewind() |
311 { | 311 { |
312 FXSYS_memset(m_pScanline, 0, m_Pitch); | 312 FXSYS_memset(m_pScanline, 0, m_Pitch); |
313 m_SrcOffset = 0; | 313 m_SrcOffset = 0; |
314 m_bEOD = FALSE; | 314 m_bEOD = false; |
315 m_Operator = 0; | 315 m_Operator = 0; |
316 return TRUE; | 316 return true; |
317 } | 317 } |
318 uint8_t* CCodec_RLScanlineDecoder::v_GetNextLine() | 318 uint8_t* CCodec_RLScanlineDecoder::v_GetNextLine() |
319 { | 319 { |
320 if (m_SrcOffset == 0) { | 320 if (m_SrcOffset == 0) { |
321 GetNextOperator(); | 321 GetNextOperator(); |
322 } else { | 322 } else { |
323 if (m_bEOD) { | 323 if (m_bEOD) { |
324 return NULL; | 324 return NULL; |
325 } | 325 } |
326 } | 326 } |
327 FXSYS_memset(m_pScanline, 0, m_Pitch); | 327 FXSYS_memset(m_pScanline, 0, m_Pitch); |
328 FX_DWORD col_pos = 0; | 328 FX_DWORD col_pos = 0; |
329 FX_BOOL» eol = FALSE; | 329 bool» eol = false; |
330 while (m_SrcOffset < m_SrcSize && !eol) { | 330 while (m_SrcOffset < m_SrcSize && !eol) { |
331 if (m_Operator < 128) { | 331 if (m_Operator < 128) { |
332 FX_DWORD copy_len = m_Operator + 1; | 332 FX_DWORD copy_len = m_Operator + 1; |
333 if (col_pos + copy_len >= m_dwLineBytes) { | 333 if (col_pos + copy_len >= m_dwLineBytes) { |
334 copy_len = m_dwLineBytes - col_pos; | 334 copy_len = m_dwLineBytes - col_pos; |
335 eol = TRUE; | 335 eol = true; |
336 } | 336 } |
337 if (copy_len >= m_SrcSize - m_SrcOffset) { | 337 if (copy_len >= m_SrcSize - m_SrcOffset) { |
338 copy_len = m_SrcSize - m_SrcOffset; | 338 copy_len = m_SrcSize - m_SrcOffset; |
339 m_bEOD = TRUE; | 339 m_bEOD = true; |
340 } | 340 } |
341 FXSYS_memcpy(m_pScanline + col_pos, m_pSrcBuf + m_SrcOffset, copy_le
n); | 341 FXSYS_memcpy(m_pScanline + col_pos, m_pSrcBuf + m_SrcOffset, copy_le
n); |
342 col_pos += copy_len; | 342 col_pos += copy_len; |
343 UpdateOperator((uint8_t)copy_len); | 343 UpdateOperator((uint8_t)copy_len); |
344 } else if (m_Operator > 128) { | 344 } else if (m_Operator > 128) { |
345 int fill = 0; | 345 int fill = 0; |
346 if (m_SrcOffset - 1 < m_SrcSize - 1) { | 346 if (m_SrcOffset - 1 < m_SrcSize - 1) { |
347 fill = m_pSrcBuf[m_SrcOffset]; | 347 fill = m_pSrcBuf[m_SrcOffset]; |
348 } | 348 } |
349 FX_DWORD duplicate_len = 257 - m_Operator; | 349 FX_DWORD duplicate_len = 257 - m_Operator; |
350 if (col_pos + duplicate_len >= m_dwLineBytes) { | 350 if (col_pos + duplicate_len >= m_dwLineBytes) { |
351 duplicate_len = m_dwLineBytes - col_pos; | 351 duplicate_len = m_dwLineBytes - col_pos; |
352 eol = TRUE; | 352 eol = true; |
353 } | 353 } |
354 FXSYS_memset(m_pScanline + col_pos, fill, duplicate_len); | 354 FXSYS_memset(m_pScanline + col_pos, fill, duplicate_len); |
355 col_pos += duplicate_len; | 355 col_pos += duplicate_len; |
356 UpdateOperator((uint8_t)duplicate_len); | 356 UpdateOperator((uint8_t)duplicate_len); |
357 } else { | 357 } else { |
358 m_bEOD = TRUE; | 358 m_bEOD = true; |
359 break; | 359 break; |
360 } | 360 } |
361 } | 361 } |
362 return m_pScanline; | 362 return m_pScanline; |
363 } | 363 } |
364 void CCodec_RLScanlineDecoder::GetNextOperator() | 364 void CCodec_RLScanlineDecoder::GetNextOperator() |
365 { | 365 { |
366 if (m_SrcOffset >= m_SrcSize) { | 366 if (m_SrcOffset >= m_SrcSize) { |
367 m_Operator = 128; | 367 m_Operator = 128; |
368 return; | 368 return; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 ICodec_ScanlineDecoder* CCodec_BasicModule::CreateRunLengthDecoder(const uint8_t
* src_buf, FX_DWORD src_size, int width, int height, | 402 ICodec_ScanlineDecoder* CCodec_BasicModule::CreateRunLengthDecoder(const uint8_t
* src_buf, FX_DWORD src_size, int width, int height, |
403 int nComps, int bpc) | 403 int nComps, int bpc) |
404 { | 404 { |
405 CCodec_RLScanlineDecoder* pRLScanlineDecoder = new CCodec_RLScanlineDecoder; | 405 CCodec_RLScanlineDecoder* pRLScanlineDecoder = new CCodec_RLScanlineDecoder; |
406 if (!pRLScanlineDecoder->Create(src_buf, src_size, width, height, nComps, bp
c)) { | 406 if (!pRLScanlineDecoder->Create(src_buf, src_size, width, height, nComps, bp
c)) { |
407 delete pRLScanlineDecoder; | 407 delete pRLScanlineDecoder; |
408 return NULL; | 408 return NULL; |
409 } | 409 } |
410 return pRLScanlineDecoder; | 410 return pRLScanlineDecoder; |
411 } | 411 } |
OLD | NEW |