From xbouchou@ensisun.imag.fr Fri Apr 25 08:27:35 1997 Date: Fri, 25 Apr 1997 00:29:29 +0200 (MET DST) From: Xavier Bouchoux To: gimp-developer@scam.XCF.Berkeley.EDU Hi! I send a patch for my plug-in (holes) because I've just got the new gimp 0.99.8, and I saw that they put my plug-in in a very alpha version. Now you'll get the dialog box and a new shape (coooool! ;-) and a better (I hope) explanation of the parameters for the pdb. It misses somethings to be 1.0: for example antialiasing the shape (Perhaps someone will find a use with big shapes....) or adding a preview... For now here is just this patch: *** holes.bak Thu Apr 24 23:27:15 1997 --- holes.c Fri Apr 25 00:14:39 1997 *************** *** 10,15 **** --- 10,18 --- * copy of the GNU General Public License * along with this program; if not, * write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA * 02139, USA. */ + + /* Holes 0.5 */ + #include #include #include *************** static HolesInterface pint = *** 87,99 **** typedef struct { float density; ! gint shape, size, inv; } holes_parameters; /* possible shapes */ #define SQUARE_SHAPE 0 #define CIRCLE_SHAPE 1 ! static holes_parameters params = { -3.1, CIRCLE_SHAPE, 8, TRUE }; --- 90,103 ---- typedef struct { float density; ! gint shape, size, flag; } holes_parameters; /* possible shapes */ #define SQUARE_SHAPE 0 #define CIRCLE_SHAPE 1 ! #define DIAMOND_SHAPE 2 ! static holes_parameters params = { -3.1, CIRCLE_SHAPE, 8, TRUE }; *************** static void query() *** 106,131 **** {PARAM_INT32, "run_mode", "Interactive, non-interactive"}, {PARAM_IMAGE, "image", "Input image (unused)"}, {PARAM_DRAWABLE, "drawable", "Input drawable"}, ! {PARAM_FLOAT, "density", "Density"}, ! {PARAM_INT32, "shape", "shape"}, {PARAM_INT32, "size", "size (in pixels)"}, ! {PARAM_INT32, "invert", "This flag chooses if the plug-in keeps the transparent regions transparent (=0), or if it keep the opaque regions opaque (=1)"}, }; static GParamDef *return_vals = NULL; static int nargs = sizeof(args) / sizeof(args[0]); static int nreturn_vals = 0; gimp_install_procedure("plug_in_holes", ! "make bucks on a image.", ! "makes holes in the alpha channel of an image, with a density depending on the actual transparency of this image. (so the image must have an alpha channel...)", ! "Xavier Bouchoux", ! "Xavier Bouchoux", ! "1997", ! "/Filters/Holes", ! "RGBA, GRAYA, INDEXEDA", ! PROC_PLUG_IN, ! nargs, nreturn_vals, ! args, return_vals); } static void run(char *name, int n_params, GParam * param, int *nreturn_vals, --- 110,136 ---- {PARAM_INT32, "run_mode", "Interactive, non-interactive"}, {PARAM_IMAGE, "image", "Input image (unused)"}, {PARAM_DRAWABLE, "drawable", "Input drawable"}, ! {PARAM_FLOAT, "density", "Density (actually the log of the density)"}, ! {PARAM_INT32, "shape", "shape (0= square, 1= round, 2= diamond)"}, {PARAM_INT32, "size", "size (in pixels)"}, ! {PARAM_INT32, "flag", "Clear it if you want to make holes in your image, or set it if you want to keep the painted (I mean opaque) regions."}, }; static GParamDef *return_vals = NULL; static int nargs = sizeof(args) / sizeof(args[0]); static int nreturn_vals = 0; gimp_install_procedure("plug_in_holes", ! "make bucks on a image.", ! "makes holes in the alpha channel of an image, with a density depending on the actual transparency of this image. (so the image must have an alpha channel...)", ! "Xavier Bouchoux", ! "Xavier Bouchoux", ! "1997", ! "/Filters/Holes", ! "RGBA, GRAYA, INDEXEDA", ! PROC_PLUG_IN, ! nargs, nreturn_vals, ! args, return_vals ! ); } static void run(char *name, int n_params, GParam * param, int *nreturn_vals, *************** static void run(char *name, int n_params *** 148,167 **** params.density = param[3].data.d_float; params.shape = param[4].data.d_int32; params.size = param[5].data.d_int32; ! params.inv = param[6].data.d_int32; } } else { /* Possibly retrieve data */ gimp_get_data("plug_in_holes", ¶ms); ! if ((run_mode == RUN_INTERACTIVE) && gimp_drawable_has_alpha (drawable->id) && (gimp_drawable_color(drawable->id) || gimp_drawable_gray(drawable->id) ||gimp_drawable_indexed (drawable->id))) { /* Oh boy. We get to do a dialog box, because we can't really expect the * user to set us up with the right values using gdb. */ if (!dialog()) { /* The dialog was closed, or something similarly evil happened. */ status = STATUS_EXECUTION_ERROR; ! } } } --- 153,172 ---- params.density = param[3].data.d_float; params.shape = param[4].data.d_int32; params.size = param[5].data.d_int32; ! params.flag = param[6].data.d_int32; } } else { /* Possibly retrieve data */ gimp_get_data("plug_in_holes", ¶ms); ! if ((run_mode == RUN_INTERACTIVE) ) { /* Oh boy. We get to do a dialog box, because we can't really expect the * user to set us up with the right values using gdb. */ if (!dialog()) { /* The dialog was closed, or something similarly evil happened. */ status = STATUS_EXECUTION_ERROR; ! } } } *************** static void run(char *name, int n_params *** 197,209 **** static void make_curve (gdouble sigma) { gdouble sigma2; ! gdouble l; ! gint temp; ! gint i, n; sigma2 = 2 * sigma * sigma; ! if (params.inv) for (i = 0; i < 256; i++) { curve[i] = (gint) (exp (- (i/22.0 * i/22.0) / sigma2) * RAND_MAX); --- 202,212 ---- static void make_curve (gdouble sigma) { gdouble sigma2; ! gint i; sigma2 = 2 * sigma * sigma; ! if (params.flag) for (i = 0; i < 256; i++) { curve[i] = (gint) (exp (- (i/22.0 * i/22.0) / sigma2) * RAND_MAX); *************** static void make_curve (gdouble sigma) *** 217,223 **** } ! /* Prepare the shape data: makes a buffer with the shape calculated with * the goood size. */ static int prepare_shape() --- 220,226 ---- } ! /* Prepare the shape data: makes a buffer with the shape calculated with * the goood size. */ static int prepare_shape() *************** static int prepare_shape() *** 226,250 **** shape_data = malloc(params.size*params.size); if (shape_data == NULL) ! return; switch (params.shape) { case SQUARE_SHAPE: for (i=0;ientry ); sprintf (buffer, "%d", (int) new_val ); ! /* avoid infinite loop (scale, entry, scale, entry ...) */ gtk_signal_handler_block_by_data ( GTK_OBJECT(entry), data ); gtk_entry_set_text ( entry, buffer); --- 575,581 ---- userdata = gtk_object_get_user_data (GTK_OBJECT (adjustment)); entry = GTK_ENTRY( userdata->entry ); sprintf (buffer, "%d", (int) new_val ); ! /* avoid infinite loop (scale, entry, scale, entry ...) */ gtk_signal_handler_block_by_data ( GTK_OBJECT(entry), data ); gtk_entry_set_text ( entry, buffer); *************** UI_paired_int_entry_update (GtkWidget *w *** 603,609 **** gtk_signal_handler_block_by_data ( GTK_OBJECT(adjustment), data ); gtk_signal_emit_by_name ( GTK_OBJECT(adjustment), "value_changed"); gtk_signal_handler_unblock_by_data ( GTK_OBJECT(adjustment), data ); ! } --- 617,623 ---- gtk_signal_handler_block_by_data ( GTK_OBJECT(adjustment), data ); gtk_signal_emit_by_name ( GTK_OBJECT(adjustment), "value_changed"); gtk_signal_handler_unblock_by_data ( GTK_OBJECT(adjustment), data ); ! } *************** UI_float_entryscale_new ( GtkTable *tabl *** 623,629 **** EntryScaleData *userdata; guchar buffer[256]; ! label = gtk_label_new (caption); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); --- 637,643 ---- EntryScaleData *userdata; guchar buffer[256]; ! label = gtk_label_new (caption); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); *************** UI_float_entryscale_new ( GtkTable *tabl *** 669,675 **** gtk_widget_show (entry); gtk_widget_show (scale); gtk_widget_show (hbox); ! } /* scale callback (float) */ --- 683,689 ---- gtk_widget_show (entry); gtk_widget_show (scale); gtk_widget_show (hbox); ! } /* scale callback (float) */ *************** UI_paired_float_scale_update (GtkAdjustm *** 692,698 **** userdata = gtk_object_get_user_data (GTK_OBJECT (adjustment)); entry = GTK_ENTRY( userdata->entry ); sprintf (buffer, "%1.2f", (gfloat) new_val ); ! /* avoid infinite loop (scale, entry, scale, entry ...) */ gtk_signal_handler_block_by_data ( GTK_OBJECT(entry), data ); gtk_entry_set_text ( entry, buffer); --- 706,712 ---- userdata = gtk_object_get_user_data (GTK_OBJECT (adjustment)); entry = GTK_ENTRY( userdata->entry ); sprintf (buffer, "%1.2f", (gfloat) new_val ); ! /* avoid infinite loop (scale, entry, scale, entry ...) */ gtk_signal_handler_block_by_data ( GTK_OBJECT(entry), data ); gtk_entry_set_text ( entry, buffer); *************** UI_paired_float_entry_update (GtkWidget *** 734,740 **** gtk_signal_handler_block_by_data ( GTK_OBJECT(adjustment), data ); gtk_signal_emit_by_name ( GTK_OBJECT(adjustment), "value_changed"); gtk_signal_handler_unblock_by_data ( GTK_OBJECT(adjustment), data ); ! } --- 748,754 ---- gtk_signal_handler_block_by_data ( GTK_OBJECT(adjustment), data ); gtk_signal_emit_by_name ( GTK_OBJECT(adjustment), "value_changed"); gtk_signal_handler_unblock_by_data ( GTK_OBJECT(adjustment), data ); ! } *************** dialog () *** 832,839 **** gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN); gtk_container_border_width (GTK_CONTAINER (frame), 10); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), frame, TRUE, TRUE, 0); ! ! table = gtk_table_new (5, 2, FALSE); gtk_container_border_width (GTK_CONTAINER (table), 10); gtk_container_add (GTK_CONTAINER (frame), table); gtk_table_set_row_spacings (GTK_TABLE (table), 3); --- 846,853 ---- gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN); gtk_container_border_width (GTK_CONTAINER (frame), 10); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), frame, TRUE, TRUE, 0); ! ! table = gtk_table_new (6, 2, FALSE); gtk_container_border_width (GTK_CONTAINER (table), 10); gtk_container_add (GTK_CONTAINER (frame), table); gtk_table_set_row_spacings (GTK_TABLE (table), 3); *************** dialog () *** 845,858 **** UI_float_entryscale_new( GTK_TABLE (table), 0, 2, "Density:", ¶ms.density, -5.0, 5.0, TRUE ); ! ! toggle = gtk_check_button_new_with_label ("Invert"); gtk_table_attach (GTK_TABLE (table), toggle, 0, 1, 3, 4, GTK_FILL, GTK_FILL, 0, 0); gtk_signal_connect (GTK_OBJECT (toggle), "toggled", (GtkSignalFunc) UI_toggle_update, ! ¶ms.inv); ! gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (toggle), params.inv); gtk_widget_show(toggle); toggle = gtk_radio_button_new_with_label (group,"square shaped holes"); --- 859,872 ---- UI_float_entryscale_new( GTK_TABLE (table), 0, 2, "Density:", ¶ms.density, -5.0, 5.0, TRUE ); ! ! toggle = gtk_check_button_new_with_label ("Keep opaque"); gtk_table_attach (GTK_TABLE (table), toggle, 0, 1, 3, 4, GTK_FILL, GTK_FILL, 0, 0); gtk_signal_connect (GTK_OBJECT (toggle), "toggled", (GtkSignalFunc) UI_toggle_update, ! ¶ms.flag); ! gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (toggle), params.flag); gtk_widget_show(toggle); toggle = gtk_radio_button_new_with_label (group,"square shaped holes"); *************** dialog () *** 877,884 **** gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (toggle), (params.shape == CIRCLE_SHAPE)); gtk_widget_show (toggle); ! ! gtk_widget_show (frame); gtk_widget_show (table); --- 891,907 ---- gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (toggle), (params.shape == CIRCLE_SHAPE)); gtk_widget_show (toggle); ! toggle = gtk_radio_button_new_with_label (group,"diamond shaped holes"); ! group = gtk_radio_button_group (GTK_RADIO_BUTTON (toggle)); ! gtk_table_attach (GTK_TABLE (table), toggle, 1, 2, 5, 6, ! GTK_FILL, GTK_FILL, 0, 0); ! gtk_signal_connect_object (GTK_OBJECT (toggle), "toggled", ! (GtkSignalFunc) shape_radio_callback, ! (gpointer)toggle); ! gtk_object_set_data(GTK_OBJECT(toggle),"Radio_ID",(gpointer)DIAMOND_SHAPE); ! gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (toggle), (params.shape == DIAMOND_SHAPE)); ! gtk_widget_show (toggle); ! gtk_widget_show (frame); gtk_widget_show (table);