From e95f39f10400746f0dc49c8afe3b3f21cdbbf381 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 1 Oct 2015 14:08:32 -0700 Subject: Merge to XFA: Clean up some image decoder classes: - Use std::vector instead of raw uint8_t* - Make ICodec_ScanlineDecoder::GetScanline() return const uint8_t* - Add FxFreeDeleter, use it in CCodec_ImageDataCache. - Make CCodec_ImageDataCache encapsulate its data members. TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1361053002 . (cherry picked from commit 022da0014faa103901ec107ed6a33e5ab00c7931) Review URL: https://codereview.chromium.org/1372993003 . --- core/src/fxcodec/codec/codec_int.h | 73 ++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 35 deletions(-) (limited to 'core/src/fxcodec/codec/codec_int.h') diff --git a/core/src/fxcodec/codec/codec_int.h b/core/src/fxcodec/codec/codec_int.h index a37f7bd7b8..dad2953e12 100644 --- a/core/src/fxcodec/codec/codec_int.h +++ b/core/src/fxcodec/codec/codec_int.h @@ -11,6 +11,7 @@ #include #include +#include "../../../../third_party/base/nonstd_unique_ptr.h" #include "../../../../third_party/libopenjpeg20/openjpeg.h" // For OPJ_SIZE_T. #include "../../../include/fxcodec/fx_codec.h" #include "../jbig2/JBig2_Context.h" @@ -36,12 +37,6 @@ class CCodec_BasicModule : public ICodec_BasicModule { int bpc); }; -struct CCodec_ImageDataCache { - int m_Width, m_Height; - int m_nCachedLines; - uint8_t m_Data; -}; - class CCodec_ScanlineDecoder : public ICodec_ScanlineDecoder { public: CCodec_ScanlineDecoder(); @@ -50,50 +45,58 @@ class CCodec_ScanlineDecoder : public ICodec_ScanlineDecoder { // ICodec_ScanlineDecoder FX_DWORD GetSrcOffset() override { return -1; } void DownScale(int dest_width, int dest_height) override; - uint8_t* GetScanline(int line) 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 { - FX_Free(m_pDataCache); - m_pDataCache = NULL; - } + void ClearImageData() override { m_pDataCache.reset(); } protected: - int m_OrigWidth; + class ImageDataCache { + public: + ImageDataCache(int width, int height, int 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 int m_Pitch; + int m_nCachedLines; + nonstd::unique_ptr m_Data; + }; - int m_OrigHeight; + virtual FX_BOOL v_Rewind() = 0; + virtual uint8_t* v_GetNextLine() = 0; + virtual void v_DownScale(int dest_width, int dest_height) = 0; - int m_DownScale; + uint8_t* ReadNextLine(); + int m_OrigWidth; + int m_OrigHeight; + int m_DownScale; int m_OutputWidth; - int m_OutputHeight; - int m_nComps; - int m_bpc; - int m_Pitch; - FX_BOOL m_bColorTransformed; - - uint8_t* ReadNextLine(); - - virtual FX_BOOL v_Rewind() = 0; - - virtual uint8_t* v_GetNextLine() = 0; - - virtual void v_DownScale(int dest_width, int dest_height) = 0; - int m_NextLine; - uint8_t* m_pLastScanline; - - CCodec_ImageDataCache* m_pDataCache; + nonstd::unique_ptr m_pDataCache; }; class CCodec_FaxModule : public ICodec_FaxModule { @@ -321,10 +324,10 @@ class CCodec_JpxModule : public ICodec_JpxModule { FX_DWORD* width, FX_DWORD* height, FX_DWORD* components) override; - FX_BOOL Decode(CJPX_Decoder* pDecoder, - uint8_t* dest_data, - int pitch, - uint8_t* offsets) override; + bool Decode(CJPX_Decoder* pDecoder, + uint8_t* dest_data, + int pitch, + const std::vector& offsets) override; void DestroyDecoder(CJPX_Decoder* pDecoder) override; }; -- cgit v1.2.3