Commit 3c85607e authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

app/Makefile.am removed.

2000-12-19  Michael Natterer  <mitch@gimp.org>

	* app/Makefile.am
	* app/gimphistogramP.h: removed.

	* app/gimphistogram.[ch]
	* app/histogramwidget.[ch]: Histogram cleanup: replaced the
	channel #define's by a properly named enum and use this enum
	type as parameter in functions instead of "int".

	* app/curves.c
	* app/histogram_tool.c
	* app/levels.c: changed accordingly.
parent ac19659a
2000-12-19 Michael Natterer <mitch@gimp.org>
* app/Makefile.am
* app/gimphistogramP.h: removed.
* app/gimphistogram.[ch]
* app/histogramwidget.[ch]: Histogram cleanup: replaced the
channel #define's by a properly named enum and use this enum
type as parameter in functions instead of "int".
* app/curves.c
* app/histogram_tool.c
* app/levels.c: changed accordingly.
2000-12-19 Sven Neumann <sven@gimp.org>
* plug-ins/common/exchange.c: applied (a modified version of)
......
......@@ -191,7 +191,6 @@ gimp_SOURCES = \
gimphelp.h \
gimphistogram.c \
gimphistogram.h \
gimphistogramP.h \
gimplist.c \
gimplist.h \
gimplistP.h \
......
......@@ -214,20 +214,20 @@ curves_colour_update (Tool *tool,
is_indexed = gimp_drawable_is_indexed (drawable);
has_alpha = GIMP_IMAGE_TYPE_HAS_ALPHA (sample_type);
curves_dialog->col_value[HISTOGRAM_RED] = color[RED_PIX];
curves_dialog->col_value[HISTOGRAM_GREEN] = color[GREEN_PIX];
curves_dialog->col_value[HISTOGRAM_BLUE] = color[BLUE_PIX];
curves_dialog->col_value[GIMP_HISTOGRAM_RED] = color[RED_PIX];
curves_dialog->col_value[GIMP_HISTOGRAM_GREEN] = color[GREEN_PIX];
curves_dialog->col_value[GIMP_HISTOGRAM_BLUE] = color[BLUE_PIX];
if (has_alpha)
{
curves_dialog->col_value [HISTOGRAM_ALPHA] = color[3];
curves_dialog->col_value [GIMP_HISTOGRAM_ALPHA] = color[3];
}
if (is_indexed)
curves_dialog->col_value [HISTOGRAM_ALPHA] = color[4];
curves_dialog->col_value [GIMP_HISTOGRAM_ALPHA] = color[4];
maxval = MAX (color[RED_PIX], color[GREEN_PIX]);
curves_dialog->col_value[HISTOGRAM_VALUE] = MAX (maxval, color[BLUE_PIX]);
curves_dialog->col_value[GIMP_HISTOGRAM_VALUE] = MAX (maxval, color[BLUE_PIX]);
g_free (color);
}
......@@ -335,11 +335,11 @@ curves_button_release (Tool *tool,
}
else if (bevent->state & GDK_CONTROL_MASK)
{
curves_add_point (drawable, x, y, HISTOGRAM_VALUE);
curves_add_point (drawable, x, y, HISTOGRAM_RED);
curves_add_point (drawable, x, y, HISTOGRAM_GREEN);
curves_add_point (drawable, x, y, HISTOGRAM_BLUE);
curves_add_point (drawable, x, y, HISTOGRAM_ALPHA);
curves_add_point (drawable, x, y, GIMP_HISTOGRAM_VALUE);
curves_add_point (drawable, x, y, GIMP_HISTOGRAM_RED);
curves_add_point (drawable, x, y, GIMP_HISTOGRAM_GREEN);
curves_add_point (drawable, x, y, GIMP_HISTOGRAM_BLUE);
curves_add_point (drawable, x, y, GIMP_HISTOGRAM_ALPHA);
curves_calculate_curve (curves_dialog);
}
......@@ -455,7 +455,7 @@ curves_initialize (GDisplay *gdisp)
curves_dialog = curves_dialog_new ();
/* Initialize the values */
curves_dialog->channel = HISTOGRAM_VALUE;
curves_dialog->channel = GIMP_HISTOGRAM_VALUE;
for (i = 0; i < 5; i++)
for (j = 0; j < 256; j++)
curves_dialog->curve[i][j] = j;
......@@ -547,7 +547,7 @@ curves_dialog_new (void)
cd->cursor_ind_width = -1;
cd->preview = TRUE;
cd->pixmap = NULL;
cd->channel = HISTOGRAM_VALUE;
cd->channel = GIMP_HISTOGRAM_VALUE;
for (i = 0; i < 5; i++)
cd->curve_type[i] = SMOOTH;
......@@ -591,11 +591,11 @@ curves_dialog_new (void)
(FALSE, curves_channel_callback,
cd, (gpointer) cd->channel,
_("Value"), (gpointer) HISTOGRAM_VALUE, &channel_items[0],
_("Red"), (gpointer) HISTOGRAM_RED, &channel_items[1],
_("Green"), (gpointer) HISTOGRAM_GREEN, &channel_items[2],
_("Blue"), (gpointer) HISTOGRAM_BLUE, &channel_items[3],
_("Alpha"), (gpointer) HISTOGRAM_ALPHA, &channel_items[4],
_("Value"), (gpointer) GIMP_HISTOGRAM_VALUE, &channel_items[0],
_("Red"), (gpointer) GIMP_HISTOGRAM_RED, &channel_items[1],
_("Green"), (gpointer) GIMP_HISTOGRAM_GREEN, &channel_items[2],
_("Blue"), (gpointer) GIMP_HISTOGRAM_BLUE, &channel_items[3],
_("Alpha"), (gpointer) GIMP_HISTOGRAM_ALPHA, &channel_items[4],
NULL);
......@@ -796,9 +796,9 @@ curves_update (CurvesDialog *cd,
sel_channel = cd->channel;
} else {
if(cd->channel == 2)
sel_channel = HISTOGRAM_ALPHA;
sel_channel = GIMP_HISTOGRAM_ALPHA;
else
sel_channel = HISTOGRAM_VALUE;
sel_channel = GIMP_HISTOGRAM_VALUE;
}
......@@ -808,8 +808,8 @@ curves_update (CurvesDialog *cd,
switch (sel_channel)
{
case HISTOGRAM_VALUE:
case HISTOGRAM_ALPHA:
case GIMP_HISTOGRAM_VALUE:
case GIMP_HISTOGRAM_ALPHA:
for (i = 0; i < XRANGE_HEIGHT / 2; i++)
{
for (j = 0; j < XRANGE_WIDTH ; j++)
......@@ -823,17 +823,17 @@ curves_update (CurvesDialog *cd,
}
break;
case HISTOGRAM_RED:
case HISTOGRAM_GREEN:
case HISTOGRAM_BLUE:
case GIMP_HISTOGRAM_RED:
case GIMP_HISTOGRAM_GREEN:
case GIMP_HISTOGRAM_BLUE:
{
for (i = 0; i < XRANGE_HEIGHT / 2; i++)
{
for (j = 0; j < XRANGE_WIDTH; j++)
{
buf[j*3+0] = cd->curve[HISTOGRAM_RED][j];
buf[j*3+1] = cd->curve[HISTOGRAM_GREEN][j];
buf[j*3+2] = cd->curve[HISTOGRAM_BLUE][j];
buf[j*3+0] = cd->curve[GIMP_HISTOGRAM_RED][j];
buf[j*3+1] = cd->curve[GIMP_HISTOGRAM_GREEN][j];
buf[j*3+2] = cd->curve[GIMP_HISTOGRAM_BLUE][j];
}
gtk_preview_draw_row (GTK_PREVIEW (cd->xrange),
buf, 0, i, XRANGE_WIDTH);
......@@ -888,14 +888,14 @@ curves_update (CurvesDialog *cd,
{
switch (sel_channel)
{
case HISTOGRAM_VALUE:
case HISTOGRAM_ALPHA:
case GIMP_HISTOGRAM_VALUE:
case GIMP_HISTOGRAM_ALPHA:
pix[0] = pix[1] = pix[2] = (255 - i);
break;
case HISTOGRAM_RED:
case HISTOGRAM_GREEN:
case HISTOGRAM_BLUE:
case GIMP_HISTOGRAM_RED:
case GIMP_HISTOGRAM_GREEN:
case GIMP_HISTOGRAM_BLUE:
pix[0] = pix[1] = pix[2] = 0;
pix[sel_channel - 1] = (255 - i);
break;
......
......@@ -20,57 +20,84 @@
#include "config.h"
#include "gimphistogramP.h"
#ifdef ENABLE_MP
#include <pthread.h>
#endif /* ENABLE_MP */
#include <glib.h>
#include <libgimp/gimpmath.h>
#include "gimphistogram.h"
#include "pixel_region.h"
#include "gimpdrawable.h"
#include "channel.h"
#include "gimpimage.h"
#include "gimprc.h"
#include <glib.h>
#include <math.h>
#ifdef ENABLE_MP
#include <pthread.h>
struct _GimpHistogram
{
gint bins;
gdouble **values;
gint nchannels;
#ifdef ENABLE_MP
pthread_mutex_t mutex;
gint nthreads;
gdouble ***tmp_values;
gchar *tmp_slots;
#endif /* ENABLE_MP */
};
GimpHistogram *
gimp_histogram_new (void)
{
GimpHistogram *histogram;
histogram = g_new (GimpHistogram, 1);
histogram->values = NULL;
histogram = g_new0 (GimpHistogram, 1);
histogram->bins = 0;
histogram->values = NULL;
histogram->nchannels = 0;
#ifdef ENABLE_MP
histogram->nthreads = 0;
histogram->tmp_values = NULL;
histogram->tmp_slot = NULL;
#endif /* ENABLE_MP */
return histogram;
}
void
gimp_histogram_free (GimpHistogram *histogram)
{
int i;
gint i;
if (histogram->values)
{
for (i = 0; i < histogram->nchannels; i++)
g_free (histogram->values[i]);
g_free (histogram->values);
}
{
for (i = 0; i < histogram->nchannels; i++)
g_free (histogram->values[i]);
g_free (histogram->values);
}
g_free (histogram);
}
void
static void
gimp_histogram_calculate_sub_region (GimpHistogram *histogram,
PixelRegion *region,
PixelRegion *mask)
{
const unsigned char *src, *msrc;
const unsigned char *m, *s;
double **values;
int h, w, max;
const guchar *src, *msrc;
const guchar *m, *s;
gdouble **values;
gint h, w, max;
#ifdef ENABLE_MP
int slot = 0;
gint slot = 0;
/* find an unused temporary slot to put our results in and lock it */
pthread_mutex_lock (&histogram->mutex);
{
......@@ -83,126 +110,149 @@ gimp_histogram_calculate_sub_region (GimpHistogram *histogram,
#else /* !ENABLE_MP */
values = histogram->values;
#endif
h = region->h;
w = region->w;
if (mask)
{
double masked;
src = region->data;
msrc = region->data;
while (h--)
{
s = src;
m = msrc;
w = region->w;
switch(region->bytes)
{
case 1:
while (w--)
{
masked = m[0] / 255.0;
values[0][s[0]] += masked;
s += 1;
m += 1;
} break;
case 2:
while (w--)
{
masked = m[0] / 255.0;
values[0][s[0]] += masked;
values[1][s[1]] += masked;
s += 2;
m += 1;
} break;
case 3: /* calculate seperate value values */
while (w--)
{
masked = m[0] / 255.0;
values[1][s[0]] += masked;
values[2][s[1]] += masked;
values[3][s[2]] += masked;
max = (s[0] > s[1]) ? s[0] : s[1];
if (s[2] > max)
values[0][s[2]] += masked;
else
values[0][max] += masked;
s += 3;
m += 1;
} break;
case 4: /* calculate seperate value values */
while (w--)
{
masked = m[0] / 255.0;
values[1][s[0]] += masked;
values[2][s[1]] += masked;
values[3][s[2]] += masked;
values[4][s[3]] += masked;
max = (s[0] > s[1]) ? s[0] : s[1];
if (s[2] > max)
values[0][s[2]] += masked;
else
values[0][max] += masked;
s += 3;
m += 1;
} break;
}
src += region->rowstride;
msrc += mask->rowstride;
gdouble masked;
src = region->data;
msrc = region->data;
while (h--)
{
s = src;
m = msrc;
w = region->w;
switch(region->bytes)
{
case 1:
while (w--)
{
masked = m[0] / 255.0;
values[0][s[0]] += masked;
s += 1;
m += 1;
}
break;
case 2:
while (w--)
{
masked = m[0] / 255.0;
values[0][s[0]] += masked;
values[1][s[1]] += masked;
s += 2;
m += 1;
}
break;
case 3: /* calculate seperate value values */
while (w--)
{
masked = m[0] / 255.0;
values[1][s[0]] += masked;
values[2][s[1]] += masked;
values[3][s[2]] += masked;
max = (s[0] > s[1]) ? s[0] : s[1];
if (s[2] > max)
values[0][s[2]] += masked;
else
values[0][max] += masked;
s += 3;
m += 1;
}
break;
case 4: /* calculate seperate value values */
while (w--)
{
masked = m[0] / 255.0;
values[1][s[0]] += masked;
values[2][s[1]] += masked;
values[3][s[2]] += masked;
values[4][s[3]] += masked;
max = (s[0] > s[1]) ? s[0] : s[1];
if (s[2] > max)
values[0][s[2]] += masked;
else
values[0][max] += masked;
s += 3;
m += 1;
}
break;
}
src += region->rowstride;
msrc += mask->rowstride;
}
}
}
else /* no mask */
{
src = region->data;
while (h--)
{
s = src;
w = region->w;
switch(region->bytes)
{
case 1:
while (w--)
{
values[0][s[0]] += 1.0;
s += 1;
} break;
case 2:
while (w--)
{
values[0][s[0]] += 1.0;
values[1][s[1]] += 1.0;
s += 2;
} break;
case 3: /* calculate seperate value values */
while (w--)
{
values[1][s[0]] += 1.0;
values[2][s[1]] += 1.0;
values[3][s[2]] += 1.0;
max = (s[0] > s[1]) ? s[0] : s[1];
if (s[2] > max)
values[0][s[2]] += 1.0;
else
values[0][max] += 1.0;
s += 3;
} break;
case 4: /* calculate seperate value values */
while (w--)
{
values[1][s[0]] += 1.0;
values[2][s[1]] += 1.0;
values[3][s[2]] += 1.0;
values[4][s[3]] += 1.0;
max = (s[0] > s[1]) ? s[0] : s[1];
if (s[2] > max)
values[0][s[2]] += 1.0;
else
values[0][max] += 1.0;
s += 4;
} break;
}
src += region->rowstride;
src = region->data;
while (h--)
{
s = src;
w = region->w;
switch(region->bytes)
{
case 1:
while (w--)
{
values[0][s[0]] += 1.0;
s += 1;
}
break;
case 2:
while (w--)
{
values[0][s[0]] += 1.0;
values[1][s[1]] += 1.0;
s += 2;
}
break;
case 3: /* calculate seperate value values */
while (w--)
{
values[1][s[0]] += 1.0;
values[2][s[1]] += 1.0;
values[3][s[2]] += 1.0;
max = (s[0] > s[1]) ? s[0] : s[1];
if (s[2] > max)
values[0][s[2]] += 1.0;
else
values[0][max] += 1.0;
s += 3;
}
break;
case 4: /* calculate seperate value values */
while (w--)
{
values[1][s[0]] += 1.0;
values[2][s[1]] += 1.0;
values[3][s[2]] += 1.0;
values[4][s[3]] += 1.0;
max = (s[0] > s[1]) ? s[0] : s[1];
if (s[2] > max)
values[0][s[2]] += 1.0;
else
values[0][max] += 1.0;
s += 4;
}
break;
}
src += region->rowstride;
}
}
}
#ifdef ENABLE_MP
/* unlock this slot */
......@@ -215,22 +265,25 @@ gimp_histogram_calculate_sub_region (GimpHistogram *histogram,
static void
gimp_histogram_alloc (GimpHistogram *histogram,
int bytes)
gint bytes)
{
int i;
gint i;
if (bytes + 1 != histogram->nchannels)
{
if (histogram->values)
{
if (histogram->values)
{
for (i = 0; i < histogram->nchannels; i++)
g_free (histogram->values[i]);
g_free (histogram->values);
}
histogram->nchannels = bytes + 1;
histogram->values = g_new0 (gdouble *, histogram->nchannels);
for (i = 0; i < histogram->nchannels; i++)
g_free (histogram->values[i]);
g_free (histogram->values);
histogram->values[i] = g_new (double, 256);
}
histogram->nchannels = bytes + 1;
histogram->values = g_new (double *, histogram->nchannels);
for (i = 0; i < histogram->nchannels; i++)
histogram->values[i] = g_new (double, 256);
}
}
void
......@@ -238,28 +291,31 @@ gimp_histogram_calculate (GimpHistogram *histogram,
PixelRegion *region,
PixelRegion *mask)
{
int i, j;
gint i, j;
#ifdef ENABLE_MP
int k;
gint k;
#endif
gimp_histogram_alloc (histogram, region->bytes);
#ifdef ENABLE_MP
pthread_mutex_init (&histogram->mutex, NULL);
histogram->tmp_slots = g_new (char, num_processors);
histogram->tmp_values = g_new (double **, num_processors);
histogram->tmp_slots = g_new0 (gchar, num_processors);
histogram->tmp_values = g_new0 (gdouble **, num_processors);
for (i = 0; i < num_processors; i++)
{
histogram->tmp_values[i] = g_new (double *, histogram->nchannels);
histogram->tmp_slots[i] = 0;
for (j = 0; j < histogram->nchannels; j++)
{
histogram->tmp_values[i][j] = g_new (double, 256);
for (k = 0; k < 256; k++)
histogram->tmp_values[i][j][k] = 0.0;
histogram->tmp_values[i] = g_new0 (double *, histogram->nchannels);
histogram->tmp_slots[i] = 0;
for (j = 0; j < histogram->nchannels; j++)
{
histogram->tmp_values[i][j] = g_new0 (gdouble, 256);
for (k = 0; k < 256; k++)
histogram->tmp_values[i][j][k] = 0.0;
}
}
}
#endif
for (i = 0; i < histogram->nchannels; i++)
......@@ -272,15 +328,16 @@ gimp_histogram_calculate (GimpHistogram *histogram,
#ifdef ENABLE_MP
/* add up all the tmp buffers and free their memmory */
for (i = 0; i < num_processors; i++)
{
for (j = 0; j < histogram->nchannels; j++)
{
for (k = 0; k < 256; k++)
histogram->values[j][k] += histogram->tmp_values[i][j][k];
g_free (histogram->tmp_values[i][j]);
for (j = 0; j < histogram->nchannels; j++)
{
for (k = 0; k < 256; k++)
histogram->values[j][k] += histogram->tmp_values[i][j][k];
g_free (histogram->tmp_values[i][j]);
}
g_free (histogram->tmp_values[i]);
}
g_free (histogram->tmp_values[i]);
}
g_free (histogram->tmp_values);
g_free (histogram->tmp_slots);
#endif
......@@ -293,56 +350,62 @@ gimp_histogram_calculate_drawable (GimpHistogram *histogram,
{
PixelRegion region;
PixelRegion mask;
int x1, y1, x2, y2;
int off_x, off_y;
int no_mask;
gint x1, y1, x2, y2;
gint off_x, off_y;
gboolean no_mask;
no_mask = (drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2) == FALSE);
pixel_region_init (&region, gimp_drawable_data (drawable), x1, y1,
(x2 - x1), (y2 - y1), FALSE);
if (!no_mask)
{
Channel *sel_mask;
GimpImage *gimage;
{
Channel *sel_mask;
GimpImage *gimage;
gimage = gimp_drawable_gimage(drawable);
sel_mask = gimp_image_get_mask (gimage);
gimage = gimp_drawable_gimage (drawable);
sel_mask = gimp_image_get_mask (gimage);
drawable_offsets (drawable, &off_x, &off_y);
pixel_region_init (&mask, gimp_drawable_data (GIMP_DRAWABLE (sel_mask)),
x1 + off_x, y1 + off_y, (x2 - x1), (y2 - y1), FALSE);
gimp_histogram_calculate (histogram, &region, &mask);
}
drawable_offsets (drawable, &off_x, &off_y);
pixel_region_init (&mask, gimp_drawable_data (GIMP_DRAWABLE (sel_mask)),
x1 + off_x, y1 + off_y, (x2 - x1), (y2 - y1), FALSE);
gimp_histogram_calculate (histogram, &region, &mask);
}
else
gimp_histogram_calculate (histogram, &region, NULL);
{
gimp_histogram_calculate (histogram, &region, NULL);
}
}
double
gimp_histogram_get_maximum (GimpHistogram *histogram,
int channel)
gdouble
gimp_histogram_get_maximum (GimpHistogram *histogram,
GimpHistogramChannel channel)
{
double max = 0.0;
int x;
gdouble max = 0.0;
gint x;
for (x = 0; x < 256; x++)
if (histogram->values[channel][x] > max)
max = histogram->values[channel][x];
return max;
}
double
gimp_histogram_get_value (GimpHistogram *histogram,
int channel,
int bin)
gdouble
gimp_histogram_get_value (GimpHistogram *histogram,
GimpHistogramChannel channel,
gint bin)
{
if (channel < histogram->nchannels && bin >= 0 && bin < 256)
return histogram->values[channel][bin];
return 0.0;
}
double
gimp_histogram_get_channel (GimpHistogram *histogram,
int channel,
int bin)
gdouble