temporary scaling test code, proper defaults for crop().
authorArnar Mar Hrafnkelsson <addi@cpan.org>
Thu, 8 Aug 2002 06:00:51 +0000 (06:00 +0000)
committerArnar Mar Hrafnkelsson <addi@cpan.org>
Thu, 8 Aug 2002 06:00:51 +0000 (06:00 +0000)
Changes
Imager.pm
image.c
lib/Imager/Regops.pm

diff --git a/Changes b/Changes
index 5bf3233..eca7192 100644 (file)
--- a/Changes
+++ b/Changes
@@ -675,7 +675,8 @@ Revision history for Perl extension Imager.
                                - Fixed tiff handling of images all contained in a 
                                        single strip (rowsperstrip = -1) and added a hack
                                        for images missing the rowsperstrip tag.
-                                       
+                               - Fixed default parameters for crop()
+                               - Added Preliminary specialized scaling code.
 =================================================================
 
         For latest versions check the Imager-devel pages:
index 805d01e..9ebcffc 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -568,7 +568,7 @@ sub paste {
 sub crop {
   my $self=shift;
   unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
-  my %hsh=(left=>0,right=>0,top=>0,bottom=>0,@_);
+  my %hsh=(left=>0,right=>$self->getwidth(),top=>0,bottom=>$self->getheight(),@_);
 
   my ($w,$h,$l,$r,$b,$t)=($self->getwidth(),$self->getheight(),
                                @hsh{qw(left right bottom top)});
diff --git a/image.c b/image.c
index b4c7100..a95313a 100644 (file)
--- a/image.c
+++ b/image.c
@@ -867,6 +867,99 @@ Lanczos(float x) {
   else return(sin(PIx) / PIx * sin(PIx2) / PIx2);
 }
 
+
+
+
+
+
+
+
+
+i_img*
+i_scaleaxis_3ch_8bit(i_img *im, int size, int Axis) {
+
+  int i, j;
+  int iEnd, jEnd;
+
+  int hsize, vsize;
+
+  short psave;
+  unsigned long *pixels;
+  i_color val;
+  i_img *new_img;
+
+  mm_log((1,"i_scaleaxis_3ch_8bit(im %p, size %d,Axis %d)\n",im, size, Axis));
+
+  if (Axis == XAXIS) {
+    hsize = size;
+    vsize = im->ysize;
+    
+    jEnd = hsize;
+    iEnd = vsize;
+    pixels = mymalloc(sizeof(*pixels) * im->xsize);
+  } else {
+    hsize = im->xsize;
+    vsize = size;
+    
+    jEnd = vsize;
+    iEnd = hsize;
+    pixels = mymalloc(sizeof(*pixels) * im->ysize);
+  }
+  
+  new_img = i_img_empty_ch(NULL, hsize, vsize, im->channels);
+
+
+  if (Axis == XAXIS) {
+    
+    for (i=0; i<iEnd; i++) {
+      int end = im->xsize;
+
+      for(j=0; j<im->xsize; j++) {
+       i_gpix(im, j, i, &val);
+       pixels[j] = (val.rgba.r<<24) | (val.rgba.g<<16) | (val.rgba.b<<8) | (val.rgba.a<<0);
+      }
+      
+      /* printf("jEnd = %d, end = %d\n", jEnd, end); */
+      while ((end+1)/2>=size) {
+       int lend = end/2;
+       end = (end+1) / 2;
+       
+       for(j=0; j<lend; j++) {
+         unsigned long a = pixels[2*j];
+         unsigned long b = pixels[2*j+1];
+         pixels[j] = (((a ^ b) & 0xfefefefeUL) >> 1) + (a & b);
+       }
+       if (end>lend) {
+         pixels[j] = pixels[2*j];
+         j++;
+       }
+      }
+
+      printf("end = %d size = %d\n", end, size);
+
+      /* Replace this with Bresenham later */
+      for(j=0; j<size; j++) {
+       float f = i;
+         /*    if ((i*size)/end <)  */
+         unsigned long t = pixels[j];
+       val.rgba.r = (t >> 24) & 0xff;
+       val.rgba.g = (t >> 16) & 0xff;
+       val.rgba.b = (t >> 8) & 0xff;
+       val.rgba.a = t & 0xff;
+       i_ppix(new_img, j, i, &val);
+      }
+    }
+  }
+  
+  return new_img;
+}
+
+
+
+
+
+
+
 /*
 =item i_scaleaxis(im, value, axis)
 
@@ -890,7 +983,10 @@ i_scaleaxis(i_img *im, float Value, int Axis) {
 
   mm_log((1,"i_scaleaxis(im %p,Value %.2f,Axis %d)\n",im,Value,Axis));
 
+
   if (Axis == XAXIS) {
+    return i_scaleaxis_3ch_8bit(im, (int)(0.5+im->xsize*Value), Axis);
+
     hsize = (int)(0.5 + im->xsize * Value);
     vsize = im->ysize;
     
index e4d2770..01712f1 100644 (file)
@@ -57,335 +57,335 @@ 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',
+          'or' => {
+                    'opcode' => 36,
                     'parms' => 2,
-                    'opcode' => 30,
-                    'func' => 0,
-                    'types' => 'rr'
+                    'func' => '0',
+                    'types' => 'rr',
+                    'result' => 'r'
                   },
-          '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'
+                       'types' => 'rr',
+                       'result' => 'p'
                      },
+          'uminus' => {
+                        'opcode' => 6,
+                        'parms' => 1,
+                        'func' => '0',
+                        'types' => 'r',
+                        'result' => 'r'
+                      },
           'getp2' => {
-                       'result' => 'p',
-                       'parms' => 2,
                        'opcode' => 16,
+                       'parms' => 2,
                        'func' => 1,
-                       'types' => 'rr'
+                       'types' => 'rr',
+                       'result' => 'p'
                      },
           'getp3' => {
-                       'result' => 'p',
-                       'parms' => 2,
                        'opcode' => 17,
+                       'parms' => 2,
                        'func' => 1,
-                       'types' => 'rr'
+                       'types' => 'rr',
+                       'result' => 'p'
                      },
-          'value' => {
-                       'result' => 'r',
+          'jumpnz' => {
+                        'opcode' => 42,
+                        'parms' => 1,
+                        'func' => '0',
+                        'types' => 'r',
+                        'result' => undef
+                      },
+          'op_count' => {
+                          'opcode' => 46,
+                          'parms' => '0',
+                          'func' => '0',
+                          'types' => '',
+                          'result' => undef
+                        },
+          'blue' => {
+                      'opcode' => 24,
+                      'parms' => 1,
+                      'func' => 1,
+                      'types' => 'p',
+                      'result' => 'r'
+                    },
+          'int' => {
+                     'opcode' => 26,
+                     'parms' => 1,
+                     'func' => 1,
+                     'types' => 'r',
+                     'result' => 'r'
+                   },
+          'le' => {
+                    'opcode' => 29,
+                    'parms' => 2,
+                    'func' => '0',
+                    'types' => 'rr',
+                    'result' => 'r'
+                  },
+          'multp' => {
+                       'opcode' => 7,
+                       'parms' => 2,
+                       'func' => '0',
+                       'types' => 'pr',
+                       'result' => 'p'
+                     },
+          'ne' => {
+                    'opcode' => 34,
+                    'parms' => 2,
+                    'func' => '0',
+                    'types' => 'rr',
+                    'result' => 'r'
+                  },
+          'jumpz' => {
+                       'opcode' => 41,
                        'parms' => 1,
-                       'opcode' => 18,
+                       'func' => '0',
+                       'types' => 'r',
+                       'result' => undef
+                     },
+          'atan2' => {
+                       'opcode' => 12,
+                       'parms' => 2,
                        'func' => 1,
-                       'types' => 'p'
+                       'types' => 'rr',
+                       'result' => 'r'
                      },
           'subtractp' => {
-                           'result' => 'p',
-                           'parms' => 2,
                            'opcode' => 9,
-                           'func' => 0,
-                           'types' => 'pp'
+                           'parms' => 2,
+                           'func' => '0',
+                           'types' => 'pp',
+                           'result' => 'p'
                          },
-          'ge' => {
-                    'result' => 'r',
-                    'parms' => 2,
-                    'opcode' => 31,
-                    'func' => 0,
-                    'types' => 'rr'
-                  },
-          'sat' => {
-                     'result' => 'r',
+          'rgb' => {
+                     'opcode' => 25,
+                     'parms' => 3,
+                     'func' => 1,
+                     'types' => 'rrr',
+                     'result' => 'p'
+                   },
+          'red' => {
+                     'opcode' => 22,
                      'parms' => 1,
-                     'opcode' => 20,
                      'func' => 1,
-                     'types' => 'p'
+                     'types' => 'p',
+                     'result' => 'r'
                    },
+          'setp' => {
+                      'opcode' => 44,
+                      'parms' => 1,
+                      'func' => '0',
+                      'types' => 'p',
+                      'result' => 'p'
+                    },
           'jump' => {
-                      'result' => undef,
-                      'parms' => 0,
                       'opcode' => 40,
-                      'func' => 0,
-                      'types' => ''
+                      'parms' => '0',
+                      'func' => '0',
+                      'types' => '',
+                      'result' => undef
                     },
-          'if' => {
-                    'result' => 'r',
-                    'parms' => 3,
-                    'opcode' => 27,
-                    'func' => 1,
-                    'types' => 'rrr'
+          'value' => {
+                       'opcode' => 18,
+                       'parms' => 1,
+                       'func' => 1,
+                       'types' => 'p',
+                       'result' => 'r'
+                     },
+          'mod' => {
+                     'opcode' => 4,
+                     'parms' => 2,
+                     'func' => '0',
+                     'types' => 'rr',
+                     'result' => 'r'
+                   },
+          'lt' => {
+                    'opcode' => 30,
+                    'parms' => 2,
+                    'func' => '0',
+                    'types' => 'rr',
+                    'result' => 'r'
                   },
+          'mult' => {
+                      'opcode' => 2,
+                      'parms' => 2,
+                      'func' => '0',
+                      'types' => 'rr',
+                      'result' => 'r'
+                    },
+          'hue' => {
+                     'opcode' => 19,
+                     'parms' => 1,
+                     'func' => 1,
+                     'types' => 'p',
+                     'result' => 'r'
+                   },
           'div' => {
-                     'result' => 'r',
-                     'parms' => 2,
                      'opcode' => 3,
-                     'func' => 0,
-                     'types' => 'rr'
+                     'parms' => 2,
+                     'func' => '0',
+                     'types' => 'rr',
+                     'result' => 'r'
                    },
-          'ifp' => {
-                     'result' => 'p',
-                     'parms' => 3,
-                     'opcode' => 28,
+          'cos' => {
+                     'opcode' => 11,
+                     'parms' => 1,
                      'func' => 1,
-                     'types' => 'rpp'
+                     'types' => 'r',
+                     'result' => 'r'
                    },
-          'set' => {
-                     'result' => 'r',
+          'subtract' => {
+                          'opcode' => 1,
+                          'parms' => 2,
+                          'func' => '0',
+                          'types' => 'rr',
+                          'result' => 'r'
+                        },
+          'sat' => {
+                     'opcode' => 20,
                      'parms' => 1,
-                     'opcode' => 43,
-                     'func' => 0,
-                     'types' => 'r'
+                     'func' => 1,
+                     'types' => 'p',
+                     'result' => 'r'
+                   },
+          'add' => {
+                     'opcode' => '0',
+                     'parms' => 2,
+                     'func' => '0',
+                     'types' => 'rr',
+                     'result' => '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,
+                     'parms' => 1,
                      'func' => 1,
-                     'types' => 'r'
+                     'types' => 'r',
+                     'result' => 'r'
                    },
           'sqrt' => {
-                      'result' => 'r',
-                      'parms' => 1,
                       'opcode' => 13,
+                      'parms' => 1,
                       'func' => 1,
-                      'types' => 'r'
+                      'types' => 'r',
+                      'result' => 'r'
                     },
+          'ret' => {
+                     'opcode' => 39,
+                     'parms' => 1,
+                     'func' => '0',
+                     'types' => 'p',
+                     'result' => undef
+                   },
           'distance' => {
-                          'result' => 'r',
-                          'parms' => 4,
                           'opcode' => 14,
+                          'parms' => 4,
                           'func' => 1,
-                          'types' => 'rrrr'
+                          'types' => 'rrrr',
+                          'result' => 'r'
                         },
-          'gt' => {
-                    'result' => 'r',
+          'set' => {
+                     'opcode' => 43,
+                     'parms' => 1,
+                     'func' => '0',
+                     'types' => 'r',
+                     'result' => 'r'
+                   },
+          'ge' => {
+                    'opcode' => 31,
                     'parms' => 2,
-                    'opcode' => 32,
-                    'func' => 0,
-                    'types' => 'rr'
+                    'func' => '0',
+                    'types' => 'rr',
+                    'result' => 'r'
                   },
-          'red' => {
-                     'result' => 'r',
+          'print' => {
+                       'opcode' => 45,
+                       'parms' => 1,
+                       'func' => '0',
+                       'types' => 'r',
+                       'result' => undef
+                     },
+          'if' => {
+                    'opcode' => 27,
+                    'parms' => 3,
+                    'func' => 1,
+                    'types' => 'rrr',
+                    'result' => 'r'
+                  },
+          'not' => {
+                     'opcode' => 37,
                      'parms' => 1,
-                     'opcode' => 22,
-                     'func' => 1,
-                     'types' => 'p'
+                     'func' => '0',
+                     'types' => 'r',
+                     'result' => 'r'
                    },
-          'rgb' => {
-                     'result' => 'p',
+          'hsv' => {
+                     'opcode' => 21,
                      'parms' => 3,
-                     'opcode' => 25,
-                     'func' => 1,
-                     'types' => 'rrr'
-                   },
-          'hue' => {
-                     'result' => 'r',
-                     'parms' => 1,
-                     'opcode' => 19,
                      'func' => 1,
-                     'types' => 'p'
+                     'types' => 'rrr',
+                     'result' => 'p'
                    },
-          'print' => {
-                       'result' => undef,
+          'green' => {
+                       'opcode' => 23,
                        'parms' => 1,
-                       'opcode' => 45,
-                       'func' => 0,
-                       'types' => 'r'
+                       'func' => 1,
+                       'types' => 'p',
+                       'result' => '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',
+          'and' => {
+                     'opcode' => 35,
+                     'parms' => 2,
+                     'func' => '0',
+                     'types' => 'rr',
+                     'result' => 'r'
+                   },
+          'abs' => {
+                     'opcode' => 38,
                      'parms' => 1,
-                     'opcode' => 26,
                      'func' => 1,
-                     'types' => 'r'
+                     'types' => 'r',
+                     'result' => 'r'
                    },
-          'op_count' => {
-                          'result' => undef,
-                          'parms' => 0,
-                          'opcode' => 46,
-                          'func' => 0,
-                          'types' => ''
-                        },
-          'or' => {
-                    'result' => 'r',
+          'eq' => {
+                    'opcode' => 33,
                     'parms' => 2,
-                    'opcode' => 36,
-                    'func' => 0,
-                    'types' => 'rr'
+                    'func' => '0',
+                    'types' => 'rr',
+                    'result' => 'r'
                   },
-          'jumpz' => {
-                       'result' => undef,
-                       'parms' => 1,
-                       'opcode' => 41,
-                       'func' => 0,
-                       'types' => 'r'
-                     },
-          'add' => {
-                     'result' => 'r',
+          'pow' => {
+                     'opcode' => 5,
                      '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'
+                     'func' => '0',
+                     'types' => 'rr',
+                     'result' => 'r'
                    },
-          'hsv' => {
-                     'result' => 'p',
+          'addp' => {
+                      'opcode' => 8,
+                      'parms' => 2,
+                      'func' => '0',
+                      'types' => 'pp',
+                      'result' => 'p'
+                    },
+          'gt' => {
+                    'opcode' => 32,
+                    'parms' => 2,
+                    'func' => '0',
+                    'types' => 'rr',
+                    'result' => 'r'
+                  },
+          'ifp' => {
+                     'opcode' => 28,
                      'parms' => 3,
-                     'opcode' => 21,
                      'func' => 1,
-                     'types' => 'rrr'
-                   },
-          'uminus' => {
-                        'result' => 'r',
-                        'parms' => 1,
-                        'opcode' => 6,
-                        'func' => 0,
-                        'types' => 'r'
-                      }
+                     'types' => 'rpp',
+                     'result' => 'p'
+                   }
         );
 $MaxOperands = 4;
 $PackCode = "i";