]> git.imager.perl.org - imager.git/blobdiff - conv.im
most numeric parameters to the XS implementation now throw an exception if supplied...
[imager.git] / conv.im
diff --git a/conv.im b/conv.im
index b7afa6478df078cb648b9f3d55b0228b82f402c6..ced813ea75ffe500ebfcddbd4193f046cd2e36c4 100644 (file)
--- a/conv.im
+++ b/conv.im
@@ -1,3 +1,4 @@
+#define IMAGER_NO_CONTEXT
 #include "imager.h"
 #include "imageri.h"
 
 #include "imager.h"
 #include "imageri.h"
 
@@ -6,7 +7,7 @@
   end effects are acounted for by increasing
   scaling the result with the sum of used coefficients
 
   end effects are acounted for by increasing
   scaling the result with the sum of used coefficients
 
-  coeff: (float array) coefficients for filter
+  coeff: (double array) coefficients for filter
     len: length of filter.. number of coefficients
            note that this has to be an odd number
            (since the filter is even);
     len: length of filter.. number of coefficients
            note that this has to be an odd number
            (since the filter is even);
 
 int
 i_conv(i_img *im, const double *coeff,int len) {
 
 int
 i_conv(i_img *im, const double *coeff,int len) {
-  int xo, yo; /* output pixel co-ordinate */
+  i_img_dim xo, yo; /* output pixel co-ordinate */
   int c, ch, center;
   double pc;
   double res[MAXCHANNELS];
   i_img *timg;
   int c, ch, center;
   double pc;
   double res[MAXCHANNELS];
   i_img *timg;
+  dIMCTXim(im);
 
 
-  mm_log((1,"i_conv(im %p, coeff %p, len %d)\n",im,coeff,len));
-  i_clear_error();
+  im_log((aIMCTX,1,"i_conv(im %p, coeff %p, len %d)\n",im,coeff,len));
+  im_clear_error(aIMCTX);
+
+  if (len < 1) {
+    im_push_error(aIMCTX, 0, "there must be at least one coefficient");
+    return 0;
+  }
  
   center=(len-1)/2;
 
  
   center=(len-1)/2;
 
@@ -45,7 +52,7 @@ i_conv(i_img *im, const double *coeff,int len) {
       for(ch = 0;ch < im->channels; ch++) 
        res[ch] = 0;
       for(c = 0;c < len; c++) {
       for(ch = 0;ch < im->channels; ch++) 
        res[ch] = 0;
       for(c = 0;c < len; c++) {
-       int xi = xo + c - center;
+       i_img_dim xi = xo + c - center;
        if (xi < 0)
          xi = 0;
        else if (xi >= im->xsize)
        if (xi < 0)
          xi = 0;
        else if (xi >= im->xsize)
@@ -71,7 +78,7 @@ i_conv(i_img *im, const double *coeff,int len) {
       for(ch =  0; ch < im->channels; ch++)
        res[ch] = 0;
       for(c = 0; c < len; c++) {
       for(ch =  0; ch < im->channels; ch++)
        res[ch] = 0;
       for(c = 0; c < len; c++) {
-       int yi = yo + c - center;
+       i_img_dim yi = yo + c - center;
        if (yi < 0)
          yi = 0;
        else if (yi >= im->ysize)
        if (yi < 0)
          yi = 0;
        else if (yi >= im->ysize)