Remove JpxModule.
Merge the single method in JpxModule into CJPX_Decoder. Make
CJPX_Decoder's ctor and Init() method private.
Change-Id: Ibd43abc9b4ed6f40c4d54ce9bf44a7c7ff3ab546
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/69874
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_dib.cpp b/core/fpdfapi/page/cpdf_dib.cpp
index f2d78d7..c6cb3da 100644
--- a/core/fpdfapi/page/cpdf_dib.cpp
+++ b/core/fpdfapi/page/cpdf_dib.cpp
@@ -29,7 +29,6 @@
#include "core/fxcodec/jbig2/jbig2module.h"
#include "core/fxcodec/jpeg/jpegmodule.h"
#include "core/fxcodec/jpx/cjpx_decoder.h"
-#include "core/fxcodec/jpx/jpxmodule.h"
#include "core/fxcodec/scanlinedecoder.h"
#include "core/fxcrt/cfx_fixedbufgrow.h"
#include "core/fxcrt/fx_safe_types.h"
@@ -629,9 +628,9 @@
}
RetainPtr<CFX_DIBitmap> CPDF_DIB::LoadJpxBitmap() {
- std::unique_ptr<CJPX_Decoder> decoder = JpxModule::CreateDecoder(
- m_pStreamAcc->GetSpan(),
- ColorSpaceOptionFromColorSpace(m_pColorSpace.Get()));
+ std::unique_ptr<CJPX_Decoder> decoder =
+ CJPX_Decoder::Create(m_pStreamAcc->GetSpan(),
+ ColorSpaceOptionFromColorSpace(m_pColorSpace.Get()));
if (!decoder)
return nullptr;
diff --git a/core/fxcodec/BUILD.gn b/core/fxcodec/BUILD.gn
index e0bc3a7..8f68f3f 100644
--- a/core/fxcodec/BUILD.gn
+++ b/core/fxcodec/BUILD.gn
@@ -65,8 +65,6 @@
"jpx/cjpx_decoder.h",
"jpx/jpx_decode_utils.cpp",
"jpx/jpx_decode_utils.h",
- "jpx/jpxmodule.cpp",
- "jpx/jpxmodule.h",
"scanlinedecoder.cpp",
"scanlinedecoder.h",
]
diff --git a/core/fxcodec/jpx/cjpx_decoder.cpp b/core/fxcodec/jpx/cjpx_decoder.cpp
index 29fb849..4fc24ee 100644
--- a/core/fxcodec/jpx/cjpx_decoder.cpp
+++ b/core/fxcodec/jpx/cjpx_decoder.cpp
@@ -385,6 +385,17 @@
} // namespace
// static
+std::unique_ptr<CJPX_Decoder> CJPX_Decoder::Create(
+ pdfium::span<const uint8_t> src_span,
+ CJPX_Decoder::ColorSpaceOption option) {
+ // Private ctor.
+ auto decoder = pdfium::WrapUnique(new CJPX_Decoder(option));
+ if (!decoder->Init(src_span))
+ return nullptr;
+ return decoder;
+}
+
+// static
void CJPX_Decoder::Sycc420ToRgbForTesting(opj_image_t* img) {
sycc420_to_rgb(img);
}
diff --git a/core/fxcodec/jpx/cjpx_decoder.h b/core/fxcodec/jpx/cjpx_decoder.h
index f0869c1..053de7b 100644
--- a/core/fxcodec/jpx/cjpx_decoder.h
+++ b/core/fxcodec/jpx/cjpx_decoder.h
@@ -38,12 +38,14 @@
COLOR_SPACE colorspace;
};
+ static std::unique_ptr<CJPX_Decoder> Create(
+ pdfium::span<const uint8_t> src_span,
+ CJPX_Decoder::ColorSpaceOption option);
+
static void Sycc420ToRgbForTesting(opj_image_t* img);
- explicit CJPX_Decoder(ColorSpaceOption option);
~CJPX_Decoder();
- bool Init(pdfium::span<const uint8_t> src_data);
JpxImageInfo GetInfo() const;
bool StartDecode();
@@ -51,6 +53,11 @@
bool Decode(uint8_t* dest_buf, uint32_t pitch, bool swap_rgb);
private:
+ // Use Create() to instantiate.
+ explicit CJPX_Decoder(ColorSpaceOption option);
+
+ bool Init(pdfium::span<const uint8_t> src_data);
+
const ColorSpaceOption m_ColorSpaceOption;
pdfium::span<const uint8_t> m_SrcData;
UnownedPtr<opj_image_t> m_Image;
diff --git a/core/fxcodec/jpx/jpxmodule.cpp b/core/fxcodec/jpx/jpxmodule.cpp
deleted file mode 100644
index 4229dc5..0000000
--- a/core/fxcodec/jpx/jpxmodule.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2014 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/jpx/jpxmodule.h"
-
-#include "third_party/base/ptr_util.h"
-
-namespace fxcodec {
-
-// static
-std::unique_ptr<CJPX_Decoder> JpxModule::CreateDecoder(
- pdfium::span<const uint8_t> src_span,
- CJPX_Decoder::ColorSpaceOption option) {
- auto decoder = pdfium::MakeUnique<CJPX_Decoder>(option);
- if (!decoder->Init(src_span))
- return nullptr;
-
- return decoder;
-}
-
-} // namespace fxcodec
diff --git a/core/fxcodec/jpx/jpxmodule.h b/core/fxcodec/jpx/jpxmodule.h
deleted file mode 100644
index 0f2fb71..0000000
--- a/core/fxcodec/jpx/jpxmodule.h
+++ /dev/null
@@ -1,34 +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_JPX_JPXMODULE_H_
-#define CORE_FXCODEC_JPX_JPXMODULE_H_
-
-#include <memory>
-#include <vector>
-
-#include "core/fxcodec/jpx/cjpx_decoder.h"
-#include "core/fxcrt/fx_system.h"
-#include "third_party/base/span.h"
-
-namespace fxcodec {
-
-class JpxModule {
- public:
- static std::unique_ptr<CJPX_Decoder> CreateDecoder(
- pdfium::span<const uint8_t> src_span,
- CJPX_Decoder::ColorSpaceOption option);
-
- JpxModule() = delete;
- JpxModule(const JpxModule&) = delete;
- JpxModule& operator=(const JpxModule&) = delete;
-};
-
-} // namespace fxcodec
-
-using JpxModule = fxcodec::JpxModule;
-
-#endif // CORE_FXCODEC_JPX_JPXMODULE_H_
diff --git a/testing/fuzzers/pdf_jpx_fuzzer.cc b/testing/fuzzers/pdf_jpx_fuzzer.cc
index 3986ae2..7053de8 100644
--- a/testing/fuzzers/pdf_jpx_fuzzer.cc
+++ b/testing/fuzzers/pdf_jpx_fuzzer.cc
@@ -8,7 +8,6 @@
#include "core/fpdfapi/page/cpdf_colorspace.h"
#include "core/fxcodec/jpx/cjpx_decoder.h"
-#include "core/fxcodec/jpx/jpxmodule.h"
#include "core/fxcrt/fx_safe_types.h"
#include "core/fxge/dib/cfx_dibitmap.h"
#include "core/fxge/fx_dib.h"
@@ -31,7 +30,7 @@
if (size < 1)
return 0;
- std::unique_ptr<CJPX_Decoder> decoder = JpxModule::CreateDecoder(
+ std::unique_ptr<CJPX_Decoder> decoder = CJPX_Decoder::Create(
{data + 1, size - 1},
static_cast<CJPX_Decoder::ColorSpaceOption>(data[0] % 3));
if (!decoder)