Added a testcase for copy() and flip() methods, fixed a bug in i_flipxy()
authorArnar Mar Hrafnkelsson <addi@cpan.org>
Fri, 4 May 2001 15:21:38 +0000 (15:21 +0000)
committerArnar Mar Hrafnkelsson <addi@cpan.org>
Fri, 4 May 2001 15:21:38 +0000 (15:21 +0000)
when flipping both horizontally and vertically.  Removed lib/Imager/Regops.pm
as it is autogenerated when make install is run.

image.c
lib/Imager/Regops.pm [deleted file]
t/t64copyflip.t [new file with mode: 0644]

diff --git a/image.c b/image.c
index b83be16296a890e20f5a492da553abfc0ed8fe94..7a94a833da72ec66f65e87c721b38e54f3f2ce23 100644 (file)
--- a/image.c
+++ b/image.c
@@ -665,7 +665,7 @@ i_flipxy(i_img *im, int direction) {
       }
     }
     break;
-  case YAXIS:
+  case YAXIS: /* Vertical flip */
     xm = xs;
     ym = ys/2;
     y2 = ys-1;
@@ -680,7 +680,7 @@ i_flipxy(i_img *im, int direction) {
       y2--;
     }
     break;
-  case XYAXIS:
+  case XYAXIS: /* Horizontal and Vertical flip */
     xm = xs/2;
     ym = ys/2;
     y2 = ys-1;
@@ -701,6 +701,32 @@ i_flipxy(i_img *im, int direction) {
       }
       y2--;
     }
+    if (xm*2 != xs) { /* odd number of column */
+      mm_log((1, "i_flipxy: odd number of columns\n"));
+      x = xm;
+      y2 = ys-1;
+      for(y=0; y<ym; y++) {
+       i_color val1, val2;
+       i_gpix(im, x,  y,  &val1);
+       i_gpix(im, x,  y2, &val2);
+       i_ppix(im, x,  y,  &val2);
+       i_ppix(im, x,  y2, &val1);
+       y2--;
+      }
+    }
+    if (ym*2 != ys) { /* odd number of rows */
+      mm_log((1, "i_flipxy: odd number of rows\n"));
+      y = ym;
+      x2 = xs-1;
+      for(x=0; x<xm; x++) {
+       i_color val1, val2;
+       i_gpix(im, x,  y,  &val1);
+       i_gpix(im, x2, y,  &val2);
+       i_ppix(im, x,  y,  &val2);
+       i_ppix(im, x2, y,  &val1);
+       x2--;
+      }
+    }
     break;
   default:
     mm_log((1, "i_flipxy: direction is invalid\n" ));
diff --git a/lib/Imager/Regops.pm b/lib/Imager/Regops.pm
deleted file mode 100644 (file)
index e4d2770..0000000
+++ /dev/null
@@ -1,426 +0,0 @@
-# AUTOMATICALLY GENERATED BY regops.perl
-package Imager::Regops;
-use strict;
-require Exporter;
-use vars qw(@ISA @EXPORT @EXPORT_OK %Attr $MaxOperands $PackCode);
-@ISA = qw(Exporter);
-@EXPORT_OK = qw(%Attr $MaxOperands $PackCode);
-
-use constant RBC_ADD => 0;
-use constant RBC_SUBTRACT => 1;
-use constant RBC_MULT => 2;
-use constant RBC_DIV => 3;
-use constant RBC_MOD => 4;
-use constant RBC_POW => 5;
-use constant RBC_UMINUS => 6;
-use constant RBC_MULTP => 7;
-use constant RBC_ADDP => 8;
-use constant RBC_SUBTRACTP => 9;
-use constant RBC_SIN => 10;
-use constant RBC_COS => 11;
-use constant RBC_ATAN2 => 12;
-use constant RBC_SQRT => 13;
-use constant RBC_DISTANCE => 14;
-use constant RBC_GETP1 => 15;
-use constant RBC_GETP2 => 16;
-use constant RBC_GETP3 => 17;
-use constant RBC_VALUE => 18;
-use constant RBC_HUE => 19;
-use constant RBC_SAT => 20;
-use constant RBC_HSV => 21;
-use constant RBC_RED => 22;
-use constant RBC_GREEN => 23;
-use constant RBC_BLUE => 24;
-use constant RBC_RGB => 25;
-use constant RBC_INT => 26;
-use constant RBC_IF => 27;
-use constant RBC_IFP => 28;
-use constant RBC_LE => 29;
-use constant RBC_LT => 30;
-use constant RBC_GE => 31;
-use constant RBC_GT => 32;
-use constant RBC_EQ => 33;
-use constant RBC_NE => 34;
-use constant RBC_AND => 35;
-use constant RBC_OR => 36;
-use constant RBC_NOT => 37;
-use constant RBC_ABS => 38;
-use constant RBC_RET => 39;
-use constant RBC_JUMP => 40;
-use constant RBC_JUMPZ => 41;
-use constant RBC_JUMPNZ => 42;
-use constant RBC_SET => 43;
-use constant RBC_SETP => 44;
-use constant RBC_PRINT => 45;
-use constant RBC_OP_COUNT => 46;
-
-@EXPORT = qw(RBC_ADD RBC_SUBTRACT RBC_MULT RBC_DIV RBC_MOD RBC_POW RBC_UMINUS RBC_MULTP RBC_ADDP RBC_SUBTRACTP RBC_SIN RBC_COS RBC_ATAN2 RBC_SQRT RBC_DISTANCE RBC_GETP1 RBC_GETP2 RBC_GETP3 RBC_VALUE RBC_HUE RBC_SAT RBC_HSV RBC_RED RBC_GREEN RBC_BLUE RBC_RGB RBC_INT RBC_IF RBC_IFP RBC_LE RBC_LT RBC_GE RBC_GT RBC_EQ RBC_NE RBC_AND RBC_OR RBC_NOT RBC_ABS RBC_RET RBC_JUMP RBC_JUMPZ RBC_JUMPNZ RBC_SET RBC_SETP RBC_PRINT RBC_OP_COUNT);
-
-%Attr = (
-          'setp' => {
-                      'result' => 'p',
-                      'parms' => 1,
-                      'opcode' => 44,
-                      'func' => 0,
-                      'types' => 'p'
-                    },
-          'green' => {
-                       'result' => 'r',
-                       'parms' => 1,
-                       'opcode' => 23,
-                       'func' => 1,
-                       'types' => 'p'
-                     },
-          'abs' => {
-                     'result' => 'r',
-                     'parms' => 1,
-                     'opcode' => 38,
-                     'func' => 1,
-                     'types' => 'r'
-                   },
-          'le' => {
-                    'result' => 'r',
-                    'parms' => 2,
-                    'opcode' => 29,
-                    'func' => 0,
-                    'types' => 'rr'
-                  },
-          'cos' => {
-                     'result' => 'r',
-                     'parms' => 1,
-                     'opcode' => 11,
-                     'func' => 1,
-                     'types' => 'r'
-                   },
-          'not' => {
-                     'result' => 'r',
-                     'parms' => 1,
-                     'opcode' => 37,
-                     'func' => 0,
-                     'types' => 'r'
-                   },
-          'ne' => {
-                    'result' => 'r',
-                    'parms' => 2,
-                    'opcode' => 34,
-                    'func' => 0,
-                    'types' => 'rr'
-                  },
-          'blue' => {
-                      'result' => 'r',
-                      'parms' => 1,
-                      'opcode' => 24,
-                      'func' => 1,
-                      'types' => 'p'
-                    },
-          'and' => {
-                     'result' => 'r',
-                     'parms' => 2,
-                     'opcode' => 35,
-                     'func' => 0,
-                     'types' => 'rr'
-                   },
-          'mult' => {
-                      'result' => 'r',
-                      'parms' => 2,
-                      'opcode' => 2,
-                      'func' => 0,
-                      'types' => 'rr'
-                    },
-          'pow' => {
-                     'result' => 'r',
-                     'parms' => 2,
-                     'opcode' => 5,
-                     'func' => 0,
-                     'types' => 'rr'
-                   },
-          'lt' => {
-                    'result' => 'r',
-                    'parms' => 2,
-                    'opcode' => 30,
-                    'func' => 0,
-                    'types' => 'rr'
-                  },
-          'mod' => {
-                     'result' => 'r',
-                     'parms' => 2,
-                     'opcode' => 4,
-                     'func' => 0,
-                     'types' => 'rr'
-                   },
-          'getp1' => {
-                       'result' => 'p',
-                       'parms' => 2,
-                       'opcode' => 15,
-                       'func' => 1,
-                       'types' => 'rr'
-                     },
-          'atan2' => {
-                       'result' => 'r',
-                       'parms' => 2,
-                       'opcode' => 12,
-                       'func' => 1,
-                       'types' => 'rr'
-                     },
-          'getp2' => {
-                       'result' => 'p',
-                       'parms' => 2,
-                       'opcode' => 16,
-                       'func' => 1,
-                       'types' => 'rr'
-                     },
-          'getp3' => {
-                       'result' => 'p',
-                       'parms' => 2,
-                       'opcode' => 17,
-                       'func' => 1,
-                       'types' => 'rr'
-                     },
-          'value' => {
-                       'result' => 'r',
-                       'parms' => 1,
-                       'opcode' => 18,
-                       'func' => 1,
-                       'types' => 'p'
-                     },
-          'subtractp' => {
-                           'result' => 'p',
-                           'parms' => 2,
-                           'opcode' => 9,
-                           'func' => 0,
-                           'types' => 'pp'
-                         },
-          'ge' => {
-                    'result' => 'r',
-                    'parms' => 2,
-                    'opcode' => 31,
-                    'func' => 0,
-                    'types' => 'rr'
-                  },
-          'sat' => {
-                     'result' => 'r',
-                     'parms' => 1,
-                     'opcode' => 20,
-                     'func' => 1,
-                     'types' => 'p'
-                   },
-          'jump' => {
-                      'result' => undef,
-                      'parms' => 0,
-                      'opcode' => 40,
-                      'func' => 0,
-                      'types' => ''
-                    },
-          'if' => {
-                    'result' => 'r',
-                    'parms' => 3,
-                    'opcode' => 27,
-                    'func' => 1,
-                    'types' => 'rrr'
-                  },
-          'div' => {
-                     'result' => 'r',
-                     'parms' => 2,
-                     'opcode' => 3,
-                     'func' => 0,
-                     'types' => 'rr'
-                   },
-          'ifp' => {
-                     'result' => 'p',
-                     'parms' => 3,
-                     'opcode' => 28,
-                     'func' => 1,
-                     'types' => 'rpp'
-                   },
-          'set' => {
-                     'result' => 'r',
-                     'parms' => 1,
-                     'opcode' => 43,
-                     'func' => 0,
-                     'types' => 'r'
-                   },
-          'eq' => {
-                    'result' => 'r',
-                    'parms' => 2,
-                    'opcode' => 33,
-                    'func' => 0,
-                    'types' => 'rr'
-                  },
-          'multp' => {
-                       'result' => 'p',
-                       'parms' => 2,
-                       'opcode' => 7,
-                       'func' => 0,
-                       'types' => 'pr'
-                     },
-          'sin' => {
-                     'result' => 'r',
-                     'parms' => 1,
-                     'opcode' => 10,
-                     'func' => 1,
-                     'types' => 'r'
-                   },
-          'sqrt' => {
-                      'result' => 'r',
-                      'parms' => 1,
-                      'opcode' => 13,
-                      'func' => 1,
-                      'types' => 'r'
-                    },
-          'distance' => {
-                          'result' => 'r',
-                          'parms' => 4,
-                          'opcode' => 14,
-                          'func' => 1,
-                          'types' => 'rrrr'
-                        },
-          'gt' => {
-                    'result' => 'r',
-                    'parms' => 2,
-                    'opcode' => 32,
-                    'func' => 0,
-                    'types' => 'rr'
-                  },
-          'red' => {
-                     'result' => 'r',
-                     'parms' => 1,
-                     'opcode' => 22,
-                     'func' => 1,
-                     'types' => 'p'
-                   },
-          'rgb' => {
-                     'result' => 'p',
-                     'parms' => 3,
-                     'opcode' => 25,
-                     'func' => 1,
-                     'types' => 'rrr'
-                   },
-          'hue' => {
-                     'result' => 'r',
-                     'parms' => 1,
-                     'opcode' => 19,
-                     'func' => 1,
-                     'types' => 'p'
-                   },
-          'print' => {
-                       'result' => undef,
-                       'parms' => 1,
-                       'opcode' => 45,
-                       'func' => 0,
-                       'types' => 'r'
-                     },
-          'jumpnz' => {
-                        'result' => undef,
-                        'parms' => 1,
-                        'opcode' => 42,
-                        'func' => 0,
-                        'types' => 'r'
-                      },
-          'addp' => {
-                      'result' => 'p',
-                      'parms' => 2,
-                      'opcode' => 8,
-                      'func' => 0,
-                      'types' => 'pp'
-                    },
-          'int' => {
-                     'result' => 'r',
-                     'parms' => 1,
-                     'opcode' => 26,
-                     'func' => 1,
-                     'types' => 'r'
-                   },
-          'op_count' => {
-                          'result' => undef,
-                          'parms' => 0,
-                          'opcode' => 46,
-                          'func' => 0,
-                          'types' => ''
-                        },
-          'or' => {
-                    'result' => 'r',
-                    'parms' => 2,
-                    'opcode' => 36,
-                    'func' => 0,
-                    'types' => 'rr'
-                  },
-          'jumpz' => {
-                       'result' => undef,
-                       'parms' => 1,
-                       'opcode' => 41,
-                       'func' => 0,
-                       'types' => 'r'
-                     },
-          'add' => {
-                     'result' => 'r',
-                     'parms' => 2,
-                     'opcode' => 0,
-                     'func' => 0,
-                     'types' => 'rr'
-                   },
-          'subtract' => {
-                          'result' => 'r',
-                          'parms' => 2,
-                          'opcode' => 1,
-                          'func' => 0,
-                          'types' => 'rr'
-                        },
-          'ret' => {
-                     'result' => undef,
-                     'parms' => 1,
-                     'opcode' => 39,
-                     'func' => 0,
-                     'types' => 'p'
-                   },
-          'hsv' => {
-                     'result' => 'p',
-                     'parms' => 3,
-                     'opcode' => 21,
-                     'func' => 1,
-                     'types' => 'rrr'
-                   },
-          'uminus' => {
-                        'result' => 'r',
-                        'parms' => 1,
-                        'opcode' => 6,
-                        'func' => 0,
-                        'types' => 'r'
-                      }
-        );
-$MaxOperands = 4;
-$PackCode = "i";
-1;
-
-__END__
-
-=head1 NAME
-
-Imager::Regops - generated information about the register based VM
-
-=head1 SYNOPSIS
-
-  use Imager::Regops;
-  $Imager::Regops::Attr{$opname}->{opcode} # opcode for given operator
-  $Imager::Regops::Attr{$opname}->{parms} # number of parameters
-  $Imager::Regops::Attr{$opname}->{types} # types of parameters
-  $Imager::Regops::Attr{$opname}->{func} # operator is a function
-  $Imager::Regops::Attr{$opname}->{result} # r for numeric, p for pixel result
-  $Imager::Regops::MaxOperands; # maximum number of operands
-
-=head1 DESCRIPTION
-
-This module is generated automatically from regmach.h so we don't need to 
-maintain the same information in at least one extra place.
-
-At least that's the idea.
-
-=head1 AUTHOR
-
-Tony Cook, tony@develop-help.com
-
-=head1 SEE ALSO
-
-perl(1), Imager(3), http://www.eecs.umich.edu/~addi/perl/Imager/
-
-=cut
-
diff --git a/t/t64copyflip.t b/t/t64copyflip.t
new file mode 100644 (file)
index 0000000..5ff095f
--- /dev/null
@@ -0,0 +1,58 @@
+BEGIN { $| = 1; print "1..5\n"; }
+END {print "not ok 1\n" unless $loaded;}
+use Imager;
+
+$loaded = 1;
+
+#$Imager::DEBUG=1;
+
+Imager::init('log'=>'testout/t64copyflip.log');
+
+$img=Imager->new() or die "unable to create image object\n";
+
+$img->open(file=>'testimg/scale.ppm',type=>'pnm');
+$nimg = $img->copy() or skip ( "\# warning ".$img->{'ERRSTR'}."\n" );
+print "ok 1\n";
+
+# test if ->copy() works
+
+$diff = Imager::i_img_diff($img->{IMG}, $nimg->{IMG});
+if ($diff > 0) { print "not ok 2 # copy and original differ!\n"; }
+else { print "ok 2\n"; }
+
+
+# test if ->flip(dir=>'h')->flip(dir=>'h') doesn't alter the image
+
+$nimg->flip(dir=>"h")->flip(dir=>"h");
+$diff = Imager::i_img_diff($img->{IMG}, $nimg->{IMG});
+if ($diff > 0) { print "not ok 3 # double horizontal flip and original differ!\n"; }
+else { print "ok 3\n"; }
+
+
+# test if ->flip(dir=>'v')->flip(dir=>'v') doesn't alter the image
+
+$nimg->flip(dir=>"v")->flip(dir=>"v");
+$diff = Imager::i_img_diff($img->{IMG}, $nimg->{IMG});
+if ($diff > 0) { print "not ok 4 # double vertical flip and original differ!\n"; }
+else { print "ok 4\n"; }
+
+
+# test if ->flip(dir=>'h')->flip(dir=>'v') is same as ->flip(dir=>'hv')
+
+$nimg->flip(dir=>"v")->flip(dir=>"h")->flip(dir=>"hv");;
+$diff = Imager::i_img_diff($img->{IMG}, $nimg->{IMG});
+if ($diff > 0) {
+  print "not ok 5 # double flips and original differ!\n";
+  $nimg->write(file=>"testout/t64copyflip_error.ppm") or die $nimg->errstr();
+}
+else { print "ok 5\n"; }
+
+sub skip {
+    print $_[0];
+    print "ok 2 # skip\n";
+    print "ok 3 # skip\n";
+    print "ok 4 # skip\n";
+    print "ok 5 # skip\n";
+    exit(0);
+}
+