app: remove the legacy color-balance cruft

This commit is contained in:
Michael Natterer 2012-03-27 21:56:29 +02:00
parent 1f7cf2dd6b
commit 2c0fde88f2
13 changed files with 46 additions and 442 deletions

View File

@ -22,8 +22,6 @@ libappbase_a_SOURCES = \
base-types.h \
base-utils.c \
base-utils.h \
color-balance.c \
color-balance.h \
cpercep.c \
cpercep.h \
gimplut.c \

View File

@ -49,7 +49,6 @@
typedef struct _GimpLut GimpLut;
typedef struct _ColorBalance ColorBalance;
typedef struct _HueSaturation HueSaturation;
typedef struct _PixelRegionIterator PixelRegionIterator;

View File

@ -1,181 +0,0 @@
/* GIMP - The GNU 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <cairo.h>
#include <glib-object.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
#include "base-types.h"
#include "color-balance.h"
#include "pixel-region.h"
/* local function prototypes */
static void color_balance_transfer_init (void);
/* private variables */
static gboolean transfer_initialized = FALSE;
static gdouble highlights[256] = { 0 };
static gdouble midtones[256] = { 0 };
static gdouble shadows[256] = { 0 };
/* public functions */
void
color_balance_init (ColorBalance *cb)
{
GimpTransferMode range;
g_return_if_fail (cb != NULL);
for (range = GIMP_SHADOWS; range <= GIMP_HIGHLIGHTS; range++)
{
cb->cyan_red[range] = 0.0;
cb->magenta_green[range] = 0.0;
cb->yellow_blue[range] = 0.0;
}
cb->preserve_luminosity = TRUE;
}
void
color_balance_create_lookup_tables (ColorBalance *cb)
{
gint i;
gint32 r_n, g_n, b_n;
g_return_if_fail (cb != NULL);
if (! transfer_initialized)
{
color_balance_transfer_init ();
transfer_initialized = TRUE;
}
for (i = 0; i < 256; i++)
{
r_n = i;
g_n = i;
b_n = i;
r_n += cb->cyan_red[GIMP_SHADOWS] * shadows[i];
r_n += cb->cyan_red[GIMP_MIDTONES] * midtones[i];
r_n += cb->cyan_red[GIMP_HIGHLIGHTS] * highlights[i];
r_n = CLAMP0255 (r_n);
g_n += cb->magenta_green[GIMP_SHADOWS] * shadows[i];
g_n += cb->magenta_green[GIMP_MIDTONES] * midtones[i];
g_n += cb->magenta_green[GIMP_HIGHLIGHTS] * highlights[i];
g_n = CLAMP0255 (g_n);
b_n += cb->yellow_blue[GIMP_SHADOWS] * shadows[i];
b_n += cb->yellow_blue[GIMP_MIDTONES] * midtones[i];
b_n += cb->yellow_blue[GIMP_HIGHLIGHTS] * highlights[i];
b_n = CLAMP0255 (b_n);
cb->r_lookup[i] = r_n;
cb->g_lookup[i] = g_n;
cb->b_lookup[i] = b_n;
}
}
void
color_balance (ColorBalance *cb,
PixelRegion *srcPR,
PixelRegion *destPR)
{
const guchar *src, *s;
guchar *dest, *d;
gboolean alpha;
gint r, g, b;
gint r_n, g_n, b_n;
gint w, h;
h = srcPR->h;
src = srcPR->data;
dest = destPR->data;
alpha = pixel_region_has_alpha (srcPR);
while (h--)
{
w = srcPR->w;
s = src;
d = dest;
while (w--)
{
r = s[RED];
g = s[GREEN];
b = s[BLUE];
r_n = cb->r_lookup[r];
g_n = cb->g_lookup[g];
b_n = cb->b_lookup[b];
if (cb->preserve_luminosity)
{
gimp_rgb_to_hsl_int (&r_n, &g_n, &b_n);
b_n = gimp_rgb_to_l_int (r, g, b);
gimp_hsl_to_rgb_int (&r_n, &g_n, &b_n);
}
d[RED] = r_n;
d[GREEN] = g_n;
d[BLUE] = b_n;
if (alpha)
d[ALPHA] = s[ALPHA];
s += srcPR->bytes;
d += destPR->bytes;
}
src += srcPR->rowstride;
dest += destPR->rowstride;
}
}
/* private functions */
static void
color_balance_transfer_init (void)
{
gint i;
for (i = 0; i < 256; i++)
{
static const gdouble a = 64, b = 85, scale = 1.785;
gdouble low = CLAMP ((i - b) / -a + .5, 0, 1) * scale;
gdouble mid = CLAMP ((i - b) / a + .5, 0, 1) *
CLAMP ((i + b - 255) / -a + .5, 0, 1) * scale;
shadows[i] = low;
midtones[i] = mid;
highlights[255 - i] = low;
}
}

View File

@ -1,43 +0,0 @@
/* GIMP - The GNU 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef __COLOR_BALANCE_H__
#define __COLOR_BALANCE_H__
struct _ColorBalance
{
gboolean preserve_luminosity;
gdouble cyan_red[3];
gdouble magenta_green[3];
gdouble yellow_blue[3];
guchar r_lookup[256];
guchar g_lookup[256];
guchar b_lookup[256];
};
void color_balance_init (ColorBalance *cb);
void color_balance_create_lookup_tables (ColorBalance *cb);
void color_balance (ColorBalance *cb,
PixelRegion *srcPR,
PixelRegion *destPR);
#endif /* __COLOR_BALANCE_H__ */

View File

@ -126,8 +126,6 @@ libappcore_a_sources = \
gimpdrawable-blend.h \
gimpdrawable-bucket-fill.c \
gimpdrawable-bucket-fill.h \
gimpdrawable-color-balance.c \
gimpdrawable-color-balance.h \
gimpdrawable-combine.c \
gimpdrawable-combine.h \
gimpdrawable-convert.c \

View File

@ -1,95 +0,0 @@
/* GIMP - The GNU 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include "core-types.h"
#include "base/color-balance.h"
#include "gegl/gimpcolorbalanceconfig.h"
/* temp */
#include "gimp.h"
#include "gimpimage.h"
#include "gimpdrawable.h"
#include "gimpdrawable-color-balance.h"
#include "gimpdrawable-operation.h"
#include "gimpdrawable-process.h"
#include "gimp-intl.h"
/* public functions */
void
gimp_drawable_color_balance (GimpDrawable *drawable,
GimpProgress *progress,
GimpTransferMode range,
gdouble cyan_red,
gdouble magenta_green,
gdouble yellow_blue,
gboolean preserve_luminosity)
{
GimpColorBalanceConfig *config;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (! gimp_drawable_is_indexed (drawable));
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
config = g_object_new (GIMP_TYPE_COLOR_BALANCE_CONFIG,
"range", range,
"preserve-luminosity", preserve_luminosity,
NULL);
g_object_set (config,
"cyan-red", cyan_red / 100.0,
"magenta-green", magenta_green / 100.0,
"yellow-blue", yellow_blue / 100.0,
NULL);
if (gimp_use_gegl (gimp_item_get_image (GIMP_ITEM (drawable))->gimp))
{
GeglNode *node;
node = g_object_new (GEGL_TYPE_NODE,
"operation", "gimp:color-balance",
NULL);
gegl_node_set (node,
"config", config,
NULL);
gimp_drawable_apply_operation (drawable, progress,
C_("undo-type", "Color Balance"),
node);
g_object_unref (node);
}
else
{
ColorBalance cruft;
gimp_color_balance_config_to_cruft (config, &cruft);
gimp_drawable_process (drawable, progress, C_("undo-type", "Color Balance"),
(PixelProcessorFunc) color_balance, &cruft);
}
g_object_unref (config);
}

View File

@ -1,31 +0,0 @@
/* GIMP - The GNU 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_DRAWABLE_COLOR_BALANCE_H__
#define __GIMP_DRAWABLE_COLOR_BALANCE_H__
void gimp_drawable_color_balance (GimpDrawable *drawable,
GimpProgress *progress,
GimpTransferMode range,
gdouble cyan_red,
gdouble magenta_green,
gdouble yellow_blue,
gboolean preserve_luminosity);
#endif /* __GIMP_DRAWABLE_COLOR_BALANCE_H__ */

View File

@ -29,9 +29,6 @@
#include "gimp-gegl-types.h"
/* temp cruft */
#include "base/color-balance.h"
#include "gimpcolorbalanceconfig.h"
@ -359,27 +356,3 @@ gimp_color_balance_config_reset_range (GimpColorBalanceConfig *config)
g_object_thaw_notify (G_OBJECT (config));
}
/* temp cruft */
void
gimp_color_balance_config_to_cruft (GimpColorBalanceConfig *config,
ColorBalance *cruft)
{
GimpTransferMode range;
g_return_if_fail (GIMP_IS_COLOR_BALANCE_CONFIG (config));
g_return_if_fail (cruft != NULL);
for (range = GIMP_SHADOWS; range <= GIMP_HIGHLIGHTS; range++)
{
cruft->cyan_red[range] = config->cyan_red[range] * 100.0;
cruft->magenta_green[range] = config->magenta_green[range] * 100.0;
cruft->yellow_blue[range] = config->yellow_blue[range] * 100.0;
}
cruft->preserve_luminosity = config->preserve_luminosity;
color_balance_create_lookup_tables (cruft);
}

View File

@ -58,9 +58,5 @@ GType gimp_color_balance_config_get_type (void) G_GNUC_CONST;
void gimp_color_balance_config_reset_range (GimpColorBalanceConfig *config);
/* temp cruft */
void gimp_color_balance_config_to_cruft (GimpColorBalanceConfig *config,
ColorBalance *cruft);
#endif /* __GIMP_COLOR_BALANCE_CONFIG_H__ */

View File

@ -23,7 +23,6 @@
#include "pdb-types.h"
#include "core/gimpdrawable-color-balance.h"
#include "core/gimpdrawable-equalize.h"
#include "core/gimpdrawable-histogram.h"
#include "core/gimpdrawable-hue-saturation.h"
@ -33,6 +32,7 @@
#include "core/gimphistogram.h"
#include "core/gimpparamspecs.h"
#include "gegl/gimpbrightnesscontrastconfig.h"
#include "gegl/gimpcolorbalanceconfig.h"
#include "gegl/gimpcolorizeconfig.h"
#include "gegl/gimpcurvesconfig.h"
#include "gegl/gimpdesaturateconfig.h"
@ -504,16 +504,29 @@ color_balance_invoker (GimpProcedure *procedure,
if (success)
{
if (! gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) ||
! gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) ||
gimp_drawable_is_indexed (drawable))
success = FALSE;
if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
GObject *config = g_object_new (GIMP_TYPE_COLORIZE_CONFIG,
"range", transfer_mode,
"preserve-luminosity", preserve_lum,
NULL);
if (success)
gimp_drawable_color_balance (drawable, progress,
transfer_mode,
cyan_red, magenta_green, yellow_blue,
preserve_lum);
g_object_set (config,
"cyan-red", cyan_red / 100.0,
"magenta-green", magenta_green / 100.0,
"yellow-blue", yellow_blue / 100.0,
NULL);
gimp_drawable_apply_operation_by_name (drawable, progress,
C_("undo-type", "Color Balance"),
"gimp:color-balance",
config);
g_object_unref (config);
}
else
success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,

View File

@ -27,8 +27,6 @@
#include "tools-types.h"
#include "base/color-balance.h"
#include "gegl/gimpcolorbalanceconfig.h"
#include "core/gimpdrawable.h"
@ -47,15 +45,12 @@
/* local function prototypes */
static void gimp_color_balance_tool_finalize (GObject *object);
static gboolean gimp_color_balance_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error);
static GeglNode * gimp_color_balance_tool_get_operation (GimpImageMapTool *im_tool,
GObject **config);
static void gimp_color_balance_tool_map (GimpImageMapTool *im_tool);
static void gimp_color_balance_tool_dialog (GimpImageMapTool *im_tool);
static void gimp_color_balance_tool_reset (GimpImageMapTool *im_tool);
@ -102,12 +97,9 @@ gimp_color_balance_tool_register (GimpToolRegisterCallback callback,
static void
gimp_color_balance_tool_class_init (GimpColorBalanceToolClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
GimpImageMapToolClass *im_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
object_class->finalize = gimp_color_balance_tool_finalize;
tool_class->initialize = gimp_color_balance_tool_initialize;
im_tool_class->dialog_desc = _("Adjust Color Balance");
@ -116,7 +108,6 @@ gimp_color_balance_tool_class_init (GimpColorBalanceToolClass *klass)
im_tool_class->export_dialog_title = _("Export Color Balance Settings");
im_tool_class->get_operation = gimp_color_balance_tool_get_operation;
im_tool_class->map = gimp_color_balance_tool_map;
im_tool_class->dialog = gimp_color_balance_tool_dialog;
im_tool_class->reset = gimp_color_balance_tool_reset;
}
@ -124,24 +115,6 @@ gimp_color_balance_tool_class_init (GimpColorBalanceToolClass *klass)
static void
gimp_color_balance_tool_init (GimpColorBalanceTool *cb_tool)
{
GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (cb_tool);
cb_tool->color_balance = g_slice_new0 (ColorBalance);
color_balance_init (cb_tool->color_balance);
im_tool->apply_func = (GimpImageMapApplyFunc) color_balance;
im_tool->apply_data = cb_tool->color_balance;
}
static void
gimp_color_balance_tool_finalize (GObject *object)
{
GimpColorBalanceTool *cb_tool = GIMP_COLOR_BALANCE_TOOL (object);
g_slice_free (ColorBalance, cb_tool->color_balance);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gboolean
@ -194,14 +167,6 @@ gimp_color_balance_tool_get_operation (GimpImageMapTool *im_tool,
return node;
}
static void
gimp_color_balance_tool_map (GimpImageMapTool *image_map_tool)
{
GimpColorBalanceTool *cb_tool = GIMP_COLOR_BALANCE_TOOL (image_map_tool);
gimp_color_balance_config_to_cruft (cb_tool->config, cb_tool->color_balance);
}
/**************************/
/* Color Balance dialog */

View File

@ -39,7 +39,6 @@ struct _GimpColorBalanceTool
GimpImageMapTool parent_instance;
GimpColorBalanceConfig *config;
ColorBalance *color_balance;
/* dialog */
GtkWidget *range_radio;

View File

@ -540,19 +540,32 @@ HELP
);
%invoke = (
headers => [ qw("core/gimpdrawable-color-balance.h") ],
headers => [ qw("gegl/gimpcolorbalanceconfig.h") ],
code => <<'CODE'
{
if (! gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) ||
! gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) ||
gimp_drawable_is_indexed (drawable))
success = FALSE;
if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
GObject *config = g_object_new (GIMP_TYPE_COLORIZE_CONFIG,
"range", transfer_mode,
"preserve-luminosity", preserve_lum,
NULL);
if (success)
gimp_drawable_color_balance (drawable, progress,
transfer_mode,
cyan_red, magenta_green, yellow_blue,
preserve_lum);
g_object_set (config,
"cyan-red", cyan_red / 100.0,
"magenta-green", magenta_green / 100.0,
"yellow-blue", yellow_blue / 100.0,
NULL);
gimp_drawable_apply_operation_by_name (drawable, progress,
C_("undo-type", "Color Balance"),
"gimp:color-balance",
config);
g_object_unref (config);
}
else
success = FALSE;
}
CODE
);