Rename CCodec_ScanlineDecoder to fxcodec::ScanlineDecoder.
Fix some nits in ScanlineDecoder along the way.
BUG=pdfium:1311
Change-Id: I35badf4cd33e659ea10efb00a2b8faabf3bb102a
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/55834
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index c026115..6d51136 100644
--- a/core/fpdfapi/page/cpdf_streamparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamparser.cpp
@@ -26,8 +26,8 @@
#include "core/fpdfapi/parser/cpdf_string.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
#include "core/fpdfapi/parser/fpdf_parser_utility.h"
-#include "core/fxcodec/codec/ccodec_scanlinedecoder.h"
#include "core/fxcodec/codec/jpegmodule.h"
+#include "core/fxcodec/codec/scanlinedecoder.h"
#include "core/fxcodec/fx_codec.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_safe_types.h"
@@ -42,7 +42,7 @@
const char kFalse[] = "false";
const char kNull[] = "null";
-uint32_t DecodeAllScanlines(std::unique_ptr<CCodec_ScanlineDecoder> pDecoder) {
+uint32_t DecodeAllScanlines(std::unique_ptr<ScanlineDecoder> pDecoder) {
if (!pDecoder)
return FX_INVALID_OFFSET;
@@ -91,14 +91,14 @@
&ignored_size);
}
if (decoder == "DCTDecode") {
- std::unique_ptr<CCodec_ScanlineDecoder> pDecoder =
+ std::unique_ptr<ScanlineDecoder> pDecoder =
CCodec_ModuleMgr::GetInstance()->GetJpegModule()->CreateDecoder(
src_span, width, height, 0,
!pParam || pParam->GetIntegerFor("ColorTransform", 1));
return DecodeAllScanlines(std::move(pDecoder));
}
if (decoder == "CCITTFaxDecode") {
- std::unique_ptr<CCodec_ScanlineDecoder> pDecoder =
+ std::unique_ptr<ScanlineDecoder> pDecoder =
CreateFaxDecoder(src_span, width, height, pParam);
return DecodeAllScanlines(std::move(pDecoder));
}
diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp
index 5e2085d..60692af 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp
@@ -17,9 +17,9 @@
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/fpdf_parser_utility.h"
-#include "core/fxcodec/codec/ccodec_scanlinedecoder.h"
#include "core/fxcodec/codec/faxmodule.h"
#include "core/fxcodec/codec/flatemodule.h"
+#include "core/fxcodec/codec/scanlinedecoder.h"
#include "core/fxcodec/fx_codec.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_safe_types.h"
@@ -291,7 +291,7 @@
return std::min(i + 1, src_span.size());
}
-std::unique_ptr<CCodec_ScanlineDecoder> CreateFaxDecoder(
+std::unique_ptr<ScanlineDecoder> CreateFaxDecoder(
pdfium::span<const uint8_t> src_span,
int width,
int height,
@@ -316,7 +316,7 @@
ByteAlign, BlackIs1, Columns, Rows);
}
-std::unique_ptr<CCodec_ScanlineDecoder> CreateFlateDecoder(
+std::unique_ptr<ScanlineDecoder> CreateFlateDecoder(
pdfium::span<const uint8_t> src_span,
int width,
int height,
diff --git a/core/fpdfapi/parser/fpdf_parser_decode.h b/core/fpdfapi/parser/fpdf_parser_decode.h
index 25213c5..6442bf1 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode.h
+++ b/core/fpdfapi/parser/fpdf_parser_decode.h
@@ -14,10 +14,13 @@
#include "core/fxcrt/unowned_ptr.h"
#include "third_party/base/span.h"
-class CCodec_ScanlineDecoder;
class CPDF_Array;
class CPDF_Dictionary;
+namespace fxcodec {
+class ScanlineDecoder;
+}
+
// Indexed by 8-bit char code, contains unicode code points.
extern const uint16_t PDFDocEncoding[256];
@@ -27,13 +30,13 @@
WideString PDF_DecodeText(pdfium::span<const uint8_t> span);
ByteString PDF_EncodeText(const WideString& str);
-std::unique_ptr<CCodec_ScanlineDecoder> CreateFaxDecoder(
+std::unique_ptr<fxcodec::ScanlineDecoder> CreateFaxDecoder(
pdfium::span<const uint8_t> src_span,
int width,
int height,
const CPDF_Dictionary* pParams);
-std::unique_ptr<CCodec_ScanlineDecoder> CreateFlateDecoder(
+std::unique_ptr<fxcodec::ScanlineDecoder> CreateFlateDecoder(
pdfium::span<const uint8_t> src_span,
int width,
int height,
diff --git a/core/fpdfapi/render/cpdf_dibbase.cpp b/core/fpdfapi/render/cpdf_dibbase.cpp
index 9e270aa..bc1c567 100644
--- a/core/fpdfapi/render/cpdf_dibbase.cpp
+++ b/core/fpdfapi/render/cpdf_dibbase.cpp
@@ -24,11 +24,11 @@
#include "core/fpdfapi/render/cpdf_pagerendercache.h"
#include "core/fpdfapi/render/cpdf_renderstatus.h"
#include "core/fxcodec/codec/basicmodule.h"
-#include "core/fxcodec/codec/ccodec_scanlinedecoder.h"
#include "core/fxcodec/codec/cjpx_decoder.h"
#include "core/fxcodec/codec/jbig2module.h"
#include "core/fxcodec/codec/jpegmodule.h"
#include "core/fxcodec/codec/jpxmodule.h"
+#include "core/fxcodec/codec/scanlinedecoder.h"
#include "core/fxcodec/fx_codec.h"
#include "core/fxcrt/cfx_fixedbufgrow.h"
#include "core/fxcrt/fx_safe_types.h"
diff --git a/core/fpdfapi/render/cpdf_dibbase.h b/core/fpdfapi/render/cpdf_dibbase.h
index f1c7d56..92d192a 100644
--- a/core/fpdfapi/render/cpdf_dibbase.h
+++ b/core/fpdfapi/render/cpdf_dibbase.h
@@ -21,7 +21,6 @@
#include "core/fxge/dib/cfx_dibbase.h"
#include "third_party/base/span.h"
-class CCodec_ScanlineDecoder;
class CPDF_Color;
class CPDF_Dictionary;
class CPDF_Document;
@@ -37,6 +36,7 @@
namespace fxcodec {
class Jbig2Context;
+class ScanlineDecoder;
}
#define FPDF_HUGE_IMAGE_SIZE 60000000
@@ -152,7 +152,7 @@
RetainPtr<CFX_DIBitmap> m_pCachedBitmap;
RetainPtr<CPDF_DIBBase> m_pMask;
RetainPtr<CPDF_StreamAcc> m_pGlobalAcc;
- std::unique_ptr<CCodec_ScanlineDecoder> m_pDecoder;
+ std::unique_ptr<fxcodec::ScanlineDecoder> m_pDecoder;
// Must come after |m_pCachedBitmap|.
std::unique_ptr<fxcodec::Jbig2Context> m_pJbig2Context;
diff --git a/core/fxcodec/BUILD.gn b/core/fxcodec/BUILD.gn
index e6f24e8..0954de7 100644
--- a/core/fxcodec/BUILD.gn
+++ b/core/fxcodec/BUILD.gn
@@ -12,8 +12,6 @@
"JBig2_DocumentContext.h",
"codec/basicmodule.cpp",
"codec/basicmodule.h",
- "codec/ccodec_scanlinedecoder.cpp",
- "codec/ccodec_scanlinedecoder.h",
"codec/cfx_codec_memory.cpp",
"codec/cfx_codec_memory.h",
"codec/cjpx_decoder.cpp",
@@ -33,6 +31,8 @@
"codec/jpegmodule.h",
"codec/jpxmodule.cpp",
"codec/jpxmodule.h",
+ "codec/scanlinedecoder.cpp",
+ "codec/scanlinedecoder.h",
"fx_codec.h",
"fx_codec_def.h",
"jbig2/JBig2_ArithDecoder.cpp",
diff --git a/core/fxcodec/codec/basicmodule.cpp b/core/fxcodec/codec/basicmodule.cpp
index f324133..7de2944 100644
--- a/core/fxcodec/codec/basicmodule.cpp
+++ b/core/fxcodec/codec/basicmodule.cpp
@@ -7,14 +7,14 @@
#include <algorithm>
#include <utility>
-#include "core/fxcodec/codec/ccodec_scanlinedecoder.h"
+#include "core/fxcodec/codec/scanlinedecoder.h"
#include "third_party/base/ptr_util.h"
namespace fxcodec {
namespace {
-class RLScanlineDecoder final : public CCodec_ScanlineDecoder {
+class RLScanlineDecoder final : public ScanlineDecoder {
public:
RLScanlineDecoder();
~RLScanlineDecoder() override;
@@ -25,7 +25,7 @@
int nComps,
int bpc);
- // CCodec_ScanlineDecoder
+ // ScanlineDecoder:
bool v_Rewind() override;
uint8_t* v_GetNextLine() override;
uint32_t GetSrcOffset() override { return m_SrcOffset; }
@@ -197,7 +197,7 @@
} // namespace
// static
-std::unique_ptr<CCodec_ScanlineDecoder> BasicModule::CreateRunLengthDecoder(
+std::unique_ptr<ScanlineDecoder> BasicModule::CreateRunLengthDecoder(
pdfium::span<const uint8_t> src_buf,
int width,
int height,
diff --git a/core/fxcodec/codec/basicmodule.h b/core/fxcodec/codec/basicmodule.h
index 514d02b..92c5ea5 100644
--- a/core/fxcodec/codec/basicmodule.h
+++ b/core/fxcodec/codec/basicmodule.h
@@ -13,13 +13,13 @@
#include "core/fxcrt/fx_system.h"
#include "third_party/base/span.h"
-class CCodec_ScanlineDecoder;
-
namespace fxcodec {
+class ScanlineDecoder;
+
class BasicModule {
public:
- static std::unique_ptr<CCodec_ScanlineDecoder> CreateRunLengthDecoder(
+ static std::unique_ptr<ScanlineDecoder> CreateRunLengthDecoder(
pdfium::span<const uint8_t> src_buf,
int width,
int height,
diff --git a/core/fxcodec/codec/ccodec_scanlinedecoder.cpp b/core/fxcodec/codec/ccodec_scanlinedecoder.cpp
deleted file mode 100644
index ee0d12a..0000000
--- a/core/fxcodec/codec/ccodec_scanlinedecoder.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "core/fxcodec/codec/ccodec_scanlinedecoder.h"
-
-#include "core/fxcrt/pauseindicator_iface.h"
-
-CCodec_ScanlineDecoder::CCodec_ScanlineDecoder()
- : CCodec_ScanlineDecoder(0, 0, 0, 0, 0, 0, 0) {}
-
-CCodec_ScanlineDecoder::CCodec_ScanlineDecoder(int nOrigWidth,
- int nOrigHeight,
- int nOutputWidth,
- int nOutputHeight,
- int nComps,
- int nBpc,
- uint32_t nPitch)
- : m_OrigWidth(nOrigWidth),
- m_OrigHeight(nOrigHeight),
- m_OutputWidth(nOutputWidth),
- m_OutputHeight(nOutputHeight),
- m_nComps(nComps),
- m_bpc(nBpc),
- m_Pitch(nPitch),
- m_NextLine(-1),
- m_pLastScanline(nullptr) {}
-
-CCodec_ScanlineDecoder::~CCodec_ScanlineDecoder() {}
-
-const uint8_t* CCodec_ScanlineDecoder::GetScanline(int line) {
- if (m_NextLine == line + 1)
- return m_pLastScanline;
-
- if (m_NextLine < 0 || m_NextLine > line) {
- if (!v_Rewind())
- return nullptr;
- m_NextLine = 0;
- }
- while (m_NextLine < line) {
- ReadNextLine();
- m_NextLine++;
- }
- m_pLastScanline = ReadNextLine();
- m_NextLine++;
- return m_pLastScanline;
-}
-
-bool CCodec_ScanlineDecoder::SkipToScanline(int line,
- PauseIndicatorIface* pPause) {
- if (m_NextLine == line || m_NextLine == line + 1)
- return false;
-
- if (m_NextLine < 0 || m_NextLine > line) {
- v_Rewind();
- m_NextLine = 0;
- }
- m_pLastScanline = nullptr;
- while (m_NextLine < line) {
- m_pLastScanline = ReadNextLine();
- m_NextLine++;
- if (pPause && pPause->NeedToPauseNow()) {
- return true;
- }
- }
- return false;
-}
-
-uint8_t* CCodec_ScanlineDecoder::ReadNextLine() {
- return v_GetNextLine();
-}
diff --git a/core/fxcodec/codec/ccodec_scanlinedecoder.h b/core/fxcodec/codec/ccodec_scanlinedecoder.h
deleted file mode 100644
index a6e6d3d..0000000
--- a/core/fxcodec/codec/ccodec_scanlinedecoder.h
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef CORE_FXCODEC_CODEC_CCODEC_SCANLINEDECODER_H_
-#define CORE_FXCODEC_CODEC_CCODEC_SCANLINEDECODER_H_
-
-#include "core/fxcrt/fx_system.h"
-
-class PauseIndicatorIface;
-
-class CCodec_ScanlineDecoder {
- public:
- CCodec_ScanlineDecoder();
- CCodec_ScanlineDecoder(int nOrigWidth,
- int nOrigHeight,
- int nOutputWidth,
- int nOutputHeight,
- int nComps,
- int nBpc,
- uint32_t nPitch);
- virtual ~CCodec_ScanlineDecoder();
-
- const uint8_t* GetScanline(int line);
- bool SkipToScanline(int line, PauseIndicatorIface* pPause);
-
- int GetWidth() { return m_OutputWidth; }
- int GetHeight() { return m_OutputHeight; }
- int CountComps() { return m_nComps; }
- int GetBPC() { return m_bpc; }
-
- virtual uint32_t GetSrcOffset() = 0;
-
- protected:
- virtual bool v_Rewind() = 0;
- virtual uint8_t* v_GetNextLine() = 0;
-
- uint8_t* ReadNextLine();
-
- int m_OrigWidth;
- int m_OrigHeight;
- int m_OutputWidth;
- int m_OutputHeight;
- int m_nComps;
- int m_bpc;
- uint32_t m_Pitch;
- int m_NextLine;
- uint8_t* m_pLastScanline;
-};
-
-#endif // CORE_FXCODEC_CODEC_CCODEC_SCANLINEDECODER_H_
diff --git a/core/fxcodec/codec/faxmodule.cpp b/core/fxcodec/codec/faxmodule.cpp
index 506970d..12e9a95 100644
--- a/core/fxcodec/codec/faxmodule.cpp
+++ b/core/fxcodec/codec/faxmodule.cpp
@@ -12,8 +12,8 @@
#include <vector>
#include "build/build_config.h"
-#include "core/fxcodec/codec/ccodec_scanlinedecoder.h"
#include "core/fxcodec/codec/codec_int.h"
+#include "core/fxcodec/codec/scanlinedecoder.h"
#include "core/fxcodec/fx_codec.h"
#include "core/fxcrt/cfx_binarybuf.h"
#include "core/fxcrt/fx_memory.h"
@@ -455,7 +455,7 @@
}
}
-class FaxDecoder final : public CCodec_ScanlineDecoder {
+class FaxDecoder final : public ScanlineDecoder {
public:
FaxDecoder(pdfium::span<const uint8_t> src_span,
int width,
@@ -466,7 +466,7 @@
bool BlackIs1);
~FaxDecoder() override;
- // CCodec_ScanlineDecoder
+ // ScanlineDecoder:
bool v_Rewind() override;
uint8_t* v_GetNextLine() override;
uint32_t GetSrcOffset() override;
@@ -491,13 +491,13 @@
bool EndOfLine,
bool EncodedByteAlign,
bool BlackIs1)
- : CCodec_ScanlineDecoder(width,
- height,
- width,
- height,
- kFaxComps,
- kFaxBpc,
- CalculatePitch32(kFaxBpc, width).ValueOrDie()),
+ : ScanlineDecoder(width,
+ height,
+ width,
+ height,
+ kFaxComps,
+ kFaxBpc,
+ CalculatePitch32(kFaxBpc, width).ValueOrDie()),
m_Encoding(K),
m_bByteAlign(EncodedByteAlign),
m_bEndOfLine(EndOfLine),
@@ -574,7 +574,7 @@
} // namespace
// static
-std::unique_ptr<CCodec_ScanlineDecoder> FaxModule::CreateDecoder(
+std::unique_ptr<ScanlineDecoder> FaxModule::CreateDecoder(
pdfium::span<const uint8_t> src_span,
int width,
int height,
diff --git a/core/fxcodec/codec/faxmodule.h b/core/fxcodec/codec/faxmodule.h
index d07632b..f665c08 100644
--- a/core/fxcodec/codec/faxmodule.h
+++ b/core/fxcodec/codec/faxmodule.h
@@ -14,13 +14,13 @@
#include "core/fxcrt/fx_system.h"
#include "third_party/base/span.h"
-class CCodec_ScanlineDecoder;
-
namespace fxcodec {
+class ScanlineDecoder;
+
class FaxModule {
public:
- static std::unique_ptr<CCodec_ScanlineDecoder> CreateDecoder(
+ static std::unique_ptr<ScanlineDecoder> CreateDecoder(
pdfium::span<const uint8_t> src_buf,
int width,
int height,
diff --git a/core/fxcodec/codec/flatemodule.cpp b/core/fxcodec/codec/flatemodule.cpp
index f49c668..d3358b4 100644
--- a/core/fxcodec/codec/flatemodule.cpp
+++ b/core/fxcodec/codec/flatemodule.cpp
@@ -12,7 +12,7 @@
#include <utility>
#include <vector>
-#include "core/fxcodec/codec/ccodec_scanlinedecoder.h"
+#include "core/fxcodec/codec/scanlinedecoder.h"
#include "core/fxcodec/fx_codec.h"
#include "core/fxcrt/fx_extension.h"
#include "third_party/base/numerics/safe_conversions.h"
@@ -570,7 +570,7 @@
return PredictorType::kNone;
}
-class FlateScanlineDecoder : public CCodec_ScanlineDecoder {
+class FlateScanlineDecoder : public ScanlineDecoder {
public:
FlateScanlineDecoder(pdfium::span<const uint8_t> src_buf,
int width,
@@ -579,7 +579,7 @@
int bpc);
~FlateScanlineDecoder() override;
- // CCodec_ScanlineDecoder:
+ // ScanlineDecoder:
bool v_Rewind() override;
uint8_t* v_GetNextLine() override;
uint32_t GetSrcOffset() override;
@@ -595,13 +595,13 @@
int height,
int nComps,
int bpc)
- : CCodec_ScanlineDecoder(width,
- height,
- width,
- height,
- nComps,
- bpc,
- CalculatePitch8(bpc, nComps, width).ValueOrDie()),
+ : ScanlineDecoder(width,
+ height,
+ width,
+ height,
+ nComps,
+ bpc,
+ CalculatePitch8(bpc, nComps, width).ValueOrDie()),
m_SrcBuf(src_span),
m_pScanline(FX_Alloc(uint8_t, m_Pitch)) {}
@@ -638,7 +638,7 @@
int Columns);
~FlatePredictorScanlineDecoder() override;
- // CCodec_ScanlineDecoder:
+ // ScanlineDecoder:
bool v_Rewind() override;
uint8_t* v_GetNextLine() override;
@@ -761,7 +761,7 @@
} // namespace
// static
-std::unique_ptr<CCodec_ScanlineDecoder> FlateModule::CreateDecoder(
+std::unique_ptr<ScanlineDecoder> FlateModule::CreateDecoder(
pdfium::span<const uint8_t> src_span,
int width,
int height,
diff --git a/core/fxcodec/codec/flatemodule.h b/core/fxcodec/codec/flatemodule.h
index 522fd9c..eef1c06 100644
--- a/core/fxcodec/codec/flatemodule.h
+++ b/core/fxcodec/codec/flatemodule.h
@@ -13,13 +13,13 @@
#include "core/fxcrt/fx_system.h"
#include "third_party/base/span.h"
-class CCodec_ScanlineDecoder;
-
namespace fxcodec {
+class ScanlineDecoder;
+
class FlateModule {
public:
- static std::unique_ptr<CCodec_ScanlineDecoder> CreateDecoder(
+ static std::unique_ptr<ScanlineDecoder> CreateDecoder(
pdfium::span<const uint8_t> src_buf,
int width,
int height,
diff --git a/core/fxcodec/codec/jpegmodule.cpp b/core/fxcodec/codec/jpegmodule.cpp
index 03b1e96..414f795 100644
--- a/core/fxcodec/codec/jpegmodule.cpp
+++ b/core/fxcodec/codec/jpegmodule.cpp
@@ -12,8 +12,8 @@
#include <utility>
#include "build/build_config.h"
-#include "core/fxcodec/codec/ccodec_scanlinedecoder.h"
#include "core/fxcodec/codec/cfx_codec_memory.h"
+#include "core/fxcodec/codec/scanlinedecoder.h"
#include "core/fxcodec/fx_codec.h"
#include "core/fxcrt/fx_memory.h"
#include "core/fxcrt/fx_safe_types.h"
@@ -215,7 +215,7 @@
namespace {
-class JpegDecoder final : public CCodec_ScanlineDecoder {
+class JpegDecoder final : public ScanlineDecoder {
public:
JpegDecoder();
~JpegDecoder() override;
@@ -226,7 +226,7 @@
int nComps,
bool ColorTransform);
- // CCodec_ScanlineDecoder
+ // ScanlineDecoder:
bool v_Rewind() override;
uint8_t* v_GetNextLine() override;
uint32_t GetSrcOffset() override;
@@ -456,7 +456,7 @@
} // namespace
-std::unique_ptr<CCodec_ScanlineDecoder> JpegModule::CreateDecoder(
+std::unique_ptr<ScanlineDecoder> JpegModule::CreateDecoder(
pdfium::span<const uint8_t> src_span,
int width,
int height,
diff --git a/core/fxcodec/codec/jpegmodule.h b/core/fxcodec/codec/jpegmodule.h
index 1f3436c..31bfeee 100644
--- a/core/fxcodec/codec/jpegmodule.h
+++ b/core/fxcodec/codec/jpegmodule.h
@@ -14,15 +14,16 @@
#include "core/fxcodec/codec/codec_module_iface.h"
#include "third_party/base/span.h"
-class CCodec_ScanlineDecoder;
class CFX_DIBAttribute;
class CFX_DIBBase;
namespace fxcodec {
+class ScanlineDecoder;
+
class JpegModule final : public CodecModuleIface {
public:
- std::unique_ptr<CCodec_ScanlineDecoder> CreateDecoder(
+ std::unique_ptr<ScanlineDecoder> CreateDecoder(
pdfium::span<const uint8_t> src_buf,
int width,
int height,
diff --git a/core/fxcodec/codec/scanlinedecoder.cpp b/core/fxcodec/codec/scanlinedecoder.cpp
new file mode 100644
index 0000000..7fefebb
--- /dev/null
+++ b/core/fxcodec/codec/scanlinedecoder.cpp
@@ -0,0 +1,73 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fxcodec/codec/scanlinedecoder.h"
+
+#include "core/fxcrt/pauseindicator_iface.h"
+
+namespace fxcodec {
+
+ScanlineDecoder::ScanlineDecoder() : ScanlineDecoder(0, 0, 0, 0, 0, 0, 0) {}
+
+ScanlineDecoder::ScanlineDecoder(int nOrigWidth,
+ int nOrigHeight,
+ int nOutputWidth,
+ int nOutputHeight,
+ int nComps,
+ int nBpc,
+ uint32_t nPitch)
+ : m_OrigWidth(nOrigWidth),
+ m_OrigHeight(nOrigHeight),
+ m_OutputWidth(nOutputWidth),
+ m_OutputHeight(nOutputHeight),
+ m_nComps(nComps),
+ m_bpc(nBpc),
+ m_Pitch(nPitch) {}
+
+ScanlineDecoder::~ScanlineDecoder() = default;
+
+const uint8_t* ScanlineDecoder::GetScanline(int line) {
+ if (m_NextLine == line + 1)
+ return m_pLastScanline;
+
+ if (m_NextLine < 0 || m_NextLine > line) {
+ if (!v_Rewind())
+ return nullptr;
+ m_NextLine = 0;
+ }
+ while (m_NextLine < line) {
+ ReadNextLine();
+ m_NextLine++;
+ }
+ m_pLastScanline = ReadNextLine();
+ m_NextLine++;
+ return m_pLastScanline;
+}
+
+bool ScanlineDecoder::SkipToScanline(int line, PauseIndicatorIface* pPause) {
+ if (m_NextLine == line || m_NextLine == line + 1)
+ return false;
+
+ if (m_NextLine < 0 || m_NextLine > line) {
+ v_Rewind();
+ m_NextLine = 0;
+ }
+ m_pLastScanline = nullptr;
+ while (m_NextLine < line) {
+ m_pLastScanline = ReadNextLine();
+ m_NextLine++;
+ if (pPause && pPause->NeedToPauseNow()) {
+ return true;
+ }
+ }
+ return false;
+}
+
+uint8_t* ScanlineDecoder::ReadNextLine() {
+ return v_GetNextLine();
+}
+
+} // namespace fxcodec
diff --git a/core/fxcodec/codec/scanlinedecoder.h b/core/fxcodec/codec/scanlinedecoder.h
new file mode 100644
index 0000000..14d4b9c
--- /dev/null
+++ b/core/fxcodec/codec/scanlinedecoder.h
@@ -0,0 +1,59 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FXCODEC_CODEC_SCANLINEDECODER_H_
+#define CORE_FXCODEC_CODEC_SCANLINEDECODER_H_
+
+#include "core/fxcrt/fx_system.h"
+
+class PauseIndicatorIface;
+
+namespace fxcodec {
+
+class ScanlineDecoder {
+ public:
+ ScanlineDecoder();
+ ScanlineDecoder(int nOrigWidth,
+ int nOrigHeight,
+ int nOutputWidth,
+ int nOutputHeight,
+ int nComps,
+ int nBpc,
+ uint32_t nPitch);
+ virtual ~ScanlineDecoder();
+
+ const uint8_t* GetScanline(int line);
+ bool SkipToScanline(int line, PauseIndicatorIface* pPause);
+
+ int GetWidth() const { return m_OutputWidth; }
+ int GetHeight() const { return m_OutputHeight; }
+ int CountComps() const { return m_nComps; }
+ int GetBPC() const { return m_bpc; }
+
+ virtual uint32_t GetSrcOffset() = 0;
+
+ protected:
+ virtual bool v_Rewind() = 0;
+ virtual uint8_t* v_GetNextLine() = 0;
+
+ uint8_t* ReadNextLine();
+
+ int m_OrigWidth;
+ int m_OrigHeight;
+ int m_OutputWidth;
+ int m_OutputHeight;
+ int m_nComps;
+ int m_bpc;
+ uint32_t m_Pitch;
+ int m_NextLine = -1;
+ uint8_t* m_pLastScanline = nullptr;
+};
+
+} // namespace fxcodec
+
+using ScanlineDecoder = fxcodec::ScanlineDecoder;
+
+#endif // CORE_FXCODEC_CODEC_SCANLINEDECODER_H_
diff --git a/testing/fuzzers/pdf_codec_fax_fuzzer.cc b/testing/fuzzers/pdf_codec_fax_fuzzer.cc
index 09f6efb..cdb456a 100644
--- a/testing/fuzzers/pdf_codec_fax_fuzzer.cc
+++ b/testing/fuzzers/pdf_codec_fax_fuzzer.cc
@@ -5,8 +5,8 @@
#include <cstdint>
#include <memory>
-#include "core/fxcodec/codec/ccodec_scanlinedecoder.h"
#include "core/fxcodec/codec/faxmodule.h"
+#include "core/fxcodec/codec/scanlinedecoder.h"
#include "testing/fuzzers/pdfium_fuzzer_util.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
@@ -32,7 +32,7 @@
data += kParameterSize;
size -= kParameterSize;
- std::unique_ptr<CCodec_ScanlineDecoder> decoder =
+ std::unique_ptr<ScanlineDecoder> decoder =
FaxModule::CreateDecoder({data, size}, width, height, K, EndOfLine,
ByteAlign, kBlackIs1, Columns, Rows);