diff options
author | thestig <thestig@chromium.org> | 2016-04-05 15:53:32 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-05 15:53:32 -0700 |
commit | 54750b570d32898c8ebd4fa59105bfd3b96043af (patch) | |
tree | 25ffed24af8fba5f2bc76266c74335f6b92c63eb /core/fxcodec | |
parent | e5984e92ff378a86118f1e6428dc325dbde9c409 (diff) | |
download | pdfium-54750b570d32898c8ebd4fa59105bfd3b96043af.tar.xz |
Remove dead image decoding/caching code.
Review URL: https://codereview.chromium.org/1860223002
Diffstat (limited to 'core/fxcodec')
-rw-r--r-- | core/fxcodec/codec/codec_int.h | 31 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec.cpp | 75 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_fax.cpp | 2 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_flate.cpp | 2 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_jpeg.cpp | 41 |
5 files changed, 5 insertions, 146 deletions
diff --git a/core/fxcodec/codec/codec_int.h b/core/fxcodec/codec/codec_int.h index c7bd9fc6fe..7f0aaef379 100644 --- a/core/fxcodec/codec/codec_int.h +++ b/core/fxcodec/codec/codec_int.h @@ -47,59 +47,28 @@ class CCodec_ScanlineDecoder : public ICodec_ScanlineDecoder { ~CCodec_ScanlineDecoder() override; // ICodec_ScanlineDecoder - void DownScale(int dest_width, int dest_height) override; const uint8_t* GetScanline(int line) override; FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) override; int GetWidth() override { return m_OutputWidth; } int GetHeight() override { return m_OutputHeight; } int CountComps() override { return m_nComps; } int GetBPC() override { return m_bpc; } - FX_BOOL IsColorTransformed() override { return m_bColorTransformed; } - void ClearImageData() override { m_pDataCache.reset(); } protected: - class ImageDataCache { - public: - ImageDataCache(int width, int height, uint32_t pitch); - ~ImageDataCache(); - - bool AllocateCache(); - void AppendLine(const uint8_t* line); - - int NumLines() const { return m_nCachedLines; } - const uint8_t* GetLine(int line) const; - bool IsSameDimensions(int width, int height) const { - return width == m_Width && height == m_Height; - } - - private: - bool IsValid() const { return m_Data.get() != nullptr; } - - const int m_Width; - const int m_Height; - const uint32_t m_Pitch; - int m_nCachedLines; - std::unique_ptr<uint8_t, FxFreeDeleter> m_Data; - }; - virtual FX_BOOL v_Rewind() = 0; virtual uint8_t* v_GetNextLine() = 0; - virtual void v_DownScale(int dest_width, int dest_height) = 0; uint8_t* ReadNextLine(); int m_OrigWidth; int m_OrigHeight; - int m_DownScale; int m_OutputWidth; int m_OutputHeight; int m_nComps; int m_bpc; uint32_t m_Pitch; - FX_BOOL m_bColorTransformed; int m_NextLine; uint8_t* m_pLastScanline; - std::unique_ptr<ImageDataCache> m_pDataCache; }; class CCodec_FaxModule : public ICodec_FaxModule { diff --git a/core/fxcodec/codec/fx_codec.cpp b/core/fxcodec/codec/fx_codec.cpp index 0952c809ac..79e5da27c8 100644 --- a/core/fxcodec/codec/fx_codec.cpp +++ b/core/fxcodec/codec/fx_codec.cpp @@ -30,55 +30,12 @@ CCodec_ModuleMgr::CCodec_ModuleMgr() m_pFlateModule(new CCodec_FlateModule) { } -CCodec_ScanlineDecoder::ImageDataCache::ImageDataCache(int width, - int height, - uint32_t pitch) - : m_Width(width), m_Height(height), m_Pitch(pitch), m_nCachedLines(0) {} - -CCodec_ScanlineDecoder::ImageDataCache::~ImageDataCache() {} - -bool CCodec_ScanlineDecoder::ImageDataCache::AllocateCache() { - if (m_Pitch == 0 || m_Height < 0) - return false; - - FX_SAFE_SIZE_T size = m_Pitch; - size *= m_Height; - if (!size.IsValid()) - return false; - - m_Data.reset(FX_TryAlloc(uint8_t, size.ValueOrDie())); - return IsValid(); -} - -void CCodec_ScanlineDecoder::ImageDataCache::AppendLine(const uint8_t* line) { - // If the callers adds more lines than there is room, fail. - if (m_Pitch == 0 || m_nCachedLines >= m_Height) { - NOTREACHED(); - return; - } - - size_t offset = m_Pitch; - FXSYS_memcpy(m_Data.get() + offset * m_nCachedLines, line, m_Pitch); - ++m_nCachedLines; -} - -const uint8_t* CCodec_ScanlineDecoder::ImageDataCache::GetLine(int line) const { - if (m_Pitch == 0 || line < 0 || line >= m_nCachedLines) - return nullptr; - - size_t offset = m_Pitch; - return m_Data.get() + offset * line; -} - CCodec_ScanlineDecoder::CCodec_ScanlineDecoder() : m_NextLine(-1), m_pLastScanline(nullptr) {} CCodec_ScanlineDecoder::~CCodec_ScanlineDecoder() {} const uint8_t* CCodec_ScanlineDecoder::GetScanline(int line) { - if (m_pDataCache && line < m_pDataCache->NumLines()) - return m_pDataCache->GetLine(line); - if (m_NextLine == line + 1) return m_pLastScanline; @@ -97,9 +54,6 @@ const uint8_t* CCodec_ScanlineDecoder::GetScanline(int line) { } FX_BOOL CCodec_ScanlineDecoder::SkipToScanline(int line, IFX_Pause* pPause) { - if (m_pDataCache && line < m_pDataCache->NumLines()) - return FALSE; - if (m_NextLine == line || m_NextLine == line + 1) return FALSE; @@ -119,31 +73,7 @@ FX_BOOL CCodec_ScanlineDecoder::SkipToScanline(int line, IFX_Pause* pPause) { } uint8_t* CCodec_ScanlineDecoder::ReadNextLine() { - uint8_t* pLine = v_GetNextLine(); - if (!pLine) - return nullptr; - - if (m_pDataCache && m_NextLine == m_pDataCache->NumLines()) - m_pDataCache->AppendLine(pLine); - return pLine; -} - -void CCodec_ScanlineDecoder::DownScale(int dest_width, int dest_height) { - dest_width = std::abs(dest_width); - dest_height = std::abs(dest_height); - v_DownScale(dest_width, dest_height); - - if (m_pDataCache && - m_pDataCache->IsSameDimensions(m_OutputWidth, m_OutputHeight)) { - return; - } - - std::unique_ptr<ImageDataCache> cache( - new ImageDataCache(m_OutputWidth, m_OutputHeight, m_Pitch)); - if (!cache->AllocateCache()) - return; - - m_pDataCache = std::move(cache); + return v_GetNextLine(); } FX_BOOL CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf, @@ -294,7 +224,6 @@ class CCodec_RLScanlineDecoder : public CCodec_ScanlineDecoder { int bpc); // CCodec_ScanlineDecoder - void v_DownScale(int dest_width, int dest_height) override {} FX_BOOL v_Rewind() override; uint8_t* v_GetNextLine() override; uint32_t GetSrcOffset() override { return m_SrcOffset; } @@ -364,8 +293,6 @@ FX_BOOL CCodec_RLScanlineDecoder::Create(const uint8_t* src_buf, m_OutputHeight = m_OrigHeight = height; m_nComps = nComps; m_bpc = bpc; - m_bColorTransformed = FALSE; - m_DownScale = 1; // Aligning the pitch to 4 bytes requires an integer overflow check. FX_SAFE_DWORD pitch = width; pitch *= nComps; diff --git a/core/fxcodec/codec/fx_codec_fax.cpp b/core/fxcodec/codec/fx_codec_fax.cpp index 0ccebba14e..6b90b15e51 100644 --- a/core/fxcodec/codec/fx_codec_fax.cpp +++ b/core/fxcodec/codec/fx_codec_fax.cpp @@ -613,7 +613,6 @@ class CCodec_FaxDecoder : public CCodec_ScanlineDecoder { int Rows); // CCodec_ScanlineDecoder - void v_DownScale(int dest_width, int dest_height) override {} FX_BOOL v_Rewind() override; uint8_t* v_GetNextLine() override; uint32_t GetSrcOffset() override; @@ -666,7 +665,6 @@ FX_BOOL CCodec_FaxDecoder::Create(const uint8_t* src_buf, m_SrcSize = src_size; m_nComps = 1; m_bpc = 1; - m_bColorTransformed = FALSE; return TRUE; } FX_BOOL CCodec_FaxDecoder::v_Rewind() { diff --git a/core/fxcodec/codec/fx_codec_flate.cpp b/core/fxcodec/codec/fx_codec_flate.cpp index 6961dcccb3..2350eb1a88 100644 --- a/core/fxcodec/codec/fx_codec_flate.cpp +++ b/core/fxcodec/codec/fx_codec_flate.cpp @@ -753,7 +753,6 @@ class CCodec_FlateScanlineDecoder : public CCodec_ScanlineDecoder { void Destroy() { delete this; } // CCodec_ScanlineDecoder - void v_DownScale(int dest_width, int dest_height) override {} FX_BOOL v_Rewind() override; uint8_t* v_GetNextLine() override; uint32_t GetSrcOffset() override; @@ -806,7 +805,6 @@ void CCodec_FlateScanlineDecoder::Create(const uint8_t* src_buf, m_OutputHeight = m_OrigHeight = height; m_nComps = nComps; m_bpc = bpc; - m_bColorTransformed = FALSE; m_Pitch = (static_cast<uint32_t>(width) * nComps * bpc + 7) / 8; m_pScanline = FX_Alloc(uint8_t, m_Pitch); m_Predictor = 0; diff --git a/core/fxcodec/codec/fx_codec_jpeg.cpp b/core/fxcodec/codec/fx_codec_jpeg.cpp index a81926e053..553e237b32 100644 --- a/core/fxcodec/codec/fx_codec_jpeg.cpp +++ b/core/fxcodec/codec/fx_codec_jpeg.cpp @@ -321,7 +321,6 @@ class CCodec_JpegDecoder : public CCodec_ScanlineDecoder { void Destroy() { delete this; } // CCodec_ScanlineDecoder - void v_DownScale(int dest_width, int dest_height) override; FX_BOOL v_Rewind() override; uint8_t* v_GetNextLine() override; uint32_t GetSrcOffset() override; @@ -346,7 +345,6 @@ class CCodec_JpegDecoder : public CCodec_ScanlineDecoder { CCodec_JpegDecoder::CCodec_JpegDecoder() { m_pScanlineBuf = NULL; - m_DownScale = 1; m_bStarted = FALSE; m_bInited = FALSE; FXSYS_memset(&cinfo, 0, sizeof(cinfo)); @@ -437,41 +435,10 @@ FX_BOOL CCodec_JpegDecoder::Create(const uint8_t* src_buf, m_pScanlineBuf = FX_Alloc(uint8_t, m_Pitch); m_nComps = cinfo.num_components; m_bpc = 8; - m_bColorTransformed = FALSE; m_bStarted = FALSE; return TRUE; } -extern "C" { -int32_t FX_GetDownsampleRatio(int32_t originWidth, - int32_t originHeight, - int32_t downsampleWidth, - int32_t downsampleHeight) { - int iratio_w = originWidth / downsampleWidth; - int iratio_h = originHeight / downsampleHeight; - int ratio = (iratio_w > iratio_h) ? iratio_h : iratio_w; - if (ratio >= 8) { - return 8; - } - if (ratio >= 4) { - return 4; - } - if (ratio >= 2) { - return 2; - } - return 1; -} -} -void CCodec_JpegDecoder::v_DownScale(int dest_width, int dest_height) { - int old_scale = m_DownScale; - m_DownScale = - FX_GetDownsampleRatio(m_OrigWidth, m_OrigHeight, dest_width, dest_height); - m_OutputWidth = (m_OrigWidth + m_DownScale - 1) / m_DownScale; - m_OutputHeight = (m_OrigHeight + m_DownScale - 1) / m_DownScale; - m_Pitch = (static_cast<uint32_t>(m_OutputWidth) * m_nComps + 3) / 4 * 4; - if (old_scale != m_DownScale) { - m_NextLine = -1; - } -} + FX_BOOL CCodec_JpegDecoder::v_Rewind() { if (m_bStarted) { jpeg_destroy_decompress(&cinfo); @@ -482,9 +449,9 @@ FX_BOOL CCodec_JpegDecoder::v_Rewind() { if (setjmp(m_JmpBuf) == -1) { return FALSE; } - cinfo.scale_denom = m_nDefaultScaleDenom * m_DownScale; - m_OutputWidth = (m_OrigWidth + m_DownScale - 1) / m_DownScale; - m_OutputHeight = (m_OrigHeight + m_DownScale - 1) / m_DownScale; + cinfo.scale_denom = m_nDefaultScaleDenom; + m_OutputWidth = m_OrigWidth; + m_OutputHeight = m_OrigHeight; if (!jpeg_start_decompress(&cinfo)) { jpeg_destroy_decompress(&cinfo); return FALSE; |