Commit 801c6d61 authored by Maurits Rijk's avatar Maurits Rijk
Browse files

Mostly minor code clean-up. Fixed one memory leak.

parent ff259644
2003-01-30 Maurits Rijk <lpeek.mrijk@consunet.nl>
* plug-ins/common/c_astretch.c
* plug-ins/common/edge.c
* plug-ins/common/cubism.c: code clean-up, plugged a few memory leaks
2003-01-30 Sven Neumann <sven@gimp.org>
 
* libgimp/gimpcompat.h: removed GIMP_ENABLE_COMPAT_CRUFT guards.
......@@ -89,6 +95,11 @@
* app/gui/module-browser.c: pack the button box non-expanding,
removed cruft from the ModuleBrowser struct.
 
2003-01-28 Maurits Rijk <lpeek.mrijk@consunet.nl>
* plug-ins/common/color_enhance.c:
* plug-ins/common/gradmap.c: minor code clean-up
2003-01-28 Tor Lillqvist <tml@iki.fi>
 
* libgimp/gimpui.def: Add missing entry points.
......
......@@ -58,6 +58,7 @@ GimpPlugInInfo PLUG_IN_INFO =
run, /* run_proc */
};
static GimpRunMode run_mode;
MAIN ()
......@@ -100,7 +101,6 @@ run (gchar *name,
{
static GimpParam values[1];
GimpDrawable *drawable;
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_ID;
......@@ -146,9 +146,8 @@ run (gchar *name,
gimp_drawable_detach (drawable);
}
static void
indexed_c_astretch (gint32 image_ID) /* a.d.m. */
indexed_c_astretch (gint32 image_ID)
{
guchar *cmap;
gint ncols,i;
......@@ -185,127 +184,73 @@ indexed_c_astretch (gint32 image_ID) /* a.d.m. */
gimp_image_set_cmap (image_ID, cmap, ncols);
}
typedef struct {
gint alpha;
guchar lut[256][3];
guchar min[3];
guchar max[3];
gboolean has_alpha;
} AutoStretchParam_t;
static void
c_astretch (GimpDrawable *drawable)
static void
find_min_max (guchar *src, gint bpp, gpointer data)
{
GimpPixelRgn src_rgn, dest_rgn;
guchar *src, *s;
guchar *dest, *d;
guchar min[3], max[3];
guchar range;
guchar lut[256][3];
gint progress, max_progress;
gint has_alpha, alpha;
gint x1, y1, x2, y2;
gint x, y, b;
gpointer pr;
/* Get selection area */
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
alpha = (has_alpha) ? drawable->bpp - 1 : drawable->bpp;
/* Initialize progress */
progress = 0;
max_progress = (x2 - x1) * (y2 - y1) * 2;
/* Get minimum and maximum values for each channel */
min[0] = min[1] = min[2] = 255;
max[0] = max[1] = max[2] = 0;
AutoStretchParam_t *param = (AutoStretchParam_t*) data;
gint b;
gimp_pixel_rgn_init (&src_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), FALSE, FALSE);
for (pr = gimp_pixel_rgns_register (1, &src_rgn);
pr != NULL;
pr = gimp_pixel_rgns_process (pr))
for (b = 0; b < param->alpha; b++)
{
src = src_rgn.data;
for (y = 0; y < src_rgn.h; y++)
if (!param->has_alpha || src[param->alpha])
{
s = src;
for (x = 0; x < src_rgn.w; x++)
{
for (b = 0; b < alpha; b++)
{
if (!has_alpha || (has_alpha && s[alpha]))
{
if (s[b] < min[b])
min[b] = s[b];
if (s[b] > max[b])
max[b] = s[b];
}
}
s += src_rgn.bpp;
}
src += src_rgn.rowstride;
if (src[b] < param->min[b])
param->min[b] = src[b];
if (src[b] > param->max[b])
param->max[b] = src[b];
}
/* Update progress */
progress += src_rgn.w * src_rgn.h;
gimp_progress_update ((double) progress / (double) max_progress);
}
}
/* Calculate LUTs with stretched contrast */
for (b = 0; b < alpha; b++)
{
range = max[b] - min[b];
if (range != 0)
for (x = min[b]; x <= max[b]; x++)
lut[x][b] = 255 * (x - min[b]) / range;
else
lut[min[b]][b] = min[b];
}
/* Now substitute pixel vales */
gimp_pixel_rgn_init (&src_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), FALSE, FALSE);
gimp_pixel_rgn_init (&dest_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), TRUE, TRUE);
for (pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn);
pr != NULL;
pr = gimp_pixel_rgns_process (pr))
{
src = src_rgn.data;
dest = dest_rgn.data;
for (y = 0; y < src_rgn.h; y++)
{
s = src;
d = dest;
for (x = 0; x < src_rgn.w; x++)
{
for (b = 0; b < alpha; b++)
d[b] = lut[s[b]][b];
static void
c_astretch_func (guchar *src, guchar *dest, gint bpp, gpointer data)
{
AutoStretchParam_t *param = (AutoStretchParam_t*) data;
gint b;
for (b = 0; b < param->alpha; b++)
dest[b] = param->lut[src[b]][b];
if (param->has_alpha)
dest[param->alpha] = src[param->alpha];
}
if (has_alpha)
d[alpha] = s[alpha];
static void
c_astretch (GimpDrawable *drawable)
{
AutoStretchParam_t param;
gint b;
s += src_rgn.bpp;
d += dest_rgn.bpp;
}
param.has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
param.alpha = (param.has_alpha) ? drawable->bpp - 1 : drawable->bpp;
src += src_rgn.rowstride;
dest += dest_rgn.rowstride;
/* Get minimum and maximum values for each channel */
param.min[0] = param.min[1] = param.min[2] = 255;
param.max[0] = param.max[1] = param.max[2] = 0;
}
gimp_rgn_iterate1 (drawable, run_mode, find_min_max, &param);
/* Update progress */
progress += src_rgn.w * src_rgn.h;
/* Calculate LUTs with stretched contrast */
for (b = 0; b < param.alpha; b++)
{
gint range = param.max[b] - param.min[b];
gint x;
gimp_progress_update ((double) progress / (double) max_progress);
if (range != 0)
for (x = param.min[b]; x <= param.max[b]; x++)
param.lut[x][b] = 255 * (x - param.min[b]) / range;
else
param.lut[param.min[b]][b] = param.min[b];
}
/* update the region */
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
gimp_rgn_iterate2 (drawable, run_mode, c_astretch_func, &param);
}
......@@ -39,6 +39,7 @@
#include "libgimp/stdplugins-intl.h"
static GimpRunMode run_mode;
/* Declare local functions.
*/
......@@ -104,7 +105,6 @@ run (gchar *name,
{
static GimpParam values[1];
GimpDrawable *drawable;
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_ID;
......@@ -149,222 +149,146 @@ run (gchar *name,
gimp_drawable_detach (drawable);
}
static gdouble
get_v (const guchar *src)
{
gdouble h, z, v;
gint c, m, y;
gint k;
guchar map[3];
c = 255 - src[0];
m = 255 - src[1];
y = 255 - src[2];
k = c;
if (m < k) k = m;
if (y < k) k = y;
map[0] = c - k;
map[1] = m - k;
map[2] = y - k;
gimp_rgb_to_hsv4(map, &h, &z, &v);
return v;
}
static void
indexed_Color_Enhance (gint32 image_ID) /* a.d.m. */
enhance_it (const guchar *src, guchar *dest, gdouble vlo, gdouble vhi)
{
gdouble h, z, v;
gint c, m, y;
gint k;
guchar map[3];
c = 255 - src[0];
m = 255 - src[1];
y = 255 - src[2];
k = c;
if (m < k) k = m;
if (y < k) k = y;
map[0] = c - k;
map[1] = m - k;
map[2] = y - k;
gimp_rgb_to_hsv4(map, &h, &z, &v);
if (vhi != vlo)
v = (v - vlo) / (vhi - vlo);
gimp_hsv_to_rgb4(map, h, z, v);
c = map[0];
m = map[1];
y = map[2];
c += k;
if (c > 255) c = 255;
m += k;
if (m > 255) m = 255;
y += k;
if (y > 255) y = 255;
dest[0] = 255 - c;
dest[1] = 255 - m;
dest[2] = 255 - y;
}
static void
indexed_Color_Enhance (gint32 image_ID)
{
guchar *cmap;
gint ncols,i;
gdouble vhi = 0.0, vlo = 1.0;
cmap = gimp_image_get_cmap (image_ID, &ncols);
if (cmap==NULL)
if (!cmap)
{
printf("Color_Enhance: cmap was NULL! Quitting...\n");
gimp_quit();
}
for (i=0;i<ncols;i++)
for (i = 0; i < ncols; i++)
{
gdouble h, s, v;
gint c, m, y;
gint k;
guchar map[3];
c = 255 - cmap[i*3+0];
m = 255 - cmap[i*3+1];
y = 255 - cmap[i*3+2];
k = c;
if (m < k) k = m;
if (y < k) k = y;
map[0] = c - k;
map[1] = m - k;
map[2] = y - k;
gimp_rgb_to_hsv4(map, &h, &s, &v);
gdouble v = get_v (&cmap[3 * i]);
if (v > vhi) vhi = v;
if (v < vlo) vlo = v;
}
for (i=0;i<ncols;i++)
for (i = 0; i < ncols; i++)
{
gdouble h, s, v;
gint c, m, y;
gint k;
guchar map[3];
c = 255 - cmap[i*3+0];
m = 255 - cmap[i*3+1];
y = 255 - cmap[i*3+2];
k = c;
if (m < k) k = m;
if (y < k) k = y;
map[0] = c - k;
map[1] = m - k;
map[2] = y - k;
gimp_rgb_to_hsv4(map, &h, &s, &v);
if (vhi!=vlo)
v = (v-vlo) / (vhi-vlo);
gimp_hsv_to_rgb4(map, h, s, v);
c = map[0];
m = map[1];
y = map[2];
c += k;
if (c > 255) c = 255;
m += k;
if (m > 255) m = 255;
y += k;
if (y > 255) y = 255;
cmap[i*3+0] = 255 - c;
cmap[i*3+1] = 255 - m;
cmap[i*3+2] = 255 - y;
enhance_it (&cmap[3 * i], &cmap[3 * i], vlo, vhi);
}
gimp_image_set_cmap (image_ID, cmap, ncols);
}
typedef struct {
gdouble vhi;
gdouble vlo;
gboolean has_alpha;
} ColorEnhanceParam_t;
static void
Color_Enhance (GimpDrawable *drawable)
static void
find_vhi_vlo (guchar *src, gint bpp, gpointer data)
{
GimpPixelRgn src_rgn, dest_rgn;
guchar *src, *s;
guchar *dest, *d;
gdouble vhi = 0.0, vlo = 1.0;
gint progress, max_progress;
gint has_alpha, alpha;
gint x1, y1, x2, y2;
gint x, y;
gpointer pr;
/* Get selection area */
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
alpha = (has_alpha) ? drawable->bpp - 1 : drawable->bpp;
/* Initialize progress */
progress = 0;
max_progress = (x2 - x1) * (y2 - y1) * 2;
gimp_pixel_rgn_init (&src_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), FALSE, FALSE);
for (pr = gimp_pixel_rgns_register (1, &src_rgn);
pr != NULL;
pr = gimp_pixel_rgns_process (pr))
ColorEnhanceParam_t *param = (ColorEnhanceParam_t*) data;
if (!param->has_alpha || src[3])
{
src = src_rgn.data;
for (y = 0; y < src_rgn.h; y++)
{
s = src;
for (x = 0; x < src_rgn.w; x++)
{
if (!has_alpha || (has_alpha && s[alpha]))
{
gdouble h, z, v;
gint c, m, y;
gint k;
guchar map[3];
c = 255 - s[0];
m = 255 - s[1];
y = 255 - s[2];
k = c;
if (m < k) k = m;
if (y < k) k = y;
map[0] = c - k;
map[1] = m - k;
map[2] = y - k;
gimp_rgb_to_hsv4(map, &h, &z, &v);
if (v > vhi) vhi = v;
if (v < vlo) vlo = v;
}
s += src_rgn.bpp;
}
src += src_rgn.rowstride;
}
/* Update progress */
progress += src_rgn.w * src_rgn.h;
gimp_progress_update ((gdouble) progress / (gdouble) max_progress);
gdouble v = get_v (src);
if (v > param->vhi) param->vhi = v;
if (v < param->vlo) param->vlo = v;
}
}
/* Now substitute pixel vales */
gimp_pixel_rgn_init (&src_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), FALSE, FALSE);
gimp_pixel_rgn_init (&dest_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), TRUE, TRUE);
static void
color_enhance_func (guchar *src, guchar *dest, gint bpp, gpointer data)
{
ColorEnhanceParam_t *param = (ColorEnhanceParam_t*) data;
for (pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn);
pr != NULL;
pr = gimp_pixel_rgns_process (pr))
{
src = src_rgn.data;
dest = dest_rgn.data;
for (y = 0; y < src_rgn.h; y++)
{
s = src;
d = dest;
for (x = 0; x < src_rgn.w; x++)
{
gdouble h, z, v;
gint c, m, y;
gint k;
guchar map[3];
c = 255 - s[0];
m = 255 - s[1];
y = 255 - s[2];
k = c;
if (m < k) k = m;
if (y < k) k = y;
map[0] = c - k;
map[1] = m - k;
map[2] = y - k;
gimp_rgb_to_hsv4(map, &h, &z, &v);
if (vhi!=vlo)
v = (v-vlo) / (vhi-vlo);
gimp_hsv_to_rgb4(map, h, z, v);
c = map[0];
m = map[1];
y = map[2];
c += k;
if (c > 255) c = 255;
m += k;
if (m > 255) m = 255;
y += k;
if (y > 255) y = 255;
d[0] = 255 - c;
d[1] = 255 - m;
d[2] = 255 - y;
if (has_alpha)
d[alpha] = s[alpha];
s += src_rgn.bpp;
d += dest_rgn.bpp;
}
src += src_rgn.rowstride;
dest += dest_rgn.rowstride;
}
/* Update progress */
progress += src_rgn.w * src_rgn.h;
gimp_progress_update ((gdouble) progress / (gdouble) max_progress);
}
enhance_it (src, dest, param->vlo, param->vhi);
/* update the region */
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
if (param->has_alpha)
dest[3] = src[3];
}
static void
Color_Enhance (GimpDrawable *drawable)
{
ColorEnhanceParam_t param;
param.has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
param.vhi = 0.0;
param.vlo = 1.0;
gimp_rgn_iterate1 (drawable, run_mode, find_vhi_vlo, &param);
gimp_rgn_iterate2 (drawable, run_mode, color_enhance_func, &param);
}
......@@ -69,7 +69,6 @@ static void run (gchar *name,
GimpParam **return_vals);
static void cubism (GimpDrawable *drawable);
static void render_cubism (GimpDrawable *drawable);
static void fill_poly_color (Polygon *poly,
GimpDrawable *drawable,
guchar *col);
......@@ -109,8 +108,6 @@ static void cubism_ok_callback (GtkWidget *widget,
* Local variables
*/
static guchar bg_col[4];
static CubismVals cvals =
{
10.0, /* tile_size */
......@@ -253,52 +250,6 @@ run (gchar *name,
gimp_drawable_detach (active_drawable);
}