]> granicus.if.org Git - imagemagick/commitdiff
Bug fixes for polynomial distort
authoranthony <anthony@git.imagemagick.org>
Wed, 4 Nov 2009 07:28:07 +0000 (07:28 +0000)
committeranthony <anthony@git.imagemagick.org>
Wed, 4 Nov 2009 07:28:07 +0000 (07:28 +0000)
ChangeLog
magick/distort.c

index f662cf3eeef5177b28b026be29752a7c1a7f95b7..efc7a59e5ec2165774f635ae4bfba7d87de73dfe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2009-11-04  6.5.7-5 Anthony Thyssen <A.Thyssen@griffith...>
+  * Bug Fix for Polynomial distortion. which is now working.
+
 2009-11-01  6.5.7-4 Cristy  <quetzlzacatenango@image...>
   * Use -define delegate:bimodal=true to activate any bimodal delegates.
   * Make sure MagickWand semaphore is acquired before locking it.
index 8892cb3e32658b2d45023bd92e64600bd7dc124c..bd549484eb41854388900831c274375b723f30ab 100644 (file)
@@ -348,7 +348,7 @@ static double *GenerateCoefficients(const Image *image,
   /* If not enough control point pairs are found for specific distortions
     fall back to Affine distortion (allowing 0 to 3 point pairs)
   */
-  if ( number_arguments < 4*cp_size &&
+  if ( number_arguments < 4*cp_size && 
        (  *method == BilinearForwardDistortion
        || *method == BilinearReverseDistortion
        || *method == PerspectiveDistortion
@@ -375,7 +375,7 @@ static double *GenerateCoefficients(const Image *image,
       if ( i == 0 ) {
         (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
                    "InvalidArgument","%s : '%s'","Polynomial",
-                   "Invalid order, should be 1 to 5, or 1.5");
+                   "Invalid order, should be interger 1 to 5, or 1.5");
         return((double *) NULL);
       }
       if ( number_arguments < 1+i*cp_size ) {
@@ -732,6 +732,14 @@ static double *GenerateCoefficients(const Image *image,
       MagickBooleanType
         status;
 
+      if ( number_arguments%cp_size != 0 ||
+           number_arguments < cp_size*4 ) {
+        (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
+               "InvalidArgument", "%s : 'require at least %ld CPs'",
+               "Perspective", 4L);
+        coeff=(double *) RelinquishMagickMemory(coeff);
+        return((double *) NULL);
+      }
       /* fake 1x8 vectors matrix directly using the coefficients array */
       vectors[0] = &(coeff[0]);
       /* 8x8 least-squares matrix (zeroed) */
@@ -839,6 +847,16 @@ static double *GenerateCoefficients(const Image *image,
       MagickBooleanType
         status;
 
+      /* check the number of arguments */
+      if ( number_arguments%cp_size != 0 ||
+           number_arguments < cp_size*4 ) {
+        (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
+               "InvalidArgument", "%s : 'require at least %ld CPs'",
+               *method == BilinearForwardDistortion ? "BilinearForward" :
+               "BilinearReverse", 4L);
+        coeff=(double *) RelinquishMagickMemory(coeff);
+        return((double *) NULL);
+      }
       /* create matrix, and a fake vectors matrix */
       matrix = AcquireMagickMatrix(4UL,4UL);
       vectors = (double **) AcquireQuantumMemory(number_values,sizeof(*vectors));
@@ -1002,7 +1020,7 @@ static double *GenerateCoefficients(const Image *image,
       for (i=0; i < number_values; i++)
         vectors[i] = &(coeff[2+i*nterms]);
       /* Add given control point pairs for least squares solving */
-      for (i=0; i < number_arguments; i+=cp_size) {
+      for (i=1; i < number_arguments; i+=cp_size) { /* NB: start = 1 not 0 */
         for (j=0; j < (long) nterms; j++)
           terms[j] = poly_basis_fn(j,arguments[i+cp_x],arguments[i+cp_y]);
         LeastSquaresAddTerms(matrix,vectors,terms,