summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-10-09 19:12:15 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-09 19:12:15 +0000
commitf9718052794c4669a4f99d8f798806c9730a9e36 (patch)
tree06267512673ee39386eda85058ccd970eff95cd3
parent1fc902fef97883f91a1ccf5bb3333ef11ed3b8fd (diff)
downloadpdfium-f9718052794c4669a4f99d8f798806c9730a9e36.tar.xz
Switch to std::vector in ccodec_flatemodule.cpp.
We may choose to clean up the memcpy's in a subsequent cl. Change-Id: I038ae67504b6b3b9c3dbd36e9ddf2600392c2d94 Reviewed-on: https://pdfium-review.googlesource.com/c/43650 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
-rw-r--r--core/fxcodec/codec/ccodec_flatemodule.cpp44
1 files changed, 21 insertions, 23 deletions
diff --git a/core/fxcodec/codec/ccodec_flatemodule.cpp b/core/fxcodec/codec/ccodec_flatemodule.cpp
index 0dc1822300..f35b9581be 100644
--- a/core/fxcodec/codec/ccodec_flatemodule.cpp
+++ b/core/fxcodec/codec/ccodec_flatemodule.cpp
@@ -652,9 +652,9 @@ class CCodec_FlatePredictorScanlineDecoder final
int m_Columns = 0;
uint32_t m_PredictPitch = 0;
size_t m_LeftOver = 0;
- uint8_t* m_pLastLine = nullptr;
- uint8_t* m_pPredictBuffer = nullptr;
- uint8_t* m_pPredictRaw = nullptr;
+ std::vector<uint8_t> m_LastLine;
+ std::vector<uint8_t> m_PredictBuffer;
+ std::vector<uint8_t> m_PredictRaw;
};
CCodec_FlatePredictorScanlineDecoder::CCodec_FlatePredictorScanlineDecoder(
@@ -680,16 +680,13 @@ CCodec_FlatePredictorScanlineDecoder::CCodec_FlatePredictorScanlineDecoder(
m_Columns = Columns;
m_PredictPitch =
CalculatePitch8(m_BitsPerComponent, m_Colors, m_Columns).ValueOrDie();
- m_pLastLine = FX_Alloc(uint8_t, m_PredictPitch);
- m_pPredictBuffer = FX_Alloc(uint8_t, m_PredictPitch);
- m_pPredictRaw = FX_Alloc(uint8_t, m_PredictPitch + 1);
+ m_LastLine.resize(m_PredictPitch);
+ m_PredictBuffer.resize(m_PredictPitch);
+ m_PredictRaw.resize(m_PredictPitch + 1);
}
-CCodec_FlatePredictorScanlineDecoder::~CCodec_FlatePredictorScanlineDecoder() {
- FX_Free(m_pLastLine);
- FX_Free(m_pPredictBuffer);
- FX_Free(m_pPredictRaw);
-}
+CCodec_FlatePredictorScanlineDecoder::~CCodec_FlatePredictorScanlineDecoder() =
+ default;
bool CCodec_FlatePredictorScanlineDecoder::v_Rewind() {
if (!CCodec_FlateScanlineDecoder::v_Rewind())
@@ -710,10 +707,10 @@ uint8_t* CCodec_FlatePredictorScanlineDecoder::v_GetNextLine() {
void CCodec_FlatePredictorScanlineDecoder::GetNextLineWithPredictedPitch() {
switch (m_Predictor) {
case PredictorType::kPng:
- FlateOutput(m_pFlate.get(), m_pPredictRaw, m_PredictPitch + 1);
- PNG_PredictLine(m_pScanline.get(), m_pPredictRaw, m_pLastLine,
+ FlateOutput(m_pFlate.get(), m_PredictRaw.data(), m_PredictPitch + 1);
+ PNG_PredictLine(m_pScanline.get(), m_PredictRaw.data(), m_LastLine.data(),
m_BitsPerComponent, m_Colors, m_Columns);
- memcpy(m_pLastLine, m_pScanline.get(), m_PredictPitch);
+ memcpy(m_LastLine.data(), m_pScanline.get(), m_PredictPitch);
break;
case PredictorType::kFlate:
FlateOutput(m_pFlate.get(), m_pScanline.get(), m_Pitch);
@@ -730,7 +727,7 @@ void CCodec_FlatePredictorScanlineDecoder::GetNextLineWithoutPredictedPitch() {
size_t bytes_to_go = m_Pitch;
size_t read_leftover = m_LeftOver > bytes_to_go ? bytes_to_go : m_LeftOver;
if (read_leftover) {
- memcpy(m_pScanline.get(), m_pPredictBuffer + m_PredictPitch - m_LeftOver,
+ memcpy(m_pScanline.get(), &m_PredictBuffer[m_PredictPitch - m_LeftOver],
read_leftover);
m_LeftOver -= read_leftover;
bytes_to_go -= read_leftover;
@@ -738,15 +735,16 @@ void CCodec_FlatePredictorScanlineDecoder::GetNextLineWithoutPredictedPitch() {
while (bytes_to_go) {
switch (m_Predictor) {
case PredictorType::kPng:
- FlateOutput(m_pFlate.get(), m_pPredictRaw, m_PredictPitch + 1);
- PNG_PredictLine(m_pPredictBuffer, m_pPredictRaw, m_pLastLine,
- m_BitsPerComponent, m_Colors, m_Columns);
- memcpy(m_pLastLine, m_pPredictBuffer, m_PredictPitch);
+ FlateOutput(m_pFlate.get(), m_PredictRaw.data(), m_PredictPitch + 1);
+ PNG_PredictLine(m_PredictBuffer.data(), m_PredictRaw.data(),
+ m_LastLine.data(), m_BitsPerComponent, m_Colors,
+ m_Columns);
+ memcpy(m_LastLine.data(), m_PredictBuffer.data(), m_PredictPitch);
break;
case PredictorType::kFlate:
- FlateOutput(m_pFlate.get(), m_pPredictBuffer, m_PredictPitch);
- TIFF_PredictLine(m_pPredictBuffer, m_PredictPitch, m_BitsPerComponent,
- m_Colors, m_Columns);
+ FlateOutput(m_pFlate.get(), m_PredictBuffer.data(), m_PredictPitch);
+ TIFF_PredictLine(m_PredictBuffer.data(), m_PredictPitch,
+ m_BitsPerComponent, m_Colors, m_Columns);
break;
default:
NOTREACHED();
@@ -754,7 +752,7 @@ void CCodec_FlatePredictorScanlineDecoder::GetNextLineWithoutPredictedPitch() {
}
size_t read_bytes =
m_PredictPitch > bytes_to_go ? bytes_to_go : m_PredictPitch;
- memcpy(m_pScanline.get() + m_Pitch - bytes_to_go, m_pPredictBuffer,
+ memcpy(m_pScanline.get() + m_Pitch - bytes_to_go, m_PredictBuffer.data(),
read_bytes);
m_LeftOver += m_PredictPitch - read_bytes;
bytes_to_go -= read_bytes;