summaryrefslogtreecommitdiff
path: root/core/fxcodec
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-10-10 17:00:30 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-10 17:00:30 +0000
commit73ae71f2f63ab8a3084cb0e691e661b071dc1a92 (patch)
treecf829c475c6af61b06a1a32075d0fac3bcfd97df /core/fxcodec
parent7eccfb6577d2bb4a7166d67e2dfd7b21fcabb2fb (diff)
downloadpdfium-73ae71f2f63ab8a3084cb0e691e661b071dc1a92.tar.xz
Use std::vector in ccodec_faxmodule.cpp
Rework a memset while we're at it. Change-Id: Id62ae3a8c1f64a93417915e23fcd93935ae95c73 Reviewed-on: https://pdfium-review.googlesource.com/c/43651 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcodec')
-rw-r--r--core/fxcodec/codec/ccodec_faxmodule.cpp39
1 files changed, 21 insertions, 18 deletions
diff --git a/core/fxcodec/codec/ccodec_faxmodule.cpp b/core/fxcodec/codec/ccodec_faxmodule.cpp
index fe9f6a9e2e..905f6472d2 100644
--- a/core/fxcodec/codec/ccodec_faxmodule.cpp
+++ b/core/fxcodec/codec/ccodec_faxmodule.cpp
@@ -7,6 +7,8 @@
#include "core/fxcodec/codec/ccodec_faxmodule.h"
#include <algorithm>
+#include <iterator>
+#include <limits>
#include <memory>
#include <vector>
@@ -14,6 +16,7 @@
#include "core/fxcodec/codec/codec_int.h"
#include "core/fxcrt/cfx_binarybuf.h"
#include "core/fxcrt/fx_memory.h"
+#include "third_party/base/logging.h"
#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
@@ -662,7 +665,7 @@ class CCodec_FaxEncoder {
CFX_BinaryBuf m_DestBuf;
std::vector<uint8_t> m_RefLine;
- uint8_t* m_pLineBuf;
+ std::vector<uint8_t> m_LineBuf;
int m_DestBitpos;
const int m_Cols;
const int m_Rows;
@@ -675,20 +678,20 @@ CCodec_FaxEncoder::CCodec_FaxEncoder(const uint8_t* src_buf,
int height,
int pitch)
: m_Cols(width), m_Rows(height), m_Pitch(pitch), m_pSrcBuf(src_buf) {
- m_RefLine.resize(m_Pitch);
- memset(m_RefLine.data(), 0xff, m_Pitch);
- m_pLineBuf = FX_Alloc2D(uint8_t, m_Pitch, 8);
+ CHECK(pitch > 0);
+ CHECK(pitch < std::numeric_limits<int>::max() / 8);
+ m_RefLine.resize(pitch);
+ std::fill(std::begin(m_RefLine), std::end(m_RefLine), 0xff);
+ m_LineBuf.resize(8 * m_Pitch);
m_DestBuf.SetAllocStep(10240);
}
-CCodec_FaxEncoder::~CCodec_FaxEncoder() {
- FX_Free(m_pLineBuf);
-}
+CCodec_FaxEncoder::~CCodec_FaxEncoder() = default;
void CCodec_FaxEncoder::AddBitStream(int data, int bitlen) {
for (int i = bitlen - 1; i >= 0; --i, ++m_DestBitpos) {
if (data & (1 << i))
- m_pLineBuf[m_DestBitpos / 8] |= 1 << (7 - m_DestBitpos % 8);
+ m_LineBuf[m_DestBitpos / 8] |= 1 << (7 - m_DestBitpos % 8);
}
}
@@ -719,28 +722,28 @@ void CCodec_FaxEncoder::FaxEncode2DLine(const uint8_t* src_buf) {
FaxG4FindB1B2(m_RefLine, m_Cols, a0, a0color, &b1, &b2);
if (b2 < a1) {
m_DestBitpos += 3;
- m_pLineBuf[m_DestBitpos / 8] |= 1 << (7 - m_DestBitpos % 8);
+ m_LineBuf[m_DestBitpos / 8] |= 1 << (7 - m_DestBitpos % 8);
++m_DestBitpos;
a0 = b2;
} else if (a1 - b1 <= 3 && b1 - a1 <= 3) {
int delta = a1 - b1;
switch (delta) {
case 0:
- m_pLineBuf[m_DestBitpos / 8] |= 1 << (7 - m_DestBitpos % 8);
+ m_LineBuf[m_DestBitpos / 8] |= 1 << (7 - m_DestBitpos % 8);
break;
case 1:
case 2:
case 3:
m_DestBitpos += delta == 1 ? 1 : delta + 2;
- m_pLineBuf[m_DestBitpos / 8] |= 1 << (7 - m_DestBitpos % 8);
+ m_LineBuf[m_DestBitpos / 8] |= 1 << (7 - m_DestBitpos % 8);
++m_DestBitpos;
- m_pLineBuf[m_DestBitpos / 8] |= 1 << (7 - m_DestBitpos % 8);
+ m_LineBuf[m_DestBitpos / 8] |= 1 << (7 - m_DestBitpos % 8);
break;
case -1:
case -2:
case -3:
m_DestBitpos += delta == -1 ? 1 : -delta + 2;
- m_pLineBuf[m_DestBitpos / 8] |= 1 << (7 - m_DestBitpos % 8);
+ m_LineBuf[m_DestBitpos / 8] |= 1 << (7 - m_DestBitpos % 8);
++m_DestBitpos;
break;
}
@@ -751,7 +754,7 @@ void CCodec_FaxEncoder::FaxEncode2DLine(const uint8_t* src_buf) {
int a2 = FindBit(src_buf, m_Cols, a1 + 1, a0color);
++m_DestBitpos;
++m_DestBitpos;
- m_pLineBuf[m_DestBitpos / 8] |= 1 << (7 - m_DestBitpos % 8);
+ m_LineBuf[m_DestBitpos / 8] |= 1 << (7 - m_DestBitpos % 8);
++m_DestBitpos;
if (a0 < 0)
a0 = 0;
@@ -771,11 +774,11 @@ void CCodec_FaxEncoder::Encode(
uint8_t last_byte = 0;
for (int i = 0; i < m_Rows; ++i) {
const uint8_t* scan_line = m_pSrcBuf + i * m_Pitch;
- memset(m_pLineBuf, 0, m_Pitch * 8);
- m_pLineBuf[0] = last_byte;
+ std::fill(std::begin(m_LineBuf), std::end(m_LineBuf), 0);
+ m_LineBuf[0] = last_byte;
FaxEncode2DLine(scan_line);
- m_DestBuf.AppendBlock(m_pLineBuf, m_DestBitpos / 8);
- last_byte = m_pLineBuf[m_DestBitpos / 8];
+ m_DestBuf.AppendBlock(m_LineBuf.data(), m_DestBitpos / 8);
+ last_byte = m_LineBuf[m_DestBitpos / 8];
m_DestBitpos %= 8;
memcpy(m_RefLine.data(), scan_line, m_Pitch);
}