static gboolean sel2path (gint32 image_ID) { gint32 selection_ID; pixel_outline_list_type olt; spline_list_array_type splines; gimp_selection_bounds (image_ID, &has_sel, &sel_x1, &sel_y1, &sel_x2, &sel_y2); sel_width = sel_x2 - sel_x1; sel_height = sel_y2 - sel_y1; /* Now get the selection channel */ selection_ID = gimp_image_get_selection (image_ID); if (selection_ID < 0) return FALSE; sel_buffer = gimp_drawable_get_buffer (selection_ID); olt = find_outline_pixels (); splines = fitted_splines (olt); do_points (splines, image_ID); g_object_unref (sel_buffer); gimp_displays_flush (); return TRUE; }
/* -------------------------- * p_create_corpus_layer * -------------------------- * create the corpus layer that builds the reference pattern * for the resynthesizer call. The reference pattern is built * as duplicate of the original image reduced to the area around the current selection. * (grown by corpus_border_radius) * Note that the duplicate image has a selection, that includes the gorwn area * around the orignal selection, but EXCLUDES the original selection * (that is the area holding the object that has to be replaced * by pattern of the surrounding area) * returns the layer_id of the reference pattern. */ static gint32 p_create_corpus_layer(gint32 image_id, gint32 drawable_id, TransValues *val_ptr) { gint32 dup_image_id; gint32 channel_id; gint32 channel_2_id; GimpRGB bck_color; GimpRGB white_opaque_color; /* gboolean has_selection; */ gboolean non_empty; gint x1, y1, x2, y2; gint32 active_layer_stackposition; gint32 active_dup_layer_id; active_layer_stackposition = gap_layer_get_stackposition(image_id, drawable_id); dup_image_id = gimp_image_duplicate(image_id); channel_id = gimp_selection_save(dup_image_id); gimp_selection_grow(dup_image_id, val_ptr->corpus_border_radius); gimp_selection_invert(dup_image_id); gimp_context_get_background(&bck_color); channel_2_id = gimp_selection_save(dup_image_id); gimp_image_select_item(dup_image_id, GIMP_CHANNEL_OP_REPLACE, channel_id); gimp_rgba_set_uchar (&white_opaque_color, 255, 255, 255, 255); gimp_context_set_background(&white_opaque_color); gimp_edit_clear(channel_2_id); gimp_context_set_background(&bck_color); /* restore original background color */ gimp_selection_load(channel_2_id); gimp_selection_invert(dup_image_id); /* has_selection = */ gimp_selection_bounds(dup_image_id, &non_empty, &x1, &y1, &x2, &y2); gimp_image_crop(dup_image_id, (x2 - x1), (y2 - y1), x1, y1); gimp_selection_invert(dup_image_id); active_dup_layer_id = gap_layer_get_id_by_stackposition(dup_image_id, active_layer_stackposition); if (1==0) { /* debug code shows the duplicate image by adding a display */ gimp_display_new(dup_image_id); } return (active_dup_layer_id); } /* end p_create_corpus_layer */
static gboolean sel2path (gint32 image_ID) { gint32 selection_ID; GimpDrawable *sel_drawable; pixel_outline_list_type olt; spline_list_array_type splines; gimp_selection_bounds (image_ID, &has_sel, &sel_x1, &sel_y1, &sel_x2, &sel_y2); sel_width = sel_x2 - sel_x1; sel_height = sel_y2 - sel_y1; /* Now get the selection channel */ selection_ID = gimp_image_get_selection (image_ID); if (selection_ID < 0) return FALSE; sel_drawable = gimp_drawable_get (selection_ID); if (gimp_drawable_bpp (selection_ID) != 1) { g_warning ("Internal error. Selection bpp > 1"); return FALSE; } gimp_pixel_rgn_init (&selection_rgn, sel_drawable, sel_x1, sel_y1, sel_width, sel_height, FALSE, FALSE); gimp_tile_cache_ntiles (2 * (sel_drawable->width + gimp_tile_width () - 1) / gimp_tile_width ()); olt = find_outline_pixels (); splines = fitted_splines (olt); do_points (splines, image_ID); gimp_drawable_detach (sel_drawable); gimp_displays_flush (); return TRUE; }
/* ------------------------------------------------------- * gap_image_set_selection_from_selection_or_drawable * ------------------------------------------------------- * create a selection in the specified image_id. * The selection is a scaled copy of the selection in another image, * referred by ref_drawable_id, or a Grayscale copy of the specified ref_drawable_id * (in case the referred image has no selection or the flag force_from_drawable is TRUE) * * - operates on a duplicate of the image referred by ref_drawable_id. * - this duplicate is scaled to same size as specified image_id * * return TRUE in case the selection was successfully created . */ gboolean gap_image_set_selection_from_selection_or_drawable(gint32 image_id, gint32 ref_drawable_id , gboolean force_from_drawable) { gint32 l_aux_channel_id; gint32 ref_image_id; gint32 work_drawable_id; /* the duplicate of the layer that is used as selction mask */ gint32 dup_image_id; gboolean has_selection; gboolean non_empty; gint x1, y1, x2, y2; if ((image_id < 0) || (ref_drawable_id < 0)) { return (FALSE); } ref_image_id = gimp_item_get_image(ref_drawable_id); if (ref_image_id < 0) { printf("ref_drawable_id does not refer to a valid image layer_id:%d\n", (int)ref_drawable_id); return (FALSE); } dup_image_id = gimp_image_duplicate(ref_image_id); if (dup_image_id < 0) { printf("duplicating of image failed, referred souce image_id:%d\n", (int)ref_image_id); return (FALSE); } /* clear undo stack */ if (gimp_image_undo_is_enabled(dup_image_id)) { gimp_image_undo_disable(dup_image_id); } if ((gimp_image_width(image_id) != gimp_image_width(dup_image_id)) || (gimp_image_height(image_id) != gimp_image_height(dup_image_id))) { if(gap_debug) { printf("scaling tmp image_id: %d\n", (int)dup_image_id); } gimp_image_scale(dup_image_id, gimp_image_width(image_id), gimp_image_height(image_id)); } has_selection = gimp_selection_bounds(ref_image_id, &non_empty, &x1, &y1, &x2, &y2); if ((has_selection) && (non_empty) && (force_from_drawable != TRUE)) { /* use scaled copy of the already exisating selection in the referred image */ work_drawable_id = gimp_image_get_selection(dup_image_id); } else { gint32 active_layer_stackposition; /* create selection as gray copy of the alt_selection layer */ active_layer_stackposition = gap_layer_get_stackposition(ref_image_id, ref_drawable_id); if(gimp_image_base_type(dup_image_id) != GIMP_GRAY) { if(gap_debug) { printf("convert to GRAYSCALE tmp image_id: %d\n", (int)dup_image_id); } gimp_image_convert_grayscale(dup_image_id); } work_drawable_id = gap_layer_get_id_by_stackposition(dup_image_id, active_layer_stackposition); gimp_layer_resize_to_image_size (work_drawable_id); } gimp_selection_all(image_id); //l_sel_channel_id = gimp_image_get_selection(image_id); l_aux_channel_id = gimp_selection_save(image_id); /* copy the work drawable (layer or channel) into the selection channel * the work layer is a grayscale copy GRAY or GRAYA of the alt_selection layer * that is already scaled and resized to fit the size of the target image * the work channel is the scaled selection of the image refred by ref_drawable_id * * copying is done into an auxiliary channel from where we regulary load the selection. * this is done because subseqent queries of the selection boudaries will deliver * full channel size rectangle after a direct copy into the selection. */ gap_layer_copy_picked_channel (l_aux_channel_id /* dst_drawable_id*/ , 0 /* dst_channel_pick */ , work_drawable_id /* src_drawable_id */ , 0 /* src_channel_pick */ , FALSE /* gboolean shadow */ ); gimp_image_select_item(image_id, GIMP_CHANNEL_OP_REPLACE, l_aux_channel_id); gimp_image_remove_channel(image_id, l_aux_channel_id); gap_image_delete_immediate(dup_image_id); return (TRUE); } /* end gap_image_set_selection_from_selection_or_drawable */
/* -------------------------- * p_process_layer * -------------------------- */ static gint32 p_process_layer(gint32 image_id, gint32 drawable_id, TransValues *val_ptr) { gboolean has_selection; gboolean non_empty; gboolean alt_selection_success; gint x1, y1, x2, y2; gint32 trans_drawable_id; if(gap_debug) { printf("corpus_border_radius: %d\n", (int)val_ptr->corpus_border_radius); printf("alt_selection: %d\n", (int)val_ptr->alt_selection); printf("seed: %d\n", (int)val_ptr->seed); } gimp_image_undo_group_start(image_id); trans_drawable_id = -1; alt_selection_success = FALSE; if(val_ptr->alt_selection >= 0) { if(gap_debug) { printf("p_process_layer creating alt_selection: %d\n", (int)val_ptr->alt_selection); } alt_selection_success = p_set_alt_selection(image_id, drawable_id, val_ptr); } has_selection = gimp_selection_bounds(image_id, &non_empty, &x1, &y1, &x2, &y2); if(gap_debug) { printf("p_process_layer has_selection: %d\n", (int)has_selection); } /* here the action starts, we create the corpus_layer_id that builds the reference pattern * (the corpus is created in a spearate image and has an expanded selection * that excludes the unwanted parts) * then start the resynthesizer plug-in to replace selected (i.e. unwanted parts) of the * processed layer (i.e. drawable_id) */ if (non_empty) { gint32 corpus_layer_id; gint32 corpus_image_id; trans_drawable_id = drawable_id; corpus_layer_id = p_create_corpus_layer(image_id, drawable_id, val_ptr); p_pdb_call_resynthesizer(image_id, drawable_id, corpus_layer_id, val_ptr->seed); /* delete the temporary working duplicate */ corpus_image_id = gimp_item_get_image(corpus_layer_id); gimp_image_delete(corpus_image_id); } else { g_message("Please make a selection (cant operate on empty selection)"); } if(alt_selection_success) { gimp_selection_none(image_id); } gimp_image_undo_group_end(image_id); return (trans_drawable_id); } /* end p_process_layer */