diff options
Diffstat (limited to 'core/fxcodec/codec')
-rw-r--r-- | core/fxcodec/codec/ccodec_faxmodule.cpp | 48 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_faxmodule.h | 22 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_flatemodule.cpp | 34 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_flatemodule.h | 22 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_jpxmodule.cpp | 10 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_jpxmodule.h | 8 |
6 files changed, 71 insertions, 73 deletions
diff --git a/core/fxcodec/codec/ccodec_faxmodule.cpp b/core/fxcodec/codec/ccodec_faxmodule.cpp index af218f7e01..faa40da6bf 100644 --- a/core/fxcodec/codec/ccodec_faxmodule.cpp +++ b/core/fxcodec/codec/ccodec_faxmodule.cpp @@ -450,8 +450,7 @@ void FaxGet1DLine(const uint8_t* src_buf, class CCodec_FaxDecoder final : public CCodec_ScanlineDecoder { public: - CCodec_FaxDecoder(const uint8_t* src_buf, - uint32_t src_size, + CCodec_FaxDecoder(pdfium::span<const uint8_t> src_span, int width, int height, uint32_t pitch, @@ -468,18 +467,16 @@ class CCodec_FaxDecoder final : public CCodec_ScanlineDecoder { private: const int m_Encoding; - int m_bitpos; - bool m_bByteAlign; + int m_bitpos = 0; + bool m_bByteAlign = false; const bool m_bEndOfLine; const bool m_bBlack; - const uint32_t m_SrcSize; - const uint8_t* const m_pSrcBuf; + pdfium::span<const uint8_t> const m_SrcSpan; std::vector<uint8_t> m_ScanlineBuf; std::vector<uint8_t> m_RefBuf; }; -CCodec_FaxDecoder::CCodec_FaxDecoder(const uint8_t* src_buf, - uint32_t src_size, +CCodec_FaxDecoder::CCodec_FaxDecoder(pdfium::span<const uint8_t> src_span, int width, int height, uint32_t pitch, @@ -489,12 +486,10 @@ CCodec_FaxDecoder::CCodec_FaxDecoder(const uint8_t* src_buf, bool BlackIs1) : CCodec_ScanlineDecoder(width, height, width, height, 1, 1, pitch), m_Encoding(K), - m_bitpos(0), m_bByteAlign(EncodedByteAlign), m_bEndOfLine(EndOfLine), m_bBlack(BlackIs1), - m_SrcSize(src_size), - m_pSrcBuf(src_buf), + m_SrcSpan(src_span), m_ScanlineBuf(pitch), m_RefBuf(pitch) {} @@ -507,35 +502,37 @@ bool CCodec_FaxDecoder::v_Rewind() { } uint8_t* CCodec_FaxDecoder::v_GetNextLine() { - int bitsize = m_SrcSize * 8; - FaxSkipEOL(m_pSrcBuf, bitsize, &m_bitpos); + int bitsize = m_SrcSpan.size() * 8; + FaxSkipEOL(m_SrcSpan.data(), bitsize, &m_bitpos); if (m_bitpos >= bitsize) return nullptr; memset(m_ScanlineBuf.data(), 0xff, m_ScanlineBuf.size()); if (m_Encoding < 0) { - FaxG4GetRow(m_pSrcBuf, bitsize, &m_bitpos, m_ScanlineBuf.data(), m_RefBuf, - m_OrigWidth); + FaxG4GetRow(m_SrcSpan.data(), bitsize, &m_bitpos, m_ScanlineBuf.data(), + m_RefBuf, m_OrigWidth); m_RefBuf = m_ScanlineBuf; } else if (m_Encoding == 0) { - FaxGet1DLine(m_pSrcBuf, bitsize, &m_bitpos, &m_ScanlineBuf, m_OrigWidth); + FaxGet1DLine(m_SrcSpan.data(), bitsize, &m_bitpos, &m_ScanlineBuf, + m_OrigWidth); } else { - if (NextBit(m_pSrcBuf, &m_bitpos)) { - FaxGet1DLine(m_pSrcBuf, bitsize, &m_bitpos, &m_ScanlineBuf, m_OrigWidth); + if (NextBit(m_SrcSpan.data(), &m_bitpos)) { + FaxGet1DLine(m_SrcSpan.data(), bitsize, &m_bitpos, &m_ScanlineBuf, + m_OrigWidth); } else { - FaxG4GetRow(m_pSrcBuf, bitsize, &m_bitpos, m_ScanlineBuf.data(), m_RefBuf, - m_OrigWidth); + FaxG4GetRow(m_SrcSpan.data(), bitsize, &m_bitpos, m_ScanlineBuf.data(), + m_RefBuf, m_OrigWidth); } m_RefBuf = m_ScanlineBuf; } if (m_bEndOfLine) - FaxSkipEOL(m_pSrcBuf, bitsize, &m_bitpos); + FaxSkipEOL(m_SrcSpan.data(), bitsize, &m_bitpos); if (m_bByteAlign && m_bitpos < bitsize) { int bitpos0 = m_bitpos; int bitpos1 = (m_bitpos + 7) / 8 * 8; while (m_bByteAlign && bitpos0 < bitpos1) { - int bit = m_pSrcBuf[bitpos0 / 8] & (1 << (7 - bitpos0 % 8)); + int bit = m_SrcSpan[bitpos0 / 8] & (1 << (7 - bitpos0 % 8)); if (bit != 0) m_bByteAlign = false; else @@ -555,7 +552,7 @@ uint8_t* CCodec_FaxDecoder::v_GetNextLine() { } uint32_t CCodec_FaxDecoder::GetSrcOffset() { - return std::min(static_cast<uint32_t>((m_bitpos + 7) / 8), m_SrcSize); + return std::min(static_cast<size_t>((m_bitpos + 7) / 8), m_SrcSpan.size()); } void FaxG4Decode(const uint8_t* src_buf, @@ -580,8 +577,7 @@ void FaxG4Decode(const uint8_t* src_buf, } std::unique_ptr<CCodec_ScanlineDecoder> CCodec_FaxModule::CreateDecoder( - const uint8_t* src_buf, - uint32_t src_size, + pdfium::span<const uint8_t> src_span, int width, int height, int K, @@ -603,7 +599,7 @@ std::unique_ptr<CCodec_ScanlineDecoder> CCodec_FaxModule::CreateDecoder( uint32_t pitch = (static_cast<uint32_t>(actual_width) + 31) / 32 * 4; return pdfium::MakeUnique<CCodec_FaxDecoder>( - src_buf, src_size, actual_width, actual_height, pitch, K, EndOfLine, + src_span, actual_width, actual_height, pitch, K, EndOfLine, EncodedByteAlign, BlackIs1); } diff --git a/core/fxcodec/codec/ccodec_faxmodule.h b/core/fxcodec/codec/ccodec_faxmodule.h index 4f8ab78ac4..3d546d741a 100644 --- a/core/fxcodec/codec/ccodec_faxmodule.h +++ b/core/fxcodec/codec/ccodec_faxmodule.h @@ -11,21 +11,23 @@ #include "core/fxcrt/fx_memory.h" #include "core/fxcrt/fx_system.h" +#include "third_party/base/span.h" class CCodec_ScanlineDecoder; class CCodec_FaxModule { public: - std::unique_ptr<CCodec_ScanlineDecoder> CreateDecoder(const uint8_t* src_buf, - uint32_t src_size, - int width, - int height, - int K, - bool EndOfLine, - bool EncodedByteAlign, - bool BlackIs1, - int Columns, - int Rows); + std::unique_ptr<CCodec_ScanlineDecoder> CreateDecoder( + pdfium::span<const uint8_t> src_buf, + int width, + int height, + int K, + bool EndOfLine, + bool EncodedByteAlign, + bool BlackIs1, + int Columns, + int Rows); + #if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ static void FaxEncode(const uint8_t* src_buf, int width, diff --git a/core/fxcodec/codec/ccodec_flatemodule.cpp b/core/fxcodec/codec/ccodec_flatemodule.cpp index 9074038c96..0a4baea38f 100644 --- a/core/fxcodec/codec/ccodec_flatemodule.cpp +++ b/core/fxcodec/codec/ccodec_flatemodule.cpp @@ -568,8 +568,7 @@ static PredictorType GetPredictor(int predictor) { class CCodec_FlateScanlineDecoder : public CCodec_ScanlineDecoder { public: - CCodec_FlateScanlineDecoder(const uint8_t* src_buf, - uint32_t src_size, + CCodec_FlateScanlineDecoder(pdfium::span<const uint8_t> src_buf, int width, int height, int nComps, @@ -587,12 +586,12 @@ class CCodec_FlateScanlineDecoder : public CCodec_ScanlineDecoder { std::unique_ptr<uint8_t, FxFreeDeleter> const m_pScanline; }; -CCodec_FlateScanlineDecoder::CCodec_FlateScanlineDecoder(const uint8_t* src_buf, - uint32_t src_size, - int width, - int height, - int nComps, - int bpc) +CCodec_FlateScanlineDecoder::CCodec_FlateScanlineDecoder( + pdfium::span<const uint8_t> src_span, + int width, + int height, + int nComps, + int bpc) : CCodec_ScanlineDecoder(width, height, width, @@ -600,7 +599,7 @@ CCodec_FlateScanlineDecoder::CCodec_FlateScanlineDecoder(const uint8_t* src_buf, nComps, bpc, CalculatePitch8(bpc, nComps, width).ValueOrDie()), - m_SrcBuf(src_buf, src_size), + m_SrcBuf(src_span), m_pScanline(FX_Alloc(uint8_t, m_Pitch)) {} CCodec_FlateScanlineDecoder::~CCodec_FlateScanlineDecoder() = default; @@ -626,8 +625,7 @@ uint32_t CCodec_FlateScanlineDecoder::GetSrcOffset() { class CCodec_FlatePredictorScanlineDecoder final : public CCodec_FlateScanlineDecoder { public: - CCodec_FlatePredictorScanlineDecoder(const uint8_t* src_buf, - uint32_t src_size, + CCodec_FlatePredictorScanlineDecoder(pdfium::span<const uint8_t> src_buf, int width, int height, int comps, @@ -658,8 +656,7 @@ class CCodec_FlatePredictorScanlineDecoder final }; CCodec_FlatePredictorScanlineDecoder::CCodec_FlatePredictorScanlineDecoder( - const uint8_t* src_buf, - uint32_t src_size, + pdfium::span<const uint8_t> src_span, int width, int height, int comps, @@ -668,7 +665,7 @@ CCodec_FlatePredictorScanlineDecoder::CCodec_FlatePredictorScanlineDecoder( int Colors, int BitsPerComponent, int Columns) - : CCodec_FlateScanlineDecoder(src_buf, src_size, width, height, comps, bpc), + : CCodec_FlateScanlineDecoder(src_span, width, height, comps, bpc), m_Predictor(predictor) { ASSERT(m_Predictor != PredictorType::kNone); if (BitsPerComponent * Colors * Columns == 0) { @@ -765,8 +762,7 @@ void CCodec_FlatePredictorScanlineDecoder::GetNextLineWithoutPredictedPitch() { } // namespace std::unique_ptr<CCodec_ScanlineDecoder> CCodec_FlateModule::CreateDecoder( - const uint8_t* src_buf, - uint32_t src_size, + pdfium::span<const uint8_t> src_span, int width, int height, int nComps, @@ -777,11 +773,11 @@ std::unique_ptr<CCodec_ScanlineDecoder> CCodec_FlateModule::CreateDecoder( int Columns) { PredictorType predictor_type = GetPredictor(predictor); if (predictor_type == PredictorType::kNone) { - return pdfium::MakeUnique<CCodec_FlateScanlineDecoder>( - src_buf, src_size, width, height, nComps, bpc); + return pdfium::MakeUnique<CCodec_FlateScanlineDecoder>(src_span, width, + height, nComps, bpc); } return pdfium::MakeUnique<CCodec_FlatePredictorScanlineDecoder>( - src_buf, src_size, width, height, nComps, bpc, predictor_type, Colors, + src_span, width, height, nComps, bpc, predictor_type, Colors, BitsPerComponent, Columns); } diff --git a/core/fxcodec/codec/ccodec_flatemodule.h b/core/fxcodec/codec/ccodec_flatemodule.h index c84be7cc87..dab34be8a0 100644 --- a/core/fxcodec/codec/ccodec_flatemodule.h +++ b/core/fxcodec/codec/ccodec_flatemodule.h @@ -10,21 +10,23 @@ #include <memory> #include "core/fxcrt/fx_system.h" +#include "third_party/base/span.h" class CCodec_ScanlineDecoder; class CCodec_FlateModule { public: - std::unique_ptr<CCodec_ScanlineDecoder> CreateDecoder(const uint8_t* src_buf, - uint32_t src_size, - int width, - int height, - int nComps, - int bpc, - int predictor, - int Colors, - int BitsPerComponent, - int Columns); + std::unique_ptr<CCodec_ScanlineDecoder> CreateDecoder( + pdfium::span<const uint8_t> src_buf, + int width, + int height, + int nComps, + int bpc, + int predictor, + int Colors, + int BitsPerComponent, + int Columns); + uint32_t FlateOrLZWDecode(bool bLZW, const uint8_t* src_buf, uint32_t src_size, diff --git a/core/fxcodec/codec/ccodec_jpxmodule.cpp b/core/fxcodec/codec/ccodec_jpxmodule.cpp index ce6a1301fd..28221be340 100644 --- a/core/fxcodec/codec/ccodec_jpxmodule.cpp +++ b/core/fxcodec/codec/ccodec_jpxmodule.cpp @@ -644,13 +644,13 @@ CCodec_JpxModule::CCodec_JpxModule() {} CCodec_JpxModule::~CCodec_JpxModule() {} std::unique_ptr<CJPX_Decoder> CCodec_JpxModule::CreateDecoder( - const uint8_t* src_buf, - uint32_t src_size, + pdfium::span<const uint8_t> src_span, CPDF_ColorSpace* cs) { auto decoder = pdfium::MakeUnique<CJPX_Decoder>(cs); - return decoder->Init(pdfium::make_span(src_buf, src_size)) - ? std::move(decoder) - : nullptr; + if (!decoder->Init(src_span)) + return nullptr; + + return decoder; } void CCodec_JpxModule::GetImageInfo(CJPX_Decoder* pDecoder, diff --git a/core/fxcodec/codec/ccodec_jpxmodule.h b/core/fxcodec/codec/ccodec_jpxmodule.h index 2a949862ca..2269ef3c62 100644 --- a/core/fxcodec/codec/ccodec_jpxmodule.h +++ b/core/fxcodec/codec/ccodec_jpxmodule.h @@ -11,6 +11,7 @@ #include <vector> #include "core/fxcrt/fx_system.h" +#include "third_party/base/span.h" class CJPX_Decoder; class CPDF_ColorSpace; @@ -20,9 +21,10 @@ class CCodec_JpxModule { CCodec_JpxModule(); ~CCodec_JpxModule(); - std::unique_ptr<CJPX_Decoder> CreateDecoder(const uint8_t* src_buf, - uint32_t src_size, - CPDF_ColorSpace* cs); + std::unique_ptr<CJPX_Decoder> CreateDecoder( + pdfium::span<const uint8_t> src_span, + CPDF_ColorSpace* cs); + void GetImageInfo(CJPX_Decoder* pDecoder, uint32_t* width, uint32_t* height, |