summaryrefslogtreecommitdiff
path: root/core/fxcodec/codec/ccodec_gifmodule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcodec/codec/ccodec_gifmodule.cpp')
-rw-r--r--core/fxcodec/codec/ccodec_gifmodule.cpp72
1 files changed, 28 insertions, 44 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);
}