Commit 066d360e authored by Barak Itkin's avatar Barak Itkin
Browse files

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.
parent ddf14282
......@@ -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;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment