5 use vars qw(@ISA @EXPORT_OK $VERSION);
40 sub diff_text_with_nul {
41 my ($desc, $text1, $text2, @params) = @_;
43 my $builder = Test::Builder->new;
46 my $imbase = Imager->new(xsize => 100, ysize => 100);
47 my $imcopy = Imager->new(xsize => 100, ysize => 100);
49 $builder->ok($imbase->string(x => 5, 'y' => 50, size => 20,
51 @params), "$desc - draw text1");
52 $builder->ok($imcopy->string(x => 5, 'y' => 50, size => 20,
54 @params), "$desc - draw text2");
55 $builder->isnt_num(Imager::i_img_diff($imbase->{IMG}, $imcopy->{IMG}), 0,
56 "$desc - check result different");
59 sub is_color3($$$$$) {
60 my ($color, $red, $green, $blue, $comment) = @_;
62 my $builder = Test::Builder->new;
64 unless (defined $color) {
65 $builder->ok(0, $comment);
66 $builder->diag("color is undef");
69 unless ($color->can('rgba')) {
70 $builder->ok(0, $comment);
71 $builder->diag("color is not a color object");
75 my ($cr, $cg, $cb) = $color->rgba;
76 unless ($builder->ok($cr == $red && $cg == $green && $cb == $blue, $comment)) {
89 sub is_color_close3($$$$$$) {
90 my ($color, $red, $green, $blue, $tolerance, $comment) = @_;
92 my $builder = Test::Builder->new;
94 unless (defined $color) {
95 $builder->ok(0, $comment);
96 $builder->diag("color is undef");
99 unless ($color->can('rgba')) {
100 $builder->ok(0, $comment);
101 $builder->diag("color is not a color object");
105 my ($cr, $cg, $cb) = $color->rgba;
106 unless ($builder->ok(abs($cr - $red) <= $tolerance
107 && abs($cg - $green) <= $tolerance
108 && abs($cb - $blue) <= $tolerance, $comment)) {
109 $builder->diag(<<END_DIAG);
110 Color out of tolerance ($tolerance):
111 Red: expected $red vs received $cr
112 Green: expected $green vs received $cg
113 Blue: expected $blue vs received $cb
121 sub is_color4($$$$$$) {
122 my ($color, $red, $green, $blue, $alpha, $comment) = @_;
124 my $builder = Test::Builder->new;
126 unless (defined $color) {
127 $builder->ok(0, $comment);
128 $builder->diag("color is undef");
131 unless ($color->can('rgba')) {
132 $builder->ok(0, $comment);
133 $builder->diag("color is not a color object");
137 my ($cr, $cg, $cb, $ca) = $color->rgba;
138 unless ($builder->ok($cr == $red && $cg == $green && $cb == $blue
139 && $ca == $alpha, $comment)) {
140 $builder->diag(<<END_DIAG);
153 sub is_fcolor4($$$$$$;$) {
154 my ($color, $red, $green, $blue, $alpha, $comment_or_diff, $comment_or_undef) = @_;
155 my ($comment, $mindiff);
156 if (defined $comment_or_undef) {
157 ( $mindiff, $comment ) = ( $comment_or_diff, $comment_or_undef )
160 ( $mindiff, $comment ) = ( 0.001, $comment_or_diff )
163 my $builder = Test::Builder->new;
165 unless (defined $color) {
166 $builder->ok(0, $comment);
167 $builder->diag("color is undef");
170 unless ($color->can('rgba')) {
171 $builder->ok(0, $comment);
172 $builder->diag("color is not a color object");
176 my ($cr, $cg, $cb, $ca) = $color->rgba;
177 unless ($builder->ok(abs($cr - $red) <= $mindiff
178 && abs($cg - $green) <= $mindiff
179 && abs($cb - $blue) <= $mindiff
180 && abs($ca - $alpha) <= $mindiff, $comment)) {
181 $builder->diag(<<END_DIAG);
194 sub is_fcolor1($$$;$) {
195 my ($color, $grey, $comment_or_diff, $comment_or_undef) = @_;
196 my ($comment, $mindiff);
197 if (defined $comment_or_undef) {
198 ( $mindiff, $comment ) = ( $comment_or_diff, $comment_or_undef )
201 ( $mindiff, $comment ) = ( 0.001, $comment_or_diff )
204 my $builder = Test::Builder->new;
206 unless (defined $color) {
207 $builder->ok(0, $comment);
208 $builder->diag("color is undef");
211 unless ($color->can('rgba')) {
212 $builder->ok(0, $comment);
213 $builder->diag("color is not a color object");
217 my ($cgrey) = $color->rgba;
218 unless ($builder->ok(abs($cgrey - $grey) <= $mindiff, $comment)) {
221 Gray: $cgrey vs $grey
229 sub is_fcolor3($$$$$;$) {
230 my ($color, $red, $green, $blue, $comment_or_diff, $comment_or_undef) = @_;
231 my ($comment, $mindiff);
232 if (defined $comment_or_undef) {
233 ( $mindiff, $comment ) = ( $comment_or_diff, $comment_or_undef )
236 ( $mindiff, $comment ) = ( 0.001, $comment_or_diff )
239 my $builder = Test::Builder->new;
241 unless (defined $color) {
242 $builder->ok(0, $comment);
243 $builder->diag("color is undef");
246 unless ($color->can('rgba')) {
247 $builder->ok(0, $comment);
248 $builder->diag("color is not a color object");
252 my ($cr, $cg, $cb) = $color->rgba;
253 unless ($builder->ok(abs($cr - $red) <= $mindiff
254 && abs($cg - $green) <= $mindiff
255 && abs($cb - $blue) <= $mindiff, $comment)) {
256 $builder->diag(<<END_DIAG);
269 my ($color, $grey, $comment) = @_;
271 my $builder = Test::Builder->new;
273 unless (defined $color) {
274 $builder->ok(0, $comment);
275 $builder->diag("color is undef");
278 unless ($color->can('rgba')) {
279 $builder->ok(0, $comment);
280 $builder->diag("color is not a color object");
284 my ($cgrey) = $color->rgba;
285 unless ($builder->ok($cgrey == $grey, $comment)) {
286 $builder->diag(<<END_DIAG);
288 Grey: $grey vs $cgrey
297 my $green=Imager::i_color_new(0,255,0,255);
298 my $blue=Imager::i_color_new(0,0,255,255);
299 my $red=Imager::i_color_new(255,0,0,255);
301 my $img=Imager::ImgRaw::new(150,150,3);
303 Imager::i_box_filled($img,70,25,130,125,$green);
304 Imager::i_box_filled($img,20,25,80,125,$blue);
305 Imager::i_arc($img,75,75,30,0,361,$red);
306 Imager::i_conv($img,[0.1, 0.2, 0.4, 0.2, 0.1]);
312 my $green = Imager::Color->new(0, 255, 0, 255);
313 my $blue = Imager::Color->new(0, 0, 255, 255);
314 my $red = Imager::Color->new(255, 0, 0, 255);
315 my $img = Imager->new(xsize => 150, ysize => 150);
316 $img->box(filled => 1, color => $green, box => [ 70, 24, 130, 124 ]);
317 $img->box(filled => 1, color => $blue, box => [ 20, 26, 80, 126 ]);
318 $img->arc(x => 75, y => 75, r => 30, color => $red);
319 $img->filter(type => 'conv', coef => [ 0.1, 0.2, 0.4, 0.2, 0.1 ]);
325 my $green = Imager::Color->new(0, 255, 0, 255);
326 my $blue = Imager::Color->new(0, 0, 255, 255);
327 my $red = Imager::Color->new(255, 0, 0, 255);
328 my $img = Imager->new(xsize => 150, ysize => 150, bits => 16);
329 $img->box(filled => 1, color => $green, box => [ 70, 24, 130, 124 ]);
330 $img->box(filled => 1, color => $blue, box => [ 20, 26, 80, 126 ]);
331 $img->arc(x => 75, y => 75, r => 30, color => $red);
332 $img->filter(type => 'conv', coef => [ 0.1, 0.2, 0.4, 0.2, 0.1 ]);
337 sub test_image_double {
338 my $green = Imager::Color->new(0, 255, 0, 255);
339 my $blue = Imager::Color->new(0, 0, 255, 255);
340 my $red = Imager::Color->new(255, 0, 0, 255);
341 my $img = Imager->new(xsize => 150, ysize => 150, bits => 'double');
342 $img->box(filled => 1, color => $green, box => [ 70, 24, 130, 124 ]);
343 $img->box(filled => 1, color => $blue, box => [ 20, 26, 80, 126 ]);
344 $img->arc(x => 75, y => 75, r => 30, color => $red);
345 $img->filter(type => 'conv', coef => [ 0.1, 0.2, 0.4, 0.2, 0.1 ]);
350 sub test_image_gray {
351 my $g50 = Imager::Color->new(128, 128, 128);
352 my $g30 = Imager::Color->new(76, 76, 76);
353 my $g70 = Imager::Color->new(178, 178, 178);
354 my $img = Imager->new(xsize => 150, ysize => 150, channels => 1);
355 $img->box(filled => 1, color => $g50, box => [ 70, 24, 130, 124 ]);
356 $img->box(filled => 1, color => $g30, box => [ 20, 26, 80, 126 ]);
357 $img->arc(x => 75, y => 75, r => 30, color => $g70);
358 $img->filter(type => 'conv', coef => [ 0.1, 0.2, 0.4, 0.2, 0.1 ]);
363 sub test_image_gray_16 {
364 my $g50 = Imager::Color->new(128, 128, 128);
365 my $g30 = Imager::Color->new(76, 76, 76);
366 my $g70 = Imager::Color->new(178, 178, 178);
367 my $img = Imager->new(xsize => 150, ysize => 150, channels => 1, bits => 16);
368 $img->box(filled => 1, color => $g50, box => [ 70, 24, 130, 124 ]);
369 $img->box(filled => 1, color => $g30, box => [ 20, 26, 80, 126 ]);
370 $img->arc(x => 75, y => 75, r => 30, color => $g70);
371 $img->filter(type => 'conv', coef => [ 0.1, 0.2, 0.4, 0.2, 0.1 ]);
376 sub test_image_mono {
377 require Imager::Fill;
378 my $fh = Imager::Fill->new(hatch => 'check1x1');
379 my $img = Imager->new(xsize => 150, ysize => 150, type => "paletted");
380 my $black = Imager::Color->new(0, 0, 0);
381 my $white = Imager::Color->new(255, 255, 255);
382 $img->addcolors(colors => [ $black, $white ]);
383 $img->box(fill => $fh, box => [ 70, 24, 130, 124 ]);
384 $img->box(filled => 1, color => $white, box => [ 20, 26, 80, 126 ]);
385 $img->arc(x => 75, y => 75, r => 30, color => $black, aa => 0);
392 basic => \&test_image,
393 basic16 => \&test_image_16,
394 basic_double => \&test_image_double,
395 gray => \&test_image_gray,
396 gray16 => \&test_image_gray_16,
397 mono => \&test_image_mono,
400 sub test_image_named {
402 or croak("No name supplied to test_image_named()");
403 my $sub = $name_to_sub{$name}
404 or croak("Unknown name $name supplied to test_image_named()");
409 sub _low_image_diff_check {
410 my ($left, $right, $comment) = @_;
412 my $builder = Test::Builder->new;
414 unless (defined $left) {
415 $builder->ok(0, $comment);
416 $builder->diag("left is undef");
419 unless (defined $right) {
420 $builder->ok(0, $comment);
421 $builder->diag("right is undef");
424 unless ($left->{IMG}) {
425 $builder->ok(0, $comment);
426 $builder->diag("left image has no low level object");
429 unless ($right->{IMG}) {
430 $builder->ok(0, $comment);
431 $builder->diag("right image has no low level object");
434 unless ($left->getwidth == $right->getwidth) {
435 $builder->ok(0, $comment);
436 $builder->diag("left width " . $left->getwidth . " vs right width "
440 unless ($left->getheight == $right->getheight) {
441 $builder->ok(0, $comment);
442 $builder->diag("left height " . $left->getheight . " vs right height "
443 . $right->getheight);
446 unless ($left->getchannels == $right->getchannels) {
447 $builder->ok(0, $comment);
448 $builder->diag("left channels " . $left->getchannels . " vs right channels "
449 . $right->getchannels);
456 sub is_image_similar($$$$) {
457 my ($left, $right, $limit, $comment) = @_;
460 local $Test::Builder::Level = $Test::Builder::Level + 1;
462 _low_image_diff_check($left, $right, $comment)
466 my $builder = Test::Builder->new;
468 my $diff = Imager::i_img_diff($left->{IMG}, $right->{IMG});
469 if ($diff > $limit) {
470 $builder->ok(0, $comment);
471 $builder->diag("image data difference > $limit - $diff");
474 # find the first mismatch
476 for my $y (0 .. $left->getheight()-1) {
477 for my $x (0.. $left->getwidth()-1) {
478 my @lsamples = $left->getsamples(x => $x, y => $y, width => 1);
479 my @rsamples = $right->getsamples(x => $x, y => $y, width => 1);
480 if ("@lsamples" ne "@rsamples") {
481 $builder->diag("first mismatch at ($x, $y) - @lsamples vs @rsamples");
491 return $builder->ok(1, $comment);
495 my ($left, $right, $comment) = @_;
497 local $Test::Builder::Level = $Test::Builder::Level + 1;
499 return is_image_similar($left, $right, 0, $comment);
502 sub is_imaged($$$;$) {
503 my $epsilon = Imager::i_img_epsilonf();
505 ($epsilon) = splice @_, 2, 1;
508 my ($left, $right, $comment) = @_;
511 local $Test::Builder::Level = $Test::Builder::Level + 1;
513 _low_image_diff_check($left, $right, $comment)
517 my $builder = Test::Builder->new;
519 my $same = Imager::i_img_samef($left->{IMG}, $right->{IMG}, $epsilon, $comment);
521 $builder->ok(0, $comment);
522 $builder->diag("images different");
524 # find the first mismatch
526 for my $y (0 .. $left->getheight()-1) {
527 for my $x (0.. $left->getwidth()-1) {
528 my @lsamples = $left->getsamples(x => $x, y => $y, width => 1, type => "float");
529 my @rsamples = $right->getsamples(x => $x, y => $y, width => 1, type => "float");
530 if ("@lsamples" ne "@rsamples") {
531 $builder->diag("first mismatch at ($x, $y) - @lsamples vs @rsamples");
540 return $builder->ok(1, $comment);
544 my ($left, $right, $comment) = @_;
546 my $builder = Test::Builder->new;
548 my $diff = Imager::i_img_diff($left->{IMG}, $right->{IMG});
550 return $builder->ok($diff, "$comment");
553 sub image_bounds_checks {
556 my $builder = Test::Builder->new;
558 $builder->ok(!$im->getpixel(x => -1, y => 0), 'bounds check get (-1, 0)');
559 $builder->ok(!$im->getpixel(x => 10, y => 0), 'bounds check get (10, 0)');
560 $builder->ok(!$im->getpixel(x => 0, y => -1), 'bounds check get (0, -1)');
561 $builder->ok(!$im->getpixel(x => 0, y => 10), 'bounds check get (0, 10)');
562 $builder->ok(!$im->getpixel(x => -1, y => 0), 'bounds check get (-1, 0) float');
563 $builder->ok(!$im->getpixel(x => 10, y => 0), 'bounds check get (10, 0) float');
564 $builder->ok(!$im->getpixel(x => 0, y => -1), 'bounds check get (0, -1) float');
565 $builder->ok(!$im->getpixel(x => 0, y => 10), 'bounds check get (0, 10) float');
566 my $black = Imager::Color->new(0, 0, 0);
567 require Imager::Color::Float;
568 my $blackf = Imager::Color::Float->new(0, 0, 0);
569 $builder->ok(!$im->setpixel(x => -1, y => 0, color => $black), 'bounds check set (-1, 0)');
570 $builder->ok(!$im->setpixel(x => 10, y => 0, color => $black), 'bounds check set (10, 0)');
571 $builder->ok(!$im->setpixel(x => 0, y => -1, color => $black), 'bounds check set (0, -1)');
572 $builder->ok(!$im->setpixel(x => 0, y => 10, color => $black), 'bounds check set (0, 10)');
573 $builder->ok(!$im->setpixel(x => -1, y => 0, color => $blackf), 'bounds check set (-1, 0) float');
574 $builder->ok(!$im->setpixel(x => 10, y => 0, color => $blackf), 'bounds check set (10, 0) float');
575 $builder->ok(!$im->setpixel(x => 0, y => -1, color => $blackf), 'bounds check set (0, -1) float');
576 $builder->ok(!$im->setpixel(x => 0, y => 10, color => $blackf), 'bounds check set (0, 10) float');
579 sub test_colorf_gpix {
580 my ($im, $x, $y, $expected, $epsilon, $comment) = @_;
582 my $builder = Test::Builder->new;
584 defined $comment or $comment = '';
586 my $c = Imager::i_gpixf($im, $x, $y);
588 $builder->ok(0, "$comment - retrieve color at ($x,$y)");
591 unless ($builder->ok(colorf_cmp($c, $expected, $epsilon) == 0,
592 "$comment - got right color ($x, $y)")) {
594 my @exp = $expected->rgba;
595 $builder->diag(<<EOS);
596 # got: ($c[0], $c[1], $c[2])
597 # expected: ($exp[0], $exp[1], $exp[2])
603 sub test_color_gpix {
604 my ($im, $x, $y, $expected, $comment) = @_;
606 my $builder = Test::Builder->new;
608 defined $comment or $comment = '';
609 my $c = Imager::i_get_pixel($im, $x, $y);
611 $builder->ok(0, "$comment - retrieve color at ($x,$y)");
614 unless ($builder->ok(color_cmp($c, $expected) == 0,
615 "got right color ($x, $y)")) {
617 my @exp = $expected->rgba;
618 $builder->diag(<<EOS);
619 # got: ($c[0], $c[1], $c[2])
620 # expected: ($exp[0], $exp[1], $exp[2])
628 sub test_colorf_glin {
629 my ($im, $x, $y, $pels, $comment) = @_;
631 my $builder = Test::Builder->new;
633 my @got = Imager::i_glinf($im, $x, $x+@$pels, $y);
635 or return $builder->is_num(scalar(@got), scalar(@$pels), "$comment - pixels retrieved");
637 return $builder->ok(!grep(colorf_cmp($pels->[$_], $got[$_], 0.005), 0..$#got),
638 "$comment - check colors ($x, $y)");
642 my ($c1, $c2, $epsilon) = @_;
644 defined $epsilon or $epsilon = 0;
649 # print "# (",join(",", @s1[0..2]),") <=> (",join(",", @s2[0..2]),")\n";
650 return abs($s1[0]-$s2[0]) >= $epsilon && $s1[0] <=> $s2[0]
651 || abs($s1[1]-$s2[1]) >= $epsilon && $s1[1] <=> $s2[1]
652 || abs($s1[2]-$s2[2]) >= $epsilon && $s1[2] <=> $s2[2];
661 return $s1[0] <=> $s2[0]
663 || $s1[2] <=> $s2[2];
666 # these test the action of the channel mask on the image supplied
667 # which should be an OO image.
669 my ($im, $epsilon) = @_;
671 my $builder = Test::Builder->new;
673 defined $epsilon or $epsilon = 0;
675 # we want to check all four of ppix() and plin(), ppix() and plinf()
676 # basic test procedure:
677 # first using default/all 1s mask, set to white
678 # make sure we got white
679 # set mask to skip a channel, set to grey
680 # make sure only the right channels set
682 print "# channel mask tests\n";
684 my $white = Imager::NC(255, 255, 255);
685 my $grey = Imager::NC(128, 128, 128);
686 my $white_grey = Imager::NC(128, 255, 128);
688 print "# with ppix\n";
689 $builder->ok($im->setmask(mask=>~0), "set to default mask");
690 $builder->ok($im->setpixel(x=>0, 'y'=>0, color=>$white), "set to white all channels");
691 test_color_gpix($im->{IMG}, 0, 0, $white, "ppix");
692 $builder->ok($im->setmask(mask=>0xF-0x2), "set channel to exclude channel1");
693 $builder->ok($im->setpixel(x=>0, 'y'=>0, color=>$grey), "set to grey, no channel 2");
694 test_color_gpix($im->{IMG}, 0, 0, $white_grey, "ppix masked");
696 print "# with plin\n";
697 $builder->ok($im->setmask(mask=>~0), "set to default mask");
698 $builder->ok($im->setscanline(x=>0, 'y'=>1, pixels => [$white]),
699 "set to white all channels");
700 test_color_gpix($im->{IMG}, 0, 1, $white, "plin");
701 $builder->ok($im->setmask(mask=>0xF-0x2), "set channel to exclude channel1");
702 $builder->ok($im->setscanline(x=>0, 'y'=>1, pixels=>[$grey]),
703 "set to grey, no channel 2");
704 test_color_gpix($im->{IMG}, 0, 1, $white_grey, "plin masked");
707 my $whitef = Imager::NCF(1.0, 1.0, 1.0);
708 my $greyf = Imager::NCF(0.5, 0.5, 0.5);
709 my $white_greyf = Imager::NCF(0.5, 1.0, 0.5);
711 print "# with ppixf\n";
712 $builder->ok($im->setmask(mask=>~0), "set to default mask");
713 $builder->ok($im->setpixel(x=>0, 'y'=>2, color=>$whitef), "set to white all channels");
714 test_colorf_gpix($im->{IMG}, 0, 2, $whitef, $epsilon, "ppixf");
715 $builder->ok($im->setmask(mask=>0xF-0x2), "set channel to exclude channel1");
716 $builder->ok($im->setpixel(x=>0, 'y'=>2, color=>$greyf), "set to grey, no channel 2");
717 test_colorf_gpix($im->{IMG}, 0, 2, $white_greyf, $epsilon, "ppixf masked");
719 print "# with plinf\n";
720 $builder->ok($im->setmask(mask=>~0), "set to default mask");
721 $builder->ok($im->setscanline(x=>0, 'y'=>3, pixels => [$whitef]),
722 "set to white all channels");
723 test_colorf_gpix($im->{IMG}, 0, 3, $whitef, $epsilon, "plinf");
724 $builder->ok($im->setmask(mask=>0xF-0x2), "set channel to exclude channel1");
725 $builder->ok($im->setscanline(x=>0, 'y'=>3, pixels=>[$greyf]),
726 "set to grey, no channel 2");
727 test_colorf_gpix($im->{IMG}, 0, 3, $white_greyf, $epsilon, "plinf masked");
737 Imager::Test - common functions used in testing Imager
741 use Imager::Test 'diff_text_with_nul';
742 diff_text_with_nul($test_name, $text1, $text2, @string_options);
746 This is a repository of functions used in testing Imager.
748 Some functions will only be useful in testing Imager itself, while
749 others should be useful in testing modules that use Imager.
751 No functions are exported by default.
755 =head2 Test functions
761 =item is_color1($color, $grey, $comment)
763 Tests if the first channel of $color matches $grey.
765 =item is_color3($color, $red, $green, $blue, $comment)
767 Tests if $color matches the given ($red, $green, $blue)
769 =item is_color4($color, $red, $green, $blue, $alpha, $comment)
771 Tests if $color matches the given ($red, $green, $blue, $alpha)
773 =item is_fcolor1($fcolor, $grey, $comment)
775 =item is_fcolor1($fcolor, $grey, $epsilon, $comment)
777 Tests if $fcolor's first channel is within $epsilon of ($grey). For
778 the first form $epsilon is taken as 0.001.
780 =item is_fcolor3($fcolor, $red, $green, $blue, $comment)
782 =item is_fcolor3($fcolor, $red, $green, $blue, $epsilon, $comment)
784 Tests if $fcolor's channels are within $epsilon of ($red, $green,
785 $blue). For the first form $epsilon is taken as 0.001.
787 =item is_fcolor4($fcolor, $red, $green, $blue, $alpha, $comment)
789 =item is_fcolor4($fcolor, $red, $green, $blue, $alpha, $epsilon, $comment)
791 Tests if $fcolor's channels are within $epsilon of ($red, $green,
792 $blue, $alpha). For the first form $epsilon is taken as 0.001.
794 =item is_image($im1, $im2, $comment)
796 Tests if the 2 images have the same content. Both images must be
797 defined, have the same width, height, channels and the same color in
798 each pixel. The color comparison is done at 8-bits per pixel. The
799 color representation such as direct vs paletted, bits per sample are
800 not checked. Equivalent to is_image_similar($im1, $im2, 0, $comment).
802 =item is_imaged($im, $im2, $comment)
804 =item is_imaged($im, $im2, $epsilon, $comment)
806 Tests if the two images have the same content at the double/sample
807 level. C<$epsilon> defaults to the platform DBL_EPSILON multiplied by
810 =item is_image_similar($im1, $im2, $maxdiff, $comment)
812 Tests if the 2 images have similar content. Both images must be
813 defined, have the same width, height and channels. The cum of the
814 squares of the differences of each sample are calculated and must be
815 less than or equal to I<$maxdiff> for the test to pass. The color
816 comparison is done at 8-bits per pixel. The color representation such
817 as direct vs paletted, bits per sample are not checked.
819 =item isnt_image($im1, $im2, $comment)
821 Tests that the two images are different. For regressions tests where
822 something (like text output of "0") produced no change, but should
823 have produced a change.
825 =item test_colorf_gpix($im, $x, $y, $expected, $epsilon, $comment)
827 Retrieves the pixel ($x,$y) from the low-level image $im and compares
828 it to the floating point color $expected, with a tolerance of epsilon.
830 =item test_color_gpix($im, $x, $y, $expected, $comment)
832 Retrieves the pixel ($x,$y) from the low-level image $im and compares
833 it to the floating point color $expected.
835 =item test_colorf_glin($im, $x, $y, $pels, $comment)
837 Retrieves the floating point pixels ($x, $y)-[$x+@$pels, $y] from the
838 low level image $im and compares them against @$pels.
840 =item is_color_close3($color, $red, $green, $blue, $tolerance, $comment)
842 Tests if $color's first three channels are within $tolerance of ($red,
847 =head2 Test suite functions
849 Functions that perform one or more tests, typically used to test
850 various parts of Imager's implementation.
854 =item image_bounds_checks($im)
856 Attempts to write to various pixel positions outside the edge of the
857 image to ensure that it fails in those locations.
859 Any new image type should pass these tests. Does 16 separate tests.
861 =item mask_tests($im, $epsilon)
863 Perform a standard set of mask tests on the OO image $im. Does 24
866 =item diff_text_with_nul($test_name, $text1, $text2, @options)
868 Creates 2 test images and writes $text1 to the first image and $text2
869 to the second image with the string() method. Each call adds 3
870 C<ok>/C<not ok> to the output of the test script.
872 Extra options that should be supplied include the font and either a
873 color or channel parameter.
875 This was explicitly created for regression tests on #21770.
879 =head2 Helper functions
883 =item test_image_raw()
885 Returns a 150x150x3 Imager::ImgRaw test image.
889 Returns a 150x150x3 8-bit/sample OO test image. Name: C<basic>.
891 =item test_image_16()
893 Returns a 150x150x3 16-bit/sample OO test image. Name: C<basic16>
895 =item test_image_double()
897 Returns a 150x150x3 double/sample OO test image. Name: C<basic_double>.
899 =item test_image_gray()
901 Returns a 150x150 single channel OO test image. Name: C<gray>.
903 =item test_image_gray_16()
905 Returns a 150x150 16-bit/sample single channel OO test image. Name:
908 =item test_image_mono()
910 Returns a 150x150 bilevel image that passes the is_bilevel() test.
913 =item test_image_named($name)
915 Return one of the other test images above based on name.
917 =item color_cmp($c1, $c2)
919 Performs an ordering of 3-channel colors (like <=>).
921 =item colorf_cmp($c1, $c2)
923 Performs an ordering of 3-channel floating point colors (like <=>).
929 Tony Cook <tony@develop-help.com>