Commit 9984145f authored by Maurits Rijk's avatar Maurits Rijk
Browse files

New routine in gimpmiscui and some code clean-up

parent 416049f4
2003-01-27 Maurits Rijk <lpeek.mrijk@consunet.nl>
* plug-ins/common/sample_colorize.c: code clean-up, added a few more
mnemonics to dialogs.
* plug-ins/gfig/gfig.c
* plug-ins/gflare/gflare.c
* plug-ins/FractalExplorer/FractalExplorer.c: use new
gimp_plug_in_parse_path routine.
* libgimp/gimpmiscui.[ch] (gimp_plug_in_parse_path): new routine used
in several plug-ins.
2003-01-27 Sven Neumann <sven@gimp.org>
 
* app/gui/preferences-dialog.c: commented out debugging output.
......
......@@ -280,3 +280,64 @@ gimp_fixme_preview_fill (GimpFixMePreview *preview,
g_free (src);
}
GList*
gimp_plug_in_parse_path (gchar *path_name, const gchar *dir_name)
{
GList *path_list = NULL;
GList *fail_list = NULL;
GList *list;
gchar *path;
path = gimp_gimprc_query (path_name);
if (!path)
{
gchar *gimprc = gimp_personal_rc_file ("gimprc");
gchar *full_path;
gchar *esc_path;
full_path = g_strconcat
("${gimp_dir}", G_DIR_SEPARATOR_S, dir_name,
G_SEARCHPATH_SEPARATOR_S,
"${gimp_data_dir}", G_DIR_SEPARATOR_S, dir_name,
NULL);
esc_path = g_strescape (full_path, NULL);
g_message (_("No %s in gimprc:\n"
"You need to add an entry like\n"
"(%s \"%s\")\n"
"to your %s file."), path_name, path_name, esc_path,
gimprc);
g_free (gimprc);
g_free (full_path);
g_free (esc_path);
return NULL;
}
path_list = gimp_path_parse (path, 16, TRUE, &fail_list);
g_free (path);
if (fail_list)
{
GString *err = g_string_new (path_name);
g_string_append (err, _(" misconfigured - "
"the following folders were not found:"));
for (list = fail_list; list; list = g_list_next (list))
{
g_string_append_c (err, '\n');
g_string_append (err, (gchar *) list->data);
}
g_message (err->str);
g_string_free (err, TRUE);
gimp_path_free (fail_list);
}
return path_list;
}
......@@ -68,6 +68,7 @@ void gimp_fixme_preview_do_row (GimpFixMePreview *preview,
gint width,
guchar *src);
GList *gimp_plug_in_parse_path (gchar *path_name, const gchar *dir_name);
G_END_DECLS
......
......@@ -711,11 +711,9 @@ delete_dialog_callback (GtkWidget *widget,
}
delete_dialog = NULL;
return;
}
static gint
static gboolean
delete_fractal_callback (GtkWidget *widget,
gpointer data)
{
......@@ -765,10 +763,7 @@ fractalexplorer_list_ok_callback (GtkWidget *widget,
list = options->list_entry;
/* Set the new layer name */
if (options->obj->draw_name)
{
g_free(options->obj->draw_name);
}
g_free(options->obj->draw_name);
options->obj->draw_name =
g_strdup (gtk_entry_get_text (GTK_ENTRY (options->name_entry)));
......@@ -785,7 +780,6 @@ fractalexplorer_list_ok_callback (GtkWidget *widget,
gtk_widget_destroy (options->query_box);
g_free (options);
}
static void
......@@ -795,7 +789,7 @@ fractalexplorer_list_cancel_callback (GtkWidget *widget,
fractalexplorerListOptions *options;
options = (fractalexplorerListOptions *) data;
if(options->created)
if (options->created)
{
/* We are creating an entry so if cancelled
* must del the list item as well
......@@ -909,9 +903,8 @@ new_button_press (GtkWidget *widget,
}
/*
* Load all fractalexplorer, which are founded in fractalexplorer-path-list, into fractalexplorer_list.
* fractalexplorer-path-list must be initialized first. (plug_in_parse_fractalexplorer_path ())
* based on code from Gflare.
* Load all fractalexplorer, which are founded in fractalexplorer-path-list,
* into fractalexplorer_list.
*/
static gint
......@@ -932,7 +925,6 @@ fractalexplorer_list_pos (fractalexplorerOBJ *fractalexplorer)
n++;
}
return n;
}
......@@ -1043,17 +1035,13 @@ static void
list_button_update (fractalexplorerOBJ *obj)
{
g_return_if_fail (obj != NULL);
pic_obj = (fractalexplorerOBJ *)obj;
pic_obj = obj;
}
fractalexplorerOBJ *
fractalexplorer_new (void)
{
fractalexplorerOBJ * new;
new = g_new0 (fractalexplorerOBJ, 1);
return new;
return g_new0 (fractalexplorerOBJ, 1);
}
void
......@@ -1127,62 +1115,11 @@ list_button_press (GtkWidget *widget,
return FALSE;
}
/*
* Query gimprc for fractalexplorer-path, and parse it.
* This code is based on script_fu_find_scripts ()
* and the Gflare plugin.
*/
void
plug_in_parse_fractalexplorer_path (void)
{
GList *fail_list = NULL;
GList *list;
gchar *fractalexplorer_path;
gimp_path_free (fractalexplorer_path_list);
fractalexplorer_path_list = NULL;
fractalexplorer_path = gimp_gimprc_query ("fractalexplorer-path");
if (!fractalexplorer_path)
{
gchar *gimprc = gimp_personal_rc_file ("gimprc");
gchar *path = g_strescape
("${gimp_dir}" G_DIR_SEPARATOR_S "fractalexplorer"
G_SEARCHPATH_SEPARATOR_S
"${gimp_data_dir}" G_DIR_SEPARATOR_S "fractalexplorer",
NULL);
g_message (_("No fractalexplorer-path in gimprc:\n"
"You need to add an entry like\n"
"(fractalexplorer-path \"%s\")\n"
"to your %s file."), path, gimprc);
g_free (gimprc);
g_free (path);
return;
}
fractalexplorer_path_list = gimp_path_parse (fractalexplorer_path,
16, TRUE, &fail_list);
g_free (fractalexplorer_path);
if (fail_list)
{
GString *err =
g_string_new (_("fractalexplorer-path misconfigured - "
"the following folders were not found:"));
for (list = fail_list; list; list = g_list_next (list))
{
g_string_append_c (err, '\n');
g_string_append (err, (gchar *) list->data);
}
g_message (err->str);
g_string_free (err, TRUE);
gimp_path_free (fail_list);
}
fractalexplorer_path_list =
gimp_plug_in_parse_path ("fractalexplorer-path", "fractalexplorer");
}
static void
......@@ -1201,7 +1138,7 @@ fractalexplorer_free_everything (fractalexplorerOBJ *fractalexplorer)
{
g_assert (fractalexplorer != NULL);
if(fractalexplorer->filename)
if (fractalexplorer->filename)
{
remove (fractalexplorer->filename);
}
......@@ -1211,15 +1148,7 @@ fractalexplorer_free_everything (fractalexplorerOBJ *fractalexplorer)
static void
fractalexplorer_list_free_all (void)
{
GList * list;
fractalexplorerOBJ * fractalexplorer;
for (list = fractalexplorer_list; list; list = g_list_next (list))
{
fractalexplorer = (fractalexplorerOBJ *) list->data;
fractalexplorer_free (fractalexplorer);
}
g_list_foreach (fractalexplorer_list, (GFunc) fractalexplorer_free, NULL);
g_list_free (fractalexplorer_list);
fractalexplorer_list = NULL;
}
......@@ -1332,7 +1261,7 @@ fractalexplorer_list_load_all (GList *plist)
}
}
if(!fractalexplorer_list)
if (!fractalexplorer_list)
{
/* lets have at least one! */
fractalexplorer = fractalexplorer_new ();
......@@ -1340,7 +1269,6 @@ fractalexplorer_list_load_all (GList *plist)
fractalexplorer_list_insert (fractalexplorer);
}
pic_obj = current_obj = fractalexplorer_list->data; /* set to first entry */
}
GtkWidget *
......@@ -1457,7 +1385,6 @@ fractalexplorer_rescan_list (void)
return;
}
/* the dialog */
dlg = gimp_dialog_new (_("Rescan for Fractals"), "fractalexplorer",
gimp_standard_help_func, "filters/fractalexplorer.html",
GTK_WIN_POS_MOUSE,
......
......@@ -191,6 +191,7 @@ typedef struct {
* Some globals
*/
static GimpRunMode run_mode;
static t_samp_interface g_di; /* global dialog interface varables */
static t_values g_values = { -1, -1, 1, 1, 0, 1, 0, 255, 1.0, 0, 255, 5.5 };
static t_samp_table_elem g_lum_tab[256];
......@@ -322,7 +323,6 @@ run (gchar *name,
{
static GimpParam values[1];
GimpDrawable *dst_drawable;
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
const gchar *l_env;
......@@ -1117,8 +1117,6 @@ p_levels_update (gint update)
}
} /* end p_levels_update */
static gint
p_level_in_events (GtkWidget *widget,
GdkEvent *event,
......@@ -2019,8 +2017,6 @@ p_get_pixel( t_GDRW *gdrw, gint32 x, gint32 y, guchar *pixel )
return;
}
/* gimp_pixel_rgn_get_pixel(&gdrw->pr, pixel, x, y); */
col = x / gdrw->tile_width;
row = y / gdrw->tile_height;
offx = x % gdrw->tile_width;
......@@ -2528,7 +2524,7 @@ p_get_gradient (gint mode)
g_free (f_samples);
} /* end p_get_gradient */
gint32
static gint32
p_is_layer_alive(gint32 drawable_id)
{
/* return -1 if layer has become invalid */
......@@ -2539,9 +2535,9 @@ p_is_layer_alive(gint32 drawable_id)
gint l_idi, l_idl;
gint l_found;
if(drawable_id < 0)
if (drawable_id < 0)
{
return (-1);
return -1;
}
/* gimp_layer_get_image_id: crash in gimp 1.1.2 if called with invalid drawable_id
......@@ -2555,69 +2551,59 @@ p_is_layer_alive(gint32 drawable_id)
* }
*/
images = gimp_image_list(&nimages);
images = gimp_image_list (&nimages);
l_idi = nimages -1;
l_found = FALSE;
while((l_idi >= 0) && images)
while ((l_idi >= 0) && images)
{
layers = gimp_image_get_layers (images[l_idi], &nlayers);
l_idl = nlayers -1;
while((l_idl >= 0) && layers)
l_idl = nlayers - 1;
while ((l_idl >= 0) && layers)
{
if(drawable_id == layers[l_idl])
if (drawable_id == layers[l_idl])
{
l_found = TRUE;
break;
}
l_idl--;
}
g_free(layers);
g_free (layers);
l_idi--;
}
if(images) g_free(images);
if(!l_found)
g_free(images);
if (!l_found)
{
printf("sample colorize: unknown layer_id %d (Image closed?)\n", (int)drawable_id);
return (-1);
printf("sample colorize: unknown layer_id %d (Image closed?)\n",
(int)drawable_id);
return -1;
}
return(drawable_id);
return drawable_id;
} /* end p_is_layer_alive */
void
static void
p_end_gdrw(t_GDRW *gdrw)
{
t_GDRW *l_sel_gdrw;
t_GDRW *sel_gdrw;
if(g_Sdebug) printf("\np_end_gdrw: drawable %p ID: %d\n", gdrw->drawable, (int)gdrw->drawable->drawable_id);
if(gdrw->tile)
if (gdrw->tile)
{
if(g_Sdebug) printf("p_end_gdrw: tile unref\n");
gimp_tile_unref( gdrw->tile, gdrw->tile_dirty);
gimp_tile_unref (gdrw->tile, gdrw->tile_dirty);
gdrw->tile = NULL;
}
l_sel_gdrw = (t_GDRW *)(gdrw->sel_gdrw);
if(l_sel_gdrw)
sel_gdrw = (t_GDRW*)(gdrw->sel_gdrw);
if (sel_gdrw)
{
if(l_sel_gdrw->tile)
if(sel_gdrw->tile)
{
if(g_Sdebug) printf("p_end_gdrw: sel_tile unref\n");
gimp_tile_unref( l_sel_gdrw->tile, l_sel_gdrw->tile_dirty);
l_sel_gdrw->tile = NULL;
if(g_Sdebug) printf("p_end_gdrw:SEL_TILE_SWAPCOUNT: %d\n", (int)l_sel_gdrw->tile_swapcount);
gimp_tile_unref (sel_gdrw->tile, sel_gdrw->tile_dirty);
sel_gdrw->tile = NULL;
}
gdrw->sel_gdrw = NULL;
}
if(g_Sdebug) printf("p_end_gdrw:TILE_SWAPCOUNT: %d\n", (int)gdrw->tile_swapcount);
} /* end p_end_gdrw */
}
void
static void
p_init_gdrw(t_GDRW *gdrw, GimpDrawable *drawable, gint dirty, gint shadow)
{
gint32 l_image_id;
......@@ -2643,13 +2629,6 @@ p_init_gdrw(t_GDRW *gdrw, GimpDrawable *drawable, gint dirty, gint shadow)
gimp_drawable_mask_bounds (drawable->drawable_id, &gdrw->x1, &gdrw->y1, &gdrw->x2, &gdrw->y2);
/*
* gimp_pixel_rgn_init (&gdrw->pr, drawable,
* gdrw->x1, gdrw->y1, gdrw->x2 - gdrw->x1, gdrw->y2 - gdrw->y1,
* dirty, shadow);
*/
gdrw->bpp = drawable->bpp;
if (gimp_drawable_has_alpha(drawable->drawable_id))
{
......@@ -2660,8 +2639,7 @@ p_init_gdrw(t_GDRW *gdrw, GimpDrawable *drawable, gint dirty, gint shadow)
{
gdrw->index_alpha = 0; /* there is no alpha channel */
}
l_image_id = gimp_layer_get_image_id(drawable->drawable_id);
/* check and see if we have a selection mask */
......@@ -2719,12 +2697,11 @@ p_init_gdrw(t_GDRW *gdrw, GimpDrawable *drawable, gint dirty, gint shadow)
else
{
gdrw->sel_gdrw = NULL; /* selection is FALSE */
}
}
} /* end p_init_gdrw */
/* analyze the colors in the sample_drawable */
int
static int
p_sample_analyze(t_GDRW *sample_gdrw)
{
gint32 l_sample_pixels;
......@@ -2748,8 +2725,6 @@ p_sample_analyze(t_GDRW *sample_gdrw)
l_progress = 0.0;
if(g_show_progress) gimp_progress_init (_("Sample Analyze..."));
prot_fp = NULL;
if(g_Sdebug) prot_fp = fopen("sample_colors.dump", "w");
p_print_values(prot_fp);
......@@ -2837,7 +2812,7 @@ p_sample_analyze(t_GDRW *sample_gdrw)
if(prot_fp) fclose(prot_fp);
/* check if there was at least one visible pixel */
if(l_sample_pixels == 0)
if (l_sample_pixels == 0)
{
printf("Error: Source sample has no visible Pixel\n");
return -1;
......@@ -2845,7 +2820,7 @@ p_sample_analyze(t_GDRW *sample_gdrw)
return 0;
} /* end p_sample_analyze */
void
static void
p_rnd_remap(gint32 lum, guchar *mapped_color)
{
t_samp_color_elem *l_col_ptr;
......@@ -2853,7 +2828,7 @@ p_rnd_remap(gint32 lum, guchar *mapped_color)
gint l_ct;
gint l_idx;
if(g_lum_tab[lum].all_samples > 1)
if (g_lum_tab[lum].all_samples > 1)
{
l_rnd = g_random_int_range (0, g_lum_tab[lum].all_samples);
l_ct = 0;
......@@ -2879,8 +2854,7 @@ p_rnd_remap(gint32 lum, guchar *mapped_color)
memcpy(mapped_color, &g_sample_color_tab[lum + lum + lum], 3);
} /* end p_rnd_remap */
void
static void
p_remap_pixel(guchar *pixel, guchar *original, gint bpp2)
{
guchar mapped_color[4];
......@@ -2891,24 +2865,30 @@ p_remap_pixel(guchar *pixel, guchar *original, gint bpp2)
double l_dg, l_dr, l_db;
double l_dlum;
l_lum = g_out_trans_tab[g_lvl_trans_tab[LUMINOSITY_1(original)]]; /* get brightness from (uncolorized) original */
if(g_values.rnd_subcolors)
/* get brightness from (uncolorized) original */
l_lum = g_out_trans_tab[g_lvl_trans_tab[LUMINOSITY_1(original)]];
if (g_values.rnd_subcolors)
{
p_rnd_remap(l_lum, mapped_color);
p_rnd_remap (l_lum, mapped_color);
}
else
{
memcpy(mapped_color, &g_sample_color_tab[l_lum + l_lum + l_lum], 3);
memcpy (mapped_color, &g_sample_color_tab[l_lum + l_lum + l_lum], 3);
}
if(g_values.hold_inten)
if (g_values.hold_inten)
{
if(g_values.orig_inten) { l_orig_lum = LUMINOSITY_0(original); }
else { l_orig_lum = 100.0 * g_lvl_trans_tab[LUMINOSITY_1(original)]; }
if (g_values.orig_inten)
{
l_orig_lum = LUMINOSITY_0(original);
}
else
{
l_orig_lum = 100.0 * g_lvl_trans_tab[LUMINOSITY_1(original)];
}
l_mapped_lum = LUMINOSITY_0(mapped_color);
if(l_mapped_lum == 0)
if (l_mapped_lum == 0)
{
/* convert black to greylevel with desired brightness value */
mapped_color[0] = l_orig_lum / 100.0;
......@@ -3028,12 +3008,12 @@ p_remap_pixel(guchar *pixel, guchar *original, gint bpp2)
{
/* overflow in the blue channel (compensate with green and red) */
l_dlum = (l_blu - 255.0) * 11.0;
if(l_mg > 0)
if (l_mg > 0)
{
l_dg = l_dlum / (59.0 + (30.0 * l_mr / l_mg));
l_dr = l_dg * l_mr / l_mg;
}
else if(l_mr > 0)
else if (l_mr > 0)
{
l_dr = l_dlum / (30.0 + (59.0 * l_mg / l_mr));
l_dg = l_dr * l_mg / l_mr;
......@@ -3061,10 +3041,9 @@ p_remap_pixel(guchar *pixel, guchar *original, gint bpp2)
}
}
mapped_color[0] = CLAMP(l_red + 0.5, 0, 255);
mapped_color[1] = CLAMP(l_grn + 0.5, 0, 255);
mapped_color[2] = CLAMP(l_blu + 0.5, 0, 255);
mapped_color[0] = CLAMP0255(l_red + 0.5);
mapped_color[1] = CLAMP0255(l_grn + 0.5);
mapped_color[2] = CLAMP0255(l_blu + 0.5);
}
}
......@@ -3073,96 +3052,40 @@ p_remap_pixel(guchar *pixel, guchar *original, gint bpp2)
memcpy(pixel, &mapped_color[0], bpp2);
} /* end p_remap_pixel */
static void
colorize_func(guchar *src, guchar *dest, gint bpp, gpointer data)
{
gboolean has_alpha = (gboolean) data;
void
if (has_alpha)
{
bpp--;
dest[bpp] = src[bpp];
}
p_remap_pixel(dest, src, bpp);
}
static void
p_colorize_drawable(gint32 drawable_id)
{
GimpDrawable *drawable;
GimpPixelRgn pixel_rgn;
GimpPixelRgn shadow_rgn;
gpointer pr;
gint l_row, l_col;
gint l_bpp2;
gint l_has_alpha;
gint l_idx_alpha;
guchar *l_ptr;
guchar *l_row_ptr;
guchar *l_sh_ptr;
guchar *l_sh_row_ptr;
gint32 l_x1, l_x2, l_y1, l_y2;
float l_progress_step;
float l_progress;
gboolean has_alpha;
if(drawable_id < 1) return;