summaryrefslogtreecommitdiff
path: root/core/fxcodec/codec/ccodec_bmpmodule.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-02-27 10:12:59 -0800
committerChromium commit bot <commit-bot@chromium.org>2017-02-27 18:37:42 +0000
commit73c9f3bb3d82563d6d4496c4b0204d5c0825e8a2 (patch)
treebbc3e4e303f5f0a0a2e3931bfde01436130220bb /core/fxcodec/codec/ccodec_bmpmodule.cpp
parent717a4fc857d66017cecc4c8f8285713135b9dc68 (diff)
downloadpdfium-73c9f3bb3d82563d6d4496c4b0204d5c0825e8a2.tar.xz
Allow building XFA without additional codecs.
This is something we'd like to try for initial XFA launches adding in codecs as justified by results in the wild. Adding statistics for the unsupported cases is a follow-up exercise once this builds correctly. We always build all the additional libraries, to allow fuzzers to link against them even if we are not shipping them. The linker will sort it out for the actual code. Rename some files to match the classes contained within. That the existing tests seem to pass with the codecs disabled warrants further investigation. Change-Id: Iad269db91289f12dc9f5dda8f48121d27a0c4367 Reviewed-on: https://pdfium-review.googlesource.com/2836 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcodec/codec/ccodec_bmpmodule.cpp')
-rw-r--r--core/fxcodec/codec/ccodec_bmpmodule.cpp127
1 files changed, 127 insertions, 0 deletions
diff --git a/core/fxcodec/codec/ccodec_bmpmodule.cpp b/core/fxcodec/codec/ccodec_bmpmodule.cpp
new file mode 100644
index 0000000000..c6ebd2d939
--- /dev/null
+++ b/core/fxcodec/codec/ccodec_bmpmodule.cpp
@@ -0,0 +1,127 @@
+// Copyright 2014 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/codec/ccodec_bmpmodule.h"
+
+#include "core/fxcodec/codec/codec_int.h"
+#include "core/fxcodec/fx_codec.h"
+#include "core/fxcodec/lbmp/fx_bmp.h"
+#include "core/fxge/fx_dib.h"
+
+struct FXBMP_Context {
+ bmp_decompress_struct_p bmp_ptr;
+ void* parent_ptr;
+ void* child_ptr;
+
+ void* (*m_AllocFunc)(unsigned int);
+ void (*m_FreeFunc)(void*);
+};
+extern "C" {
+static void* bmp_alloc_func(unsigned int size) {
+ return FX_Alloc(char, size);
+}
+static void bmp_free_func(void* p) {
+ FX_Free(p);
+}
+};
+static void bmp_error_data(bmp_decompress_struct_p bmp_ptr,
+ const FX_CHAR* err_msg) {
+ FXSYS_strncpy((char*)bmp_ptr->err_ptr, err_msg, BMP_MAX_ERROR_SIZE - 1);
+ longjmp(bmp_ptr->jmpbuf, 1);
+}
+static void bmp_read_scanline(bmp_decompress_struct_p bmp_ptr,
+ int32_t row_num,
+ uint8_t* row_buf) {
+ FXBMP_Context* p = (FXBMP_Context*)bmp_ptr->context_ptr;
+ CCodec_BmpModule* pModule = (CCodec_BmpModule*)p->parent_ptr;
+ pModule->ReadScanlineCallback(p->child_ptr, row_num, row_buf);
+}
+static bool bmp_get_data_position(bmp_decompress_struct_p bmp_ptr,
+ uint32_t rcd_pos) {
+ FXBMP_Context* p = (FXBMP_Context*)bmp_ptr->context_ptr;
+ CCodec_BmpModule* pModule = (CCodec_BmpModule*)p->parent_ptr;
+ return pModule->InputImagePositionBufCallback(p->child_ptr, rcd_pos);
+}
+
+FXBMP_Context* CCodec_BmpModule::Start(void* pModule) {
+ FXBMP_Context* p = FX_Alloc(FXBMP_Context, 1);
+ if (!p)
+ return nullptr;
+
+ FXSYS_memset(p, 0, sizeof(FXBMP_Context));
+ if (!p)
+ return nullptr;
+
+ p->m_AllocFunc = bmp_alloc_func;
+ p->m_FreeFunc = bmp_free_func;
+ p->bmp_ptr = nullptr;
+ p->parent_ptr = (void*)this;
+ p->child_ptr = pModule;
+ p->bmp_ptr = bmp_create_decompress();
+ if (!p->bmp_ptr) {
+ FX_Free(p);
+ return nullptr;
+ }
+ p->bmp_ptr->context_ptr = (void*)p;
+ p->bmp_ptr->err_ptr = m_szLastError;
+ p->bmp_ptr->bmp_error_fn = bmp_error_data;
+ p->bmp_ptr->bmp_get_row_fn = bmp_read_scanline;
+ p->bmp_ptr->bmp_get_data_position_fn = bmp_get_data_position;
+ return p;
+}
+
+void CCodec_BmpModule::Finish(FXBMP_Context* ctx) {
+ if (ctx) {
+ bmp_destroy_decompress(&ctx->bmp_ptr);
+ ctx->m_FreeFunc(ctx);
+ }
+}
+int32_t CCodec_BmpModule::ReadHeader(FXBMP_Context* ctx,
+ int32_t* width,
+ int32_t* height,
+ bool* tb_flag,
+ int32_t* components,
+ int32_t* pal_num,
+ uint32_t** pal_pp,
+ CFX_DIBAttribute* pAttribute) {
+ if (setjmp(ctx->bmp_ptr->jmpbuf)) {
+ return 0;
+ }
+ int32_t ret = bmp_read_header(ctx->bmp_ptr);
+ if (ret != 1) {
+ return ret;
+ }
+ *width = ctx->bmp_ptr->width;
+ *height = ctx->bmp_ptr->height;
+ *tb_flag = ctx->bmp_ptr->imgTB_flag;
+ *components = ctx->bmp_ptr->components;
+ *pal_num = ctx->bmp_ptr->pal_num;
+ *pal_pp = ctx->bmp_ptr->pal_ptr;
+ if (pAttribute) {
+ pAttribute->m_wDPIUnit = FXCODEC_RESUNIT_METER;
+ pAttribute->m_nXDPI = ctx->bmp_ptr->dpi_x;
+ pAttribute->m_nYDPI = ctx->bmp_ptr->dpi_y;
+ pAttribute->m_nBmpCompressType = ctx->bmp_ptr->compress_flag;
+ }
+ return 1;
+}
+
+int32_t CCodec_BmpModule::LoadImage(FXBMP_Context* ctx) {
+ if (setjmp(ctx->bmp_ptr->jmpbuf))
+ return 0;
+ return bmp_decode_image(ctx->bmp_ptr);
+}
+
+uint32_t CCodec_BmpModule::GetAvailInput(FXBMP_Context* ctx,
+ uint8_t** avail_buf_ptr) {
+ return bmp_get_avail_input(ctx->bmp_ptr, avail_buf_ptr);
+}
+
+void CCodec_BmpModule::Input(FXBMP_Context* ctx,
+ const uint8_t* src_buf,
+ uint32_t src_size) {
+ bmp_input_buffer(ctx->bmp_ptr, (uint8_t*)src_buf, src_size);
+}