]> git.imager.perl.org - imager.git/blobdiff - t/t106tiff.t
report the error if we can't read the alpha test images
[imager.git] / t / t106tiff.t
index dae0fd7fd895edc1787641530e69638945f0fb41..0c964eca46abe53ae94870603bd50bfc3cee4647 100644 (file)
@@ -1,7 +1,7 @@
 #!perl -w
 use strict;
 use lib 't';
-use Test::More tests => 101;
+use Test::More tests => 127;
 use Imager qw(:all);
 $^W=1; # warnings during command-line tests
 $|=1;  # give us some progress in the test harness
@@ -32,7 +32,7 @@ SKIP:
     $im = Imager->new(xsize=>2, ysize=>2);
     ok(!$im->write(file=>"testout/notiff.tif"), "should fail to write tiff");
     is($im->errstr, 'format not supported', "check no tiff message");
-    skip("no tiff support", 97);
+    skip("no tiff support", 123);
   }
 
   Imager::i_tags_add($img, "i_xres", 0, "300", 0);
@@ -398,13 +398,55 @@ SKIP:
     my $im = Imager->new;
     ok(!$im->read(file=>'t/t106tiff.t', type=>'tiff'),
        "fail to read script as image");
-    is($im->errstr, 
-       "Error opening file: Not a TIFF file, bad magic number 8483 (0x2123)", 
-       "check error message");
+    # we get different magic number values depending on the platform
+    # byte ordering
+    cmp_ok($im->errstr, '=~',
+          "Error opening file: Not a TIFF (?:or MDI )?file, bad magic number (8483 \\(0x2123\\)|8993 \\(0x2321\\))", 
+          "check error message");
     my @ims = Imager->read_multi(file =>'t/t106tiff.t', type=>'tiff');
     ok(!@ims, "fail to read_multi script as image");
-    is($im->errstr, 
-       "Error opening file: Not a TIFF file, bad magic number 8483 (0x2123)", 
+    cmp_ok($im->errstr, '=~',
+          "Error opening file: Not a TIFF (?:or MDI )?file, bad magic number (8483 \\(0x2123\\)|8993 \\(0x2321\\))", 
        "check error message");
   }
+
+  { # write_multi to data
+    my $data;
+    my $im = Imager->new(xsize => 50, ysize => 50);
+    ok(Imager->write_multi({ data => \$data, type=>'tiff' }, $im, $im),
+       "write multi to in memory");
+    ok(length $data, "make sure something written");
+    my @im = Imager->read_multi(data => $data);
+    is(@im, 2, "make sure we can read it back");
+    is(Imager::i_img_diff($im[0]{IMG}, $im->{IMG}), 0,
+       "check first image");
+    is(Imager::i_img_diff($im[1]{IMG}, $im->{IMG}), 0,
+       "check second image");
+  }
+
+  { # handling of an alpha channel for various images
+    my $photo_rgb = 2;
+    my $photo_cmyk = 5;
+    my $photo_cielab = 8;
+    my @alpha_images =
+      (
+       [ 'srgb.tif',    3, $photo_rgb ],
+       [ 'srgba.tif',   4, $photo_rgb  ],
+       [ 'srgbaa.tif',  4, $photo_rgb  ],
+       [ 'scmyk.tif',   3, $photo_cmyk ],
+       [ 'scmyka.tif',  4, $photo_cmyk ],
+       [ 'scmykaa.tif', 4, $photo_cmyk ],
+       [ 'slab.tif',    3, $photo_cielab ],
+      );
+    for my $test (@alpha_images) {
+      my $im = Imager->new;
+      ok($im->read(file => "testimg/$test->[0]"),
+        "read alpha test $test->[0]")
+         or print "# ", $im->errstr, "\n";
+      is($im->getchannels, $test->[1], "channels for $test->[0] match");
+      is($im->tags(name=>'tiff_photometric'), $test->[2],
+        "photometric for $test->[0] match");
+    }
+  }
 }
+