Commit dde36031 authored by jaycox's avatar jaycox

build color_cmds, lut_funcs, and pixel_processor feedback in the splash


	* app/Makefile.am: build color_cmds, lut_funcs, and pixel_processor
	* app/app_procs.c: feedback in the splash screen when loading
 	parasites.
	* app/boundary.c: Optimized find_empty_segs.

	* app/brightness_contrast.[ch]
	* app/levels.[ch]
	* app/posterize.[ch]:
 	moved pdb and lut calculation code.  These files now contain only
	GUI functions.

	* app/channel.c: Optimized channel_bounds (fewer compares, better
 	use of registers).  Use color_region instead of channel_*_segment
 	in channel_combine_rect.  Optimized channel_combine_ellipse by
 	skipping pixels inside of the ellipse.  Use
 	pixel_region_process_parallel in channel_combine_mask.  Use a
 	GimpLut in channel_invert, and channel_sharpen.

	* app/invert.c
	* app/equalize.c: moved the lut functions to lut_funcs.c

	* app/gimpdrawable.c, app/gimpdrawableP.h
	* app/gimpimage.c, app/gimpimageP.h: removed unused gimpmatrix
	variables/includes.

	* app/gimplut.[ch]: added new function gimp_lut_process_inline
 	that operates on a single PixelRegion.

	* app/gimpparasite.[ch]: new functions to save/load parasiterc

	* app/parasitelist.[ch]: new functions to save/load ParasiteLists
 	in/from files.

	* libgimp/parasite.[ch]: new functions to load/save parasites.

	* app/internal_procs.c: get some procs from new location in
	color_cmds.h.

	* app/pixel_region.[ch]: moved pixel_regions_process_parallel
 	related functions to a new file.

	* app/color_cmds.[ch]: new files for PDB
 	definitions/implementations of color correction functions.

	* app/lut_funcs.[ch]: new files to hold lut creation functions.

	* app/pixel_processor.[ch]: new files that contain the
 	pixel_regions_process_parallel routines.  Added some new
 	capabilities that are currently unused.
parent 8650675f
1999-04-08 Jay Cox <jaycox@earthlink.net>
* app/Makefile.am: build color_cmds, lut_funcs, and pixel_processor
* app/app_procs.c: feedback in the splash screen when loading
parasites.
* app/boundary.c: Optimized find_empty_segs.
* app/brightness_contrast.[ch]
* app/levels.[ch]
* app/posterize.[ch]:
moved pdb and lut calculation code. These files now contain only
GUI functions.
* app/channel.c: Optimized channel_bounds (fewer compares, better
use of registers). Use color_region instead of channel_*_segment
in channel_combine_rect. Optimized channel_combine_ellipse by
skipping pixels inside of the ellipse. Use
pixel_region_process_parallel in channel_combine_mask. Use a
GimpLut in channel_invert, and channel_sharpen.
* app/invert.c
* app/equalize.c: moved the lut functions to lut_funcs.c
* app/gimpdrawable.c, app/gimpdrawableP.h
* app/gimpimage.c, app/gimpimageP.h: removed unused gimpmatrix
variables/includes.
* app/gimplut.[ch]: added new function gimp_lut_process_inline
that operates on a single PixelRegion.
* app/gimpparasite.[ch]: new functions to save/load parasiterc
* app/parasitelist.[ch]: new functions to save/load ParasiteLists
in/from files.
* libgimp/parasite.[ch]: new functions to load/save parasites.
* app/internal_procs.c: get some procs from new location in
color_cmds.h.
* app/pixel_region.[ch]: moved pixel_regions_process_parallel
related functions to a new file.
* app/color_cmds.[ch]: new files for PDB
definitions/implementations of color correction functions.
* app/lut_funcs.[ch]: new files to hold lut creation functions.
* app/pixel_processor.[ch]: new files that contain the
pixel_regions_process_parallel routines. Added some new
capabilities that are currently unused.
Fri Apr 9 01:52:23 MEST 1999 Sven Neumann <sven@gimp.org>
* plug-ins/autocrop/autocrop.c: Fixed a Bad Bug(TM).
......
......@@ -77,6 +77,8 @@ gimp_SOURCES = \
color_area.h \
color_balance.c \
color_balance.h \
color_cmds.c \
color_cmds.h \
color_notebook.c \
color_notebook.h \
color_panel.c \
......@@ -245,6 +247,8 @@ gimp_SOURCES = \
layers_dialogP.h \
levels.c \
levels.h \
lut_funcs.c \
lut_funcs.h \
magnify.c \
magnify.h \
main.c \
......@@ -288,6 +292,8 @@ gimp_SOURCES = \
pencil.h \
perspective_tool.c \
perspective_tool.h \
pixel_processor.c \
pixel_processor.h \
pixel_region.c \
pixel_region.h \
pixmaps.h \
......
......@@ -85,6 +85,7 @@
#include "color_notebook.h"
#include "color_select.h"
#include "gimpparasite.h"
#include "libgimp/gimpintl.h"
......@@ -535,15 +536,16 @@ app_init (void)
file_ops_pre_init (); /* pre-initialize the file types */
RESET_BAR();
xcf_init (); /* initialize the xcf file format routines */
gimp_init_parasites (); /* initialize the parasite table */
app_init_update_status (_("Looking for data files"), _("Brushes"), 0.00);
app_init_update_status (_("Looking for data files"), _("Parasites"), 0.00);
gimp_init_parasites (); /* initialize the global parasite table */
app_init_update_status (NULL, _("Brushes"), 0.20);
brushes_init (no_data); /* initialize the list of gimp brushes */
app_init_update_status (NULL, _("Patterns"), 0.25);
app_init_update_status (NULL, _("Patterns"), 0.40);
patterns_init (no_data); /* initialize the list of gimp patterns */
app_init_update_status (NULL, _("Palettes"), 0.50);
app_init_update_status (NULL, _("Palettes"), 0.60);
palettes_init (no_data); /* initialize the list of gimp palettes */
app_init_update_status (NULL, _("Gradients"), 0.75);
app_init_update_status (NULL, _("Gradients"), 0.80);
gradients_init (no_data); /* initialize the list of gimp gradients */
app_init_update_status (NULL, NULL, 1.00);
......@@ -635,6 +637,7 @@ app_exit_finish (void)
menus_quit ();
tile_swap_exit ();
save_unitrc ();
gimp_parasiterc_save ();
/* Things to do only if there is an interface */
if (no_interface == FALSE)
......
......@@ -83,6 +83,8 @@ find_empty_segs (PixelRegion *maskPR,
int val, last;
int tilex;
Tile *tile = NULL;
int endx, l_num_empty, dstep;
data = NULL;
start = 0;
......@@ -121,7 +123,9 @@ find_empty_segs (PixelRegion *maskPR,
empty_segs[(*num_empty)++] = 0;
last = -1;
for (x = start; x < end; x++)
l_num_empty = *num_empty;
for (x = start; x < end;)
{
/* Check to see if we must advance to next tile */
if ((x / TILE_WIDTH) != tilex)
......@@ -132,22 +136,46 @@ find_empty_segs (PixelRegion *maskPR,
data = (unsigned char*)tile_data_pointer (tile, x % TILE_WIDTH, scanline % TILE_HEIGHT) + (tile_bpp(tile) - 1);
tilex = x / TILE_WIDTH;
dstep = tile_bpp(tile);
}
endx = x + (TILE_WIDTH - (x%TILE_WIDTH));
endx = MINIMUM(end, endx);
if (type == IgnoreBounds && (endx > x1 || x < x2))
for (; x < endx; x++)
{
if (*data > HALF_WAY)
if (x >= x1 && x < x2)
val = -1;
else
val = 1;
else
val = -1;
empty_segs[*num_empty] = x;
val = (*data > HALF_WAY) ? 1 : -1;
data += dstep;
/* The IgnoreBounds case */
if (val == 1 && type == IgnoreBounds)
if (x >= x1 && x < x2)
val = -1;
if (last != val)
empty_segs[l_num_empty++] = x;
if (last * val < 0)
(*num_empty)++;
last = val;
last = val;
}
else
for (; x < endx; x++)
{
if (*data > HALF_WAY)
val = 1;
else
val = -1;
data += dstep;
if (last != val)
empty_segs[l_num_empty++] = x;
last = val;
}
data += tile_bpp(tile);
}
*num_empty = l_num_empty;
if (last > 0)
empty_segs[(*num_empty)++] = x;
......
......@@ -160,6 +160,79 @@ gimp_lut_process (GimpLut *lut,
}
}
void
gimp_lut_process_inline (GimpLut *lut,
PixelRegion *srcPR)
{
int h, width, src_r_i;
unsigned char *src;
unsigned char *lut0 = NULL, *lut1 = NULL, *lut2 = NULL, *lut3 = NULL;
if (lut->nchannels > 0)
lut0 = lut->luts[0];
if (lut->nchannels > 1)
lut1 = lut->luts[1];
if (lut->nchannels > 2)
lut2 = lut->luts[2];
if (lut->nchannels > 3)
lut3 = lut->luts[3];
h = srcPR->h;
src = srcPR->data;
width = srcPR->w;
src_r_i = srcPR->rowstride - (srcPR->bytes * srcPR->w);
if (src_r_i == 0)
{
width *= h;
h = 1;
}
while (h--)
{
switch (lut->nchannels)
{
case 1:
while (width--)
{
*src = lut0[*src];
src++;
}
break;
case 2:
while (width--)
{
src[0] = lut0[src[0]];
src[1] = lut1[src[1]];
src += 2;
}
break;
case 3:
while (width--)
{
src[0] = lut0[src[0]];
src[1] = lut1[src[1]];
src[2] = lut2[src[2]];
src += 3;
}
break;
case 4:
while (width--)
{
src[0] = lut0[src[0]];
src[1] = lut1[src[1]];
src[2] = lut2[src[2]];
src[3] = lut3[src[3]];
src += 4;
}
break;
default:
fprintf(stderr, "gimplut: Error: nchannels = %d\n", lut->nchannels);
}
width = srcPR->w;
src += src_r_i;
}
}
void
gimp_lut_process_2 (PixelRegion *srcPR,
PixelRegion *destPR,
......
......@@ -49,6 +49,11 @@ void gimp_lut_process (GimpLut *lut,
PixelRegion *srcPR,
PixelRegion *destPR);
/* gimp_lut_process_inline is like gimp_lut_process except it uses a
single PixelRegion as both the source and destination */
void gimp_lut_process_inline(GimpLut *lut,
PixelRegion *src_destPR);
/* gimp_lut_process_2 is the same as gimp_lut_process but the lut
perameter is last instead of first. this is necesary because
pixel_region_process_paralell sends the user_data as the 1st
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "gimplut.h"
#include "gimphistogram.h"
#include <stdio.h>
#include <math.h>
#include <glib.h>
/* ---------- Brightness/Contrast -----------*/
typedef struct B_C_struct
{
double brightness;
double contrast;
} B_C_struct;
static float
brightness_contrast_lut_func(B_C_struct *data,
int nchannels, int channel, float value)
{
float nvalue;
double power;
/* return the original value for the alpha channel */
if ((nchannels == 2 || nchannels == 4) && channel == nchannels -1)
return value;
/* apply brightness */
if (data->brightness < 0.0)
value = value * (1.0 + data->brightness);
else
value = value + ((1.0 - value) * data->brightness);
/* apply contrast */
if (data->contrast < 0.0)
{
if (value > 0.5)
nvalue = 1.0 - value;
else
nvalue = value;
if (nvalue < 0.0)
nvalue = 0.0;
nvalue = 0.5 * pow (nvalue * 2.0 , (double) (1.0 + data->contrast));
if (value > 0.5)
value = 1.0 - nvalue;
else
value = nvalue;
}
else
{
if (value > 0.5)
nvalue = 1.0 - value;
else
nvalue = value;
if (nvalue < 0.0)
nvalue = 0.0;
power = (data->contrast == 1.0) ? 127 : 1.0 / (1.0 - data->contrast);
nvalue = 0.5 * pow (2.0 * nvalue, power);
if (value > 0.5)
value = 1.0 - nvalue;
else
value = nvalue;
}
return value;
}
void
brightness_contrast_lut_setup(GimpLut *lut, double brightness, double contrast,
int nchannels)
{
B_C_struct data;
data.brightness = brightness;
data.contrast = contrast;
gimp_lut_setup(lut, (GimpLutFunc) brightness_contrast_lut_func,
(void *) &data, nchannels);
}
GimpLut *
brightness_contrast_lut_new(double brightness, double contrast,
int nchannels)
{
GimpLut *lut;
lut = gimp_lut_new();
brightness_contrast_lut_setup(lut, brightness, contrast, nchannels);
return lut;
}
/* ---------------- invert ------------------ */
static float
invert_lut_func(void *unused,
int nchannels, int channel, float value)
{
/* don't invert the alpha channel */
if ((nchannels == 2 || nchannels == 4) && channel == nchannels -1)
return value;
return 1.0 - value;
}
void
invert_lut_setup(GimpLut *lut, int nchannels)
{
gimp_lut_setup_exact(lut, (GimpLutFunc) invert_lut_func,
NULL , nchannels);
}
GimpLut *
invert_lut_new(int nchannels)
{
GimpLut *lut;
lut = gimp_lut_new();
invert_lut_setup(lut, nchannels);
return lut;
}
/* ---------------- add (or subract)------------------ */
static float
add_lut_func(double *ammount,
int nchannels, int channel, float value)
{
/* don't change the alpha channel */
if ((nchannels == 2 || nchannels == 4) && channel == nchannels -1)
return value;
return (value + *ammount);
}
void
add_lut_setup(GimpLut *lut, double ammount, int nchannels)
{
gimp_lut_setup(lut, (GimpLutFunc) add_lut_func,
(void *) &ammount , nchannels);
}
GimpLut *
add_lut_new(double ammount, int nchannels)
{
GimpLut *lut;
lut = gimp_lut_new();
add_lut_setup(lut, ammount, nchannels);
return lut;
}
/* ---------------- intersect (MINIMUM(pixel, value)) ------------------ */
static float
intersect_lut_func(double *min,
int nchannels, int channel, float value)
{
/* don't change the alpha channel */
if ((nchannels == 2 || nchannels == 4) && channel == nchannels -1)
return value;
return MIN(value, *min);
}
void
intersect_lut_setup(GimpLut *lut, double value, int nchannels)
{
gimp_lut_setup_exact(lut, (GimpLutFunc) intersect_lut_func,
(void *) &value , nchannels);
}
GimpLut *
intersect_lut_new(double value, int nchannels)
{
GimpLut *lut;
lut = gimp_lut_new();
intersect_lut_setup(lut, value, nchannels);
return lut;
}
/* ---------------- Threshold ------------------ */
static float
threshold_lut_func(double *min,
int nchannels, int channel, float value)
{
/* don't change the alpha channel */
if ((nchannels == 2 || nchannels == 4) && channel == nchannels -1)
return value;
if (value < *min)
return 0.0;
return 1.0;
}
void
threshold_lut_setup(GimpLut *lut, double value, int nchannels)
{
gimp_lut_setup_exact(lut, (GimpLutFunc) threshold_lut_func,
(void *) &value , nchannels);
}
GimpLut *
threshold_lut_new(double value, int nchannels)
{
GimpLut *lut;
lut = gimp_lut_new();
threshold_lut_setup(lut, value, nchannels);
return lut;
}
/* ------------- levels ------------ */
typedef struct
{
double *gamma;
int *low_input;
int *high_input;
int *low_output;
int *high_output;
} levels_struct;
static float
levels_lut_func(levels_struct *data,
int nchannels, int channel, float value)
{
double inten;
int j;
if (nchannels == 1)
j = 0;
else
j = channel + 1;
inten = value;
/* For color images this runs through the loop with j = channel +1
the first time and j = 0 the second time */
/* For bw images this runs through the loop with j = 0 the first and
only time */
for (; j >= 0; j -= (channel + 1))
{
/* don't apply the overall curve to the alpha channel */
if (j == 0 && (nchannels == 2 || nchannels == 4)
&& channel == nchannels -1)
return inten;
/* determine input intensity */
if (data->high_input[j] != data->low_input[j])
inten = (double) (255.0*inten - data->low_input[j]) /
(double) (data->high_input[j] - data->low_input[j]);
else
inten = (double) (255.0*inten - data->low_input[j]);
if (data->gamma[j] != 0.0)
{
if (inten >= 0.0)
inten = pow ( inten, (1.0 / data->gamma[j]));
else
inten = -pow (-inten, (1.0 / data->gamma[j]));
}
/* determine the output intensity */
if (data->high_output[j] >= data->low_output[j])
inten = (double) (inten * (data->high_output[j] - data->low_output[j]) +
data->low_output[j]);
else if (data->high_output[j] < data->low_output[j])
inten = (double) (data->low_output[j] - inten *
(data->low_output[j] - data->high_output[j]));
inten /= 255.0;
}
return inten;
}
void
levels_lut_setup(GimpLut *lut, double *gamma, int *low_input, int *high_input,
int *low_output, int *high_output, int nchannels)
{
levels_struct data;
data.gamma = gamma;
data.low_input = low_input;
data.high_input = high_input;
data.low_output = low_output;
data.high_output = high_output;
gimp_lut_setup(lut, (GimpLutFunc) levels_lut_func,
(void *) &data, nchannels);
}
GimpLut *
levels_lut_new(double *gamma, int *low_input, int *high_input,
int *low_output, int *high_output, int nchannels)
{
GimpLut *lut;
lut = gimp_lut_new();
levels_lut_setup(lut, gamma, low_input, high_input,
low_output, high_output, nchannels);
return lut;
}
/* --------------- posterize ---------------- */
static float
posterize_lut_func(int *ilevels,
int nchannels, int channel, float value)
{
int levels;
/* don't posterize the alpha channel */
if ((nchannels == 2 || nchannels == 4) && channel == nchannels -1)
return value;
if (*ilevels < 2)
levels = 2;
else
levels = *ilevels;
value = rint(value * (levels - 1.0)) / (levels - 1.0);
return value;
}
void
posterize_lut_setup(GimpLut *lut, int levels, int nchannels)
{
gimp_lut_setup_exact(lut, (GimpLutFunc) posterize_lut_func,
(void *) &levels , nchannels);
}
GimpLut *
posterize_lut_new(int levels, int nchannels)
{
GimpLut *lut;
lut = gimp_lut_new();
posterize_lut_setup(lut, levels, nchannels);
return lut;
}
/* --------------- equalize ------------- */
struct hist_lut_struct
{
GimpHistogram *histogram;
int part[5][257];
};
static float
equalize_lut_func(struct hist_lut_struct *hlut,
int nchannels, int channel, float value)
{
int i = 0, j;
j = (int)(value * 255.0 + 0.5);
while (hlut->part[channel][i + 1] <= j)
i++;
return i / 255.0;
}
void
eq_histogram_lut_setup (GimpLut *lut, GimpHistogram *hist, int bytes)
{
int i, k, j;
struct hist_lut_struct hlut;
double pixels_per_value;
double desired;
double sum, dif;
/* Find partition points */
pixels_per_value = gimp_histogram_get_count(hist, 0, 255) / 256.0;
for (k = 0; k < bytes; k++)
{
/* First and last points in partition */
hlut.part[k][0] = 0;
hlut.part[k][256] = 256;
/* Find intermediate points */
j = 0;
sum = gimp_histogram_get_channel(hist, k, 0) +
gimp_histogram_get_channel(hist, k, 1);
for (i = 1; i < 256; i++)
{
desired = i * pixels_per_value;
while (sum <= desired)
{
j++;
sum += gimp_histogram_get_channel(hist, k, j + 1);
}
/* Nearest sum */
dif = sum - gimp_histogram_get_channel(hist, k, j);
if ((sum - desired) > (dif / 2.0))
hlut.part[k][i] = j;
else
hlut.part[k][i] = j + 1;
}
}
gimp_lut_setup(lut, (GimpLutFunc) equalize_lut_func,
(void *) &hlut, bytes);
}
GimpLut *
eq_histogram_lut_new(GimpHistogram *h, int nchannels)
{
GimpLut *lut;
lut = gimp_lut_new();
eq_histogram_lut_setup(lut, h, nchannels);
return lut;
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
<