Commit 20ca1e8644339ebb3df84c645b2244b5f786a6b3

Authored by m-holger
1 parent b7abb12f

In Pl_TIFFPredictor::processRow optimize 8 bits_per_sample case

Showing 1 changed file with 36 additions and 14 deletions
libqpdf/Pl_TIFFPredictor.cc
... ... @@ -58,24 +58,46 @@ void
58 58 Pl_TIFFPredictor::processRow()
59 59 {
60 60 QTC::TC("libtests", "Pl_TIFFPredictor processRow", (action == a_decode ? 0 : 1));
61   - BitWriter bw(p_next);
62   - BitStream in(cur_row.data(), cur_row.size());
63 61 previous.assign(samples_per_pixel, 0);
64   - for (unsigned int col = 0; col < this->columns; ++col) {
65   - for (auto& prev: previous) {
66   - long long sample = in.getBitsSigned(this->bits_per_sample);
67   - long long new_sample = sample;
68   - if (action == a_encode) {
69   - new_sample -= prev;
70   - prev = sample;
71   - } else {
72   - new_sample += prev;
73   - prev = new_sample;
  62 + if (bits_per_sample != 8) {
  63 + BitWriter bw(p_next);
  64 + BitStream in(cur_row.data(), cur_row.size());
  65 + for (unsigned int col = 0; col < this->columns; ++col) {
  66 + for (auto& prev: previous) {
  67 + long long sample = in.getBitsSigned(this->bits_per_sample);
  68 + long long new_sample = sample;
  69 + if (action == a_encode) {
  70 + new_sample -= prev;
  71 + prev = sample;
  72 + } else {
  73 + new_sample += prev;
  74 + prev = new_sample;
  75 + }
  76 + bw.writeBitsSigned(new_sample, this->bits_per_sample);
  77 + }
  78 + }
  79 + bw.flush();
  80 + } else {
  81 + auto next = cur_row.begin();
  82 + auto cr_end = cur_row.end();
  83 + auto pr_end = previous.end();
  84 +
  85 + while (next != cr_end) {
  86 + for (auto prev = previous.begin(); prev != pr_end && next != cr_end; ++prev, ++next) {
  87 + long long sample = *next;
  88 + long long new_sample = sample;
  89 + if (action == a_encode) {
  90 + new_sample -= *prev;
  91 + *prev = sample;
  92 + } else {
  93 + new_sample += *prev;
  94 + *prev = new_sample;
  95 + }
  96 + auto out = static_cast<unsigned char>(255U & new_sample);
  97 + p_next->write(&out, 1);
74 98 }
75   - bw.writeBitsSigned(new_sample, this->bits_per_sample);
76 99 }
77 100 }
78   - bw.flush();
79 101 }
80 102  
81 103 void
... ...