void gimp_gegl_apply_scale (GeglBuffer *src_buffer, GimpProgress *progress, const gchar *undo_desc, GeglBuffer *dest_buffer, GimpInterpolationType interpolation_type, gdouble x, gdouble y) { GeglNode *node; g_return_if_fail (GEGL_IS_BUFFER (src_buffer)); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); g_return_if_fail (GEGL_IS_BUFFER (dest_buffer)); node = gegl_node_new_child (NULL, "operation", "gegl:scale", "origin-x", 0.0, "origin-y", 0.0, "filter", gimp_interpolation_to_gegl_filter (interpolation_type), "hard-edges", TRUE, "x", x, "y", y, NULL); gimp_gegl_apply_operation (src_buffer, progress, undo_desc, node, dest_buffer, NULL); g_object_unref (node); }
void gimp_gegl_apply_transform (GeglBuffer *src_buffer, GimpProgress *progress, const gchar *undo_desc, GeglBuffer *dest_buffer, GimpInterpolationType interpolation_type, GimpMatrix3 *transform) { GeglNode *node; g_return_if_fail (GEGL_IS_BUFFER (src_buffer)); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); g_return_if_fail (GEGL_IS_BUFFER (dest_buffer)); node = gegl_node_new_child (NULL, "operation", "gegl:transform", "filter", gimp_interpolation_to_gegl_filter (interpolation_type), "hard-edges", TRUE, NULL); gimp_gegl_node_set_matrix (node, transform); gimp_gegl_apply_operation (src_buffer, progress, undo_desc, node, dest_buffer, NULL); g_object_unref (node); }
void gimp_gegl_apply_color_reduction (GeglBuffer *src_buffer, GimpProgress *progress, const gchar *undo_desc, GeglBuffer *dest_buffer, gint bits, gint dither_type) { GeglNode *node; g_return_if_fail (GEGL_IS_BUFFER (src_buffer)); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); g_return_if_fail (GEGL_IS_BUFFER (dest_buffer)); node = gegl_node_new_child (NULL, "operation", "gegl:color-reduction", "red-bits", bits, "green-bits", bits, "blue-bits", bits, "alpha-bits", bits, "dither-strategy", dither_type, NULL); gimp_gegl_apply_operation (src_buffer, progress, undo_desc, node, dest_buffer, NULL); g_object_unref (node); }
void gimp_gegl_apply_opacity (GeglBuffer *src_buffer, GimpProgress *progress, const gchar *undo_desc, GeglBuffer *dest_buffer, GeglBuffer *mask, gint mask_offset_x, gint mask_offset_y, gdouble opacity) { GeglNode *node; g_return_if_fail (GEGL_IS_BUFFER (src_buffer)); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); g_return_if_fail (GEGL_IS_BUFFER (dest_buffer)); g_return_if_fail (mask == NULL || GEGL_IS_BUFFER (mask)); node = gimp_gegl_create_apply_opacity_node (mask, mask_offset_x, mask_offset_y, opacity); gimp_gegl_apply_operation (src_buffer, progress, undo_desc, node, dest_buffer, NULL); g_object_unref (node); }
void gimp_gegl_apply_gaussian_blur (GeglBuffer *src_buffer, GimpProgress *progress, const gchar *undo_desc, GeglBuffer *dest_buffer, const GeglRectangle *dest_rect, gdouble std_dev_x, gdouble std_dev_y) { GeglNode *node; g_return_if_fail (GEGL_IS_BUFFER (src_buffer)); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); g_return_if_fail (GEGL_IS_BUFFER (dest_buffer)); node = gegl_node_new_child (NULL, "operation", "gegl:gaussian-blur", "std-dev-x", std_dev_x, "std-dev-y", std_dev_y, NULL); gimp_gegl_apply_operation (src_buffer, progress, undo_desc, node, dest_buffer, dest_rect); g_object_unref (node); }
void gimp_gegl_apply_shrink (GeglBuffer *src_buffer, GimpProgress *progress, const gchar *undo_desc, GeglBuffer *dest_buffer, const GeglRectangle *dest_rect, gint radius_x, gint radius_y, gboolean edge_lock) { GeglNode *node; g_return_if_fail (GEGL_IS_BUFFER (src_buffer)); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); g_return_if_fail (GEGL_IS_BUFFER (dest_buffer)); node = gegl_node_new_child (NULL, "operation", "gimp:shrink", "radius-x", radius_x, "radius-y", radius_y, "edge-lock", edge_lock, NULL); gimp_gegl_apply_operation (src_buffer, progress, undo_desc, node, dest_buffer, dest_rect); g_object_unref (node); }
void gimp_gegl_apply_invert_linear (GeglBuffer *src_buffer, GimpProgress *progress, const gchar *undo_desc, GeglBuffer *dest_buffer) { GeglNode *node; g_return_if_fail (GEGL_IS_BUFFER (src_buffer)); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); g_return_if_fail (GEGL_IS_BUFFER (dest_buffer)); node = gegl_node_new_child (NULL, "operation", "gegl:invert-linear", NULL); gimp_gegl_apply_operation (src_buffer, progress, undo_desc, node, dest_buffer, NULL); g_object_unref (node); }
void gimp_gegl_apply_flatten (GeglBuffer *src_buffer, GimpProgress *progress, const gchar *undo_desc, GeglBuffer *dest_buffer, const GimpRGB *background) { GeglNode *node; g_return_if_fail (GEGL_IS_BUFFER (src_buffer)); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); g_return_if_fail (GEGL_IS_BUFFER (dest_buffer)); g_return_if_fail (background != NULL); node = gimp_gegl_create_flatten_node (background); gimp_gegl_apply_operation (src_buffer, progress, undo_desc, node, dest_buffer, NULL); g_object_unref (node); }
void gimp_gegl_apply_threshold (GeglBuffer *src_buffer, GimpProgress *progress, const gchar *undo_desc, GeglBuffer *dest_buffer, gdouble value) { GeglNode *node; g_return_if_fail (GEGL_IS_BUFFER (src_buffer)); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); g_return_if_fail (GEGL_IS_BUFFER (dest_buffer)); node = gegl_node_new_child (NULL, "operation", "gegl:threshold", "value", value, NULL); gimp_gegl_apply_operation (src_buffer, progress, undo_desc, node, dest_buffer, NULL); g_object_unref (node); }
static void gimp_n_point_deformation_tool_apply_deformation (GimpNPointDeformationTool *npd_tool) { GimpTool *tool = GIMP_TOOL (npd_tool); GimpNPointDeformationOptions *npd_options; GeglBuffer *buffer; GimpImage *image; gint width, height, prev; npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool); image = gimp_display_get_image (tool->display); buffer = gimp_drawable_get_buffer (tool->drawable); width = gegl_buffer_get_width (buffer); height = gegl_buffer_get_height (buffer); prev = npd_options->rigidity; npd_options->rigidity = 0; gimp_n_point_deformation_tool_set_options (npd_tool, npd_options); npd_options->rigidity = prev; gimp_drawable_push_undo (tool->drawable, _("N-Point Deformation"), NULL, 0, 0, width, height); gimp_gegl_apply_operation (NULL, NULL, _("N-Point Deformation"), npd_tool->npd_node, gimp_drawable_get_buffer (tool->drawable), NULL); gimp_drawable_update (tool->drawable, 0, 0, width, height); gimp_projection_flush (gimp_image_get_projection (image)); }
static GeglBuffer * gradient_precalc_shapeburst (GimpImage *image, GimpDrawable *drawable, const GeglRectangle *region, gdouble dist, GimpProgress *progress) { GimpChannel *mask; GeglBuffer *dist_buffer; GeglBuffer *temp_buffer; GeglNode *shapeburst; gdouble max; gfloat max_iteration; gimp_progress_set_text (progress, _("Calculating distance map")); /* allocate the distance map */ dist_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, region->width, region->height), babl_format ("Y float")); /* allocate the selection mask copy * XXX: its format should be the same of gimp:shapeburst input buffer * porting the op to 'float' should be reflected here as well */ temp_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, region->width, region->height), babl_format ("Y u8")); mask = gimp_image_get_mask (image); /* If the image mask is not empty, use it as the shape burst source */ if (! gimp_channel_is_empty (mask)) { gint x, y, width, height; gint off_x, off_y; gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height); gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y); /* copy the mask to the temp mask */ gegl_buffer_copy (gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)), GEGL_RECTANGLE (x + off_x, y + off_y, width, height), temp_buffer, GEGL_RECTANGLE (0, 0, 0, 0)); } else { /* If the intended drawable has an alpha channel, use that */ if (gimp_drawable_has_alpha (drawable)) { const Babl *component_format; component_format = babl_format ("A u8"); /* extract the aplha into the temp mask */ gegl_buffer_set_format (temp_buffer, component_format); gegl_buffer_copy (gimp_drawable_get_buffer (drawable), GEGL_RECTANGLE (region->x, region->y, region->width, region->height), temp_buffer, GEGL_RECTANGLE (0, 0, 0, 0)); gegl_buffer_set_format (temp_buffer, NULL); } else { GeglColor *white = gegl_color_new ("white"); /* Otherwise, just fill the shapeburst to white */ gegl_buffer_set_color (temp_buffer, NULL, white); g_object_unref (white); } } shapeburst = gegl_node_new_child (NULL, "operation", "gimp:shapeburst", NULL); gimp_gegl_progress_connect (shapeburst, progress, NULL); gimp_gegl_apply_operation (temp_buffer, NULL, NULL, shapeburst, dist_buffer, NULL); gegl_node_get (shapeburst, "max-iterations", &max, NULL); g_object_unref (shapeburst); max_iteration = max; g_object_unref (temp_buffer); /* normalize the shapeburst with the max iteration */ if (max_iteration > 0) { GeglBufferIterator *iter; iter = gegl_buffer_iterator_new (dist_buffer, NULL, 0, NULL, GEGL_BUFFER_READWRITE, GEGL_ABYSS_NONE); while (gegl_buffer_iterator_next (iter)) { gint count = iter->length; gfloat *data = iter->data[0]; while (count--) *data++ /= max_iteration; } } return dist_buffer; }
void gimp_drawable_real_apply_buffer (GimpDrawable *drawable, GeglBuffer *buffer, const GeglRectangle *buffer_region, gboolean push_undo, const gchar *undo_desc, gdouble opacity, GimpLayerModeEffects mode, GeglBuffer *base_buffer, gint base_x, gint base_y) { GimpItem *item = GIMP_ITEM (drawable); GimpImage *image = gimp_item_get_image (item); GimpChannel *mask = gimp_image_get_mask (image); GeglBuffer *mask_buffer = NULL; GeglNode *apply; GimpComponentMask affect; gint x, y, width, height; gint offset_x, offset_y; /* don't apply the mask to itself and don't apply an empty mask */ if (GIMP_DRAWABLE (mask) == drawable || gimp_channel_is_empty (mask)) mask = NULL; if (! base_buffer) base_buffer = gimp_drawable_get_buffer (drawable); /* get the layer offsets */ gimp_item_get_offset (item, &offset_x, &offset_y); /* make sure the image application coordinates are within drawable bounds */ gimp_rectangle_intersect (base_x, base_y, buffer_region->width, buffer_region->height, 0, 0, gimp_item_get_width (item), gimp_item_get_height (item), &x, &y, &width, &height); if (mask) { GimpItem *mask_item = GIMP_ITEM (mask); /* make sure coordinates are in mask bounds ... * we need to add the layer offset to transform coords * into the mask coordinate system */ gimp_rectangle_intersect (x, y, width, height, -offset_x, -offset_y, gimp_item_get_width (mask_item), gimp_item_get_height (mask_item), &x, &y, &width, &height); } if (push_undo) { GimpDrawableUndo *undo; gimp_drawable_push_undo (drawable, undo_desc, NULL, x, y, width, height); undo = GIMP_DRAWABLE_UNDO (gimp_image_undo_get_fadeable (image)); if (undo) { undo->paint_mode = mode; undo->opacity = opacity; undo->applied_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, width, height), gegl_buffer_get_format (buffer)); gegl_buffer_copy (buffer, GEGL_RECTANGLE (buffer_region->x + (x - base_x), buffer_region->y + (y - base_y), width, height), undo->applied_buffer, GEGL_RECTANGLE (0, 0, width, height)); } } if (mask) mask_buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)); affect = gimp_drawable_get_active_mask (drawable); apply = gimp_gegl_create_apply_buffer_node (buffer, base_x - buffer_region->x, base_y - buffer_region->y, 0, 0, 0, 0, mask_buffer, -offset_x, -offset_y, opacity, mode, affect); gimp_gegl_apply_operation (base_buffer, NULL, NULL, apply, gimp_drawable_get_buffer (drawable), GEGL_RECTANGLE (x, y, width, height)); g_object_unref (apply); }
static GeglBuffer * gradient_precalc_shapeburst (GimpImage *image, GimpDrawable *drawable, const GeglRectangle *region, gdouble dist, GimpProgress *progress) { GimpChannel *mask; GeglBuffer *dist_buffer; GeglBuffer *temp_buffer; GeglNode *shapeburst; gimp_progress_set_text (progress, _("Calculating distance map")); /* allocate the distance map */ dist_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, region->width, region->height), babl_format ("Y float")); /* allocate the selection mask copy */ temp_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, region->width, region->height), babl_format ("Y float")); mask = gimp_image_get_mask (image); /* If the image mask is not empty, use it as the shape burst source */ if (! gimp_channel_is_empty (mask)) { gint x, y, width, height; gint off_x, off_y; gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height); gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y); /* copy the mask to the temp mask */ gegl_buffer_copy (gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)), GEGL_RECTANGLE (x + off_x, y + off_y, width, height), temp_buffer, GEGL_RECTANGLE (0, 0, 0, 0)); } else { /* If the intended drawable has an alpha channel, use that */ if (gimp_drawable_has_alpha (drawable)) { const Babl *component_format; component_format = babl_format ("A float"); /* extract the aplha into the temp mask */ gegl_buffer_set_format (temp_buffer, component_format); gegl_buffer_copy (gimp_drawable_get_buffer (drawable), GEGL_RECTANGLE (region->x, region->y, region->width, region->height), temp_buffer, GEGL_RECTANGLE (0, 0, 0, 0)); gegl_buffer_set_format (temp_buffer, NULL); } else { GeglColor *white = gegl_color_new ("white"); /* Otherwise, just fill the shapeburst to white */ gegl_buffer_set_color (temp_buffer, NULL, white); g_object_unref (white); } } shapeburst = gegl_node_new_child (NULL, "operation", "gimp:shapeburst", "normalize", TRUE, NULL); gimp_gegl_progress_connect (shapeburst, progress, NULL); gimp_gegl_apply_operation (temp_buffer, NULL, NULL, shapeburst, dist_buffer, NULL); g_object_unref (shapeburst); g_object_unref (temp_buffer); return dist_buffer; }
static void gimp_warp_tool_animate (GimpWarpTool *wt) { GimpTool *tool = GIMP_TOOL (wt); GimpWarpOptions *options = GIMP_WARP_TOOL_GET_OPTIONS (wt); GimpImage *orig_image; GimpImage *image; GimpLayer *layer; GimpLayer *first_layer; GeglNode *scale_node; GimpProgress *progress; GtkWidget *widget; gint i; if (! gimp_warp_tool_get_undo_desc (tool, tool->display)) { gimp_tool_message_literal (tool, tool->display, _("Please add some warp strokes first.")); return; } /* get rid of the image map so we can use wt->graph */ if (wt->image_map) { gimp_image_map_abort (wt->image_map); g_object_unref (wt->image_map); wt->image_map = NULL; } gimp_progress_start (GIMP_PROGRESS (tool), FALSE, _("Rendering Frame %d"), 1); orig_image = gimp_item_get_image (GIMP_ITEM (tool->drawable)); image = gimp_create_image (orig_image->gimp, gimp_item_get_width (GIMP_ITEM (tool->drawable)), gimp_item_get_height (GIMP_ITEM (tool->drawable)), gimp_drawable_get_base_type (tool->drawable), gimp_drawable_get_precision (tool->drawable), TRUE); /* the first frame is always the unwarped image */ layer = GIMP_LAYER (gimp_item_convert (GIMP_ITEM (tool->drawable), image, GIMP_TYPE_LAYER)); gimp_object_take_name (GIMP_OBJECT (layer), g_strdup_printf (_("Frame %d"), 1)); gimp_item_set_offset (GIMP_ITEM (layer), 0, 0); gimp_item_set_visible (GIMP_ITEM (layer), TRUE, FALSE); gimp_layer_set_mode (layer, GIMP_NORMAL_MODE, FALSE); gimp_layer_set_opacity (layer, GIMP_OPACITY_OPAQUE, FALSE); gimp_image_add_layer (image, layer, NULL, 0, FALSE); first_layer = layer; scale_node = gegl_node_new_child (NULL, "operation", "gimp:scalar-multiply", "n-components", 2, NULL); gimp_warp_tool_add_op (wt, scale_node); progress = gimp_sub_progress_new (GIMP_PROGRESS (tool)); for (i = 1; i < options->n_animation_frames; i++) { gimp_progress_set_text (GIMP_PROGRESS (tool), _("Rendering Frame %d"), i + 1); gimp_sub_progress_set_step (GIMP_SUB_PROGRESS (progress), i, options->n_animation_frames); layer = GIMP_LAYER (gimp_item_duplicate (GIMP_ITEM (first_layer), GIMP_TYPE_LAYER)); gimp_object_take_name (GIMP_OBJECT (layer), g_strdup_printf (_("Frame %d"), i + 1)); gegl_node_set (scale_node, "factor", (gdouble) i / (gdouble) (options->n_animation_frames - 1), NULL); gimp_gegl_apply_operation (gimp_drawable_get_buffer (GIMP_DRAWABLE (first_layer)), progress, _("Frame"), wt->graph, gimp_drawable_get_buffer (GIMP_DRAWABLE (layer)), NULL); gimp_image_add_layer (image, layer, NULL, 0, FALSE); } g_object_unref (progress); gimp_warp_tool_remove_op (wt, scale_node); gimp_progress_end (GIMP_PROGRESS (tool)); /* recreate the image map */ gimp_warp_tool_create_image_map (wt, tool->drawable); gimp_image_map_apply (wt->image_map, NULL); widget = GTK_WIDGET (gimp_display_get_shell (tool->display)); gimp_create_display (orig_image->gimp, image, GIMP_UNIT_PIXEL, 1.0, G_OBJECT (gtk_widget_get_screen (widget)), gimp_widget_get_monitor (widget)); g_object_unref (image); }