2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-04 03:10:52 +00:00

Add tests for new PNG filters

This commit is contained in:
Jay Berkenbilt 2017-12-25 10:27:45 -05:00
parent 38bdbc0719
commit 4edfe1f41d
7 changed files with 79 additions and 10 deletions

View File

@ -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;

View File

@ -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

View File

@ -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)
{

View File

@ -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
{

View File

@ -2335,6 +2335,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 ---");

Binary file not shown.

Binary file not shown.