[gegl/soc-2011-seamless-clone: 6/23] Lots of bug fixing, the operations now works



commit aa6b46d301933140724bae53a627c669c8c5907a
Author: Barak Itkin <lightningismyname gmail com>
Date:   Wed Aug 3 00:11:10 2011 +0300

    Lots of bug fixing, the operations now works

 operations/common/seamless-clone/make-mesh.c       |    2 +-
 .../seamless-clone/poly2tri-c/render/mesh-render.c |   20 +++++---
 operations/common/seamless-clone/seamless-clone.c  |   49 +++++++++++++++-----
 3 files changed, 50 insertions(+), 21 deletions(-)
---
diff --git a/operations/common/seamless-clone/make-mesh.c b/operations/common/seamless-clone/make-mesh.c
index b45ce18..2c2b292 100644
--- a/operations/common/seamless-clone/make-mesh.c
+++ b/operations/common/seamless-clone/make-mesh.c
@@ -126,7 +126,7 @@ sc_compute_sample_list_weights (gdouble        Px,
 
       temp = (dx1 * dx2 + dy1 * dy2) / (norm1 * norm2);
 
-      if (temp > 1)
+      if (temp <= 1 && temp >= -1)
         {
 		  /* Result is in the range of 0 to PI */
           ang = acos (temp);
diff --git a/operations/common/seamless-clone/poly2tri-c/render/mesh-render.c b/operations/common/seamless-clone/poly2tri-c/render/mesh-render.c
index 1785059..34317ac 100755
--- a/operations/common/seamless-clone/poly2tri-c/render/mesh-render.c
+++ b/operations/common/seamless-clone/poly2tri-c/render/mesh-render.c
@@ -119,8 +119,12 @@ p2tr_triangulation_locate_point2 (P2tRTriangulation *T,
       P2trHashSetIter iter;
       p2tr_hash_set_iter_init (&iter, T->tris);
       while (p2tr_hash_set_iter_next (&iter, (gpointer*)&tr))
-        if (p2tr_triangle_compute_barycentric_coords (tr, Px, Py, u, v))
-          return tr;
+        {
+          if (p2tr_triangule_quick_box_test (tr, Px, Py))
+            continue;
+          else if (p2tr_triangle_compute_barycentric_coords (tr, Px, Py, u, v))
+            return tr;
+        }
       return NULL;
     }
   else
@@ -202,8 +206,8 @@ p2tr_mesh_render_scanline (P2tRTriangulation    *T,
 
   tribuf[0] = p2tr_triangulation_locate_point2 (T, config->min_x, config->min_y, NULL, &uvbuf[0], &uvbuf[1]);
 
-  for (x = 0; x < config->x_samples; x++)
-    for (y = 0; y < config->y_samples; y++)
+  for (y = 0; y < config->y_samples; y++)
+    for (x = 0; x < config->x_samples; x++)
     {
       gdouble Px = config->min_x + x * config->step_x;
       gdouble Py = config->min_y + y * config->step_y;
@@ -226,12 +230,12 @@ p2tr_mesh_render_scanline (P2tRTriangulation    *T,
   GTimer *timer = g_timer_new ();
   g_timer_start (timer);
 
-  for (x = 0; x < config->x_samples; x++)
-    for (y = 0; y < config->y_samples; y++)
+  for (y = 0; y < config->y_samples; y++)
+    for (x = 0; x < config->x_samples; x++)
     {
         gdouble u = Puv[0], v = Puv[1];
         tr_now = *Ptri++;
-        uvbuf++;
+        Puv += 2;
         
         if (tr_now == NULL)
           {
@@ -287,4 +291,4 @@ p2tr_write_ppm (FILE            *f,
         }
       fprintf (f, "\n");
     }
-}
\ No newline at end of file
+}
diff --git a/operations/common/seamless-clone/seamless-clone.c b/operations/common/seamless-clone/seamless-clone.c
index 9ad3941..35e844d 100644
--- a/operations/common/seamless-clone/seamless-clone.c
+++ b/operations/common/seamless-clone/seamless-clone.c
@@ -87,29 +87,32 @@ sc_point_to_color_func (P2tRPoint *point,
   ScSampleList       *sl = g_hash_table_lookup (cci->sampling, point);
   gfloat aux_c[4], input_c[4], dest_c[3] = {0, 0, 0};
   gint i;
+  gdouble weightT = 0;
   guint N = sl->points->len;
-  
+
   Babl *format = babl_format ("RGBA float");
 
   for (i = 0; i < N; i++)
     {
-      P2tRPoint *pt = g_ptr_array_index (sl->points, i);
+      ScPoint *pt = g_ptr_array_index (sl->points, i);
       gdouble weight = g_array_index (sl->weights, gdouble, i);
+      // g_print ("%f+",weight);
 
-      g_assert (format != NULL);
       gegl_buffer_sample (cci->aux_buf, pt->x, pt->y, NULL, aux_c, format, GEGL_INTERPOLATION_NEAREST);
-      g_assert (format != NULL);
       gegl_buffer_sample (cci->input_buf, pt->x, pt->y, NULL, input_c, format, GEGL_INTERPOLATION_NEAREST);
       
-      dest_c[0] = weight * (input_c[0] - aux_c[0]);
-      dest_c[1] = weight * (input_c[1] - aux_c[1]);
-      dest_c[2] = weight * (input_c[2] - aux_c[2]);
+      dest_c[0] += weight * (input_c[0] - aux_c[0]);
+      dest_c[1] += weight * (input_c[1] - aux_c[1]);
+      dest_c[2] += weight * (input_c[2] - aux_c[2]);
+      weightT += weight;
 	}
 
-  dest[0] = dest_c[0] / sl->total_weight;
-  dest[1] = dest_c[1] / sl->total_weight;
-  dest[2] = dest_c[2] / sl->total_weight;
+  // g_print ("=%f\n",weightT);
+  dest[0] = dest_c[0] / weightT;
+  dest[1] = dest_c[1] / weightT;
+  dest[2] = dest_c[2] / weightT;
   dest[3] = 1;
+  //g_print ("(%f,%f,%f)",dest[0],dest[1],dest[2]);
 }
 
 static gboolean
@@ -119,7 +122,8 @@ process (GeglOperation       *operation,
          GeglBuffer          *output,
          const GeglRectangle *result)
 {
-  gfloat    *aux_raw, *out_raw;
+  gfloat    *aux_raw, *out_raw, *pixel;
+  gdouble    x, y;
 
   GeglRectangle aux_rect = *gegl_operation_source_get_bounding_box (operation, "aux");
 
@@ -133,6 +137,8 @@ process (GeglOperation       *operation,
   ScColorComputeInfo  cci;
   P2tRImageConfig     imcfg;
 
+  Babl               *format = babl_format("RGBA float");
+
   g_debug ("seamless-clone.c::process");
   printf ("The aux_rect is: ");
   gegl_rectangle_dump (&aux_rect);
@@ -143,7 +149,7 @@ process (GeglOperation       *operation,
   
   /* First, find the paste outline */
   aux_raw = g_new (gfloat, 4 * aux_rect.width * aux_rect.height);
-  gegl_buffer_get (aux, 1.0, &aux_rect, babl_format("RGBA float"), aux_raw, GEGL_AUTO_ROWSTRIDE);
+  gegl_buffer_get (aux, 1.0, &aux_rect, format, aux_raw, GEGL_AUTO_ROWSTRIDE);
 
   g_debug ("Start making outline");
   outline = sc_outline_find_ccw (&aux_rect, aux_raw);
@@ -187,6 +193,25 @@ process (GeglOperation       *operation,
   p2tr_mesh_render_scanline (mesh, out_raw, &imcfg, sc_point_to_color_func, &cci);
   g_debug ("Finish mesh rendering");
 
+  g_debug ("Start aux adding");
+  pixel = out_raw;
+
+  pixel = out_raw;
+  for (y = 0; y < imcfg.y_samples; y++)
+    for (x = 0; x < imcfg.x_samples; x++)
+      {
+        gfloat aux_c[4];
+        gdouble Px = imcfg.min_x + x * imcfg.step_x;
+        gdouble Py = imcfg.min_y + y * imcfg.step_y;
+        gegl_buffer_sample (aux, Px, Py, NULL, aux_c, format, GEGL_INTERPOLATION_NEAREST);
+        *pixel++ += aux_c[0];
+        *pixel++ += aux_c[1];
+        *pixel++ += aux_c[2];
+        *pixel++;// += 0;//aux_c[3];
+      }
+
+  g_debug ("Finish aux adding");
+  
   /* TODO: Add the aux to the mesh rendering! */
   gegl_buffer_set (output, result, babl_format("RGBA float"), out_raw, GEGL_AUTO_ROWSTRIDE);
 



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