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,10 +3,8 @@ | ||
| 3 | #include <qpdf/BitStream.hh> | 3 | #include <qpdf/BitStream.hh> |
| 4 | #include <qpdf/BitWriter.hh> | 4 | #include <qpdf/BitWriter.hh> |
| 5 | #include <qpdf/QTC.hh> | 5 | #include <qpdf/QTC.hh> |
| 6 | -#include <qpdf/QUtil.hh> | ||
| 7 | 6 | ||
| 8 | #include <climits> | 7 | #include <climits> |
| 9 | -#include <cstring> | ||
| 10 | #include <stdexcept> | 8 | #include <stdexcept> |
| 11 | #include <vector> | 9 | #include <vector> |
| 12 | 10 | ||
| @@ -21,8 +19,7 @@ Pl_TIFFPredictor::Pl_TIFFPredictor( | @@ -21,8 +19,7 @@ Pl_TIFFPredictor::Pl_TIFFPredictor( | ||
| 21 | action(action), | 19 | action(action), |
| 22 | columns(columns), | 20 | columns(columns), |
| 23 | samples_per_pixel(samples_per_pixel), | 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 | if (samples_per_pixel < 1) { | 24 | if (samples_per_pixel < 1) { |
| 28 | throw std::runtime_error("TIFFPredictor created with invalid samples_per_pixel"); | 25 | throw std::runtime_error("TIFFPredictor created with invalid samples_per_pixel"); |
| @@ -35,31 +32,28 @@ Pl_TIFFPredictor::Pl_TIFFPredictor( | @@ -35,31 +32,28 @@ Pl_TIFFPredictor::Pl_TIFFPredictor( | ||
| 35 | throw std::runtime_error("TIFFPredictor created with invalid columns value"); | 32 | throw std::runtime_error("TIFFPredictor created with invalid columns value"); |
| 36 | } | 33 | } |
| 37 | this->bytes_per_row = bpr & UINT_MAX; | 34 | this->bytes_per_row = bpr & UINT_MAX; |
| 38 | - this->cur_row.assign(this->bytes_per_row, 0); | ||
| 39 | } | 35 | } |
| 40 | 36 | ||
| 41 | void | 37 | void |
| 42 | Pl_TIFFPredictor::write(unsigned char const* data, size_t len) | 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 | size_t offset = 0; | 41 | size_t offset = 0; |
| 46 | while (len >= left) { | 42 | while (len >= left) { |
| 47 | // finish off current row | 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 | offset += left; | 45 | offset += left; |
| 50 | len -= left; | 46 | len -= left; |
| 51 | 47 | ||
| 52 | processRow(); | 48 | processRow(); |
| 53 | 49 | ||
| 54 | // Prepare for next row | 50 | // Prepare for next row |
| 55 | - this->cur_row.assign(this->bytes_per_row, 0); | 51 | + this->cur_row.clear(); |
| 56 | left = this->bytes_per_row; | 52 | left = this->bytes_per_row; |
| 57 | - this->pos = 0; | ||
| 58 | } | 53 | } |
| 59 | if (len) { | 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 | void | 59 | void |
| @@ -94,11 +88,11 @@ Pl_TIFFPredictor::processRow() | @@ -94,11 +88,11 @@ Pl_TIFFPredictor::processRow() | ||
| 94 | void | 88 | void |
| 95 | Pl_TIFFPredictor::finish() | 89 | Pl_TIFFPredictor::finish() |
| 96 | { | 90 | { |
| 97 | - if (this->pos) { | 91 | + if (!cur_row.empty()) { |
| 98 | // write partial row | 92 | // write partial row |
| 93 | + cur_row.insert(cur_row.end(), bytes_per_row - cur_row.size(), 0); | ||
| 99 | processRow(); | 94 | processRow(); |
| 100 | } | 95 | } |
| 101 | - this->pos = 0; | ||
| 102 | - this->cur_row.assign(this->bytes_per_row, 0); | 96 | + cur_row.clear(); |
| 103 | getNext()->finish(); | 97 | getNext()->finish(); |
| 104 | } | 98 | } |
libqpdf/qpdf/Pl_TIFFPredictor.hh
| @@ -34,7 +34,6 @@ class Pl_TIFFPredictor: public Pipeline | @@ -34,7 +34,6 @@ class Pl_TIFFPredictor: public Pipeline | ||
| 34 | unsigned int samples_per_pixel; | 34 | unsigned int samples_per_pixel; |
| 35 | unsigned int bits_per_sample; | 35 | unsigned int bits_per_sample; |
| 36 | std::vector<unsigned char> cur_row; | 36 | std::vector<unsigned char> cur_row; |
| 37 | - size_t pos; | ||
| 38 | }; | 37 | }; |
| 39 | 38 | ||
| 40 | #endif // PL_TIFFPREDICTOR_HH | 39 | #endif // PL_TIFFPREDICTOR_HH |