static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[1]; gint32 image_ID; GimpPDBStatusType status = GIMP_PDB_SUCCESS; *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; INIT_I18N(); image_ID = param[1].data.d_image; if (status == GIMP_PDB_SUCCESS) { gimp_progress_init (_("Guillotine")); guillotine (image_ID); gimp_displays_flush (); } values[0].data.d_status = status; }
int ProgressIntern( int command, char* argument ) { double percentage; switch( command ) { case _initProgress: gimp_progress_init( argument ); return TRUE; break; case _setProgress: sscanf(argument,"%lf", &percentage); gimp_progress_update ((gdouble) percentage/100.0); return TRUE; break; case _disposeProgress: percentage = 1.0; gimp_progress_update ((gdouble) percentage); return TRUE; break; case _idleProgress: return TRUE; } return TRUE; }
static void compute_image (GimpDrawable *drawable) { GimpDrawable *effect; guchar *scalarfield = NULL; /* Get some useful info on the input drawable */ /* ========================================== */ if (! gimp_drawable_mask_intersect (drawable->drawable_id, &border_x, &border_y, &border_w, &border_h)) return; gimp_progress_init (_("Van Gogh (LIC)")); if (licvals.effect_convolve == 0) generatevectors (); if (licvals.filtlen < 0.1) licvals.filtlen = 0.1; l = licvals.filtlen; dx = dy = licvals.noisemag; minv = licvals.minv / 10.0; maxv = licvals.maxv / 10.0; isteps = licvals.intsteps; source_drw_has_alpha = gimp_drawable_has_alpha (drawable->drawable_id); effect = gimp_drawable_get (licvals.effect_image_id); effect_width = effect->width; effect_height = effect->height; switch (licvals.effect_channel) { case 0: scalarfield = rgb_to_hsl (effect, LIC_HUE); break; case 1: scalarfield = rgb_to_hsl (effect, LIC_SATURATION); break; case 2: scalarfield = rgb_to_hsl (effect, LIC_BRIGHTNESS); break; } compute_lic (drawable, scalarfield, licvals.effect_operator); g_free (scalarfield); /* Update image */ /* ============ */ gimp_drawable_flush (drawable); gimp_drawable_merge_shadow (drawable->drawable_id, TRUE); gimp_drawable_update (drawable->drawable_id, border_x, border_y, border_w, border_h); gimp_displays_flush (); }
static void run (const gchar *name, gint n_params, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[1]; GimpDrawable *drawable; GimpRunMode run_mode; GimpPDBStatusType status = GIMP_PDB_SUCCESS; gint32 image_id; *nreturn_vals = 1; *return_vals = values; run_mode = param[0].data.d_int32; if (run_mode == GIMP_RUN_NONINTERACTIVE) { if (n_params != 3) { status = GIMP_PDB_CALLING_ERROR; } } if (status == GIMP_PDB_SUCCESS) { /* Get the specified drawable */ drawable = gimp_drawable_get(param[2].data.d_drawable); image_id = param[1].data.d_image; /* Make sure that the drawable is gray or RGB or indexed */ if (gimp_drawable_is_rgb (drawable->drawable_id) || gimp_drawable_is_gray (drawable->drawable_id) || gimp_drawable_is_indexed (drawable->drawable_id)) { gimp_progress_init ("Autocropping..."); gimp_tile_cache_ntiles (1 + (drawable->width > drawable->height ? (drawable->width / gimp_tile_width()) : (drawable->height / gimp_tile_height()))); do_acrop(drawable, image_id); if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_displays_flush (); gimp_drawable_detach (drawable); } else { status = GIMP_PDB_EXECUTION_ERROR; } } values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; }
static void load_help_progress_start (const gchar *message, gboolean cancelable, gpointer user_data) { gimp_progress_init (message); }
static gint32 create_image (GdkPixbuf *pixbuf, GdkRegion *shape, const gchar *name) { gint32 image; gint32 layer; gdouble xres, yres; gchar *comment; gint width, height; gboolean status; status = gimp_progress_init (_("Importing screenshot")); width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf); image = gimp_image_new (width, height, GIMP_RGB); gimp_image_undo_disable (image); gimp_get_monitor_resolution (&xres, &yres); gimp_image_set_resolution (image, xres, yres); comment = gimp_get_default_comment (); if (comment) { GimpParasite *parasite; parasite = gimp_parasite_new ("gimp-comment", GIMP_PARASITE_PERSISTENT, strlen (comment) + 1, comment); gimp_image_parasite_attach (image, parasite); gimp_parasite_free (parasite); g_free (comment); } layer = gimp_layer_new_from_pixbuf (image, name ? name : _("Screenshot"), pixbuf, 100, GIMP_NORMAL_MODE, 0.0, 1.0); gimp_image_add_layer (image, layer, 0); if (shape && ! gdk_region_empty (shape)) { image_select_shape (image, shape); if (! gimp_selection_is_empty (image)) { gimp_layer_add_alpha (layer); gimp_edit_clear (layer); gimp_selection_none (image); } } gimp_image_undo_enable (image); return image; }
static void run (const gchar *name, gint n_params, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[1]; GimpRunMode run_mode; GimpPDBStatusType status = GIMP_PDB_SUCCESS; gint32 drawable_id; gint32 image_id; INIT_I18N (); gegl_init (NULL, NULL); *nreturn_vals = 1; *return_vals = values; run_mode = param[0].data.d_int32; if (run_mode == GIMP_RUN_NONINTERACTIVE) { if (n_params != 3) { status = GIMP_PDB_CALLING_ERROR; } } if (status == GIMP_PDB_SUCCESS) { /* Get the specified drawable */ image_id = param[1].data.d_int32; drawable_id = param[2].data.d_int32; /* Make sure that the drawable is gray or RGB or indexed */ if (gimp_drawable_is_rgb (drawable_id) || gimp_drawable_is_gray (drawable_id) || gimp_drawable_is_indexed (drawable_id)) { gimp_progress_init (_("Zealous cropping")); do_zcrop (drawable_id, image_id); if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_displays_flush (); } else { status = GIMP_PDB_EXECUTION_ERROR; } } values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; gegl_exit (); }
static void begin_print (GtkPrintOperation *operation, GtkPrintContext *context, PrintData *data) { gtk_print_operation_set_use_full_page (operation, data->use_full_page); gimp_progress_init (_("Printing")); }
pixel_outline_list_type find_outline_pixels (void) { pixel_outline_list_type outline_list; unsigned row, col; gint height; gint width; bitmap_type marked = local_new_bitmap (sel_get_width(),sel_get_height()); /* printf("width = %d, height = %d\n",BITMAP_WIDTH(marked),BITMAP_HEIGHT(marked)); */ gimp_progress_init (_("Selection to Path")); O_LIST_LENGTH (outline_list) = 0; outline_list.data = NULL; height = sel_get_height (); width = sel_get_width (); for (row = 0; row < height; row++) { for (col = 0; col < width; col++) { edge_type edge; if (sel_pixel_is_white(row, col)) continue; edge = next_unmarked_outline_edge (row, col, START_EDGE,marked); if (edge != no_edge) { pixel_outline_type outline; boolean clockwise = edge == bottom; outline = find_one_outline (edge, row, col, &marked); /* Outside outlines will start at a top edge, and move counterclockwise, and inside outlines will start at a bottom edge, and move clockwise. This happens because of the order in which we look at the edges. */ O_CLOCKWISE (outline) = clockwise; append_pixel_outline (&outline_list, outline); } } if ((row & 0xf) == 0) gimp_progress_update (((gdouble)row) / height); } gimp_progress_update (1.0); local_free_bitmap (&marked); return outline_list; }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[1]; GimpDrawable *drawable; GimpPDBStatusType status = GIMP_PDB_SUCCESS; GimpRunMode run_mode; gint32 image_ID; INIT_I18N(); run_mode = param[0].data.d_int32; /* Get the specified drawable */ drawable = gimp_drawable_get (param[2].data.d_drawable); image_ID = param[1].data.d_image; /* Make sure that the drawable is gray or RGB color */ if (gimp_drawable_is_rgb (drawable->drawable_id) || gimp_drawable_is_gray (drawable->drawable_id)) { gimp_progress_init (_("Auto-Stretching HSV")); gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1)); autostretch_hsv (drawable); if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_displays_flush (); } else if (gimp_drawable_is_indexed (drawable->drawable_id)) { indexed_autostretch_hsv (image_ID); if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_displays_flush (); } else { /* gimp_message ("autostretch_hsv: cannot operate on indexed color images"); */ status = GIMP_PDB_EXECUTION_ERROR; } *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; gimp_drawable_detach (drawable); }
static void scatter_hsv (GimpDrawable *drawable) { gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1)); gimp_progress_init (_("HSV Noise")); gimp_rgn_iterate2 (drawable, 0 /* unused */, scatter_hsv_func, NULL); gimp_drawable_detach (drawable); }
static GimpPDBStatusType run_pspi (const gchar *pdb_name, gint n_params, const GimpParam *param) { GimpRunMode run_mode = param[0].data.d_int32; GimpDrawable *drawable; GimpPDBStatusType status = GIMP_PDB_SUCCESS; PSPlugInEntry *pspie; gint x1, y1, x2, y2; get_saved_plugin_data (); if ((pspie = g_hash_table_lookup (entry_hash, pdb_name)) != NULL) { gchar *name; if (run_mode == GIMP_RUN_NONINTERACTIVE) { if (n_params != standard_nargs) return GIMP_PDB_CALLING_ERROR; } else if (run_mode == GIMP_RUN_INTERACTIVE) { if ((status = pspi_params (pspie)) != GIMP_PDB_SUCCESS) return status; } drawable = gimp_drawable_get (param[2].data.d_drawable); gimp_ui_init (PLUGIN_NAME, TRUE); if ((status = pspi_prepare (pspie, drawable)) != GIMP_PDB_SUCCESS) return status; name = g_strdup_printf (_("Applying %s:"), strrchr (pspie->menu_path, '/') + 1); gimp_progress_init (name); g_free (name); if ((status = pspi_apply (pspie, drawable)) != GIMP_PDB_SUCCESS) return status; gimp_drawable_flush (drawable); gimp_drawable_merge_shadow (drawable->drawable_id, TRUE); gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2); gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1)); gimp_displays_flush (); return GIMP_PDB_SUCCESS; } return GIMP_PDB_CALLING_ERROR; }
// Called before any real progress is made static void progressStart(gchar * message) { gimp_progress_init(message); gimp_progress_update(0.0); #ifdef DEBUG /* To console. On Windows, it annoyingly opens a console. On Unix it dissappears unless console already open. */ g_printf(message); g_printf("\n"); #endif }
static void mblur (GimpDrawable *drawable, GimpPreview *preview) { gint x, y; gint width, height; if (preview) { gimp_preview_get_position (preview, &x, &y); gimp_preview_get_size (preview, &width, &height); } else { gimp_drawable_mask_bounds (drawable->drawable_id, &x, &y, &width, &height); width -= x; height -= y; } if (width < 1 || height < 1) return; if (! preview) gimp_progress_init (_("Motion blurring")); switch (mbvals.mblur_type) { case MBLUR_LINEAR: mblur_linear (drawable, preview, x, y, width, height); break; case MBLUR_RADIAL: mblur_radial (drawable, preview, x, y, width, height); break; case MBLUR_ZOOM: mblur_zoom (drawable, preview, x, y, width, height); break; default: break; } if (! preview) { gimp_drawable_flush (drawable); gimp_drawable_merge_shadow (drawable->drawable_id, TRUE); gimp_drawable_update (drawable->drawable_id, x, y, width, height); } }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[3]; GimpRunMode run_mode = param[0].data.d_int32; GimpPDBStatusType status = GIMP_PDB_SUCCESS; *nreturn_vals = 3; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; values[1].type = GIMP_PDB_INT32; values[1].data.d_int32 = 0; values[2].type = GIMP_PDB_INT32ARRAY; values[2].data.d_int32array = NULL; INIT_I18N(); if (status == GIMP_PDB_SUCCESS) { GList *images; GList *list; gint i; gimp_progress_init (_("Guillotine")); images = guillotine (param[1].data.d_image, run_mode == GIMP_RUN_INTERACTIVE); values[1].data.d_int32 = g_list_length (images); values[2].data.d_int32array = g_new (gint32, values[1].data.d_int32); for (list = images, i = 0; list; list = g_list_next (list), i++) { values[2].data.d_int32array[i] = GPOINTER_TO_INT (list->data); } g_list_free (images); if (run_mode == GIMP_RUN_INTERACTIVE) gimp_displays_flush (); } values[0].data.d_status = status; }
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); }
/* * Red Eye Removal Alorithm, based on using a threshold to detect * red pixels. Having a user-made selection around the eyes will * prevent incorrect pixels from being selected. */ static void remove_redeye (GimpDrawable *drawable) { GimpPixelRgn src_rgn; GimpPixelRgn dest_rgn; gint progress, max_progress; gboolean has_alpha; gint x, y; gint width, height; gint i; gpointer pr; if (! gimp_drawable_mask_intersect (drawable->drawable_id, &x, &y, &width, &height)) return; gimp_progress_init (_("Removing red eye")); has_alpha = gimp_drawable_has_alpha (drawable->drawable_id); progress = 0; max_progress = width * height; gimp_pixel_rgn_init (&src_rgn, drawable, x, y, width, height, FALSE, FALSE); gimp_pixel_rgn_init (&dest_rgn, drawable, x, y, width, height, TRUE, TRUE); for (pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn), i = 0; pr != NULL; pr = gimp_pixel_rgns_process (pr), i++) { redeye_inner_loop (src_rgn.data, dest_rgn.data, src_rgn.w, src_rgn.h, src_rgn.bpp, has_alpha, src_rgn.rowstride); progress += src_rgn.w * src_rgn.h; if (i % 16 == 0) gimp_progress_update ((gdouble) progress / (gdouble) max_progress); } gimp_progress_update (1.0); gimp_drawable_flush (drawable); gimp_drawable_merge_shadow (drawable->drawable_id, TRUE); gimp_drawable_update (drawable->drawable_id, x, y, width, height); }
static gint32 load_image (const gchar *filename, GError **load_error) { gint32 image; gint32 layer; GdkPixbuf *pixbuf; gint width; gint height; GError *error = NULL; pixbuf = load_rsvg_pixbuf (filename, &load_vals, &error); if (! pixbuf) { /* Do not rely on librsvg setting GError on failure! */ g_set_error (load_error, error ? error->domain : 0, error ? error->code : 0, _("Could not open '%s' for reading: %s"), gimp_filename_to_utf8 (filename), error ? error->message : _("Unknown reason")); g_clear_error (&error); return -1; } gimp_progress_init (_("Rendering SVG")); width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf); image = gimp_image_new (width, height, GIMP_RGB); gimp_image_undo_disable (image); gimp_image_set_filename (image, filename); gimp_image_set_resolution (image, load_vals.resolution, load_vals.resolution); layer = gimp_layer_new_from_pixbuf (image, _("Rendered SVG"), pixbuf, 100, GIMP_NORMAL_MODE, 0.0, 1.0); gimp_image_insert_layer (image, layer, -1, 0); gimp_image_undo_enable (image); return image; }
static GimpPDBStatusType main_function (GimpDrawable *drawable, GimpPreview *preview) { MaxRgbParam_t param; param.init_value = (pvals.max_p > 0) ? 0 : 255; param.flag = (0 < pvals.max_p) ? 1 : -1; param.has_alpha = gimp_drawable_has_alpha (drawable->drawable_id); if (preview) { gint i; guchar *buffer; guchar *src; gint width, height, bpp; src = gimp_zoom_preview_get_source (GIMP_ZOOM_PREVIEW (preview), &width, &height, &bpp); buffer = g_new (guchar, width * height * bpp); for (i = 0; i < width * height; i++) { max_rgb_func (src + i * bpp, buffer + i * bpp, bpp, ¶m); } gimp_preview_draw_buffer (preview, buffer, width * bpp); g_free (buffer); g_free (src); } else { gimp_progress_init (_("Max RGB")); gimp_rgn_iterate2 (drawable, 0 /* unused */, max_rgb_func, ¶m); gimp_drawable_detach (drawable); } return GIMP_PDB_SUCCESS; }
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; GimpRunMode run_mode; GimpDrawable *drawable; /* Setting mandatory output values */ *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; /* Getting run_mode - we won't display a dialog if * we are in NONINTERACTIVE mode */ run_mode = param[0].data.d_int32; /* Get the specified drawable */ drawable = gimp_drawable_get (param[2].data.d_drawable); gimp_progress_init ("Exponential Range ..."); /* * * GTimer timer = g_timer_new time (); */ exponentialrange (drawable); /* g_print ("blur() took %g seconds.\n", g_timer_elapsed (timer)); * g_timer_destroy (timer); */ gimp_displays_flush (); gimp_drawable_detach (drawable); }
static gint32 page_curl (gint32 drawable_id) { gint curl_layer_id; gimp_image_undo_group_start (image_id); gimp_progress_init (_("Page Curl")); init_calculation (drawable_id); curl_layer_id = do_curl_effect (drawable_id); clear_curled_region (drawable_id); gimp_image_undo_group_end (image_id); return curl_layer_id; }
/** * gimp_progress_init_printf: * @format: a standard printf() format string * @Varargs: arguments for @format * * Initializes the progress bar for the current plug-in. * * Initializes the progress bar for the current plug-in. It is only * valid to call this procedure from a plug-in. * * Returns: %TRUE on success. * * Since: GIMP 2.4 **/ gboolean gimp_progress_init_printf (const gchar *format, ...) { gchar *text; gboolean retval; va_list args; g_return_val_if_fail (format != NULL, FALSE); va_start (args, format); text = g_strdup_vprintf (format, args); va_end (args); retval = gimp_progress_init (text); g_free (text); return retval; }
static void polarize (GimpDrawable *drawable) { GimpRgnIterator *iter; GimpPixelFetcher *pft; GimpRGB background; pft = gimp_pixel_fetcher_new (drawable, FALSE); gimp_context_get_background (&background); gimp_rgb_set_alpha (&background, 0.0); gimp_pixel_fetcher_set_bg_color (pft, &background); gimp_pixel_fetcher_set_edge_mode (pft, GIMP_PIXEL_FETCHER_EDGE_SMEAR); gimp_progress_init (_("Polar coordinates")); iter = gimp_rgn_iterator_new (drawable, 0); gimp_rgn_iterator_dest (iter, polarize_func, pft); gimp_rgn_iterator_free (iter); gimp_pixel_fetcher_destroy (pft); }
static gboolean copy_file (GFile *src_file, GFile *dest_file, Mode mode, GimpRunMode run_mode, GError **error) { UriProgress progress = { 0, }; gboolean success; gimp_progress_init (_("Connecting to server")); progress.mode = mode; success = g_file_copy (src_file, dest_file, G_FILE_COPY_OVERWRITE, NULL, uri_progress_callback, &progress, error); gimp_progress_update (1.0); if (! success && run_mode == GIMP_RUN_INTERACTIVE && (*error)->domain == G_IO_ERROR && (*error)->code == G_IO_ERROR_NOT_MOUNTED) { g_clear_error (error); if (mount_enclosing_volume (mode == DOWNLOAD ? src_file : dest_file, error)) { success = g_file_copy (src_file, dest_file, 0, NULL, uri_progress_callback, &progress, error); } } return success; }
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; GimpRunMode run_mode; GimpDrawable *drawable; /* Setting mandatory output values */ *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; /* Getting run_mode - we won't display a dialog if * we are in NONINTERACTIVE mode */ run_mode = param[0].data.d_int32; /* Get the specified drawable */ drawable = gimp_drawable_get(param[2].data.d_drawable); gimp_progress_init("Dotify..."); /* Let's time blur * * GTimer timer = g_timer_new time(); */ srand(time(NULL)); blur(drawable); gimp_displays_flush(); gimp_drawable_detach(drawable); }
static void lens_distort (GimpDrawable *drawable) { GimpRgnIterator *iter; GimpPixelFetcher *pft; GimpRGB background; lens_setup_calc (drawable->width, drawable->height); pft = gimp_pixel_fetcher_new (drawable, FALSE); gimp_context_get_background (&background); gimp_rgb_set_alpha (&background, 0.0); gimp_pixel_fetcher_set_bg_color (pft, &background); gimp_pixel_fetcher_set_edge_mode (pft, GIMP_PIXEL_FETCHER_EDGE_BACKGROUND); gimp_progress_init (_("Lens distortion")); iter = gimp_rgn_iterator_new (drawable, 0); gimp_rgn_iterator_dest (iter, (GimpRgnFuncDest) lens_distort_func, pft); gimp_rgn_iterator_free (iter); gimp_pixel_fetcher_destroy (pft); }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[1]; GimpDrawable *drawable; GimpRunMode run_mode; GimpPDBStatusType status = GIMP_PDB_SUCCESS; run_mode = param[0].data.d_int32; INIT_I18N (); *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; /* Get the specified drawable */ drawable = gimp_drawable_get (param[2].data.d_drawable); switch (run_mode) { case GIMP_RUN_INTERACTIVE: /* Possibly retrieve data */ gimp_get_data (PIXELIZE_PROC, &pvals); /* First acquire information with a dialog */ if (! pixelize_dialog (drawable)) { gimp_drawable_detach (drawable); return; } break; case GIMP_RUN_NONINTERACTIVE: /* Make sure all the arguments are there! */ if ((! strcmp (name, PIXELIZE_PROC) && nparams != 4) || (! strcmp (name, PIXELIZE2_PROC) && nparams != 5)) { status = GIMP_PDB_CALLING_ERROR; } if (status == GIMP_PDB_SUCCESS) { pvals.pixelwidth = (gdouble) param[3].data.d_int32; if (nparams == 4) pvals.pixelheight = pvals.pixelwidth; else pvals.pixelheight = (gdouble) param[4].data.d_int32; } if ((status == GIMP_PDB_SUCCESS) && (pvals.pixelwidth <= 0 || pvals.pixelheight <= 0)) { status = GIMP_PDB_CALLING_ERROR; } break; case GIMP_RUN_WITH_LAST_VALS: /* Possibly retrieve data */ gimp_get_data (PIXELIZE_PROC, &pvals); break; default: break; } if (status == GIMP_PDB_SUCCESS) { /* Make sure that the drawable is gray or RGB color */ if (gimp_drawable_is_rgb (drawable->drawable_id) || gimp_drawable_is_gray (drawable->drawable_id)) { gimp_progress_init (_("Pixelizing")); /* set the tile cache size */ gimp_tile_cache_ntiles (TILE_CACHE_SIZE); /* run the pixelize effect */ pixelize (drawable, NULL); if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_displays_flush (); /* Store data */ if (run_mode == GIMP_RUN_INTERACTIVE) gimp_set_data (PIXELIZE_PROC, &pvals, sizeof (PixelizeValues)); } else { /* g_message ("pixelize: cannot operate on indexed color images"); */ status = GIMP_PDB_EXECUTION_ERROR; } } values[0].data.d_status = status; gimp_drawable_detach (drawable); }
static inline void filter (void) { static void (* overlap)(guchar *, const guchar *); GimpPixelRgn src; GimpPixelRgn dst; GimpRGB color; guchar pixel[4]; gint division_x; gint division_y; gint offset_x; gint offset_y; Tile *tiles; gint numof_tiles; Tile *t; gint i; gint x; gint y; gint move_max_pixels; gint clear_x0; gint clear_y0; gint clear_x1; gint clear_y1; gint clear_width; gint clear_height; guchar *pixels; guchar *buffer; gint dindex; gint sindex; gint px, py; GRand *gr; gr = g_rand_new (); /* INITIALIZE */ gimp_pixel_rgn_init (&src, p.drawable, 0, 0, p.drawable->width, p.drawable->height, FALSE, FALSE); gimp_pixel_rgn_init (&dst, p.drawable, 0, 0, p.drawable->width, p.drawable->height, TRUE, TRUE); pixels = g_new (guchar, p.drawable->bpp * p.drawable->width * p.drawable->height); buffer = g_new (guchar, p.drawable->bpp * p.params.tile_width * p.params.tile_height); overlap = p.drawable_has_alpha ? overlap_RGBA : overlap_RGB; gimp_progress_init (_("Paper Tile")); gimp_drawable_mask_bounds (p.drawable->drawable_id, &p.selection.x0, &p.selection.y0, &p.selection.x1, &p.selection.y1); p.selection.width = p.selection.x1 - p.selection.x0; p.selection.height = p.selection.y1 - p.selection.y0; gimp_tile_cache_ntiles (2 * (p.selection.width / gimp_tile_width () + 1)); /* TILES */ division_x = p.params.division_x; division_y = p.params.division_y; if (p.params.fractional_type == FRACTIONAL_TYPE_FORCE) { if (0 < p.drawable->width % p.params.tile_width) division_x++; if (0 < p.drawable->height % p.params.tile_height) division_y++; if (p.params.centering) { if (1 < p.drawable->width % p.params.tile_width) { division_x++; offset_x = (p.drawable->width % p.params.tile_width) / 2 - p.params.tile_width; } else { offset_x = 0; } if (1 < p.drawable->height % p.params.tile_height) { division_y++; offset_y = (p.drawable->height % p.params.tile_height) / 2 - p.params.tile_height; } else { offset_y = 0; } } else { offset_x = 0; offset_y = 0; } } else { if (p.params.centering) { offset_x = (p.drawable->width % p.params.tile_width) / 2; offset_y = (p.drawable->height % p.params.tile_height) / 2; } else { offset_x = 0; offset_y = 0; } } move_max_pixels = p.params.move_max_rate * p.params.tile_width / 100.0; numof_tiles = division_x * division_y; t = tiles = g_new(Tile, numof_tiles); for (y = 0; y < division_y; y++) { gint srcy = offset_y + p.params.tile_height * y; for (x = 0; x < division_x; x++, t++) { gint srcx = offset_x + p.params.tile_width * x; if (srcx < 0) { t->x = 0; t->width = srcx + p.params.tile_width; } else if (srcx + p.params.tile_width < p.drawable->width) { t->x = srcx; t->width = p.params.tile_width; } else { t->x = srcx; t->width = p.drawable->width - srcx; } if (srcy < 0) { t->y = 0; t->height = srcy + p.params.tile_height; } else if (srcy + p.params.tile_height < p.drawable->height) { t->y = srcy; t->height = p.params.tile_height; } else { t->y = srcy; t->height = p.drawable->height - srcy; } t->z = g_rand_int (gr); random_move (&t->move_x, &t->move_y, move_max_pixels); } } qsort (tiles, numof_tiles, sizeof *tiles, tile_compare); gimp_pixel_rgn_get_rect (&src, pixels, 0, 0, p.drawable->width, p.drawable->height); if (p.params.fractional_type == FRACTIONAL_TYPE_IGNORE) { clear_x0 = offset_x; clear_y0 = offset_y; clear_width = p.params.tile_width * division_x; clear_height = p.params.tile_height * division_y; } else { clear_x0 = 0; clear_y0 = 0; clear_width = p.drawable->width; clear_height = p.drawable->height; } clear_x1 = clear_x0 + clear_width; clear_y1 = clear_y0 + clear_height; switch (p.params.background_type) { case BACKGROUND_TYPE_TRANSPARENT: for (y = clear_y0; y < clear_y1; y++) { for (x = clear_x0; x < clear_x1; x++) { dindex = p.drawable->bpp * (p.drawable->width * y + x); for (i = 0; i < p.drawable->bpp; i++) { pixels[dindex+i] = 0; } } } break; case BACKGROUND_TYPE_INVERTED: for (y = clear_y0; y < clear_y1; y++) { for (x = clear_x0; x < clear_x1; x++) { dindex = p.drawable->bpp * (p.drawable->width * y + x); pixels[dindex+0] = 255 - pixels[dindex+0]; pixels[dindex+1] = 255 - pixels[dindex+1]; pixels[dindex+2] = 255 - pixels[dindex+2]; } } break; case BACKGROUND_TYPE_IMAGE: break; case BACKGROUND_TYPE_FOREGROUND: gimp_context_get_foreground (&color); gimp_rgb_get_uchar (&color, &pixel[0], &pixel[1], &pixel[2]); pixel[3] = 255; for (y = clear_y0; y < clear_y1; y++) { for (x = clear_x0; x < clear_x1; x++) { dindex = p.drawable->bpp * (p.drawable->width * y + x); for (i = 0; i < p.drawable->bpp; i++) { pixels[dindex+i] = pixel[i]; } } } break; case BACKGROUND_TYPE_BACKGROUND: gimp_context_get_background (&color); gimp_rgb_get_uchar (&color, &pixel[0], &pixel[1], &pixel[2]); pixel[3] = 255; for (y = clear_y0; y < clear_y1; y++) { for (x = clear_x0; x < clear_x1; x++) { dindex = p.drawable->bpp * (p.drawable->width * y + x); for(i = 0; i < p.drawable->bpp; i++) { pixels[dindex+i] = pixel[i]; } } } break; case BACKGROUND_TYPE_COLOR: gimp_rgba_get_uchar (&p.params.background_color, pixel, pixel + 1, pixel + 2, pixel + 3); for (y = clear_y0; y < clear_y1; y++) { for (x = clear_x0; x < clear_x1; x++) { dindex = p.drawable->bpp * (p.drawable->width * y + x); for(i = 0; i < p.drawable->bpp; i++) { pixels[dindex+i] = pixel[i]; } } } break; } /* DRAW */ for (t = tiles, i = 0; i < numof_tiles; i++, t++) { gint x0 = t->x + t->move_x; gint y0 = t->y + t->move_y; gimp_pixel_rgn_get_rect (&src, buffer, t->x, t->y, t->width, t->height); for (y = 0; y < t->height; y++) { py = y0 + y; for (x = 0; x < t->width; x++) { px = x0 + x; sindex = p.drawable->bpp * (t->width * y + x); if (0 <= px && px < p.drawable->width && 0 <= py && py < p.drawable->height) { dindex = p.drawable->bpp * (p.drawable->width * py + px); overlap(&pixels[dindex], &buffer[sindex]); } else if (p.params.wrap_around) { px = (px + p.drawable->width) % p.drawable->width; py = (py + p.drawable->height) % p.drawable->height; dindex = p.drawable->bpp * (p.drawable->width * py + px); overlap(&pixels[dindex], &buffer[sindex]); } } } gimp_progress_update ((gdouble) i / (gdouble) numof_tiles); } gimp_pixel_rgn_set_rect (&dst, pixels, 0, 0, p.drawable->width, p.drawable->height); gimp_progress_update (1.0); gimp_drawable_flush (p.drawable); gimp_drawable_merge_shadow (p.drawable->drawable_id, TRUE); gimp_drawable_update (p.drawable->drawable_id, p.selection.x0, p.selection.y0, p.selection.width, p.selection.height); g_rand_free (gr); g_free (buffer); g_free (pixels); g_free (tiles); }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[3]; GimpRunMode run_mode; GimpPDBStatusType status = GIMP_PDB_SUCCESS; gint32 new_layer = -1; gint width; gint height; run_mode = param[0].data.d_int32; INIT_I18N (); *nreturn_vals = 3; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; values[1].type = GIMP_PDB_IMAGE; values[2].type = GIMP_PDB_LAYER; width = gimp_drawable_width (param[2].data.d_drawable); height = gimp_drawable_height (param[2].data.d_drawable); switch (run_mode) { case GIMP_RUN_INTERACTIVE: /* Possibly retrieve data */ gimp_get_data (PLUG_IN_PROC, &tvals); /* First acquire information with a dialog */ if (! tile_dialog (param[1].data.d_image, param[2].data.d_drawable)) return; break; case GIMP_RUN_NONINTERACTIVE: /* Make sure all the arguments are there! */ if (nparams != 6) { status = GIMP_PDB_CALLING_ERROR; } else { tvals.new_width = param[3].data.d_int32; tvals.new_height = param[4].data.d_int32; tvals.new_image = param[5].data.d_int32 ? TRUE : FALSE; if (tvals.new_width < 0 || tvals.new_height < 0) status = GIMP_PDB_CALLING_ERROR; } break; case GIMP_RUN_WITH_LAST_VALS: /* Possibly retrieve data */ gimp_get_data (PLUG_IN_PROC, &tvals); break; default: break; } if (status == GIMP_PDB_SUCCESS) { gimp_progress_init (_("Tiling")); values[1].data.d_image = tile (param[1].data.d_image, param[2].data.d_drawable, &new_layer); values[2].data.d_layer = new_layer; /* Store data */ if (run_mode == GIMP_RUN_INTERACTIVE) gimp_set_data (PLUG_IN_PROC, &tvals, sizeof (TileVals)); if (run_mode != GIMP_RUN_NONINTERACTIVE) { if (tvals.new_image) gimp_display_new (values[1].data.d_image); else gimp_displays_flush (); } } values[0].data.d_status = status; }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[1]; gint32 image_ID; GimpDrawable *drawable; GimpRunMode run_mode; GimpPDBStatusType status = GIMP_PDB_SUCCESS; run_mode = param[0].data.d_int32; INIT_I18N (); *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; /* Get the specified image and drawable */ image_ID = param[1].data.d_image; drawable = gimp_drawable_get (param[2].data.d_drawable); /* set the tile cache size so that the gaussian blur works well */ gimp_tile_cache_ntiles (2 * (MAX (drawable->width, drawable->height) / gimp_tile_width () + 1)); if (strcmp (name, PLUG_IN_PROC) == 0) { switch (run_mode) { case GIMP_RUN_INTERACTIVE: /* Possibly retrieve data */ gimp_get_data (PLUG_IN_PROC, &dogvals); /* First acquire information with a dialog */ if (! dog_dialog (image_ID, drawable)) return; break; case GIMP_RUN_NONINTERACTIVE: /* Make sure all the arguments are there! */ if (nparams != 7) status = GIMP_PDB_CALLING_ERROR; if (status == GIMP_PDB_SUCCESS) { dogvals.inner = param[3].data.d_float; dogvals.outer = param[4].data.d_float; dogvals.normalize = param[5].data.d_int32; dogvals.invert = param[6].data.d_int32; } if (status == GIMP_PDB_SUCCESS && (dogvals.inner <= 0.0 && dogvals.outer <= 0.0)) status = GIMP_PDB_CALLING_ERROR; break; case GIMP_RUN_WITH_LAST_VALS: /* Possibly retrieve data */ gimp_get_data (PLUG_IN_PROC, &dogvals); break; default: break; } } else { status = GIMP_PDB_CALLING_ERROR; } if (status == GIMP_PDB_SUCCESS) { /* Make sure that the drawable is gray or RGB color */ if (gimp_drawable_is_rgb (drawable->drawable_id) || gimp_drawable_is_gray (drawable->drawable_id)) { gimp_progress_init (_("DoG Edge Detect")); /* run the Difference of Gaussians */ gimp_image_undo_group_start (image_ID); dog (image_ID, drawable, dogvals.inner, dogvals.outer, TRUE); gimp_image_undo_group_end (image_ID); gimp_progress_update (1.0); /* Store data */ if (run_mode == GIMP_RUN_INTERACTIVE) gimp_set_data (PLUG_IN_PROC, &dogvals, sizeof (DoGValues)); if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_displays_flush (); } else { g_message (_("Cannot operate on indexed color images.")); status = GIMP_PDB_EXECUTION_ERROR; } gimp_drawable_detach (drawable); } values[0].data.d_status = status; }