gimp/app/lut_funcs.c

426 lines
9.7 KiB
C
Raw Normal View History

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.
1999-04-09 14:00:11 +08:00
/* 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.
*/
Win32 portability changes: * config.h.win32, README.win32: Small changes. * tools/pdbgen/pdb/*.pdb: Include <string.h>. * app/*_cmds.c: Autogenerated files reflect above changes. * libgimp/makefile.msc app/makefile.msc: Various updates, including new object files. Gtk+ directory now should be called gtk+ (not gtk-plus). Use win32-specific gdk subdir. Glib directory now should be called just glib. * libgimp/gimp.def: Updates. * libgimp/gimpfeatures.h.win32: Made current with gimpfeatures.h.in. * libgimp/gimpfileselection.c: Define S_ISDIR and S_ISREG if necessary. * tools/pdbgen/pdb/fileops.pdb: Must have a statement (even an empty one) after a label. * app/fileops_cmds.c: Autogenerated file reflects above changes. * app/crop.c: Include <string.h>. * app/{app_procs,batch,fileops,datafiles,errorconsole,general, plug_in,temp_buf,tile_swap}.c: Test NATIVE_WIN32, not _MSC_VER. (NATIVE_WIN32 means we are using the Microsoft C runtime, even if we might be compiling with gcc.) * app/fileops.c: Don't include <process.h> here. * app/fileops.h: Do include <process.h> here. * app/gimpparasite.c: Include config.h, guard inclusion of <unistd.h>. (Is the inclusion of unistd.h in source files all over the place really necessary?) * app/ink.c: MSC doesn't handle conversion from unsigned __int64 to double, so cast to signed. * app/lut_funcs.c: Include config.h, and define rint() if necessary. * app/pixel_processor.c: Include config.h without "..", like in all the other places. Include <string.h> * app/text_tool.c: Guard the "POINTS" identifier that clashes with <windows.h>, sigh.
1999-05-05 05:32:17 +08:00
#include "config.h"
#include <stdio.h>
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.
1999-04-09 14:00:11 +08:00
#include <glib.h>
#include "libgimpmath/gimpmath.h"
#include "apptypes.h"
#include "gimplut.h"
#include "gimphistogram.h"
Win32 portability changes: * config.h.win32, README.win32: Small changes. * tools/pdbgen/pdb/*.pdb: Include <string.h>. * app/*_cmds.c: Autogenerated files reflect above changes. * libgimp/makefile.msc app/makefile.msc: Various updates, including new object files. Gtk+ directory now should be called gtk+ (not gtk-plus). Use win32-specific gdk subdir. Glib directory now should be called just glib. * libgimp/gimp.def: Updates. * libgimp/gimpfeatures.h.win32: Made current with gimpfeatures.h.in. * libgimp/gimpfileselection.c: Define S_ISDIR and S_ISREG if necessary. * tools/pdbgen/pdb/fileops.pdb: Must have a statement (even an empty one) after a label. * app/fileops_cmds.c: Autogenerated file reflects above changes. * app/crop.c: Include <string.h>. * app/{app_procs,batch,fileops,datafiles,errorconsole,general, plug_in,temp_buf,tile_swap}.c: Test NATIVE_WIN32, not _MSC_VER. (NATIVE_WIN32 means we are using the Microsoft C runtime, even if we might be compiling with gcc.) * app/fileops.c: Don't include <process.h> here. * app/fileops.h: Do include <process.h> here. * app/gimpparasite.c: Include config.h, guard inclusion of <unistd.h>. (Is the inclusion of unistd.h in source files all over the place really necessary?) * app/ink.c: MSC doesn't handle conversion from unsigned __int64 to double, so cast to signed. * app/lut_funcs.c: Include config.h, and define rint() if necessary. * app/pixel_processor.c: Include config.h without "..", like in all the other places. Include <string.h> * app/text_tool.c: Guard the "POINTS" identifier that clashes with <windows.h>, sigh.
1999-05-05 05:32:17 +08:00
app/Makefile.am app/channel_pvt.h app/drawable_pvt.h app/gdisplayF.h 2000-12-29 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/channel_pvt.h * app/drawable_pvt.h * app/gdisplayF.h * app/gimpdrawableP.h * app/gimpimageP.h * app/layer_pvt.h * app/toolsF.h: removed these files. * app/apptypes.h * tools/pdbgen/enums.pl: added tons of opaque typedefs and enums. * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/color.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/display.pdb * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/help.pdb * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/layer.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb * tools/pdbgen/pdb/selection.pdb * tools/pdbgen/pdb/tools.pdb * app/*: chainsaw #include cleanup: - Never (never!!) include stuff in header files except where we need access to structures' contents (like derived objects). - Added prototypes and proper formating in many files. - The #include order in *all* *.c files is as follows: #include "config.h" #include <system stuff> #include <gtk/gtk.h> #include "apptypes.h" #include "gimp stuff" #include "libgimp stuff" #include "libgimp/gimpintl.h" By following this scheme we can easily see a file's dependencies from it's #include's and can grep for the inclusion to find out where a file is used. * tools/pdbgen/app.pl: changed to follow the include scheme above. * libgimp/Makefile.am * libgimp/gimpuitypes.h: new file, included from libgimp/gimpui.h and from app/apptypes.h. * libgimp/gimpcolorbutton.[ch] * libgimp/gimpdialog.[ch] * libgimp/gimphelpui.[ch] * libgimp/gimpparasite.[ch] * libgimp/gimppatheditor.[ch] * libgimp/gimpprotocol.c * libgimp/gimpquerybox.[ch] * libgimp/gimpsizeentry.[ch] * libgimp/gimptypes.h * libgimp/gimpui.h * libgimp/gimpunit.h * libgimp/gimpunitmenu.[ch] * libgimp/gimpwidgets.[ch]: changed accordingly. * plug-ins/FractalExplorer/Dialogs.c * plug-ins/gdyntext/message_window.c * plug-ins/imagemap/imap_default_dialog.c * plug-ins/imagemap/imap_file.c: these files used to include "libgimp/gimpui.h" without including "libgimp/gimp.h". This is no longer possible because the libgimpui headers don't inlcude "libgimp/gimpunit.h" any more.
2000-12-29 23:22:01 +08:00
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.
1999-04-09 14:00:11 +08:00
/* ---------- 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 (MIN (pixel, value)) ------------------ */
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.
1999-04-09 14:00:11 +08:00
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);
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.
1999-04-09 14:00:11 +08:00
}
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);
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.
1999-04-09 14:00:11 +08:00
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;
}