Change Pl_TIFFPredictor::cur_row to std::vector<unsigned char>

This commit is contained in:
m-holger 2024-01-21 17:19:40 +00:00
parent 6b80e0f14b
commit 902fd6df71
2 changed files with 9 additions and 8 deletions

View File

@ -35,8 +35,7 @@ Pl_TIFFPredictor::Pl_TIFFPredictor(
throw std::runtime_error("TIFFPredictor created with invalid columns value");
}
this->bytes_per_row = bpr & UINT_MAX;
this->cur_row = QUtil::make_shared_array<unsigned char>(this->bytes_per_row);
memset(this->cur_row.get(), 0, this->bytes_per_row);
this->cur_row.assign(this->bytes_per_row, 0);
}
void
@ -46,19 +45,19 @@ Pl_TIFFPredictor::write(unsigned char const* data, size_t len)
size_t offset = 0;
while (len >= left) {
// finish off current row
memcpy(this->cur_row.get() + this->pos, data + offset, left);
memcpy(this->cur_row.data() + this->pos, data + offset, left);
offset += left;
len -= left;
processRow();
// Prepare for next row
memset(this->cur_row.get(), 0, this->bytes_per_row);
this->cur_row.assign(this->bytes_per_row, 0);
left = this->bytes_per_row;
this->pos = 0;
}
if (len) {
memcpy(this->cur_row.get() + this->pos, data + offset, len);
memcpy(this->cur_row.data() + this->pos, data + offset, len);
}
this->pos += len;
}
@ -68,7 +67,7 @@ Pl_TIFFPredictor::processRow()
{
QTC::TC("libtests", "Pl_TIFFPredictor processRow", (action == a_decode ? 0 : 1));
BitWriter bw(this->getNext());
BitStream in(this->cur_row.get(), this->bytes_per_row);
BitStream in(this->cur_row.data(), this->bytes_per_row);
std::vector<long long> prev;
for (unsigned int i = 0; i < this->samples_per_pixel; ++i) {
long long sample = in.getBitsSigned(this->bits_per_sample);
@ -100,6 +99,6 @@ Pl_TIFFPredictor::finish()
processRow();
}
this->pos = 0;
memset(this->cur_row.get(), 0, this->bytes_per_row);
this->cur_row.assign(this->bytes_per_row, 0);
getNext()->finish();
}

View File

@ -6,6 +6,8 @@
#include <qpdf/Pipeline.hh>
#include<vector>
class Pl_TIFFPredictor: public Pipeline
{
public:
@ -31,7 +33,7 @@ class Pl_TIFFPredictor: public Pipeline
unsigned int bytes_per_row;
unsigned int samples_per_pixel;
unsigned int bits_per_sample;
std::shared_ptr<unsigned char> cur_row;
std::vector<unsigned char> cur_row;
size_t pos;
};