#include "regmach.h"
#include "imextdef.h"
#include "imextpltypes.h"
+#include <float.h>
#if i_int_hlines_testing()
#include "imageri.h"
#define i_img_get_width(im) ((im)->xsize)
#define i_img_get_height(im) ((im)->ysize)
+#define i_img_epsilonf() (DBL_EPSILON * 4)
+
MODULE = Imager PACKAGE = Imager::Color PREFIX = ICL_
Imager::Color
Imager::ImgRaw im1
Imager::ImgRaw im2
+int
+i_img_samef(im1, im2, epsilon = i_img_epsilonf(), what=NULL)
+ Imager::ImgRaw im1
+ Imager::ImgRaw im2
+ double epsilon
+ const char *what
+
+double
+i_img_epsilonf()
+
bool
_is_color_object(sv)
SV* sv
return tdiff;
}
+int
+i_img_samef(i_img *im1,i_img *im2, double epsilon, char const *what) {
+ int x,y,ch,xb,yb,chb;
+ i_fcolor val1,val2;
+
+ if (what == NULL)
+ what = "(null)";
+
+ mm_log((1,"i_img_samef(im1 0x%x,im2 0x%x, epsilon %g, what '%s')\n", im1, im2, epsilon, what));
+
+ xb=(im1->xsize<im2->xsize)?im1->xsize:im2->xsize;
+ yb=(im1->ysize<im2->ysize)?im1->ysize:im2->ysize;
+ chb=(im1->channels<im2->channels)?im1->channels:im2->channels;
+
+ mm_log((1,"i_img_samef: xb=%d xy=%d chb=%d\n",xb,yb,chb));
+
+ for(y = 0; y < yb; y++) {
+ for(x = 0; x < xb; x++) {
+ i_gpixf(im1, x, y, &val1);
+ i_gpixf(im2, x, y, &val2);
+
+ for(ch = 0; ch < chb; ch++) {
+ double sdiff = val1.channel[ch] - val2.channel[ch];
+ if (fabs(sdiff) > epsilon) {
+ mm_log((1,"i_img_samef <- different %g @(%d,%d)\n", sdiff, x, y));
+ return 0;
+ }
+ }
+ }
+ }
+ mm_log((1,"i_img_samef <- same\n"));
+
+ return 1;
+}
+
/* just a tiny demo of haar wavelets */
i_img*
float i_img_diff (i_img *im1,i_img *im2);
double i_img_diffd(i_img *im1,i_img *im2);
+int i_img_samef(i_img *im1,i_img *im2, double epsilon, const char *what);
/* font routines */
}
sub is_imaged($$$) {
+ my $epsilon = Imager::i_img_epsilonf();
+ if (@_ > 3) {
+ ($epsilon) = splice @_, 2, 1;
+ }
+
my ($left, $right, $comment) = @_;
{
my $builder = Test::Builder->new;
- my $diff = Imager::i_img_diffd($left->{IMG}, $right->{IMG});
- if ($diff > 0) {
+ my $same = Imager::i_img_samef($left->{IMG}, $right->{IMG}, $epsilon, $comment);
+ if (!$same) {
$builder->ok(0, $comment);
- $builder->diag("image data difference: $diff");
-
+ $builder->diag("images different");
+
# find the first mismatch
PIXELS:
for my $y (0 .. $left->getheight()-1) {
for my $x (0.. $left->getwidth()-1) {
- my @lsamples = $left->getsamples(x => $x, y => $y, width => 1);
- my @rsamples = $right->getsamples(x => $x, y => $y, width => 1);
+ my @lsamples = $left->getsamples(x => $x, y => $y, width => 1, type => "float");
+ my @rsamples = $right->getsamples(x => $x, y => $y, width => 1, type => "float");
if ("@lsamples" ne "@rsamples") {
$builder->diag("first mismatch at ($x, $y) - @lsamples vs @rsamples");
last PIXELS;
=item is_imaged($im, $im2, $comment)
+=item is_imaged($im, $im2, $epsilon, $comment)
+
Tests if the two images have the same content at the double/sample
-level.
+level. C<$epsilon> defaults to the platform DBL_EPSILON multiplied by
+four.
=item is_image_similar($im1, $im2, $maxdiff, $comment)