2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-02-02 11:58:25 +00:00

Test inline stream data with different decode levels

This commit is contained in:
Jay Berkenbilt 2022-05-07 16:39:58 -04:00
parent f08f398920
commit 2e87d593eb
14 changed files with 2471 additions and 3 deletions

2
TODO
View File

@ -50,8 +50,6 @@ Output JSON v2
General things to remember:
* Test inline and file stream data.
* Make sure all the information from --check and other informational
options (--show-linearization, --show-encryption, --show-xref,
--list-attachments, --show-npages) is available in the json output.

View File

@ -6,6 +6,7 @@ use Cwd;
use Digest::MD5;
use File::Basename;
use File::Copy;
use File::Compare;
use File::Spec;
unshift(@INC, '../../libtests/qtest/arg_parser');
@ -1110,7 +1111,7 @@ my @json_files = (
['V4-aes', ['--json-key=encrypt']],
['V4-aes', ['--json-key=encrypt', '--show-encryption-key']],
);
$n_tests += 5 + (2 * scalar(@json_files));
$n_tests += 24 + (2 * scalar(@json_files));
foreach my $d (@json_files)
{
my ($file, $xargs) = @$d;
@ -1170,6 +1171,64 @@ $td->runtest("check stream (file)",
{$td->FILE => "auto-4"},
{$td->FILE => "bad-data-4.out"});
foreach my $l (qw(none generalized specialized all))
{
if ($l ne 'all')
{
# We don't want a dependency on the exact value of the
# uncompressed jpeg, which can differ depending on which jpeg
# library is use.
$td->runtest("image-streams json inline: $l",
{$td->COMMAND =>
"qpdf image-streams-small.pdf --json=2" .
" --decode-level=$l --json-stream-data=inline"},
{$td->FILE => "json-image-streams-$l-inline-v2.out",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
}
$td->runtest("image-streams json file: $l",
{$td->COMMAND =>
"qpdf image-streams-small.pdf --json=2" .
" --decode-level=$l --json-stream-data=file" .
" --json-stream-prefix=auto --json-key=qpdf" .
" --json-object=12 --json-object=16 --json-object=18"},
{$td->FILE => "json-image-streams-$l-file-v2.out",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
# object 12: /FlateDecode
# object 16: /DCTDecode
# object 18: /RunLengthDecode
my %exp_compression = (
'12' => {'none' => 1},
'16' => {'none' => 1, 'generalized' => 1, 'specialized' => 1},
'18' => {'none' => 1, 'generalized' => 1},
);
foreach my $obj (qw(12 16 18))
{
my $compressed = (exists $exp_compression{$obj}{$l});
my $suf = $compressed ? "compressed" : "uncompressed";
if (($obj eq '16') && (! $compressed))
{
# Rather than testing the uncompressed DCT, just make sure
# it is different from the compressed DCT.
my $same = (compare(
"auto-$obj",
"image-streams-small-$obj-compressed.out") ?
"same" : "different");
$td->runtest("check stream data ($obj, $l)",
{$td->STRING => $same},
{$td->STRING => "same"});
}
else
{
$td->runtest("check stream data ($obj, $l)",
{$td->FILE => "auto-$obj"},
{$td->FILE => "image-streams-small-$obj-$suf.out"});
}
}
}
show_ntests();
# ----------
$td->notify("--- Page API Tests ---");

Binary file not shown.

View File

@ -0,0 +1,2 @@
BT /F1 24 Tf 72 320 Td (/DeviceCMYK with filter null) Tj ET
q 244 0 0 144 184 100 cm /Im1 Do Q

Binary file not shown.

After

Width:  |  Height:  |  Size: 454 B

Binary file not shown.

View File

@ -0,0 +1,44 @@
{
"version": 2,
"parameters": {
"decodelevel": "all"
},
"qpdf": {
"jsonversion": 2,
"pdfversion": "1.3",
"objects": {
"obj:12 0 R": {
"stream": {
"datafile": "auto-12",
"dict": {}
}
},
"obj:16 0 R": {
"stream": {
"datafile": "auto-16",
"dict": {
"/BitsPerComponent": 8,
"/ColorSpace": "/DeviceCMYK",
"/Height": 48,
"/Subtype": "/Image",
"/Type": "/XObject",
"/Width": 40
}
}
},
"obj:18 0 R": {
"stream": {
"datafile": "auto-18",
"dict": {
"/BitsPerComponent": 8,
"/ColorSpace": "/DeviceCMYK",
"/Height": 48,
"/Subtype": "/Image",
"/Type": "/XObject",
"/Width": 40
}
}
}
}
}
}

View File

@ -0,0 +1,46 @@
{
"version": 2,
"parameters": {
"decodelevel": "generalized"
},
"qpdf": {
"jsonversion": 2,
"pdfversion": "1.3",
"objects": {
"obj:12 0 R": {
"stream": {
"datafile": "auto-12",
"dict": {}
}
},
"obj:16 0 R": {
"stream": {
"datafile": "auto-16",
"dict": {
"/BitsPerComponent": 8,
"/ColorSpace": "/DeviceCMYK",
"/Filter": "/DCTDecode",
"/Height": 48,
"/Subtype": "/Image",
"/Type": "/XObject",
"/Width": 40
}
}
},
"obj:18 0 R": {
"stream": {
"datafile": "auto-18",
"dict": {
"/BitsPerComponent": 8,
"/ColorSpace": "/DeviceCMYK",
"/Filter": "/RunLengthDecode",
"/Height": 48,
"/Subtype": "/Image",
"/Type": "/XObject",
"/Width": 40
}
}
}
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,48 @@
{
"version": 2,
"parameters": {
"decodelevel": "none"
},
"qpdf": {
"jsonversion": 2,
"pdfversion": "1.3",
"objects": {
"obj:12 0 R": {
"stream": {
"datafile": "auto-12",
"dict": {
"/Filter": "/FlateDecode"
}
}
},
"obj:16 0 R": {
"stream": {
"datafile": "auto-16",
"dict": {
"/BitsPerComponent": 8,
"/ColorSpace": "/DeviceCMYK",
"/Filter": "/DCTDecode",
"/Height": 48,
"/Subtype": "/Image",
"/Type": "/XObject",
"/Width": 40
}
}
},
"obj:18 0 R": {
"stream": {
"datafile": "auto-18",
"dict": {
"/BitsPerComponent": 8,
"/ColorSpace": "/DeviceCMYK",
"/Filter": "/RunLengthDecode",
"/Height": 48,
"/Subtype": "/Image",
"/Type": "/XObject",
"/Width": 40
}
}
}
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,45 @@
{
"version": 2,
"parameters": {
"decodelevel": "specialized"
},
"qpdf": {
"jsonversion": 2,
"pdfversion": "1.3",
"objects": {
"obj:12 0 R": {
"stream": {
"datafile": "auto-12",
"dict": {}
}
},
"obj:16 0 R": {
"stream": {
"datafile": "auto-16",
"dict": {
"/BitsPerComponent": 8,
"/ColorSpace": "/DeviceCMYK",
"/Filter": "/DCTDecode",
"/Height": 48,
"/Subtype": "/Image",
"/Type": "/XObject",
"/Width": 40
}
}
},
"obj:18 0 R": {
"stream": {
"datafile": "auto-18",
"dict": {
"/BitsPerComponent": 8,
"/ColorSpace": "/DeviceCMYK",
"/Height": 48,
"/Subtype": "/Image",
"/Type": "/XObject",
"/Width": 40
}
}
}
}
}
}

File diff suppressed because one or more lines are too long