diff options
author | Nicolas Pena <npm@chromium.org> | 2017-06-19 11:36:42 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-06-19 16:19:54 +0000 |
commit | bc29701214bf96bfacbef04b345bee76fd7bce84 (patch) | |
tree | caa404141f9e13200b380294f9ba5efccc149862 /core/fxcodec/codec | |
parent | c533f4b7390afc3b372c0184d274053039ac264d (diff) | |
download | pdfium-bc29701214bf96bfacbef04b345bee76fd7bce84.tar.xz |
Make out_row_buffer an std::vector
The out_row_buffer of BMPDecompressor is made a vector. This forces the
class to have constructor/destructor. Some other members were changed
to be of size_t instead of int32_t.
Change-Id: I3f70b0322dcee2ddf9a00da7962b43f3415ba545
Reviewed-on: https://pdfium-review.googlesource.com/6691
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcodec/codec')
-rw-r--r-- | core/fxcodec/codec/ccodec_bmpmodule.cpp | 49 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_bmpmodule.h | 4 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_progressivedecoder.h | 3 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_progress.cpp | 12 |
4 files changed, 34 insertions, 34 deletions
diff --git a/core/fxcodec/codec/ccodec_bmpmodule.cpp b/core/fxcodec/codec/ccodec_bmpmodule.cpp index 9186553c7b..370919634a 100644 --- a/core/fxcodec/codec/ccodec_bmpmodule.cpp +++ b/core/fxcodec/codec/ccodec_bmpmodule.cpp @@ -13,16 +13,13 @@ #include "core/fxge/fx_dib.h" #include "third_party/base/ptr_util.h" -CBmpContext::CBmpContext(BMPDecompressor* pBmp, - CCodec_BmpModule* pModule, +CBmpContext::CBmpContext(CCodec_BmpModule* pModule, CCodec_BmpModule::Delegate* pDelegate) - : m_pBmp(pBmp), m_pModule(pModule), m_pDelegate(pDelegate) { + : m_pModule(pModule), m_pDelegate(pDelegate) { memset(m_szLastError, 0, sizeof(m_szLastError)); } -CBmpContext::~CBmpContext() { - bmp_destroy_decompress(&m_pBmp); -} +CBmpContext::~CBmpContext() {} CCodec_BmpModule::CCodec_BmpModule() {} @@ -30,13 +27,9 @@ CCodec_BmpModule::~CCodec_BmpModule() {} std::unique_ptr<CCodec_BmpModule::Context> CCodec_BmpModule::Start( Delegate* pDelegate) { - 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; + auto p = pdfium::MakeUnique<CBmpContext>(this, pDelegate); + p->m_Bmp.context_ptr = p.get(); + p->m_Bmp.err_ptr = p->m_szLastError; return p; } @@ -49,45 +42,45 @@ 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_Bmp.jmpbuf)) return 0; - int32_t ret = ctx->m_pBmp->ReadHeader(); + int32_t ret = ctx->m_Bmp.ReadHeader(); if (ret != 1) return ret; - *width = ctx->m_pBmp->width; - *height = ctx->m_pBmp->height; - *tb_flag = ctx->m_pBmp->imgTB_flag; - *components = ctx->m_pBmp->components; - *pal_num = ctx->m_pBmp->pal_num; - *pal_pp = ctx->m_pBmp->pal_ptr; + *width = ctx->m_Bmp.width; + *height = ctx->m_Bmp.height; + *tb_flag = false; + *components = ctx->m_Bmp.components; + *pal_num = ctx->m_Bmp.pal_num; + *pal_pp = ctx->m_Bmp.pal_ptr; if (pAttribute) { pAttribute->m_wDPIUnit = FXCODEC_RESUNIT_METER; - pAttribute->m_nXDPI = ctx->m_pBmp->dpi_x; - pAttribute->m_nYDPI = ctx->m_pBmp->dpi_y; - pAttribute->m_nBmpCompressType = ctx->m_pBmp->compress_flag; + pAttribute->m_nXDPI = ctx->m_Bmp.dpi_x; + pAttribute->m_nYDPI = ctx->m_Bmp.dpi_y; + pAttribute->m_nBmpCompressType = ctx->m_Bmp.compress_flag; } return 1; } int32_t CCodec_BmpModule::LoadImage(Context* pContext) { auto* ctx = static_cast<CBmpContext*>(pContext); - if (setjmp(ctx->m_pBmp->jmpbuf)) + if (setjmp(ctx->m_Bmp.jmpbuf)) return 0; - return ctx->m_pBmp->DecodeImage(); + return ctx->m_Bmp.DecodeImage(); } uint32_t CCodec_BmpModule::GetAvailInput(Context* pContext, uint8_t** avail_buf_ptr) { auto* ctx = static_cast<CBmpContext*>(pContext); - return ctx->m_pBmp->GetAvailInput(avail_buf_ptr); + return ctx->m_Bmp.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); - ctx->m_pBmp->SetInputBuffer(const_cast<uint8_t*>(src_buf), src_size); + ctx->m_Bmp.SetInputBuffer(const_cast<uint8_t*>(src_buf), src_size); } diff --git a/core/fxcodec/codec/ccodec_bmpmodule.h b/core/fxcodec/codec/ccodec_bmpmodule.h index 10bc6b714e..4009150c59 100644 --- a/core/fxcodec/codec/ccodec_bmpmodule.h +++ b/core/fxcodec/codec/ccodec_bmpmodule.h @@ -8,6 +8,7 @@ #define CORE_FXCODEC_CODEC_CCODEC_BMPMODULE_H_ #include <memory> +#include <vector> #include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_system.h" @@ -24,7 +25,8 @@ class CCodec_BmpModule { class Delegate { public: virtual bool BmpInputImagePositionBuf(uint32_t rcd_pos) = 0; - virtual void BmpReadScanline(int32_t row_num, uint8_t* row_buf) = 0; + virtual void BmpReadScanline(uint32_t row_num, + const std::vector<uint8_t>& row_buf) = 0; }; CCodec_BmpModule(); diff --git a/core/fxcodec/codec/ccodec_progressivedecoder.h b/core/fxcodec/codec/ccodec_progressivedecoder.h index 50c5405e9b..4417e47824 100644 --- a/core/fxcodec/codec/ccodec_progressivedecoder.h +++ b/core/fxcodec/codec/ccodec_progressivedecoder.h @@ -150,7 +150,8 @@ class CCodec_ProgressiveDecoder : public CCodec_BmpModule::Delegate, // CCodec_BmpModule::Delegate bool BmpInputImagePositionBuf(uint32_t rcd_pos) override; - void BmpReadScanline(int32_t row_num, uint8_t* row_buf) override; + void BmpReadScanline(uint32_t row_num, + const std::vector<uint8_t>& row_buf) override; private: bool BmpReadMoreData(CCodec_BmpModule* pBmpModule, diff --git a/core/fxcodec/codec/fx_codec_progress.cpp b/core/fxcodec/codec/fx_codec_progress.cpp index 5ec7d661f5..3c377771ea 100644 --- a/core/fxcodec/codec/fx_codec_progress.cpp +++ b/core/fxcodec/codec/fx_codec_progress.cpp @@ -8,6 +8,7 @@ #include <algorithm> #include <memory> +#include <vector> #include "core/fxcodec/fx_codec.h" #include "core/fxge/dib/cfx_dibitmap.h" @@ -878,18 +879,21 @@ bool CCodec_ProgressiveDecoder::BmpInputImagePositionBuf(uint32_t rcd_pos) { return BmpReadMoreData(m_pCodecMgr->GetBmpModule(), error_status); } -void CCodec_ProgressiveDecoder::BmpReadScanline(int32_t row_num, - uint8_t* row_buf) { +void CCodec_ProgressiveDecoder::BmpReadScanline( + uint32_t row_num, + const std::vector<uint8_t>& row_buf) { CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = m_pDeviceBitmap; ASSERT(pDIBitmap); - memcpy(m_pDecodeBuf, row_buf, m_ScanlineSize); + std::copy(row_buf.begin(), row_buf.begin() + m_ScanlineSize, m_pDecodeBuf); 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) + if ((src_top >= 0 && row_num < static_cast<uint32_t>(src_top)) || + src_bottom < 0 || row_num >= static_cast<uint32_t>(src_bottom)) { return; + } double scale_y = (double)des_hei / (double)src_hei; int src_row = row_num - src_top; |