diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-03-01 12:15:00 -0800 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-03-01 20:43:46 +0000 |
commit | b4a261855b34b4c8d938118762ae609a34a3ae99 (patch) | |
tree | 7b084e874cbf41eec73a3cec949dc810983cc0cf | |
parent | fed39cf4a23341cf9cb5a5b432248b4247022282 (diff) | |
download | pdfium-b4a261855b34b4c8d938118762ae609a34a3ae99.tar.xz |
Create virtual codec APIs so chrome/fuzzers can link separately
The one step to make an actual concrete class is conditionalized
in fpdfview and is unconditional in the fuzzer.
Also replace the clumsy C-style callbacks with a delegate
interface as long as we are making new interfaces.
Change-Id: I733a437483ce5e0c34211cfbbda05105336f55b5
Reviewed-on: https://pdfium-review.googlesource.com/2887
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r-- | BUILD.gn | 4 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_bmpmodule.cpp | 14 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_bmpmodule.h | 29 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_gifmodule.cpp | 31 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_gifmodule.h | 44 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_pngmodule.cpp | 18 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_pngmodule.h | 25 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_progressivedecoder.h | 94 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_tiffmodule.h | 19 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec.cpp | 12 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_progress.cpp | 385 | ||||
-rw-r--r-- | core/fxcodec/codec/icodec_bmpmodule.h | 51 | ||||
-rw-r--r-- | core/fxcodec/codec/icodec_gifmodule.h | 68 | ||||
-rw-r--r-- | core/fxcodec/codec/icodec_pngmodule.h | 47 | ||||
-rw-r--r-- | core/fxcodec/codec/icodec_tiffmodule.h | 36 | ||||
-rw-r--r-- | core/fxcodec/fx_codec.h | 79 | ||||
-rw-r--r-- | fpdfsdk/fpdfview.cpp | 36 | ||||
-rw-r--r-- | testing/libfuzzer/xfa_codec_fuzzer.h | 16 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_ffwidget.cpp | 4 |
19 files changed, 562 insertions, 450 deletions
@@ -709,6 +709,10 @@ static_library("fxcodec") { "core/fxcodec/codec/ccodec_tiffmodule.cpp", "core/fxcodec/codec/ccodec_tiffmodule.h", "core/fxcodec/codec/fx_codec_progress.cpp", + "core/fxcodec/codec/icodec_bmpmodule.h", + "core/fxcodec/codec/icodec_gifmodule.h", + "core/fxcodec/codec/icodec_pngmodule.h", + "core/fxcodec/codec/icodec_tiffmodule.h", "core/fxcodec/lbmp/fx_bmp.cpp", "core/fxcodec/lbmp/fx_bmp.h", "core/fxcodec/lgif/fx_gif.cpp", diff --git a/core/fxcodec/codec/ccodec_bmpmodule.cpp b/core/fxcodec/codec/ccodec_bmpmodule.cpp index c6ebd2d939..9d64199501 100644 --- a/core/fxcodec/codec/ccodec_bmpmodule.cpp +++ b/core/fxcodec/codec/ccodec_bmpmodule.cpp @@ -14,7 +14,6 @@ struct FXBMP_Context { bmp_decompress_struct_p bmp_ptr; void* parent_ptr; - void* child_ptr; void* (*m_AllocFunc)(unsigned int); void (*m_FreeFunc)(void*); @@ -37,16 +36,22 @@ static void bmp_read_scanline(bmp_decompress_struct_p bmp_ptr, 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); + pModule->GetDelegate()->BmpReadScanline(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); + return pModule->GetDelegate()->BmpInputImagePositionBuf(rcd_pos); } -FXBMP_Context* CCodec_BmpModule::Start(void* pModule) { +CCodec_BmpModule::CCodec_BmpModule() { + memset(m_szLastError, 0, sizeof(m_szLastError)); +} + +CCodec_BmpModule::~CCodec_BmpModule() {} + +FXBMP_Context* CCodec_BmpModule::Start() { FXBMP_Context* p = FX_Alloc(FXBMP_Context, 1); if (!p) return nullptr; @@ -59,7 +64,6 @@ FXBMP_Context* CCodec_BmpModule::Start(void* pModule) { 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); diff --git a/core/fxcodec/codec/ccodec_bmpmodule.h b/core/fxcodec/codec/ccodec_bmpmodule.h index 605bd620c2..11d5931cac 100644 --- a/core/fxcodec/codec/ccodec_bmpmodule.h +++ b/core/fxcodec/codec/ccodec_bmpmodule.h @@ -7,23 +7,21 @@ #ifndef CORE_FXCODEC_CODEC_CCODEC_BMPMODULE_H_ #define CORE_FXCODEC_CODEC_CCODEC_BMPMODULE_H_ +#include "core/fxcodec/codec/icodec_bmpmodule.h" #include "core/fxcrt/fx_system.h" -struct FXBMP_Context; -class CFX_DIBAttribute; - -class CCodec_BmpModule { +class CCodec_BmpModule : public ICodec_BmpModule { public: - CCodec_BmpModule() { FXSYS_memset(m_szLastError, 0, sizeof(m_szLastError)); } - - FXBMP_Context* Start(void* pModule); - void Finish(FXBMP_Context* pContext); + CCodec_BmpModule(); + ~CCodec_BmpModule() override; - uint32_t GetAvailInput(FXBMP_Context* pContext, uint8_t** avail_buf_ptr); + FXBMP_Context* Start() override; + void Finish(FXBMP_Context* pContext) override; + uint32_t GetAvailInput(FXBMP_Context* pContext, + uint8_t** avail_buf_ptr) override; void Input(FXBMP_Context* pContext, const uint8_t* src_buf, - uint32_t src_size); - + uint32_t src_size) override; int32_t ReadHeader(FXBMP_Context* pContext, int32_t* width, int32_t* height, @@ -31,13 +29,8 @@ class CCodec_BmpModule { int32_t* components, int32_t* pal_num, uint32_t** pal_pp, - CFX_DIBAttribute* pAttribute); - int32_t LoadImage(FXBMP_Context* pContext); - - bool (*InputImagePositionBufCallback)(void* pModule, uint32_t rcd_pos); - void (*ReadScanlineCallback)(void* pModule, - int32_t row_num, - uint8_t* row_buf); + CFX_DIBAttribute* pAttribute) override; + int32_t LoadImage(FXBMP_Context* pContext) override; protected: FX_CHAR m_szLastError[256]; diff --git a/core/fxcodec/codec/ccodec_gifmodule.cpp b/core/fxcodec/codec/ccodec_gifmodule.cpp index e3b2648c43..a85bc5eddc 100644 --- a/core/fxcodec/codec/ccodec_gifmodule.cpp +++ b/core/fxcodec/codec/ccodec_gifmodule.cpp @@ -14,11 +14,11 @@ struct FXGIF_Context { gif_decompress_struct_p gif_ptr; void* parent_ptr; - void* child_ptr; void* (*m_AllocFunc)(unsigned int); void (*m_FreeFunc)(void*); }; + extern "C" { static void* gif_alloc_func(unsigned int size) { return FX_Alloc(char, size); @@ -27,31 +27,36 @@ static void gif_free_func(void* p) { FX_Free(p); } }; + static void gif_error_data(gif_decompress_struct_p gif_ptr, const FX_CHAR* err_msg) { FXSYS_strncpy((char*)gif_ptr->err_ptr, err_msg, GIF_MAX_ERROR_SIZE - 1); longjmp(gif_ptr->jmpbuf, 1); } + static uint8_t* gif_ask_buf_for_pal(gif_decompress_struct_p gif_ptr, int32_t pal_size) { FXGIF_Context* p = (FXGIF_Context*)gif_ptr->context_ptr; CCodec_GifModule* pModule = (CCodec_GifModule*)p->parent_ptr; - return pModule->AskLocalPaletteBufCallback( - p->child_ptr, gif_get_frame_num(gif_ptr), pal_size); + return pModule->GetDelegate()->GifAskLocalPaletteBuf( + gif_get_frame_num(gif_ptr), pal_size); } + static void gif_record_current_position(gif_decompress_struct_p gif_ptr, uint32_t* cur_pos_ptr) { FXGIF_Context* p = (FXGIF_Context*)gif_ptr->context_ptr; CCodec_GifModule* pModule = (CCodec_GifModule*)p->parent_ptr; - pModule->RecordCurrentPositionCallback(p->child_ptr, *cur_pos_ptr); + pModule->GetDelegate()->GifRecordCurrentPosition(*cur_pos_ptr); } + static void gif_read_scanline(gif_decompress_struct_p gif_ptr, int32_t row_num, uint8_t* row_buf) { FXGIF_Context* p = (FXGIF_Context*)gif_ptr->context_ptr; CCodec_GifModule* pModule = (CCodec_GifModule*)p->parent_ptr; - pModule->ReadScanlineCallback(p->child_ptr, row_num, row_buf); + pModule->GetDelegate()->GifReadScanline(row_num, row_buf); } + static bool gif_get_record_position(gif_decompress_struct_p gif_ptr, uint32_t cur_pos, int32_t left, @@ -67,13 +72,18 @@ static bool gif_get_record_position(gif_decompress_struct_p gif_ptr, bool interlace) { FXGIF_Context* p = (FXGIF_Context*)gif_ptr->context_ptr; CCodec_GifModule* pModule = (CCodec_GifModule*)p->parent_ptr; - return pModule->InputRecordPositionBufCallback( - p->child_ptr, cur_pos, FX_RECT(left, top, left + width, top + height), - pal_num, pal_ptr, delay_time, user_input, trans_index, disposal_method, - interlace); + return pModule->GetDelegate()->GifInputRecordPositionBuf( + cur_pos, FX_RECT(left, top, left + width, top + height), pal_num, pal_ptr, + delay_time, user_input, trans_index, disposal_method, interlace); +} + +CCodec_GifModule::CCodec_GifModule() { + memset(m_szLastError, 0, sizeof(m_szLastError)); } -FXGIF_Context* CCodec_GifModule::Start(void* pModule) { +CCodec_GifModule::~CCodec_GifModule() {} + +FXGIF_Context* CCodec_GifModule::Start() { FXGIF_Context* p = FX_Alloc(FXGIF_Context, 1); if (!p) return nullptr; @@ -83,7 +93,6 @@ FXGIF_Context* CCodec_GifModule::Start(void* pModule) { p->m_FreeFunc = gif_free_func; p->gif_ptr = nullptr; p->parent_ptr = (void*)this; - p->child_ptr = pModule; p->gif_ptr = gif_create_decompress(); if (!p->gif_ptr) { FX_Free(p); diff --git a/core/fxcodec/codec/ccodec_gifmodule.h b/core/fxcodec/codec/ccodec_gifmodule.h index 21ac92d6c7..7721d7a767 100644 --- a/core/fxcodec/codec/ccodec_gifmodule.h +++ b/core/fxcodec/codec/ccodec_gifmodule.h @@ -7,24 +7,23 @@ #ifndef CORE_FXCODEC_CODEC_CCODEC_GIFMODULE_H_ #define CORE_FXCODEC_CODEC_CCODEC_GIFMODULE_H_ +#include "core/fxcodec/codec/icodec_gifmodule.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_system.h" -class CFX_DIBAttribute; -struct FXGIF_Context; - -class CCodec_GifModule { +class CCodec_GifModule : public ICodec_GifModule { public: - CCodec_GifModule() { FXSYS_memset(m_szLastError, 0, sizeof(m_szLastError)); } - - FXGIF_Context* Start(void* pModule); - void Finish(FXGIF_Context* pContext); + CCodec_GifModule(); + ~CCodec_GifModule() override; + FXGIF_Context* Start() override; + void Finish(FXGIF_Context* pContext) override; uint32_t GetAvailInput(FXGIF_Context* pContext, - uint8_t** avail_buf_ptr = nullptr); + uint8_t** avail_buf_ptr = nullptr) override; + void Input(FXGIF_Context* pContext, const uint8_t* src_buf, - uint32_t src_size); + uint32_t src_size) override; int32_t ReadHeader(FXGIF_Context* pContext, int* width, @@ -32,31 +31,12 @@ class CCodec_GifModule { int* pal_num, void** pal_pp, int* bg_index, - CFX_DIBAttribute* pAttribute); - - int32_t LoadFrameInfo(FXGIF_Context* pContext, int* frame_num); + CFX_DIBAttribute* pAttribute) override; + int32_t LoadFrameInfo(FXGIF_Context* pContext, int* frame_num) override; int32_t LoadFrame(FXGIF_Context* pContext, int frame_num, - CFX_DIBAttribute* pAttribute); - - void (*RecordCurrentPositionCallback)(void* pModule, uint32_t& cur_pos); - uint8_t* (*AskLocalPaletteBufCallback)(void* pModule, - int32_t frame_num, - int32_t pal_size); - bool (*InputRecordPositionBufCallback)(void* pModule, - uint32_t rcd_pos, - const FX_RECT& img_rc, - int32_t pal_num, - void* pal_ptr, - int32_t delay_time, - bool user_input, - int32_t trans_index, - int32_t disposal_method, - bool interlace); - void (*ReadScanlineCallback)(void* pModule, - int32_t row_num, - uint8_t* row_buf); + CFX_DIBAttribute* pAttribute) override; protected: FX_CHAR m_szLastError[256]; diff --git a/core/fxcodec/codec/ccodec_pngmodule.cpp b/core/fxcodec/codec/ccodec_pngmodule.cpp index d3e24cd9ea..028513b729 100644 --- a/core/fxcodec/codec/ccodec_pngmodule.cpp +++ b/core/fxcodec/codec/ccodec_pngmodule.cpp @@ -97,7 +97,6 @@ struct FXPNG_Context { png_structp png_ptr; png_infop info_ptr; void* parent_ptr; - void* child_ptr; void* (*m_AllocFunc)(unsigned int); void (*m_FreeFunc)(void*); @@ -135,8 +134,8 @@ static void _png_get_header_func(png_structp png_ptr, png_infop info_ptr) { png_set_palette_to_rgb(png_ptr); } pass = png_set_interlace_handling(png_ptr); - if (!pModule->ReadHeaderCallback(p->child_ptr, width, height, bpc, pass, - &color_type, &gamma)) { + if (!pModule->GetDelegate()->PngReadHeader(width, height, bpc, pass, + &color_type, &gamma)) { png_error(p->png_ptr, "Read Header Callback Error"); } int intent; @@ -189,16 +188,22 @@ static void _png_get_row_func(png_structp png_ptr, CCodec_PngModule* pModule = (CCodec_PngModule*)p->parent_ptr; uint8_t* src_buf = nullptr; - if (!pModule->AskScanlineBufCallback(p->child_ptr, row_num, src_buf)) { + if (!pModule->GetDelegate()->PngAskScanlineBuf(row_num, src_buf)) { png_error(png_ptr, "Ask Scanline buffer Callback Error"); } if (src_buf) { png_progressive_combine_row(png_ptr, src_buf, new_row); } - pModule->FillScanlineBufCompletedCallback(p->child_ptr, pass, row_num); + pModule->GetDelegate()->PngFillScanlineBufCompleted(pass, row_num); } -FXPNG_Context* CCodec_PngModule::Start(void* pModule) { +CCodec_PngModule::CCodec_PngModule() { + memset(m_szLastError, 0, sizeof(m_szLastError)); +} + +CCodec_PngModule::~CCodec_PngModule() {} + +FXPNG_Context* CCodec_PngModule::Start() { FXPNG_Context* p = FX_Alloc(FXPNG_Context, 1); if (!p) return nullptr; @@ -208,7 +213,6 @@ FXPNG_Context* CCodec_PngModule::Start(void* pModule) { p->png_ptr = nullptr; p->info_ptr = nullptr; p->parent_ptr = (void*)this; - p->child_ptr = pModule; p->png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); if (!p->png_ptr) { diff --git a/core/fxcodec/codec/ccodec_pngmodule.h b/core/fxcodec/codec/ccodec_pngmodule.h index 77c4af3946..1f3a3d96cc 100644 --- a/core/fxcodec/codec/ccodec_pngmodule.h +++ b/core/fxcodec/codec/ccodec_pngmodule.h @@ -7,33 +7,22 @@ #ifndef CORE_FXCODEC_CODEC_CCODEC_PNGMODULE_H_ #define CORE_FXCODEC_CODEC_CCODEC_PNGMODULE_H_ +#include "core/fxcodec/codec/icodec_pngmodule.h" #include "core/fxcrt/fx_system.h" -class CFX_DIBAttribute; -struct FXPNG_Context; - #define PNG_ERROR_SIZE 256 -class CCodec_PngModule { +class CCodec_PngModule : public ICodec_PngModule { public: - CCodec_PngModule() { FXSYS_memset(m_szLastError, 0, sizeof(m_szLastError)); } + CCodec_PngModule(); + ~CCodec_PngModule() override; - FXPNG_Context* Start(void* pModule); - void Finish(FXPNG_Context* pContext); + FXPNG_Context* Start() override; + void Finish(FXPNG_Context* pContext) override; bool Input(FXPNG_Context* pContext, const uint8_t* src_buf, uint32_t src_size, - CFX_DIBAttribute* pAttribute); - - bool (*ReadHeaderCallback)(void* pModule, - int width, - int height, - int bpc, - int pass, - int* color_type, - double* gamma); - bool (*AskScanlineBufCallback)(void* pModule, int line, uint8_t*& src_buf); - void (*FillScanlineBufCompletedCallback)(void* pModule, int pass, int line); + CFX_DIBAttribute* pAttribute) override; protected: FX_CHAR m_szLastError[PNG_ERROR_SIZE]; diff --git a/core/fxcodec/codec/ccodec_progressivedecoder.h b/core/fxcodec/codec/ccodec_progressivedecoder.h index e97d1b9f78..61703dde29 100644 --- a/core/fxcodec/codec/ccodec_progressivedecoder.h +++ b/core/fxcodec/codec/ccodec_progressivedecoder.h @@ -9,27 +9,25 @@ #include <vector> +#include "core/fxcodec/codec/icodec_bmpmodule.h" +#include "core/fxcodec/codec/icodec_gifmodule.h" +#include "core/fxcodec/codec/icodec_pngmodule.h" +#include "core/fxcodec/codec/icodec_tiffmodule.h" #include "core/fxcodec/fx_codec_def.h" #include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/fx_system.h" #include "core/fxge/fx_dib.h" -class CCodec_BmpModule; -class CCodec_GifContext; -class CCodec_GifModule; class CCodec_JpegModule; class CCodec_ModuleMgr; -class CCodec_PngContext; -class CCodec_TiffContext; class CFX_DIBAttribute; class IFX_SeekableReadStream; class IFX_Pause; -struct FXBMP_Context; -struct FXGIF_Context; struct FXJPEG_Context; -struct FXPNG_Context; -class CCodec_ProgressiveDecoder { +class CCodec_ProgressiveDecoder : public ICodec_BmpModule::Delegate, + public ICodec_GifModule::Delegate, + public ICodec_PngModule::Delegate { public: enum FXCodec_Format { FXCodec_Invalid = 0, @@ -44,7 +42,7 @@ class CCodec_ProgressiveDecoder { }; explicit CCodec_ProgressiveDecoder(CCodec_ModuleMgr* pCodecMgr); - ~CCodec_ProgressiveDecoder(); + virtual ~CCodec_ProgressiveDecoder(); FXCODEC_STATUS LoadImageInfo( const CFX_RetainPtr<IFX_SeekableReadStream>& pFile, @@ -170,60 +168,46 @@ class CCodec_ProgressiveDecoder { bool m_BmpIsTopBottom; FXCODEC_STATUS m_status; + // ICodec_PngModule::Delegate + bool PngReadHeader(int width, + int height, + int bpc, + int pass, + int* color_type, + double* gamma) override; + bool PngAskScanlineBuf(int line, uint8_t*& src_buf) override; + void PngFillScanlineBufCompleted(int pass, int line) override; + + // ICodec_GifModule::Delegate + void GifRecordCurrentPosition(uint32_t& cur_pos) override; + uint8_t* GifAskLocalPaletteBuf(int32_t frame_num, int32_t pal_size) override; + bool GifInputRecordPositionBuf(uint32_t rcd_pos, + const FX_RECT& img_rc, + int32_t pal_num, + void* pal_ptr, + int32_t delay_time, + bool user_input, + int32_t trans_index, + int32_t disposal_method, + bool interlace) override; + void GifReadScanline(int32_t row_num, uint8_t* row_buf) override; + + // ICodec_BmpModule::Delegate + bool BmpInputImagePositionBuf(uint32_t rcd_pos) override; + void BmpReadScanline(int32_t row_num, uint8_t* row_buf) override; + protected: -#ifdef PDF_ENABLE_XFA_PNG - static bool PngReadHeaderFunc(void* pModule, - int width, - int height, - int bpc, - int pass, - int* color_type, - double* gamma); - static bool PngAskScanlineBufFunc(void* pModule, int line, uint8_t*& src_buf); - static void PngFillScanlineBufCompletedFunc(void* pModule, - int pass, - int line); -#endif // PDF_ENABLE_XFA_PNG - -#ifdef PDF_ENABLE_XFA_GIF - static void GifRecordCurrentPositionCallback(void* pModule, - uint32_t& cur_pos); - static uint8_t* GifAskLocalPaletteBufCallback(void* pModule, - int32_t frame_num, - int32_t pal_size); - static bool GifInputRecordPositionBufCallback(void* pModule, - uint32_t rcd_pos, - const FX_RECT& img_rc, - int32_t pal_num, - void* pal_ptr, - int32_t delay_time, - bool user_input, - int32_t trans_index, - int32_t disposal_method, - bool interlace); - static void GifReadScanlineCallback(void* pModule, - int32_t row_num, - uint8_t* row_buf); - bool GifReadMoreData(CCodec_GifModule* pGifModule, + bool BmpReadMoreData(ICodec_BmpModule* pBmpModule, + FXCODEC_STATUS& err_status); + bool GifReadMoreData(ICodec_GifModule* pGifModule, FXCODEC_STATUS& err_status); void GifDoubleLineResampleVert(CFX_DIBitmap* pDeviceBitmap, double scale_y, int des_row); -#endif // PDF_ENABLE_XFA_GIF - -#ifdef PDF_ENABLE_XFA_BMP - static bool BmpInputImagePositionBufCallback(void* pModule, uint32_t rcd_pos); - static void BmpReadScanlineCallback(void* pModule, - int32_t row_num, - uint8_t* row_buf); void PngOneOneMapResampleHorz(CFX_DIBitmap* pDeviceBitmap, int32_t des_line, uint8_t* src_scan, FXCodec_Format src_format); - bool BmpReadMoreData(CCodec_BmpModule* pBmpModule, - FXCODEC_STATUS& err_status); -#endif // PDF_ENABLE_XFA_BMP - bool DetectImageType(FXCODEC_IMAGE_TYPE imageType, CFX_DIBAttribute* pAttribute); void GetDownScale(int& down_scale); diff --git a/core/fxcodec/codec/ccodec_tiffmodule.h b/core/fxcodec/codec/ccodec_tiffmodule.h index dd2cbd768c..a8820f4aac 100644 --- a/core/fxcodec/codec/ccodec_tiffmodule.h +++ b/core/fxcodec/codec/ccodec_tiffmodule.h @@ -7,30 +7,25 @@ #ifndef CORE_FXCODEC_CODEC_CCODEC_TIFFMODULE_H_ #define CORE_FXCODEC_CODEC_CCODEC_TIFFMODULE_H_ +#include "core/fxcodec/codec/icodec_tiffmodule.h" #include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/fx_system.h" -class CCodec_TiffContext; -class CFX_DIBAttribute; -class CFX_DIBitmap; -class IFX_SeekableReadStream; - -class CCodec_TiffModule { +class CCodec_TiffModule : public ICodec_TiffModule { public: - ~CCodec_TiffModule() {} + ~CCodec_TiffModule() override {} CCodec_TiffContext* CreateDecoder( - const CFX_RetainPtr<IFX_SeekableReadStream>& file_ptr); - + const CFX_RetainPtr<IFX_SeekableReadStream>& file_ptr) override; bool LoadFrameInfo(CCodec_TiffContext* ctx, int32_t frame, int32_t* width, int32_t* height, int32_t* comps, int32_t* bpc, - CFX_DIBAttribute* pAttribute); - bool Decode(CCodec_TiffContext* ctx, class CFX_DIBitmap* pDIBitmap); - void DestroyDecoder(CCodec_TiffContext* ctx); + CFX_DIBAttribute* pAttribute) override; + bool Decode(CCodec_TiffContext* ctx, class CFX_DIBitmap* pDIBitmap) override; + void DestroyDecoder(CCodec_TiffContext* ctx) override; }; #endif // CORE_FXCODEC_CODEC_CCODEC_TIFFMODULE_H_ diff --git a/core/fxcodec/codec/fx_codec.cpp b/core/fxcodec/codec/fx_codec.cpp index d9a36a6c5a..0d886b43cb 100644 --- a/core/fxcodec/codec/fx_codec.cpp +++ b/core/fxcodec/codec/fx_codec.cpp @@ -24,18 +24,6 @@ CCodec_ModuleMgr::CCodec_ModuleMgr() m_pJpxModule(new CCodec_JpxModule), m_pJbig2Module(new CCodec_Jbig2Module), m_pIccModule(new CCodec_IccModule), -#ifdef PDF_ENABLE_XFA_BMP - m_pBmpModule(new CCodec_BmpModule), -#endif // PDF_ENABLE_XFA_BMP -#ifdef PDF_ENABLE_XFA_GIF - m_pGifModule(new CCodec_GifModule), -#endif // PDF_ENABLE_XFA_GIF -#ifdef PDF_ENABLE_XFA_PNG - m_pPngModule(new CCodec_PngModule), -#endif // PDF_ENABLE_XFA_PNG -#ifdef PDF_ENABLE_XFA_TIFF - m_pTiffModule(new CCodec_TiffModule), -#endif // PDF_ENABLE_XFA_TIFF m_pFlateModule(new CCodec_FlateModule) { } diff --git a/core/fxcodec/codec/fx_codec_progress.cpp b/core/fxcodec/codec/fx_codec_progress.cpp index e4996c887a..1f2f50c29e 100644 --- a/core/fxcodec/codec/fx_codec_progress.cpp +++ b/core/fxcodec/codec/fx_codec_progress.cpp @@ -12,18 +12,17 @@ #include "core/fxcodec/fx_codec.h" #include "core/fxge/fx_dib.h" #include "third_party/base/numerics/safe_math.h" +#include "third_party/base/ptr_util.h" #define FXCODEC_BLOCK_SIZE 4096 namespace { -#ifdef PDF_ENABLE_XFA_PNG #if _FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_IOS_ const double kPngGamma = 1.7; #else // _FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_IOS_ const double kPngGamma = 2.2; #endif // _FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_IOS_ -#endif // PDF_ENABLE_XFA_PNG void RGB2BGR(uint8_t* buffer, int width = 1) { if (buffer && width > 0) { @@ -301,22 +300,14 @@ CCodec_ProgressiveDecoder::~CCodec_ProgressiveDecoder() { m_pFile = nullptr; if (m_pJpegContext) m_pCodecMgr->GetJpegModule()->Finish(m_pJpegContext); -#ifdef PDF_ENABLE_XFA_BMP if (m_pBmpContext) m_pCodecMgr->GetBmpModule()->Finish(m_pBmpContext); -#endif // PDF_ENABLE_XFA_BMP -#ifdef PDF_ENABLE_XFA_GIF if (m_pGifContext) m_pCodecMgr->GetGifModule()->Finish(m_pGifContext); -#endif // PDF_ENABLE_XFA_GIF -#ifdef PDF_ENABLE_XFA_PNG if (m_pPngContext) m_pCodecMgr->GetPngModule()->Finish(m_pPngContext); -#endif // PDF_ENABLE_XFA_PNG -#ifdef PDF_ENABLE_XFA_TIFF if (m_pTiffContext) m_pCodecMgr->GetTiffModule()->DestroyDecoder(m_pTiffContext); -#endif // PDF_ENABLE_XFA_TIFF FX_Free(m_pSrcBuf); FX_Free(m_pDecodeBuf); FX_Free(m_pSrcPalette); @@ -359,42 +350,39 @@ bool CCodec_ProgressiveDecoder::JpegReadMoreData(CCodec_JpegModule* pJpegModule, return true; } -#ifdef PDF_ENABLE_XFA_PNG -bool CCodec_ProgressiveDecoder::PngReadHeaderFunc(void* pModule, - int width, - int height, - int bpc, - int pass, - int* color_type, - double* gamma) { - CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; - if (!pCodec->m_pDeviceBitmap) { - pCodec->m_SrcWidth = width; - pCodec->m_SrcHeight = height; - pCodec->m_SrcBPC = bpc; - pCodec->m_SrcPassNumber = pass; +bool CCodec_ProgressiveDecoder::PngReadHeader(int width, + int height, + int bpc, + int pass, + int* color_type, + double* gamma) { + if (!m_pDeviceBitmap) { + m_SrcWidth = width; + m_SrcHeight = height; + m_SrcBPC = bpc; + m_SrcPassNumber = pass; switch (*color_type) { case 0: - pCodec->m_SrcComponents = 1; + m_SrcComponents = 1; break; case 4: - pCodec->m_SrcComponents = 2; + m_SrcComponents = 2; break; case 2: - pCodec->m_SrcComponents = 3; + m_SrcComponents = 3; break; case 3: case 6: - pCodec->m_SrcComponents = 4; + m_SrcComponents = 4; break; default: - pCodec->m_SrcComponents = 0; + m_SrcComponents = 0; break; } - pCodec->m_clipBox = FX_RECT(0, 0, width, height); + m_clipBox = FX_RECT(0, 0, width, height); return false; } - FXDIB_Format format = pCodec->m_pDeviceBitmap->GetFormat(); + FXDIB_Format format = m_pDeviceBitmap->GetFormat(); switch (format) { case FXDIB_1bppMask: case FXDIB_1bppRgb: @@ -419,32 +407,26 @@ bool CCodec_ProgressiveDecoder::PngReadHeaderFunc(void* pModule, return true; } -bool CCodec_ProgressiveDecoder::PngAskScanlineBufFunc(void* pModule, - int line, - uint8_t*& src_buf) { - CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; - CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap; +bool CCodec_ProgressiveDecoder::PngAskScanlineBuf(int line, uint8_t*& src_buf) { + CFX_DIBitmap* pDIBitmap = m_pDeviceBitmap; if (!pDIBitmap) { ASSERT(false); return false; } - if (line >= pCodec->m_clipBox.top && line < pCodec->m_clipBox.bottom) { - double scale_y = - (double)pCodec->m_sizeY / (double)pCodec->m_clipBox.Height(); - int32_t row = - (int32_t)((line - pCodec->m_clipBox.top) * scale_y) + pCodec->m_startY; + if (line >= m_clipBox.top && line < m_clipBox.bottom) { + double scale_y = (double)m_sizeY / (double)m_clipBox.Height(); + int32_t row = (int32_t)((line - m_clipBox.top) * scale_y) + m_startY; uint8_t* src_scan = (uint8_t*)pDIBitmap->GetScanline(row); - uint8_t* des_scan = pCodec->m_pDecodeBuf; - src_buf = pCodec->m_pDecodeBuf; + uint8_t* des_scan = m_pDecodeBuf; + src_buf = m_pDecodeBuf; int32_t src_Bpp = pDIBitmap->GetBPP() >> 3; - int32_t des_Bpp = (pCodec->m_SrcFormat & 0xff) >> 3; - int32_t src_left = pCodec->m_startX; - int32_t des_left = pCodec->m_clipBox.left; + int32_t des_Bpp = (m_SrcFormat & 0xff) >> 3; + int32_t src_left = m_startX; + int32_t des_left = m_clipBox.left; src_scan += src_left * src_Bpp; des_scan += des_left * des_Bpp; - for (int32_t src_col = 0; src_col < pCodec->m_sizeX; src_col++) { - PixelWeight* pPixelWeights = - pCodec->m_WeightHorzOO.GetPixelWeight(src_col); + for (int32_t src_col = 0; src_col < m_sizeX; src_col++) { + PixelWeight* pPixelWeights = m_WeightHorzOO.GetPixelWeight(src_col); if (pPixelWeights->m_SrcStart != pPixelWeights->m_SrcEnd) { continue; } @@ -566,17 +548,15 @@ void CCodec_ProgressiveDecoder::PngOneOneMapResampleHorz( } } -void CCodec_ProgressiveDecoder::PngFillScanlineBufCompletedFunc(void* pModule, - int pass, - int line) { - CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; - CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap; +void CCodec_ProgressiveDecoder::PngFillScanlineBufCompleted(int pass, + int line) { + CFX_DIBitmap* pDIBitmap = m_pDeviceBitmap; ASSERT(pDIBitmap); - int src_top = pCodec->m_clipBox.top; - int src_bottom = pCodec->m_clipBox.bottom; - int des_top = pCodec->m_startY; - int src_hei = pCodec->m_clipBox.Height(); - int des_hei = pCodec->m_sizeY; + int src_top = m_clipBox.top; + int src_bottom = m_clipBox.bottom; + int des_top = m_startY; + int src_hei = m_clipBox.Height(); + int des_hei = m_sizeY; if (line >= src_top && line < src_bottom) { double scale_y = (double)des_hei / (double)src_hei; int src_row = line - src_top; @@ -584,21 +564,18 @@ void CCodec_ProgressiveDecoder::PngFillScanlineBufCompletedFunc(void* pModule, if (des_row >= des_top + des_hei) { return; } - pCodec->PngOneOneMapResampleHorz(pDIBitmap, des_row, pCodec->m_pDecodeBuf, - pCodec->m_SrcFormat); - if (pCodec->m_SrcPassNumber == 1 && scale_y > 1.0) { - pCodec->ResampleVert(pDIBitmap, scale_y, des_row); + PngOneOneMapResampleHorz(pDIBitmap, des_row, m_pDecodeBuf, m_SrcFormat); + if (m_SrcPassNumber == 1 && scale_y > 1.0) { + ResampleVert(pDIBitmap, scale_y, des_row); return; } if (pass == 6 && scale_y > 1.0) { - pCodec->ResampleVert(pDIBitmap, scale_y, des_row); + ResampleVert(pDIBitmap, scale_y, des_row); } } } -#endif // PDF_ENABLE_XFA_PNG -#ifdef PDF_ENABLE_XFA_GIF -bool CCodec_ProgressiveDecoder::GifReadMoreData(CCodec_GifModule* pGifModule, +bool CCodec_ProgressiveDecoder::GifReadMoreData(ICodec_GifModule* pGifModule, FXCODEC_STATUS& err_status) { uint32_t dwSize = (uint32_t)m_pFile->GetSize(); if (dwSize <= m_offSet) { @@ -635,24 +612,18 @@ bool CCodec_ProgressiveDecoder::GifReadMoreData(CCodec_GifModule* pGifModule, return true; } -void CCodec_ProgressiveDecoder::GifRecordCurrentPositionCallback( - void* pModule, - uint32_t& cur_pos) { - CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; +void CCodec_ProgressiveDecoder::GifRecordCurrentPosition(uint32_t& cur_pos) { uint32_t remain_size = - pCodec->m_pCodecMgr->GetGifModule()->GetAvailInput(pCodec->m_pGifContext); - cur_pos = pCodec->m_offSet - remain_size; + m_pCodecMgr->GetGifModule()->GetAvailInput(m_pGifContext); + cur_pos = m_offSet - remain_size; } -uint8_t* CCodec_ProgressiveDecoder::GifAskLocalPaletteBufCallback( - void* pModule, - int32_t frame_num, - int32_t pal_size) { +uint8_t* CCodec_ProgressiveDecoder::GifAskLocalPaletteBuf(int32_t frame_num, + int32_t pal_size) { return FX_Alloc(uint8_t, pal_size); } -bool CCodec_ProgressiveDecoder::GifInputRecordPositionBufCallback( - void* pModule, +bool CCodec_ProgressiveDecoder::GifInputRecordPositionBuf( uint32_t rcd_pos, const FX_RECT& img_rc, int32_t pal_num, @@ -662,58 +633,56 @@ bool CCodec_ProgressiveDecoder::GifInputRecordPositionBufCallback( int32_t trans_index, int32_t disposal_method, bool interlace) { - CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; - pCodec->m_offSet = rcd_pos; + m_offSet = rcd_pos; FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR; - if (!pCodec->GifReadMoreData(pCodec->m_pCodecMgr->GetGifModule(), - error_status)) { + if (!GifReadMoreData(m_pCodecMgr->GetGifModule(), error_status)) { return false; } uint8_t* pPalette = nullptr; if (pal_num != 0 && pal_ptr) { pPalette = (uint8_t*)pal_ptr; } else { - pal_num = pCodec->m_GifPltNumber; - pPalette = pCodec->m_pGifPalette; + pal_num = m_GifPltNumber; + pPalette = m_pGifPalette; } - if (!pCodec->m_pSrcPalette) - pCodec->m_pSrcPalette = FX_Alloc(FX_ARGB, pal_num); - else if (pal_num > pCodec->m_SrcPaletteNumber) - pCodec->m_pSrcPalette = FX_Realloc(FX_ARGB, pCodec->m_pSrcPalette, pal_num); - if (!pCodec->m_pSrcPalette) + if (!m_pSrcPalette) + m_pSrcPalette = FX_Alloc(FX_ARGB, pal_num); + else if (pal_num > m_SrcPaletteNumber) + m_pSrcPalette = FX_Realloc(FX_ARGB, m_pSrcPalette, pal_num); + if (!m_pSrcPalette) return false; - pCodec->m_SrcPaletteNumber = pal_num; + m_SrcPaletteNumber = pal_num; for (int i = 0; i < pal_num; i++) { uint32_t j = i * 3; - pCodec->m_pSrcPalette[i] = + m_pSrcPalette[i] = ArgbEncode(0xff, pPalette[j], pPalette[j + 1], pPalette[j + 2]); } - pCodec->m_GifTransIndex = trans_index; - pCodec->m_GifFrameRect = img_rc; - pCodec->m_SrcPassNumber = interlace ? 4 : 1; - int32_t pal_index = pCodec->m_GifBgIndex; - CFX_DIBitmap* pDevice = pCodec->m_pDeviceBitmap; + m_GifTransIndex = trans_index; + m_GifFrameRect = img_rc; + m_SrcPassNumber = interlace ? 4 : 1; + int32_t pal_index = m_GifBgIndex; + CFX_DIBitmap* pDevice = m_pDeviceBitmap; if (trans_index >= pal_num) trans_index = -1; if (trans_index != -1) { - pCodec->m_pSrcPalette[trans_index] &= 0x00ffffff; + m_pSrcPalette[trans_index] &= 0x00ffffff; if (pDevice->HasAlpha()) pal_index = trans_index; } if (pal_index >= pal_num) return false; - int startX = pCodec->m_startX; - int startY = pCodec->m_startY; - int sizeX = pCodec->m_sizeX; - int sizeY = pCodec->m_sizeY; + int startX = m_startX; + int startY = m_startY; + int sizeX = m_sizeX; + int sizeY = m_sizeY; int Bpp = pDevice->GetBPP() / 8; - FX_ARGB argb = pCodec->m_pSrcPalette[pal_index]; + FX_ARGB argb = m_pSrcPalette[pal_index]; for (int row = 0; row < sizeY; row++) { uint8_t* pScanline = (uint8_t*)pDevice->GetScanline(row + startY) + startX * Bpp; - switch (pCodec->m_TransMethod) { + switch (m_TransMethod) { case 3: { uint8_t gray = FXRGB2GRAY(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb)); @@ -741,36 +710,34 @@ bool CCodec_ProgressiveDecoder::GifInputRecordPositionBufCallback( return true; } -void CCodec_ProgressiveDecoder::GifReadScanlineCallback(void* pModule, - int32_t row_num, - uint8_t* row_buf) { - CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; - CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap; +void CCodec_ProgressiveDecoder::GifReadScanline(int32_t row_num, + uint8_t* row_buf) { + CFX_DIBitmap* pDIBitmap = m_pDeviceBitmap; ASSERT(pDIBitmap); - int32_t img_width = pCodec->m_GifFrameRect.Width(); + int32_t img_width = m_GifFrameRect.Width(); if (!pDIBitmap->HasAlpha()) { uint8_t* byte_ptr = row_buf; for (int i = 0; i < img_width; i++) { - if (*byte_ptr == pCodec->m_GifTransIndex) { - *byte_ptr = pCodec->m_GifBgIndex; + if (*byte_ptr == m_GifTransIndex) { + *byte_ptr = m_GifBgIndex; } byte_ptr++; } } - int32_t pal_index = pCodec->m_GifBgIndex; - if (pCodec->m_GifTransIndex != -1 && pCodec->m_pDeviceBitmap->HasAlpha()) { - pal_index = pCodec->m_GifTransIndex; + int32_t pal_index = m_GifBgIndex; + if (m_GifTransIndex != -1 && m_pDeviceBitmap->HasAlpha()) { + pal_index = m_GifTransIndex; } - FXSYS_memset(pCodec->m_pDecodeBuf, pal_index, pCodec->m_SrcWidth); + FXSYS_memset(m_pDecodeBuf, pal_index, m_SrcWidth); bool bLastPass = (row_num % 2) == 1; - int32_t line = row_num + pCodec->m_GifFrameRect.top; - int32_t left = pCodec->m_GifFrameRect.left; - FXSYS_memcpy(pCodec->m_pDecodeBuf + left, row_buf, img_width); - int src_top = pCodec->m_clipBox.top; - int src_bottom = pCodec->m_clipBox.bottom; - int des_top = pCodec->m_startY; - int src_hei = pCodec->m_clipBox.Height(); - int des_hei = pCodec->m_sizeY; + int32_t line = row_num + m_GifFrameRect.top; + int32_t left = m_GifFrameRect.left; + FXSYS_memcpy(m_pDecodeBuf + left, row_buf, img_width); + int src_top = m_clipBox.top; + int src_bottom = m_clipBox.bottom; + int des_top = m_startY; + int src_hei = m_clipBox.Height(); + int des_hei = m_sizeY; if (line < src_top || line >= src_bottom) return; @@ -780,18 +747,17 @@ void CCodec_ProgressiveDecoder::GifReadScanlineCallback(void* pModule, if (des_row >= des_top + des_hei) return; - pCodec->ReSampleScanline(pDIBitmap, des_row, pCodec->m_pDecodeBuf, - pCodec->m_SrcFormat); - if (scale_y > 1.0 && (!pCodec->m_bInterpol || pCodec->m_SrcPassNumber == 1)) { - pCodec->ResampleVert(pDIBitmap, scale_y, des_row); + ReSampleScanline(pDIBitmap, des_row, m_pDecodeBuf, m_SrcFormat); + if (scale_y > 1.0 && (!m_bInterpol || m_SrcPassNumber == 1)) { + ResampleVert(pDIBitmap, scale_y, des_row); return; } if (scale_y <= 1.0) return; - int des_bottom = des_top + pCodec->m_sizeY; + int des_bottom = des_top + m_sizeY; int des_Bpp = pDIBitmap->GetBPP() >> 3; - uint32_t des_ScanOffet = pCodec->m_startX * des_Bpp; + uint32_t des_ScanOffet = m_startX * des_Bpp; if (des_row + (int)scale_y >= des_bottom - 1) { uint8_t* scan_src = (uint8_t*)pDIBitmap->GetScanline(des_row) + des_ScanOffet; @@ -799,12 +765,12 @@ void CCodec_ProgressiveDecoder::GifReadScanlineCallback(void* pModule, while (++cur_row < des_bottom) { uint8_t* scan_des = (uint8_t*)pDIBitmap->GetScanline(cur_row) + des_ScanOffet; - uint32_t size = pCodec->m_sizeX * des_Bpp; + uint32_t size = m_sizeX * des_Bpp; FXSYS_memmove(scan_des, scan_src, size); } } if (bLastPass) - pCodec->GifDoubleLineResampleVert(pDIBitmap, scale_y, des_row); + GifDoubleLineResampleVert(pDIBitmap, scale_y, des_row); } void CCodec_ProgressiveDecoder::GifDoubleLineResampleVert( @@ -887,10 +853,8 @@ void CCodec_ProgressiveDecoder::GifDoubleLineResampleVert( GifDoubleLineResampleVert(pDeviceBitmap, scale_y, des_row + (int)scale_y); } } -#endif // PDF_ENABLE_XFA_GIF -#ifdef PDF_ENABLE_XFA_BMP -bool CCodec_ProgressiveDecoder::BmpReadMoreData(CCodec_BmpModule* pBmpModule, +bool CCodec_ProgressiveDecoder::BmpReadMoreData(ICodec_BmpModule* pBmpModule, FXCODEC_STATUS& err_status) { uint32_t dwSize = (uint32_t)m_pFile->GetSize(); if (dwSize <= m_offSet) @@ -927,28 +891,22 @@ bool CCodec_ProgressiveDecoder::BmpReadMoreData(CCodec_BmpModule* pBmpModule, return true; } -bool CCodec_ProgressiveDecoder::BmpInputImagePositionBufCallback( - void* pModule, - uint32_t rcd_pos) { - CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; - pCodec->m_offSet = rcd_pos; +bool CCodec_ProgressiveDecoder::BmpInputImagePositionBuf(uint32_t rcd_pos) { + m_offSet = rcd_pos; FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR; - return pCodec->BmpReadMoreData(pCodec->m_pCodecMgr->GetBmpModule(), - error_status); + return BmpReadMoreData(m_pCodecMgr->GetBmpModule(), error_status); } -void CCodec_ProgressiveDecoder::BmpReadScanlineCallback(void* pModule, - int32_t row_num, - uint8_t* row_buf) { - CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; - CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap; +void CCodec_ProgressiveDecoder::BmpReadScanline(int32_t row_num, + uint8_t* row_buf) { + CFX_DIBitmap* pDIBitmap = m_pDeviceBitmap; ASSERT(pDIBitmap); - FXSYS_memcpy(pCodec->m_pDecodeBuf, row_buf, pCodec->m_ScanlineSize); - int src_top = pCodec->m_clipBox.top; - int src_bottom = pCodec->m_clipBox.bottom; - int des_top = pCodec->m_startY; - int src_hei = pCodec->m_clipBox.Height(); - int des_hei = pCodec->m_sizeY; + FXSYS_memcpy(m_pDecodeBuf, row_buf, m_ScanlineSize); + int src_top = m_clipBox.top; + int src_bottom = m_clipBox.bottom; + int des_top = m_startY; + int src_hei = m_clipBox.Height(); + int des_hei = m_sizeY; if (row_num < src_top || row_num >= src_bottom) return; @@ -958,18 +916,16 @@ void CCodec_ProgressiveDecoder::BmpReadScanlineCallback(void* pModule, if (des_row >= des_top + des_hei) return; - pCodec->ReSampleScanline(pDIBitmap, des_row, pCodec->m_pDecodeBuf, - pCodec->m_SrcFormat); + ReSampleScanline(pDIBitmap, des_row, m_pDecodeBuf, m_SrcFormat); if (scale_y <= 1.0) return; - if (pCodec->m_BmpIsTopBottom || !pCodec->m_bInterpol) { - pCodec->ResampleVert(pDIBitmap, scale_y, des_row); + if (m_BmpIsTopBottom || !m_bInterpol) { + ResampleVert(pDIBitmap, scale_y, des_row); return; } - pCodec->ResampleVertBT(pDIBitmap, scale_y, des_row); + ResampleVertBT(pDIBitmap, scale_y, des_row); } -#endif // PDF_ENABLE_XFA_BMP void CCodec_ProgressiveDecoder::ResampleVertBT(CFX_DIBitmap* pDeviceBitmap, double scale_y, @@ -1067,17 +1023,14 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, FXSYS_memset(m_pSrcBuf, 0, size); m_SrcSize = size; switch (imageType) { -#ifdef PDF_ENABLE_XFA_BMP case FXCODEC_IMAGE_BMP: { - CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule(); + ICodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule(); if (!pBmpModule) { m_status = FXCODEC_STATUS_ERR_MEMORY; return false; } - pBmpModule->InputImagePositionBufCallback = - BmpInputImagePositionBufCallback; - pBmpModule->ReadScanlineCallback = BmpReadScanlineCallback; - m_pBmpContext = pBmpModule->Start((void*)this); + pBmpModule->SetDelegate(this); + m_pBmpContext = pBmpModule->Start(); if (!m_pBmpContext) { m_status = FXCODEC_STATUS_ERR_MEMORY; return false; @@ -1123,7 +1076,6 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, m_status = FXCODEC_STATUS_ERR_FORMAT; return false; } -#endif // PDF_ENABLE_XFA_BMP case FXCODEC_IMAGE_JPG: { CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule(); if (!pJpegModule) { @@ -1167,20 +1119,14 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, m_status = FXCODEC_STATUS_ERR_FORMAT; return false; } -#ifdef PDF_ENABLE_XFA_PNG case FXCODEC_IMAGE_PNG: { - CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule(); + ICodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule(); if (!pPngModule) { m_status = FXCODEC_STATUS_ERR_MEMORY; return false; } - pPngModule->ReadHeaderCallback = - CCodec_ProgressiveDecoder::PngReadHeaderFunc; - pPngModule->AskScanlineBufCallback = - CCodec_ProgressiveDecoder::PngAskScanlineBufFunc; - pPngModule->FillScanlineBufCompletedCallback = - CCodec_ProgressiveDecoder::PngFillScanlineBufCompletedFunc; - m_pPngContext = pPngModule->Start((void*)this); + pPngModule->SetDelegate(this); + m_pPngContext = pPngModule->Start(); if (!m_pPngContext) { m_status = FXCODEC_STATUS_ERR_MEMORY; return false; @@ -1230,23 +1176,14 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, } return true; } -#endif // PDF_ENABLE_XFA_PNG -#ifdef PDF_ENABLE_XFA_GIF case FXCODEC_IMAGE_GIF: { - CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); + ICodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); if (!pGifModule) { m_status = FXCODEC_STATUS_ERR_MEMORY; return false; } - pGifModule->RecordCurrentPositionCallback = - CCodec_ProgressiveDecoder::GifRecordCurrentPositionCallback; - pGifModule->AskLocalPaletteBufCallback = - CCodec_ProgressiveDecoder::GifAskLocalPaletteBufCallback; - pGifModule->InputRecordPositionBufCallback = - CCodec_ProgressiveDecoder::GifInputRecordPositionBufCallback; - pGifModule->ReadScanlineCallback = - CCodec_ProgressiveDecoder::GifReadScanlineCallback; - m_pGifContext = pGifModule->Start((void*)this); + pGifModule->SetDelegate(this); + m_pGifContext = pGifModule->Start(); if (!m_pGifContext) { m_status = FXCODEC_STATUS_ERR_MEMORY; return false; @@ -1284,10 +1221,8 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, m_status = FXCODEC_STATUS_ERR_FORMAT; return false; } -#endif // PDF_XFA_ENABLE_GIF -#ifdef PDF_ENABLE_XFA_TIFF case FXCODEC_IMAGE_TIF: { - CCodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule(); + ICodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule(); if (!pTiffModule) { m_status = FXCODEC_STATUS_ERR_FORMAT; return false; @@ -1311,7 +1246,6 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, } return true; } -#endif // PDF_ENABLE_XFA_TIFF default: m_status = FXCODEC_STATUS_ERR_FORMAT; return false; @@ -1857,21 +1791,18 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::GetFrames(int32_t& frames, } switch (m_imagType) { case FXCODEC_IMAGE_JPG: -#ifdef PDF_ENABLE_XFA_BMP case FXCODEC_IMAGE_BMP: -#endif -#ifdef PDF_ENABLE_XFA_PNG case FXCODEC_IMAGE_PNG: -#endif -#ifdef PDF_ENABLE_XFA_TIFF case FXCODEC_IMAGE_TIF: -#endif frames = m_FrameNumber = 1; m_status = FXCODEC_STATUS_DECODE_READY; return m_status; -#ifdef PDF_ENABLE_XFA_GIF case FXCODEC_IMAGE_GIF: { - CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); + ICodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); + if (!pGifModule) { + m_status = FXCODEC_STATUS_ERR_MEMORY; + return m_status; + } while (true) { int32_t readResult = pGifModule->LoadFrameInfo(m_pGifContext, &m_FrameNumber); @@ -1899,7 +1830,6 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::GetFrames(int32_t& frames, return m_status; } } -#endif // PDF_ENABLE_XFA_GIF default: return FXCODEC_STATUS_ERROR; } @@ -2000,9 +1930,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; return m_status; } -#ifdef PDF_ENABLE_XFA_PNG case FXCODEC_IMAGE_PNG: { - CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule(); + ICodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule(); if (!pPngModule) { m_pDeviceBitmap = nullptr; m_pFile = nullptr; @@ -2013,7 +1942,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, pPngModule->Finish(m_pPngContext); m_pPngContext = nullptr; } - m_pPngContext = pPngModule->Start((void*)this); + m_pPngContext = pPngModule->Start(); if (!m_pPngContext) { m_pDeviceBitmap = nullptr; m_pFile = nullptr; @@ -2053,10 +1982,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; return m_status; } -#endif // PDF_ENABLE_XFA_PNG -#ifdef PDF_ENABLE_XFA_GIF case FXCODEC_IMAGE_GIF: { - CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); + ICodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); if (!pGifModule) { m_pDeviceBitmap = nullptr; m_pFile = nullptr; @@ -2076,10 +2003,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; return m_status; } -#endif // PDF_ENABLE_XFA_GIF -#ifdef PDF_ENABLE_XFA_BMP case FXCODEC_IMAGE_BMP: { - CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule(); + ICodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule(); if (!pBmpModule) { m_pDeviceBitmap = nullptr; m_pFile = nullptr; @@ -2108,12 +2033,9 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; return m_status; } -#endif // PDF_ENABLE_XFA_BMP -#ifdef PDF_ENABLE_XFA_TIFF case FXCODEC_IMAGE_TIF: m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; return m_status; -#endif // PDF_ENABLE_XFA_TIFF default: return FXCODEC_STATUS_ERROR; } @@ -2156,9 +2078,12 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) { } } } -#ifdef PDF_ENABLE_XFA_PNG case FXCODEC_IMAGE_PNG: { - CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule(); + ICodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule(); + if (!pPngModule) { + m_status = FXCODEC_STATUS_ERR_MEMORY; + return m_status; + } while (true) { uint32_t remain_size = (uint32_t)m_pFile->GetSize() - m_offSet; uint32_t input_size = @@ -2201,10 +2126,12 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) { } } } -#endif // PDF_ENABLE_XFA_PNG -#ifdef PDF_ENABLE_XFA_GIF case FXCODEC_IMAGE_GIF: { - CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); + ICodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); + if (!pGifModule) { + m_status = FXCODEC_STATUS_ERR_MEMORY; + return m_status; + } while (true) { int32_t readRes = pGifModule->LoadFrame(m_pGifContext, m_FrameCur, nullptr); @@ -2234,10 +2161,12 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) { return m_status; } } -#endif // PDF_ENABLE_XFA_GIF -#ifdef PDF_ENABLE_XFA_BMP case FXCODEC_IMAGE_BMP: { - CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule(); + ICodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule(); + if (!pBmpModule) { + m_status = FXCODEC_STATUS_ERR_MEMORY; + return m_status; + } while (true) { int32_t readRes = pBmpModule->LoadImage(m_pBmpContext); while (readRes == 2) { @@ -2265,11 +2194,13 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) { m_status = FXCODEC_STATUS_ERROR; return m_status; } - }; -#endif // PDF_ENABLE_XFA_BMP -#ifdef PDF_ENABLE_XFA_TIFF + } case FXCODEC_IMAGE_TIF: { - CCodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule(); + ICodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule(); + if (!pTiffModule) { + m_status = FXCODEC_STATUS_ERR_MEMORY; + return m_status; + } bool ret = false; if (m_pDeviceBitmap->GetBPP() == 32 && m_pDeviceBitmap->GetWidth() == m_SrcWidth && m_SrcWidth == m_sizeX && @@ -2411,12 +2342,12 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) { m_status = FXCODEC_STATUS_DECODE_FINISH; return m_status; } -#endif // PDF_ENABLE_XFA_TIFF default: return FXCODEC_STATUS_ERROR; } } -CCodec_ProgressiveDecoder* CCodec_ModuleMgr::CreateProgressiveDecoder() { - return new CCodec_ProgressiveDecoder(this); +std::unique_ptr<CCodec_ProgressiveDecoder> +CCodec_ModuleMgr::CreateProgressiveDecoder() { + return pdfium::MakeUnique<CCodec_ProgressiveDecoder>(this); } diff --git a/core/fxcodec/codec/icodec_bmpmodule.h b/core/fxcodec/codec/icodec_bmpmodule.h new file mode 100644 index 0000000000..a67e20cf02 --- /dev/null +++ b/core/fxcodec/codec/icodec_bmpmodule.h @@ -0,0 +1,51 @@ +// Copyright 2017 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 + +#ifndef CORE_FXCODEC_CODEC_ICODEC_BMPMODULE_H_ +#define CORE_FXCODEC_CODEC_ICODEC_BMPMODULE_H_ + +#include "core/fxcrt/fx_system.h" + +struct FXBMP_Context; +class CFX_DIBAttribute; + +// Virtual interface to avoid linking in a concrete implementation +// if we do not enable this codec. +class ICodec_BmpModule { + public: + class Delegate { + public: + virtual bool BmpInputImagePositionBuf(uint32_t rcd_pos) = 0; + virtual void BmpReadScanline(int32_t row_num, uint8_t* row_buf) = 0; + }; + + virtual ~ICodec_BmpModule() {} + + virtual FXBMP_Context* Start() = 0; + virtual void Finish(FXBMP_Context* pContext) = 0; + virtual uint32_t GetAvailInput(FXBMP_Context* pContext, + uint8_t** avail_buf_ptr) = 0; + virtual void Input(FXBMP_Context* pContext, + const uint8_t* src_buf, + uint32_t src_size) = 0; + virtual int32_t ReadHeader(FXBMP_Context* pContext, + int32_t* width, + int32_t* height, + bool* tb_flag, + int32_t* components, + int32_t* pal_num, + uint32_t** pal_pp, + CFX_DIBAttribute* pAttribute) = 0; + virtual int32_t LoadImage(FXBMP_Context* pContext) = 0; + + Delegate* GetDelegate() const { return m_pDelegate; } + void SetDelegate(Delegate* pDelegate) { m_pDelegate = pDelegate; } + + protected: + Delegate* m_pDelegate; +}; + +#endif // CORE_FXCODEC_CODEC_ICODEC_BMPMODULE_H_ diff --git a/core/fxcodec/codec/icodec_gifmodule.h b/core/fxcodec/codec/icodec_gifmodule.h new file mode 100644 index 0000000000..9dc0708ebe --- /dev/null +++ b/core/fxcodec/codec/icodec_gifmodule.h @@ -0,0 +1,68 @@ +// Copyright 2017 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 + +#ifndef CORE_FXCODEC_CODEC_ICODEC_GIFMODULE_H_ +#define CORE_FXCODEC_CODEC_ICODEC_GIFMODULE_H_ + +#include "core/fxcrt/fx_coordinates.h" +#include "core/fxcrt/fx_system.h" + +class CFX_DIBAttribute; +struct FXGIF_Context; + +// Virtual interface to avoid linking in a concrete implementation +// if we do not enable this codec. +class ICodec_GifModule { + public: + class Delegate { + public: + virtual void GifRecordCurrentPosition(uint32_t& cur_pos) = 0; + virtual uint8_t* GifAskLocalPaletteBuf(int32_t frame_num, + int32_t pal_size) = 0; + virtual bool GifInputRecordPositionBuf(uint32_t rcd_pos, + const FX_RECT& img_rc, + int32_t pal_num, + void* pal_ptr, + int32_t delay_time, + bool user_input, + int32_t trans_index, + int32_t disposal_method, + bool interlace) = 0; + virtual void GifReadScanline(int32_t row_num, uint8_t* row_buf) = 0; + }; + + virtual ~ICodec_GifModule() {} + + virtual FXGIF_Context* Start() = 0; + virtual void Finish(FXGIF_Context* pContext) = 0; + virtual uint32_t GetAvailInput(FXGIF_Context* pContext, + uint8_t** avail_buf_ptr = nullptr) = 0; + + virtual void Input(FXGIF_Context* pContext, + const uint8_t* src_buf, + uint32_t src_size) = 0; + + virtual int32_t ReadHeader(FXGIF_Context* pContext, + int* width, + int* height, + int* pal_num, + void** pal_pp, + int* bg_index, + CFX_DIBAttribute* pAttribute) = 0; + + virtual int32_t LoadFrameInfo(FXGIF_Context* pContext, int* frame_num) = 0; + virtual int32_t LoadFrame(FXGIF_Context* pContext, + int frame_num, + CFX_DIBAttribute* pAttribute) = 0; + + Delegate* GetDelegate() const { return m_pDelegate; } + void SetDelegate(Delegate* pDelegate) { m_pDelegate = pDelegate; } + + protected: + Delegate* m_pDelegate; +}; + +#endif // CORE_FXCODEC_CODEC_ICODEC_GIFMODULE_H_ diff --git a/core/fxcodec/codec/icodec_pngmodule.h b/core/fxcodec/codec/icodec_pngmodule.h new file mode 100644 index 0000000000..63e61fe5b5 --- /dev/null +++ b/core/fxcodec/codec/icodec_pngmodule.h @@ -0,0 +1,47 @@ +// Copyright 2017 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 + +#ifndef CORE_FXCODEC_CODEC_ICODEC_PNGMODULE_H_ +#define CORE_FXCODEC_CODEC_ICODEC_PNGMODULE_H_ + +#include "core/fxcrt/fx_system.h" + +class CFX_DIBAttribute; +struct FXPNG_Context; + +// Virtual interface to avoid linking in a concrete implementation +// if we do not enable this codec. +class ICodec_PngModule { + public: + class Delegate { + public: + virtual bool PngReadHeader(int width, + int height, + int bpc, + int pass, + int* color_type, + double* gamma) = 0; + virtual bool PngAskScanlineBuf(int line, uint8_t*& src_buf) = 0; + virtual void PngFillScanlineBufCompleted(int pass, int line) = 0; + }; + + virtual ~ICodec_PngModule() {} + + virtual FXPNG_Context* Start() = 0; + virtual void Finish(FXPNG_Context* pContext) = 0; + virtual bool Input(FXPNG_Context* pContext, + const uint8_t* src_buf, + uint32_t src_size, + CFX_DIBAttribute* pAttribute) = 0; + + Delegate* GetDelegate() const { return m_pDelegate; } + void SetDelegate(Delegate* delegate) { m_pDelegate = delegate; } + + protected: + Delegate* m_pDelegate; +}; + +#endif // CORE_FXCODEC_CODEC_ICODEC_PNGMODULE_H_ diff --git a/core/fxcodec/codec/icodec_tiffmodule.h b/core/fxcodec/codec/icodec_tiffmodule.h new file mode 100644 index 0000000000..540d82ff63 --- /dev/null +++ b/core/fxcodec/codec/icodec_tiffmodule.h @@ -0,0 +1,36 @@ +// Copyright 2017 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 + +#ifndef CORE_FXCODEC_CODEC_ICODEC_TIFFMODULE_H_ +#define CORE_FXCODEC_CODEC_ICODEC_TIFFMODULE_H_ + +#include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/fx_system.h" + +class CCodec_TiffContext; +class CFX_DIBAttribute; +class CFX_DIBitmap; +class IFX_SeekableReadStream; + +class ICodec_TiffModule { + public: + virtual ~ICodec_TiffModule() {} + + virtual CCodec_TiffContext* CreateDecoder( + const CFX_RetainPtr<IFX_SeekableReadStream>& file_ptr) = 0; + virtual bool LoadFrameInfo(CCodec_TiffContext* ctx, + int32_t frame, + int32_t* width, + int32_t* height, + int32_t* comps, + int32_t* bpc, + CFX_DIBAttribute* pAttribute) = 0; + virtual bool Decode(CCodec_TiffContext* ctx, + class CFX_DIBitmap* pDIBitmap) = 0; + virtual void DestroyDecoder(CCodec_TiffContext* ctx) = 0; +}; + +#endif // CORE_FXCODEC_CODEC_ICODEC_TIFFMODULE_H_ diff --git a/core/fxcodec/fx_codec.h b/core/fxcodec/fx_codec.h index a33e117c7e..b0b9fa1821 100644 --- a/core/fxcodec/fx_codec.h +++ b/core/fxcodec/fx_codec.h @@ -9,6 +9,7 @@ #include <map> #include <memory> +#include <utility> #include <vector> #include "core/fxcodec/codec/ccodec_basicmodule.h" @@ -23,27 +24,18 @@ #include "core/fxcrt/fx_basic.h" #include "core/fxcrt/fx_coordinates.h" +#ifdef PDF_ENABLE_XFA +#include "core/fxcodec/codec/icodec_bmpmodule.h" +#include "core/fxcodec/codec/icodec_gifmodule.h" +#include "core/fxcodec/codec/icodec_pngmodule.h" +#include "core/fxcodec/codec/icodec_tiffmodule.h" +#endif // PDF_ENABLE_XFA + class CFX_DIBSource; class CJPX_Decoder; class CPDF_ColorSpace; class CPDF_StreamAcc; -#ifdef PDF_ENABLE_XFA_BMP -#include "core/fxcodec/codec/ccodec_bmpmodule.h" -#endif // PDF_ENABLE_XFA_BMP - -#ifdef PDF_ENABLE_XFA_GIF -#include "core/fxcodec/codec/ccodec_gifmodule.h" -#endif // PDF_ENABLE_XFA_GIF - -#ifdef PDF_ENABLE_XFA_PNG -#include "core/fxcodec/codec/ccodec_pngmodule.h" -#endif // PDF_ENABLE_XFA_PNG - -#ifdef PDF_ENABLE_XFA_TIFF -#include "core/fxcodec/codec/ccodec_tiffmodule.h" -#endif // PDF_ENABLE_XFA_TIFF - #ifdef PDF_ENABLE_XFA class CCodec_ProgressiveDecoder; @@ -81,25 +73,25 @@ class CCodec_ModuleMgr { CCodec_FlateModule* GetFlateModule() const { return m_pFlateModule.get(); } #ifdef PDF_ENABLE_XFA - CCodec_ProgressiveDecoder* CreateProgressiveDecoder(); + std::unique_ptr<CCodec_ProgressiveDecoder> CreateProgressiveDecoder(); + void SetBmpModule(std::unique_ptr<ICodec_BmpModule> module) { + m_pBmpModule = std::move(module); + } + void SetGifModule(std::unique_ptr<ICodec_GifModule> module) { + m_pGifModule = std::move(module); + } + void SetPngModule(std::unique_ptr<ICodec_PngModule> module) { + m_pPngModule = std::move(module); + } + void SetTiffModule(std::unique_ptr<ICodec_TiffModule> module) { + m_pTiffModule = std::move(module); + } + ICodec_BmpModule* GetBmpModule() const { return m_pBmpModule.get(); } + ICodec_GifModule* GetGifModule() const { return m_pGifModule.get(); } + ICodec_PngModule* GetPngModule() const { return m_pPngModule.get(); } + ICodec_TiffModule* GetTiffModule() const { return m_pTiffModule.get(); } #endif // PDF_ENABLE_XFA -#ifdef PDF_ENABLE_XFA_BMP - CCodec_BmpModule* GetBmpModule() const { return m_pBmpModule.get(); } -#endif // PDF_ENABLE_XFA_BMP - -#ifdef PDF_ENABLE_XFA_GIF - CCodec_GifModule* GetGifModule() const { return m_pGifModule.get(); } -#endif // PDF_ENABLE_XFA_GIF - -#ifdef PDF_ENABLE_XFA_PNG - CCodec_PngModule* GetPngModule() const { return m_pPngModule.get(); } -#endif // PDF_ENABLE_XFA_PNG - -#ifdef PDF_ENABLE_XFA_TIFF - CCodec_TiffModule* GetTiffModule() const { return m_pTiffModule.get(); } -#endif // PDF_ENABLE_XFA_TIFF - protected: std::unique_ptr<CCodec_BasicModule> m_pBasicModule; std::unique_ptr<CCodec_FaxModule> m_pFaxModule; @@ -108,21 +100,12 @@ class CCodec_ModuleMgr { std::unique_ptr<CCodec_Jbig2Module> m_pJbig2Module; std::unique_ptr<CCodec_IccModule> m_pIccModule; -#ifdef PDF_ENABLE_XFA_BMP - std::unique_ptr<CCodec_BmpModule> m_pBmpModule; -#endif // PDF_ENABLE_XFA_BMP - -#ifdef PDF_ENABLE_XFA_GIF - std::unique_ptr<CCodec_GifModule> m_pGifModule; -#endif // PDF_ENABLE_XFA_GIF - -#ifdef PDF_ENABLE_XFA_PNG - std::unique_ptr<CCodec_PngModule> m_pPngModule; -#endif // PDF_ENABLE_XFA_PNG - -#ifdef PDF_ENABLE_XFA_TIFF - std::unique_ptr<CCodec_TiffModule> m_pTiffModule; -#endif // PDF_ENABLE_XFA_TIFF +#ifdef PDF_ENABLE_XFA + std::unique_ptr<ICodec_BmpModule> m_pBmpModule; + std::unique_ptr<ICodec_GifModule> m_pGifModule; + std::unique_ptr<ICodec_PngModule> m_pPngModule; + std::unique_ptr<ICodec_TiffModule> m_pTiffModule; +#endif // PDF_ENABLE_XFA std::unique_ptr<CCodec_FlateModule> m_pFlateModule; }; diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index e1fba8df66..1e7a651aa8 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -44,6 +44,22 @@ #include "xfa/fxbarcode/BC_Library.h" #endif // PDF_ENABLE_XFA +#ifdef PDF_ENABLE_XFA_BMP +#include "core/fxcodec/codec/ccodec_bmpmodule.h" +#endif + +#ifdef PDF_ENABLE_XFA_GIF +#include "core/fxcodec/codec/ccodec_gifmodule.h" +#endif + +#ifdef PDF_ENABLE_XFA_PNG +#include "core/fxcodec/codec/ccodec_pngmodule.h" +#endif + +#ifdef PDF_ENABLE_XFA_TIFF +#include "core/fxcodec/codec/ccodec_tiffmodule.h" +#endif + #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ #include "core/fxge/cfx_windowsdevice.h" #endif @@ -364,6 +380,26 @@ FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* cfg) { pModuleMgr->LoadEmbeddedCNS1CMaps(); pModuleMgr->LoadEmbeddedKorea1CMaps(); +#ifdef PDF_ENABLE_XFA_BMP + pModuleMgr->GetCodecModule()->SetBmpModule( + pdfium::MakeUnique<CCodec_BmpModule>()); +#endif + +#ifdef PDF_ENABLE_XFA_GIF + pModuleMgr->GetCodecModule()->SetGifModule( + pdfium::MakeUnique<CCodec_GifModule>()); +#endif + +#ifdef PDF_ENABLE_XFA_PNG + pModuleMgr->GetCodecModule()->SetPngModule( + pdfium::MakeUnique<CCodec_PngModule>()); +#endif + +#ifdef PDF_ENABLE_XFA_TIFF + pModuleMgr->GetCodecModule()->SetTiffModule( + pdfium::MakeUnique<CCodec_TiffModule>()); +#endif + #ifdef PDF_ENABLE_XFA FXJSE_Initialize(); BC_Library_Init(); diff --git a/testing/libfuzzer/xfa_codec_fuzzer.h b/testing/libfuzzer/xfa_codec_fuzzer.h index 8608993396..9a8b23e368 100644 --- a/testing/libfuzzer/xfa_codec_fuzzer.h +++ b/testing/libfuzzer/xfa_codec_fuzzer.h @@ -7,16 +7,26 @@ #include <memory> +#include "core/fxcodec/codec/ccodec_bmpmodule.h" +#include "core/fxcodec/codec/ccodec_gifmodule.h" +#include "core/fxcodec/codec/ccodec_pngmodule.h" #include "core/fxcodec/codec/ccodec_progressivedecoder.h" +#include "core/fxcodec/codec/ccodec_tiffmodule.h" #include "core/fxcodec/fx_codec.h" #include "core/fxcrt/fx_stream.h" +#include "third_party/base/ptr_util.h" class XFACodecFuzzer { public: static int Fuzz(const uint8_t* data, size_t size, FXCODEC_IMAGE_TYPE type) { - std::unique_ptr<CCodec_ModuleMgr> mgr(new CCodec_ModuleMgr()); - std::unique_ptr<CCodec_ProgressiveDecoder> decoder( - mgr->CreateProgressiveDecoder()); + auto mgr = pdfium::MakeUnique<CCodec_ModuleMgr>(); + mgr->SetBmpModule(pdfium::MakeUnique<CCodec_BmpModule>()); + mgr->SetGifModule(pdfium::MakeUnique<CCodec_GifModule>()); + mgr->SetPngModule(pdfium::MakeUnique<CCodec_PngModule>()); + mgr->SetTiffModule(pdfium::MakeUnique<CCodec_TiffModule>()); + + std::unique_ptr<CCodec_ProgressiveDecoder> decoder = + mgr->CreateProgressiveDecoder(); CFX_RetainPtr<Reader> source(new Reader(data, size)); FXCODEC_STATUS status = decoder->LoadImageInfo(source, type, nullptr, true); if (status != FXCODEC_STATUS_FRAME_READY) diff --git a/xfa/fxfa/app/xfa_ffwidget.cpp b/xfa/fxfa/app/xfa_ffwidget.cpp index 1ffd712a3a..9995fd11b2 100644 --- a/xfa/fxfa/app/xfa_ffwidget.cpp +++ b/xfa/fxfa/app/xfa_ffwidget.cpp @@ -1128,7 +1128,7 @@ CFX_DIBitmap* XFA_LoadImageFromBuffer( CFX_DIBAttribute dibAttr; CFX_DIBitmap* pBitmap = nullptr; - CCodec_ProgressiveDecoder* pProgressiveDecoder = + std::unique_ptr<CCodec_ProgressiveDecoder> pProgressiveDecoder = pCodecMgr->CreateProgressiveDecoder(); pProgressiveDecoder->LoadImageInfo(pImageFileRead, type, &dibAttr, false); switch (dibAttr.m_wDPIUnit) { @@ -1164,9 +1164,9 @@ CFX_DIBitmap* XFA_LoadImageFromBuffer( pProgressiveDecoder->ContinueDecode(); } } - delete pProgressiveDecoder; return pBitmap; } + void XFA_RectWidthoutMargin(CFX_RectF& rt, const CXFA_Margin& mg, bool bUI) { if (!mg) { return; |