summaryrefslogtreecommitdiff
path: root/core/fxcodec
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-10-09 19:44:11 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-09 19:44:11 +0000
commit3e838a75ae5c0bb0e524f745df69e54a021fc5ec (patch)
tree92d389fbba456469c14e75d7723493dc85603b81 /core/fxcodec
parent78606af0550f34a41d262e0a01381f48b7dfe197 (diff)
downloadpdfium-3e838a75ae5c0bb0e524f745df69e54a021fc5ec.tar.xz
Pass CFX_CodecMemory in place of spans to codecs.
Next step towards making CFX_CodecMemory own the memory it is ref-counting. Change-Id: I5922d80d13032c3ea028447c47d34a10234109a3 Reviewed-on: https://pdfium-review.googlesource.com/c/43630 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcodec')
-rw-r--r--core/fxcodec/bmp/cfx_bmpdecompressor.cpp6
-rw-r--r--core/fxcodec/bmp/cfx_bmpdecompressor.h2
-rw-r--r--core/fxcodec/codec/ccodec_bmpmodule.cpp7
-rw-r--r--core/fxcodec/codec/ccodec_bmpmodule.h2
-rw-r--r--core/fxcodec/codec/ccodec_gifmodule.cpp5
-rw-r--r--core/fxcodec/codec/ccodec_gifmodule.h2
-rw-r--r--core/fxcodec/codec/ccodec_jpegmodule.cpp3
-rw-r--r--core/fxcodec/codec/ccodec_jpegmodule.h2
-rw-r--r--core/fxcodec/codec/ccodec_pngmodule.cpp3
-rw-r--r--core/fxcodec/codec/ccodec_pngmodule.h2
-rw-r--r--core/fxcodec/codec/ccodec_progressivedecoder.cpp40
-rw-r--r--core/fxcodec/codec/ccodec_tiffmodule.cpp2
-rw-r--r--core/fxcodec/codec/ccodec_tiffmodule.h2
-rw-r--r--core/fxcodec/codec/cfx_codec_memory.h1
-rw-r--r--core/fxcodec/codec/codec_module_iface.h3
-rw-r--r--core/fxcodec/gif/cfx_gifcontext.cpp4
-rw-r--r--core/fxcodec/gif/cfx_gifcontext.h2
-rw-r--r--core/fxcodec/gif/cfx_gifcontext_unittest.cpp96
18 files changed, 111 insertions, 73 deletions
diff --git a/core/fxcodec/bmp/cfx_bmpdecompressor.cpp b/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
index de97c6d527..35b76f2343 100644
--- a/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
+++ b/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
@@ -8,6 +8,7 @@
#include <algorithm>
#include <limits>
+#include <utility>
#include "core/fxcodec/bmp/cfx_bmpcontext.h"
#include "core/fxcrt/fx_safe_types.h"
@@ -659,8 +660,9 @@ void CFX_BmpDecompressor::SaveDecodingStatus(int32_t status) {
decode_status_ = status;
}
-void CFX_BmpDecompressor::SetInputBuffer(pdfium::span<uint8_t> src_buf) {
- input_buffer_ = pdfium::MakeRetain<CFX_CodecMemory>(src_buf);
+void CFX_BmpDecompressor::SetInputBuffer(
+ RetainPtr<CFX_CodecMemory> codec_memory) {
+ input_buffer_ = std::move(codec_memory);
}
FX_FILESIZE CFX_BmpDecompressor::GetAvailInput() const {
diff --git a/core/fxcodec/bmp/cfx_bmpdecompressor.h b/core/fxcodec/bmp/cfx_bmpdecompressor.h
index beaf9bf78a..53d52ae14c 100644
--- a/core/fxcodec/bmp/cfx_bmpdecompressor.h
+++ b/core/fxcodec/bmp/cfx_bmpdecompressor.h
@@ -25,7 +25,7 @@ class CFX_BmpDecompressor {
void Error();
int32_t DecodeImage();
int32_t ReadHeader();
- void SetInputBuffer(pdfium::span<uint8_t> src_buf);
+ void SetInputBuffer(RetainPtr<CFX_CodecMemory> codec_memory);
FX_FILESIZE GetAvailInput() const;
jmp_buf jmpbuf_;
diff --git a/core/fxcodec/codec/ccodec_bmpmodule.cpp b/core/fxcodec/codec/ccodec_bmpmodule.cpp
index 9884662bd3..37a0b2cb29 100644
--- a/core/fxcodec/codec/ccodec_bmpmodule.cpp
+++ b/core/fxcodec/codec/ccodec_bmpmodule.cpp
@@ -6,6 +6,8 @@
#include "core/fxcodec/codec/ccodec_bmpmodule.h"
+#include <utility>
+
#include "core/fxcodec/bmp/cfx_bmpcontext.h"
#include "core/fxcodec/codec/codec_int.h"
#include "core/fxcodec/fx_codec.h"
@@ -68,8 +70,9 @@ FX_FILESIZE CCodec_BmpModule::GetAvailInput(Context* pContext) const {
}
bool CCodec_BmpModule::Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute*) {
- static_cast<CFX_BmpContext*>(pContext)->m_Bmp.SetInputBuffer(src_buf);
+ auto* ctx = static_cast<CFX_BmpContext*>(pContext);
+ ctx->m_Bmp.SetInputBuffer(std::move(codec_memory));
return true;
}
diff --git a/core/fxcodec/codec/ccodec_bmpmodule.h b/core/fxcodec/codec/ccodec_bmpmodule.h
index d5b6a75494..f8a82727bc 100644
--- a/core/fxcodec/codec/ccodec_bmpmodule.h
+++ b/core/fxcodec/codec/ccodec_bmpmodule.h
@@ -32,7 +32,7 @@ class CCodec_BmpModule final : public CodecModuleIface {
// CodecModuleIface:
FX_FILESIZE GetAvailInput(Context* pContext) const override;
bool Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute* pAttribute) override;
std::unique_ptr<Context> Start(Delegate* pDelegate);
diff --git a/core/fxcodec/codec/ccodec_gifmodule.cpp b/core/fxcodec/codec/ccodec_gifmodule.cpp
index 289993c903..4162171827 100644
--- a/core/fxcodec/codec/ccodec_gifmodule.cpp
+++ b/core/fxcodec/codec/ccodec_gifmodule.cpp
@@ -71,8 +71,9 @@ FX_FILESIZE CCodec_GifModule::GetAvailInput(Context* pContext) const {
}
bool CCodec_GifModule::Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute*) {
- static_cast<CFX_GifContext*>(pContext)->SetInputBuffer(src_buf);
+ auto* ctx = static_cast<CFX_GifContext*>(pContext);
+ ctx->SetInputBuffer(std::move(codec_memory));
return true;
}
diff --git a/core/fxcodec/codec/ccodec_gifmodule.h b/core/fxcodec/codec/ccodec_gifmodule.h
index 665208ba1a..0e85998dc3 100644
--- a/core/fxcodec/codec/ccodec_gifmodule.h
+++ b/core/fxcodec/codec/ccodec_gifmodule.h
@@ -41,7 +41,7 @@ class CCodec_GifModule final : public CodecModuleIface {
// CodecModuleIface:
FX_FILESIZE GetAvailInput(Context* context) const override;
bool Input(Context* context,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute* pAttribute) override;
std::unique_ptr<Context> Start(Delegate* pDelegate);
diff --git a/core/fxcodec/codec/ccodec_jpegmodule.cpp b/core/fxcodec/codec/ccodec_jpegmodule.cpp
index 7c15aa35a0..4a6059ad18 100644
--- a/core/fxcodec/codec/ccodec_jpegmodule.cpp
+++ b/core/fxcodec/codec/ccodec_jpegmodule.cpp
@@ -413,8 +413,9 @@ std::unique_ptr<CodecModuleIface::Context> CCodec_JpegModule::Start() {
}
bool CCodec_JpegModule::Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute*) {
+ pdfium::span<uint8_t> src_buf = codec_memory->GetSpan();
auto* ctx = static_cast<CJpegContext*>(pContext);
if (ctx->m_SkipSize) {
if (ctx->m_SkipSize > src_buf.size()) {
diff --git a/core/fxcodec/codec/ccodec_jpegmodule.h b/core/fxcodec/codec/ccodec_jpegmodule.h
index 45b1d1b6d1..258038f9cd 100644
--- a/core/fxcodec/codec/ccodec_jpegmodule.h
+++ b/core/fxcodec/codec/ccodec_jpegmodule.h
@@ -31,7 +31,7 @@ class CCodec_JpegModule final : public CodecModuleIface {
// CodecModuleIface:
FX_FILESIZE GetAvailInput(Context* pContext) const override;
bool Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute* pAttribute) override;
jmp_buf* GetJumpMark(Context* pContext);
diff --git a/core/fxcodec/codec/ccodec_pngmodule.cpp b/core/fxcodec/codec/ccodec_pngmodule.cpp
index 593c215db4..31de538087 100644
--- a/core/fxcodec/codec/ccodec_pngmodule.cpp
+++ b/core/fxcodec/codec/ccodec_pngmodule.cpp
@@ -210,7 +210,7 @@ FX_FILESIZE CCodec_PngModule::GetAvailInput(Context* pContext) const {
}
bool CCodec_PngModule::Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute* pAttribute) {
auto* ctx = static_cast<CPngContext*>(pContext);
if (setjmp(png_jmpbuf(ctx->m_pPng))) {
@@ -220,6 +220,7 @@ bool CCodec_PngModule::Input(Context* pContext,
}
return false;
}
+ pdfium::span<uint8_t> src_buf = codec_memory->GetSpan();
png_process_data(ctx->m_pPng, ctx->m_pInfo, src_buf.data(), src_buf.size());
return true;
}
diff --git a/core/fxcodec/codec/ccodec_pngmodule.h b/core/fxcodec/codec/ccodec_pngmodule.h
index e97a221dfc..9754cb3bbd 100644
--- a/core/fxcodec/codec/ccodec_pngmodule.h
+++ b/core/fxcodec/codec/ccodec_pngmodule.h
@@ -35,7 +35,7 @@ class CCodec_PngModule final : public CodecModuleIface {
// CodecModuleIface:
FX_FILESIZE GetAvailInput(Context* pContext) const override;
bool Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute* pAttribute) override;
std::unique_ptr<Context> Start(Delegate* pDelegate);
diff --git a/core/fxcodec/codec/ccodec_progressivedecoder.cpp b/core/fxcodec/codec/ccodec_progressivedecoder.cpp
index 0e6014595e..07665c1d4a 100644
--- a/core/fxcodec/codec/ccodec_progressivedecoder.cpp
+++ b/core/fxcodec/codec/ccodec_progressivedecoder.cpp
@@ -718,7 +718,10 @@ bool CCodec_ProgressiveDecoder::BmpDetectImageTypeInBuffer(
std::unique_ptr<CodecModuleIface::Context> pBmpContext =
pBmpModule->Start(this);
- pBmpModule->Input(pBmpContext.get(), {m_pSrcBuf.get(), m_SrcSize}, nullptr);
+ pBmpModule->Input(pBmpContext.get(),
+ pdfium::MakeRetain<CFX_CodecMemory>(
+ pdfium::make_span(m_pSrcBuf.get(), m_SrcSize)),
+ nullptr);
std::vector<uint32_t> palette;
int32_t readResult = pBmpModule->ReadHeader(
@@ -863,7 +866,10 @@ bool CCodec_ProgressiveDecoder::GifDetectImageTypeInBuffer(
return false;
}
m_pGifContext = pGifModule->Start(this);
- pGifModule->Input(m_pGifContext.get(), {m_pSrcBuf.get(), m_SrcSize}, nullptr);
+ pGifModule->Input(m_pGifContext.get(),
+ pdfium::MakeRetain<CFX_CodecMemory>(
+ pdfium::make_span(m_pSrcBuf.get(), m_SrcSize)),
+ nullptr);
m_SrcComponents = 1;
CFX_GifDecodeStatus readResult = pGifModule->ReadHeader(
m_pGifContext.get(), &m_SrcWidth, &m_SrcHeight, &m_GifPltNumber,
@@ -1046,7 +1052,9 @@ bool CCodec_ProgressiveDecoder::JpegDetectImageTypeInBuffer(
m_status = FXCODEC_STATUS_ERR_MEMORY;
return false;
}
- pJpegModule->Input(m_pJpegContext.get(), {m_pSrcBuf.get(), m_SrcSize},
+ pJpegModule->Input(m_pJpegContext.get(),
+ pdfium::MakeRetain<CFX_CodecMemory>(
+ pdfium::make_span(m_pSrcBuf.get(), m_SrcSize)),
nullptr);
// Setting jump marker before calling ReadHeader, since a longjmp to
// the marker indicates a fatal error.
@@ -1256,8 +1264,11 @@ bool CCodec_ProgressiveDecoder::PngDetectImageTypeInBuffer(
m_status = FXCODEC_STATUS_ERR_MEMORY;
return false;
}
- bool bResult = pPngModule->Input(m_pPngContext.get(),
- {m_pSrcBuf.get(), m_SrcSize}, pAttribute);
+ bool bResult =
+ pPngModule->Input(m_pPngContext.get(),
+ pdfium::MakeRetain<CFX_CodecMemory>(
+ pdfium::make_span(m_pSrcBuf.get(), m_SrcSize)),
+ pAttribute);
while (bResult) {
uint32_t remain_size = static_cast<uint32_t>(m_pFile->GetSize()) - m_offSet;
uint32_t input_size =
@@ -1277,8 +1288,11 @@ bool CCodec_ProgressiveDecoder::PngDetectImageTypeInBuffer(
return false;
}
m_offSet += input_size;
- bResult = pPngModule->Input(m_pPngContext.get(),
- {m_pSrcBuf.get(), input_size}, pAttribute);
+ bResult =
+ pPngModule->Input(m_pPngContext.get(),
+ pdfium::MakeRetain<CFX_CodecMemory>(
+ pdfium::make_span(m_pSrcBuf.get(), input_size)),
+ pAttribute);
}
m_pPngContext.reset();
if (m_SrcPassNumber == 0) {
@@ -1365,8 +1379,11 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::PngContinueDecode() {
return m_status;
}
m_offSet += input_size;
- bResult = pPngModule->Input(m_pPngContext.get(),
- {m_pSrcBuf.get(), input_size}, nullptr);
+ bResult =
+ pPngModule->Input(m_pPngContext.get(),
+ pdfium::MakeRetain<CFX_CodecMemory>(
+ pdfium::make_span(m_pSrcBuf.get(), input_size)),
+ nullptr);
if (!bResult) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
@@ -1633,7 +1650,10 @@ bool CCodec_ProgressiveDecoder::ReadMoreData(
return false;
}
m_offSet += dwBytesToFetchFromFile;
- return pModule->Input(pContext, {m_pSrcBuf.get(), m_SrcSize}, nullptr);
+ return pModule->Input(pContext,
+ pdfium::MakeRetain<CFX_CodecMemory>(
+ pdfium::make_span(m_pSrcBuf.get(), m_SrcSize)),
+ nullptr);
}
FXCODEC_STATUS CCodec_ProgressiveDecoder::LoadImageInfo(
diff --git a/core/fxcodec/codec/ccodec_tiffmodule.cpp b/core/fxcodec/codec/ccodec_tiffmodule.cpp
index d2c6c26dc0..15b80676b5 100644
--- a/core/fxcodec/codec/ccodec_tiffmodule.cpp
+++ b/core/fxcodec/codec/ccodec_tiffmodule.cpp
@@ -502,7 +502,7 @@ FX_FILESIZE CCodec_TiffModule::GetAvailInput(Context* pContext) const {
}
bool CCodec_TiffModule::Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute*) {
NOTREACHED();
return false;
diff --git a/core/fxcodec/codec/ccodec_tiffmodule.h b/core/fxcodec/codec/ccodec_tiffmodule.h
index 15d2a9f6d2..eee24de410 100644
--- a/core/fxcodec/codec/ccodec_tiffmodule.h
+++ b/core/fxcodec/codec/ccodec_tiffmodule.h
@@ -25,7 +25,7 @@ class CCodec_TiffModule final : public CodecModuleIface {
// CodecModuleIface:
FX_FILESIZE GetAvailInput(Context* pContext) const override;
bool Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute* pAttribute) override;
bool LoadFrameInfo(Context* ctx,
diff --git a/core/fxcodec/codec/cfx_codec_memory.h b/core/fxcodec/codec/cfx_codec_memory.h
index 2907e892d2..0d11d41de8 100644
--- a/core/fxcodec/codec/cfx_codec_memory.h
+++ b/core/fxcodec/codec/cfx_codec_memory.h
@@ -13,6 +13,7 @@ class CFX_CodecMemory final : public Retainable {
template <typename T, typename... Args>
friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+ pdfium::span<uint8_t> GetSpan() { return buffer_; }
uint8_t* GetBuffer() { return buffer_.data(); }
size_t GetSize() const { return buffer_.size(); }
size_t GetPosition() const { return pos_; }
diff --git a/core/fxcodec/codec/codec_module_iface.h b/core/fxcodec/codec/codec_module_iface.h
index e7faa892b2..52cb564d9a 100644
--- a/core/fxcodec/codec/codec_module_iface.h
+++ b/core/fxcodec/codec/codec_module_iface.h
@@ -7,6 +7,7 @@
#ifndef CORE_FXCODEC_CODEC_CODEC_MODULE_IFACE_H_
#define CORE_FXCODEC_CODEC_CODEC_MODULE_IFACE_H_
+#include "core/fxcodec/codec/cfx_codec_memory.h"
#include "core/fxcrt/fx_system.h"
#include "third_party/base/span.h"
@@ -28,7 +29,7 @@ class CodecModuleIface {
// setting details about the image extracted from the buffer into |pAttribute|
// (if provided and the codec is capable providing that information).
virtual bool Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute* pAttribute) = 0;
};
diff --git a/core/fxcodec/gif/cfx_gifcontext.cpp b/core/fxcodec/gif/cfx_gifcontext.cpp
index c1467ae233..076331f418 100644
--- a/core/fxcodec/gif/cfx_gifcontext.cpp
+++ b/core/fxcodec/gif/cfx_gifcontext.cpp
@@ -342,8 +342,8 @@ CFX_GifDecodeStatus CFX_GifContext::LoadFrame(int32_t frame_num) {
return CFX_GifDecodeStatus::Error;
}
-void CFX_GifContext::SetInputBuffer(pdfium::span<uint8_t> src_buf) {
- input_buffer_ = pdfium::MakeRetain<CFX_CodecMemory>(src_buf);
+void CFX_GifContext::SetInputBuffer(RetainPtr<CFX_CodecMemory> codec_memory) {
+ input_buffer_ = std::move(codec_memory);
}
uint32_t CFX_GifContext::GetAvailInput() const {
diff --git a/core/fxcodec/gif/cfx_gifcontext.h b/core/fxcodec/gif/cfx_gifcontext.h
index c2828db6bb..4cf84a5ac6 100644
--- a/core/fxcodec/gif/cfx_gifcontext.h
+++ b/core/fxcodec/gif/cfx_gifcontext.h
@@ -41,7 +41,7 @@ class CFX_GifContext : public CodecModuleIface::Context {
CFX_GifDecodeStatus ReadHeader();
CFX_GifDecodeStatus GetFrame();
CFX_GifDecodeStatus LoadFrame(int32_t frame_num);
- void SetInputBuffer(pdfium::span<uint8_t> src_buf);
+ void SetInputBuffer(RetainPtr<CFX_CodecMemory> codec_memory);
uint32_t GetAvailInput() const;
size_t GetFrameNum() const { return images_.size(); }
diff --git a/core/fxcodec/gif/cfx_gifcontext_unittest.cpp b/core/fxcodec/gif/cfx_gifcontext_unittest.cpp
index b9805ef399..31cac45795 100644
--- a/core/fxcodec/gif/cfx_gifcontext_unittest.cpp
+++ b/core/fxcodec/gif/cfx_gifcontext_unittest.cpp
@@ -19,6 +19,9 @@ class CFX_GifContextForTest final : public CFX_GifContext {
using CFX_GifContext::ReadLogicalScreenDescriptor;
CFX_CodecMemory* InputBuffer() const { return input_buffer_.Get(); }
+ void SetTestInputBuffer(pdfium::span<uint8_t> input) {
+ SetInputBuffer(pdfium::MakeRetain<CFX_CodecMemory>(input));
+ }
};
TEST(CFX_GifContext, SetInputBuffer) {
@@ -27,27 +30,27 @@ TEST(CFX_GifContext, SetInputBuffer) {
// Context must not outlive its buffers.
CFX_GifContextForTest context(nullptr, nullptr);
- context.SetInputBuffer({nullptr, 0});
+ context.SetTestInputBuffer({nullptr, 0});
EXPECT_EQ(nullptr, context.InputBuffer()->GetBuffer());
EXPECT_EQ(0u, context.InputBuffer()->GetSize());
EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
- context.SetInputBuffer({nullptr, 100});
+ context.SetTestInputBuffer({nullptr, 100});
EXPECT_EQ(nullptr, context.InputBuffer()->GetBuffer());
EXPECT_EQ(100u, context.InputBuffer()->GetSize());
EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
- context.SetInputBuffer({buffer, 0});
+ context.SetTestInputBuffer({buffer, 0});
EXPECT_EQ(buffer, context.InputBuffer()->GetBuffer());
EXPECT_EQ(0u, context.InputBuffer()->GetSize());
EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
- context.SetInputBuffer({buffer, 3});
+ context.SetTestInputBuffer({buffer, 3});
EXPECT_EQ(buffer, context.InputBuffer()->GetBuffer());
EXPECT_EQ(3u, context.InputBuffer()->GetSize());
EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
- context.SetInputBuffer({buffer, 100});
+ context.SetTestInputBuffer({buffer, 100});
EXPECT_EQ(buffer, context.InputBuffer()->GetBuffer());
EXPECT_EQ(100u, context.InputBuffer()->GetSize());
EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
@@ -62,18 +65,18 @@ TEST(CFX_GifContext, ReadAllOrNone) {
// Context must not outlive its buffers.
CFX_GifContextForTest context(nullptr, nullptr);
- context.SetInputBuffer({nullptr, 0});
+ context.SetTestInputBuffer({nullptr, 0});
EXPECT_FALSE(context.ReadAllOrNone(nullptr, 0));
EXPECT_FALSE(context.ReadAllOrNone(nullptr, 10));
EXPECT_FALSE(context.ReadAllOrNone(dest_buffer.data(), 0));
EXPECT_FALSE(context.ReadAllOrNone(dest_buffer.data(), 10));
- context.SetInputBuffer({src_buffer, 0});
+ context.SetTestInputBuffer({src_buffer, 0});
dest_buffer.resize(sizeof(src_buffer));
EXPECT_FALSE(context.ReadAllOrNone(dest_buffer.data(), sizeof(src_buffer)));
- context.SetInputBuffer({src_buffer, 1});
+ context.SetTestInputBuffer({src_buffer, 1});
EXPECT_FALSE(context.ReadAllOrNone(dest_buffer.data(), sizeof(src_buffer)));
EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
EXPECT_FALSE(context.ReadAllOrNone(nullptr, sizeof(src_buffer)));
@@ -81,13 +84,13 @@ TEST(CFX_GifContext, ReadAllOrNone) {
EXPECT_TRUE(context.ReadAllOrNone(dest_buffer.data(), 1));
EXPECT_EQ(src_buffer[0], dest_buffer[0]);
- context.SetInputBuffer(src_buffer);
+ context.SetTestInputBuffer(src_buffer);
EXPECT_FALSE(context.ReadAllOrNone(nullptr, sizeof(src_buffer)));
EXPECT_TRUE(context.ReadAllOrNone(dest_buffer.data(), sizeof(src_buffer)));
for (size_t i = 0; i < sizeof(src_buffer); i++)
EXPECT_EQ(src_buffer[i], dest_buffer[i]);
- context.SetInputBuffer(src_buffer);
+ context.SetTestInputBuffer(src_buffer);
for (size_t i = 0; i < sizeof(src_buffer); i++) {
EXPECT_TRUE(context.ReadAllOrNone(dest_buffer.data(), 1));
EXPECT_EQ(src_buffer[i], dest_buffer[0]);
@@ -99,57 +102,57 @@ TEST(CFX_GifContext, ReadGifSignature) {
CFX_GifContextForTest context(nullptr, nullptr);
{
uint8_t data[1];
- context.SetInputBuffer({data, 0});
+ context.SetTestInputBuffer({data, 0});
EXPECT_EQ(CFX_GifDecodeStatus::Unfinished, context.ReadGifSignature());
EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
- context.SetInputBuffer({});
+ context.SetTestInputBuffer({});
}
// Make sure testing the entire signature
{
uint8_t data[] = {'G', 'I', 'F'};
- context.SetInputBuffer(data);
+ context.SetTestInputBuffer(data);
EXPECT_EQ(CFX_GifDecodeStatus::Unfinished, context.ReadGifSignature());
EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
- context.SetInputBuffer({});
+ context.SetTestInputBuffer({});
}
{
uint8_t data[] = {'N', 'O', 'T', 'G', 'I', 'F'};
- context.SetInputBuffer(data);
+ context.SetTestInputBuffer(data);
EXPECT_EQ(CFX_GifDecodeStatus::Error, context.ReadGifSignature());
EXPECT_EQ(6u, context.InputBuffer()->GetPosition());
- context.SetInputBuffer({});
+ context.SetTestInputBuffer({});
}
// Make sure not matching GIF8*a
{
uint8_t data[] = {'G', 'I', 'F', '8', '0', 'a'};
- context.SetInputBuffer(data);
+ context.SetTestInputBuffer(data);
EXPECT_EQ(CFX_GifDecodeStatus::Error, context.ReadGifSignature());
EXPECT_EQ(6u, context.InputBuffer()->GetPosition());
- context.SetInputBuffer({});
+ context.SetTestInputBuffer({});
}
// Make sure not matching GIF**a
{
uint8_t data[] = {'G', 'I', 'F', '9', '2', 'a'};
- context.SetInputBuffer(data);
+ context.SetTestInputBuffer(data);
EXPECT_EQ(CFX_GifDecodeStatus::Error, context.ReadGifSignature());
EXPECT_EQ(6u, context.InputBuffer()->GetPosition());
- context.SetInputBuffer({});
+ context.SetTestInputBuffer({});
}
// One valid signature
{
uint8_t data[] = {'G', 'I', 'F', '8', '7', 'a'};
- context.SetInputBuffer(data);
+ context.SetTestInputBuffer(data);
EXPECT_EQ(CFX_GifDecodeStatus::Success, context.ReadGifSignature());
EXPECT_EQ(6u, context.InputBuffer()->GetPosition());
- context.SetInputBuffer({});
+ context.SetTestInputBuffer({});
}
// The other valid signature
{
uint8_t data[] = {'G', 'I', 'F', '8', '9', 'a'};
- context.SetInputBuffer(data);
+ context.SetTestInputBuffer(data);
EXPECT_EQ(CFX_GifDecodeStatus::Success, context.ReadGifSignature());
EXPECT_EQ(6u, context.InputBuffer()->GetPosition());
- context.SetInputBuffer({});
+ context.SetTestInputBuffer({});
}
}
@@ -157,16 +160,16 @@ TEST(CFX_GifContext, ReadLocalScreenDescriptor) {
CFX_GifContextForTest context(nullptr, nullptr);
{
uint8_t data[1];
- context.SetInputBuffer({data, 0});
+ context.SetTestInputBuffer({data, 0});
EXPECT_EQ(CFX_GifDecodeStatus::Unfinished,
context.ReadLogicalScreenDescriptor());
- context.SetInputBuffer({});
+ context.SetTestInputBuffer({});
}
// LSD with all the values zero'd
{
uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)];
memset(&lsd, 0, sizeof(CFX_GifLocalScreenDescriptor));
- context.SetInputBuffer(lsd);
+ context.SetTestInputBuffer(lsd);
EXPECT_EQ(CFX_GifDecodeStatus::Success,
context.ReadLogicalScreenDescriptor());
@@ -177,13 +180,13 @@ TEST(CFX_GifContext, ReadLocalScreenDescriptor) {
EXPECT_EQ(0, context.height_);
EXPECT_EQ(0u, context.bc_index_);
EXPECT_EQ(0u, context.pixel_aspect_);
- context.SetInputBuffer({});
+ context.SetTestInputBuffer({});
}
// LSD with no global palette
{
uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)] = {0x0A, 0x00, 0x00, 0x0F,
0x00, 0x01, 0x02};
- context.SetInputBuffer(lsd);
+ context.SetTestInputBuffer(lsd);
EXPECT_EQ(CFX_GifDecodeStatus::Success,
context.ReadLogicalScreenDescriptor());
@@ -194,19 +197,19 @@ TEST(CFX_GifContext, ReadLocalScreenDescriptor) {
EXPECT_EQ(0x0F00, context.height_);
EXPECT_EQ(0u, context.bc_index_); // bc_index_ is 0 if no global palette
EXPECT_EQ(2u, context.pixel_aspect_);
- context.SetInputBuffer({});
+ context.SetTestInputBuffer({});
}
// LSD with global palette bit set, but no global palette
{
uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)] = {0x0A, 0x00, 0x00, 0x0F,
0x80, 0x01, 0x02};
- context.SetInputBuffer(lsd);
+ context.SetTestInputBuffer(lsd);
EXPECT_EQ(CFX_GifDecodeStatus::Unfinished,
context.ReadLogicalScreenDescriptor());
EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
- context.SetInputBuffer({});
+ context.SetTestInputBuffer({});
}
// LSD with global palette
{
@@ -215,7 +218,8 @@ TEST(CFX_GifContext, ReadLocalScreenDescriptor) {
uint8_t palette[4 * sizeof(CFX_GifPalette)];
} data = {{0x0A, 0x00, 0x00, 0x0F, 0xA9, 0x01, 0x02},
{0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1}};
- context.SetInputBuffer({reinterpret_cast<uint8_t*>(&data), sizeof(data)});
+ context.SetTestInputBuffer(
+ {reinterpret_cast<uint8_t*>(&data), sizeof(data)});
EXPECT_EQ(CFX_GifDecodeStatus::Success,
context.ReadLogicalScreenDescriptor());
@@ -230,7 +234,7 @@ TEST(CFX_GifContext, ReadLocalScreenDescriptor) {
EXPECT_EQ(2, context.global_color_resolution_);
EXPECT_EQ(0, memcmp(data.palette, context.global_palette_.data(),
sizeof(data.palette)));
- context.SetInputBuffer({});
+ context.SetTestInputBuffer({});
}
}
@@ -243,21 +247,22 @@ TEST(CFX_GifContext, ReadHeader) {
uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)];
} data = {{'N', 'O', 'T', 'G', 'I', 'F'},
{0x0A, 0x00, 0x00, 0x0F, 0x00, 0x01, 0x02}};
- context.SetInputBuffer({reinterpret_cast<uint8_t*>(&data), sizeof(data)});
+ context.SetTestInputBuffer(
+ {reinterpret_cast<uint8_t*>(&data), sizeof(data)});
EXPECT_EQ(CFX_GifDecodeStatus::Error, context.ReadHeader());
EXPECT_EQ(sizeof(data.signature), context.InputBuffer()->GetPosition());
- context.SetInputBuffer({});
+ context.SetTestInputBuffer({});
}
// Short after signature
{
uint8_t signature[] = {'G', 'I', 'F', '8', '7', 'a'};
- context.SetInputBuffer(
+ context.SetTestInputBuffer(
{reinterpret_cast<uint8_t*>(&signature), sizeof(signature)});
EXPECT_EQ(CFX_GifDecodeStatus::Unfinished, context.ReadHeader());
EXPECT_EQ(sizeof(signature), context.InputBuffer()->GetPosition());
- context.SetInputBuffer({});
+ context.SetTestInputBuffer({});
}
// Success without global palette
{
@@ -266,7 +271,8 @@ TEST(CFX_GifContext, ReadHeader) {
uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)];
} data = {{'G', 'I', 'F', '8', '7', 'a'},
{0x0A, 0x00, 0x00, 0x0F, 0x00, 0x01, 0x02}};
- context.SetInputBuffer({reinterpret_cast<uint8_t*>(&data), sizeof(data)});
+ context.SetTestInputBuffer(
+ {reinterpret_cast<uint8_t*>(&data), sizeof(data)});
EXPECT_EQ(CFX_GifDecodeStatus::Success, context.ReadHeader());
EXPECT_EQ(sizeof(data), context.InputBuffer()->GetPosition());
@@ -274,7 +280,7 @@ TEST(CFX_GifContext, ReadHeader) {
EXPECT_EQ(0x0F00, context.height_);
EXPECT_EQ(0u, context.bc_index_); // bc_index_ is 0 if no global palette
EXPECT_EQ(2u, context.pixel_aspect_);
- context.SetInputBuffer({});
+ context.SetTestInputBuffer({});
}
// Missing Global Palette
{
@@ -283,11 +289,12 @@ TEST(CFX_GifContext, ReadHeader) {
uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)];
} data = {{'G', 'I', 'F', '8', '7', 'a'},
{0x0A, 0x00, 0x00, 0x0F, 0x80, 0x01, 0x02}};
- context.SetInputBuffer({reinterpret_cast<uint8_t*>(&data), sizeof(data)});
+ context.SetTestInputBuffer(
+ {reinterpret_cast<uint8_t*>(&data), sizeof(data)});
EXPECT_EQ(CFX_GifDecodeStatus::Unfinished, context.ReadHeader());
EXPECT_EQ(sizeof(data.signature), context.InputBuffer()->GetPosition());
- context.SetInputBuffer({});
+ context.SetTestInputBuffer({});
}
// Success with global palette
{
@@ -298,7 +305,8 @@ TEST(CFX_GifContext, ReadHeader) {
} data = {{'G', 'I', 'F', '8', '7', 'a'},
{0x0A, 0x00, 0x00, 0x0F, 0xA9, 0x01, 0x02},
{0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1}};
- context.SetInputBuffer({reinterpret_cast<uint8_t*>(&data), sizeof(data)});
+ context.SetTestInputBuffer(
+ {reinterpret_cast<uint8_t*>(&data), sizeof(data)});
EXPECT_EQ(CFX_GifDecodeStatus::Success, context.ReadHeader());
EXPECT_EQ(sizeof(data), context.InputBuffer()->GetPosition());
@@ -311,6 +319,6 @@ TEST(CFX_GifContext, ReadHeader) {
EXPECT_EQ(2, context.global_color_resolution_);
EXPECT_EQ(0, memcmp(data.palette, context.global_palette_.data(),
sizeof(data.palette)));
- context.SetInputBuffer({});
+ context.SetTestInputBuffer({});
}
}