Rename CCodec_Jbig2Module to fxcodec::Jbig2Module.
Also add core/fxcodec/JBig2_DocumentContext.cpp and move
JBig2_DocumentContext code into it.
BUG=pdfium:1311
Change-Id: Ic4b746e78eba4692e83362e8105106a041455a7e
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/55831
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_dibbase.cpp b/core/fpdfapi/render/cpdf_dibbase.cpp
index 19614d0..93f77f3 100644
--- a/core/fpdfapi/render/cpdf_dibbase.cpp
+++ b/core/fpdfapi/render/cpdf_dibbase.cpp
@@ -24,9 +24,9 @@
#include "core/fpdfapi/render/cpdf_pagerendercache.h"
#include "core/fpdfapi/render/cpdf_renderstatus.h"
#include "core/fxcodec/codec/ccodec_basicmodule.h"
-#include "core/fxcodec/codec/ccodec_jbig2module.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/fx_codec.h"
@@ -282,10 +282,9 @@
return LoadState::kFail;
FXCODEC_STATUS iDecodeStatus;
- CCodec_Jbig2Module* pJbig2Module =
- CCodec_ModuleMgr::GetInstance()->GetJbig2Module();
+ Jbig2Module* pJbig2Module = CCodec_ModuleMgr::GetInstance()->GetJbig2Module();
if (!m_pJbig2Context) {
- m_pJbig2Context = pdfium::MakeUnique<CCodec_Jbig2Context>();
+ m_pJbig2Context = pdfium::MakeUnique<Jbig2Context>();
if (m_pStreamAcc->GetImageParam()) {
const CPDF_Stream* pGlobals =
m_pStreamAcc->GetImageParam()->GetStreamFor("JBIG2Globals");
diff --git a/core/fpdfapi/render/cpdf_dibbase.h b/core/fpdfapi/render/cpdf_dibbase.h
index 632bddd..f1c7d56 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_Jbig2Context;
class CCodec_ScanlineDecoder;
class CPDF_Color;
class CPDF_Dictionary;
@@ -36,6 +35,10 @@
int m_ColorKeyMax;
};
+namespace fxcodec {
+class Jbig2Context;
+}
+
#define FPDF_HUGE_IMAGE_SIZE 60000000
class CPDF_DIBBase final : public CFX_DIBBase {
@@ -152,7 +155,7 @@
std::unique_ptr<CCodec_ScanlineDecoder> m_pDecoder;
// Must come after |m_pCachedBitmap|.
- std::unique_ptr<CCodec_Jbig2Context> m_pJbig2Context;
+ std::unique_ptr<fxcodec::Jbig2Context> m_pJbig2Context;
UnownedPtr<const CPDF_Stream> m_pMaskStream;
LoadState m_Status = LoadState::kFail;
diff --git a/core/fxcodec/BUILD.gn b/core/fxcodec/BUILD.gn
index ccdbd3c..0464d0d 100644
--- a/core/fxcodec/BUILD.gn
+++ b/core/fxcodec/BUILD.gn
@@ -8,6 +8,7 @@
jumbo_source_set("fxcodec") {
sources = [
+ "JBig2_DocumentContext.cpp",
"JBig2_DocumentContext.h",
"codec/ccodec_basicmodule.cpp",
"codec/ccodec_basicmodule.h",
@@ -15,8 +16,6 @@
"codec/ccodec_faxmodule.h",
"codec/ccodec_flatemodule.cpp",
"codec/ccodec_flatemodule.h",
- "codec/ccodec_jbig2module.cpp",
- "codec/ccodec_jbig2module.h",
"codec/ccodec_scanlinedecoder.cpp",
"codec/ccodec_scanlinedecoder.h",
"codec/cfx_codec_memory.cpp",
@@ -28,6 +27,8 @@
"codec/fx_codec.cpp",
"codec/iccmodule.cpp",
"codec/iccmodule.h",
+ "codec/jbig2module.cpp",
+ "codec/jbig2module.h",
"codec/jpegmodule.cpp",
"codec/jpegmodule.h",
"codec/jpxmodule.cpp",
diff --git a/core/fxcodec/JBig2_DocumentContext.cpp b/core/fxcodec/JBig2_DocumentContext.cpp
new file mode 100644
index 0000000..6e29259
--- /dev/null
+++ b/core/fxcodec/JBig2_DocumentContext.cpp
@@ -0,0 +1,14 @@
+// Copyright 2019 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/JBig2_DocumentContext.h"
+
+#include "core/fxcodec/jbig2/JBig2_Image.h"
+#include "core/fxcodec/jbig2/JBig2_SymbolDict.h"
+
+JBig2_DocumentContext::JBig2_DocumentContext() = default;
+
+JBig2_DocumentContext::~JBig2_DocumentContext() = default;
diff --git a/core/fxcodec/codec/fx_codec.cpp b/core/fxcodec/codec/fx_codec.cpp
index 0f6a944..65a29ae 100644
--- a/core/fxcodec/codec/fx_codec.cpp
+++ b/core/fxcodec/codec/fx_codec.cpp
@@ -11,8 +11,8 @@
#include <memory>
#include <utility>
-#include "core/fxcodec/codec/ccodec_jbig2module.h"
#include "core/fxcodec/codec/codec_int.h"
+#include "core/fxcodec/codec/jbig2module.h"
#include "core/fxcodec/codec/jpegmodule.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_safe_types.h"
@@ -46,7 +46,7 @@
CCodec_ModuleMgr::CCodec_ModuleMgr()
: m_pJpegModule(pdfium::MakeUnique<JpegModule>()),
- m_pJbig2Module(pdfium::MakeUnique<CCodec_Jbig2Module>()) {
+ m_pJbig2Module(pdfium::MakeUnique<Jbig2Module>()) {
#ifdef PDF_ENABLE_XFA_BMP
SetBmpModule(pdfium::MakeUnique<BmpModule>());
#endif
diff --git a/core/fxcodec/codec/ccodec_jbig2module.cpp b/core/fxcodec/codec/jbig2module.cpp
similarity index 75%
rename from core/fxcodec/codec/ccodec_jbig2module.cpp
rename to core/fxcodec/codec/jbig2module.cpp
index 43b3ab0..c37b0bf 100644
--- a/core/fxcodec/codec/ccodec_jbig2module.cpp
+++ b/core/fxcodec/codec/jbig2module.cpp
@@ -4,19 +4,13 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include "core/fxcodec/codec/ccodec_jbig2module.h"
-
-#include <list>
-#include <memory>
+#include "core/fxcodec/codec/jbig2module.h"
#include "core/fxcodec/JBig2_DocumentContext.h"
#include "core/fxcodec/jbig2/JBig2_Context.h"
-#include "core/fxcodec/jbig2/JBig2_Image.h"
#include "third_party/base/ptr_util.h"
-JBig2_DocumentContext::JBig2_DocumentContext() {}
-
-JBig2_DocumentContext::~JBig2_DocumentContext() {}
+namespace fxcodec {
JBig2_DocumentContext* GetJBig2DocumentContext(
std::unique_ptr<JBig2_DocumentContext>* pContextHolder) {
@@ -25,16 +19,16 @@
return pContextHolder->get();
}
-CCodec_Jbig2Context::CCodec_Jbig2Context() = default;
+Jbig2Context::Jbig2Context() = default;
-CCodec_Jbig2Context::~CCodec_Jbig2Context() = default;
+Jbig2Context::~Jbig2Context() = default;
-CCodec_Jbig2Module::CCodec_Jbig2Module() = default;
+Jbig2Module::Jbig2Module() = default;
-CCodec_Jbig2Module::~CCodec_Jbig2Module() = default;
+Jbig2Module::~Jbig2Module() = default;
-FXCODEC_STATUS CCodec_Jbig2Module::StartDecode(
- CCodec_Jbig2Context* pJbig2Context,
+FXCODEC_STATUS Jbig2Module::StartDecode(
+ Jbig2Context* pJbig2Context,
std::unique_ptr<JBig2_DocumentContext>* pContextHolder,
uint32_t width,
uint32_t height,
@@ -67,15 +61,14 @@
return Decode(pJbig2Context, succeeded);
}
-FXCODEC_STATUS CCodec_Jbig2Module::ContinueDecode(
- CCodec_Jbig2Context* pJbig2Context,
- PauseIndicatorIface* pPause) {
+FXCODEC_STATUS Jbig2Module::ContinueDecode(Jbig2Context* pJbig2Context,
+ PauseIndicatorIface* pPause) {
bool succeeded = pJbig2Context->m_pContext->Continue(pPause);
return Decode(pJbig2Context, succeeded);
}
-FXCODEC_STATUS CCodec_Jbig2Module::Decode(CCodec_Jbig2Context* pJbig2Context,
- bool decode_success) {
+FXCODEC_STATUS Jbig2Module::Decode(Jbig2Context* pJbig2Context,
+ bool decode_success) {
FXCODEC_STATUS status = pJbig2Context->m_pContext->GetProcessingStatus();
if (status != FXCODEC_STATUS_DECODE_FINISH)
return status;
@@ -90,3 +83,5 @@
dword_buf[i] = ~dword_buf[i];
return FXCODEC_STATUS_DECODE_FINISH;
}
+
+} // namespace fxcodec
diff --git a/core/fxcodec/codec/ccodec_jbig2module.h b/core/fxcodec/codec/jbig2module.h
similarity index 69%
rename from core/fxcodec/codec/ccodec_jbig2module.h
rename to core/fxcodec/codec/jbig2module.h
index 2c370ce..18cb127 100644
--- a/core/fxcodec/codec/ccodec_jbig2module.h
+++ b/core/fxcodec/codec/jbig2module.h
@@ -4,8 +4,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#ifndef CORE_FXCODEC_CODEC_CCODEC_JBIG2MODULE_H_
-#define CORE_FXCODEC_CODEC_CCODEC_JBIG2MODULE_H_
+#ifndef CORE_FXCODEC_CODEC_JBIG2MODULE_H_
+#define CORE_FXCODEC_CODEC_JBIG2MODULE_H_
#include <memory>
@@ -14,13 +14,15 @@
class CJBig2_Context;
class CJBig2_Image;
-class PauseIndicatorIface;
class JBig2_DocumentContext;
+class PauseIndicatorIface;
-class CCodec_Jbig2Context {
+namespace fxcodec {
+
+class Jbig2Context {
public:
- CCodec_Jbig2Context();
- ~CCodec_Jbig2Context();
+ Jbig2Context();
+ ~Jbig2Context();
uint32_t m_width = 0;
uint32_t m_height = 0;
@@ -33,13 +35,13 @@
std::unique_ptr<CJBig2_Context> m_pContext;
};
-class CCodec_Jbig2Module {
+class Jbig2Module {
public:
- CCodec_Jbig2Module();
- ~CCodec_Jbig2Module();
+ Jbig2Module();
+ ~Jbig2Module();
FXCODEC_STATUS StartDecode(
- CCodec_Jbig2Context* pJbig2Context,
+ Jbig2Context* pJbig2Context,
std::unique_ptr<JBig2_DocumentContext>* pContextHolder,
uint32_t width,
uint32_t height,
@@ -51,12 +53,16 @@
uint32_t dest_pitch,
PauseIndicatorIface* pPause);
- FXCODEC_STATUS ContinueDecode(CCodec_Jbig2Context* pJbig2Context,
+ FXCODEC_STATUS ContinueDecode(Jbig2Context* pJbig2Context,
PauseIndicatorIface* pPause);
private:
- FXCODEC_STATUS Decode(CCodec_Jbig2Context* pJbig2Context,
- bool decode_success);
+ FXCODEC_STATUS Decode(Jbig2Context* pJbig2Context, bool decode_success);
};
-#endif // CORE_FXCODEC_CODEC_CCODEC_JBIG2MODULE_H_
+} // namespace fxcodec
+
+using Jbig2Context = fxcodec::Jbig2Context;
+using Jbig2Module = fxcodec::Jbig2Module;
+
+#endif // CORE_FXCODEC_CODEC_JBIG2MODULE_H_
diff --git a/core/fxcodec/fx_codec.h b/core/fxcodec/fx_codec.h
index 60a7b91..ede8d3a 100644
--- a/core/fxcodec/fx_codec.h
+++ b/core/fxcodec/fx_codec.h
@@ -34,8 +34,6 @@
#endif // PDF_ENABLE_XFA_TIFF
#endif // PDF_ENABLE_XFA
-class CCodec_Jbig2Module;
-
#ifdef PDF_ENABLE_XFA
class CCodec_ProgressiveDecoder;
@@ -52,6 +50,7 @@
#endif // PDF_ENABLE_XFA
namespace fxcodec {
+class Jbig2Module;
class JpegModule;
}
@@ -63,7 +62,7 @@
static CCodec_ModuleMgr* GetInstance();
fxcodec::JpegModule* GetJpegModule() const { return m_pJpegModule.get(); }
- CCodec_Jbig2Module* GetJbig2Module() const { return m_pJbig2Module.get(); }
+ fxcodec::Jbig2Module* GetJbig2Module() const { return m_pJbig2Module.get(); }
#ifdef PDF_ENABLE_XFA
std::unique_ptr<CCodec_ProgressiveDecoder> CreateProgressiveDecoder();
@@ -102,7 +101,7 @@
~CCodec_ModuleMgr();
std::unique_ptr<fxcodec::JpegModule> m_pJpegModule;
- std::unique_ptr<CCodec_Jbig2Module> m_pJbig2Module;
+ std::unique_ptr<fxcodec::Jbig2Module> m_pJbig2Module;
#ifdef PDF_ENABLE_XFA
#ifdef PDF_ENABLE_XFA_BMP
diff --git a/testing/fuzzers/pdf_codec_jbig2_fuzzer.cc b/testing/fuzzers/pdf_codec_jbig2_fuzzer.cc
index e559d3d..ea59351 100644
--- a/testing/fuzzers/pdf_codec_jbig2_fuzzer.cc
+++ b/testing/fuzzers/pdf_codec_jbig2_fuzzer.cc
@@ -5,7 +5,7 @@
#include <cstdint>
#include "core/fxcodec/JBig2_DocumentContext.h"
-#include "core/fxcodec/codec/ccodec_jbig2module.h"
+#include "core/fxcodec/codec/jbig2module.h"
#include "core/fxcodec/jbig2/JBig2_Context.h"
#include "core/fxcrt/fx_safe_types.h"
#include "core/fxge/dib/cfx_dibitmap.h"
@@ -35,8 +35,8 @@
if (!bitmap->Create(width, height, FXDIB_1bppRgb))
return 0;
- CCodec_Jbig2Module module;
- CCodec_Jbig2Context jbig2_context;
+ Jbig2Module module;
+ Jbig2Context jbig2_context;
std::unique_ptr<JBig2_DocumentContext> document_context;
FXCODEC_STATUS status = module.StartDecode(
&jbig2_context, &document_context, width, height, {data, size}, 1, {}, 0,