Commit 5b7a44e1cc97035226b001e10993a3ad394389dc
1 parent
902fd6df
In Pl_TIFFPredictor remove calls to memcpy
Instead of overwriting cur_row.data() use clear and insert.
Showing
2 changed files
with
8 additions
and
15 deletions
libqpdf/Pl_TIFFPredictor.cc
| ... | ... | @@ -3,10 +3,8 @@ |
| 3 | 3 | #include <qpdf/BitStream.hh> |
| 4 | 4 | #include <qpdf/BitWriter.hh> |
| 5 | 5 | #include <qpdf/QTC.hh> |
| 6 | -#include <qpdf/QUtil.hh> | |
| 7 | 6 | |
| 8 | 7 | #include <climits> |
| 9 | -#include <cstring> | |
| 10 | 8 | #include <stdexcept> |
| 11 | 9 | #include <vector> |
| 12 | 10 | |
| ... | ... | @@ -21,8 +19,7 @@ Pl_TIFFPredictor::Pl_TIFFPredictor( |
| 21 | 19 | action(action), |
| 22 | 20 | columns(columns), |
| 23 | 21 | samples_per_pixel(samples_per_pixel), |
| 24 | - bits_per_sample(bits_per_sample), | |
| 25 | - pos(0) | |
| 22 | + bits_per_sample(bits_per_sample) | |
| 26 | 23 | { |
| 27 | 24 | if (samples_per_pixel < 1) { |
| 28 | 25 | throw std::runtime_error("TIFFPredictor created with invalid samples_per_pixel"); |
| ... | ... | @@ -35,31 +32,28 @@ Pl_TIFFPredictor::Pl_TIFFPredictor( |
| 35 | 32 | throw std::runtime_error("TIFFPredictor created with invalid columns value"); |
| 36 | 33 | } |
| 37 | 34 | this->bytes_per_row = bpr & UINT_MAX; |
| 38 | - this->cur_row.assign(this->bytes_per_row, 0); | |
| 39 | 35 | } |
| 40 | 36 | |
| 41 | 37 | void |
| 42 | 38 | Pl_TIFFPredictor::write(unsigned char const* data, size_t len) |
| 43 | 39 | { |
| 44 | - size_t left = this->bytes_per_row - this->pos; | |
| 40 | + size_t left = this->bytes_per_row - cur_row.size(); | |
| 45 | 41 | size_t offset = 0; |
| 46 | 42 | while (len >= left) { |
| 47 | 43 | // finish off current row |
| 48 | - memcpy(this->cur_row.data() + this->pos, data + offset, left); | |
| 44 | + cur_row.insert(cur_row.end(), data + offset, data + offset + left); | |
| 49 | 45 | offset += left; |
| 50 | 46 | len -= left; |
| 51 | 47 | |
| 52 | 48 | processRow(); |
| 53 | 49 | |
| 54 | 50 | // Prepare for next row |
| 55 | - this->cur_row.assign(this->bytes_per_row, 0); | |
| 51 | + this->cur_row.clear(); | |
| 56 | 52 | left = this->bytes_per_row; |
| 57 | - this->pos = 0; | |
| 58 | 53 | } |
| 59 | 54 | if (len) { |
| 60 | - memcpy(this->cur_row.data() + this->pos, data + offset, len); | |
| 55 | + cur_row.insert(cur_row.end(), data + offset, data + offset + len); | |
| 61 | 56 | } |
| 62 | - this->pos += len; | |
| 63 | 57 | } |
| 64 | 58 | |
| 65 | 59 | void |
| ... | ... | @@ -94,11 +88,11 @@ Pl_TIFFPredictor::processRow() |
| 94 | 88 | void |
| 95 | 89 | Pl_TIFFPredictor::finish() |
| 96 | 90 | { |
| 97 | - if (this->pos) { | |
| 91 | + if (!cur_row.empty()) { | |
| 98 | 92 | // write partial row |
| 93 | + cur_row.insert(cur_row.end(), bytes_per_row - cur_row.size(), 0); | |
| 99 | 94 | processRow(); |
| 100 | 95 | } |
| 101 | - this->pos = 0; | |
| 102 | - this->cur_row.assign(this->bytes_per_row, 0); | |
| 96 | + cur_row.clear(); | |
| 103 | 97 | getNext()->finish(); |
| 104 | 98 | } | ... | ... |
libqpdf/qpdf/Pl_TIFFPredictor.hh