summaryrefslogtreecommitdiff
path: root/core/fxcodec/codec
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2017-06-14 18:20:33 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-06-14 22:34:13 +0000
commitc71fdcb1c9c4bc4457afff0f0358d3862ef3b8b7 (patch)
tree11c5ba087ecfe6bffe8bf7cd190fb951ee823253 /core/fxcodec/codec
parentd321ef9bb7143e393deb9b0ff7420c96db6a0e4c (diff)
downloadpdfium-c71fdcb1c9c4bc4457afff0f0358d3862ef3b8b7.tar.xz
Cleanup fx_bmp part 1
This CL creates BMPDecompressor from a struct and moves into this class many methods which naturally belong to it. Change-Id: I042fac9b48d0b732ee9e43fbeb0eec6b52007dab Reviewed-on: https://pdfium-review.googlesource.com/6511 Commit-Queue: Nicolás Peña <npm@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcodec/codec')
-rw-r--r--core/fxcodec/codec/ccodec_bmpmodule.cpp59
1 files changed, 11 insertions, 48 deletions
diff --git a/core/fxcodec/codec/ccodec_bmpmodule.cpp b/core/fxcodec/codec/ccodec_bmpmodule.cpp
index 15394f1356..9186553c7b 100644
--- a/core/fxcodec/codec/ccodec_bmpmodule.cpp
+++ b/core/fxcodec/codec/ccodec_bmpmodule.cpp
@@ -13,42 +13,7 @@
#include "core/fxge/fx_dib.h"
#include "third_party/base/ptr_util.h"
-class CBmpContext : public CCodec_BmpModule::Context {
- public:
- 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;
- CFX_UnownedPtr<CCodec_BmpModule::Delegate> const m_pDelegate;
- char m_szLastError[256];
-};
-
-extern "C" {
-
-static void bmp_error_data(bmp_decompress_struct_p pBmp, const char* err_msg) {
- strncpy(pBmp->err_ptr, err_msg, BMP_MAX_ERROR_SIZE - 1);
- longjmp(pBmp->jmpbuf, 1);
-}
-
-static void bmp_read_scanline(bmp_decompress_struct_p pBmp,
- int32_t row_num,
- uint8_t* row_buf) {
- 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<CBmpContext*>(pBmp->context_ptr);
- return p->m_pDelegate->BmpInputImagePositionBuf(rcd_pos);
-}
-
-} // extern "C"
-
-CBmpContext::CBmpContext(bmp_decompress_struct_p pBmp,
+CBmpContext::CBmpContext(BMPDecompressor* pBmp,
CCodec_BmpModule* pModule,
CCodec_BmpModule::Delegate* pDelegate)
: m_pBmp(pBmp), m_pModule(pModule), m_pDelegate(pDelegate) {
@@ -65,16 +30,13 @@ CCodec_BmpModule::~CCodec_BmpModule() {}
std::unique_ptr<CCodec_BmpModule::Context> CCodec_BmpModule::Start(
Delegate* pDelegate) {
- bmp_decompress_struct_p pBmp = bmp_create_decompress();
+ BMPDecompressor* pBmp = bmp_create_decompress();
if (!pBmp)
return nullptr;
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;
- p->m_pBmp->bmp_get_data_position_fn = bmp_get_data_position;
return p;
}
@@ -87,13 +49,13 @@ int32_t CCodec_BmpModule::ReadHeader(Context* pContext,
uint32_t** pal_pp,
CFX_DIBAttribute* pAttribute) {
auto* ctx = static_cast<CBmpContext*>(pContext);
- if (setjmp(ctx->m_pBmp->jmpbuf)) {
+ if (setjmp(ctx->m_pBmp->jmpbuf))
return 0;
- }
- int32_t ret = bmp_read_header(ctx->m_pBmp);
- if (ret != 1) {
+
+ int32_t ret = ctx->m_pBmp->ReadHeader();
+ if (ret != 1)
return ret;
- }
+
*width = ctx->m_pBmp->width;
*height = ctx->m_pBmp->height;
*tb_flag = ctx->m_pBmp->imgTB_flag;
@@ -113,18 +75,19 @@ 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);
+
+ return ctx->m_pBmp->DecodeImage();
}
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);
+ return ctx->m_pBmp->GetAvailInput(avail_buf_ptr);
}
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);
+ ctx->m_pBmp->SetInputBuffer(const_cast<uint8_t*>(src_buf), src_size);
}