summaryrefslogtreecommitdiff
path: root/core/fxcodec/codec
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcodec/codec')
-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
4 files changed, 53 insertions, 79 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;