Commit adff5aeb authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

code cleanup. Removed unsued code, renamed variables and types.

2005-02-11  Sven Neumann  <sven@gimp.org>

	* app/base/pixel-processor.[ch]: code cleanup. Removed unsued code,
	renamed variables and types.

	* app/base/gimphistogram.c
	* app/core/gimpchannel-combine.c
	* app/core/gimpchannel.c
	* app/core/gimpdrawable-equalize.c
	* app/core/gimpdrawable-invert.c
	* app/core/gimpdrawable-levels.c
	* app/paint-funcs/paint-funcs.c
	* tools/pdbgen/pdb/color.pdb: changed accordingly.

	* app/pdb/color_cmds.c: regenerated.
parent 9c01b4dc
2005-02-11 Sven Neumann <sven@gimp.org>
* app/base/pixel-processor.[ch]: code cleanup. Removed unsued code,
renamed variables and types.
* app/base/gimphistogram.c
* app/core/gimpchannel-combine.c
* app/core/gimpchannel.c
* app/core/gimpdrawable-equalize.c
* app/core/gimpdrawable-invert.c
* app/core/gimpdrawable-levels.c
* app/paint-funcs/paint-funcs.c
* tools/pdbgen/pdb/color.pdb: changed accordingly.
* app/pdb/color_cmds.c: regenerated.
2005-02-11 Sven Neumann <sven@gimp.org>
* app/base/pixel-processor.c: include <string.h>.
......
......@@ -143,7 +143,8 @@ gimp_histogram_calculate (GimpHistogram *histogram,
for (j = 0; j < 256; j++)
histogram->values[i][j] = 0.0;
pixel_regions_process_parallel ((p_func) gimp_histogram_calculate_sub_region,
pixel_regions_process_parallel ((PixelProcessorFunc)
gimp_histogram_calculate_sub_region,
histogram, 2, region, mask);
#ifdef ENABLE_MP
......
......@@ -44,26 +44,28 @@
extern GimpBaseConfig *base_config;
typedef void (* p1_func) (gpointer ,
typedef void (* p1_func) (gpointer data,
PixelRegion *);
typedef void (* p2_func) (gpointer ,
typedef void (* p2_func) (gpointer data,
PixelRegion * ,
PixelRegion *);
typedef void (* p3_func) (gpointer ,
typedef void (* p3_func) (gpointer data,
PixelRegion *,
PixelRegion *,
PixelRegion *);
typedef void (* p4_func) (gpointer ,
typedef void (* p4_func) (gpointer data,
PixelRegion *,
PixelRegion *,
PixelRegion *,
PixelRegion *);
typedef struct _PixelProcessor PixelProcessor;
struct _PixelProcessor
{
gpointer data;
p_func f;
PixelProcessorFunc f;
PixelRegionIterator *PRI;
#ifdef ENABLE_MP
......@@ -73,103 +75,96 @@ struct _PixelProcessor
gint n_regions;
PixelRegion *r[4];
void *progress_report_data;
ProgressReportFunc progress_report_func;
};
static void pixel_processor_free (PixelProcessor *pp);
#ifdef ENABLE_MP
static void *
do_parallel_regions (PixelProcessor *p_s)
do_parallel_regions (PixelProcessor *processor)
{
PixelRegion tr[4];
gint n_tiles = 0;
gint i;
gboolean cont = TRUE;
pthread_mutex_lock (&p_s->mutex);
pthread_mutex_lock (&processor->mutex);
if (p_s->nthreads != 0 && p_s->PRI)
p_s->PRI = pixel_regions_process (p_s->PRI);
if (processor->nthreads != 0 && processor->PRI)
processor->PRI = pixel_regions_process (processor->PRI);
if (p_s->PRI == NULL)
if (processor->PRI == NULL)
{
pthread_mutex_unlock (&p_s->mutex);
pthread_mutex_unlock (&processor->mutex);
return NULL;
}
p_s->nthreads++;
processor->nthreads++;
do
{
for (i = 0; i < p_s->n_regions; i++)
if (p_s->r[i])
for (i = 0; i < processor->n_regions; i++)
if (processor->r[i])
{
memcpy (&tr[i], p_s->r[i], sizeof (PixelRegion));
memcpy (&tr[i], processor->r[i], sizeof (PixelRegion));
if (tr[i].tiles)
tile_lock(tr[i].curtile);
}
pthread_mutex_unlock (&p_s->mutex);
pthread_mutex_unlock (&processor->mutex);
n_tiles++;
switch(p_s->n_regions)
switch(processor->n_regions)
{
case 1:
((p1_func) p_s->f) (p_s->data,
p_s->r[0] ? &tr[0] : NULL);
((p1_func) processor->f) (processor->data,
processor->r[0] ? &tr[0] : NULL);
break;
case 2:
((p2_func) p_s->f) (p_s->data,
p_s->r[0] ? &tr[0] : NULL,
p_s->r[1] ? &tr[1] : NULL);
((p2_func) processor->f) (processor->data,
processor->r[0] ? &tr[0] : NULL,
processor->r[1] ? &tr[1] : NULL);
break;
case 3:
((p3_func) p_s->f) (p_s->data,
p_s->r[0] ? &tr[0] : NULL,
p_s->r[1] ? &tr[1] : NULL,
p_s->r[2] ? &tr[2] : NULL);
((p3_func) processor->f) (processor->data,
processor->r[0] ? &tr[0] : NULL,
processor->r[1] ? &tr[1] : NULL,
processor->r[2] ? &tr[2] : NULL);
break;
case 4:
((p4_func) p_s->f) (p_s->data,
p_s->r[0] ? &tr[0] : NULL,
p_s->r[1] ? &tr[1] : NULL,
p_s->r[2] ? &tr[2] : NULL,
p_s->r[3] ? &tr[3] : NULL);
((p4_func) processor->f) (processor->data,
processor->r[0] ? &tr[0] : NULL,
processor->r[1] ? &tr[1] : NULL,
processor->r[2] ? &tr[2] : NULL,
processor->r[3] ? &tr[3] : NULL);
break;
default:
g_warning ("do_parallel_regions: Bad number of regions %d\n",
p_s->n_regions);
processor->n_regions);
break;
}
pthread_mutex_lock (&p_s->mutex);
pthread_mutex_lock (&processor->mutex);
for (i = 0; i < p_s->n_regions; i++)
if (p_s->r[i])
for (i = 0; i < processor->n_regions; i++)
if (processor->r[i])
{
if (tr[i].tiles)
tile_release (tr[i].curtile, tr[i].dirty);
}
if (p_s->progress_report_func &&
!p_s->progress_report_func (p_s->progress_report_data,
p_s->r[0]->x, p_s->r[0]->y,
p_s->r[0]->w, p_s->r[0]->h))
cont = FALSE;
}
while (cont && p_s->PRI &&
(p_s->PRI = pixel_regions_process (p_s->PRI)));
while (processor->PRI &&
(processor->PRI = pixel_regions_process (processor->PRI)));
p_s->nthreads--;
processor->nthreads--;
pthread_mutex_unlock (&p_s->mutex);
pthread_mutex_unlock (&processor->mutex);
return NULL;
}
......@@ -184,54 +179,46 @@ do_parallel_regions (PixelProcessor *p_s)
*/
static gpointer
do_parallel_regions_single (PixelProcessor *p_s)
do_parallel_regions_single (PixelProcessor *processor)
{
gboolean cont = TRUE;
do
{
switch (p_s->n_regions)
switch (processor->n_regions)
{
case 1:
((p1_func) p_s->f) (p_s->data,
p_s->r[0]);
((p1_func) processor->f) (processor->data,
processor->r[0]);
break;
case 2:
((p2_func) p_s->f) (p_s->data,
p_s->r[0],
p_s->r[1]);
((p2_func) processor->f) (processor->data,
processor->r[0],
processor->r[1]);
break;
case 3:
((p3_func) p_s->f) (p_s->data,
p_s->r[0],
p_s->r[1],
p_s->r[2]);
((p3_func) processor->f) (processor->data,
processor->r[0],
processor->r[1],
processor->r[2]);
break;
case 4:
((p4_func) p_s->f) (p_s->data,
p_s->r[0],
p_s->r[1],
p_s->r[2],
p_s->r[3]);
((p4_func) processor->f) (processor->data,
processor->r[0],
processor->r[1],
processor->r[2],
processor->r[3]);
break;
default:
g_warning ("do_parallel_regions_single: Bad number of regions %d\n",
p_s->n_regions);
processor->n_regions);
}
if (p_s->progress_report_func &&
!p_s->progress_report_func (p_s->progress_report_data,
p_s->r[0]->x, p_s->r[0]->y,
p_s->r[0]->w, p_s->r[0]->h))
cont = FALSE;
}
while (cont && p_s->PRI &&
(p_s->PRI = pixel_regions_process (p_s->PRI)));
while (processor->PRI &&
(processor->PRI = pixel_regions_process (processor->PRI)));
return NULL;
}
......@@ -239,17 +226,15 @@ do_parallel_regions_single (PixelProcessor *p_s)
#define MAX_THREADS 30
static void
pixel_regions_do_parallel (PixelProcessor *p_s)
pixel_regions_do_parallel (PixelProcessor *processor)
{
#ifdef ENABLE_MP
gint nthreads;
nthreads = MIN (base_config->num_processors, MAX_THREADS);
gint nthreads = MIN (base_config->num_processors, MAX_THREADS);
/* make sure we have at least one tile per thread */
nthreads = MIN (nthreads,
(p_s->PRI->region_width * p_s->PRI->region_height)
/ (TILE_WIDTH * TILE_HEIGHT));
(processor->PRI->region_width *
processor->PRI->region_height) / (TILE_WIDTH * TILE_HEIGHT));
if (nthreads > 1)
{
......@@ -263,180 +248,118 @@ pixel_regions_do_parallel (PixelProcessor *p_s)
{
pthread_create (&threads[i], &pthread_attr,
(void *(*)(void *)) do_parallel_regions,
p_s);
processor);
}
for (i = 0; i < nthreads; i++)
{
gint ret;
gint ret = pthread_join (threads[i], NULL);
if ((ret = pthread_join (threads[i], NULL)))
{
g_printerr ("pixel_regions_do_parallel: "
"pthread_join returned: %d\n", ret);
}
if (ret)
g_printerr ("pixel_regions_do_parallel: "
"pthread_join returned: %d\n", ret);
}
if (p_s->nthreads != 0)
if (processor->nthreads != 0)
g_printerr ("pixel_regions_do_prarallel: we lost a thread\n");
}
else
#endif
{
do_parallel_regions_single (p_s);
do_parallel_regions_single (processor);
}
}
static PixelProcessor *
pixel_regions_real_process_parallel (p_func f,
gpointer data,
ProgressReportFunc report_func,
gpointer report_data,
gint num_regions,
va_list ap)
pixel_regions_process_parallel_valist (PixelProcessorFunc f,
gpointer data,
gint num_regions,
va_list ap)
{
PixelProcessor *processor = g_new (PixelProcessor, 1);
gint i;
PixelProcessor *p_s;
p_s = g_new (PixelProcessor, 1);
for (i = 0; i < num_regions; i++)
p_s->r[i] = va_arg (ap, PixelRegion *);
processor->r[i] = va_arg (ap, PixelRegion *);
switch(num_regions)
{
case 1:
p_s->PRI = pixel_regions_register (num_regions,
p_s->r[0]);
processor->PRI = pixel_regions_register (num_regions,
processor->r[0]);
break;
case 2:
p_s->PRI = pixel_regions_register (num_regions,
p_s->r[0],
p_s->r[1]);
processor->PRI = pixel_regions_register (num_regions,
processor->r[0],
processor->r[1]);
break;
case 3:
p_s->PRI = pixel_regions_register (num_regions,
p_s->r[0],
p_s->r[1],
p_s->r[2]);
processor->PRI = pixel_regions_register (num_regions,
processor->r[0],
processor->r[1],
processor->r[2]);
break;
case 4:
p_s->PRI = pixel_regions_register (num_regions,
p_s->r[0],
p_s->r[1],
p_s->r[2],
p_s->r[3]);
processor->PRI = pixel_regions_register (num_regions,
processor->r[0],
processor->r[1],
processor->r[2],
processor->r[3]);
break;
default:
g_warning ("pixel_regions_real_process_parallel:"
"Bad number of regions %d\n", p_s->n_regions);
}
if (!p_s->PRI)
{
pixel_processor_free (p_s);
g_warning ("pixel_regions_process_parallel:"
"Bad number of regions %d\n", processor->n_regions);
pixel_processor_free (processor);
return NULL;
}
p_s->f = f;
p_s->data = data;
p_s->n_regions = num_regions;
processor->f = f;
processor->data = data;
processor->n_regions = num_regions;
#ifdef ENABLE_MP
pthread_mutex_init (&p_s->mutex, NULL);
p_s->nthreads = 0;
pthread_mutex_init (&processor->mutex, NULL);
processor->nthreads = 0;
#endif
p_s->progress_report_data = report_data;
p_s->progress_report_func = report_func;
pixel_regions_do_parallel (p_s);
pixel_regions_do_parallel (processor);
if (p_s->PRI)
return p_s;
if (processor->PRI)
return processor;
#ifdef ENABLE_MP
pthread_mutex_destroy (&p_s->mutex);
pthread_mutex_destroy (&processor->mutex);
#endif
pixel_processor_free (p_s);
pixel_processor_free (processor);
return NULL;
}
void
pixel_regions_process_parallel (p_func f,
gpointer data,
gint num_regions,
pixel_regions_process_parallel (PixelProcessorFunc f,
gpointer data,
gint num_regions,
...)
{
va_list va;
va_start (va, num_regions);
pixel_regions_real_process_parallel (f, data, NULL, NULL, num_regions, va);
pixel_regions_process_parallel_valist (f, data, num_regions, va);
va_end (va);
}
PixelProcessor *
pixel_regions_process_parallel_progress (p_func f,
gpointer data,
ProgressReportFunc progress_func,
gpointer progress_data,
gint num_regions,
...)
{
PixelProcessor *ret;
va_list va;
va_start (va, num_regions);
ret = pixel_regions_real_process_parallel (f, data,
progress_func, progress_data,
num_regions, va);
va_end (va);
return ret;
}
void
pixel_processor_stop (PixelProcessor *pp)
{
if (!pp)
return;
if (pp->PRI)
{
pixel_regions_process_stop (pp->PRI);
pp->PRI = NULL;
}
pixel_processor_free (pp);
}
PixelProcessor *
pixel_processor_cont (PixelProcessor *pp)
static void
pixel_processor_free (PixelProcessor *processor)
{
pixel_regions_do_parallel (pp);
if (pp->PRI)
return pp;
pixel_processor_free (pp);
if (processor->PRI)
pixel_regions_process_stop (processor->PRI);
return NULL;
}
void
pixel_processor_free (PixelProcessor *pp)
{
if (pp->PRI)
pixel_processor_stop (pp);
else
g_free(pp);
g_free (processor);
}
......@@ -22,31 +22,13 @@
#define __PIXEL_PROCESSOR_H__
typedef struct _PixelProcessor PixelProcessor;
typedef void (* PixelProcessorFunc) (void);
typedef void (* p_func) (void);
typedef gint (* ProgressReportFunc) (gpointer ,
gint ,
gint ,
gint ,
gint );
void pixel_regions_process_parallel (p_func f,
gpointer data,
gint num_regions,
...);
PixelProcessor * pixel_process_progress (p_func f,
gpointer data,
ProgressReportFunc progress_func,
gpointer progress_data,
gint num_regions,
...);
void pixel_processor_free (PixelProcessor *pp);
void pixel_processor_stop (PixelProcessor *pp);
PixelProcessor * pixel_processor_cont (PixelProcessor *pp);
void pixel_regions_process_parallel (PixelProcessorFunc func,
gpointer data,
gint num_regions,
...);
#endif /* __PIXEL_PROCESSOR_H__ */
......@@ -514,19 +514,19 @@ gimp_channel_combine_mask (GimpChannel *mask,
{
case GIMP_CHANNEL_OP_ADD:
case GIMP_CHANNEL_OP_REPLACE:
pixel_regions_process_parallel ((p_func)
pixel_regions_process_parallel ((PixelProcessorFunc)
gimp_channel_combine_sub_region_add,
NULL, 2, &srcPR, &destPR);
break;
case GIMP_CHANNEL_OP_SUBTRACT:
pixel_regions_process_parallel ((p_func)
pixel_regions_process_parallel ((PixelProcessorFunc)
gimp_channel_combine_sub_region_sub,
NULL, 2, &srcPR, &destPR);
break;
case GIMP_CHANNEL_OP_INTERSECT:
pixel_regions_process_parallel ((p_func)
pixel_regions_process_parallel ((PixelProcessorFunc)
gimp_channel_combine_sub_region_intersect,
NULL, 2, &srcPR, &destPR);
break;
......
......@@ -1176,7 +1176,7 @@ gimp_channel_real_sharpen (GimpChannel *channel,
TRUE);
lut = threshold_lut_new (0.5, 1);
pixel_regions_process_parallel ((p_func) gimp_lut_process_inline,
pixel_regions_process_parallel ((PixelProcessorFunc) gimp_lut_process_inline,
lut, 1, &maskPR);
gimp_lut_free (lut);
......@@ -1297,8 +1297,9 @@ gimp_channel_real_invert (GimpChannel *channel,
lut = invert_lut_new (1);
pixel_regions_process_parallel ((p_func) gimp_lut_process_inline, lut,
1, &maskPR);