Commit ec0087e3ce2ae7554098b3506378ca3eb9d87795

Authored by Jay Berkenbilt
1 parent 53971d50

Support TIFF Predictor (fixes #171)

ChangeLog
  1 +2018-01-13 Jay Berkenbilt <ejb@ql.org>
  2 +
  3 + * Add support for TIFF predictor for LZW and Flate streams. Now
  4 + all predictor functions are supported.
  5 +
1 6 2017-12-25 Jay Berkenbilt <ejb@ql.org>
2 7  
3 8 * Clarify documentation around options that control parsing but
... ...
libqpdf/QPDF_Stream.cc
... ... @@ -4,6 +4,7 @@
4 4 #include <qpdf/Pipeline.hh>
5 5 #include <qpdf/Pl_Flate.hh>
6 6 #include <qpdf/Pl_PNGFilter.hh>
  7 +#include <qpdf/Pl_TIFFPredictor.hh>
7 8 #include <qpdf/Pl_RC4.hh>
8 9 #include <qpdf/Pl_Buffer.hh>
9 10 #include <qpdf/Pl_ASCII85Decoder.hh>
... ... @@ -133,7 +134,7 @@ QPDF_Stream::understandDecodeParams(
133 134 if (predictor_obj.isInteger())
134 135 {
135 136 predictor = predictor_obj.getIntValue();
136   - if (! ((predictor == 1) ||
  137 + if (! ((predictor == 1) || (predictor == 2) ||
137 138 ((predictor >= 10) && (predictor <= 15))))
138 139 {
139 140 filterable = false;
... ... @@ -459,14 +460,24 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline,
459 460 {
460 461 std::string const& filter = *iter;
461 462  
462   - if (((filter == "/FlateDecode") || (filter == "/LZWDecode")) &&
463   - ((predictor >= 10) && (predictor <= 15)))
  463 + if ((filter == "/FlateDecode") || (filter == "/LZWDecode"))
464 464 {
465   - QTC::TC("qpdf", "QPDF_Stream PNG filter");
466   - pipeline = new Pl_PNGFilter(
467   - "png decode", pipeline, Pl_PNGFilter::a_decode,
468   - columns, colors, bits_per_component);
469   - to_delete.push_back(pipeline);
  465 + if ((predictor >= 10) && (predictor <= 15))
  466 + {
  467 + QTC::TC("qpdf", "QPDF_Stream PNG filter");
  468 + pipeline = new Pl_PNGFilter(
  469 + "png decode", pipeline, Pl_PNGFilter::a_decode,
  470 + columns, colors, bits_per_component);
  471 + to_delete.push_back(pipeline);
  472 + }
  473 + else if (predictor == 2)
  474 + {
  475 + QTC::TC("qpdf", "QPDF_Stream TIFF predictor");
  476 + pipeline = new Pl_TIFFPredictor(
  477 + "tiff decode", pipeline, Pl_TIFFPredictor::a_decode,
  478 + columns, colors, bits_per_component);
  479 + to_delete.push_back(pipeline);
  480 + }
470 481 }
471 482  
472 483 if (filter == "/Crypt")
... ...
qpdf/qpdf.testcov
... ... @@ -301,3 +301,4 @@ qpdf-c called qpdf_set_decode_level 0
301 301 qpdf-c called qpdf_set_compress_streams 0
302 302 qpdf-c called qpdf_set_preserve_unreferenced_objects 0
303 303 qpdf-c called qpdf_set_newline_before_endstream 0
  304 +QPDF_Stream TIFF predictor 0
... ...
qpdf/qtest/qpdf.test
... ... @@ -240,7 +240,7 @@ foreach my $d (@bug_tests)
240 240 show_ntests();
241 241 # ----------
242 242 $td->notify("--- Miscellaneous Tests ---");
243   -$n_tests += 86;
  243 +$n_tests += 87;
244 244  
245 245 $td->runtest("qpdf version",
246 246 {$td->COMMAND => "qpdf --version"},
... ... @@ -684,6 +684,12 @@ $td-&gt;runtest(&quot;short /O or /U&quot;,
684 684 $td->EXIT_STATUS => 0},
685 685 $td->NORMALIZE_NEWLINES);
686 686  
  687 +$td->runtest("stream with tiff predictor",
  688 + {$td->COMMAND => "qpdf --check tiff-predictor.pdf"},
  689 + {$td->FILE => "tiff-predictor.out",
  690 + $td->EXIT_STATUS => 0},
  691 + $td->NORMALIZE_NEWLINES);
  692 +
687 693 show_ntests();
688 694 # ----------
689 695 $td->notify("--- Newline before endstream ---");
... ...
qpdf/qtest/qpdf/tiff-predictor.out 0 → 100644
  1 +checking tiff-predictor.pdf
  2 +PDF Version: 1.5
  3 +File is not encrypted
  4 +File is not linearized
  5 +No syntax or stream encoding errors found; the file may still contain
  6 +errors that qpdf cannot detect
... ...
qpdf/qtest/qpdf/tiff-predictor.pdf 0 → 100644
No preview for this file type