mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-03 07:12:28 +00:00
Add tests for new PNG filters
This commit is contained in:
parent
38bdbc0719
commit
4edfe1f41d
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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 ---");
|
||||
|
BIN
qpdf/qtest/qpdf/png-filters-decoded.pdf
Normal file
BIN
qpdf/qtest/qpdf/png-filters-decoded.pdf
Normal file
Binary file not shown.
BIN
qpdf/qtest/qpdf/png-filters.pdf
Normal file
BIN
qpdf/qtest/qpdf/png-filters.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user