aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libqpdf/Pl_PNGFilter.cc5
-rw-r--r--libtests/libtests.testcov4
-rw-r--r--libtests/png_filter.cc15
-rw-r--r--libtests/qtest/png_filter.test42
-rw-r--r--qpdf/qtest/qpdf.test23
-rw-r--r--qpdf/qtest/qpdf/png-filters-decoded.pdfbin0 -> 33789 bytes
-rw-r--r--qpdf/qtest/qpdf/png-filters.pdfbin0 -> 16827 bytes
7 files changed, 79 insertions, 10 deletions
diff --git a/libqpdf/Pl_PNGFilter.cc b/libqpdf/Pl_PNGFilter.cc
index 5504112e..35ab03f8 100644
--- a/libqpdf/Pl_PNGFilter.cc
+++ b/libqpdf/Pl_PNGFilter.cc
@@ -1,4 +1,5 @@
#include <qpdf/Pl_PNGFilter.hh>
+#include <qpdf/QTC.hh>
#include <stdexcept>
#include <string.h>
#include <limits.h>
@@ -134,6 +135,7 @@ Pl_PNGFilter::decodeRow()
void
Pl_PNGFilter::decodeSub()
{
+ QTC::TC("libtests", "Pl_PNGFilter decodeSub");
unsigned char* buffer = this->cur_row + 1;
unsigned int bpp = this->bytes_per_pixel;
@@ -153,6 +155,7 @@ Pl_PNGFilter::decodeSub()
void
Pl_PNGFilter::decodeUp()
{
+ QTC::TC("libtests", "Pl_PNGFilter decodeUp");
unsigned char* buffer = this->cur_row + 1;
unsigned char* above_buffer = this->prev_row + 1;
@@ -166,6 +169,7 @@ Pl_PNGFilter::decodeUp()
void
Pl_PNGFilter::decodeAverage()
{
+ QTC::TC("libtests", "Pl_PNGFilter decodeAverage");
unsigned char* buffer = this->cur_row + 1;
unsigned char* above_buffer = this->prev_row + 1;
unsigned int bpp = this->bytes_per_pixel;
@@ -188,6 +192,7 @@ Pl_PNGFilter::decodeAverage()
void
Pl_PNGFilter::decodePaeth()
{
+ QTC::TC("libtests", "Pl_PNGFilter decodePaeth");
unsigned char* buffer = this->cur_row + 1;
unsigned char* above_buffer = this->prev_row + 1;
unsigned int bpp = this->bytes_per_pixel;
diff --git a/libtests/libtests.testcov b/libtests/libtests.testcov
index 87216b61..03ca98a6 100644
--- a/libtests/libtests.testcov
+++ b/libtests/libtests.testcov
@@ -29,3 +29,7 @@ Pl_RunLength flush full buffer 1
Pl_RunLength flush empty buffer 0
Pl_DCT empty_pipeline_output_buffer 0
Pl_DCT term_pipeline_destination 0
+Pl_PNGFilter decodeSub 0
+Pl_PNGFilter decodeUp 0
+Pl_PNGFilter decodeAverage 0
+Pl_PNGFilter decodePaeth 0
diff --git a/libtests/png_filter.cc b/libtests/png_filter.cc
index 6a4f676c..7494cb7a 100644
--- a/libtests/png_filter.cc
+++ b/libtests/png_filter.cc
@@ -8,7 +8,8 @@
#include <string.h>
#include <stdlib.h>
-void run(char const* filename, bool encode, unsigned int columns)
+void run(char const* filename, bool encode, unsigned int columns,
+ int bits_per_sample, int samples_per_pixel)
{
// Decode the file
FILE* in = QUtil::safe_fopen(filename, "rb");
@@ -17,7 +18,7 @@ void run(char const* filename, bool encode, unsigned int columns)
Pipeline* pl = new Pl_PNGFilter(
"png", out,
encode ? Pl_PNGFilter::a_encode : Pl_PNGFilter::a_decode,
- columns);
+ columns, samples_per_pixel, bits_per_sample);
assert((2 * (columns + 1)) < 1024);
unsigned char buf[1024];
size_t len;
@@ -54,18 +55,22 @@ void run(char const* filename, bool encode, unsigned int columns)
int main(int argc, char* argv[])
{
- if (argc != 4)
+ if (argc != 6)
{
- std::cerr << "Usage: pipeline {en,de}code filename columns" << std::endl;
+ std::cerr << "Usage: png_filter {en,de}code filename"
+ << " columns samples-per-pixel bits-per-sample"
+ << std::endl;
exit(2);
}
bool encode = (strcmp(argv[1], "encode") == 0);
char* filename = argv[2];
int columns = QUtil::string_to_int(argv[3]);
+ int samples_per_pixel = QUtil::string_to_int(argv[4]);
+ int bits_per_sample = QUtil::string_to_int(argv[5]);
try
{
- run(filename, encode, columns);
+ run(filename, encode, columns, bits_per_sample, samples_per_pixel);
}
catch (std::exception& e)
{
diff --git a/libtests/qtest/png_filter.test b/libtests/qtest/png_filter.test
index 5b75a208..ff3cef54 100644
--- a/libtests/qtest/png_filter.test
+++ b/libtests/qtest/png_filter.test
@@ -14,7 +14,7 @@ my $td = new TestDriver('png_filter');
cleanup();
$td->runtest("decode columns = 4",
- {$td->COMMAND => "png_filter decode in1 4"},
+ {$td->COMMAND => "png_filter decode in1 4 1 8"},
{$td->STRING => "done\n",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
@@ -24,7 +24,7 @@ $td->runtest("check output",
{$td->FILE => "out1"});
$td->runtest("decode columns = 5",
- {$td->COMMAND => "png_filter decode in2 5"},
+ {$td->COMMAND => "png_filter decode in2 5 1 8"},
{$td->STRING => "done\n",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
@@ -34,7 +34,7 @@ $td->runtest("check output",
{$td->FILE => "out2"});
$td->runtest("encode columns = 4",
- {$td->COMMAND => "png_filter encode out1 4"},
+ {$td->COMMAND => "png_filter encode out1 4 1 8"},
{$td->STRING => "done\n",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
@@ -44,7 +44,7 @@ $td->runtest("check output",
{$td->FILE => "in1"});
$td->runtest("encode columns = 5",
- {$td->COMMAND => "png_filter encode out2 5"},
+ {$td->COMMAND => "png_filter encode out2 5 1 8"},
{$td->STRING => "done\n",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
@@ -53,9 +53,41 @@ $td->runtest("check output",
{$td->FILE => "out"},
{$td->FILE => "in2"});
+my @other = (
+ '01--32-3-16',
+ '02--32-1-8',
+ '03--32-3-8',
+ '04--32-1-8',
+ '05--32-3-8',
+ '06--32-1-8',
+ '07--32-3-8',
+ '08--32-1-8',
+ '09--32-3-8',
+ '10--32-1-8',
+ '11--32-3-8',
+ '12--32-1-4',
+ );
+
+foreach my $i (@other)
+{
+ $i =~ m/^.*?--(\d+)-(\d+)-(\d+)$/ or die;
+ my $columns = $1;
+ my $samples_per_pixel = $2;
+ my $bits_per_sample = $3;
+ $td->runtest("decode $i",
+ {$td->COMMAND => "png_filter decode $i.data" .
+ " $columns $samples_per_pixel $bits_per_sample"},
+ {$td->STRING => "done\n",
+ $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
+ $td->runtest("check output for $i",
+ {$td->FILE => "out"},
+ {$td->FILE => "$i.decoded"});
+}
+
cleanup();
-$td->report(8);
+$td->report(8 + (2 * scalar(@other)));
sub cleanup
{
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test
index 2a8d20e7..6c88e098 100644
--- a/qpdf/qtest/qpdf.test
+++ b/qpdf/qtest/qpdf.test
@@ -2336,6 +2336,29 @@ $td->runtest("convert inline-images to qdf",
compare_pdfs("inline-images.pdf", "a.pdf");
show_ntests();
+
+
+# ----------
+$td->notify("--- PNG filtering Tests ---");
+$n_tests += 2;
+$n_compare_pdfs += 1;
+
+# The PDF file was submitted on bug #83 on github. All the PNG filters
+# are exercised. The test suite does not exercise PNG predictors with
+# LZW because I don't have a way to create such a file, but it's very
+# likely that it will work since the handling of the PNG filters is
+# separate from the regular decompression.
+$td->runtest("decode png-filtering",
+ {$td->COMMAND => "qpdf --static-id" .
+ " --compress-streams=n --decode-level=generalized" .
+ " png-filters.pdf a.pdf"},
+ {$td->STRING => "", $td->EXIT_STATUS => 0});
+$td->runtest("check output",
+ {$td->FILE => "a.pdf"},
+ {$td->FILE => "png-filters-decoded.pdf"});
+compare_pdfs("png-filters.pdf", "a.pdf");
+
+show_ntests();
# ----------
$td->notify("--- fix-qdf Tests ---");
$n_tests += 5;
diff --git a/qpdf/qtest/qpdf/png-filters-decoded.pdf b/qpdf/qtest/qpdf/png-filters-decoded.pdf
new file mode 100644
index 00000000..3b45730b
--- /dev/null
+++ b/qpdf/qtest/qpdf/png-filters-decoded.pdf
Binary files differ
diff --git a/qpdf/qtest/qpdf/png-filters.pdf b/qpdf/qtest/qpdf/png-filters.pdf
new file mode 100644
index 00000000..290eb2fd
--- /dev/null
+++ b/qpdf/qtest/qpdf/png-filters.pdf
Binary files differ