app: remove the legacy levels cruft

This commit is contained in:
Michael Natterer 2012-03-23 10:25:34 +01:00
parent a34b19774b
commit cde58408fa
13 changed files with 94 additions and 413 deletions

View File

@ -32,8 +32,6 @@ libappbase_a_SOURCES = \
gimplut.h \
hue-saturation.c \
hue-saturation.h \
levels.c \
levels.h \
lut-funcs.c \
lut-funcs.h \
pixel-processor.c \

View File

@ -52,7 +52,6 @@ typedef struct _GimpLut GimpLut;
typedef struct _ColorBalance ColorBalance;
typedef struct _HueSaturation HueSaturation;
typedef struct _Levels Levels;
typedef struct _Threshold Threshold;
typedef struct _PixelRegionIterator PixelRegionIterator;

View File

@ -1,113 +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 "levels.h"
/* public functions */
void
levels_init (Levels *levels)
{
GimpHistogramChannel channel;
g_return_if_fail (levels != NULL);
for (channel = GIMP_HISTOGRAM_VALUE;
channel <= GIMP_HISTOGRAM_ALPHA;
channel++)
{
levels->gamma[channel] = 1.0;
levels->low_input[channel] = 0;
levels->high_input[channel] = 255;
levels->low_output[channel] = 0;
levels->high_output[channel] = 255;
}
}
gfloat
levels_lut_func (Levels *levels,
gint n_channels,
gint channel,
gfloat value)
{
gdouble inten;
gint j;
if (n_channels <= 2)
j = channel;
else
j = channel + 1;
inten = value;
/* For RGB and RGBA images this runs through the loop with j = channel + 1
* the first time and j = 0 the second time
*
* For GRAY 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 && (n_channels == 2 || n_channels == 4) &&
channel == n_channels - 1)
return inten;
/* determine input intensity */
if (levels->high_input[j] != levels->low_input[j])
{
inten = ((gdouble) (255.0 * inten - levels->low_input[j]) /
(gdouble) (levels->high_input[j] - levels->low_input[j]));
}
else
{
inten = (gdouble) (255.0 * inten - levels->low_input[j]);
}
/* clamp to new black and white points */
inten = CLAMP (inten, 0.0, 1.0);
if (levels->gamma[j] != 0.0)
{
inten = pow ( inten, (1.0 / levels->gamma[j]));
}
/* determine the output intensity */
if (levels->high_output[j] >= levels->low_output[j])
inten = (gdouble) (inten * (levels->high_output[j] -
levels->low_output[j]) +
levels->low_output[j]);
else if (levels->high_output[j] < levels->low_output[j])
inten = (gdouble) (levels->low_output[j] - inten *
(levels->low_output[j] - levels->high_output[j]));
inten /= 255.0;
}
return inten;
}

View File

@ -1,41 +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 __LEVELS_H__
#define __LEVELS_H__
struct _Levels
{
gdouble gamma[5];
gint low_input[5];
gint high_input[5];
gint low_output[5];
gint high_output[5];
};
void levels_init (Levels *levels);
gfloat levels_lut_func (Levels *levels,
gint n_channels,
gint channel,
gfloat value);
#endif /* __LEVELS_H__ */

View File

@ -22,15 +22,9 @@
#include "core-types.h"
#include "base/gimphistogram.h"
#include "base/gimplut.h"
#include "base/levels.h"
#include "gegl/gimplevelsconfig.h"
/* temp */
#include "gimp.h"
#include "gimpimage.h"
#include "gimpdrawable.h"
#include "gimpdrawable-histogram.h"
#include "gimpdrawable-levels.h"
@ -41,74 +35,17 @@
#include "gimp-intl.h"
/* local function prototypes */
static void gimp_drawable_levels_internal (GimpDrawable *drawable,
GimpProgress *progress,
GimpLevelsConfig *config);
/* public functions */
void
gimp_drawable_levels (GimpDrawable *drawable,
GimpProgress *progress,
gint32 channel,
gint32 low_input,
gint32 high_input,
gdouble gamma,
gint32 low_output,
gint32 high_output)
{
GimpLevelsConfig *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)));
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
g_return_if_fail (channel >= GIMP_HISTOGRAM_VALUE &&
channel <= GIMP_HISTOGRAM_ALPHA);
g_return_if_fail (low_input >= 0 && low_input <= 255);
g_return_if_fail (high_input >= 0 && high_input <= 255);
g_return_if_fail (gamma >= 0.1 && gamma <= 10.0);
g_return_if_fail (low_output >= 0 && low_output <= 255);
g_return_if_fail (high_output >= 0 && high_output <= 255);
if (channel == GIMP_HISTOGRAM_ALPHA)
g_return_if_fail (gimp_drawable_has_alpha (drawable));
if (gimp_drawable_is_gray (drawable))
g_return_if_fail (channel == GIMP_HISTOGRAM_VALUE ||
channel == GIMP_HISTOGRAM_ALPHA);
config = g_object_new (GIMP_TYPE_LEVELS_CONFIG, NULL);
g_object_set (config,
"channel", channel,
NULL);
g_object_set (config,
"low-input", low_input / 255.0,
"high-input", high_input / 255.0,
"gamma", gamma,
"low-output", low_output / 255.0,
"high-output", high_output / 255.0,
NULL);
gimp_drawable_levels_internal (drawable, progress, config);
g_object_unref (config);
}
void
gimp_drawable_levels_stretch (GimpDrawable *drawable,
GimpProgress *progress)
{
GimpLevelsConfig *config;
GimpHistogram *histogram;
GeglNode *levels;
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)));
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
@ -125,48 +62,17 @@ gimp_drawable_levels_stretch (GimpDrawable *drawable,
gimp_histogram_unref (histogram);
gimp_drawable_levels_internal (drawable, progress, config);
levels = g_object_new (GEGL_TYPE_NODE,
"operation", "gimp:levels",
NULL);
gegl_node_set (levels,
"config", config,
NULL);
gimp_drawable_apply_operation (drawable, progress, _("Levels"),
levels, TRUE);
g_object_unref (levels);
g_object_unref (config);
}
/* private functions */
static void
gimp_drawable_levels_internal (GimpDrawable *drawable,
GimpProgress *progress,
GimpLevelsConfig *config)
{
if (gimp_use_gegl (gimp_item_get_image (GIMP_ITEM (drawable))->gimp))
{
GeglNode *levels;
levels = g_object_new (GEGL_TYPE_NODE,
"operation", "gimp:levels",
NULL);
gegl_node_set (levels,
"config", config,
NULL);
gimp_drawable_apply_operation (drawable, progress, _("Levels"),
levels, TRUE);
g_object_unref (levels);
}
else
{
Levels levels;
GimpLut *lut = gimp_lut_new ();
gimp_levels_config_to_cruft (config, &levels,
gimp_drawable_is_rgb (drawable));
gimp_lut_setup (lut,
(GimpLutFunc) levels_lut_func, &levels,
gimp_drawable_bytes (drawable));
gimp_drawable_process_lut (drawable, progress, _("Levels"), lut);
gimp_lut_free (lut);
}
}

View File

@ -19,15 +19,6 @@
#define __GIMP_DRAWABLE_LEVELS_H__
void gimp_drawable_levels (GimpDrawable *drawable,
GimpProgress *progress,
gint32 channel,
gint32 low_input,
gint32 high_input,
gdouble gamma,
gint32 low_output,
gint32 high_output);
void gimp_drawable_levels_stretch (GimpDrawable *drawable,
GimpProgress *progress);

View File

@ -35,9 +35,6 @@
#include "base/gimphistogram.h"
/* temp cruft */
#include "base/levels.h"
#include "core/gimpcurve.h"
#include "gimpcurvesconfig.h"
@ -819,37 +816,3 @@ gimp_levels_config_save_cruft (GimpLevelsConfig *config,
return TRUE;
}
/* temp cruft */
void
gimp_levels_config_to_cruft (GimpLevelsConfig *config,
Levels *cruft,
gboolean is_color)
{
GimpHistogramChannel channel;
g_return_if_fail (GIMP_IS_LEVELS_CONFIG (config));
g_return_if_fail (cruft != NULL);
for (channel = GIMP_HISTOGRAM_VALUE;
channel <= GIMP_HISTOGRAM_ALPHA;
channel++)
{
cruft->gamma[channel] = config->gamma[channel];
cruft->low_input[channel] = config->low_input[channel] * 255.999;
cruft->high_input[channel] = config->high_input[channel] * 255.999;
cruft->low_output[channel] = config->low_output[channel] * 255.999;
cruft->high_output[channel] = config->high_output[channel] * 255.999;
}
if (! is_color)
{
cruft->gamma[1] = cruft->gamma[GIMP_HISTOGRAM_ALPHA];
cruft->low_input[1] = cruft->low_input[GIMP_HISTOGRAM_ALPHA];
cruft->high_input[1] = cruft->high_input[GIMP_HISTOGRAM_ALPHA];
cruft->low_output[1] = cruft->low_output[GIMP_HISTOGRAM_ALPHA];
cruft->high_output[1] = cruft->high_output[GIMP_HISTOGRAM_ALPHA];
}
}

View File

@ -83,10 +83,4 @@ gboolean gimp_levels_config_save_cruft (GimpLevelsConfig *config,
GError **error);
/* temp cruft */
void gimp_levels_config_to_cruft (GimpLevelsConfig *config,
Levels *cruft,
gboolean is_color);
#endif /* __GIMP_LEVELS_CONFIG_H__ */

View File

@ -36,6 +36,7 @@
#include "gegl/gimpcolorizeconfig.h"
#include "gegl/gimpcurvesconfig.h"
#include "gegl/gimpdesaturateconfig.h"
#include "gegl/gimplevelsconfig.h"
#include "gegl/gimpposterizeconfig.h"
#include "gegl/gimpthresholdconfig.h"
@ -116,21 +117,33 @@ levels_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) ||
(! gimp_drawable_has_alpha (drawable) &&
channel == GIMP_HISTOGRAM_ALPHA) ||
(gimp_drawable_is_gray (drawable) &&
channel != GIMP_HISTOGRAM_VALUE && channel != GIMP_HISTOGRAM_ALPHA))
success = FALSE;
if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
(gimp_drawable_has_alpha (drawable) || channel != GIMP_HISTOGRAM_ALPHA) &&
(! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
{
GObject *config = g_object_new (GIMP_TYPE_LEVELS_CONFIG,
"channel", channel,
NULL);
if (success)
gimp_drawable_levels (drawable, progress,
channel,
low_input, high_input,
gamma,
low_output, high_output);
g_object_set (config,
"low-input", low_input / 255.0,
"high-input", high_input / 255.0,
"gamma", gamma,
"low-output", low_output / 255.0,
"high-output", high_output / 255.0,
NULL);
gimp_drawable_apply_operation_by_name (drawable, progress,
C_("undo-type", "Levels"),
"gimp:levels",
config, TRUE);
g_object_unref (config);
}
else
success = TRUE;
}
return gimp_procedure_get_return_values (procedure, success,
@ -152,13 +165,13 @@ levels_auto_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))
if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
gimp_drawable_levels_stretch (drawable, progress);
}
else
success = FALSE;
if (success)
gimp_drawable_levels_stretch (drawable, progress);
}
return gimp_procedure_get_return_values (procedure, success,
@ -180,13 +193,13 @@ levels_stretch_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))
if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
gimp_drawable_levels_stretch (drawable, progress);
}
else
success = FALSE;
if (success)
gimp_drawable_levels_stretch (drawable, progress);
}
return gimp_procedure_get_return_values (procedure, success,
@ -837,7 +850,7 @@ register_color_procs (GimpPDB *pdb)
gimp_procedure_set_static_strings (procedure,
"gimp-levels-stretch",
"Automatically modifies intensity levels in the specified drawable.",
"This procedure allows intensity levels in the specified drawable to be remapped according to a set of guessed parameters. It is equivalent to clicking the \"Auto\" button in the Levels tool. This procedure is only valid on RGB color and grayscale images. It will not operate on indexed drawables.",
"This procedure allows intensity levels in the specified drawable to be remapped according to a set of guessed parameters. It is equivalent to clicking the \"Auto\" button in the Levels tool.",
"Joao S.O. Bueno, Shawn Willden",
"Joao S.O. Bueno, Shawn Willden",
"2003",

View File

@ -31,8 +31,6 @@
#include "tools-types.h"
#include "base/gimphistogram.h"
#include "base/gimplut.h"
#include "base/levels.h"
#include "gegl/gimplevelsconfig.h"
#include "gegl/gimpoperationlevels.h"
@ -82,7 +80,6 @@ static void gimp_levels_tool_color_picked (GimpColorTool *color_tool
static GeglNode * gimp_levels_tool_get_operation (GimpImageMapTool *im_tool,
GObject **config);
static void gimp_levels_tool_map (GimpImageMapTool *im_tool);
static void gimp_levels_tool_dialog (GimpImageMapTool *im_tool);
static void gimp_levels_tool_dialog_unmap (GtkWidget *dialog,
GimpLevelsTool *tool);
@ -175,7 +172,6 @@ gimp_levels_tool_class_init (GimpLevelsToolClass *klass)
im_tool_class->export_dialog_title = _("Export Levels");
im_tool_class->get_operation = gimp_levels_tool_get_operation;
im_tool_class->map = gimp_levels_tool_map;
im_tool_class->dialog = gimp_levels_tool_dialog;
im_tool_class->reset = gimp_levels_tool_reset;
im_tool_class->settings_import = gimp_levels_tool_settings_import;
@ -185,14 +181,7 @@ gimp_levels_tool_class_init (GimpLevelsToolClass *klass)
static void
gimp_levels_tool_init (GimpLevelsTool *tool)
{
GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (tool);
tool->lut = gimp_lut_new ();
tool->histogram = gimp_histogram_new ();
tool->active_picker = NULL;
im_tool->apply_func = (GimpImageMapApplyFunc) gimp_lut_process;
im_tool->apply_data = tool->lut;
tool->histogram = gimp_histogram_new ();
}
static void
@ -200,8 +189,6 @@ gimp_levels_tool_finalize (GObject *object)
{
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (object);
gimp_lut_free (tool->lut);
if (tool->histogram)
{
gimp_histogram_unref (tool->histogram);
@ -223,13 +210,6 @@ gimp_levels_tool_initialize (GimpTool *tool,
if (! drawable)
return FALSE;
if (gimp_drawable_is_indexed (drawable))
{
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
_("Levels does not operate on indexed layers."));
return FALSE;
}
gimp_config_reset (GIMP_CONFIG (l_tool->config));
if (l_tool->active_picker)
@ -277,22 +257,6 @@ gimp_levels_tool_get_operation (GimpImageMapTool *im_tool,
return node;
}
static void
gimp_levels_tool_map (GimpImageMapTool *image_map_tool)
{
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
GimpDrawable *drawable = image_map_tool->drawable;
Levels levels;
gimp_levels_config_to_cruft (tool->config, &levels,
gimp_drawable_is_rgb (drawable));
gimp_lut_setup (tool->lut,
(GimpLutFunc) levels_lut_func,
&levels,
gimp_drawable_bytes (drawable));
}
/*******************/
/* Levels dialog */

View File

@ -38,7 +38,6 @@ struct _GimpLevelsTool
GimpImageMapTool parent_instance;
GimpLevelsConfig *config;
GimpLut *lut;
/* dialog */
GimpHistogram *histogram;

View File

@ -167,9 +167,7 @@ gimp_levels_auto (gint32 drawable_ID)
*
* This procedure allows intensity levels in the specified drawable to
* be remapped according to a set of guessed parameters. It is
* equivalent to clicking the \"Auto\" button in the Levels tool. This
* procedure is only valid on RGB color and grayscale images. It will
* not operate on indexed drawables.
* equivalent to clicking the \"Auto\" button in the Levels tool.
*
* Returns: TRUE on success.
**/

View File

@ -100,24 +100,36 @@ HELP
);
%invoke = (
headers => [ qw("core/gimpdrawable-levels.h") ],
headers => [ qw("gegl/gimplevelsconfig.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) ||
(! gimp_drawable_has_alpha (drawable) &&
channel == GIMP_HISTOGRAM_ALPHA) ||
(gimp_drawable_is_gray (drawable) &&
channel != GIMP_HISTOGRAM_VALUE && channel != GIMP_HISTOGRAM_ALPHA))
success = FALSE;
if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
(gimp_drawable_has_alpha (drawable) || channel != GIMP_HISTOGRAM_ALPHA) &&
(! gimp_drawable_is_gray (drawable) ||
channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
{
GObject *config = g_object_new (GIMP_TYPE_LEVELS_CONFIG,
"channel", channel,
NULL);
if (success)
gimp_drawable_levels (drawable, progress,
channel,
low_input, high_input,
gamma,
low_output, high_output);
g_object_set (config,
"low-input", low_input / 255.0,
"high-input", high_input / 255.0,
"gamma", gamma,
"low-output", low_output / 255.0,
"high-output", high_output / 255.0,
NULL);
gimp_drawable_apply_operation_by_name (drawable, progress,
C_("undo-type", "Levels"),
"gimp:levels",
config, TRUE);
g_object_unref (config);
}
else
success = TRUE;
}
CODE
);
@ -129,9 +141,7 @@ sub levels_stretch {
$help = <<'HELP';
This procedure allows intensity levels in the specified drawable to be
remapped according to a set of guessed parameters. It is equivalent to
clicking the "Auto" button in the Levels tool. This procedure is
only valid on RGB color and grayscale images. It will not operate on
indexed drawables.
clicking the "Auto" button in the Levels tool.
HELP
$author = $copyright = 'Joao S.O. Bueno, Shawn Willden';
@ -146,13 +156,13 @@ HELP
headers => [ qw("core/gimpdrawable-levels.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))
if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
gimp_drawable_levels_stretch (drawable, progress);
}
else
success = FALSE;
if (success)
gimp_drawable_levels_stretch (drawable, progress);
}
CODE
);
@ -170,13 +180,13 @@ sub levels_auto {
headers => [ qw("core/gimpdrawable-levels.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))
if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
gimp_drawable_levels_stretch (drawable, progress);
}
else
success = FALSE;
if (success)
gimp_drawable_levels_stretch (drawable, progress);
}
CODE
);