fill the original cage position with a plain color + UI

This commit is contained in:
Michael Muré 2010-08-15 14:20:47 +02:00
parent e2a7ef2e32
commit f44dcf26b3
6 changed files with 83 additions and 29 deletions

View File

@ -105,6 +105,13 @@ gimp_operation_cage_transform_class_init (GimpOperationCageTransformClass *klass
GIMP_TYPE_CAGE_CONFIG,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, GIMP_OPERATION_CAGE_TRANSFORM_PROP_FILL,
g_param_spec_boolean ("fill_plain_color",
"Blocking render",
"Fill the original position of the cage with a plain color",
FALSE,
G_PARAM_READWRITE));
}
static void
@ -141,6 +148,10 @@ gimp_operation_cage_transform_get_property (GObject *object,
g_value_set_object (value, self->config);
break;
case GIMP_OPERATION_CAGE_TRANSFORM_PROP_FILL:
g_value_set_boolean (value, self->fill_plain_color);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -163,6 +174,10 @@ gimp_operation_cage_transform_set_property (GObject *object,
self->config = g_value_dup_object (value);
break;
case GIMP_OPERATION_CAGE_TRANSFORM_PROP_FILL:
self->fill_plain_color = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -192,10 +207,11 @@ gimp_operation_cage_transform_process (GeglOperation *operation,
gint x, y;
GeglRectangle cage_bb = gimp_cage_config_get_bounding_box (config);
GeglRectangle buffer_bb = *gegl_operation_source_get_bounding_box (operation, "input");
gfloat *coords = g_slice_alloc ( 2 * sizeof (gfloat));
GimpVector2 p1_d, p2_d, p3_d, p4_d;
GimpVector2 p1_s, p2_s, p3_s, p4_s;
GimpVector2 plain_color;
gboolean plain_color_set = FALSE;
/* pre-fill the out buffer with no-displacement coordinate */
GeglBufferIterator *it = gegl_buffer_iterator_new (out_buf, roi, NULL, GEGL_BUFFER_WRITE);
@ -210,9 +226,23 @@ gimp_operation_cage_transform_process (GeglOperation *operation,
gfloat *output = it->data[0];
while(n_pixels--)
{
if (oct->fill_plain_color && gimp_cage_config_point_inside(config, x, y))
{
if (!plain_color_set)
{
plain_color.x = x;
plain_color.y = y;
plain_color_set = TRUE;
}
output[0] = plain_color.x;
output[1] = plain_color.y;
}
else
{
output[0] = x;
output[1] = y;
}
output += 2;
@ -255,7 +285,7 @@ gimp_operation_cage_transform_process (GeglOperation *operation,
{
gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
out_buf,
&buffer_bb,
roi,
p1_s, p1_d,
p2_s, p2_d,
p3_s, p3_d,
@ -264,7 +294,7 @@ gimp_operation_cage_transform_process (GeglOperation *operation,
gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
out_buf,
&buffer_bb,
roi,
p1_s, p1_d,
p3_s, p3_d,
p4_s, p4_d,
@ -344,8 +374,8 @@ gimp_operation_cage_transform_interpolate_source_coords_recurs (GimpOperationCag
rect.x = xmax;
rect.y = ymax;
x = (gfloat) xmax;
y = (gfloat) ymax;
x = (gdouble) xmax;
y = (gdouble) ymax;
denom = (p2_d.x - p1_d.x) * p3_d.y + (p1_d.x - p3_d.x) * p2_d.y + (p3_d.x - p2_d.x) * p1_d.y;
a = ((p2_d.x - x) * p3_d.y + (x - p3_d.x) * p2_d.y + (p3_d.x - p2_d.x) * y) / denom;

View File

@ -26,7 +26,8 @@
enum
{
GIMP_OPERATION_CAGE_TRANSFORM_PROP_0,
GIMP_OPERATION_CAGE_TRANSFORM_PROP_CONFIG
GIMP_OPERATION_CAGE_TRANSFORM_PROP_CONFIG,
GIMP_OPERATION_CAGE_TRANSFORM_PROP_FILL
};
#define GIMP_TYPE_OPERATION_CAGE_TRANSFORM (gimp_operation_cage_transform_get_type ())
@ -44,6 +45,8 @@ struct _GimpOperationCageTransform
GeglOperationComposer parent_instance;
GimpCageConfig *config;
gboolean fill_plain_color;
Babl *format_coords;
};

View File

@ -43,7 +43,8 @@
enum
{
PROP_0,
PROP_CAGE_MODE
PROP_CAGE_MODE,
PROP_FILL_PLAIN_COLOR
};
static void gimp_cage_options_set_property (GObject *object,
@ -75,6 +76,11 @@ gimp_cage_options_class_init (GimpCageOptionsClass *klass)
GIMP_TYPE_CAGE_MODE,
GIMP_CAGE_MODE_CAGE_CHANGE,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FILL_PLAIN_COLOR,
"fill-plain-color", NULL,
FALSE,
GIMP_PARAM_STATIC_STRINGS);
}
static void
@ -97,6 +103,10 @@ gimp_cage_options_set_property (GObject *object,
options->cage_mode = g_value_get_enum (value);
break;
case PROP_FILL_PLAIN_COLOR:
options->fill_plain_color = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -117,6 +127,10 @@ gimp_cage_options_get_property (GObject *object,
g_value_set_enum (value, options->cage_mode);
break;
case PROP_FILL_PLAIN_COLOR:
g_value_set_boolean (value, options->fill_plain_color);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -130,6 +144,7 @@ gimp_cage_options_gui (GimpToolOptions *tool_options)
GtkWidget *vbox = gimp_tool_options_gui (tool_options);
GtkWidget *hbox;
GtkWidget *mode;
GtkWidget *button;
hbox = gtk_hbox_new (FALSE, 2);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
@ -140,5 +155,11 @@ gimp_cage_options_gui (GimpToolOptions *tool_options)
gtk_box_pack_start (GTK_BOX (vbox), mode, FALSE, FALSE, 0);
gtk_widget_show (mode);
button = gimp_prop_check_button_new (config, "fill-plain-color",
_("Fill the original cage position with a plain color"));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
return vbox;
}

View File

@ -41,6 +41,7 @@ struct _GimpCageOptions
GimpTransformOptions parent_instance;
GimpCageMode cage_mode;
gboolean fill_plain_color;
};

View File

@ -673,7 +673,6 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
GimpCageConfig *config = ct->config;
Babl *format;
GeglRectangle rect;
GeglNode *gegl, *input, *output;
GeglProcessor *processor;
GimpProgress *progress;
@ -687,7 +686,10 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
}
format = babl_format_n(babl_type("float"), config->cage_vertice_number * 2);
rect = gimp_cage_config_get_bounding_box (config);
progress = gimp_progress_start (GIMP_PROGRESS (display),
_("Coefficient computation"),
FALSE);
gegl = gegl_node_new ();
@ -705,11 +707,6 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
gegl_node_connect_to (input, "output",
output, "input");
progress = gimp_progress_start (GIMP_PROGRESS (display),
_("Coefficient computation"),
FALSE);
processor = gegl_node_new_processor (output, NULL);
while (gegl_processor_work (processor, &value))
@ -728,6 +725,7 @@ static void
gimp_cage_tool_process (GimpCageTool *ct,
GimpDisplay *display)
{
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
TileManager *new_tiles;
GeglRectangle rect;
@ -783,6 +781,7 @@ gimp_cage_tool_process (GimpCageTool *ct,
cage = gegl_node_new_child (gegl,
"operation", "gimp:cage_transform",
"config", ct->config,
"fill_plain_color", options->fill_plain_color,
NULL);
coef = gegl_node_new_child (gegl,