summaryrefslogtreecommitdiff
path: root/core/fxcodec/codec/ccodec_jpegmodule.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-09-25 20:06:50 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-09-25 20:06:50 +0000
commit958142efa4561b5efd52733ad6c3b889cf49b3ae (patch)
treeda605e08bceccbae3e23d87471c197b37ac48e28 /core/fxcodec/codec/ccodec_jpegmodule.cpp
parentfed6e124109f089a38e24e37b104d983231bee78 (diff)
downloadpdfium-958142efa4561b5efd52733ad6c3b889cf49b3ae.tar.xz
Introduce CodecModuleIface for progressive decoder modules.
Another step before trying to fix the memory issue. Forces common APIs on the bunch of decoders, though some methods are unused. Requires adding some arguments/return values to get to a common API which are not used in all cases (yet?). Required converting some args to spans. Required proxying a GetJumpMark() call through the public module API to the private context. Bug: pdfium:1082 Change-Id: I0c0b7415141ff2a6f4f44777ca3d05521f08130d Reviewed-on: https://pdfium-review.googlesource.com/41950 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcodec/codec/ccodec_jpegmodule.cpp')
-rw-r--r--core/fxcodec/codec/ccodec_jpegmodule.cpp34
1 files changed, 19 insertions, 15 deletions
diff --git a/core/fxcodec/codec/ccodec_jpegmodule.cpp b/core/fxcodec/codec/ccodec_jpegmodule.cpp
index aaf16ae762..7c15aa35a0 100644
--- a/core/fxcodec/codec/ccodec_jpegmodule.cpp
+++ b/core/fxcodec/codec/ccodec_jpegmodule.cpp
@@ -31,12 +31,12 @@ extern "C" {
#endif
} // extern "C"
-class CJpegContext final : public CCodec_JpegModule::Context {
+class CJpegContext final : public CodecModuleIface::Context {
public:
CJpegContext();
~CJpegContext() override;
- jmp_buf* GetJumpMark() override { return &m_JumpMark; }
+ jmp_buf* GetJumpMark() { return &m_JumpMark; }
jmp_buf m_JumpMark;
jpeg_decompress_struct m_Info;
@@ -398,7 +398,7 @@ CJpegContext::~CJpegContext() {
jpeg_destroy_decompress(&m_Info);
}
-std::unique_ptr<CCodec_JpegModule::Context> CCodec_JpegModule::Start() {
+std::unique_ptr<CodecModuleIface::Context> CCodec_JpegModule::Start() {
// Use ordinary pointer until past the possibility of a longjump.
auto* pContext = new CJpegContext();
if (setjmp(pContext->m_JumpMark) == -1) {
@@ -412,22 +412,22 @@ std::unique_ptr<CCodec_JpegModule::Context> CCodec_JpegModule::Start() {
return pdfium::WrapUnique(pContext);
}
-void CCodec_JpegModule::Input(Context* pContext,
- const unsigned char* src_buf,
- uint32_t src_size) {
+bool CCodec_JpegModule::Input(Context* pContext,
+ pdfium::span<uint8_t> src_buf,
+ CFX_DIBAttribute*) {
auto* ctx = static_cast<CJpegContext*>(pContext);
if (ctx->m_SkipSize) {
- if (ctx->m_SkipSize > src_size) {
+ if (ctx->m_SkipSize > src_buf.size()) {
ctx->m_SrcMgr.bytes_in_buffer = 0;
- ctx->m_SkipSize -= src_size;
- return;
+ ctx->m_SkipSize -= src_buf.size();
+ return true;
}
- src_size -= ctx->m_SkipSize;
- src_buf += ctx->m_SkipSize;
+ src_buf = src_buf.subspan(ctx->m_SkipSize);
ctx->m_SkipSize = 0;
}
- ctx->m_SrcMgr.next_input_byte = src_buf;
- ctx->m_SrcMgr.bytes_in_buffer = src_size;
+ ctx->m_SrcMgr.next_input_byte = src_buf.data();
+ ctx->m_SrcMgr.bytes_in_buffer = src_buf.size();
+ return true;
}
#ifdef PDF_ENABLE_XFA
@@ -464,9 +464,13 @@ bool CCodec_JpegModule::ReadScanline(Context* pContext,
return nlines == 1;
}
-uint32_t CCodec_JpegModule::GetAvailInput(Context* pContext) const {
+FX_FILESIZE CCodec_JpegModule::GetAvailInput(Context* pContext) const {
auto* ctx = static_cast<CJpegContext*>(pContext);
- return (uint32_t)ctx->m_SrcMgr.bytes_in_buffer;
+ return static_cast<FX_FILESIZE>(ctx->m_SrcMgr.bytes_in_buffer);
+}
+
+jmp_buf* CCodec_JpegModule::GetJumpMark(Context* pContext) {
+ return static_cast<CJpegContext*>(pContext)->GetJumpMark();
}
#if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_