app: remove the lagacy hue-saturation cruft

it's unclear whether the operation is correct, but that can be sorted
out on master and merged.
This commit is contained in:
Michael Natterer
2012-03-29 02:35:56 +02:00
parent 8008b75411
commit f248324fd3
13 changed files with 42 additions and 484 deletions

View File

@ -26,8 +26,6 @@ libappbase_a_SOURCES = \
cpercep.h \
gimplut.c \
gimplut.h \
hue-saturation.c \
hue-saturation.h \
pixel-processor.c \
pixel-processor.h \
pixel-region.c \

View File

@ -49,8 +49,6 @@
typedef struct _GimpLut GimpLut;
typedef struct _HueSaturation HueSaturation;
typedef struct _PixelRegionIterator PixelRegionIterator;
typedef struct _PixelRegion PixelRegion;
typedef struct _PixelRegionHolder PixelRegionHolder;

View File

@ -1,211 +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 "hue-saturation.h"
#include "pixel-region.h"
void
hue_saturation_init (HueSaturation *hs)
{
GimpHueRange partition;
g_return_if_fail (hs != NULL);
hs->overlap = 0.0;
for (partition = GIMP_ALL_HUES; partition <= GIMP_MAGENTA_HUES; partition++)
{
hs->hue[partition] = 0.0;
hs->lightness[partition] = 0.0;
hs->saturation[partition] = 0.0;
}
}
void
hue_saturation_calculate_transfers (HueSaturation *hs)
{
gint value;
gint hue;
gint i;
g_return_if_fail (hs != NULL);
/* Calculate transfers */
for (hue = 0; hue < 6; hue++)
for (i = 0; i < 256; i++)
{
/* Hue */
value = (hs->hue[0] + hs->hue[hue + 1]) * 255.0 / 360.0;
if ((i + value) < 0)
hs->hue_transfer[hue][i] = 255 + (i + value);
else if ((i + value) > 255)
hs->hue_transfer[hue][i] = i + value - 255;
else
hs->hue_transfer[hue][i] = i + value;
/* Lightness */
value = (hs->lightness[0] + hs->lightness[hue + 1]) * 127.0 / 100.0;
value = CLAMP (value, -255, 255);
if (value < 0)
hs->lightness_transfer[hue][i] = (guchar) ((i * (255 + value)) / 255);
else
hs->lightness_transfer[hue][i] = (guchar) (i + ((255 - i) * value) / 255);
/* Saturation */
value = (hs->saturation[0] + hs->saturation[hue + 1]) * 255.0 / 100.0;
value = CLAMP (value, -255, 255);
/* This change affects the way saturation is computed. With the
old code (different code for value < 0), increasing the
saturation affected muted colors very much, and bright colors
less. With the new code, it affects muted colors and bright
colors more or less evenly. For enhancing the color in photos,
the new behavior is exactly what you want. It's hard for me
to imagine a case in which the old behavior is better.
*/
hs->saturation_transfer[hue][i] = CLAMP ((i * (255 + value)) / 255, 0, 255);
}
}
void
hue_saturation (HueSaturation *hs,
PixelRegion *srcPR,
PixelRegion *destPR)
{
const guchar *src, *s;
guchar *dest, *d;
const gint hue_thresholds[] = { 21, 64, 106, 149, 192, 234, 255 };
gint alpha;
gint w, h;
gint r, g, b;
gint hue;
gint hue_counter;
gint secondary_hue = 0;
gboolean use_secondary_hue = FALSE;
gfloat primary_intensity = 0.0;
gfloat secondary_intensity = 0.0;
gfloat overlap_hue = (hs->overlap / 100.0) * 21;
/* Set the transfer arrays (for speed) */
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];
gimp_rgb_to_hsl_int (&r, &g, &b);
hue = (r + (128 / 6)) / 6;
for (hue_counter = 0; hue_counter < 7; hue_counter++)
if (r < hue_thresholds[hue_counter] + overlap_hue)
{
gint hue_threshold = hue_thresholds[hue_counter];
hue = hue_counter;
if (overlap_hue > 1.0 && r > hue_threshold - overlap_hue)
{
secondary_hue = hue_counter + 1;
use_secondary_hue = TRUE;
secondary_intensity =
(r - hue_threshold + overlap_hue) / (2.0 * overlap_hue);
primary_intensity = 1.0 - secondary_intensity;
}
else
{
use_secondary_hue = FALSE;
}
break;
}
if (hue >= 6)
{
hue = 0;
use_secondary_hue = FALSE;
}
if (secondary_hue >= 6)
secondary_hue = 0;
if (use_secondary_hue)
{
/* find nearest hue on the circle
* between primary and secondary hue
*/
gint diff;
diff = hs->hue_transfer[hue][r] - hs->hue_transfer[secondary_hue][r];
if (diff < -127 || diff >= 128)
r = (gint) (hs->hue_transfer[hue][r] * primary_intensity +
(hs->hue_transfer[secondary_hue][r] + 255) * secondary_intensity) % 255;
else
r = hs->hue_transfer[hue][r] * primary_intensity +
hs->hue_transfer[secondary_hue][r] * secondary_intensity;
g = hs->saturation_transfer[hue][g] * primary_intensity +
hs->saturation_transfer[secondary_hue][g] * secondary_intensity;
b = hs->lightness_transfer[hue][b] * primary_intensity +
hs->lightness_transfer[secondary_hue][b] * secondary_intensity;
}
else
{
r = hs->hue_transfer[hue][r];
g = hs->saturation_transfer[hue][g];
b = hs->lightness_transfer[hue][b];
}
gimp_hsl_to_rgb_int (&r, &g, &b);
d[RED] = r;
d[GREEN] = g;
d[BLUE] = b;
if (alpha)
d[ALPHA] = s[ALPHA];
s += srcPR->bytes;
d += destPR->bytes;
}
src += srcPR->rowstride;
dest += destPR->rowstride;
}
}

View File

@ -1,42 +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 __HUE_SATURATION_H__
#define __HUE_SATURATION_H__
struct _HueSaturation
{
gdouble hue[7];
gdouble lightness[7];
gdouble saturation[7];
gdouble overlap;
gint hue_transfer[6][256];
gint lightness_transfer[6][256];
gint saturation_transfer[6][256];
};
void hue_saturation_init (HueSaturation *hs);
void hue_saturation_calculate_transfers (HueSaturation *hs);
void hue_saturation (HueSaturation *hs,
PixelRegion *srcPR,
PixelRegion *destPR);
#endif /* __HUE_SATURATION_H__ */

View File

@ -136,8 +136,6 @@ libappcore_a_sources = \
gimpdrawable-foreground-extract.h \
gimpdrawable-histogram.c \
gimpdrawable-histogram.h \
gimpdrawable-hue-saturation.c \
gimpdrawable-hue-saturation.h \
gimpdrawable-levels.c \
gimpdrawable-levels.h \
gimpdrawable-offset.c \

View File

@ -1,92 +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/hue-saturation.h"
#include "gegl/gimphuesaturationconfig.h"
/* temp */
#include "gimp.h"
#include "gimpimage.h"
#include "gimpdrawable.h"
#include "gimpdrawable-hue-saturation.h"
#include "gimpdrawable-operation.h"
#include "gimpdrawable-process.h"
#include "gimp-intl.h"
/* public functions */
void
gimp_drawable_hue_saturation (GimpDrawable *drawable,
GimpProgress *progress,
GimpHueRange range,
gdouble hue,
gdouble saturation,
gdouble lightness)
{
GimpHueSaturationConfig *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_HUE_SATURATION_CONFIG,
"range", range,
NULL);
g_object_set (config,
"hue", hue / 180.0,
"saturation", saturation / 100.0,
"lightness", lightness / 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:hue-saturation",
NULL);
gegl_node_set (node,
"config", config,
NULL);
gimp_drawable_apply_operation (drawable, progress, _("Hue-Saturation"),
node);
g_object_unref (node);
}
else
{
HueSaturation cruft;
gimp_hue_saturation_config_to_cruft (config, &cruft);
gimp_drawable_process (drawable, progress, _("Hue_Saturation"),
(PixelProcessorFunc) hue_saturation, &cruft);
}
g_object_unref (config);
}

View File

@ -1,30 +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_HUE_SATURATION_H__
#define __GIMP_DRAWABLE_HUE_SATURATION_H__
void gimp_drawable_hue_saturation (GimpDrawable *drawable,
GimpProgress *progress,
GimpHueRange range,
gdouble hue,
gdouble saturation,
gdouble lightness);
#endif /* __GIMP_DRAWABLE_HUE_SATURATION_H__ */

View File

@ -27,9 +27,6 @@
#include "gimp-gegl-types.h"
/* temp cruft */
#include "base/hue-saturation.h"
#include "gimphuesaturationconfig.h"
@ -352,27 +349,3 @@ gimp_hue_saturation_config_reset_range (GimpHueSaturationConfig *config)
g_object_thaw_notify (G_OBJECT (config));
}
/* temp cruft */
void
gimp_hue_saturation_config_to_cruft (GimpHueSaturationConfig *config,
HueSaturation *cruft)
{
GimpHueRange range;
g_return_if_fail (GIMP_IS_HUE_SATURATION_CONFIG (config));
g_return_if_fail (cruft != NULL);
for (range = GIMP_ALL_HUES; range <= GIMP_MAGENTA_HUES; range++)
{
cruft->hue[range] = config->hue[range] * 180;
cruft->saturation[range] = config->saturation[range] * 100;
cruft->lightness[range] = config->lightness[range] * 100;
}
cruft->overlap = config->overlap * 100;
hue_saturation_calculate_transfers (cruft);
}

View File

@ -58,9 +58,5 @@ GType gimp_hue_saturation_config_get_type (void) G_GNUC_CONST;
void gimp_hue_saturation_config_reset_range (GimpHueSaturationConfig *config);
/* temp cruft */
void gimp_hue_saturation_config_to_cruft (GimpHueSaturationConfig *config,
HueSaturation *cruft);
#endif /* __GIMP_HUE_SATURATION_CONFIG_H__ */

View File

@ -25,7 +25,6 @@
#include "core/gimpdrawable-equalize.h"
#include "core/gimpdrawable-histogram.h"
#include "core/gimpdrawable-hue-saturation.h"
#include "core/gimpdrawable-levels.h"
#include "core/gimpdrawable-operation.h"
#include "core/gimpdrawable.h"
@ -36,6 +35,7 @@
#include "gegl/gimpcolorizeconfig.h"
#include "gegl/gimpcurvesconfig.h"
#include "gegl/gimpdesaturateconfig.h"
#include "gegl/gimphuesaturationconfig.h"
#include "gegl/gimplevelsconfig.h"
#include "gegl/gimpposterizeconfig.h"
#include "gegl/gimpthresholdconfig.h"
@ -79,7 +79,6 @@ brightness_contrast_invoker (GimpProcedure *procedure,
C_("undo-type", "Brightness-Contrast"),
"gimp:brightness-contrast",
config);
g_object_unref (config);
}
else
@ -139,7 +138,6 @@ levels_invoker (GimpProcedure *procedure,
C_("undo-type", "Levels"),
"gimp:levels",
config);
g_object_unref (config);
}
else
@ -234,7 +232,6 @@ posterize_invoker (GimpProcedure *procedure,
_("Posterize"),
"gimp:posterize",
config);
g_object_unref (config);
}
else
@ -272,7 +269,6 @@ desaturate_invoker (GimpProcedure *procedure,
_("Desaturate"),
"gimp:desaturate",
config);
g_object_unref (config);
}
else
@ -312,7 +308,6 @@ desaturate_full_invoker (GimpProcedure *procedure,
_("Desaturate"),
"gimp:desaturate",
config);
g_object_unref (config);
}
else
@ -421,7 +416,6 @@ curves_spline_invoker (GimpProcedure *procedure,
C_("undo-type", "Curves"),
"gimp:curves",
config);
g_object_unref (config);
}
else
@ -468,7 +462,6 @@ curves_explicit_invoker (GimpProcedure *procedure,
C_("undo-type", "Curves"),
"gimp:curves",
config);
g_object_unref (config);
}
else
@ -522,7 +515,6 @@ color_balance_invoker (GimpProcedure *procedure,
C_("undo-type", "Color Balance"),
"gimp:color-balance",
config);
g_object_unref (config);
}
else
@ -568,7 +560,6 @@ colorize_invoker (GimpProcedure *procedure,
C_("undo-type", "Colorize"),
"gimp:colorize",
config);
g_object_unref (config);
}
else
@ -675,14 +666,27 @@ hue_saturation_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_HUE_SATURATION_CONFIG,
"range", hue_range,
NULL);
if (success)
gimp_drawable_hue_saturation (drawable, progress,
hue_range, hue_offset, saturation, lightness);
g_object_set (config,
"hue", hue_offset / 180.0,
"saturation", saturation / 100.0,
"lightness", lightness / 100.0,
NULL);
gimp_drawable_apply_operation_by_name (drawable, progress,
_("Hue-Saturation"),
"gimp:hue-saturation",
config);
g_object_unref (config);
}
else
success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,
@ -720,7 +724,6 @@ threshold_invoker (GimpProcedure *procedure,
_("Threshold"),
"gimp:threshold",
config);
g_object_unref (config);
}
else

View File

@ -27,8 +27,6 @@
#include "tools-types.h"
#include "base/hue-saturation.h"
#include "gegl/gimphuesaturationconfig.h"
#include "gegl/gimpoperationhuesaturation.h"
@ -53,15 +51,12 @@
/* local function prototypes */
static void gimp_hue_saturation_tool_finalize (GObject *object);
static gboolean gimp_hue_saturation_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error);
static GeglNode * gimp_hue_saturation_tool_get_operation (GimpImageMapTool *im_tool,
GObject **config);
static void gimp_hue_saturation_tool_map (GimpImageMapTool *im_tool);
static void gimp_hue_saturation_tool_dialog (GimpImageMapTool *im_tool);
static void gimp_hue_saturation_tool_reset (GimpImageMapTool *im_tool);
@ -110,12 +105,9 @@ gimp_hue_saturation_tool_register (GimpToolRegisterCallback callback,
static void
gimp_hue_saturation_tool_class_init (GimpHueSaturationToolClass *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_hue_saturation_tool_finalize;
tool_class->initialize = gimp_hue_saturation_tool_initialize;
im_tool_class->dialog_desc = _("Adjust Hue / Lightness / Saturation");
@ -124,7 +116,6 @@ gimp_hue_saturation_tool_class_init (GimpHueSaturationToolClass *klass)
im_tool_class->export_dialog_title = _("Export Hue-Saturation Settings");
im_tool_class->get_operation = gimp_hue_saturation_tool_get_operation;
im_tool_class->map = gimp_hue_saturation_tool_map;
im_tool_class->dialog = gimp_hue_saturation_tool_dialog;
im_tool_class->reset = gimp_hue_saturation_tool_reset;
}
@ -132,24 +123,6 @@ gimp_hue_saturation_tool_class_init (GimpHueSaturationToolClass *klass)
static void
gimp_hue_saturation_tool_init (GimpHueSaturationTool *hs_tool)
{
GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (hs_tool);
hs_tool->hue_saturation = g_slice_new0 (HueSaturation);
hue_saturation_init (hs_tool->hue_saturation);
im_tool->apply_func = (GimpImageMapApplyFunc) hue_saturation;
im_tool->apply_data = hs_tool->hue_saturation;
}
static void
gimp_hue_saturation_tool_finalize (GObject *object)
{
GimpHueSaturationTool *hs_tool = GIMP_HUE_SATURATION_TOOL (object);
g_slice_free (HueSaturation, hs_tool->hue_saturation);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gboolean
@ -202,14 +175,6 @@ gimp_hue_saturation_tool_get_operation (GimpImageMapTool *im_tool,
return node;
}
static void
gimp_hue_saturation_tool_map (GimpImageMapTool *image_map_tool)
{
GimpHueSaturationTool *hs_tool = GIMP_HUE_SATURATION_TOOL (image_map_tool);
gimp_hue_saturation_config_to_cruft (hs_tool->config, hs_tool->hue_saturation);
}
/***************************/
/* Hue-Saturation dialog */

View File

@ -38,7 +38,6 @@ struct _GimpHueSaturationTool
GimpImageMapTool parent_instance;
GimpHueSaturationConfig *config;
HueSaturation *hue_saturation;
/* dialog */
GtkWidget *range_radio;

View File

@ -53,7 +53,6 @@ HELP
C_("undo-type", "Brightness-Contrast"),
"gimp:brightness-contrast",
config);
g_object_unref (config);
}
else
@ -125,7 +124,6 @@ HELP
C_("undo-type", "Levels"),
"gimp:levels",
config);
g_object_unref (config);
}
else
@ -225,7 +223,6 @@ HELP
_("Posterize"),
"gimp:posterize",
config);
g_object_unref (config);
}
else
@ -266,7 +263,6 @@ HELP
_("Desaturate"),
"gimp:desaturate",
config);
g_object_unref (config);
}
else
@ -314,7 +310,6 @@ HELP
_("Desaturate"),
"gimp:desaturate",
config);
g_object_unref (config);
}
else
@ -443,7 +438,6 @@ HELP
C_("undo-type", "Curves"),
"gimp:curves",
config);
g_object_unref (config);
}
else
@ -498,7 +492,6 @@ HELP
C_("undo-type", "Curves"),
"gimp:curves",
config);
g_object_unref (config);
}
else
@ -561,7 +554,6 @@ HELP
C_("undo-type", "Color Balance"),
"gimp:color-balance",
config);
g_object_unref (config);
}
else
@ -610,7 +602,6 @@ HELP
C_("undo-type", "Colorize"),
"gimp:colorize",
config);
g_object_unref (config);
}
else
@ -732,17 +723,30 @@ HELP
);
%invoke = (
headers => [ qw("core/gimpdrawable-hue-saturation.h") ],
headers => [ qw("gegl/gimphuesaturationconfig.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_HUE_SATURATION_CONFIG,
"range", hue_range,
NULL);
if (success)
gimp_drawable_hue_saturation (drawable, progress,
hue_range, hue_offset, saturation, lightness);
g_object_set (config,
"hue", hue_offset / 180.0,
"saturation", saturation / 100.0,
"lightness", lightness / 100.0,
NULL);
gimp_drawable_apply_operation_by_name (drawable, progress,
_("Hue-Saturation"),
"gimp:hue-saturation",
config);
g_object_unref (config);
}
else
success = FALSE;
}
CODE
);
@ -785,7 +789,6 @@ HELP
_("Threshold"),
"gimp:threshold",
config);
g_object_unref (config);
}
else