[gegl] affine: parse full 3x3 matrices, try to do perspective



commit 0e03573c6e6b32a4253db5d96a08ff92df5143f9
Author: Mikael Magnusson <mikachu gmail com>
Date:   Tue Aug 9 16:34:31 2011 +0200

    affine: parse full 3x3 matrices, try to do perspective
    
    The code does not produce the correct results yet, it now parses the matrices
    correctly, presumably nothing is using gegl to pass in transforms as strings
    yet.

 gegl/gegl-matrix.c         |    4 ++--
 operations/affine/affine.c |   37 +++++++++++++++++++++++--------------
 2 files changed, 25 insertions(+), 16 deletions(-)
---
diff --git a/gegl/gegl-matrix.c b/gegl/gegl-matrix.c
index e7c9c69..2b191a0 100644
--- a/gegl/gegl-matrix.c
+++ b/gegl/gegl-matrix.c
@@ -259,7 +259,7 @@ gegl_matrix3_parse_string (GeglMatrix3  *matrix,
 
 
       for (i=0;i<3;i++)
-        for (j=0;j<2;j++)
+        for (j=0;j<3;j++)
           {
             a = strtod(p, &p);
             matrix->coeff [j][i] = a;
@@ -279,7 +279,7 @@ gchar *gegl_matrix3_to_string (GeglMatrix3 *matrix)
   gint a=0;
 
   for (i=0;i<3;i++)
-    for (j=0;j<2;j++)
+    for (j=0;j<3;j++)
       {
         if (a!=0)
           g_string_append (str, ",");
diff --git a/operations/affine/affine.c b/operations/affine/affine.c
index d4f73c9..36fe2bd 100644
--- a/operations/affine/affine.c
+++ b/operations/affine/affine.c
@@ -656,8 +656,10 @@ affine_generic (GeglBuffer  *dest,
   GeglMatrix2           inverse_jacobian;
   gdouble               u_start,
                         v_start,
+                        w_start,
                         u_float,
-                        v_float;
+                        v_float,
+                        w_float;
 
   const Babl           *format;
 
@@ -681,35 +683,42 @@ affine_generic (GeglBuffer  *dest,
 
       gegl_matrix3_copy_into (&inverse, matrix);
       gegl_matrix3_invert (&inverse);
+      /* set inverse_jacobian for samplers that support it */
       inverse_jacobian.coeff[0][0] = inverse.coeff[0][0];
       inverse_jacobian.coeff[0][1] = inverse.coeff[0][1];
       inverse_jacobian.coeff[1][0] = inverse.coeff[1][0];
       inverse_jacobian.coeff[1][1] = inverse.coeff[1][1];
 
-     /* set inverse_jacobian for samplers that support it */
       u_start = inverse.coeff[0][0] * roi->x + inverse.coeff[0][1]
                     * roi->y + inverse.coeff[0][2];
       v_start = inverse.coeff[1][0] * roi->x + inverse.coeff[1][1]
                     * roi->y + inverse.coeff[1][2];
+      w_start = inverse.coeff[2][0] * roi->x + inverse.coeff[2][1]
+                    * roi->y + inverse.coeff[2][2];
 
       /* correct rounding on e.g. negative scaling (is this sound?) */
       if (inverse.coeff [0][0] < 0.)  u_start -= .001;
       if (inverse.coeff [1][1] < 0.)  v_start -= .001;
+      if (inverse.coeff [2][1] < 0.)  w_start -= .001;
 
       for (dest_ptr = dest_buf, y = roi->height; y--;)
         {
-           u_float = u_start;
-           v_float = v_start;
-
-           for (x = roi->width; x--;)
-             {
-               gegl_sampler_get (sampler, u_float, v_float, &inverse_jacobian, dest_ptr);
-               dest_ptr+=4;
-               u_float += inverse.coeff [0][0];
-               v_float += inverse.coeff [1][0];
-             }
-           u_start += inverse.coeff [0][1];
-           v_start += inverse.coeff [1][1];
+          u_float = u_start;
+          v_float = v_start;
+          w_float = w_start;
+
+          for (x = roi->width; x--;)
+            {
+              gegl_sampler_get (sampler, u_float/w_float, v_float/w_float, &inverse_jacobian, dest_ptr);
+              dest_ptr+=4;
+              u_float += inverse.coeff [0][0];
+              v_float += inverse.coeff [1][0];
+              w_float += inverse.coeff [2][0];
+            }
+
+          u_start += inverse.coeff [0][1];
+          v_start += inverse.coeff [1][1];
+          w_start += inverse.coeff [2][1];
         }
     }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]