diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfapi/fpdf_render/cpdf_pagerendercache.h | 1 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render_cache.cpp | 10 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp | 14 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/render_int.h | 4 | ||||
-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 | ||||
-rw-r--r-- | core/include/fxcodec/fx_codec.h | 6 | ||||
-rw-r--r-- | core/include/fxge/fx_dib.h | 1 |
11 files changed, 7 insertions, 180 deletions
diff --git a/core/fpdfapi/fpdf_render/cpdf_pagerendercache.h b/core/fpdfapi/fpdf_render/cpdf_pagerendercache.h index 4e47e019b4..4f9ea1fe46 100644 --- a/core/fpdfapi/fpdf_render/cpdf_pagerendercache.h +++ b/core/fpdfapi/fpdf_render/cpdf_pagerendercache.h @@ -28,7 +28,6 @@ class CPDF_PageRenderCache { m_nCacheSize(0), m_bCurFindCache(FALSE) {} ~CPDF_PageRenderCache(); - void ClearImageData(); uint32_t EstimateSize(); void CacheOptimization(int32_t dwLimitCacheSize); diff --git a/core/fpdfapi/fpdf_render/fpdf_render_cache.cpp b/core/fpdfapi/fpdf_render/fpdf_render_cache.cpp index f5bc584348..a2592004e7 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_cache.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_cache.cpp @@ -188,15 +188,7 @@ void CPDF_ImageCacheEntry::Reset(const CFX_DIBitmap* pBitmap) { } CalcSize(); } -void CPDF_PageRenderCache::ClearImageData() { - for (const auto& it : m_ImageCache) - it.second->ClearImageData(); -} -void CPDF_ImageCacheEntry::ClearImageData() { - if (m_pCachedBitmap && !m_pCachedBitmap->GetBuffer()) { - ((CPDF_DIBSource*)m_pCachedBitmap)->ClearImageData(); - } -} + static uint32_t FPDF_ImageCache_EstimateImageSize(const CFX_DIBSource* pDIB) { return pDIB && pDIB->GetBuffer() ? (uint32_t)pDIB->GetHeight() * pDIB->GetPitch() + diff --git a/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp index 144de779e9..7a4a36e1cf 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp @@ -1474,20 +1474,6 @@ FX_BOOL CPDF_DIBSource::TransMask() const { m_Family == PDFCS_DEVICECMYK; } -void CPDF_DIBSource::SetDownSampleSize(int dest_width, int dest_height) { - if (m_pDecoder) { - m_pDecoder->DownScale(dest_width, dest_height); - m_Width = m_pDecoder->GetWidth(); - m_Height = m_pDecoder->GetHeight(); - } -} - -void CPDF_DIBSource::ClearImageData() { - if (m_pDecoder) { - m_pDecoder->ClearImageData(); - } -} - CPDF_ImageLoaderHandle::CPDF_ImageLoaderHandle() { m_pImageLoader = nullptr; m_pCache = nullptr; diff --git a/core/fpdfapi/fpdf_render/render_int.h b/core/fpdfapi/fpdf_render/render_int.h index b22b9fc39b..eab6c9ff21 100644 --- a/core/fpdfapi/fpdf_render/render_int.h +++ b/core/fpdfapi/fpdf_render/render_int.h @@ -443,7 +443,7 @@ class CPDF_ImageCacheEntry { public: CPDF_ImageCacheEntry(CPDF_Document* pDoc, CPDF_Stream* pStream); ~CPDF_ImageCacheEntry(); - void ClearImageData(); + void Reset(const CFX_DIBitmap* pBitmap); FX_BOOL GetCachedBitmap(CFX_DIBSource*& pBitmap, CFX_DIBSource*& pMask, @@ -521,11 +521,9 @@ class CPDF_DIBSource : public CFX_DIBSource { FX_BOOL bFlipX, int clip_left, int clip_width) const override; - void SetDownSampleSize(int dest_width, int dest_height) override; CFX_DIBitmap* GetBitmap() const; void ReleaseBitmap(CFX_DIBitmap* pBitmap) const; - void ClearImageData(); uint32_t GetMatteColor() const { return m_MatteColor; } int StartLoadDIBSource(CPDF_Document* pDoc, 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; diff --git a/core/include/fxcodec/fx_codec.h b/core/include/fxcodec/fx_codec.h index a674eb7290..9db5e8c34b 100644 --- a/core/include/fxcodec/fx_codec.h +++ b/core/include/fxcodec/fx_codec.h @@ -118,8 +118,6 @@ class ICodec_ScanlineDecoder { virtual uint32_t GetSrcOffset() = 0; - virtual void DownScale(int dest_width, int dest_height) = 0; - virtual const uint8_t* GetScanline(int line) = 0; virtual FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) = 0; @@ -131,10 +129,6 @@ class ICodec_ScanlineDecoder { virtual int CountComps() = 0; virtual int GetBPC() = 0; - - virtual FX_BOOL IsColorTransformed() = 0; - - virtual void ClearImageData() = 0; }; class ICodec_FlateModule { diff --git a/core/include/fxge/fx_dib.h b/core/include/fxge/fx_dib.h index 09081786ef..59a494182c 100644 --- a/core/include/fxge/fx_dib.h +++ b/core/include/fxge/fx_dib.h @@ -181,7 +181,6 @@ class CFX_DIBSource { FX_BOOL bFlipX, int clip_left, int clip_width) const = 0; - virtual void SetDownSampleSize(int width, int height) {} int GetBPP() const { return m_bpp; } |