| 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 11 matching lines...) Expand all Loading... |
| 22 m_pJbig2Module(new CCodec_Jbig2Module), | 22 m_pJbig2Module(new CCodec_Jbig2Module), |
| 23 m_pIccModule(new CCodec_IccModule), | 23 m_pIccModule(new CCodec_IccModule), |
| 24 m_pFlateModule(new CCodec_FlateModule), | 24 m_pFlateModule(new CCodec_FlateModule), |
| 25 m_pPngModule(new CCodec_PngModule), | 25 m_pPngModule(new CCodec_PngModule), |
| 26 m_pGifModule(new CCodec_GifModule), | 26 m_pGifModule(new CCodec_GifModule), |
| 27 m_pBmpModule(new CCodec_BmpModule), | 27 m_pBmpModule(new CCodec_BmpModule), |
| 28 m_pTiffModule(new CCodec_TiffModule) {} | 28 m_pTiffModule(new CCodec_TiffModule) {} |
| 29 | 29 |
| 30 CCodec_ScanlineDecoder::ImageDataCache::ImageDataCache(int width, | 30 CCodec_ScanlineDecoder::ImageDataCache::ImageDataCache(int width, |
| 31 int height, | 31 int height, |
| 32 int pitch) | 32 FX_DWORD pitch) |
| 33 : m_Width(width), m_Height(height), m_Pitch(pitch), m_nCachedLines(0) { | 33 : m_Width(width), m_Height(height), m_Pitch(pitch), m_nCachedLines(0) {} |
| 34 } | |
| 35 | 34 |
| 36 CCodec_ScanlineDecoder::ImageDataCache::~ImageDataCache() { | 35 CCodec_ScanlineDecoder::ImageDataCache::~ImageDataCache() { |
| 37 } | 36 } |
| 38 | 37 |
| 39 bool CCodec_ScanlineDecoder::ImageDataCache::AllocateCache() { | 38 bool CCodec_ScanlineDecoder::ImageDataCache::AllocateCache() { |
| 40 if (m_Pitch <= 0 || m_Height < 0) | 39 if (m_Pitch == 0 || m_Height < 0) |
| 41 return false; | 40 return false; |
| 42 | 41 |
| 43 FX_SAFE_SIZE_T size = m_Pitch; | 42 FX_SAFE_SIZE_T size = m_Pitch; |
| 44 size *= m_Height; | 43 size *= m_Height; |
| 45 if (!size.IsValid()) | 44 if (!size.IsValid()) |
| 46 return false; | 45 return false; |
| 47 | 46 |
| 48 m_Data.reset(FX_TryAlloc(uint8_t, size.ValueOrDie())); | 47 m_Data.reset(FX_TryAlloc(uint8_t, size.ValueOrDie())); |
| 49 return IsValid(); | 48 return IsValid(); |
| 50 } | 49 } |
| 51 | 50 |
| 52 void CCodec_ScanlineDecoder::ImageDataCache::AppendLine(const uint8_t* line) { | 51 void CCodec_ScanlineDecoder::ImageDataCache::AppendLine(const uint8_t* line) { |
| 53 // If the callers adds more lines than there is room, fail. | 52 // If the callers adds more lines than there is room, fail. |
| 54 if (m_Pitch <= 0 || m_nCachedLines >= m_Height) { | 53 if (m_Pitch == 0 || m_nCachedLines >= m_Height) { |
| 55 NOTREACHED(); | 54 NOTREACHED(); |
| 56 return; | 55 return; |
| 57 } | 56 } |
| 58 | 57 |
| 59 size_t offset = m_Pitch; | 58 size_t offset = m_Pitch; |
| 60 FXSYS_memcpy(m_Data.get() + offset * m_nCachedLines, line, m_Pitch); | 59 FXSYS_memcpy(m_Data.get() + offset * m_nCachedLines, line, m_Pitch); |
| 61 ++m_nCachedLines; | 60 ++m_nCachedLines; |
| 62 } | 61 } |
| 63 | 62 |
| 64 const uint8_t* CCodec_ScanlineDecoder::ImageDataCache::GetLine(int line) const { | 63 const uint8_t* CCodec_ScanlineDecoder::ImageDataCache::GetLine(int line) const { |
| 65 if (m_Pitch <= 0 || line < 0 || line >= m_nCachedLines) | 64 if (m_Pitch == 0 || line < 0 || line >= m_nCachedLines) |
| 66 return nullptr; | 65 return nullptr; |
| 67 | 66 |
| 68 size_t offset = m_Pitch; | 67 size_t offset = m_Pitch; |
| 69 return m_Data.get() + offset * line; | 68 return m_Data.get() + offset * line; |
| 70 } | 69 } |
| 71 | 70 |
| 72 CCodec_ScanlineDecoder::CCodec_ScanlineDecoder() | 71 CCodec_ScanlineDecoder::CCodec_ScanlineDecoder() |
| 73 : m_NextLine(-1), m_pLastScanline(nullptr) { | 72 : m_NextLine(-1), m_pLastScanline(nullptr) { |
| 74 } | 73 } |
| 75 | 74 |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 int nComps, | 356 int nComps, |
| 358 int bpc) { | 357 int bpc) { |
| 359 m_pSrcBuf = src_buf; | 358 m_pSrcBuf = src_buf; |
| 360 m_SrcSize = src_size; | 359 m_SrcSize = src_size; |
| 361 m_OutputWidth = m_OrigWidth = width; | 360 m_OutputWidth = m_OrigWidth = width; |
| 362 m_OutputHeight = m_OrigHeight = height; | 361 m_OutputHeight = m_OrigHeight = height; |
| 363 m_nComps = nComps; | 362 m_nComps = nComps; |
| 364 m_bpc = bpc; | 363 m_bpc = bpc; |
| 365 m_bColorTransformed = FALSE; | 364 m_bColorTransformed = FALSE; |
| 366 m_DownScale = 1; | 365 m_DownScale = 1; |
| 367 m_Pitch = (width * nComps * bpc + 31) / 32 * 4; | 366 // Aligning the pitch to 4 bytes requires an integer overflow check. |
| 368 m_dwLineBytes = (width * nComps * bpc + 7) / 8; | 367 FX_SAFE_DWORD pitch = width; |
| 368 pitch *= nComps; |
| 369 pitch *= bpc; |
| 370 pitch += 31; |
| 371 pitch /= 32; |
| 372 pitch *= 4; |
| 373 if (!pitch.IsValid()) { |
| 374 return FALSE; |
| 375 } |
| 376 m_Pitch = pitch.ValueOrDie(); |
| 377 // Overflow should already have been checked before this is called. |
| 378 m_dwLineBytes = (static_cast<FX_DWORD>(width) * nComps * bpc + 7) / 8; |
| 369 m_pScanline = FX_Alloc(uint8_t, m_Pitch); | 379 m_pScanline = FX_Alloc(uint8_t, m_Pitch); |
| 370 return CheckDestSize(); | 380 return CheckDestSize(); |
| 371 } | 381 } |
| 372 FX_BOOL CCodec_RLScanlineDecoder::v_Rewind() { | 382 FX_BOOL CCodec_RLScanlineDecoder::v_Rewind() { |
| 373 FXSYS_memset(m_pScanline, 0, m_Pitch); | 383 FXSYS_memset(m_pScanline, 0, m_Pitch); |
| 374 m_SrcOffset = 0; | 384 m_SrcOffset = 0; |
| 375 m_bEOD = FALSE; | 385 m_bEOD = FALSE; |
| 376 m_Operator = 0; | 386 m_Operator = 0; |
| 377 return TRUE; | 387 return TRUE; |
| 378 } | 388 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 int nComps, | 475 int nComps, |
| 466 int bpc) { | 476 int bpc) { |
| 467 CCodec_RLScanlineDecoder* pRLScanlineDecoder = new CCodec_RLScanlineDecoder; | 477 CCodec_RLScanlineDecoder* pRLScanlineDecoder = new CCodec_RLScanlineDecoder; |
| 468 if (!pRLScanlineDecoder->Create(src_buf, src_size, width, height, nComps, | 478 if (!pRLScanlineDecoder->Create(src_buf, src_size, width, height, nComps, |
| 469 bpc)) { | 479 bpc)) { |
| 470 delete pRLScanlineDecoder; | 480 delete pRLScanlineDecoder; |
| 471 return NULL; | 481 return NULL; |
| 472 } | 482 } |
| 473 return pRLScanlineDecoder; | 483 return pRLScanlineDecoder; |
| 474 } | 484 } |
| OLD | NEW |