1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
|
#!/usr/bin/perl
use warnings;
use strict;
use English qw( -no_match_vars );
use IPC::Cmd qw(can_run run);
use File::Spec;
use File::Temp;
use version;
#use Test::More tests => 8;
use Test::More tests => 19;
#use Test::More tests => 25; when TIFF changes in
use PDF::Builder;
# 0: allow use of Graphics::TIFF, 1: force non-GT usage
my $noGT = 0;
my $diag = '';
my $failed;
# Filename 3 tests ------------------
# tests 1 and 3 will mention TIFF_GT if Graphics::TIFF is installed and
# usable, otherwise they will display just TIFF. you can use this information
# if you are not sure about the status of Graphics::TIFF.
my $pdf = PDF::Builder->new('-compress' => 'none'); # common $pdf all tests
my $has_GT = 0; # global flag for all tests that need to know if Graphics::TIFF
my ($page, $img, $example, $expected);
# -silent shuts off one-time warning for rest of run
my $tiff = $pdf->image_tiff('t/resources/1x1.tif', -silent => 1, -nouseGT => $noGT);
# 1
if ($tiff->usesLib() == 1) {
$has_GT = 1;
isa_ok($tiff, 'PDF::Builder::Resource::XObject::Image::TIFF_GT',
q{$pdf->image_tiff(filename)});
} else {
isa_ok($tiff, 'PDF::Builder::Resource::XObject::Image::TIFF',
q{$pdf->image_tiff(filename)});
}
# 2
is($tiff->width(), 1,
q{Image from filename has a width});
# 3
my $gfx = $pdf->page()->gfx();
$gfx->image($tiff, 72, 144, 216, 288);
like($pdf->to_string(), qr/q 216 0 0 288 72 144 cm \S+ Do Q/,
q{Add TIFF to PDF});
# Filehandle (old library only) 2 tests ------------------
# 4
$pdf = PDF::Builder->new();
open my $fh, '<', 't/resources/1x1.tif' or
die "Couldn't open file t/resources/1x1.tif";
$tiff = $pdf->image_tiff($fh, -nouseGT => 1);
isa_ok($tiff, 'PDF::Builder::Resource::XObject::Image::TIFF',
q{$pdf->image_tiff(filehandle)});
# 5
is($tiff->width(), 1,
q{Image from filehandle has a width});
close $fh;
# LZW Compression 2 tests ------------------
$pdf = PDF::Builder->new('-compress' => 'none');
# 6
my $lzw_tiff = $pdf->image_tiff('t/resources/1x1-lzw.tif', -nouseGT => $noGT);
if ($lzw_tiff->usesLib() == 1) {
isa_ok($lzw_tiff, 'PDF::Builder::Resource::XObject::Image::TIFF_GT',
q{$pdf->image_tiff(), LZW compression});
} else {
isa_ok($lzw_tiff, 'PDF::Builder::Resource::XObject::Image::TIFF',
q{$pdf->image_tiff(), LZW compression});
}
$gfx = $pdf->page()->gfx();
$gfx->image($lzw_tiff, 72, 360, 216, 432);
# 7
like($pdf->to_string(), qr/q 216 0 0 432 72 360 cm \S+ Do Q/,
q{Add TIFF to PDF});
# Missing file 1 test ------------------
# 8
$pdf = PDF::Builder->new();
eval { $pdf->image_tiff('t/resources/this.file.does.not.exist', -nouseGT => $noGT) };
ok($@, q{Fail fast if the requested file doesn't exist});
##############################################################
# common data for remaining tests
my $width = 1000;
my $height = 100;
my $directory = File::Temp->newdir();
my $tiff_f = File::Spec->catfile($directory, 'test.tif');
my $pdfout = File::Spec->catfile($directory, 'test.pdf');
my $pngout = File::Spec->catfile($directory, 'out.png');
# NOTE: following 4 tests use 'convert' tool from ImageMagick.
# They may require software installation on your system, and
# will be skipped if the necessary software is not found.
#
# Some of the following tests will need ghostScript on Windows platforms.
# Note that GS installation MAY not permanently add GS to %Path% -- you
# may have to do this manually
my ($convert, $gs, $convertX, $gsX);
# ImageMagick pre-v7 has a "convert" utility.
# On v7, this is called via "magick convert"
# On Windows, be careful NOT to run "convert", as this is a HDD reformatter!
if (can_run("magick")) {
$convert = "magick convert";
} elsif ($OSNAME ne 'MSWin32' and can_run("convert")) {
$convert = "convert";
}
# check if reasonably recent version
$convert = check_version($convert, '-version', 'ImageMagick ([0-9.]+)', '6.9.7');
# use $convertX instead of $convert in selected tests if IM excluded version
# (error) found
#$convertX = exclude_version($convert, '-v', 'ImageMagick ([0-9.]+)',
# ['8.0.4','100.0', ]);
#$convertX = $convert; # if want to keep tests changed, but not exclude
# $convert undef if not installed, can't parse format, version too low
# will skip "No ImageMagick"
# on Windows, ImageMagick can be 64-bit or 32-bit version, so try both. it's
# needed for some magick convert operations, and also standalone, and
# usually must be installed.
# on Linux-like systems, it's usually just 'gs' and comes with the platform.
if (can_run("gswin64c")) {
$gs = "gswin64c";
} elsif (can_run("gswin32c")) {
$gs = "gswin32c";
} elsif (can_run("gs")) {
$gs = "gs";
}
# check if reasonably recent version
$gs = check_version($gs, '-v', 'Ghostscript ([0-9.]+)', '9.25.0');
# use $gsX instead of $gs in selected tests if GS excluded version (error) found
$gsX = exclude_version($gs, '-v', 'Ghostscript ([0-9.]+)',
['9.56.0','9.56.1', ]);
#$gsX = $gs; # if want to keep tests changed, but not exclude
# $convert undef if not installed, can't parse format, version too low
# will skip "No Ghostscript"
# alpha layer handling ------------------
# convert and Graphics::TIFF needed
# 9
SKIP: {
skip "ImageMagick, Ghostscript, and/or Graphics::TIFF is not available.", 1 unless
defined $convert and defined $gs and $has_GT;
system("$convert -depth 1 -gravity center -pointsize 78 -size ${width}x${height} caption:\"A caption for the image\" $tiff_f");
# ----------
$pdf = PDF::Builder->new(-file => $pdfout);
$page = $pdf->page();
$page->mediabox($width, $height);
$gfx = $page->gfx();
$img = $pdf->image_tiff($tiff_f, -nouseGT => $noGT);
$gfx->image($img, 0, 0, $width, $height);
$pdf->save();
$pdf->end();
# ----------
system("$gs -q -dNOPAUSE -dBATCH -sDEVICE=pngalpha -g${width}x${height} -dPDFFitPage -dUseCropBox -sOutputFile=$pngout $pdfout");
my $example = `$convert $pngout -colorspace gray -depth 1 txt:-`;
my $expected = `$convert $tiff_f -depth 1 txt:-`;
# ----------
is($example, $expected, 'alpha + flate') or show_diag();
}
# G4 (NOT converted to Flate) ------------------
# convert and Graphics::TIFF are needed
# 10
SKIP: {
skip "ImageMagick, Ghostscript, and/or Graphics::TIFF is not available.", 1 unless
defined $convert and defined $gs and $has_GT;
system("$convert -depth 1 -gravity center -pointsize 78 -size ${width}x${height} caption:\"A caption for the image\" -background white -alpha off -compress Group4 $tiff_f");
# ----------
$pdf = PDF::Builder->new(-file => $pdfout);
$page = $pdf->page();
$page->mediabox($width, $height);
$gfx = $page->gfx();
$img = $pdf->image_tiff($tiff_f, -nouseGT => $noGT);
$gfx->image($img, 0, 0, $width, $height);
$pdf->save();
$pdf->end();
# ----------
system("$gs -q -dNOPAUSE -dBATCH -sDEVICE=pnggray -g${width}x${height} -dPDFFitPage -dUseCropBox -sOutputFile=$pngout $pdfout");
$example = `$convert $pngout -depth 1 txt:-`;
$expected = `$convert $tiff_f -depth 1 txt:-`;
# ----------
is($example, $expected, 'G4 (not converted to flate)') or show_diag();
}
# LZW (NOT converted to Flate) ------------------
# convert and Graphics::TIFF needed for these two tests
# 11
SKIP: {
skip "ImageMagick, Ghostscript, and/or Graphics::TIFF is not available.", 1 unless
defined $convert and defined $gs and $has_GT;
system("$convert -depth 1 -gravity center -pointsize 78 -size ${width}x${height} caption:\"A caption for the image\" -background white -alpha off -compress lzw $tiff_f");
# ----------
$pdf = PDF::Builder->new(-file => $pdfout);
$page = $pdf->page();
$page->mediabox( $width, $height );
$gfx = $page->gfx();
$img = $pdf->image_tiff($tiff_f, -nouseGT => 0);
$gfx->image( $img, 0, 0, $width, $height );
$pdf->save();
$pdf->end();
# ----------
system("$gs -q -dNOPAUSE -dBATCH -sDEVICE=pnggray -g${width}x${height} -dPDFFitPage -dUseCropBox -sOutputFile=$pngout $pdfout");
$example = `$convert $pngout -depth 1 -alpha off txt:-`;
$expected = `$convert $tiff_f -depth 1 -alpha off txt:-`;
# ----------
is($example, $expected, 'single-strip lzw (not converted to flate) with GT') or show_diag();
}
# 12
SKIP: {
skip "ImageMagick, Ghostscript, and/or Graphics::TIFF is not available.", 1 unless
defined $convert and defined $gs and $has_GT;
system("$convert -depth 1 -gravity center -pointsize 78 -size ${width}x${height} caption:\"A caption for the image\" -background white -alpha off -define tiff:rows-per-strip=50 -compress lzw $tiff_f");
# ----------
$pdf = PDF::Builder->new(-file => $pdfout);
$page = $pdf->page();
$page->mediabox( $width, $height );
$gfx = $page->gfx();
$img = $pdf->image_tiff($tiff_f, -nouseGT => 0);
$gfx->image( $img, 0, 0, $width, $height );
$pdf->save();
$pdf->end();
# ----------
system("$gs -q -dNOPAUSE -dBATCH -sDEVICE=pnggray -g${width}x${height} -dPDFFitPage -dUseCropBox -sOutputFile=$pngout $pdfout");
$example = `$convert $pngout -depth 1 -alpha off txt:-`;
$expected = `$convert $tiff_f -depth 1 -alpha off txt:-`;
# ----------
#print "for 12, example =\n$example\n expected =\n$expected\n";
is($example, $expected, 'multi-strip lzw (not converted to flate) with GT') or show_diag();
}
# 13
SKIP: {
skip "ImageMagick, Ghostscript, and/or Graphics::TIFF is not available.", 1 unless
defined $convert and defined $gsX and $has_GT;
$width = 20;
$height = 20;
system("$convert -depth 8 -size 2x2 pattern:gray50 -scale 1000% -alpha off -define tiff:predictor=2 -compress lzw $tiff_f");
# ----------
$pdf = PDF::Builder->new(-file => $pdfout);
$page = $pdf->page();
$page->mediabox( $width, $height );
$gfx = $page->gfx();
$img = $pdf->image_tiff($tiff_f, -nouseGT => 0);
$gfx->image( $img, 0, 0, $width, $height );
$pdf->save();
$pdf->end();
# ----------
system("$gs -q -dNOPAUSE -dBATCH -sDEVICE=pnggray -g${width}x${height} -dPDFFitPage -dUseCropBox -sOutputFile=$pngout $pdfout");
$example = `$convert $pngout -depth 8 -alpha off txt:-`;
$expected = `$convert $tiff_f -depth 8 -alpha off txt:-`;
# ----------
is($example, $expected, 'lzw+horizontal predictor (not converted to flate) with GT') or show_diag();
}
# 14
SKIP: {
skip "ImageMagick, Ghostscript, and/or Graphics::TIFF is not available.", 1 unless
defined $convert and defined $gs and $has_GT;
$width = 1000;
$height = 100;
system("$convert -depth 1 -gravity center -pointsize 78 -size ${width}x${height} caption:\"A caption for the image\" -compress lzw $tiff_f");
# ----------
$pdf = PDF::Builder->new(-file => $pdfout);
$page = $pdf->page();
$page->mediabox( $width, $height );
$gfx = $page->gfx();
$img = $pdf->image_tiff($tiff_f, -nouseGT => $noGT);
$gfx->image( $img, 0, 0, $width, $height );
$pdf->save();
$pdf->end();
# ----------
system("$gs -q -dNOPAUSE -dBATCH -sDEVICE=pngalpha -g${width}x${height} -dPDFFitPage -dUseCropBox -sOutputFile=$pngout $pdfout");
$example = `$convert $pngout -colorspace gray -depth 1 txt:-`;
$expected = `$convert $tiff_f -depth 1 txt:-`;
# ----------
is($example, $expected, 'alpha + lzw') or show_diag();
}
# 15
SKIP: {
skip "Either ImageMagick or Ghostscript not available.", 1 unless
defined $convert and defined $gs;
system("$convert -depth 1 -gravity center -pointsize 78 -size ${width}x${height} caption:\"A caption for the image\" -background white -alpha off -compress lzw $tiff_f");
# ----------
$pdf = PDF::Builder->new(-file => $pdfout);
$page = $pdf->page();
$page->mediabox( $width, $height );
$gfx = $page->gfx();
$img = $pdf->image_tiff($tiff_f, -nouseGT => 1);
$gfx->image( $img, 0, 0, $width, $height );
$pdf->save();
$pdf->end();
# ----------
system("$gs -q -dNOPAUSE -dBATCH -sDEVICE=pnggray -g${width}x${height} -dPDFFitPage -dUseCropBox -sOutputFile=$pngout $pdfout");
$example = `$convert $pngout -depth 1 -alpha off txt:-`;
$expected = `$convert $tiff_f -depth 1 -alpha off txt:-`;
# ----------
is($example, $expected, 'single-strip lzw (not converted to flate) without GT') or show_diag();
}
SKIP: {
skip "Either ImageMagick or Ghostscript not available.", 1 unless
defined $convert and defined $gsX;
# 16
$width = 20;
$height = 20;
system("$convert -depth 8 -size 2x2 pattern:gray50 -scale 1000% -alpha off -define tiff:predictor=2 -compress lzw $tiff_f");
# ----------
$pdf = PDF::Builder->new(-file => $pdfout);
$page = $pdf->page();
$page->mediabox( $width, $height );
$gfx = $page->gfx();
$img = $pdf->image_tiff($tiff_f, -nouseGT => 1);
$gfx->image( $img, 0, 0, $width, $height );
$pdf->save();
$pdf->end();
# ----------
system("$gs -q -dNOPAUSE -dBATCH -sDEVICE=pnggray -g${width}x${height} -dPDFFitPage -dUseCropBox -sOutputFile=$pngout $pdfout");
$example = `$convert $pngout -depth 1 -alpha off txt:-`;
$expected = `$convert $tiff_f -depth 1 -alpha off txt:-`;
# ----------
is($example, $expected, 'lzw+horizontal predictor (not converted to flate) without GT') or show_diag();
$width = 1000;
$height = 100;
}
# 17 TODO
SKIP: {
skip "multi-strip lzw without GT is not currently supported", 1;
system("$convert -depth 1 -gravity center -pointsize 78 -size ${width}x${height} caption:\"A caption for the image\" -background white -alpha off -define tiff:rows-per-strip=50 -compress lzw $tiff_f");
# ----------
$pdf = PDF::Builder->new(-file => $pdfout);
$page = $pdf->page();
$page->mediabox( $width, $height );
$gfx = $page->gfx();
$img = $pdf->image_tiff($tiff_f, -nouseGT => 1);
$gfx->image( $img, 0, 0, $width, $height );
$pdf->save();
$pdf->end();
# ----------
system("$gs -q -dNOPAUSE -dBATCH -sDEVICE=pnggray -g${width}x${height} -dPDFFitPage -dUseCropBox -sOutputFile=$pngout $pdfout");
$example = `$convert $pngout -depth 1 -alpha off txt:-`;
$expected = `$convert $tiff_f -depth 1 -alpha off txt:-`;
# ----------
is($example, $expected, 'multi-strip lzw (not converted to flate) without GT') or show_diag();
}
# read TIFF with colormap ------------------
# convert and Graphics::TIFF needed for this test
# 18
SKIP: {
skip "ImageMagick and/or Graphics::TIFF is not available.", 1 unless
defined $convert and $has_GT;
# .png file is temporary file (output, input, erased)
my $colormap = File::Spec->catfile($directory, 'colormap.png');
system("$convert rose: -type palette -depth 2 $colormap");
system("$convert $colormap $tiff_f");
$pdf = PDF::Builder->new(-file => $pdfout);
$page = $pdf->page;
$page->mediabox( $width, $height );
$gfx = $page->gfx();
$img = $pdf->image_tiff($tiff_f, -nouseGT => $noGT);
$gfx->image( $img, 0, 0, $width, $height );
$pdf->save();
$pdf->end();
pass 'successfully read TIFF with colormap';
}
# 19
SKIP: {
skip "ImageMagick, Ghostscript, and/or Graphics::TIFF is not available.", 1 unless
defined $convert and defined $gs and $has_GT;
$width = 6;
$height = 1;
system("$convert -depth 1 -size ${width}x${height} pattern:gray50 -alpha on $tiff_f");
$pdf = PDF::Builder->new(-file => $pdfout);
$page = $pdf->page();
$page->mediabox( $width, $height );
$gfx = $page->gfx();
$img = $pdf->image_tiff($tiff_f, -nouseGT => 0);
$gfx->image( $img, 0, 0, $width, $height );
$pdf->save();
$pdf->end();
# ----------
system("$gs -q -dNOPAUSE -dBATCH -sDEVICE=pnggray -g${width}x${height} -dPDFFitPage -dUseCropBox -sOutputFile=$pngout $pdfout");
$example = `$convert $pngout -depth 1 -alpha off txt:-`;
$expected = `$convert $tiff_f -depth 1 -alpha off txt:-`;
# "For reasons I don't understand, gs swaps the last two pixels here, so let's
# ignore them." This glitch is reported by @carygravel ("gs consistently
# swapped two pixels in the last byte of the first row" over multiple test
# images), but the PDF produced appears to be OK -- it's just something odd
# happening in producing the PNG for comparison. We'll keep an eye on it, as I
# don't particularly like magic solutions. See PR #165.
$example =~ s/(.*\n).*\n.*\n$/$1/;
$expected =~ s/(.*\n).*\n.*\n$/$1/;
# ----------
is($example, $expected, "bilevel and alpha when width not a whole number of bytes with GT") or show_diag();
}
if (0) { ####################################### when TIFF changes in
# 20 TODO
SKIP: {
skip "alpha layer without GT is not currently supported", 1;
#SKIP: {
# skip "Either ImageMagick or Ghostscript not available.", 1 unless
# defined $convert and defined $gs;
$width = 6;
$height = 1;
system("$convert -depth 1 -size ${width}x${height} pattern:gray50 -alpha on $tiff_f");
$pdf = PDF::Builder->new(-file => $pdfout);
$page = $pdf->page();
$page->mediabox( $width, $height );
$gfx = $page->gfx();
$img = $pdf->image_tiff($tiff_f, -nouseGT => 1);
$gfx->image( $img, 0, 0, $width, $height );
$pdf->save();
$pdf->end();
# ----------
system("$gs -q -dNOPAUSE -dBATCH -sDEVICE=pnggray -g${width}x${height} -dPDFFitPage -dUseCropBox -sOutputFile=$pngout $pdfout");
$example = `$convert $pngout -depth 1 -alpha off txt:-`;
$expected = `$convert $tiff_f -depth 1 -alpha off txt:-`;
# for reasons I don't understand, gs swaps the last two pixels here, so let's
# ignore them
$example =~ s/(.*\n).*\n.*\n$/$1/;
$expected =~ s/(.*\n).*\n.*\n$/$1/;
# ----------
is($example, $expected, "bilevel and alpha when width not a whole number of bytes without GT");
}
# 21
SKIP: {
skip "ImageMagick, Ghostscript, and/or Graphics::TIFF is not available.", 1 unless
defined $convert and defined $gs and $has_GT;
$width = 6;
$height = 2;
system("$convert -depth 1 -size ${width}x${height} pattern:gray50 -alpha off -define tiff:rows-per-strip=1 -compress fax $tiff_f");
$pdf = PDF::Builder->new(-file => $pdfout);
$page = $pdf->page();
$page->mediabox( $width, $height );
$gfx = $page->gfx();
$img = $pdf->image_tiff($tiff_f, -nouseGT => 0);
$gfx->image( $img, 0, 0, $width, $height );
$pdf->save();
$pdf->end();
# ----------
system("$gs -q -dNOPAUSE -dBATCH -sDEVICE=pnggray -g${width}x${height} -dPDFFitPage -dUseCropBox -sOutputFile=$pngout $pdfout");
$example = `$convert $pngout -depth 1 -alpha off txt:-`;
$expected = `$convert $tiff_f -depth 1 -alpha off txt:-`;
# ----------
is($example, $expected, 'multi-strip group 3 (not converted to flate) with GT');
}
# 22
SKIP: {
skip "ImageMagick, Ghostscript, and/or Graphics::TIFF is not available.", 1 unless
defined $convert and defined $gs and $has_GT;
$width = 6;
$height = 2;
system("$convert -depth 1 -size ${width}x${height} pattern:gray50 -alpha off -define tiff:rows-per-strip=1 -compress group4 $tiff_f");
$pdf = PDF::Builder->new(-file => $pdfout);
$page = $pdf->page();
$page->mediabox( $width, $height );
$gfx = $page->gfx();
$img = $pdf->image_tiff($tiff_f, -nouseGT => 0);
$gfx->image( $img, 0, 0, $width, $height );
$pdf->save();
$pdf->end();
# ----------
system("$gs -q -dNOPAUSE -dBATCH -sDEVICE=pnggray -g${width}x${height} -dPDFFitPage -dUseCropBox -sOutputFile=$pngout $pdfout");
$example = `$convert $pngout -depth 1 -alpha off txt:-`;
$expected = `$convert $tiff_f -depth 1 -alpha off txt:-`;
# ----------
is($example, $expected, 'multi-strip g4 (not converted to flate) with GT');
}
# 23
SKIP: {
skip "ImageMagick, Ghostscript, and/or Graphics::TIFF is not available.", 1 unless
defined $convert and defined $gs and $has_GT;
$width = 6;
$height = 2;
system("$convert -depth 1 -size ${width}x${height} pattern:gray50 -alpha off -define tiff:rows-per-strip=1 -define quantum:polarity=min-is-black -compress fax $tiff_f");
$pdf = PDF::Builder->new(-file => $pdfout);
$page = $pdf->page();
$page->mediabox( $width, $height );
$gfx = $page->gfx();
$img = $pdf->image_tiff($tiff_f, -nouseGT => 0);
$gfx->image( $img, 0, 0, $width, $height );
$pdf->save();
$pdf->end();
# ----------
system("$gs -q -dNOPAUSE -dBATCH -sDEVICE=pnggray -g${width}x${height} -dPDFFitPage -dUseCropBox -sOutputFile=$pngout $pdfout");
$example = `$convert $pngout -depth 1 -alpha off txt:-`;
$expected = `$convert $tiff_f -depth 1 -alpha off txt:-`;
# ----------
is($example, $expected, 'multi-strip g3 min-is-black (not converted to flate) with GT');
}
# 24
SKIP: {
skip "ImageMagick, Ghostscript, and/or Graphics::TIFF is not available.", 1 unless
defined $convert and defined $gs and $has_GT;
$width = 6;
$height = 2;
system("$convert -depth 1 -size ${width}x${height} pattern:gray50 -alpha off -define tiff:rows-per-strip=1 -define quantum:polarity=min-is-black -compress group4 $tiff_f");
$pdf = PDF::Builder->new(-file => $pdfout);
$page = $pdf->page();
$page->mediabox( $width, $height );
$gfx = $page->gfx();
$img = $pdf->image_tiff($tiff_f, -nouseGT => 0);
$gfx->image( $img, 0, 0, $width, $height );
$pdf->save();
$pdf->end();
# ----------
system("$gs -q -dNOPAUSE -dBATCH -sDEVICE=pnggray -g${width}x${height} -dPDFFitPage -dUseCropBox -sOutputFile=$pngout $pdfout");
$example = `$convert $pngout -depth 1 -alpha off txt:-`;
$expected = `$convert $tiff_f -depth 1 -alpha off txt:-`;
# ----------
is($example, $expected, 'multi-strip g4 min-is-black (not converted to flate) with GT');
}
# 25
SKIP: {
skip "ImageMagick, Ghostscript, and/or Graphics::TIFF is not available.", 1 unless
defined $convert and defined $gs and $has_GT;
$width = 6;
$height = 2;
system("$convert -depth 1 -size ${width}x${height} pattern:gray50 -alpha off -define tiff:fill-order=lsb -compress group4 $tiff_f");
$pdf = PDF::Builder->new(-file => $pdfout);
$page = $pdf->page();
$page->mediabox( $width, $height );
$gfx = $page->gfx();
$img = $pdf->image_tiff($tiff_f, -nouseGT => 0);
$gfx->image( $img, 0, 0, $width, $height );
$pdf->save();
$pdf->end();
# ----------
system("$gs -q -dNOPAUSE -dBATCH -sDEVICE=pnggray -g${width}x${height} -dPDFFitPage -dUseCropBox -sOutputFile=$pngout $pdfout");
$example = `$convert $pngout -depth 1 -alpha off txt:-`;
$expected = `$convert $tiff_f -depth 1 -alpha off txt:-`;
# ----------
is($example, $expected, 'LSB fillorder with GT');
}
} ####################################### when TIFF changes in
##############################################################
# cleanup. all tests involving these files skipped?
# check non-Perl utility versions
sub check_version {
my ($cmd, $arg, $regex, $min_ver) = @_;
# was the check routine already defined (installed)?
if (defined $cmd) {
# should match dotted version number
my $output = `$cmd $arg`;
$diag .= $output;
if ($output =~ m/$regex/) {
if (version->parse($1) >= version->parse($min_ver)) {
return $cmd;
}
}
}
return; # cmd not defined (not installed) so return undef
}
# exclude specified non-Perl utility versions
# do not call if don't have one or more exclusion ranges
sub exclude_version {
my ($cmd, $arg, $regex, $ex_ver_r) = @_;
my (@ex_ver, $my_ver);
if (defined $ex_ver_r) {
@ex_ver = @$ex_ver_r;
} else {
return; # called w/o exclusion list: fail
}
# need 2, 4, 6,... dotted versions
if (!scalar(@ex_ver) || scalar(@ex_ver)%2) {
return; # called with zero or odd number of elements: fail
}
if (defined $cmd) {
# dotted version number should not fall into an excluded range
my $output = `$cmd $arg`;
$diag .= $output;
if ($output =~ m/$regex/) {
$my_ver = version->parse($1);
for (my $i=0; $i<scalar(@ex_ver); $i+=2) {
if ($my_ver >= version->parse($ex_ver[$i ]) &&
$my_ver <= version->parse($ex_ver[$i+1])) {
return; # fell into one of the exclusion ranges
}
}
return $cmd; # didn't hit any exclusions, so OK
}
}
return; # cmd not defined (not installed) so return undef
}
sub show_diag {
#$failed = 0;
$failed = 1;
return;
}
if ($failed) { diag($diag) }
|