summaryrefslogtreecommitdiff
path: root/core/fxcodec/codec/ccodec_bmpmodule.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-06-01 12:29:09 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-06-01 20:14:44 +0000
commit5171a27eaa7489939310bd2864864867cc78ce21 (patch)
tree3c4a0cf4a4d4296ddc2c92c39850a5821f21e5cd /core/fxcodec/codec/ccodec_bmpmodule.cpp
parent5f34d479d06ebab9079c2d0704dee872cc45dd86 (diff)
downloadpdfium-5171a27eaa7489939310bd2864864867cc78ce21.tar.xz
Use unique_ptrs for codec contexts in ccodec_progressivedecoder.chromium/3118
Change-Id: I4deaf8ca946c2dcb6842c5702b02eed1c22b1201 Reviewed-on: https://pdfium-review.googlesource.com/6191 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcodec/codec/ccodec_bmpmodule.cpp')
-rw-r--r--core/fxcodec/codec/ccodec_bmpmodule.cpp46
1 files changed, 24 insertions, 22 deletions
diff --git a/core/fxcodec/codec/ccodec_bmpmodule.cpp b/core/fxcodec/codec/ccodec_bmpmodule.cpp
index ae0a30c4b4..15394f1356 100644
--- a/core/fxcodec/codec/ccodec_bmpmodule.cpp
+++ b/core/fxcodec/codec/ccodec_bmpmodule.cpp
@@ -11,13 +11,14 @@
#include "core/fxcodec/lbmp/fx_bmp.h"
#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxge/fx_dib.h"
+#include "third_party/base/ptr_util.h"
-class CCodec_BmpModule::Context {
+class CBmpContext : public CCodec_BmpModule::Context {
public:
- Context(bmp_decompress_struct_p pBmp,
- CCodec_BmpModule* pModule,
- CCodec_BmpModule::Delegate* pDelegate);
- ~Context();
+ CBmpContext(bmp_decompress_struct_p pBmp,
+ CCodec_BmpModule* pModule,
+ CCodec_BmpModule::Delegate* pDelegate);
+ ~CBmpContext() override;
bmp_decompress_struct_p m_pBmp;
CFX_UnownedPtr<CCodec_BmpModule> const m_pModule;
@@ -35,26 +36,26 @@ static void bmp_error_data(bmp_decompress_struct_p pBmp, const char* err_msg) {
static void bmp_read_scanline(bmp_decompress_struct_p pBmp,
int32_t row_num,
uint8_t* row_buf) {
- auto* p = reinterpret_cast<CCodec_BmpModule::Context*>(pBmp->context_ptr);
+ auto* p = reinterpret_cast<CBmpContext*>(pBmp->context_ptr);
p->m_pDelegate->BmpReadScanline(row_num, row_buf);
}
static bool bmp_get_data_position(bmp_decompress_struct_p pBmp,
uint32_t rcd_pos) {
- auto* p = reinterpret_cast<CCodec_BmpModule::Context*>(pBmp->context_ptr);
+ auto* p = reinterpret_cast<CBmpContext*>(pBmp->context_ptr);
return p->m_pDelegate->BmpInputImagePositionBuf(rcd_pos);
}
} // extern "C"
-CCodec_BmpModule::Context::Context(bmp_decompress_struct_p pBmp,
- CCodec_BmpModule* pModule,
- CCodec_BmpModule::Delegate* pDelegate)
+CBmpContext::CBmpContext(bmp_decompress_struct_p pBmp,
+ CCodec_BmpModule* pModule,
+ CCodec_BmpModule::Delegate* pDelegate)
: m_pBmp(pBmp), m_pModule(pModule), m_pDelegate(pDelegate) {
memset(m_szLastError, 0, sizeof(m_szLastError));
}
-CCodec_BmpModule::Context::~Context() {
+CBmpContext::~CBmpContext() {
bmp_destroy_decompress(&m_pBmp);
}
@@ -62,13 +63,14 @@ CCodec_BmpModule::CCodec_BmpModule() {}
CCodec_BmpModule::~CCodec_BmpModule() {}
-CCodec_BmpModule::Context* CCodec_BmpModule::Start(Delegate* pDelegate) {
+std::unique_ptr<CCodec_BmpModule::Context> CCodec_BmpModule::Start(
+ Delegate* pDelegate) {
bmp_decompress_struct_p pBmp = bmp_create_decompress();
if (!pBmp)
return nullptr;
- auto* p = new Context(pBmp, this, pDelegate);
- p->m_pBmp->context_ptr = p;
+ auto p = pdfium::MakeUnique<CBmpContext>(pBmp, this, pDelegate);
+ p->m_pBmp->context_ptr = p.get();
p->m_pBmp->err_ptr = p->m_szLastError;
p->m_pBmp->bmp_error_fn = bmp_error_data;
p->m_pBmp->bmp_get_row_fn = bmp_read_scanline;
@@ -76,11 +78,7 @@ CCodec_BmpModule::Context* CCodec_BmpModule::Start(Delegate* pDelegate) {
return p;
}
-void CCodec_BmpModule::Finish(Context* ctx) {
- delete ctx;
-}
-
-int32_t CCodec_BmpModule::ReadHeader(Context* ctx,
+int32_t CCodec_BmpModule::ReadHeader(Context* pContext,
int32_t* width,
int32_t* height,
bool* tb_flag,
@@ -88,6 +86,7 @@ int32_t CCodec_BmpModule::ReadHeader(Context* ctx,
int32_t* pal_num,
uint32_t** pal_pp,
CFX_DIBAttribute* pAttribute) {
+ auto* ctx = static_cast<CBmpContext*>(pContext);
if (setjmp(ctx->m_pBmp->jmpbuf)) {
return 0;
}
@@ -110,19 +109,22 @@ int32_t CCodec_BmpModule::ReadHeader(Context* ctx,
return 1;
}
-int32_t CCodec_BmpModule::LoadImage(Context* ctx) {
+int32_t CCodec_BmpModule::LoadImage(Context* pContext) {
+ auto* ctx = static_cast<CBmpContext*>(pContext);
if (setjmp(ctx->m_pBmp->jmpbuf))
return 0;
return bmp_decode_image(ctx->m_pBmp);
}
-uint32_t CCodec_BmpModule::GetAvailInput(Context* ctx,
+uint32_t CCodec_BmpModule::GetAvailInput(Context* pContext,
uint8_t** avail_buf_ptr) {
+ auto* ctx = static_cast<CBmpContext*>(pContext);
return bmp_get_avail_input(ctx->m_pBmp, avail_buf_ptr);
}
-void CCodec_BmpModule::Input(Context* ctx,
+void CCodec_BmpModule::Input(Context* pContext,
const uint8_t* src_buf,
uint32_t src_size) {
+ auto* ctx = static_cast<CBmpContext*>(pContext);
bmp_input_buffer(ctx->m_pBmp, (uint8_t*)src_buf, src_size);
}