Commit 49e8789d authored by Maurits Rijk's avatar Maurits Rijk
Browse files

More code clean-up in several plug-ins, mainly simplifying preview stuff.

parent 47f2a7f8
2003-02-01 Maurits Rijk <lpeek.mrijk@consunet.nl>
* libgimp/gimpmiscui.[ch]: factored out more preview stuff from several
plug-ins.
* plug-ins/common/waves.c
* plug-ins/common/sharpen.c
* plug-ins/common/AlienMap.c
* plug-ins/common/AlienMap2.c
* plug-ins/common/noisify.c: more code clean-up
2003-02-01 Sven Neumann <sven@gimp.org>
 
* app/config/gimpconfig.[ch]
......@@ -180,6 +191,11 @@
 
* configure.in: Added Vietnamese (vi) to ALL_LINGUAS
 
2003-01-30 Maurits Rijk <lpeek.mrijk@consunet.nl>
* plug-ins/common/ps.c (save_dialog): corrected small error with
mnemonic.
2003-01-30 Maurits Rijk <lpeek.mrijk@consunet.nl>
 
* plug-ins/common/c_astretch.c
......
......@@ -166,6 +166,37 @@ gimp_fixme_preview_do_row (GimpFixMePreview *preview,
}
}
void
gimp_fixme_preview_update (GimpFixMePreview *preview,
GimpFixeMePreviewFunc func,
gpointer data)
{
gint x, y;
guchar *buffer;
gint bpp;
bpp = preview->bpp;
buffer = (guchar*) g_malloc (preview->rowstride);
for (y = 0; y < preview->height; y++)
{
guchar *src = preview->cache + y * preview->rowstride;
guchar *dest = buffer;
for (x = 0; x < preview->width; x++)
{
func (src, dest, bpp, data);
src += bpp;
dest += bpp;
}
gimp_fixme_preview_do_row(preview, y, preview->width, buffer);
}
gtk_widget_queue_draw(preview->widget);
g_free (buffer);
}
void
gimp_fixme_preview_fill_with_thumb (GimpFixMePreview *preview,
gint32 drawable_ID)
......@@ -281,12 +312,92 @@ gimp_fixme_preview_fill (GimpFixMePreview *preview,
g_free (src);
}
void
gimp_fixme_preview_fill_scaled (GimpFixMePreview *preview,
GimpDrawable *drawable)
{
gint bpp;
gint x1, y1, x2, y2;
gint sel_width, sel_height;
gint width, height;
gdouble px, py;
gdouble dx, dy;
gint x, y;
guchar *dest;
GimpPixelFetcher *pft;
gimp_drawable_mask_bounds(drawable->drawable_id, &x1, &y1, &x2, &y2);
sel_width = x2 - x1;
sel_height = y2 - y1;
/* Calculate preview size */
if (sel_width > sel_height)
{
width = MIN(sel_width, PREVIEW_SIZE);
height = sel_height * width / sel_width;
}
else
{
height = MIN(sel_height, PREVIEW_SIZE);
width = sel_width * height / sel_height;
}
if (width < 2) width = 2;
if (height < 2) height = 2;
bpp = gimp_drawable_bpp (drawable->drawable_id);
if (gimp_drawable_is_indexed (drawable->drawable_id))
{
gint32 image_ID = gimp_drawable_image (drawable->drawable_id);
preview->cmap = gimp_image_get_cmap (image_ID, &preview->ncolors);
}
else
{
preview->cmap = NULL;
}
gtk_preview_size (GTK_PREVIEW (preview->widget), width, height);
preview->even = g_malloc (width * 3);
preview->odd = g_malloc (width * 3);
preview->cache = g_malloc(width * bpp * height);
preview->rowstride = width * bpp;
preview->bpp = bpp;
dx = (gdouble) (x2 - x1 - 1) / (width - 1);
dy = (gdouble) (y2 - y1 - 1) / (height - 1);
py = y1;
pft = gimp_pixel_fetcher_new (drawable);
for (y = 0; y < height; y++)
{
dest = preview->cache + y * preview->rowstride;
px = x1;
for (x = 0; x < width; x++)
{
gimp_pixel_fetcher_get_pixel (pft, (gint) px, (gint) py, dest);
dest += bpp;
px += dx;
}
gimp_fixme_preview_do_row (preview, y, width, dest);
py += dy;
}
gimp_pixel_fetcher_destroy (pft);
preview->buffer = GTK_PREVIEW (preview->widget)->buffer;
preview->width = GTK_PREVIEW (preview->widget)->buffer_width;
preview->height = GTK_PREVIEW (preview->widget)->buffer_height;
}
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);
......@@ -322,19 +433,7 @@ gimp_plug_in_parse_path (gchar *path_name, const gchar *dir_name)
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);
/* We just ignore the fail_list */
gimp_path_free (fail_list);
}
......
......@@ -56,13 +56,23 @@ typedef struct {
gdouble scale_y;
} GimpFixMePreview;
typedef void (*GimpFixeMePreviewFunc)(guchar *src, guchar *dest,
gint bpp, gpointer data);
GimpFixMePreview *gimp_fixme_preview_new (GimpDrawable *drawable,
gboolean has_frame);
void gimp_fixme_preview_free (GimpFixMePreview *preview);
void gimp_fixme_preview_update (GimpFixMePreview *preview,
GimpFixeMePreviewFunc func,
gpointer data);
void gimp_fixme_preview_fill_with_thumb (GimpFixMePreview *preview,
gint32 drawable_ID);
void gimp_fixme_preview_fill (GimpFixMePreview *preview,
GimpDrawable *drawable);
void gimp_fixme_preview_fill_scaled (GimpFixMePreview *preview,
GimpDrawable *drawable);
void gimp_fixme_preview_do_row (GimpFixMePreview *preview,
gint row,
gint width,
......
......@@ -835,7 +835,6 @@ static unsigned char header_data[] = { 71,99,218,218,99,11,71,218,71,71,
/***** Magic numbers *****/
#define PREVIEW_SIZE 128
#define SCALE_WIDTH 200
#define SINUS 0
......@@ -855,9 +854,6 @@ typedef struct
typedef struct
{
GtkWidget *preview;
guchar *image;
guchar *wimage;
gint run;
} alienmap_interface_t;
......@@ -875,8 +871,6 @@ static void alienmap (GimpDrawable *drawable);
static void transform (guchar *, guchar *, guchar *,
double, double, double);
static void build_preview_source_image( void);
static gint alienmap_dialog (void);
static void dialog_update_preview (void);
static void dialog_scale_update (GtkAdjustment *adjustment,
......@@ -889,6 +883,7 @@ static void alienmap_logo_dialog (void);
/***** Variables *****/
static GimpRunMode run_mode;
static GimpFixMePreview *preview;
GimpPlugInInfo PLUG_IN_INFO =
{
......@@ -900,9 +895,6 @@ GimpPlugInInfo PLUG_IN_INFO =
static alienmap_interface_t wint =
{
NULL, /* preview */
NULL, /* image */
NULL, /* wimage */
FALSE /* run */
};
......@@ -917,9 +909,6 @@ static alienmap_vals_t wvals =
};
static GimpDrawable *drawable;
static gint sel_x1, sel_y1, sel_x2, sel_y2;
static gint preview_width, preview_height;
static gdouble scale_x, scale_y;
/***** Functions *****/
......@@ -1035,9 +1024,6 @@ run (char *name,
GimpParam **return_vals)
{
static GimpParam values[1];
double xhsiz, yhsiz;
gint sel_width, sel_height;
int pwidth, pheight;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
INIT_I18N_UI ();
......@@ -1053,46 +1039,6 @@ run (char *name,
/* Get the specified drawable */
drawable = gimp_drawable_get (param[2].data.d_drawable);
gimp_drawable_mask_bounds(drawable->drawable_id,
&sel_x1, &sel_y1, &sel_x2, &sel_y2);
sel_width = sel_x2 - sel_x1;
sel_height = sel_y2 - sel_y1;
xhsiz = (double) (sel_width - 1) / 2.0;
yhsiz = (double) (sel_height - 1) / 2.0;
if (xhsiz < yhsiz)
{
scale_x = yhsiz / xhsiz;
scale_y = 1.0;
}
else if (xhsiz > yhsiz)
{
scale_x = 1.0;
scale_y = xhsiz / yhsiz;
}
else
{
scale_x = 1.0;
scale_y = 1.0;
}
/* Calculate preview size */
if (sel_width > sel_height)
{
pwidth = MIN (sel_width, PREVIEW_SIZE);
pheight = sel_height * pwidth / sel_width;
}
else
{
pheight = MIN (sel_height, PREVIEW_SIZE);
pwidth = sel_width * pheight / sel_height;
}
preview_width = MAX (pwidth, 2); /* Min size is 2 */
preview_height = MAX (pheight, 2);
/* See how we will run */
switch (run_mode)
{
......@@ -1189,53 +1135,6 @@ alienmap (GimpDrawable *drawable)
gimp_rgn_iterate2 (drawable, run_mode, alienmap_func, NULL);
}
static void
build_preview_source_image (void)
{
double left, right, bottom, top;
double px, py;
double dx, dy;
int x, y;
guchar *p;
guchar pixel[4];
GimpPixelFetcher *pft;
wint.image = g_new (guchar, preview_width * preview_height * 3);
wint.wimage = g_new (guchar, preview_width * preview_height * 3);
left = sel_x1;
right = sel_x2 - 1;
bottom = sel_y2 - 1;
top = sel_y1;
dx = (right - left) / (preview_width - 1);
dy = (bottom - top) / (preview_height - 1);
py = top;
p = wint.image;
pft = gimp_pixel_fetcher_new (drawable);
for (y = 0; y < preview_height; y++)
{
px = left;
for (x = 0; x < preview_width; x++)
{
gimp_pixel_fetcher_get_pixel (pft, (gint) px, (gint) py, pixel);
*p++ = pixel[0];
*p++ = pixel[1];
*p++ = pixel[2];
px += dx;
}
py += dy;
}
gimp_pixel_fetcher_destroy (pft);
}
static gint
alienmap_dialog (void)
{
......@@ -1250,8 +1149,6 @@ alienmap_dialog (void)
gimp_ui_init ("alienmap", TRUE);
build_preview_source_image ();
dialog =
gimp_dialog_new (_("AlienMap"), "alienmap",
gimp_standard_help_func, "filters/alienmap.html",
......@@ -1287,10 +1184,10 @@ alienmap_dialog (void)
gtk_table_attach (GTK_TABLE (top_table), frame, 0, 1, 0, 1, 0, 0, 0, 0);
gtk_widget_show (frame);
wint.preview = gtk_preview_new (GTK_PREVIEW_COLOR);
gtk_preview_size (GTK_PREVIEW (wint.preview), preview_width, preview_height);
gtk_container_add (GTK_CONTAINER (frame), wint.preview);
gtk_widget_show (wint.preview);
preview = gimp_fixme_preview_new (NULL, FALSE);
gimp_fixme_preview_fill_scaled (preview, drawable);
gtk_container_add (GTK_CONTAINER (frame), preview->widget);
gtk_widget_show (preview->widget);
/* Controls */
table = gtk_table_new (3, 3, FALSE);
......@@ -1402,71 +1299,13 @@ alienmap_dialog (void)
gtk_main ();
gdk_flush ();
g_free (wint.image);
g_free (wint.wimage);
return wint.run;
}
static void
dialog_update_preview (void)
{
double left, right, bottom, top;
double dx, dy;
int px, py;
int x, y;
double redstretch, greenstretch, bluestretch;
guchar r,g,b;
double scale_x, scale_y;
guchar *p_ul, *i, *p;
left = sel_x1;
right = sel_x2 - 1;
bottom = sel_y2 - 1;
top = sel_y1;
dx = (right - left) / (preview_width - 1);
dy = (bottom - top) / (preview_height - 1);
redstretch = wvals.redstretch;
greenstretch = wvals.greenstretch;
bluestretch = wvals.bluestretch;
scale_x = (double) (preview_width - 1) / (right - left);
scale_y = (double) (preview_height - 1) / (bottom - top);
py = 0;
p_ul = wint.wimage;
for (y = 0; y < preview_height; y++)
{
px = 0;
for (x = 0; x < preview_width; x++)
{
i = wint.image + 3 * (preview_width * py + px);
r = *i++;
g = *i++;
b = *i;
transform(&r,&g,&b,redstretch, greenstretch, bluestretch);
p_ul[0] = r;
p_ul[1] = g;
p_ul[2] = b;
p_ul += 3;
px += 1; /* dx; */
}
py +=1; /* dy; */
}
p = wint.wimage;
for (y = 0; y < preview_height; y++)
{
gtk_preview_draw_row(GTK_PREVIEW(wint.preview), p, 0, y, preview_width);
p += preview_width * 3;
}
gtk_widget_queue_draw(wint.preview);
gdk_flush();
gimp_fixme_preview_update (preview, alienmap_func, NULL);
}
static void
......
......@@ -829,7 +829,6 @@ static unsigned char header_data[] = { 71,99,218,218,99,11,71,218,71,71,
19,19,19,19,19,19,19,19,19,8};
/***** Magic numbers *****/
#define PREVIEW_SIZE 128
#define SCALE_WIDTH 200
#define ENTRY_WIDTH 6
......@@ -855,14 +854,9 @@ typedef struct
typedef struct
{
GtkWidget *preview;
guchar *image;
guchar *wimage;
gint run;
} alienmap2_interface_t;
/* Declare local functions. */
static void query (void);
......@@ -875,9 +869,6 @@ static void run (char *name,
static void alienmap2 (GimpDrawable *drawable);
static void transform (guchar*, guchar*, guchar*);
static void build_preview_source_image (void);
static gint alienmap2_dialog (void);
static void dialog_update_preview (void);
static void dialog_scale_update (GtkAdjustment *adjustment,
......@@ -892,6 +883,7 @@ static void alienmap2_logo_dialog (void);
/***** Variables *****/
static GimpRunMode run_mode;
static GimpFixMePreview *preview;
GimpPlugInInfo PLUG_IN_INFO =
{
......@@ -903,9 +895,6 @@ GimpPlugInInfo PLUG_IN_INFO =
static alienmap2_interface_t wint =
{
NULL, /* preview */
NULL, /* image */
NULL, /* wimage */
FALSE /* run */
};
......@@ -924,10 +913,6 @@ static alienmap2_vals_t wvals =
};
static GimpDrawable *drawable;
static gint sel_x1, sel_y1, sel_x2, sel_y2;
static gint sel_width, sel_height;
static gint preview_width, preview_height;
static gdouble scale_x, scale_y;
/***** Functions *****/
......@@ -1020,8 +1005,6 @@ run (char *name,
GimpParam **return_vals)
{
static GimpParam values[1];
double xhsiz, yhsiz;
int pwidth, pheight;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
INIT_I18N_UI ();
......@@ -1037,46 +1020,6 @@ run (char *name,
/* Get the specified drawable */
drawable = gimp_drawable_get (param[2].data.d_drawable);
gimp_drawable_mask_bounds(drawable->drawable_id,
&sel_x1, &sel_y1, &sel_x2, &sel_y2);
sel_width = sel_x2 - sel_x1;
sel_height = sel_y2 - sel_y1;
xhsiz = (double) (sel_width - 1) / 2.0;
yhsiz = (double) (sel_height - 1) / 2.0;
if (xhsiz < yhsiz)
{
scale_x = yhsiz / xhsiz;
scale_y = 1.0;
}
else if (xhsiz > yhsiz)
{
scale_x = 1.0;
scale_y = xhsiz / yhsiz;
}
else
{
scale_x = 1.0;
scale_y = 1.0;
}
/* Calculate preview size */
if (sel_width > sel_height)
{
pwidth = MIN(sel_width, PREVIEW_SIZE);
pheight = sel_height * pwidth / sel_width;
}
else
{
pheight = MIN(sel_height, PREVIEW_SIZE);
pwidth = sel_width * pheight / sel_height;
}
preview_width = MAX(pwidth, 2); /* Min size is 2 */
preview_height = MAX(pheight, 2);
/* See how we will run */
switch (run_mode)
{
......@@ -1177,52 +1120,6 @@ alienmap2 (GimpDrawable *drawable)
gimp_rgn_iterate2 (drawable, run_mode, alienmap2_func, NULL);
}
static void
build_preview_source_image (void)
{
double left, right, bottom, top;
double px, py;
double dx, dy;
int x, y;
guchar *p;
guchar pixel[4];
GimpPixelFetcher *pft;
wint.image = g_new (guchar, preview_width * preview_height * 3);
wint.wimage = g_new (guchar, preview_width * preview_height * 3);
left = sel_x1;
right = sel_x2 - 1;
bottom = sel_y2 - 1;
top = sel_y1;
dx = (right - left) / (preview_width - 1);
dy = (bottom - top) / (preview_height - 1);
py = top;
p = wint.image;
pft = gimp_pixel_fetcher_new (drawable);
for (y = 0; y < preview_height; y++)
{
px = left;
for (x = 0; x < preview_width; x++)
{
gimp_pixel_fetcher_get_pixel (pft, (gint) px, (gint) py, pixel);
*p++ = pixel[0];
*p++ = pixel[1];
*p++ = pixel[2];
px += dx;
}
py += dy;
}
gimp_pixel_fetcher_destroy (pft);
}
static