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; }
static void gimp_aspect_preview_draw_buffer (GimpPreview *preview, const guchar *buffer, gint rowstride) { GimpDrawable *drawable = GIMP_ASPECT_PREVIEW (preview)->drawable; gint32 image_id; image_id = gimp_item_get_image (drawable->drawable_id); if (gimp_selection_is_empty (image_id)) { gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview->area), 0, 0, preview->width, preview->height, gimp_drawable_type (drawable->drawable_id), buffer, rowstride); } else { guchar *sel; guchar *src; gint selection_id; gint width, height; gint bpp; selection_id = gimp_image_get_selection (image_id); width = preview->width; height = preview->height; src = gimp_drawable_get_thumbnail_data (drawable->drawable_id, &width, &height, &bpp); sel = gimp_drawable_get_thumbnail_data (selection_id, &width, &height, &bpp); gimp_preview_area_mask (GIMP_PREVIEW_AREA (preview->area), 0, 0, preview->width, preview->height, gimp_drawable_type (drawable->drawable_id), src, width * drawable->bpp, buffer, rowstride, sel, width); g_free (sel); g_free (src); } }
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; }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[1]; GimpPDBStatusType status = GIMP_PDB_SUCCESS; *nreturn_vals = 1; *return_vals = values; INIT_I18N (); values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; Current.drawable = gimp_drawable_get (param[2].data.d_drawable); Current.mask = gimp_drawable_get (gimp_image_get_selection (param[1].data.d_image)); if (gimp_drawable_is_rgb (Current.drawable->drawable_id)) { if (color_rotate_dialog ()) { gimp_progress_init (_("Rotating the colors")); gimp_tile_cache_ntiles (2 * (Current.drawable->width / gimp_tile_width () + 1)); color_rotate (Current.drawable); gimp_displays_flush (); } else { status = GIMP_PDB_CANCEL; } } else { status = GIMP_PDB_EXECUTION_ERROR; } values[0].data.d_status = status; if (status == GIMP_PDB_SUCCESS) gimp_drawable_detach (Current.drawable); }
void dialogMaskChangedCallback(GtkWidget *widget, PlugInVals *vals) { gint value; #ifdef DEBUG g_warning("dialogMaskChangedCallback"); #endif if (GTK_WIDGET_SENSITIVE(widget)) { //if (gtk_widget_get_sensitive(widget)) { if (gimp_int_combo_box_get_active(GIMP_INT_COMBO_BOX(widget),&value)) { vals->mask_drawable_id = value; } else { vals->mask_drawable_id = -1; } } else { vals->mask_drawable_id = gimp_image_get_selection(gimp_drawable_get_image(vals->image_drawable_id)); } update_mask(vals); renderPreview(vals); }
/* do the analyzing */ static void analyze (GimpDrawable *drawable) { GimpPixelRgn srcPR; guchar *src_row, *cmap; gint x, y, numcol; gint x1, y1, x2, y2, w, h; guchar r, g, b; gint a; guchar idx; gboolean gray; gboolean has_alpha; gboolean has_sel; guchar *sel; GimpPixelRgn selPR; gint ofsx, ofsy; GimpDrawable *selDrawable; gimp_progress_init (_("Colorcube Analysis")); if (! gimp_drawable_mask_intersect (drawable->drawable_id, &x1, &y1, &w, &h)) return; x2 = x1 + w; y2 = y1 + h; /* * Get the size of the input image (this will/must be the same * as the size of the output image). */ width = drawable->width; height = drawable->height; bpp = drawable->bpp; has_sel = !gimp_selection_is_empty (imageID); gimp_drawable_offsets (drawable->drawable_id, &ofsx, &ofsy); /* initialize the pixel region */ gimp_pixel_rgn_init (&srcPR, drawable, 0, 0, width, height, FALSE, FALSE); cmap = gimp_image_get_colormap (imageID, &numcol); gray = (gimp_drawable_is_gray (drawable->drawable_id) || gimp_item_is_channel (drawable->drawable_id)); has_alpha = gimp_drawable_has_alpha (drawable->drawable_id); selDrawable = gimp_drawable_get (gimp_image_get_selection (imageID)); gimp_pixel_rgn_init (&selPR, selDrawable, 0, 0, width, height, FALSE, FALSE); /* allocate row buffer */ src_row = g_new (guchar, (x2 - x1) * bpp); sel = g_new (guchar, x2 - x1); for (y = y1; y < y2; y++) { gimp_pixel_rgn_get_row (&srcPR, src_row, x1, y, (x2 - x1)); if (has_sel) gimp_pixel_rgn_get_row (&selPR, sel, x1 + ofsx, y + ofsy, (x2 - x1)); for (x = 0; x < w; x++) { /* Start with full opacity. */ a = 255; /* * If the image is indexed, fetch RGB values * from colormap. */ if (cmap) { idx = src_row[x * bpp]; r = cmap[idx * 3]; g = cmap[idx * 3 + 1]; b = cmap[idx * 3 + 2]; if (has_alpha) a = src_row[x * bpp + 1]; } else if (gray) { r = g = b = src_row[x * bpp]; if (has_alpha) a = src_row[x * bpp + 1]; } else { r = src_row[x * bpp]; g = src_row[x * bpp + 1]; b = src_row[x * bpp + 2]; if (has_alpha) a = src_row[x * bpp + 3]; } if (has_sel) a *= sel[x]; else a *= 255; if (a != 0) insertcolor (r, g, b, (gdouble) a * (1.0 / (255.0 * 255.0))); } /* tell the user what we're doing */ if ((y % 10) == 0) gimp_progress_update ((gdouble) y / (gdouble) (y2 - y1)); } gimp_progress_update (1.0); /* clean up */ gimp_drawable_detach (selDrawable); g_free (src_row); g_free (sel); }
/* ------------------------------------------------------- * 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 */