Commit ddf14282 authored by Barak Itkin's avatar Barak Itkin
Browse files

Make the two-step seamless clone realtime!

parent 570bb34d
......@@ -200,7 +200,16 @@ p2tr_mesh_render_cache_uvt (P2tRTriangulation *T,
P2tRuvt *dest,
P2tRImageConfig *config)
{
gint x, y;
p2tr_mesh_render_cache_uvt_exact (T, dest, config->x_samples * config->y_samples, config);
}
void
p2tr_mesh_render_cache_uvt_exact (P2tRTriangulation *T,
P2tRuvt *dest,
gint dest_len,
P2tRImageConfig *config)
{
gint x, y, n = dest_len;
P2tRuvt *uvt = dest;
P2tRTriangle *tr_prev = NULL;
......@@ -210,6 +219,7 @@ p2tr_mesh_render_cache_uvt (P2tRTriangulation *T,
for (y = 0; y < config->y_samples; y++)
for (x = 0; x < config->x_samples; x++)
{
if (n-- == 0) return;
gdouble Px = config->min_x + x * config->step_x;
gdouble Py = config->min_y + y * config->step_y;
uvt3_t(uvt) = p2tr_triangulation_locate_point2 (T, Px, Py, tr_prev, &uvt3_u(uvt), &uvt3_v(uvt));
......@@ -218,6 +228,7 @@ p2tr_mesh_render_cache_uvt (P2tRTriangulation *T,
}
}
void
p2tr_mesh_render_scanline (P2tRTriangulation *T,
gfloat *dest,
......
......@@ -40,6 +40,14 @@ p2tr_mesh_render_cache_uvt (P2tRTriangulation *T,
P2tRuvt *dest,
P2tRImageConfig *config);
/* Like the regular version, but cache only the specified amount of
* pixels */
void
p2tr_mesh_render_cache_uvt_exact (P2tRTriangulation *T,
P2tRuvt *dest,
gint dest_len,
P2tRImageConfig *config);
void
p2tr_mesh_render_scanline (P2tRTriangulation *T,
gfloat *dest,
......
......@@ -65,6 +65,10 @@ process (GeglOperation *operation,
ScPreprocessResult *result = sc_preprocess_new ();
gpointer *dest = GEGL_CHANT_PROPERTIES (operation) -> result;
GeglBuffer *uvt;
GeglBufferIterator *iter;
P2tRImageConfig config;
if (dest == NULL)
{
return FALSE;
......@@ -82,6 +86,22 @@ process (GeglOperation *operation,
/* If caching of UV is desired, it shold be done here, and possibly
* by using a regular operation rather than a sink one, so that we can
* output UV coords */
result->uvt = gegl_buffer_new (roi, babl_uvt_format);
iter = gegl_buffer_iterator_new (result->uvt, roi, NULL, GEGL_BUFFER_WRITE);
config.step_x = config.step_y = 1;
config.cpp = 4; /* Not that it will be used, but it won't harm */
while (gegl_buffer_iterator_next (iter))
{
config.min_x = iter->roi[0].x;
config.min_y = iter->roi[0].y;
config.x_samples = iter->roi[0].width;
config.y_samples = iter->roi[0].height;
p2tr_mesh_render_cache_uvt_exact (result->mesh, (P2tRuvt*) iter->data[0], iter->length, &config);
}
/* No need to free the iterator */
*dest = result;
......@@ -89,6 +109,7 @@ process (GeglOperation *operation,
sc_mesh_sampling_free (mesh_sampling);
p2tr_triangulation_free (mesh);
sc_outline_free (outline);
gegl_buffer_destroy (uvt);
*/
return TRUE;
......
......@@ -147,10 +147,11 @@ process (GeglOperation *operation,
ScPreprocessResult *spr = o->prepare;
gfloat *out_raw, *pixel;
P2tRuvt *uvt_raw;
gdouble x, y;
GeglRectangle aux_rect = *gegl_operation_source_get_bounding_box (operation, "aux");
GeglRectangle to_render;
GeglRectangle to_render, mesh_rect;
ScColorComputeInfo cci;
P2tRImageConfig imcfg;
......@@ -173,6 +174,7 @@ process (GeglOperation *operation,
/* Alocate the output buffer */
out_raw = g_new (gfloat, 4 * to_render.width * to_render.height);
uvt_raw = g_new (P2tRuvt, 3 * to_render.width * to_render.height);
/* Render the mesh into it */
cci.aux_buf = aux;
......@@ -186,14 +188,15 @@ process (GeglOperation *operation,
cci.y = o->y;
/* Render as if there is no offset, since the mesh has no offset */
imcfg.min_x = to_render.x - o->x;
imcfg.min_y = to_render.y - o->y;
mesh_rect.x = imcfg.min_x = to_render.x - o->x;
mesh_rect.y = imcfg.min_y = to_render.y - o->y;
imcfg.step_x = imcfg.step_y = 1;
imcfg.x_samples = to_render.width;
imcfg.y_samples = to_render.height;
mesh_rect.width = imcfg.x_samples = to_render.width;
mesh_rect.height = imcfg.y_samples = to_render.height;
imcfg.cpp = 4;
p2tr_mesh_render_scanline (spr->mesh, out_raw, &imcfg, sc_point_to_color_func, &cci);
gegl_buffer_get (spr->uvt, 1.0, &mesh_rect, babl_uvt_format, uvt_raw, GEGL_AUTO_ROWSTRIDE);
p2tr_mesh_render_scanline2 (uvt_raw, out_raw, &imcfg, sc_point_to_color_func, &cci);
pixel = out_raw;
......@@ -217,6 +220,7 @@ process (GeglOperation *operation,
gegl_buffer_set (output, &to_render, babl_format("R'G'B'A float"), out_raw, GEGL_AUTO_ROWSTRIDE);
g_free (out_raw);
g_free (uvt_raw);
g_hash_table_destroy (cci.pt2col);
return TRUE;
......
......@@ -31,6 +31,7 @@ typedef struct {
P2tRTriangulation *mesh;
GeglRectangle mesh_bounds;
ScMeshSampling *sampling;
GeglBuffer *uvt;
} ScPreprocessResult;
#define sc_preprocess_new() (g_new0 (ScPreprocessResult, 1))
......@@ -45,4 +46,7 @@ typedef struct {
// g_free (self);
//}
#define babl_uvt_type (babl_type_new ("uvt", "bits", sizeof (P2tRuvt) * 8, NULL))
#define babl_uvt_format (babl_format_n (babl_uvt_type, 3))
#endif
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