summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2017-06-19 11:36:42 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-06-19 16:19:54 +0000
commitbc29701214bf96bfacbef04b345bee76fd7bce84 (patch)
treecaa404141f9e13200b380294f9ba5efccc149862 /core
parentc533f4b7390afc3b372c0184d274053039ac264d (diff)
downloadpdfium-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')
-rw-r--r--core/fxcodec/codec/ccodec_bmpmodule.cpp49
-rw-r--r--core/fxcodec/codec/ccodec_bmpmodule.h4
-rw-r--r--core/fxcodec/codec/ccodec_progressivedecoder.h3
-rw-r--r--core/fxcodec/codec/fx_codec_progress.cpp12
-rw-r--r--core/fxcodec/lbmp/fx_bmp.cpp180
-rw-r--r--core/fxcodec/lbmp/fx_bmp.h31
6 files changed, 136 insertions, 143 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;
diff --git a/core/fxcodec/lbmp/fx_bmp.cpp b/core/fxcodec/lbmp/fx_bmp.cpp
index 1febce63eb..62ae681b2a 100644
--- a/core/fxcodec/lbmp/fx_bmp.cpp
+++ b/core/fxcodec/lbmp/fx_bmp.cpp
@@ -30,24 +30,40 @@ uint16_t GetWord_LSBFirst(uint8_t* p) {
return p[0] | (p[1] << 8);
}
-BMPDecompressor* bmp_create_decompress() {
- BMPDecompressor* bmp_ptr = FX_Alloc(BMPDecompressor, 1);
- memset(bmp_ptr, 0, sizeof(BMPDecompressor));
- bmp_ptr->decode_status = BMP_D_STATUS_HEADER;
- bmp_ptr->bmp_header_ptr = FX_Alloc(BmpFileHeader, 1);
- return bmp_ptr;
-}
-
-void bmp_destroy_decompress(BMPDecompressor** bmp_ptr_ptr) {
- if (!bmp_ptr_ptr || !*bmp_ptr_ptr)
- return;
-
- BMPDecompressor* bmp_ptr = *bmp_ptr_ptr;
- *bmp_ptr_ptr = nullptr;
- FX_Free(bmp_ptr->out_row_buffer);
- FX_Free(bmp_ptr->pal_ptr);
- FX_Free(bmp_ptr->bmp_header_ptr);
- FX_Free(bmp_ptr);
+BMPDecompressor::BMPDecompressor()
+ : err_ptr(nullptr),
+ context_ptr(nullptr),
+ bmp_header_ptr(FX_Alloc(BmpFileHeader, 1)),
+ bmp_infoheader_ptr(nullptr),
+ width(0),
+ height(0),
+ compress_flag(0),
+ components(0),
+ src_row_bytes(0),
+ out_row_bytes(0),
+ bitCounts(0),
+ color_used(0),
+ pal_num(0),
+ pal_type(0),
+ pal_ptr(nullptr),
+ data_size(0),
+ img_data_offset(0),
+ img_ifh_size(0),
+ row_num(0),
+ col_num(0),
+ dpi_x(0),
+ dpi_y(0),
+ mask_red(0),
+ mask_green(0),
+ mask_blue(0),
+ next_in(nullptr),
+ avail_in(0),
+ skip_size(0),
+ decode_status(BMP_D_STATUS_HEADER) {}
+
+BMPDecompressor::~BMPDecompressor() {
+ FX_Free(pal_ptr);
+ FX_Free(bmp_header_ptr);
}
void BMPDecompressor::Error(const char* err_msg) {
@@ -55,7 +71,8 @@ void BMPDecompressor::Error(const char* err_msg) {
longjmp(jmpbuf, 1);
}
-void BMPDecompressor::ReadScanline(int32_t row_num, uint8_t* row_buf) {
+void BMPDecompressor::ReadScanline(uint32_t row_num,
+ const std::vector<uint8_t>& row_buf) {
auto* p = reinterpret_cast<CBmpContext*>(context_ptr);
p->m_pDelegate->BmpReadScanline(row_num, row_buf);
}
@@ -108,7 +125,6 @@ int32_t BMPDecompressor::ReadHeader() {
bitCounts = GetWord_LSBFirst(
reinterpret_cast<uint8_t*>(&bmp_core_header_ptr->bcBitCount));
compress_flag = BMP_RGB;
- imgTB_flag = false;
} break;
case kBmpInfoHeaderSize: {
BmpInfoHeaderPtr bmp_info_header_ptr = nullptr;
@@ -128,14 +144,6 @@ int32_t BMPDecompressor::ReadHeader() {
(uint8_t*)&bmp_info_header_ptr->biXPelsPerMeter);
dpi_y = (int32_t)GetDWord_LSBFirst(
(uint8_t*)&bmp_info_header_ptr->biYPelsPerMeter);
- if (height < 0) {
- if (height == std::numeric_limits<int>::min()) {
- Error("Unsupported height");
- NOTREACHED();
- }
- height = -height;
- imgTB_flag = true;
- }
} break;
default: {
if (img_ifh_size >
@@ -159,23 +167,14 @@ int32_t BMPDecompressor::ReadHeader() {
(uint8_t*)&bmp_info_header_ptr->biXPelsPerMeter);
dpi_y = GetDWord_LSBFirst(
(uint8_t*)&bmp_info_header_ptr->biYPelsPerMeter);
- if (height < 0) {
- if (height == std::numeric_limits<int>::min()) {
- Error("Unsupported height");
- NOTREACHED();
- }
- height = -height;
- imgTB_flag = true;
- }
- if (compress_flag == BMP_RGB && biPlanes == 1 && color_used == 0) {
+ if (compress_flag == BMP_RGB && biPlanes == 1 && color_used == 0)
break;
- }
}
Error("Unsupported Bmp File");
NOTREACHED();
}
}
- if (width <= 0 || width > BMP_MAX_WIDTH || compress_flag > BMP_BITFIELDS) {
+ if (width > BMP_MAX_WIDTH || compress_flag > BMP_BITFIELDS) {
Error("The Bmp File Is Corrupt");
NOTREACHED();
}
@@ -214,16 +213,14 @@ int32_t BMPDecompressor::ReadHeader() {
components = 4;
break;
}
- FX_Free(out_row_buffer);
- out_row_buffer = nullptr;
+ out_row_buffer.clear();
if (out_row_bytes <= 0) {
Error("The Bmp File Is Corrupt");
NOTREACHED();
}
- out_row_buffer = FX_Alloc(uint8_t, out_row_bytes);
- memset(out_row_buffer, 0, out_row_bytes);
+ out_row_buffer.resize(out_row_bytes);
SaveDecodingStatus(BMP_D_STATUS_PAL);
}
if (decode_status == BMP_D_STATUS_PAL) {
@@ -346,20 +343,22 @@ bool BMPDecompressor::ValidateColorIndex(uint8_t val) {
int32_t BMPDecompressor::DecodeRGB() {
uint8_t* des_buf = nullptr;
while (row_num < height) {
- uint8_t* row_buf = out_row_buffer;
+ size_t idx = 0;
if (!ReadData(&des_buf, src_row_bytes))
return 2;
SaveDecodingStatus(BMP_D_STATUS_DATA);
switch (bitCounts) {
case 1: {
- for (int32_t col = 0; col < width; ++col)
- *row_buf++ = des_buf[col >> 3] & (0x80 >> (col % 8)) ? 0x01 : 0x00;
+ for (uint32_t col = 0; col < width; ++col)
+ out_row_buffer[idx++] =
+ des_buf[col >> 3] & (0x80 >> (col % 8)) ? 0x01 : 0x00;
} break;
case 4: {
- for (int32_t col = 0; col < width; ++col) {
- *row_buf++ = (col & 0x01) ? (des_buf[col >> 1] & 0x0F)
- : ((des_buf[col >> 1] & 0xF0) >> 4);
+ for (uint32_t col = 0; col < width; ++col) {
+ out_row_buffer[idx++] = (col & 0x01)
+ ? (des_buf[col >> 1] & 0x0F)
+ : ((des_buf[col >> 1] & 0xF0) >> 4);
}
} break;
case 16: {
@@ -382,26 +381,28 @@ int32_t BMPDecompressor::DecodeRGB() {
blue_bits = 8 - blue_bits;
green_bits -= 8;
red_bits -= 8;
- for (int32_t col = 0; col < width; ++col) {
+ for (uint32_t col = 0; col < width; ++col) {
*buf = GetWord_LSBFirst((uint8_t*)buf);
- *row_buf++ = static_cast<uint8_t>((*buf & mask_blue) << blue_bits);
- *row_buf++ = static_cast<uint8_t>((*buf & mask_green) >> green_bits);
- *row_buf++ = static_cast<uint8_t>((*buf++ & mask_red) >> red_bits);
+ out_row_buffer[idx++] =
+ static_cast<uint8_t>((*buf & mask_blue) << blue_bits);
+ out_row_buffer[idx++] =
+ static_cast<uint8_t>((*buf & mask_green) >> green_bits);
+ out_row_buffer[idx++] =
+ static_cast<uint8_t>((*buf++ & mask_red) >> red_bits);
}
} break;
case 8:
case 24:
case 32:
- memcpy(out_row_buffer, des_buf, src_row_bytes);
- row_buf += src_row_bytes;
+ std::copy(des_buf, des_buf + src_row_bytes, out_row_buffer.begin());
+ idx += src_row_bytes;
break;
}
- for (uint8_t* buf = out_row_buffer; buf < row_buf; ++buf) {
- if (!ValidateColorIndex(*buf))
+ for (uint8_t byte : out_row_buffer) {
+ if (!ValidateColorIndex(byte))
return 0;
}
- ReadScanline(imgTB_flag ? row_num++ : (height - 1 - row_num++),
- out_row_buffer);
+ ReadScanline(height - 1 - row_num++, out_row_buffer);
}
SaveDecodingStatus(BMP_D_STATUS_TAIL);
return 1;
@@ -429,17 +430,15 @@ int32_t BMPDecompressor::DecodeRLE8() {
Error("The Bmp File Is Corrupt");
NOTREACHED();
}
- ReadScanline(imgTB_flag ? row_num++ : (height - 1 - row_num++),
- out_row_buffer);
+ ReadScanline(height - 1 - row_num++, out_row_buffer);
col_num = 0;
- memset(out_row_buffer, 0, out_row_bytes);
+ std::fill(out_row_buffer.begin(), out_row_buffer.end(), 0);
SaveDecodingStatus(BMP_D_STATUS_DATA);
continue;
}
case RLE_EOI: {
if (row_num < height) {
- ReadScanline(imgTB_flag ? row_num++ : (height - 1 - row_num++),
- out_row_buffer);
+ ReadScanline(height - 1 - row_num++, out_row_buffer);
}
SaveDecodingStatus(BMP_D_STATUS_TAIL);
return 1;
@@ -450,16 +449,15 @@ int32_t BMPDecompressor::DecodeRLE8() {
skip_size = skip_size_org;
return 2;
}
- col_num += (int32_t)delta_ptr[0];
- int32_t bmp_row_num_next = row_num + (int32_t)delta_ptr[1];
+ col_num += delta_ptr[0];
+ size_t bmp_row_num_next = row_num + delta_ptr[1];
if (col_num >= out_row_bytes || bmp_row_num_next >= height) {
Error("The Bmp File Is Corrupt Or Not Supported");
NOTREACHED();
}
while (row_num < bmp_row_num_next) {
- memset(out_row_buffer, 0, out_row_bytes);
- ReadScanline(imgTB_flag ? row_num++ : (height - 1 - row_num++),
- out_row_buffer);
+ std::fill(out_row_buffer.begin(), out_row_buffer.end(), 0);
+ ReadScanline(height - 1 - row_num++, out_row_buffer);
}
} break;
default: {
@@ -475,13 +473,13 @@ int32_t BMPDecompressor::DecodeRLE8() {
skip_size = skip_size_org;
return 2;
}
- uint8_t* first_buf = out_row_buffer + col_num;
- memcpy(out_row_buffer + col_num, second_byte_ptr, *first_byte_ptr);
- for (size_t i = 0; i < *first_byte_ptr; ++i) {
- if (!ValidateColorIndex(first_buf[i]))
+ std::copy(second_byte_ptr, second_byte_ptr + *first_byte_ptr,
+ out_row_buffer.begin() + col_num);
+ for (size_t i = col_num; i < col_num + *first_byte_ptr; ++i) {
+ if (!ValidateColorIndex(out_row_buffer[i]))
return 0;
}
- col_num += (int32_t)(*first_byte_ptr);
+ col_num += *first_byte_ptr;
}
}
} break;
@@ -495,13 +493,12 @@ int32_t BMPDecompressor::DecodeRLE8() {
skip_size = skip_size_org;
return 2;
}
- uint8_t* first_buf = out_row_buffer + col_num;
- memset(out_row_buffer + col_num, *second_byte_ptr, *first_byte_ptr);
- for (size_t i = 0; i < *first_byte_ptr; ++i) {
- if (!ValidateColorIndex(first_buf[i]))
- return 0;
- }
- col_num += (int32_t)(*first_byte_ptr);
+ std::fill(out_row_buffer.begin() + col_num,
+ out_row_buffer.begin() + col_num + *first_byte_ptr,
+ *second_byte_ptr);
+ if (!ValidateColorIndex(out_row_buffer[col_num]))
+ return 0;
+ col_num += *first_byte_ptr;
}
}
}
@@ -531,17 +528,15 @@ int32_t BMPDecompressor::DecodeRLE4() {
Error("The Bmp File Is Corrupt");
NOTREACHED();
}
- ReadScanline(imgTB_flag ? row_num++ : (height - 1 - row_num++),
- out_row_buffer);
+ ReadScanline(height - 1 - row_num++, out_row_buffer);
col_num = 0;
- memset(out_row_buffer, 0, out_row_bytes);
+ std::fill(out_row_buffer.begin(), out_row_buffer.end(), 0);
SaveDecodingStatus(BMP_D_STATUS_DATA);
continue;
}
case RLE_EOI: {
if (row_num < height) {
- ReadScanline(imgTB_flag ? row_num++ : (height - 1 - row_num++),
- out_row_buffer);
+ ReadScanline(height - 1 - row_num++, out_row_buffer);
}
SaveDecodingStatus(BMP_D_STATUS_TAIL);
return 1;
@@ -552,16 +547,15 @@ int32_t BMPDecompressor::DecodeRLE4() {
skip_size = skip_size_org;
return 2;
}
- col_num += (int32_t)delta_ptr[0];
- int32_t bmp_row_num_next = row_num + (int32_t)delta_ptr[1];
+ col_num += delta_ptr[0];
+ size_t bmp_row_num_next = row_num + delta_ptr[1];
if (col_num >= out_row_bytes || bmp_row_num_next >= height) {
Error("The Bmp File Is Corrupt Or Not Supported");
NOTREACHED();
}
while (row_num < bmp_row_num_next) {
- memset(out_row_buffer, 0, out_row_bytes);
- ReadScanline(imgTB_flag ? row_num++ : (height - 1 - row_num++),
- out_row_buffer);
+ std::fill(out_row_buffer.begin(), out_row_buffer.end(), 0);
+ ReadScanline(height - 1 - row_num++, out_row_buffer);
}
} break;
default: {
@@ -588,7 +582,7 @@ int32_t BMPDecompressor::DecodeRLE4() {
if (!ValidateColorIndex(color))
return 0;
- *(out_row_buffer + col_num++) = color;
+ out_row_buffer[col_num++] = color;
}
}
}
@@ -617,7 +611,7 @@ int32_t BMPDecompressor::DecodeRLE4() {
i & 0x01 ? (second_byte & 0x0F) : (second_byte & 0xF0) >> 4;
if (!ValidateColorIndex(second_byte))
return 0;
- *(out_row_buffer + col_num++) = second_byte;
+ out_row_buffer[col_num++] = second_byte;
}
}
}
diff --git a/core/fxcodec/lbmp/fx_bmp.h b/core/fxcodec/lbmp/fx_bmp.h
index 2612d7eb8c..bf5e94fc23 100644
--- a/core/fxcodec/lbmp/fx_bmp.h
+++ b/core/fxcodec/lbmp/fx_bmp.h
@@ -8,6 +8,7 @@
#define CORE_FXCODEC_LBMP_FX_BMP_H_
#include <setjmp.h>
+#include <vector>
#include "core/fxcodec/codec/ccodec_bmpmodule.h"
#include "core/fxcrt/fx_basic.h"
@@ -68,6 +69,9 @@ typedef struct tagBmpInfoHeader {
class BMPDecompressor {
public:
+ BMPDecompressor();
+ ~BMPDecompressor();
+
void Error(const char* err_msg);
int32_t DecodeImage();
int32_t ReadHeader();
@@ -81,24 +85,24 @@ class BMPDecompressor {
BmpFileHeaderPtr bmp_header_ptr;
BmpInfoHeaderPtr bmp_infoheader_ptr;
- int32_t width;
- int32_t height;
+ std::vector<uint8_t> out_row_buffer;
+
+ uint32_t width;
+ uint32_t height;
uint32_t compress_flag;
int32_t components;
- int32_t src_row_bytes;
- int32_t out_row_bytes;
- uint8_t* out_row_buffer;
+ size_t src_row_bytes;
+ size_t out_row_bytes;
uint16_t bitCounts;
uint32_t color_used;
- bool imgTB_flag;
int32_t pal_num;
int32_t pal_type;
uint32_t* pal_ptr;
uint32_t data_size;
uint32_t img_data_offset;
uint32_t img_ifh_size;
- int32_t row_num;
- int32_t col_num;
+ size_t row_num;
+ size_t col_num;
int32_t dpi_x;
int32_t dpi_y;
uint32_t mask_red;
@@ -112,7 +116,7 @@ class BMPDecompressor {
private:
bool GetDataPosition(uint32_t cur_pos);
- void ReadScanline(int32_t row_num, uint8_t* row_buf);
+ void ReadScanline(uint32_t row_num, const std::vector<uint8_t>& row_buf);
int32_t DecodeRGB();
int32_t DecodeRLE8();
int32_t DecodeRLE4();
@@ -122,17 +126,12 @@ class BMPDecompressor {
bool ValidateFlag() const;
};
-BMPDecompressor* bmp_create_decompress();
-void bmp_destroy_decompress(BMPDecompressor** bmp_ptr_ptr);
-
class CBmpContext : public CCodec_BmpModule::Context {
public:
- CBmpContext(BMPDecompressor* pBmp,
- CCodec_BmpModule* pModule,
- CCodec_BmpModule::Delegate* pDelegate);
+ CBmpContext(CCodec_BmpModule* pModule, CCodec_BmpModule::Delegate* pDelegate);
~CBmpContext() override;
- BMPDecompressor* m_pBmp;
+ BMPDecompressor m_Bmp;
CFX_UnownedPtr<CCodec_BmpModule> const m_pModule;
CFX_UnownedPtr<CCodec_BmpModule::Delegate> const m_pDelegate;
char m_szLastError[256];