5 use vars qw(@ISA @EXPORT_OK $VERSION);
43 sub diff_text_with_nul {
44 my ($desc, $text1, $text2, @params) = @_;
46 my $builder = Test::Builder->new;
49 my $imbase = Imager->new(xsize => 100, ysize => 100);
50 my $imcopy = Imager->new(xsize => 100, ysize => 100);
52 $builder->ok($imbase->string(x => 5, 'y' => 50, size => 20,
54 @params), "$desc - draw text1");
55 $builder->ok($imcopy->string(x => 5, 'y' => 50, size => 20,
57 @params), "$desc - draw text2");
58 $builder->isnt_num(Imager::i_img_diff($imbase->{IMG}, $imcopy->{IMG}), 0,
59 "$desc - check result different");
62 sub is_color3($$$$$) {
63 my ($color, $red, $green, $blue, $comment) = @_;
65 my $builder = Test::Builder->new;
67 unless (defined $color) {
68 $builder->ok(0, $comment);
69 $builder->diag("color is undef");
72 unless ($color->can('rgba')) {
73 $builder->ok(0, $comment);
74 $builder->diag("color is not a color object");
78 my ($cr, $cg, $cb) = $color->rgba;
79 unless ($builder->ok($cr == $red && $cg == $green && $cb == $blue, $comment)) {
92 sub is_color_close3($$$$$$) {
93 my ($color, $red, $green, $blue, $tolerance, $comment) = @_;
95 my $builder = Test::Builder->new;
97 unless (defined $color) {
98 $builder->ok(0, $comment);
99 $builder->diag("color is undef");
102 unless ($color->can('rgba')) {
103 $builder->ok(0, $comment);
104 $builder->diag("color is not a color object");
108 my ($cr, $cg, $cb) = $color->rgba;
109 unless ($builder->ok(abs($cr - $red) <= $tolerance
110 && abs($cg - $green) <= $tolerance
111 && abs($cb - $blue) <= $tolerance, $comment)) {
112 $builder->diag(<<END_DIAG);
113 Color out of tolerance ($tolerance):
114 Red: expected $red vs received $cr
115 Green: expected $green vs received $cg
116 Blue: expected $blue vs received $cb
124 sub is_color4($$$$$$) {
125 my ($color, $red, $green, $blue, $alpha, $comment) = @_;
127 my $builder = Test::Builder->new;
129 unless (defined $color) {
130 $builder->ok(0, $comment);
131 $builder->diag("color is undef");
134 unless ($color->can('rgba')) {
135 $builder->ok(0, $comment);
136 $builder->diag("color is not a color object");
140 my ($cr, $cg, $cb, $ca) = $color->rgba;
141 unless ($builder->ok($cr == $red && $cg == $green && $cb == $blue
142 && $ca == $alpha, $comment)) {
143 $builder->diag(<<END_DIAG);
156 sub is_fcolor4($$$$$$;$) {
157 my ($color, $red, $green, $blue, $alpha, $comment_or_diff, $comment_or_undef) = @_;
158 my ($comment, $mindiff);
159 if (defined $comment_or_undef) {
160 ( $mindiff, $comment ) = ( $comment_or_diff, $comment_or_undef )
163 ( $mindiff, $comment ) = ( 0.001, $comment_or_diff )
166 my $builder = Test::Builder->new;
168 unless (defined $color) {
169 $builder->ok(0, $comment);
170 $builder->diag("color is undef");
173 unless ($color->can('rgba')) {
174 $builder->ok(0, $comment);
175 $builder->diag("color is not a color object");
179 my ($cr, $cg, $cb, $ca) = $color->rgba;
180 unless ($builder->ok(abs($cr - $red) <= $mindiff
181 && abs($cg - $green) <= $mindiff
182 && abs($cb - $blue) <= $mindiff
183 && abs($ca - $alpha) <= $mindiff, $comment)) {
184 $builder->diag(<<END_DIAG);
197 sub is_fcolor1($$$;$) {
198 my ($color, $grey, $comment_or_diff, $comment_or_undef) = @_;
199 my ($comment, $mindiff);
200 if (defined $comment_or_undef) {
201 ( $mindiff, $comment ) = ( $comment_or_diff, $comment_or_undef )
204 ( $mindiff, $comment ) = ( 0.001, $comment_or_diff )
207 my $builder = Test::Builder->new;
209 unless (defined $color) {
210 $builder->ok(0, $comment);
211 $builder->diag("color is undef");
214 unless ($color->can('rgba')) {
215 $builder->ok(0, $comment);
216 $builder->diag("color is not a color object");
220 my ($cgrey) = $color->rgba;
221 unless ($builder->ok(abs($cgrey - $grey) <= $mindiff, $comment)) {
224 Gray: $cgrey vs $grey
232 sub is_fcolor3($$$$$;$) {
233 my ($color, $red, $green, $blue, $comment_or_diff, $comment_or_undef) = @_;
234 my ($comment, $mindiff);
235 if (defined $comment_or_undef) {
236 ( $mindiff, $comment ) = ( $comment_or_diff, $comment_or_undef )
239 ( $mindiff, $comment ) = ( 0.001, $comment_or_diff )
242 my $builder = Test::Builder->new;
244 unless (defined $color) {
245 $builder->ok(0, $comment);
246 $builder->diag("color is undef");
249 unless ($color->can('rgba')) {
250 $builder->ok(0, $comment);
251 $builder->diag("color is not a color object");
255 my ($cr, $cg, $cb) = $color->rgba;
256 unless ($builder->ok(abs($cr - $red) <= $mindiff
257 && abs($cg - $green) <= $mindiff
258 && abs($cb - $blue) <= $mindiff, $comment)) {
259 $builder->diag(<<END_DIAG);
272 my ($color, $grey, $comment) = @_;
274 my $builder = Test::Builder->new;
276 unless (defined $color) {
277 $builder->ok(0, $comment);
278 $builder->diag("color is undef");
281 unless ($color->can('rgba')) {
282 $builder->ok(0, $comment);
283 $builder->diag("color is not a color object");
287 my ($cgrey) = $color->rgba;
288 unless ($builder->ok($cgrey == $grey, $comment)) {
289 $builder->diag(<<END_DIAG);
291 Grey: $grey vs $cgrey
300 my $green=Imager::i_color_new(0,255,0,255);
301 my $blue=Imager::i_color_new(0,0,255,255);
302 my $red=Imager::i_color_new(255,0,0,255);
304 my $img=Imager::ImgRaw::new(150,150,3);
306 Imager::i_box_filled($img,70,25,130,125,$green);
307 Imager::i_box_filled($img,20,25,80,125,$blue);
308 Imager::i_arc($img,75,75,30,0,361,$red);
309 Imager::i_conv($img,[0.1, 0.2, 0.4, 0.2, 0.1]);
315 my $green = Imager::Color->new(0, 255, 0, 255);
316 my $blue = Imager::Color->new(0, 0, 255, 255);
317 my $red = Imager::Color->new(255, 0, 0, 255);
318 my $img = Imager->new(xsize => 150, ysize => 150);
319 $img->box(filled => 1, color => $green, box => [ 70, 24, 130, 124 ]);
320 $img->box(filled => 1, color => $blue, box => [ 20, 26, 80, 126 ]);
321 $img->arc(x => 75, y => 75, r => 30, color => $red);
322 $img->filter(type => 'conv', coef => [ 0.1, 0.2, 0.4, 0.2, 0.1 ]);
328 my $green = Imager::Color->new(0, 255, 0, 255);
329 my $blue = Imager::Color->new(0, 0, 255, 255);
330 my $red = Imager::Color->new(255, 0, 0, 255);
331 my $img = Imager->new(xsize => 150, ysize => 150, bits => 16);
332 $img->box(filled => 1, color => $green, box => [ 70, 24, 130, 124 ]);
333 $img->box(filled => 1, color => $blue, box => [ 20, 26, 80, 126 ]);
334 $img->arc(x => 75, y => 75, r => 30, color => $red);
335 $img->filter(type => 'conv', coef => [ 0.1, 0.2, 0.4, 0.2, 0.1 ]);
340 sub test_image_double {
341 my $green = Imager::Color->new(0, 255, 0, 255);
342 my $blue = Imager::Color->new(0, 0, 255, 255);
343 my $red = Imager::Color->new(255, 0, 0, 255);
344 my $img = Imager->new(xsize => 150, ysize => 150, bits => 'double');
345 $img->box(filled => 1, color => $green, box => [ 70, 24, 130, 124 ]);
346 $img->box(filled => 1, color => $blue, box => [ 20, 26, 80, 126 ]);
347 $img->arc(x => 75, y => 75, r => 30, color => $red);
348 $img->filter(type => 'conv', coef => [ 0.1, 0.2, 0.4, 0.2, 0.1 ]);
353 sub test_image_gray {
354 my $g50 = Imager::Color->new(128, 128, 128);
355 my $g30 = Imager::Color->new(76, 76, 76);
356 my $g70 = Imager::Color->new(178, 178, 178);
357 my $img = Imager->new(xsize => 150, ysize => 150, channels => 1);
358 $img->box(filled => 1, color => $g50, box => [ 70, 24, 130, 124 ]);
359 $img->box(filled => 1, color => $g30, box => [ 20, 26, 80, 126 ]);
360 $img->arc(x => 75, y => 75, r => 30, color => $g70);
361 $img->filter(type => 'conv', coef => [ 0.1, 0.2, 0.4, 0.2, 0.1 ]);
366 sub test_image_gray_16 {
367 my $g50 = Imager::Color->new(128, 128, 128);
368 my $g30 = Imager::Color->new(76, 76, 76);
369 my $g70 = Imager::Color->new(178, 178, 178);
370 my $img = Imager->new(xsize => 150, ysize => 150, channels => 1, bits => 16);
371 $img->box(filled => 1, color => $g50, box => [ 70, 24, 130, 124 ]);
372 $img->box(filled => 1, color => $g30, box => [ 20, 26, 80, 126 ]);
373 $img->arc(x => 75, y => 75, r => 30, color => $g70);
374 $img->filter(type => 'conv', coef => [ 0.1, 0.2, 0.4, 0.2, 0.1 ]);
379 sub test_image_mono {
380 require Imager::Fill;
381 my $fh = Imager::Fill->new(hatch => 'check1x1');
382 my $img = Imager->new(xsize => 150, ysize => 150, type => "paletted");
383 my $black = Imager::Color->new(0, 0, 0);
384 my $white = Imager::Color->new(255, 255, 255);
385 $img->addcolors(colors => [ $black, $white ]);
386 $img->box(fill => $fh, box => [ 70, 24, 130, 124 ]);
387 $img->box(filled => 1, color => $white, box => [ 20, 26, 80, 126 ]);
388 $img->arc(x => 75, y => 75, r => 30, color => $black, aa => 0);
395 basic => \&test_image,
396 basic16 => \&test_image_16,
397 basic_double => \&test_image_double,
398 gray => \&test_image_gray,
399 gray16 => \&test_image_gray_16,
400 mono => \&test_image_mono,
403 sub test_image_named {
405 or croak("No name supplied to test_image_named()");
406 my $sub = $name_to_sub{$name}
407 or croak("Unknown name $name supplied to test_image_named()");
412 sub _low_image_diff_check {
413 my ($left, $right, $comment) = @_;
415 my $builder = Test::Builder->new;
417 unless (defined $left) {
418 $builder->ok(0, $comment);
419 $builder->diag("left is undef");
422 unless (defined $right) {
423 $builder->ok(0, $comment);
424 $builder->diag("right is undef");
427 unless ($left->{IMG}) {
428 $builder->ok(0, $comment);
429 $builder->diag("left image has no low level object");
432 unless ($right->{IMG}) {
433 $builder->ok(0, $comment);
434 $builder->diag("right image has no low level object");
437 unless ($left->getwidth == $right->getwidth) {
438 $builder->ok(0, $comment);
439 $builder->diag("left width " . $left->getwidth . " vs right width "
443 unless ($left->getheight == $right->getheight) {
444 $builder->ok(0, $comment);
445 $builder->diag("left height " . $left->getheight . " vs right height "
446 . $right->getheight);
449 unless ($left->getchannels == $right->getchannels) {
450 $builder->ok(0, $comment);
451 $builder->diag("left channels " . $left->getchannels . " vs right channels "
452 . $right->getchannels);
459 sub is_image_similar($$$$) {
460 my ($left, $right, $limit, $comment) = @_;
463 local $Test::Builder::Level = $Test::Builder::Level + 1;
465 _low_image_diff_check($left, $right, $comment)
469 my $builder = Test::Builder->new;
471 my $diff = Imager::i_img_diff($left->{IMG}, $right->{IMG});
472 if ($diff > $limit) {
473 $builder->ok(0, $comment);
474 $builder->diag("image data difference > $limit - $diff");
477 # find the first mismatch
479 for my $y (0 .. $left->getheight()-1) {
480 for my $x (0.. $left->getwidth()-1) {
481 my @lsamples = $left->getsamples(x => $x, y => $y, width => 1);
482 my @rsamples = $right->getsamples(x => $x, y => $y, width => 1);
483 if ("@lsamples" ne "@rsamples") {
484 $builder->diag("first mismatch at ($x, $y) - @lsamples vs @rsamples");
494 return $builder->ok(1, $comment);
498 my ($left, $right, $comment) = @_;
500 local $Test::Builder::Level = $Test::Builder::Level + 1;
502 return is_image_similar($left, $right, 0, $comment);
505 sub is_imaged($$$;$) {
506 my $epsilon = Imager::i_img_epsilonf();
508 ($epsilon) = splice @_, 2, 1;
511 my ($left, $right, $comment) = @_;
514 local $Test::Builder::Level = $Test::Builder::Level + 1;
516 _low_image_diff_check($left, $right, $comment)
520 my $builder = Test::Builder->new;
522 my $same = Imager::i_img_samef($left->{IMG}, $right->{IMG}, $epsilon, $comment);
524 $builder->ok(0, $comment);
525 $builder->diag("images different");
527 # find the first mismatch
529 for my $y (0 .. $left->getheight()-1) {
530 for my $x (0.. $left->getwidth()-1) {
531 my @lsamples = $left->getsamples(x => $x, y => $y, width => 1, type => "float");
532 my @rsamples = $right->getsamples(x => $x, y => $y, width => 1, type => "float");
533 if ("@lsamples" ne "@rsamples") {
534 $builder->diag("first mismatch at ($x, $y) - @lsamples vs @rsamples");
543 return $builder->ok(1, $comment);
547 my ($left, $right, $comment) = @_;
549 my $builder = Test::Builder->new;
551 my $diff = Imager::i_img_diff($left->{IMG}, $right->{IMG});
553 return $builder->ok($diff, "$comment");
556 sub image_bounds_checks {
559 my $builder = Test::Builder->new;
561 $builder->ok(!$im->getpixel(x => -1, y => 0), 'bounds check get (-1, 0)');
562 $builder->ok(!$im->getpixel(x => 10, y => 0), 'bounds check get (10, 0)');
563 $builder->ok(!$im->getpixel(x => 0, y => -1), 'bounds check get (0, -1)');
564 $builder->ok(!$im->getpixel(x => 0, y => 10), 'bounds check get (0, 10)');
565 $builder->ok(!$im->getpixel(x => -1, y => 0), 'bounds check get (-1, 0) float');
566 $builder->ok(!$im->getpixel(x => 10, y => 0), 'bounds check get (10, 0) float');
567 $builder->ok(!$im->getpixel(x => 0, y => -1), 'bounds check get (0, -1) float');
568 $builder->ok(!$im->getpixel(x => 0, y => 10), 'bounds check get (0, 10) float');
569 my $black = Imager::Color->new(0, 0, 0);
570 require Imager::Color::Float;
571 my $blackf = Imager::Color::Float->new(0, 0, 0);
572 $builder->ok(!$im->setpixel(x => -1, y => 0, color => $black), 'bounds check set (-1, 0)');
573 $builder->ok(!$im->setpixel(x => 10, y => 0, color => $black), 'bounds check set (10, 0)');
574 $builder->ok(!$im->setpixel(x => 0, y => -1, color => $black), 'bounds check set (0, -1)');
575 $builder->ok(!$im->setpixel(x => 0, y => 10, color => $black), 'bounds check set (0, 10)');
576 $builder->ok(!$im->setpixel(x => -1, y => 0, color => $blackf), 'bounds check set (-1, 0) float');
577 $builder->ok(!$im->setpixel(x => 10, y => 0, color => $blackf), 'bounds check set (10, 0) float');
578 $builder->ok(!$im->setpixel(x => 0, y => -1, color => $blackf), 'bounds check set (0, -1) float');
579 $builder->ok(!$im->setpixel(x => 0, y => 10, color => $blackf), 'bounds check set (0, 10) float');
582 sub test_colorf_gpix {
583 my ($im, $x, $y, $expected, $epsilon, $comment) = @_;
585 my $builder = Test::Builder->new;
587 defined $comment or $comment = '';
589 my $c = Imager::i_gpixf($im, $x, $y);
591 $builder->ok(0, "$comment - retrieve color at ($x,$y)");
594 unless ($builder->ok(colorf_cmp($c, $expected, $epsilon) == 0,
595 "$comment - got right color ($x, $y)")) {
597 my @exp = $expected->rgba;
598 $builder->diag(<<EOS);
599 # got: ($c[0], $c[1], $c[2])
600 # expected: ($exp[0], $exp[1], $exp[2])
606 sub test_color_gpix {
607 my ($im, $x, $y, $expected, $comment) = @_;
609 my $builder = Test::Builder->new;
611 defined $comment or $comment = '';
612 my $c = Imager::i_get_pixel($im, $x, $y);
614 $builder->ok(0, "$comment - retrieve color at ($x,$y)");
617 unless ($builder->ok(color_cmp($c, $expected) == 0,
618 "got right color ($x, $y)")) {
620 my @exp = $expected->rgba;
621 $builder->diag(<<EOS);
622 # got: ($c[0], $c[1], $c[2])
623 # expected: ($exp[0], $exp[1], $exp[2])
631 sub test_colorf_glin {
632 my ($im, $x, $y, $pels, $comment) = @_;
634 my $builder = Test::Builder->new;
636 my @got = Imager::i_glinf($im, $x, $x+@$pels, $y);
638 or return $builder->is_num(scalar(@got), scalar(@$pels), "$comment - pixels retrieved");
640 return $builder->ok(!grep(colorf_cmp($pels->[$_], $got[$_], 0.005), 0..$#got),
641 "$comment - check colors ($x, $y)");
645 my ($c1, $c2, $epsilon) = @_;
647 defined $epsilon or $epsilon = 0;
652 # print "# (",join(",", @s1[0..2]),") <=> (",join(",", @s2[0..2]),")\n";
653 return abs($s1[0]-$s2[0]) >= $epsilon && $s1[0] <=> $s2[0]
654 || abs($s1[1]-$s2[1]) >= $epsilon && $s1[1] <=> $s2[1]
655 || abs($s1[2]-$s2[2]) >= $epsilon && $s1[2] <=> $s2[2];
664 return $s1[0] <=> $s2[0]
666 || $s1[2] <=> $s2[2];
669 # these test the action of the channel mask on the image supplied
670 # which should be an OO image.
672 my ($im, $epsilon) = @_;
674 my $builder = Test::Builder->new;
676 defined $epsilon or $epsilon = 0;
678 # we want to check all four of ppix() and plin(), ppix() and plinf()
679 # basic test procedure:
680 # first using default/all 1s mask, set to white
681 # make sure we got white
682 # set mask to skip a channel, set to grey
683 # make sure only the right channels set
685 print "# channel mask tests\n";
687 my $white = Imager::NC(255, 255, 255);
688 my $grey = Imager::NC(128, 128, 128);
689 my $white_grey = Imager::NC(128, 255, 128);
691 print "# with ppix\n";
692 $builder->ok($im->setmask(mask=>~0), "set to default mask");
693 $builder->ok($im->setpixel(x=>0, 'y'=>0, color=>$white), "set to white all channels");
694 test_color_gpix($im->{IMG}, 0, 0, $white, "ppix");
695 $builder->ok($im->setmask(mask=>0xF-0x2), "set channel to exclude channel1");
696 $builder->ok($im->setpixel(x=>0, 'y'=>0, color=>$grey), "set to grey, no channel 2");
697 test_color_gpix($im->{IMG}, 0, 0, $white_grey, "ppix masked");
699 print "# with plin\n";
700 $builder->ok($im->setmask(mask=>~0), "set to default mask");
701 $builder->ok($im->setscanline(x=>0, 'y'=>1, pixels => [$white]),
702 "set to white all channels");
703 test_color_gpix($im->{IMG}, 0, 1, $white, "plin");
704 $builder->ok($im->setmask(mask=>0xF-0x2), "set channel to exclude channel1");
705 $builder->ok($im->setscanline(x=>0, 'y'=>1, pixels=>[$grey]),
706 "set to grey, no channel 2");
707 test_color_gpix($im->{IMG}, 0, 1, $white_grey, "plin masked");
710 my $whitef = Imager::NCF(1.0, 1.0, 1.0);
711 my $greyf = Imager::NCF(0.5, 0.5, 0.5);
712 my $white_greyf = Imager::NCF(0.5, 1.0, 0.5);
714 print "# with ppixf\n";
715 $builder->ok($im->setmask(mask=>~0), "set to default mask");
716 $builder->ok($im->setpixel(x=>0, 'y'=>2, color=>$whitef), "set to white all channels");
717 test_colorf_gpix($im->{IMG}, 0, 2, $whitef, $epsilon, "ppixf");
718 $builder->ok($im->setmask(mask=>0xF-0x2), "set channel to exclude channel1");
719 $builder->ok($im->setpixel(x=>0, 'y'=>2, color=>$greyf), "set to grey, no channel 2");
720 test_colorf_gpix($im->{IMG}, 0, 2, $white_greyf, $epsilon, "ppixf masked");
722 print "# with plinf\n";
723 $builder->ok($im->setmask(mask=>~0), "set to default mask");
724 $builder->ok($im->setscanline(x=>0, 'y'=>3, pixels => [$whitef]),
725 "set to white all channels");
726 test_colorf_gpix($im->{IMG}, 0, 3, $whitef, $epsilon, "plinf");
727 $builder->ok($im->setmask(mask=>0xF-0x2), "set channel to exclude channel1");
728 $builder->ok($im->setscanline(x=>0, 'y'=>3, pixels=>[$greyf]),
729 "set to grey, no channel 2");
730 test_colorf_gpix($im->{IMG}, 0, 3, $white_greyf, $epsilon, "plinf masked");
740 Imager::Test - common functions used in testing Imager
744 use Imager::Test 'diff_text_with_nul';
745 diff_text_with_nul($test_name, $text1, $text2, @string_options);
749 This is a repository of functions used in testing Imager.
751 Some functions will only be useful in testing Imager itself, while
752 others should be useful in testing modules that use Imager.
754 No functions are exported by default.
758 =head2 Test functions
764 =item is_color1($color, $grey, $comment)
766 Tests if the first channel of $color matches $grey.
768 =item is_color3($color, $red, $green, $blue, $comment)
770 Tests if $color matches the given ($red, $green, $blue)
772 =item is_color4($color, $red, $green, $blue, $alpha, $comment)
774 Tests if $color matches the given ($red, $green, $blue, $alpha)
776 =item is_fcolor1($fcolor, $grey, $comment)
778 =item is_fcolor1($fcolor, $grey, $epsilon, $comment)
780 Tests if $fcolor's first channel is within $epsilon of ($grey). For
781 the first form $epsilon is taken as 0.001.
783 =item is_fcolor3($fcolor, $red, $green, $blue, $comment)
785 =item is_fcolor3($fcolor, $red, $green, $blue, $epsilon, $comment)
787 Tests if $fcolor's channels are within $epsilon of ($red, $green,
788 $blue). For the first form $epsilon is taken as 0.001.
790 =item is_fcolor4($fcolor, $red, $green, $blue, $alpha, $comment)
792 =item is_fcolor4($fcolor, $red, $green, $blue, $alpha, $epsilon, $comment)
794 Tests if $fcolor's channels are within $epsilon of ($red, $green,
795 $blue, $alpha). For the first form $epsilon is taken as 0.001.
797 =item is_image($im1, $im2, $comment)
799 Tests if the 2 images have the same content. Both images must be
800 defined, have the same width, height, channels and the same color in
801 each pixel. The color comparison is done at 8-bits per pixel. The
802 color representation such as direct vs paletted, bits per sample are
803 not checked. Equivalent to is_image_similar($im1, $im2, 0, $comment).
805 =item is_imaged($im, $im2, $comment)
807 =item is_imaged($im, $im2, $epsilon, $comment)
809 Tests if the two images have the same content at the double/sample
810 level. C<$epsilon> defaults to the platform DBL_EPSILON multiplied by
813 =item is_image_similar($im1, $im2, $maxdiff, $comment)
815 Tests if the 2 images have similar content. Both images must be
816 defined, have the same width, height and channels. The cum of the
817 squares of the differences of each sample are calculated and must be
818 less than or equal to I<$maxdiff> for the test to pass. The color
819 comparison is done at 8-bits per pixel. The color representation such
820 as direct vs paletted, bits per sample are not checked.
822 =item isnt_image($im1, $im2, $comment)
824 Tests that the two images are different. For regressions tests where
825 something (like text output of "0") produced no change, but should
826 have produced a change.
828 =item test_colorf_gpix($im, $x, $y, $expected, $epsilon, $comment)
830 Retrieves the pixel ($x,$y) from the low-level image $im and compares
831 it to the floating point color $expected, with a tolerance of epsilon.
833 =item test_color_gpix($im, $x, $y, $expected, $comment)
835 Retrieves the pixel ($x,$y) from the low-level image $im and compares
836 it to the floating point color $expected.
838 =item test_colorf_glin($im, $x, $y, $pels, $comment)
840 Retrieves the floating point pixels ($x, $y)-[$x+@$pels, $y] from the
841 low level image $im and compares them against @$pels.
843 =item is_color_close3($color, $red, $green, $blue, $tolerance, $comment)
845 Tests if $color's first three channels are within $tolerance of ($red,
850 =head2 Test suite functions
852 Functions that perform one or more tests, typically used to test
853 various parts of Imager's implementation.
857 =item image_bounds_checks($im)
859 Attempts to write to various pixel positions outside the edge of the
860 image to ensure that it fails in those locations.
862 Any new image type should pass these tests. Does 16 separate tests.
864 =item mask_tests($im, $epsilon)
866 Perform a standard set of mask tests on the OO image $im. Does 24
869 =item diff_text_with_nul($test_name, $text1, $text2, @options)
871 Creates 2 test images and writes $text1 to the first image and $text2
872 to the second image with the string() method. Each call adds 3
873 C<ok>/C<not ok> to the output of the test script.
875 Extra options that should be supplied include the font and either a
876 color or channel parameter.
878 This was explicitly created for regression tests on #21770.
882 =head2 Helper functions
886 =item test_image_raw()
888 Returns a 150x150x3 Imager::ImgRaw test image.
892 Returns a 150x150x3 8-bit/sample OO test image. Name: C<basic>.
894 =item test_image_16()
896 Returns a 150x150x3 16-bit/sample OO test image. Name: C<basic16>
898 =item test_image_double()
900 Returns a 150x150x3 double/sample OO test image. Name: C<basic_double>.
902 =item test_image_gray()
904 Returns a 150x150 single channel OO test image. Name: C<gray>.
906 =item test_image_gray_16()
908 Returns a 150x150 16-bit/sample single channel OO test image. Name:
911 =item test_image_mono()
913 Returns a 150x150 bilevel image that passes the is_bilevel() test.
916 =item test_image_named($name)
918 Return one of the other test images above based on name.
920 =item color_cmp($c1, $c2)
922 Performs an ordering of 3-channel colors (like <=>).
924 =item colorf_cmp($c1, $c2)
926 Performs an ordering of 3-channel floating point colors (like <=>).
932 Tony Cook <tony@develop-help.com>