summaryrefslogtreecommitdiff
path: root/core/fxcodec
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcodec')
-rw-r--r--core/fxcodec/codec/ccodec_jbig2module.h8
-rw-r--r--core/fxcodec/codec/fx_codec_jbig.cpp4
-rw-r--r--core/fxcodec/jbig2/JBig2_BitStream.cpp3
-rw-r--r--core/fxcodec/jbig2/JBig2_BitStream.h3
-rw-r--r--core/fxcodec/jbig2/JBig2_BitStream_unittest.cpp36
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.cpp11
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.h4
7 files changed, 36 insertions, 33 deletions
diff --git a/core/fxcodec/codec/ccodec_jbig2module.h b/core/fxcodec/codec/ccodec_jbig2module.h
index c74ed5fb02..e4e0af35da 100644
--- a/core/fxcodec/codec/ccodec_jbig2module.h
+++ b/core/fxcodec/codec/ccodec_jbig2module.h
@@ -25,8 +25,8 @@ class CCodec_Jbig2Context {
uint32_t m_width;
uint32_t m_height;
- CPDF_StreamAcc* m_pGlobalStream;
- CPDF_StreamAcc* m_pSrcStream;
+ CFX_RetainPtr<CPDF_StreamAcc> m_pGlobalStream;
+ CFX_RetainPtr<CPDF_StreamAcc> m_pSrcStream;
uint8_t* m_dest_buf;
uint32_t m_dest_pitch;
IFX_Pause* m_pPause;
@@ -43,8 +43,8 @@ class CCodec_Jbig2Module {
std::unique_ptr<JBig2_DocumentContext>* pContextHolder,
uint32_t width,
uint32_t height,
- CPDF_StreamAcc* src_stream,
- CPDF_StreamAcc* global_stream,
+ const CFX_RetainPtr<CPDF_StreamAcc>& src_stream,
+ const CFX_RetainPtr<CPDF_StreamAcc>& global_stream,
uint8_t* dest_buf,
uint32_t dest_pitch,
IFX_Pause* pPause);
diff --git a/core/fxcodec/codec/fx_codec_jbig.cpp b/core/fxcodec/codec/fx_codec_jbig.cpp
index dc82305616..951fec4813 100644
--- a/core/fxcodec/codec/fx_codec_jbig.cpp
+++ b/core/fxcodec/codec/fx_codec_jbig.cpp
@@ -45,8 +45,8 @@ FXCODEC_STATUS CCodec_Jbig2Module::StartDecode(
std::unique_ptr<JBig2_DocumentContext>* pContextHolder,
uint32_t width,
uint32_t height,
- CPDF_StreamAcc* src_stream,
- CPDF_StreamAcc* global_stream,
+ const CFX_RetainPtr<CPDF_StreamAcc>& src_stream,
+ const CFX_RetainPtr<CPDF_StreamAcc>& global_stream,
uint8_t* dest_buf,
uint32_t dest_pitch,
IFX_Pause* pPause) {
diff --git a/core/fxcodec/jbig2/JBig2_BitStream.cpp b/core/fxcodec/jbig2/JBig2_BitStream.cpp
index 67d82f49a7..921fa2a661 100644
--- a/core/fxcodec/jbig2/JBig2_BitStream.cpp
+++ b/core/fxcodec/jbig2/JBig2_BitStream.cpp
@@ -11,7 +11,8 @@
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
-CJBig2_BitStream::CJBig2_BitStream(CPDF_StreamAcc* pSrcStream)
+CJBig2_BitStream::CJBig2_BitStream(
+ const CFX_RetainPtr<CPDF_StreamAcc>& pSrcStream)
: m_pBuf(pSrcStream->GetData()),
m_dwLength(pSrcStream->GetSize()),
m_dwByteIdx(0),
diff --git a/core/fxcodec/jbig2/JBig2_BitStream.h b/core/fxcodec/jbig2/JBig2_BitStream.h
index 551b7df9b1..7517eb0c6c 100644
--- a/core/fxcodec/jbig2/JBig2_BitStream.h
+++ b/core/fxcodec/jbig2/JBig2_BitStream.h
@@ -7,13 +7,14 @@
#ifndef CORE_FXCODEC_JBIG2_JBIG2_BITSTREAM_H_
#define CORE_FXCODEC_JBIG2_JBIG2_BITSTREAM_H_
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_basic.h"
class CPDF_StreamAcc;
class CJBig2_BitStream {
public:
- explicit CJBig2_BitStream(CPDF_StreamAcc* pSrcStream);
+ explicit CJBig2_BitStream(const CFX_RetainPtr<CPDF_StreamAcc>& pSrcStream);
~CJBig2_BitStream();
// TODO(thestig): readFoo() should return bool.
diff --git a/core/fxcodec/jbig2/JBig2_BitStream_unittest.cpp b/core/fxcodec/jbig2/JBig2_BitStream_unittest.cpp
index f9d69b9c53..7b91eff982 100644
--- a/core/fxcodec/jbig2/JBig2_BitStream_unittest.cpp
+++ b/core/fxcodec/jbig2/JBig2_BitStream_unittest.cpp
@@ -16,10 +16,10 @@ TEST(JBig2_BitStream, ReadNBits) {
data.get()[0] = 0xb1; // 10110001
auto in_stream = pdfium::MakeUnique<CPDF_Stream>(std::move(data), 1, nullptr);
- auto acc = pdfium::MakeUnique<CPDF_StreamAcc>();
- acc->LoadAllData(in_stream.get());
+ auto acc = pdfium::MakeRetain<CPDF_StreamAcc>(in_stream.get());
+ acc->LoadAllData();
- CJBig2_BitStream stream(acc.get());
+ CJBig2_BitStream stream(acc);
uint32_t val1;
EXPECT_EQ(0, stream.readNBits(1, &val1));
@@ -41,10 +41,10 @@ TEST(JBig2_BitStream, ReadNBitsLargerThenData) {
data.get()[0] = 0xb1;
auto in_stream = pdfium::MakeUnique<CPDF_Stream>(std::move(data), 1, nullptr);
- auto acc = pdfium::MakeUnique<CPDF_StreamAcc>();
- acc->LoadAllData(in_stream.get());
+ auto acc = pdfium::MakeRetain<CPDF_StreamAcc>(in_stream.get());
+ acc->LoadAllData();
- CJBig2_BitStream stream(acc.get());
+ CJBig2_BitStream stream(acc);
uint32_t val1;
EXPECT_EQ(0, stream.readNBits(10, &val1));
@@ -53,10 +53,10 @@ TEST(JBig2_BitStream, ReadNBitsLargerThenData) {
TEST(JBig2_BitStream, ReadNBitsNullStream) {
auto in_stream = pdfium::MakeUnique<CPDF_Stream>(nullptr, 0, nullptr);
- auto acc = pdfium::MakeUnique<CPDF_StreamAcc>();
- acc->LoadAllData(in_stream.get());
+ auto acc = pdfium::MakeRetain<CPDF_StreamAcc>(in_stream.get());
+ acc->LoadAllData();
- CJBig2_BitStream stream(acc.get());
+ CJBig2_BitStream stream(acc);
uint32_t val1;
EXPECT_EQ(-1, stream.readNBits(1, &val1));
@@ -69,10 +69,10 @@ TEST(JBig2_BitStream, ReadNBitsEmptyStream) {
std::unique_ptr<uint8_t, FxFreeDeleter> data(FX_Alloc(uint8_t, 1));
auto in_stream = pdfium::MakeUnique<CPDF_Stream>(std::move(data), 0, nullptr);
- auto acc = pdfium::MakeUnique<CPDF_StreamAcc>();
- acc->LoadAllData(in_stream.get());
+ auto acc = pdfium::MakeRetain<CPDF_StreamAcc>(in_stream.get());
+ acc->LoadAllData();
- CJBig2_BitStream stream(acc.get());
+ CJBig2_BitStream stream(acc);
uint32_t val1;
EXPECT_EQ(-1, stream.readNBits(1, &val1));
@@ -86,10 +86,10 @@ TEST(JBig2_BitStream, ReadNBitsOutOfBounds) {
data.get()[0] = 0xb1; // 10110001
auto in_stream = pdfium::MakeUnique<CPDF_Stream>(std::move(data), 1, nullptr);
- auto acc = pdfium::MakeUnique<CPDF_StreamAcc>();
- acc->LoadAllData(in_stream.get());
+ auto acc = pdfium::MakeRetain<CPDF_StreamAcc>(in_stream.get());
+ acc->LoadAllData();
- CJBig2_BitStream stream(acc.get());
+ CJBig2_BitStream stream(acc);
uint32_t val1;
EXPECT_EQ(0, stream.readNBits(8, &val1));
@@ -107,10 +107,10 @@ TEST(JBig2_BitStream, ReadNBitsWhereNIs36) {
data.get()[4] = 0x40;
auto in_stream = pdfium::MakeUnique<CPDF_Stream>(std::move(data), 5, nullptr);
- auto acc = pdfium::MakeUnique<CPDF_StreamAcc>();
- acc->LoadAllData(in_stream.get());
+ auto acc = pdfium::MakeRetain<CPDF_StreamAcc>(in_stream.get());
+ acc->LoadAllData();
- CJBig2_BitStream stream(acc.get());
+ CJBig2_BitStream stream(acc);
// This will shift off the top two bits and they end up lost.
uint32_t val1;
diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp
index 9261d16bfc..116abb7754 100644
--- a/core/fxcodec/jbig2/JBig2_Context.cpp
+++ b/core/fxcodec/jbig2/JBig2_Context.cpp
@@ -46,11 +46,12 @@ size_t GetRefAggContextSize(bool val) {
// difference for typical JBIG2 documents.
static const int kSymbolDictCacheMaxSize = 2;
-CJBig2_Context::CJBig2_Context(CPDF_StreamAcc* pGlobalStream,
- CPDF_StreamAcc* pSrcStream,
- std::list<CJBig2_CachePair>* pSymbolDictCache,
- IFX_Pause* pPause,
- bool bIsGlobal)
+CJBig2_Context::CJBig2_Context(
+ const CFX_RetainPtr<CPDF_StreamAcc>& pGlobalStream,
+ const CFX_RetainPtr<CPDF_StreamAcc>& pSrcStream,
+ std::list<CJBig2_CachePair>* pSymbolDictCache,
+ IFX_Pause* pPause,
+ bool bIsGlobal)
: m_nSegmentDecoded(0),
m_bInPage(false),
m_bBufSpecified(false),
diff --git a/core/fxcodec/jbig2/JBig2_Context.h b/core/fxcodec/jbig2/JBig2_Context.h
index cd44a82c61..31865d4d46 100644
--- a/core/fxcodec/jbig2/JBig2_Context.h
+++ b/core/fxcodec/jbig2/JBig2_Context.h
@@ -40,8 +40,8 @@ using CJBig2_CachePair =
class CJBig2_Context {
public:
- CJBig2_Context(CPDF_StreamAcc* pGlobalStream,
- CPDF_StreamAcc* pSrcStream,
+ CJBig2_Context(const CFX_RetainPtr<CPDF_StreamAcc>& pGlobalStream,
+ const CFX_RetainPtr<CPDF_StreamAcc>& pSrcStream,
std::list<CJBig2_CachePair>* pSymbolDictCache,
IFX_Pause* pPause,
bool bIsGlobal);