mirror of https://github.com/GNOME/gimp.git
solve the problem result cropped to the bounding box of the cage
This commit is contained in:
parent
19b81bb097
commit
34b40a6c7e
|
@ -38,6 +38,7 @@
|
||||||
|
|
||||||
#include "gimpcageconfig.h"
|
#include "gimpcageconfig.h"
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_CODE (GimpCageConfig, gimp_cage_config,
|
G_DEFINE_TYPE_WITH_CODE (GimpCageConfig, gimp_cage_config,
|
||||||
GIMP_TYPE_IMAGE_MAP_CONFIG,
|
GIMP_TYPE_IMAGE_MAP_CONFIG,
|
||||||
G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG,
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG,
|
||||||
|
@ -366,7 +367,7 @@ gimp_cage_config_reverse_cage_if_needed (GimpCageConfig *gcc)
|
||||||
sum += z;
|
sum += z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sum > 0 mean a cage defined clockwise, so we reverse it */
|
/* sum > 0 mean a cage defined counter-clockwise, so we reverse it */
|
||||||
if (sum > 0)
|
if (sum > 0)
|
||||||
{
|
{
|
||||||
gimp_cage_config_reverse_cage (gcc);
|
gimp_cage_config_reverse_cage (gcc);
|
||||||
|
|
|
@ -41,6 +41,7 @@ static void gimp_operation_cage_transform_set_property (G
|
||||||
static void gimp_operation_cage_transform_prepare (GeglOperation *operation);
|
static void gimp_operation_cage_transform_prepare (GeglOperation *operation);
|
||||||
static gboolean gimp_operation_cage_transform_process (GeglOperation *operation,
|
static gboolean gimp_operation_cage_transform_process (GeglOperation *operation,
|
||||||
GeglBuffer *in_buf,
|
GeglBuffer *in_buf,
|
||||||
|
GeglBuffer *aux_buf,
|
||||||
GeglBuffer *out_buf,
|
GeglBuffer *out_buf,
|
||||||
const GeglRectangle *roi);
|
const GeglRectangle *roi);
|
||||||
static void gimp_operation_cage_transform_interpolate_source_coords_recurs (GimpOperationCageTransform *oct,
|
static void gimp_operation_cage_transform_interpolate_source_coords_recurs (GimpOperationCageTransform *oct,
|
||||||
|
@ -57,9 +58,10 @@ GeglRectangle gimp_operation_cage_transform_get_cached_region (G
|
||||||
GeglRectangle gimp_operation_cage_transform_get_required_for_output (GeglOperation *operation,
|
GeglRectangle gimp_operation_cage_transform_get_required_for_output (GeglOperation *operation,
|
||||||
const gchar *input_pad,
|
const gchar *input_pad,
|
||||||
const GeglRectangle *roi);
|
const GeglRectangle *roi);
|
||||||
|
GeglRectangle gimp_operation_cage_get_bounding_box (GeglOperation *operation);
|
||||||
|
|
||||||
G_DEFINE_TYPE (GimpOperationCageTransform, gimp_operation_cage_transform,
|
G_DEFINE_TYPE (GimpOperationCageTransform, gimp_operation_cage_transform,
|
||||||
GEGL_TYPE_OPERATION_FILTER)
|
GEGL_TYPE_OPERATION_COMPOSER)
|
||||||
|
|
||||||
#define parent_class gimp_operation_cage_transform_parent_class
|
#define parent_class gimp_operation_cage_transform_parent_class
|
||||||
|
|
||||||
|
@ -71,7 +73,7 @@ gimp_operation_cage_transform_class_init (GimpOperationCageTransformClass *klass
|
||||||
{
|
{
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
|
GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
|
||||||
GeglOperationFilterClass *filter_class = GEGL_OPERATION_FILTER_CLASS (klass);
|
GeglOperationComposerClass *filter_class = GEGL_OPERATION_COMPOSER_CLASS (klass);
|
||||||
|
|
||||||
object_class->get_property = gimp_operation_cage_transform_get_property;
|
object_class->get_property = gimp_operation_cage_transform_get_property;
|
||||||
object_class->set_property = gimp_operation_cage_transform_set_property;
|
object_class->set_property = gimp_operation_cage_transform_set_property;
|
||||||
|
@ -87,6 +89,7 @@ gimp_operation_cage_transform_class_init (GimpOperationCageTransformClass *klass
|
||||||
operation_class->get_required_for_output = gimp_operation_cage_transform_get_required_for_output;
|
operation_class->get_required_for_output = gimp_operation_cage_transform_get_required_for_output;
|
||||||
operation_class->get_cached_region = gimp_operation_cage_transform_get_cached_region;
|
operation_class->get_cached_region = gimp_operation_cage_transform_get_cached_region;
|
||||||
operation_class->no_cache = FALSE;
|
operation_class->no_cache = FALSE;
|
||||||
|
operation_class->get_bounding_box = gimp_operation_cage_get_bounding_box;
|
||||||
|
|
||||||
filter_class->process = gimp_operation_cage_transform_process;
|
filter_class->process = gimp_operation_cage_transform_process;
|
||||||
|
|
||||||
|
@ -174,6 +177,7 @@ gimp_operation_cage_transform_prepare (GeglOperation *operation)
|
||||||
static gboolean
|
static gboolean
|
||||||
gimp_operation_cage_transform_process (GeglOperation *operation,
|
gimp_operation_cage_transform_process (GeglOperation *operation,
|
||||||
GeglBuffer *in_buf,
|
GeglBuffer *in_buf,
|
||||||
|
GeglBuffer *aux_buf,
|
||||||
GeglBuffer *out_buf,
|
GeglBuffer *out_buf,
|
||||||
const GeglRectangle *roi)
|
const GeglRectangle *roi)
|
||||||
{
|
{
|
||||||
|
@ -181,11 +185,12 @@ gimp_operation_cage_transform_process (GeglOperation *operation,
|
||||||
GimpCageConfig *config = GIMP_CAGE_CONFIG (oct->config);
|
GimpCageConfig *config = GIMP_CAGE_CONFIG (oct->config);
|
||||||
|
|
||||||
gint x, y;
|
gint x, y;
|
||||||
GeglRectangle bounding_box = gimp_cage_config_get_bounding_box (config);
|
GeglRectangle cage_bb = gimp_cage_config_get_bounding_box (config);
|
||||||
|
GeglRectangle buffer_bb = *gegl_operation_source_get_bounding_box (operation, "input");
|
||||||
|
|
||||||
for (x = bounding_box.x; x < bounding_box.x + bounding_box.width - 1; x++)
|
for (x = cage_bb.x; x < cage_bb.x + cage_bb.width - 1; x++)
|
||||||
{
|
{
|
||||||
for (y = bounding_box.y; y < bounding_box.y + bounding_box.height - 1; y++)
|
for (y = cage_bb.y; y < cage_bb.y + cage_bb.height - 1; y++)
|
||||||
{
|
{
|
||||||
GimpCoords p1_s = {x, y, };
|
GimpCoords p1_s = {x, y, };
|
||||||
GimpCoords p2_s = {x+1, y, };
|
GimpCoords p2_s = {x+1, y, };
|
||||||
|
@ -194,21 +199,21 @@ gimp_operation_cage_transform_process (GeglOperation *operation,
|
||||||
|
|
||||||
GimpCoords p1_d, p2_d, p3_d, p4_d;
|
GimpCoords p1_d, p2_d, p3_d, p4_d;
|
||||||
|
|
||||||
p1_d = gimp_cage_transform_compute_destination (config, in_buf, p1_s);
|
p1_d = gimp_cage_transform_compute_destination (config, aux_buf, p1_s);
|
||||||
p2_d = gimp_cage_transform_compute_destination (config, in_buf, p2_s);
|
p2_d = gimp_cage_transform_compute_destination (config, aux_buf, p2_s);
|
||||||
p3_d = gimp_cage_transform_compute_destination (config, in_buf, p3_s);
|
p3_d = gimp_cage_transform_compute_destination (config, aux_buf, p3_s);
|
||||||
p4_d = gimp_cage_transform_compute_destination (config, in_buf, p4_s);
|
p4_d = gimp_cage_transform_compute_destination (config, aux_buf, p4_s);
|
||||||
|
|
||||||
gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
|
gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
|
||||||
out_buf,
|
out_buf,
|
||||||
roi,
|
&buffer_bb,
|
||||||
p1_s, p1_d,
|
p1_s, p1_d,
|
||||||
p2_s, p2_d,
|
p2_s, p2_d,
|
||||||
p3_s, p3_d);
|
p3_s, p3_d);
|
||||||
|
|
||||||
gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
|
gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
|
||||||
out_buf,
|
out_buf,
|
||||||
roi,
|
&buffer_bb,
|
||||||
p1_s, p1_d,
|
p1_s, p1_d,
|
||||||
p3_s, p3_d,
|
p3_s, p3_d,
|
||||||
p4_s, p4_d);
|
p4_s, p4_d);
|
||||||
|
@ -362,8 +367,8 @@ gimp_operation_cage_transform_interpolate_source_coords_recurs (GimpOperationCa
|
||||||
|
|
||||||
static GimpCoords
|
static GimpCoords
|
||||||
gimp_cage_transform_compute_destination (GimpCageConfig *config,
|
gimp_cage_transform_compute_destination (GimpCageConfig *config,
|
||||||
GeglBuffer *coef_buf,
|
GeglBuffer *coef_buf,
|
||||||
GimpCoords coords)
|
GimpCoords coords)
|
||||||
{
|
{
|
||||||
gfloat *coef;
|
gfloat *coef;
|
||||||
gdouble pos_x, pos_y;
|
gdouble pos_x, pos_y;
|
||||||
|
@ -373,9 +378,6 @@ gimp_cage_transform_compute_destination (GimpCageConfig *config,
|
||||||
gint cvn = config->cage_vertice_number;
|
gint cvn = config->cage_vertice_number;
|
||||||
Babl *format_coef = babl_format_n (babl_type ("float"), 2 * cvn);
|
Babl *format_coef = babl_format_n (babl_type ("float"), 2 * cvn);
|
||||||
|
|
||||||
gfloat coefeu;
|
|
||||||
|
|
||||||
|
|
||||||
rect.height = 1;
|
rect.height = 1;
|
||||||
rect.width = 1;
|
rect.width = 1;
|
||||||
rect.x = coords.x;
|
rect.x = coords.x;
|
||||||
|
@ -390,7 +392,6 @@ gimp_cage_transform_compute_destination (GimpCageConfig *config,
|
||||||
|
|
||||||
for(i = 0; i < cvn; i++)
|
for(i = 0; i < cvn; i++)
|
||||||
{
|
{
|
||||||
coefeu = coef[i];
|
|
||||||
|
|
||||||
if (!isnan(coef[i]))
|
if (!isnan(coef[i]))
|
||||||
{
|
{
|
||||||
|
@ -404,7 +405,6 @@ gimp_cage_transform_compute_destination (GimpCageConfig *config,
|
||||||
|
|
||||||
for(i = 0; i < cvn; i++)
|
for(i = 0; i < cvn; i++)
|
||||||
{
|
{
|
||||||
coefeu = coef[i + cvn];
|
|
||||||
|
|
||||||
if (!isnan(coef[i]))
|
if (!isnan(coef[i]))
|
||||||
{
|
{
|
||||||
|
@ -426,7 +426,17 @@ gimp_cage_transform_compute_destination (GimpCageConfig *config,
|
||||||
|
|
||||||
GeglRectangle
|
GeglRectangle
|
||||||
gimp_operation_cage_transform_get_cached_region (GeglOperation *operation,
|
gimp_operation_cage_transform_get_cached_region (GeglOperation *operation,
|
||||||
const GeglRectangle *roi)
|
const GeglRectangle *roi)
|
||||||
|
{
|
||||||
|
GeglRectangle result = *gegl_operation_source_get_bounding_box (operation, "input");
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
GeglRectangle
|
||||||
|
gimp_operation_cage_transform_get_required_for_output (GeglOperation *operation,
|
||||||
|
const gchar *input_pad,
|
||||||
|
const GeglRectangle *roi)
|
||||||
{
|
{
|
||||||
GeglRectangle result = *gegl_operation_source_get_bounding_box (operation, "input");
|
GeglRectangle result = *gegl_operation_source_get_bounding_box (operation, "input");
|
||||||
|
|
||||||
|
@ -434,9 +444,7 @@ gimp_operation_cage_transform_get_cached_region (GeglOperation *operatio
|
||||||
}
|
}
|
||||||
|
|
||||||
GeglRectangle
|
GeglRectangle
|
||||||
gimp_operation_cage_transform_get_required_for_output (GeglOperation *operation,
|
gimp_operation_cage_get_bounding_box (GeglOperation *operation)
|
||||||
const gchar *input_pad,
|
|
||||||
const GeglRectangle *roi)
|
|
||||||
{
|
{
|
||||||
GeglRectangle result = *gegl_operation_source_get_bounding_box (operation, "input");
|
GeglRectangle result = *gegl_operation_source_get_bounding_box (operation, "input");
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#define __GIMP_OPERATION_CAGE_TRANSFORM_H__
|
#define __GIMP_OPERATION_CAGE_TRANSFORM_H__
|
||||||
|
|
||||||
#include <gegl-plugin.h>
|
#include <gegl-plugin.h>
|
||||||
#include <operation/gegl-operation-filter.h>
|
#include <operation/gegl-operation-composer.h>
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
@ -41,15 +41,15 @@ typedef struct _GimpOperationCageTransformClass GimpOperationCageTransformClass;
|
||||||
|
|
||||||
struct _GimpOperationCageTransform
|
struct _GimpOperationCageTransform
|
||||||
{
|
{
|
||||||
GeglOperationFilter parent_instance;
|
GeglOperationComposer parent_instance;
|
||||||
|
|
||||||
GimpCageConfig *config;
|
GimpCageConfig *config;
|
||||||
Babl *format_coords;
|
Babl *format_coords;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GimpOperationCageTransformClass
|
struct _GimpOperationCageTransformClass
|
||||||
{
|
{
|
||||||
GeglOperationFilterClass parent_class;
|
GeglOperationComposerClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include "core/gimpdrawable.h"
|
#include "core/gimpdrawable.h"
|
||||||
#include "core/gimpdrawable-operation.h"
|
#include "core/gimpdrawable-operation.h"
|
||||||
#include "core/gimpdrawable-shadow.h"
|
#include "core/gimpdrawable-shadow.h"
|
||||||
|
#include "core/gimpimagemap.h"
|
||||||
#include "base/tile-manager.h"
|
#include "base/tile-manager.h"
|
||||||
|
|
||||||
#include "widgets/gimphelp-ids.h"
|
#include "widgets/gimphelp-ids.h"
|
||||||
|
@ -102,6 +103,8 @@ static void gimp_cage_tool_compute_coef (GimpCageTool *ct,
|
||||||
GimpDisplay *display);
|
GimpDisplay *display);
|
||||||
static void gimp_cage_tool_process (GimpCageTool *ct,
|
static void gimp_cage_tool_process (GimpCageTool *ct,
|
||||||
GimpDisplay *display);
|
GimpDisplay *display);
|
||||||
|
static void gimp_cage_tool_prepare_preview (GimpCageTool *ct,
|
||||||
|
GimpDisplay *display);
|
||||||
|
|
||||||
G_DEFINE_TYPE (GimpCageTool, gimp_cage_tool, GIMP_TYPE_DRAW_TOOL)
|
G_DEFINE_TYPE (GimpCageTool, gimp_cage_tool, GIMP_TYPE_DRAW_TOOL)
|
||||||
|
|
||||||
|
@ -191,6 +194,8 @@ gimp_cage_tool_start (GimpCageTool *ct,
|
||||||
gimp_tool_control_activate (tool->control);
|
gimp_tool_control_activate (tool->control);
|
||||||
|
|
||||||
tool->display = display;
|
tool->display = display;
|
||||||
|
|
||||||
|
//gimp_cage_tool_prepare_preview (ct, display);
|
||||||
|
|
||||||
gimp_draw_tool_start (draw_tool, display);
|
gimp_draw_tool_start (draw_tool, display);
|
||||||
}
|
}
|
||||||
|
@ -218,6 +223,9 @@ gimp_cage_tool_halt (GimpCageTool *ct)
|
||||||
|
|
||||||
gegl_buffer_destroy (ct->coef);
|
gegl_buffer_destroy (ct->coef);
|
||||||
ct->coef = NULL;
|
ct->coef = NULL;
|
||||||
|
|
||||||
|
//g_object_unref (ct->image_map);
|
||||||
|
//ct->image_map = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -346,6 +354,12 @@ gimp_cage_tool_motion (GimpTool *tool,
|
||||||
coords->y);
|
coords->y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* {
|
||||||
|
GeglRectangle rect = {0, 0, 300, 300};
|
||||||
|
gimp_image_map_apply (ct->image_map, &rect);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
gimp_draw_tool_resume (draw_tool);
|
gimp_draw_tool_resume (draw_tool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -603,52 +617,54 @@ gimp_cage_tool_process (GimpCageTool *ct,
|
||||||
GeglNode *coef, *cage, *render, *input, *output;
|
GeglNode *coef, *cage, *render, *input, *output;
|
||||||
|
|
||||||
input = gegl_node_new_child (gegl,
|
input = gegl_node_new_child (gegl,
|
||||||
"operation", "gimp:tilemanager-source",
|
"operation", "gimp:tilemanager-source",
|
||||||
"tile-manager", gimp_drawable_get_tiles (drawable),
|
"tile-manager", gimp_drawable_get_tiles (drawable),
|
||||||
"linear", TRUE,
|
"linear", TRUE,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
cage = gegl_node_new_child (gegl,
|
cage = gegl_node_new_child (gegl,
|
||||||
"operation", "gegl:cage_transform",
|
"operation", "gegl:cage_transform",
|
||||||
"config", ct->config,
|
"config", ct->config,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
coef = gegl_node_new_child (gegl,
|
coef = gegl_node_new_child (gegl,
|
||||||
"operation", "gegl:buffer-source",
|
"operation", "gegl:buffer-source",
|
||||||
"buffer", ct->coef,
|
"buffer", ct->coef,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
gegl_node_connect_to (coef, "output",
|
|
||||||
cage, "input");
|
|
||||||
|
|
||||||
render = gegl_node_new_child (gegl,
|
render = gegl_node_new_child (gegl,
|
||||||
"operation", "gegl:render_mapping",
|
"operation", "gegl:render_mapping",
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
gegl_node_connect_to (cage, "output",
|
new_tiles = gimp_drawable_get_shadow_tiles (drawable);
|
||||||
render, "aux");
|
output = gegl_node_new_child (gegl,
|
||||||
|
"operation", "gimp:tilemanager-sink",
|
||||||
|
"tile-manager", new_tiles,
|
||||||
|
"linear", TRUE,
|
||||||
|
NULL);
|
||||||
|
|
||||||
/* render = gegl_node_new_child (gegl,
|
/* render = gegl_node_new_child (gegl,
|
||||||
"operation", "gegl:debugit",
|
"operation", "gegl:debugit",
|
||||||
NULL);*/
|
NULL);*/
|
||||||
|
|
||||||
|
gegl_node_connect_to (input, "output",
|
||||||
|
cage, "input");
|
||||||
|
|
||||||
gegl_node_connect_to (input, "output",
|
gegl_node_connect_to (input, "output",
|
||||||
render, "input");
|
render, "input");
|
||||||
|
|
||||||
|
gegl_node_connect_to (coef, "output",
|
||||||
|
cage, "aux");
|
||||||
|
|
||||||
|
gegl_node_connect_to (cage, "output",
|
||||||
|
render, "aux");
|
||||||
|
|
||||||
|
gegl_node_connect_to (render, "output",
|
||||||
|
output, "input");
|
||||||
|
|
||||||
/* gimp_drawable_apply_operation (drawable, progress, _("Cage transform"),
|
/* gimp_drawable_apply_operation (drawable, progress, _("Cage transform"),
|
||||||
render, TRUE);*/
|
render, TRUE);*/
|
||||||
|
|
||||||
new_tiles = gimp_drawable_get_shadow_tiles (drawable);
|
|
||||||
|
|
||||||
output = gegl_node_new_child (gegl,
|
|
||||||
"operation", "gimp:tilemanager-sink",
|
|
||||||
"tile-manager", new_tiles,
|
|
||||||
"linear", TRUE,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
gegl_node_connect_to (render, "output",
|
|
||||||
output, "input");
|
|
||||||
|
|
||||||
gegl_node_process (output);
|
gegl_node_process (output);
|
||||||
|
|
||||||
|
@ -674,3 +690,35 @@ gimp_cage_tool_process (GimpCageTool *ct,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
gimp_cage_tool_prepare_preview (GimpCageTool *ct,
|
||||||
|
GimpDisplay *display)
|
||||||
|
{
|
||||||
|
GimpImage *image = gimp_display_get_image (display);
|
||||||
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
||||||
|
GimpImageMap *image_map;
|
||||||
|
|
||||||
|
GeglNode *gegl = gegl_node_new ();
|
||||||
|
GeglNode *coef, *cage;
|
||||||
|
|
||||||
|
coef = gegl_node_new_child (gegl,
|
||||||
|
"operation", "gegl:buffer-source",
|
||||||
|
"buffer", ct->coef,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
cage = gegl_node_new_child (gegl,
|
||||||
|
"operation", "gegl:cage",
|
||||||
|
"config", ct->config,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
gegl_node_connect_to (coef, "output",
|
||||||
|
cage, "aux");
|
||||||
|
|
||||||
|
image_map = gimp_image_map_new (drawable,
|
||||||
|
_("Cage transform"),
|
||||||
|
cage,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
g_object_unref (gegl);
|
||||||
|
}
|
||||||
|
|
|
@ -46,7 +46,9 @@ struct _GimpCageTool
|
||||||
gint handle_moved;
|
gint handle_moved;
|
||||||
gboolean cage_complete;
|
gboolean cage_complete;
|
||||||
|
|
||||||
GeglBuffer *coef;
|
GeglBuffer *coef;
|
||||||
|
|
||||||
|
GimpImageMap *image_map;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue