[gegl] Handle most cases where parts of the paste are outside the background



commit 1baf5e917e313606aec457e8721b10551b3aff0c
Author: Barak Itkin <lightningismyname gmail com>
Date:   Sat Aug 20 00:04:38 2011 +0300

    Handle most cases where parts of the paste are outside the background
    
    Since we can't compute the color difference of an outline point if it's
    outside the background bounds, we will simply ignore it in the weighted
    average. This removes the artifacts that appeared from such cases.
    
    Note that this doesn't solve the problem where all selected sample
    points are outside the background, but the algorithm isn't really meant
    for handling such cases so this is the best we can do.

 .../common/seamless-clone/seamless-clone-render.c  |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/operations/common/seamless-clone/seamless-clone-render.c 
b/operations/common/seamless-clone/seamless-clone-render.c
index 6c8ab9c..ce4bf90 100644
--- a/operations/common/seamless-clone/seamless-clone-render.c
+++ b/operations/common/seamless-clone/seamless-clone-render.c
@@ -81,7 +81,7 @@ typedef struct {
   GeglBuffer     *input_buf;
   ScMeshSampling *sampling;
   GHashTable     *pt2col;
-
+  GeglRectangle   bg_rect;
   /* Offset to be applied to the paste */
   gint x, y;
 } ScColorComputeInfo;
@@ -120,6 +120,22 @@ sc_point_to_color_func (P2tRPoint *point,
       ScPoint *pt = g_ptr_array_index (sl->points, i);
       gdouble weight = g_array_index (sl->weights, gdouble, i);
 
+      /* The original outline point is on (pt->x,pt->y) in terms of mesh
+       * coordinates. But, since we are translating, it's location in
+       * background coordinates is (pt->x + cci->x, pt->y + cci->y)
+       */
+       
+      /* If the outline point is outside the background, then we can't
+       * compute a propper difference there. So, don't add it to the
+       * sampling */
+#define sc_rect_contains(rect,x0,y0) \
+     (((x0) >= (rect).x) && ((x0) < (rect).x + (rect).width)  \
+   && ((y0) >= (rect).y) && ((y0) < (rect).y + (rect).height))
+
+      if (! sc_rect_contains (cci->bg_rect, pt->x + cci->x, pt->y + cci->y)) { continue;}
+
+#undef sc_rect_contains
+
       gegl_buffer_sample (cci->aux_buf, pt->x, pt->y, NULL, aux_c, format, GEGL_INTERPOLATION_NEAREST);
       /* Sample the BG with the offset */
       gegl_buffer_sample (cci->input_buf, pt->x + cci->x, pt->y + cci->y, NULL, input_c, format, 
GEGL_INTERPOLATION_NEAREST);
@@ -187,6 +203,8 @@ process (GeglOperation       *operation,
   cci.x = o->x;
   cci.y = o->y;
 
+  cci.bg_rect = *gegl_operation_source_get_bounding_box (operation, "input");
+
   /* Render as if there is no offset, since the mesh has no offset */
   mesh_rect.x = imcfg.min_x = to_render.x - o->x;
   mesh_rect.y = imcfg.min_y = to_render.y - o->y;


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