summaryrefslogtreecommitdiff
path: root/core/fxcodec
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcodec')
-rw-r--r--core/fxcodec/codec/ccodec_gifmodule.cpp72
-rw-r--r--core/fxcodec/codec/ccodec_gifmodule.h18
-rw-r--r--core/fxcodec/codec/ccodec_progressivedecoder.h4
-rw-r--r--core/fxcodec/codec/fx_codec_progress.cpp38
-rw-r--r--core/fxcodec/lgif/cgifcontext.cpp64
-rw-r--r--core/fxcodec/lgif/cgifcontext.h (renamed from core/fxcodec/lgif/cgifdecompressor.h)24
-rw-r--r--core/fxcodec/lgif/cgifdecompressor.cpp69
-rw-r--r--core/fxcodec/lgif/fx_gif.cpp347
-rw-r--r--core/fxcodec/lgif/fx_gif.h15
9 files changed, 304 insertions, 347 deletions
diff --git a/core/fxcodec/codec/ccodec_gifmodule.cpp b/core/fxcodec/codec/ccodec_gifmodule.cpp
index 983daa088f..438f019ee9 100644
--- a/core/fxcodec/codec/ccodec_gifmodule.cpp
+++ b/core/fxcodec/codec/ccodec_gifmodule.cpp
@@ -8,7 +8,7 @@
#include "core/fxcodec/codec/codec_int.h"
#include "core/fxcodec/fx_codec.h"
-#include "core/fxcodec/lgif/cgifdecompressor.h"
+#include "core/fxcodec/lgif/cgifcontext.h"
#include "core/fxcodec/lgif/fx_gif.h"
#include "core/fxge/fx_dib.h"
#include "third_party/base/ptr_util.h"
@@ -19,77 +19,61 @@ CCodec_GifModule::CCodec_GifModule() {
CCodec_GifModule::~CCodec_GifModule() {}
-FXGIF_Context* CCodec_GifModule::Start() {
- FXGIF_Context* p = FX_Alloc(FXGIF_Context, 1);
- if (!p)
- return nullptr;
-
- memset(p, 0, sizeof(FXGIF_Context));
- p->parent_ptr = this;
- p->m_Gif = pdfium::MakeUnique<CGifDecompressor>(p, m_szLastError);
- return p;
-}
-
-void CCodec_GifModule::Finish(FXGIF_Context* ctx) {
- if (ctx) {
- ctx->m_Gif = nullptr;
- FX_Free(ctx);
- }
+std::unique_ptr<CGifContext> CCodec_GifModule::Start() {
+ return pdfium::MakeUnique<CGifContext>(this, m_szLastError);
}
-GifDecodeStatus CCodec_GifModule::ReadHeader(FXGIF_Context* ctx,
+GifDecodeStatus CCodec_GifModule::ReadHeader(CGifContext* context,
int* width,
int* height,
int* pal_num,
void** pal_pp,
int* bg_index,
CFX_DIBAttribute* pAttribute) {
- if (setjmp(ctx->m_Gif->jmpbuf))
+ if (setjmp(context->jmpbuf))
return GifDecodeStatus::Error;
- GifDecodeStatus ret = gif_read_header(ctx->m_Gif.get());
+ GifDecodeStatus ret = gif_read_header(context);
if (ret != GifDecodeStatus::Success)
return ret;
- *width = ctx->m_Gif->width;
- *height = ctx->m_Gif->height;
- *pal_num = ctx->m_Gif->global_pal_num;
- *pal_pp = ctx->m_Gif->m_GlobalPalette.empty()
- ? nullptr
- : ctx->m_Gif->m_GlobalPalette.data();
- *bg_index = ctx->m_Gif->bc_index;
+ *width = context->width;
+ *height = context->height;
+ *pal_num = context->global_pal_num;
+ *pal_pp = context->m_GlobalPalette.empty() ? nullptr
+ : context->m_GlobalPalette.data();
+ *bg_index = context->bc_index;
return GifDecodeStatus::Success;
}
-GifDecodeStatus CCodec_GifModule::LoadFrameInfo(FXGIF_Context* ctx,
+GifDecodeStatus CCodec_GifModule::LoadFrameInfo(CGifContext* context,
int* frame_num) {
- if (setjmp(ctx->m_Gif->jmpbuf))
+ if (setjmp(context->jmpbuf))
return GifDecodeStatus::Error;
- GifDecodeStatus ret = gif_get_frame(ctx->m_Gif.get());
+ GifDecodeStatus ret = gif_get_frame(context);
if (ret != GifDecodeStatus::Success)
return ret;
- *frame_num = gif_get_frame_num(ctx->m_Gif.get());
+ *frame_num = gif_get_frame_num(context);
return GifDecodeStatus::Success;
}
-GifDecodeStatus CCodec_GifModule::LoadFrame(FXGIF_Context* ctx,
+GifDecodeStatus CCodec_GifModule::LoadFrame(CGifContext* context,
int frame_num,
CFX_DIBAttribute* pAttribute) {
- if (setjmp(ctx->m_Gif->jmpbuf))
+ if (setjmp(context->jmpbuf))
return GifDecodeStatus::Error;
- GifDecodeStatus ret = gif_load_frame(ctx->m_Gif.get(), frame_num);
+ GifDecodeStatus ret = gif_load_frame(context, frame_num);
if (ret == GifDecodeStatus::Success) {
if (pAttribute) {
- pAttribute->m_nGifLeft =
- ctx->m_Gif->m_Images[frame_num]->m_ImageInfo.left;
- pAttribute->m_nGifTop = ctx->m_Gif->m_Images[frame_num]->m_ImageInfo.top;
- pAttribute->m_fAspectRatio = ctx->m_Gif->pixel_aspect;
+ pAttribute->m_nGifLeft = context->m_Images[frame_num]->m_ImageInfo.left;
+ pAttribute->m_nGifTop = context->m_Images[frame_num]->m_ImageInfo.top;
+ pAttribute->m_fAspectRatio = context->pixel_aspect;
const uint8_t* buf =
- reinterpret_cast<const uint8_t*>(ctx->m_Gif->cmt_data.GetBuffer(0));
- uint32_t len = ctx->m_Gif->cmt_data.GetLength();
+ reinterpret_cast<const uint8_t*>(context->cmt_data.GetBuffer(0));
+ uint32_t len = context->cmt_data.GetLength();
if (len > 21) {
uint8_t size = *buf++;
if (size != 0)
@@ -102,13 +86,13 @@ GifDecodeStatus CCodec_GifModule::LoadFrame(FXGIF_Context* ctx,
return ret;
}
-uint32_t CCodec_GifModule::GetAvailInput(FXGIF_Context* ctx,
+uint32_t CCodec_GifModule::GetAvailInput(CGifContext* context,
uint8_t** avail_buf_ptr) {
- return gif_get_avail_input(ctx->m_Gif.get(), avail_buf_ptr);
+ return gif_get_avail_input(context, avail_buf_ptr);
}
-void CCodec_GifModule::Input(FXGIF_Context* ctx,
+void CCodec_GifModule::Input(CGifContext* context,
const uint8_t* src_buf,
uint32_t src_size) {
- gif_input_buffer(ctx->m_Gif.get(), (uint8_t*)src_buf, src_size);
+ gif_input_buffer(context, (uint8_t*)src_buf, src_size);
}
diff --git a/core/fxcodec/codec/ccodec_gifmodule.h b/core/fxcodec/codec/ccodec_gifmodule.h
index 862bee5fe7..5f3f45f83f 100644
--- a/core/fxcodec/codec/ccodec_gifmodule.h
+++ b/core/fxcodec/codec/ccodec_gifmodule.h
@@ -7,12 +7,13 @@
#ifndef CORE_FXCODEC_CODEC_CCODEC_GIFMODULE_H_
#define CORE_FXCODEC_CODEC_CCODEC_GIFMODULE_H_
+#include <memory>
+
#include "core/fxcodec/lgif/fx_gif.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_system.h"
class CFX_DIBAttribute;
-class FXGIF_Context;
class CCodec_GifModule {
public:
@@ -34,16 +35,13 @@ class CCodec_GifModule {
CCodec_GifModule();
~CCodec_GifModule();
- FXGIF_Context* Start();
- void Finish(FXGIF_Context* pContext);
- uint32_t GetAvailInput(FXGIF_Context* pContext,
+ std::unique_ptr<CGifContext> Start();
+ uint32_t GetAvailInput(CGifContext* context,
uint8_t** avail_buf_ptr = nullptr);
- void Input(FXGIF_Context* pContext,
- const uint8_t* src_buf,
- uint32_t src_size);
+ void Input(CGifContext* context, const uint8_t* src_buf, uint32_t src_size);
- GifDecodeStatus ReadHeader(FXGIF_Context* pContext,
+ GifDecodeStatus ReadHeader(CGifContext* context,
int* width,
int* height,
int* pal_num,
@@ -51,8 +49,8 @@ class CCodec_GifModule {
int* bg_index,
CFX_DIBAttribute* pAttribute);
- GifDecodeStatus LoadFrameInfo(FXGIF_Context* pContext, int* frame_num);
- GifDecodeStatus LoadFrame(FXGIF_Context* pContext,
+ GifDecodeStatus LoadFrameInfo(CGifContext* context, int* frame_num);
+ GifDecodeStatus LoadFrame(CGifContext* context,
int frame_num,
CFX_DIBAttribute* pAttribute);
diff --git a/core/fxcodec/codec/ccodec_progressivedecoder.h b/core/fxcodec/codec/ccodec_progressivedecoder.h
index 6fa0dafab0..2b343b7e94 100644
--- a/core/fxcodec/codec/ccodec_progressivedecoder.h
+++ b/core/fxcodec/codec/ccodec_progressivedecoder.h
@@ -7,6 +7,7 @@
#ifndef CORE_FXCODEC_CODEC_CCODEC_PROGRESSIVEDECODER_H_
#define CORE_FXCODEC_CODEC_CCODEC_PROGRESSIVEDECODER_H_
+#include <memory>
#include <vector>
#include "core/fxcodec/codec/ccodec_bmpmodule.h"
@@ -14,6 +15,7 @@
#include "core/fxcodec/codec/ccodec_pngmodule.h"
#include "core/fxcodec/codec/ccodec_tiffmodule.h"
#include "core/fxcodec/fx_codec_def.h"
+#include "core/fxcodec/lgif/cgifcontext.h"
#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxge/fx_dib.h"
@@ -128,7 +130,7 @@ class CCodec_ProgressiveDecoder : public CCodec_BmpModule::Delegate,
CCodec_ModuleMgr* m_pCodecMgr;
FXJPEG_Context* m_pJpegContext;
FXPNG_Context* m_pPngContext;
- FXGIF_Context* m_pGifContext;
+ std::unique_ptr<CGifContext> m_pGifContext;
FXBMP_Context* m_pBmpContext;
CCodec_TiffContext* m_pTiffContext;
FXCODEC_IMAGE_TYPE m_imagType;
diff --git a/core/fxcodec/codec/fx_codec_progress.cpp b/core/fxcodec/codec/fx_codec_progress.cpp
index c61cb0bbaf..aa97ac4bb2 100644
--- a/core/fxcodec/codec/fx_codec_progress.cpp
+++ b/core/fxcodec/codec/fx_codec_progress.cpp
@@ -258,7 +258,6 @@ CCodec_ProgressiveDecoder::CCodec_ProgressiveDecoder(
m_pFile = nullptr;
m_pJpegContext = nullptr;
m_pPngContext = nullptr;
- m_pGifContext = nullptr;
m_pBmpContext = nullptr;
m_pTiffContext = nullptr;
m_pCodecMgr = nullptr;
@@ -299,8 +298,6 @@ CCodec_ProgressiveDecoder::~CCodec_ProgressiveDecoder() {
m_pCodecMgr->GetJpegModule()->Finish(m_pJpegContext);
if (m_pBmpContext)
m_pCodecMgr->GetBmpModule()->Finish(m_pBmpContext);
- if (m_pGifContext)
- m_pCodecMgr->GetGifModule()->Finish(m_pGifContext);
if (m_pPngContext)
m_pCodecMgr->GetPngModule()->Finish(m_pPngContext);
if (m_pTiffContext)
@@ -579,7 +576,7 @@ bool CCodec_ProgressiveDecoder::GifReadMoreData(CCodec_GifModule* pGifModule,
return false;
}
dwSize = dwSize - m_offSet;
- uint32_t dwAvail = pGifModule->GetAvailInput(m_pGifContext, nullptr);
+ uint32_t dwAvail = pGifModule->GetAvailInput(m_pGifContext.get(), nullptr);
if (dwAvail == m_SrcSize) {
if (dwSize > FXCODEC_BLOCK_SIZE) {
dwSize = FXCODEC_BLOCK_SIZE;
@@ -605,13 +602,13 @@ bool CCodec_ProgressiveDecoder::GifReadMoreData(CCodec_GifModule* pGifModule,
return false;
}
m_offSet += dwSize;
- pGifModule->Input(m_pGifContext, m_pSrcBuf, dwSize + dwAvail);
+ pGifModule->Input(m_pGifContext.get(), m_pSrcBuf, dwSize + dwAvail);
return true;
}
void CCodec_ProgressiveDecoder::GifRecordCurrentPosition(uint32_t& cur_pos) {
uint32_t remain_size =
- m_pCodecMgr->GetGifModule()->GetAvailInput(m_pGifContext);
+ m_pCodecMgr->GetGifModule()->GetAvailInput(m_pGifContext.get());
cur_pos = m_offSet - remain_size;
}
@@ -1177,20 +1174,16 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType,
}
pGifModule->SetDelegate(this);
m_pGifContext = pGifModule->Start();
- if (!m_pGifContext) {
- m_status = FXCODEC_STATUS_ERR_MEMORY;
- return false;
- }
bool bResult = m_pFile->ReadBlock(m_pSrcBuf, 0, size);
if (!bResult) {
m_status = FXCODEC_STATUS_ERR_READ;
return false;
}
m_offSet += size;
- pGifModule->Input(m_pGifContext, m_pSrcBuf, size);
+ pGifModule->Input(m_pGifContext.get(), m_pSrcBuf, size);
m_SrcComponents = 1;
GifDecodeStatus readResult = pGifModule->ReadHeader(
- m_pGifContext, &m_SrcWidth, &m_SrcHeight, &m_GifPltNumber,
+ m_pGifContext.get(), &m_SrcWidth, &m_SrcHeight, &m_GifPltNumber,
(void**)&m_pGifPalette, &m_GifBgIndex, nullptr);
while (readResult == GifDecodeStatus::Unfinished) {
FXCODEC_STATUS error_status = FXCODEC_STATUS_ERR_FORMAT;
@@ -1199,7 +1192,7 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType,
return false;
}
readResult = pGifModule->ReadHeader(
- m_pGifContext, &m_SrcWidth, &m_SrcHeight, &m_GifPltNumber,
+ m_pGifContext.get(), &m_SrcWidth, &m_SrcHeight, &m_GifPltNumber,
(void**)&m_pGifPalette, &m_GifBgIndex, nullptr);
}
if (readResult == GifDecodeStatus::Success) {
@@ -1207,10 +1200,7 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType,
m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight);
return true;
}
- if (m_pGifContext) {
- pGifModule->Finish(m_pGifContext);
- m_pGifContext = nullptr;
- }
+ m_pGifContext = nullptr;
m_status = FXCODEC_STATUS_ERR_FORMAT;
return false;
}
@@ -1800,23 +1790,22 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::GetFrames(int32_t& frames) {
}
while (true) {
GifDecodeStatus readResult =
- pGifModule->LoadFrameInfo(m_pGifContext, &m_FrameNumber);
+ pGifModule->LoadFrameInfo(m_pGifContext.get(), &m_FrameNumber);
while (readResult == GifDecodeStatus::Unfinished) {
FXCODEC_STATUS error_status = FXCODEC_STATUS_ERR_READ;
if (!GifReadMoreData(pGifModule, error_status))
return error_status;
- readResult = pGifModule->LoadFrameInfo(m_pGifContext, &m_FrameNumber);
+ readResult =
+ pGifModule->LoadFrameInfo(m_pGifContext.get(), &m_FrameNumber);
}
if (readResult == GifDecodeStatus::Success) {
frames = m_FrameNumber;
m_status = FXCODEC_STATUS_DECODE_READY;
return m_status;
}
- if (m_pGifContext) {
- pGifModule->Finish(m_pGifContext);
+ if (m_pGifContext.get())
m_pGifContext = nullptr;
- }
m_status = FXCODEC_STATUS_ERROR;
return m_status;
}
@@ -2118,7 +2107,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode() {
}
while (true) {
GifDecodeStatus readRes =
- pGifModule->LoadFrame(m_pGifContext, m_FrameCur, nullptr);
+ pGifModule->LoadFrame(m_pGifContext.get(), m_FrameCur, nullptr);
while (readRes == GifDecodeStatus::Unfinished) {
FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH;
if (!GifReadMoreData(pGifModule, error_status)) {
@@ -2127,7 +2116,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode() {
m_status = error_status;
return m_status;
}
- readRes = pGifModule->LoadFrame(m_pGifContext, m_FrameCur, nullptr);
+ readRes =
+ pGifModule->LoadFrame(m_pGifContext.get(), m_FrameCur, nullptr);
}
if (readRes == GifDecodeStatus::Success) {
m_pDeviceBitmap = nullptr;
diff --git a/core/fxcodec/lgif/cgifcontext.cpp b/core/fxcodec/lgif/cgifcontext.cpp
new file mode 100644
index 0000000000..aa2aba6075
--- /dev/null
+++ b/core/fxcodec/lgif/cgifcontext.cpp
@@ -0,0 +1,64 @@
+// Copyright 2017 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/lgif/cgifcontext.h"
+
+#include <utility>
+
+#include "core/fxcodec/codec/ccodec_gifmodule.h"
+#include "core/fxcodec/lgif/fx_gif.h"
+#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
+
+CGifContext::CGifContext(CCodec_GifModule* gif_module, char* error_string)
+ : global_pal_num(0),
+ img_row_offset(0),
+ img_row_avail_size(0),
+ avail_in(0),
+ decode_status(GIF_D_STATUS_SIG),
+ skip_size(0),
+ m_Module(gif_module),
+ err_ptr(error_string),
+ next_in(nullptr),
+ width(0),
+ height(0),
+ bc_index(0),
+ pixel_aspect(0),
+ global_sort_flag(0),
+ global_color_resolution(0),
+ img_pass_num(0) {}
+
+CGifContext::~CGifContext() {}
+
+void CGifContext::ErrorData(const char* err_msg) {
+ strncpy(err_ptr, err_msg, GIF_MAX_ERROR_SIZE - 1);
+ longjmp(jmpbuf, 1);
+}
+
+void CGifContext::RecordCurrentPosition(uint32_t* cur_pos_ptr) {
+ m_Module->GetDelegate()->GifRecordCurrentPosition(*cur_pos_ptr);
+}
+
+void CGifContext::ReadScanline(int32_t row_num, uint8_t* row_buf) {
+ m_Module->GetDelegate()->GifReadScanline(row_num, row_buf);
+}
+
+bool CGifContext::GetRecordPosition(uint32_t cur_pos,
+ int32_t left,
+ int32_t top,
+ int32_t width,
+ int32_t height,
+ int32_t pal_num,
+ GifPalette* pal_ptr,
+ int32_t delay_time,
+ bool user_input,
+ int32_t trans_index,
+ int32_t disposal_method,
+ bool interlace) {
+ return m_Module->GetDelegate()->GifInputRecordPositionBuf(
+ cur_pos, FX_RECT(left, top, left + width, top + height), pal_num, pal_ptr,
+ delay_time, user_input, trans_index, disposal_method, interlace);
+}
diff --git a/core/fxcodec/lgif/cgifdecompressor.h b/core/fxcodec/lgif/cgifcontext.h
index 8d241546e3..2ee8fbe396 100644
--- a/core/fxcodec/lgif/cgifdecompressor.h
+++ b/core/fxcodec/lgif/cgifcontext.h
@@ -4,8 +4,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#ifndef CORE_FXCODEC_LGIF_CGIFDECOMPRESSOR_H_
-#define CORE_FXCODEC_LGIF_CGIFDECOMPRESSOR_H_
+#ifndef CORE_FXCODEC_LGIF_CGIFCONTEXT_H_
+#define CORE_FXCODEC_LGIF_CGIFCONTEXT_H_
#include <setjmp.h>
#include <memory>
@@ -16,20 +16,10 @@
class CCodec_GifModule;
-// TODO(npm): Get rid of this, maybe rename CGifDecompressor->GifContext
-class FXGIF_Context {
+class CGifContext {
public:
- FXGIF_Context();
- ~FXGIF_Context();
-
- std::unique_ptr<CGifDecompressor> m_Gif;
- CCodec_GifModule* parent_ptr;
-};
-
-class CGifDecompressor {
- public:
- CGifDecompressor(FXGIF_Context* p, char* error_string);
- ~CGifDecompressor();
+ CGifContext(CCodec_GifModule* gif_module, char* error_string);
+ ~CGifContext();
void ErrorData(const char* err_msg);
void RecordCurrentPosition(uint32_t* cur_pos_ptr);
@@ -56,8 +46,8 @@ class CGifDecompressor {
int32_t decode_status;
uint32_t skip_size;
+ CCodec_GifModule* m_Module;
char* err_ptr;
- FXGIF_Context* gif_context;
CFX_ByteString cmt_data;
std::unique_ptr<GifGCE> m_GifGCE;
uint8_t* next_in;
@@ -74,4 +64,4 @@ class CGifDecompressor {
uint8_t img_pass_num;
};
-#endif // CORE_FXCODEC_LGIF_CGIFDECOMPRESSOR_H_
+#endif // CORE_FXCODEC_LGIF_CGIFCONTEXT_H_
diff --git a/core/fxcodec/lgif/cgifdecompressor.cpp b/core/fxcodec/lgif/cgifdecompressor.cpp
deleted file mode 100644
index 6e9352f0af..0000000000
--- a/core/fxcodec/lgif/cgifdecompressor.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright 2017 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/lgif/cgifdecompressor.h"
-
-#include <utility>
-
-#include "core/fxcodec/codec/ccodec_gifmodule.h"
-#include "core/fxcodec/lgif/fx_gif.h"
-#include "third_party/base/ptr_util.h"
-#include "third_party/base/stl_util.h"
-
-FXGIF_Context::FXGIF_Context() {}
-
-FXGIF_Context::~FXGIF_Context() {}
-
-CGifDecompressor::CGifDecompressor(FXGIF_Context* p, char* error_string)
- : global_pal_num(0),
- img_row_offset(0),
- img_row_avail_size(0),
- avail_in(0),
- decode_status(GIF_D_STATUS_SIG),
- skip_size(0),
- err_ptr(error_string),
- gif_context(p),
- next_in(nullptr),
- width(0),
- height(0),
- bc_index(0),
- pixel_aspect(0),
- global_sort_flag(0),
- global_color_resolution(0),
- img_pass_num(0) {}
-
-CGifDecompressor::~CGifDecompressor() {}
-
-void CGifDecompressor::ErrorData(const char* err_msg) {
- strncpy(err_ptr, err_msg, GIF_MAX_ERROR_SIZE - 1);
- longjmp(jmpbuf, 1);
-}
-
-void CGifDecompressor::RecordCurrentPosition(uint32_t* cur_pos_ptr) {
- gif_context->parent_ptr->GetDelegate()->GifRecordCurrentPosition(
- *cur_pos_ptr);
-}
-
-void CGifDecompressor::ReadScanline(int32_t row_num, uint8_t* row_buf) {
- gif_context->parent_ptr->GetDelegate()->GifReadScanline(row_num, row_buf);
-}
-
-bool CGifDecompressor::GetRecordPosition(uint32_t cur_pos,
- int32_t left,
- int32_t top,
- int32_t width,
- int32_t height,
- int32_t pal_num,
- GifPalette* pal_ptr,
- int32_t delay_time,
- bool user_input,
- int32_t trans_index,
- int32_t disposal_method,
- bool interlace) {
- return gif_context->parent_ptr->GetDelegate()->GifInputRecordPositionBuf(
- cur_pos, FX_RECT(left, top, left + width, top + height), pal_num, pal_ptr,
- delay_time, user_input, trans_index, disposal_method, interlace);
-}
diff --git a/core/fxcodec/lgif/fx_gif.cpp b/core/fxcodec/lgif/fx_gif.cpp
index 4248c88a01..b9ff41cc2e 100644
--- a/core/fxcodec/lgif/fx_gif.cpp
+++ b/core/fxcodec/lgif/fx_gif.cpp
@@ -10,7 +10,7 @@
#include <utility>
#include "core/fxcodec/lbmp/fx_bmp.h"
-#include "core/fxcodec/lgif/cgifdecompressor.h"
+#include "core/fxcodec/lgif/cgifcontext.h"
#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
@@ -24,60 +24,60 @@ static_assert(sizeof(GifLSD) == 7, "GifLSD should have a size of 7");
namespace {
-uint8_t* gif_read_data(CGifDecompressor* gif_ptr,
+uint8_t* gif_read_data(CGifContext* context,
uint8_t** des_buf_pp,
uint32_t data_size) {
- if (!gif_ptr || gif_ptr->avail_in < gif_ptr->skip_size + data_size)
+ if (!context || context->avail_in < context->skip_size + data_size)
return nullptr;
- *des_buf_pp = gif_ptr->next_in + gif_ptr->skip_size;
- gif_ptr->skip_size += data_size;
+ *des_buf_pp = context->next_in + context->skip_size;
+ context->skip_size += data_size;
return *des_buf_pp;
}
-void gif_save_decoding_status(CGifDecompressor* gif_ptr, int32_t status) {
- gif_ptr->decode_status = status;
- gif_ptr->next_in += gif_ptr->skip_size;
- gif_ptr->avail_in -= gif_ptr->skip_size;
- gif_ptr->skip_size = 0;
+void gif_save_decoding_status(CGifContext* context, int32_t status) {
+ context->decode_status = status;
+ context->next_in += context->skip_size;
+ context->avail_in -= context->skip_size;
+ context->skip_size = 0;
}
-GifDecodeStatus gif_decode_extension(CGifDecompressor* gif_ptr) {
+GifDecodeStatus gif_decode_extension(CGifContext* context) {
uint8_t* data_size_ptr = nullptr;
uint8_t* data_ptr = nullptr;
- uint32_t skip_size_org = gif_ptr->skip_size;
- switch (gif_ptr->decode_status) {
+ uint32_t skip_size_org = context->skip_size;
+ switch (context->decode_status) {
case GIF_D_STATUS_EXT_CE: {
- if (!gif_read_data(gif_ptr, &data_size_ptr, 1)) {
- gif_ptr->skip_size = skip_size_org;
+ if (!gif_read_data(context, &data_size_ptr, 1)) {
+ context->skip_size = skip_size_org;
return GifDecodeStatus::Unfinished;
}
- gif_ptr->cmt_data.clear();
+ context->cmt_data.clear();
while (*data_size_ptr != GIF_BLOCK_TERMINAL) {
uint8_t data_size = *data_size_ptr;
- if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) ||
- !gif_read_data(gif_ptr, &data_size_ptr, 1)) {
- gif_ptr->skip_size = skip_size_org;
+ if (!gif_read_data(context, &data_ptr, *data_size_ptr) ||
+ !gif_read_data(context, &data_size_ptr, 1)) {
+ context->skip_size = skip_size_org;
return GifDecodeStatus::Unfinished;
}
- gif_ptr->cmt_data += CFX_ByteString(data_ptr, data_size);
+ context->cmt_data += CFX_ByteString(data_ptr, data_size);
}
break;
}
case GIF_D_STATUS_EXT_PTE: {
GifPTE* gif_pte = nullptr;
- if (!gif_read_data(gif_ptr, reinterpret_cast<uint8_t**>(&gif_pte), 13))
+ if (!gif_read_data(context, reinterpret_cast<uint8_t**>(&gif_pte), 13))
return GifDecodeStatus::Unfinished;
- gif_ptr->m_GifGCE = nullptr;
- if (!gif_read_data(gif_ptr, &data_size_ptr, 1)) {
- gif_ptr->skip_size = skip_size_org;
+ context->m_GifGCE = nullptr;
+ if (!gif_read_data(context, &data_size_ptr, 1)) {
+ context->skip_size = skip_size_org;
return GifDecodeStatus::Unfinished;
}
while (*data_size_ptr != GIF_BLOCK_TERMINAL) {
- if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) ||
- !gif_read_data(gif_ptr, &data_size_ptr, 1)) {
- gif_ptr->skip_size = skip_size_org;
+ if (!gif_read_data(context, &data_ptr, *data_size_ptr) ||
+ !gif_read_data(context, &data_size_ptr, 1)) {
+ context->skip_size = skip_size_org;
return GifDecodeStatus::Unfinished;
}
}
@@ -85,45 +85,45 @@ GifDecodeStatus gif_decode_extension(CGifDecompressor* gif_ptr) {
}
case GIF_D_STATUS_EXT_GCE: {
GifGCE* gif_gce_ptr = nullptr;
- if (!gif_read_data(gif_ptr, reinterpret_cast<uint8_t**>(&gif_gce_ptr), 6))
+ if (!gif_read_data(context, reinterpret_cast<uint8_t**>(&gif_gce_ptr), 6))
return GifDecodeStatus::Unfinished;
- if (!gif_ptr->m_GifGCE.get())
- gif_ptr->m_GifGCE = pdfium::MakeUnique<GifGCE>();
- gif_ptr->m_GifGCE->block_size = gif_gce_ptr->block_size;
- gif_ptr->m_GifGCE->gce_flag = gif_gce_ptr->gce_flag;
- gif_ptr->m_GifGCE->delay_time = GetWord_LSBFirst(
+ if (!context->m_GifGCE.get())
+ context->m_GifGCE = pdfium::MakeUnique<GifGCE>();
+ context->m_GifGCE->block_size = gif_gce_ptr->block_size;
+ context->m_GifGCE->gce_flag = gif_gce_ptr->gce_flag;
+ context->m_GifGCE->delay_time = GetWord_LSBFirst(
reinterpret_cast<uint8_t*>(&gif_gce_ptr->delay_time));
- gif_ptr->m_GifGCE->trans_index = gif_gce_ptr->trans_index;
+ context->m_GifGCE->trans_index = gif_gce_ptr->trans_index;
break;
}
default: {
- if (gif_ptr->decode_status == GIF_D_STATUS_EXT_PTE)
- gif_ptr->m_GifGCE = nullptr;
- if (!gif_read_data(gif_ptr, &data_size_ptr, 1))
+ if (context->decode_status == GIF_D_STATUS_EXT_PTE)
+ context->m_GifGCE = nullptr;
+ if (!gif_read_data(context, &data_size_ptr, 1))
return GifDecodeStatus::Unfinished;
while (*data_size_ptr != GIF_BLOCK_TERMINAL) {
- if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr) ||
- !gif_read_data(gif_ptr, &data_size_ptr, 1)) {
- gif_ptr->skip_size = skip_size_org;
+ if (!gif_read_data(context, &data_ptr, *data_size_ptr) ||
+ !gif_read_data(context, &data_size_ptr, 1)) {
+ context->skip_size = skip_size_org;
return GifDecodeStatus::Unfinished;
}
}
}
}
- gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG);
+ gif_save_decoding_status(context, GIF_D_STATUS_SIG);
return GifDecodeStatus::Success;
}
-GifDecodeStatus gif_decode_image_info(CGifDecompressor* gif_ptr) {
- if (gif_ptr->width == 0 || gif_ptr->height == 0) {
- gif_ptr->ErrorData("No Image Header Info");
+GifDecodeStatus gif_decode_image_info(CGifContext* context) {
+ if (context->width == 0 || context->height == 0) {
+ context->ErrorData("No Image Header Info");
return GifDecodeStatus::Error;
}
- uint32_t skip_size_org = gif_ptr->skip_size;
+ uint32_t skip_size_org = context->skip_size;
GifImageInfo* gif_img_info_ptr = nullptr;
- if (!gif_read_data(gif_ptr, reinterpret_cast<uint8_t**>(&gif_img_info_ptr),
+ if (!gif_read_data(context, reinterpret_cast<uint8_t**>(&gif_img_info_ptr),
9))
return GifDecodeStatus::Unfinished;
@@ -138,18 +138,18 @@ GifDecodeStatus gif_decode_image_info(CGifDecompressor* gif_ptr) {
GetWord_LSBFirst(reinterpret_cast<uint8_t*>(&gif_img_info_ptr->height));
gif_image->m_ImageInfo.local_flag = gif_img_info_ptr->local_flag;
if (gif_image->m_ImageInfo.left + gif_image->m_ImageInfo.width >
- gif_ptr->width ||
+ context->width ||
gif_image->m_ImageInfo.top + gif_image->m_ImageInfo.height >
- gif_ptr->height) {
- gif_ptr->ErrorData("Image Data Out Of LSD, The File May Be Corrupt");
+ context->height) {
+ context->ErrorData("Image Data Out Of LSD, The File May Be Corrupt");
return GifDecodeStatus::Error;
}
GifLF* gif_img_info_lf_ptr = (GifLF*)&gif_img_info_ptr->local_flag;
if (gif_img_info_lf_ptr->local_pal) {
int32_t loc_pal_size = (2 << gif_img_info_lf_ptr->pal_bits) * 3;
uint8_t* loc_pal_ptr = nullptr;
- if (!gif_read_data(gif_ptr, &loc_pal_ptr, loc_pal_size)) {
- gif_ptr->skip_size = skip_size_org;
+ if (!gif_read_data(context, &loc_pal_ptr, loc_pal_size)) {
+ context->skip_size = skip_size_org;
return GifDecodeStatus::Unfinished;
}
gif_image->m_LocalPalettes = std::vector<GifPalette>(loc_pal_size / 3);
@@ -157,28 +157,28 @@ GifDecodeStatus gif_decode_image_info(CGifDecompressor* gif_ptr) {
reinterpret_cast<uint8_t*>(gif_image->m_LocalPalettes.data()));
}
uint8_t* code_size_ptr = nullptr;
- if (!gif_read_data(gif_ptr, &code_size_ptr, 1)) {
- gif_ptr->skip_size = skip_size_org;
+ if (!gif_read_data(context, &code_size_ptr, 1)) {
+ context->skip_size = skip_size_org;
return GifDecodeStatus::Unfinished;
}
gif_image->image_code_size = *code_size_ptr;
- gif_ptr->RecordCurrentPosition(&gif_image->image_data_pos);
- gif_image->image_data_pos += gif_ptr->skip_size;
+ context->RecordCurrentPosition(&gif_image->image_data_pos);
+ gif_image->image_data_pos += context->skip_size;
gif_image->m_ImageGCE = nullptr;
- if (gif_ptr->m_GifGCE.get()) {
- gif_image->m_ImageGCE = std::move(gif_ptr->m_GifGCE);
- gif_ptr->m_GifGCE = nullptr;
+ if (context->m_GifGCE.get()) {
+ gif_image->m_ImageGCE = std::move(context->m_GifGCE);
+ context->m_GifGCE = nullptr;
}
- gif_ptr->m_Images.push_back(std::move(gif_image));
- gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA);
+ context->m_Images.push_back(std::move(gif_image));
+ gif_save_decoding_status(context, GIF_D_STATUS_IMG_DATA);
return GifDecodeStatus::Success;
}
-void gif_decoding_failure_at_tail_cleanup(CGifDecompressor* gif_ptr,
+void gif_decoding_failure_at_tail_cleanup(CGifContext* context,
GifImage* gif_image_ptr) {
gif_image_ptr->m_ImageRowBuf.clear();
- gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL);
- gif_ptr->ErrorData("Decode Image Data Error");
+ gif_save_decoding_status(context, GIF_D_STATUS_TAIL);
+ context->ErrorData("Decode Image Data Error");
}
} // namespace
@@ -350,77 +350,77 @@ GifDecodeStatus CGifLZWDecoder::Decode(uint8_t* des_buf, uint32_t* des_size) {
return GifDecodeStatus::Error;
}
-GifDecodeStatus gif_read_header(CGifDecompressor* gif_ptr) {
- if (!gif_ptr)
+GifDecodeStatus gif_read_header(CGifContext* context) {
+ if (!context)
return GifDecodeStatus::Error;
- uint32_t skip_size_org = gif_ptr->skip_size;
+ uint32_t skip_size_org = context->skip_size;
GifHeader* gif_header_ptr = nullptr;
- if (!gif_read_data(gif_ptr, reinterpret_cast<uint8_t**>(&gif_header_ptr), 6))
+ if (!gif_read_data(context, reinterpret_cast<uint8_t**>(&gif_header_ptr), 6))
return GifDecodeStatus::Unfinished;
if (strncmp(gif_header_ptr->signature, GIF_SIGNATURE, 3) != 0 ||
gif_header_ptr->version[0] != '8' || gif_header_ptr->version[2] != 'a') {
- gif_ptr->ErrorData("Not A Gif Image");
+ context->ErrorData("Not A Gif Image");
return GifDecodeStatus::Error;
}
GifLSD* gif_lsd_ptr = nullptr;
- if (!gif_read_data(gif_ptr, reinterpret_cast<uint8_t**>(&gif_lsd_ptr), 7)) {
- gif_ptr->skip_size = skip_size_org;
+ if (!gif_read_data(context, reinterpret_cast<uint8_t**>(&gif_lsd_ptr), 7)) {
+ context->skip_size = skip_size_org;
return GifDecodeStatus::Unfinished;
}
if (reinterpret_cast<GifGF*>(&gif_lsd_ptr->global_flag)->global_pal) {
- gif_ptr->global_pal_num =
+ context->global_pal_num =
2 << reinterpret_cast<GifGF*>(&gif_lsd_ptr->global_flag)->pal_bits;
- int32_t global_pal_size = gif_ptr->global_pal_num * 3;
+ int32_t global_pal_size = context->global_pal_num * 3;
uint8_t* global_pal_ptr = nullptr;
- if (!gif_read_data(gif_ptr, &global_pal_ptr, global_pal_size)) {
- gif_ptr->skip_size = skip_size_org;
+ if (!gif_read_data(context, &global_pal_ptr, global_pal_size)) {
+ context->skip_size = skip_size_org;
return GifDecodeStatus::Unfinished;
}
- gif_ptr->global_sort_flag = ((GifGF*)&gif_lsd_ptr->global_flag)->sort_flag;
- gif_ptr->global_color_resolution =
+ context->global_sort_flag = ((GifGF*)&gif_lsd_ptr->global_flag)->sort_flag;
+ context->global_color_resolution =
((GifGF*)&gif_lsd_ptr->global_flag)->color_resolution;
- gif_ptr->m_GlobalPalette.resize(global_pal_size / 3);
- memcpy(gif_ptr->m_GlobalPalette.data(), global_pal_ptr, global_pal_size);
+ context->m_GlobalPalette.resize(global_pal_size / 3);
+ memcpy(context->m_GlobalPalette.data(), global_pal_ptr, global_pal_size);
}
- gif_ptr->width =
+ context->width =
(int)GetWord_LSBFirst(reinterpret_cast<uint8_t*>(&gif_lsd_ptr->width));
- gif_ptr->height =
+ context->height =
(int)GetWord_LSBFirst(reinterpret_cast<uint8_t*>(&gif_lsd_ptr->height));
- gif_ptr->bc_index = gif_lsd_ptr->bc_index;
- gif_ptr->pixel_aspect = gif_lsd_ptr->pixel_aspect;
+ context->bc_index = gif_lsd_ptr->bc_index;
+ context->pixel_aspect = gif_lsd_ptr->pixel_aspect;
return GifDecodeStatus::Success;
}
-GifDecodeStatus gif_get_frame(CGifDecompressor* gif_ptr) {
- if (!gif_ptr)
+GifDecodeStatus gif_get_frame(CGifContext* context) {
+ if (!context)
return GifDecodeStatus::Error;
GifDecodeStatus ret = GifDecodeStatus::Success;
while (true) {
- switch (gif_ptr->decode_status) {
+ switch (context->decode_status) {
case GIF_D_STATUS_TAIL:
return GifDecodeStatus::Success;
case GIF_D_STATUS_SIG: {
uint8_t* sig_ptr = nullptr;
- if (!gif_read_data(gif_ptr, &sig_ptr, 1))
+ if (!gif_read_data(context, &sig_ptr, 1))
return GifDecodeStatus::Unfinished;
switch (*sig_ptr) {
case GIF_SIG_EXTENSION:
- gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT);
+ gif_save_decoding_status(context, GIF_D_STATUS_EXT);
continue;
case GIF_SIG_IMAGE:
- gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_INFO);
+ gif_save_decoding_status(context, GIF_D_STATUS_IMG_INFO);
continue;
case GIF_SIG_TRAILER:
- gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL);
+ gif_save_decoding_status(context, GIF_D_STATUS_TAIL);
return GifDecodeStatus::Success;
default:
- if (gif_ptr->avail_in) {
+ if (context->avail_in) {
// The Gif File has non_standard Tag!
- gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG);
+ gif_save_decoding_status(context, GIF_D_STATUS_SIG);
continue;
}
// The Gif File Doesn't have Trailer Tag!
@@ -429,31 +429,31 @@ GifDecodeStatus gif_get_frame(CGifDecompressor* gif_ptr) {
}
case GIF_D_STATUS_EXT: {
uint8_t* ext_ptr = nullptr;
- if (!gif_read_data(gif_ptr, &ext_ptr, 1))
+ if (!gif_read_data(context, &ext_ptr, 1))
return GifDecodeStatus::Unfinished;
switch (*ext_ptr) {
case GIF_BLOCK_CE:
- gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_CE);
+ gif_save_decoding_status(context, GIF_D_STATUS_EXT_CE);
continue;
case GIF_BLOCK_GCE:
- gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_GCE);
+ gif_save_decoding_status(context, GIF_D_STATUS_EXT_GCE);
continue;
case GIF_BLOCK_PTE:
- gif_save_decoding_status(gif_ptr, GIF_D_STATUS_EXT_PTE);
+ gif_save_decoding_status(context, GIF_D_STATUS_EXT_PTE);
continue;
default: {
int32_t status = GIF_D_STATUS_EXT_UNE;
if (*ext_ptr == GIF_BLOCK_PTE) {
status = GIF_D_STATUS_EXT_PTE;
}
- gif_save_decoding_status(gif_ptr, status);
+ gif_save_decoding_status(context, status);
continue;
}
}
}
case GIF_D_STATUS_IMG_INFO: {
- ret = gif_decode_image_info(gif_ptr);
+ ret = gif_decode_image_info(context);
if (ret != GifDecodeStatus::Success)
return ret;
continue;
@@ -461,25 +461,25 @@ GifDecodeStatus gif_get_frame(CGifDecompressor* gif_ptr) {
case GIF_D_STATUS_IMG_DATA: {
uint8_t* data_size_ptr = nullptr;
uint8_t* data_ptr = nullptr;
- uint32_t skip_size_org = gif_ptr->skip_size;
- if (!gif_read_data(gif_ptr, &data_size_ptr, 1))
+ uint32_t skip_size_org = context->skip_size;
+ if (!gif_read_data(context, &data_size_ptr, 1))
return GifDecodeStatus::Unfinished;
while (*data_size_ptr != GIF_BLOCK_TERMINAL) {
- if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr)) {
- gif_ptr->skip_size = skip_size_org;
+ if (!gif_read_data(context, &data_ptr, *data_size_ptr)) {
+ context->skip_size = skip_size_org;
return GifDecodeStatus::Unfinished;
}
- gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA);
- skip_size_org = gif_ptr->skip_size;
- if (!gif_read_data(gif_ptr, &data_size_ptr, 1))
+ gif_save_decoding_status(context, GIF_D_STATUS_IMG_DATA);
+ skip_size_org = context->skip_size;
+ if (!gif_read_data(context, &data_size_ptr, 1))
return GifDecodeStatus::Unfinished;
}
- gif_save_decoding_status(gif_ptr, GIF_D_STATUS_SIG);
+ gif_save_decoding_status(context, GIF_D_STATUS_SIG);
continue;
}
default: {
- ret = gif_decode_extension(gif_ptr);
+ ret = gif_decode_extension(context);
if (ret != GifDecodeStatus::Success)
return ret;
break;
@@ -489,32 +489,32 @@ GifDecodeStatus gif_get_frame(CGifDecompressor* gif_ptr) {
return GifDecodeStatus::Success;
}
-GifDecodeStatus gif_load_frame(CGifDecompressor* gif_ptr, int32_t frame_num) {
- if (!gif_ptr || !pdfium::IndexInBounds(gif_ptr->m_Images, frame_num))
+GifDecodeStatus gif_load_frame(CGifContext* context, int32_t frame_num) {
+ if (!context || !pdfium::IndexInBounds(context->m_Images, frame_num))
return GifDecodeStatus::Error;
uint8_t* data_size_ptr = nullptr;
uint8_t* data_ptr = nullptr;
- uint32_t skip_size_org = gif_ptr->skip_size;
- GifImage* gif_image_ptr = gif_ptr->m_Images[frame_num].get();
+ uint32_t skip_size_org = context->skip_size;
+ GifImage* gif_image_ptr = context->m_Images[frame_num].get();
uint32_t gif_img_row_bytes = gif_image_ptr->m_ImageInfo.width;
if (gif_img_row_bytes == 0) {
- gif_ptr->ErrorData("Error Invalid Number of Row Bytes");
+ context->ErrorData("Error Invalid Number of Row Bytes");
return GifDecodeStatus::Error;
}
- if (gif_ptr->decode_status == GIF_D_STATUS_TAIL) {
+ if (context->decode_status == GIF_D_STATUS_TAIL) {
gif_image_ptr->m_ImageRowBuf.resize(gif_img_row_bytes);
GifGCE* gif_img_gce_ptr = gif_image_ptr->m_ImageGCE.get();
int32_t loc_pal_num =
((GifLF*)&gif_image_ptr->m_ImageInfo.local_flag)->local_pal
? (2 << ((GifLF*)&gif_image_ptr->m_ImageInfo.local_flag)->pal_bits)
: 0;
- gif_ptr->avail_in = 0;
+ context->avail_in = 0;
GifPalette* pLocalPalette = gif_image_ptr->m_LocalPalettes.empty()
? nullptr
: gif_image_ptr->m_LocalPalettes.data();
if (!gif_img_gce_ptr) {
- bool bRes = gif_ptr->GetRecordPosition(
+ bool bRes = context->GetRecordPosition(
gif_image_ptr->image_data_pos, gif_image_ptr->m_ImageInfo.left,
gif_image_ptr->m_ImageInfo.top, gif_image_ptr->m_ImageInfo.width,
gif_image_ptr->m_ImageInfo.height, loc_pal_num, pLocalPalette, 0, 0,
@@ -522,11 +522,11 @@ GifDecodeStatus gif_load_frame(CGifDecompressor* gif_ptr, int32_t frame_num) {
(bool)((GifLF*)&gif_image_ptr->m_ImageInfo.local_flag)->interlace);
if (!bRes) {
gif_image_ptr->m_ImageRowBuf.clear();
- gif_ptr->ErrorData("Error Read Record Position Data");
+ context->ErrorData("Error Read Record Position Data");
return GifDecodeStatus::Error;
}
} else {
- bool bRes = gif_ptr->GetRecordPosition(
+ bool bRes = context->GetRecordPosition(
gif_image_ptr->image_data_pos, gif_image_ptr->m_ImageInfo.left,
gif_image_ptr->m_ImageInfo.top, gif_image_ptr->m_ImageInfo.width,
gif_image_ptr->m_ImageInfo.height, loc_pal_num, pLocalPalette,
@@ -540,131 +540,130 @@ GifDecodeStatus gif_load_frame(CGifDecompressor* gif_ptr, int32_t frame_num) {
(bool)((GifLF*)&gif_image_ptr->m_ImageInfo.local_flag)->interlace);
if (!bRes) {
gif_image_ptr->m_ImageRowBuf.clear();
- gif_ptr->ErrorData("Error Read Record Position Data");
+ context->ErrorData("Error Read Record Position Data");
return GifDecodeStatus::Error;
}
}
if (gif_image_ptr->image_code_size >= 32) {
gif_image_ptr->m_ImageRowBuf.clear();
- gif_ptr->ErrorData("Error Invalid Code Size");
+ context->ErrorData("Error Invalid Code Size");
return GifDecodeStatus::Error;
}
- if (!gif_ptr->m_ImgDecoder.get())
- gif_ptr->m_ImgDecoder =
- pdfium::MakeUnique<CGifLZWDecoder>(gif_ptr->err_ptr);
- gif_ptr->m_ImgDecoder->InitTable(gif_image_ptr->image_code_size);
- gif_ptr->img_row_offset = 0;
- gif_ptr->img_row_avail_size = 0;
- gif_ptr->img_pass_num = 0;
+ if (!context->m_ImgDecoder.get())
+ context->m_ImgDecoder =
+ pdfium::MakeUnique<CGifLZWDecoder>(context->err_ptr);
+ context->m_ImgDecoder->InitTable(gif_image_ptr->image_code_size);
+ context->img_row_offset = 0;
+ context->img_row_avail_size = 0;
+ context->img_pass_num = 0;
gif_image_ptr->image_row_num = 0;
- gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA);
+ gif_save_decoding_status(context, GIF_D_STATUS_IMG_DATA);
}
- CGifLZWDecoder* img_decoder_ptr = gif_ptr->m_ImgDecoder.get();
- if (gif_ptr->decode_status == GIF_D_STATUS_IMG_DATA) {
- if (!gif_read_data(gif_ptr, &data_size_ptr, 1))
+ CGifLZWDecoder* img_decoder_ptr = context->m_ImgDecoder.get();
+ if (context->decode_status == GIF_D_STATUS_IMG_DATA) {
+ if (!gif_read_data(context, &data_size_ptr, 1))
return GifDecodeStatus::Unfinished;
if (*data_size_ptr != GIF_BLOCK_TERMINAL) {
- if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr)) {
- gif_ptr->skip_size = skip_size_org;
+ if (!gif_read_data(context, &data_ptr, *data_size_ptr)) {
+ context->skip_size = skip_size_org;
return GifDecodeStatus::Unfinished;
}
img_decoder_ptr->Input(data_ptr, *data_size_ptr);
- gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA);
- gif_ptr->img_row_offset += gif_ptr->img_row_avail_size;
- gif_ptr->img_row_avail_size = gif_img_row_bytes - gif_ptr->img_row_offset;
+ gif_save_decoding_status(context, GIF_D_STATUS_IMG_DATA);
+ context->img_row_offset += context->img_row_avail_size;
+ context->img_row_avail_size = gif_img_row_bytes - context->img_row_offset;
GifDecodeStatus ret = img_decoder_ptr->Decode(
- gif_image_ptr->m_ImageRowBuf.data() + gif_ptr->img_row_offset,
- &gif_ptr->img_row_avail_size);
+ gif_image_ptr->m_ImageRowBuf.data() + context->img_row_offset,
+ &context->img_row_avail_size);
if (ret == GifDecodeStatus::Error) {
- gif_decoding_failure_at_tail_cleanup(gif_ptr, gif_image_ptr);
+ gif_decoding_failure_at_tail_cleanup(context, gif_image_ptr);
return GifDecodeStatus::Error;
}
while (ret != GifDecodeStatus::Error) {
if (ret == GifDecodeStatus::Success) {
- gif_ptr->ReadScanline(gif_image_ptr->image_row_num,
+ context->ReadScanline(gif_image_ptr->image_row_num,
gif_image_ptr->m_ImageRowBuf.data());
gif_image_ptr->m_ImageRowBuf.clear();
- gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL);
+ gif_save_decoding_status(context, GIF_D_STATUS_TAIL);
return GifDecodeStatus::Success;
}
if (ret == GifDecodeStatus::Unfinished) {
ASSERT(img_decoder_ptr->GetAvailInput() == 0);
- skip_size_org = gif_ptr->skip_size;
- if (!gif_read_data(gif_ptr, &data_size_ptr, 1))
+ skip_size_org = context->skip_size;
+ if (!gif_read_data(context, &data_size_ptr, 1))
return GifDecodeStatus::Unfinished;
if (*data_size_ptr != GIF_BLOCK_TERMINAL) {
- if (!gif_read_data(gif_ptr, &data_ptr, *data_size_ptr)) {
- gif_ptr->skip_size = skip_size_org;
+ if (!gif_read_data(context, &data_ptr, *data_size_ptr)) {
+ context->skip_size = skip_size_org;
return GifDecodeStatus::Unfinished;
}
img_decoder_ptr->Input(data_ptr, *data_size_ptr);
- gif_save_decoding_status(gif_ptr, GIF_D_STATUS_IMG_DATA);
- gif_ptr->img_row_offset += gif_ptr->img_row_avail_size;
- gif_ptr->img_row_avail_size =
- gif_img_row_bytes - gif_ptr->img_row_offset;
+ gif_save_decoding_status(context, GIF_D_STATUS_IMG_DATA);
+ context->img_row_offset += context->img_row_avail_size;
+ context->img_row_avail_size =
+ gif_img_row_bytes - context->img_row_offset;
ret = img_decoder_ptr->Decode(
- gif_image_ptr->m_ImageRowBuf.data() + gif_ptr->img_row_offset,
- &gif_ptr->img_row_avail_size);
+ gif_image_ptr->m_ImageRowBuf.data() + context->img_row_offset,
+ &context->img_row_avail_size);
}
}
if (ret == GifDecodeStatus::InsufficientDestSize) {
if (((GifLF*)&gif_image_ptr->m_ImageInfo.local_flag)->interlace) {
- gif_ptr->ReadScanline(gif_image_ptr->image_row_num,
+ context->ReadScanline(gif_image_ptr->image_row_num,
gif_image_ptr->m_ImageRowBuf.data());
gif_image_ptr->image_row_num +=
- s_gif_interlace_step[gif_ptr->img_pass_num];
+ s_gif_interlace_step[context->img_pass_num];
if (gif_image_ptr->image_row_num >=
(int32_t)gif_image_ptr->m_ImageInfo.height) {
- gif_ptr->img_pass_num++;
- if (gif_ptr->img_pass_num == FX_ArraySize(s_gif_interlace_step)) {
- gif_decoding_failure_at_tail_cleanup(gif_ptr, gif_image_ptr);
+ context->img_pass_num++;
+ if (context->img_pass_num == FX_ArraySize(s_gif_interlace_step)) {
+ gif_decoding_failure_at_tail_cleanup(context, gif_image_ptr);
return GifDecodeStatus::Error;
}
gif_image_ptr->image_row_num =
- s_gif_interlace_step[gif_ptr->img_pass_num] / 2;
+ s_gif_interlace_step[context->img_pass_num] / 2;
}
} else {
- gif_ptr->ReadScanline(gif_image_ptr->image_row_num++,
+ context->ReadScanline(gif_image_ptr->image_row_num++,
gif_image_ptr->m_ImageRowBuf.data());
}
- gif_ptr->img_row_offset = 0;
- gif_ptr->img_row_avail_size = gif_img_row_bytes;
+ context->img_row_offset = 0;
+ context->img_row_avail_size = gif_img_row_bytes;
ret = img_decoder_ptr->Decode(
- gif_image_ptr->m_ImageRowBuf.data() + gif_ptr->img_row_offset,
- &gif_ptr->img_row_avail_size);
+ gif_image_ptr->m_ImageRowBuf.data() + context->img_row_offset,
+ &context->img_row_avail_size);
}
if (ret == GifDecodeStatus::Error) {
- gif_decoding_failure_at_tail_cleanup(gif_ptr, gif_image_ptr);
+ gif_decoding_failure_at_tail_cleanup(context, gif_image_ptr);
return GifDecodeStatus::Error;
}
}
}
- gif_save_decoding_status(gif_ptr, GIF_D_STATUS_TAIL);
+ gif_save_decoding_status(context, GIF_D_STATUS_TAIL);
}
- gif_ptr->ErrorData("Decode Image Data Error");
+ context->ErrorData("Decode Image Data Error");
return GifDecodeStatus::Error;
}
-void gif_input_buffer(CGifDecompressor* gif_ptr,
+void gif_input_buffer(CGifContext* context,
uint8_t* src_buf,
uint32_t src_size) {
- gif_ptr->next_in = src_buf;
- gif_ptr->avail_in = src_size;
- gif_ptr->skip_size = 0;
+ context->next_in = src_buf;
+ context->avail_in = src_size;
+ context->skip_size = 0;
}
-uint32_t gif_get_avail_input(CGifDecompressor* gif_ptr,
- uint8_t** avail_buf_ptr) {
+uint32_t gif_get_avail_input(CGifContext* context, uint8_t** avail_buf_ptr) {
if (avail_buf_ptr) {
*avail_buf_ptr = nullptr;
- if (gif_ptr->avail_in > 0)
- *avail_buf_ptr = gif_ptr->next_in;
+ if (context->avail_in > 0)
+ *avail_buf_ptr = context->next_in;
}
- return gif_ptr->avail_in;
+ return context->avail_in;
}
-int32_t gif_get_frame_num(CGifDecompressor* gif_ptr) {
- return pdfium::CollectionSize<int32_t>(gif_ptr->m_Images);
+int32_t gif_get_frame_num(CGifContext* context) {
+ return pdfium::CollectionSize<int32_t>(context->m_Images);
}
diff --git a/core/fxcodec/lgif/fx_gif.h b/core/fxcodec/lgif/fx_gif.h
index 7bae79f245..5df1f817ef 100644
--- a/core/fxcodec/lgif/fx_gif.h
+++ b/core/fxcodec/lgif/fx_gif.h
@@ -13,7 +13,7 @@
#include "core/fxcrt/fx_basic.h"
-class CGifDecompressor;
+class CGifContext;
#define GIF_SIGNATURE "GIF"
#define GIF_SIG_EXTENSION 0x21
@@ -166,14 +166,13 @@ class CGifLZWDecoder {
static const int32_t s_gif_interlace_step[4] = {8, 8, 4, 2};
-GifDecodeStatus gif_read_header(CGifDecompressor* gif_ptr);
-GifDecodeStatus gif_get_frame(CGifDecompressor* gif_ptr);
-int32_t gif_get_frame_num(CGifDecompressor* gif_ptr);
-GifDecodeStatus gif_load_frame(CGifDecompressor* gif_ptr, int32_t frame_num);
-void gif_input_buffer(CGifDecompressor* gif_ptr,
+GifDecodeStatus gif_read_header(CGifContext* gif_ptr);
+GifDecodeStatus gif_get_frame(CGifContext* gif_ptr);
+int32_t gif_get_frame_num(CGifContext* gif_ptr);
+GifDecodeStatus gif_load_frame(CGifContext* gif_ptr, int32_t frame_num);
+void gif_input_buffer(CGifContext* gif_ptr,
uint8_t* src_buf,
uint32_t src_size);
-uint32_t gif_get_avail_input(CGifDecompressor* gif_ptr,
- uint8_t** avail_buf_ptr);
+uint32_t gif_get_avail_input(CGifContext* gif_ptr, uint8_t** avail_buf_ptr);
#endif // CORE_FXCODEC_LGIF_FX_GIF_H_