mirror of https://github.com/GNOME/gimp.git
app: remove the legacy brightness-contrast code and use GEGL instead
it's reasonably fast now.
This commit is contained in:
parent
4ab4da0e6c
commit
15957cb3c4
|
@ -28,67 +28,6 @@
|
|||
#include "lut-funcs.h"
|
||||
|
||||
|
||||
/* ---------- Brightness/Contrast -----------*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gdouble brightness;
|
||||
gdouble contrast;
|
||||
} BrightnessContrastLutData;
|
||||
|
||||
static gfloat
|
||||
brightness_contrast_lut_func (BrightnessContrastLutData *data,
|
||||
gint nchannels,
|
||||
gint channel,
|
||||
gfloat value)
|
||||
{
|
||||
gdouble slant;
|
||||
|
||||
/* 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);
|
||||
|
||||
slant = tan ((data->contrast + 1) * G_PI_4);
|
||||
value = (value - 0.5) * slant + 0.5;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void
|
||||
brightness_contrast_lut_setup (GimpLut *lut,
|
||||
gdouble brightness,
|
||||
gdouble contrast,
|
||||
gint n_channels)
|
||||
{
|
||||
BrightnessContrastLutData data;
|
||||
|
||||
g_return_if_fail (lut != NULL);
|
||||
|
||||
data.brightness = brightness;
|
||||
data.contrast = contrast;
|
||||
|
||||
gimp_lut_setup (lut,
|
||||
(GimpLutFunc) brightness_contrast_lut_func, &data, n_channels);
|
||||
}
|
||||
|
||||
GimpLut *
|
||||
brightness_contrast_lut_new (gdouble brightness,
|
||||
gdouble contrast,
|
||||
gint n_channels)
|
||||
{
|
||||
GimpLut *lut = gimp_lut_new ();
|
||||
|
||||
brightness_contrast_lut_setup (lut, brightness, contrast, n_channels);
|
||||
|
||||
return lut;
|
||||
}
|
||||
|
||||
/* --------------- equalize ------------- */
|
||||
|
||||
typedef struct
|
||||
|
|
|
@ -19,14 +19,6 @@
|
|||
#define __LUT_FUNCS_H__
|
||||
|
||||
|
||||
GimpLut * brightness_contrast_lut_new (gdouble brightness,
|
||||
gdouble contrast,
|
||||
gint n_channels);
|
||||
void brightness_contrast_lut_setup (GimpLut *lut,
|
||||
gdouble brightness,
|
||||
gdouble contrast,
|
||||
gint n_channels);
|
||||
|
||||
GimpLut * equalize_lut_new (GimpHistogram *histogram,
|
||||
gint n_channels);
|
||||
|
||||
|
|
|
@ -122,8 +122,6 @@ libappcore_a_sources = \
|
|||
gimpdrawable.h \
|
||||
gimpdrawable-blend.c \
|
||||
gimpdrawable-blend.h \
|
||||
gimpdrawable-brightness-contrast.c \
|
||||
gimpdrawable-brightness-contrast.h \
|
||||
gimpdrawable-bucket-fill.c \
|
||||
gimpdrawable-bucket-fill.h \
|
||||
gimpdrawable-color-balance.c \
|
||||
|
|
|
@ -1,89 +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/gimplut.h"
|
||||
#include "base/lut-funcs.h"
|
||||
|
||||
#include "gegl/gimpbrightnesscontrastconfig.h"
|
||||
|
||||
/* temp */
|
||||
#include "gimp.h"
|
||||
#include "gimpimage.h"
|
||||
|
||||
#include "gimpdrawable.h"
|
||||
#include "gimpdrawable-brightness-contrast.h"
|
||||
#include "gimpdrawable-operation.h"
|
||||
#include "gimpdrawable-process.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
||||
void
|
||||
gimp_drawable_brightness_contrast (GimpDrawable *drawable,
|
||||
GimpProgress *progress,
|
||||
gint brightness,
|
||||
gint contrast)
|
||||
{
|
||||
GimpBrightnessContrastConfig *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_BRIGHTNESS_CONTRAST_CONFIG,
|
||||
"brightness", brightness / 127.0,
|
||||
"contrast", contrast / 127.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:brightness-contrast",
|
||||
"config", config,
|
||||
NULL);
|
||||
|
||||
gimp_drawable_apply_operation (drawable, progress,
|
||||
C_("undo-type", "Brightness-Contrast")
|
||||
, node, TRUE);
|
||||
g_object_unref (node);
|
||||
}
|
||||
else
|
||||
{
|
||||
GimpLut *lut;
|
||||
|
||||
lut = brightness_contrast_lut_new (config->brightness / 2.0,
|
||||
config->contrast,
|
||||
gimp_drawable_bytes (drawable));
|
||||
|
||||
gimp_drawable_process_lut (drawable, progress,
|
||||
C_("undo-type", "Brightness-Contrast"),
|
||||
lut);
|
||||
gimp_lut_free (lut);
|
||||
}
|
||||
|
||||
g_object_unref (config);
|
||||
}
|
|
@ -1,28 +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_BRIGHTNESS_CONTRAST_H__
|
||||
#define __GIMP_DRAWABLE_BRIGHTNESS_CONTRAST_H__
|
||||
|
||||
|
||||
void gimp_drawable_brightness_contrast (GimpDrawable *drawable,
|
||||
GimpProgress *progress,
|
||||
gint brightness,
|
||||
gint contrast);
|
||||
|
||||
|
||||
#endif /* __GIMP_DRAWABLE_BRIGHTNESS_CONTRAST_H__ */
|
|
@ -24,7 +24,6 @@
|
|||
#include "pdb-types.h"
|
||||
|
||||
#include "base/gimphistogram.h"
|
||||
#include "core/gimpdrawable-brightness-contrast.h"
|
||||
#include "core/gimpdrawable-color-balance.h"
|
||||
#include "core/gimpdrawable-curves.h"
|
||||
#include "core/gimpdrawable-equalize.h"
|
||||
|
@ -34,6 +33,7 @@
|
|||
#include "core/gimpdrawable-operation.h"
|
||||
#include "core/gimpdrawable.h"
|
||||
#include "core/gimpparamspecs.h"
|
||||
#include "gegl/gimpbrightnesscontrastconfig.h"
|
||||
#include "gegl/gimpcolorizeconfig.h"
|
||||
#include "gegl/gimpdesaturateconfig.h"
|
||||
#include "gegl/gimpposterizeconfig.h"
|
||||
|
@ -66,14 +66,24 @@ brightness_contrast_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) &&
|
||||
! gimp_drawable_is_indexed (drawable))
|
||||
{
|
||||
GObject *config = g_object_new (GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG,
|
||||
"brightness", brightness / 127.0,
|
||||
"contrast", contrast / 127.0,
|
||||
NULL);
|
||||
|
||||
if (success)
|
||||
gimp_drawable_brightness_contrast (drawable, progress,
|
||||
brightness, contrast);
|
||||
gimp_drawable_apply_operation_by_name (drawable, progress,
|
||||
C_("undo-type", "Brightness-Contrast"),
|
||||
"gimp:brightness-contrast",
|
||||
config, TRUE);
|
||||
|
||||
g_object_unref (config);
|
||||
}
|
||||
else
|
||||
success = FALSE;
|
||||
}
|
||||
|
||||
return gimp_procedure_get_return_values (procedure, success,
|
||||
|
|
|
@ -27,9 +27,6 @@
|
|||
|
||||
#include "tools-types.h"
|
||||
|
||||
#include "base/gimplut.h"
|
||||
#include "base/lut-funcs.h"
|
||||
|
||||
#include "gegl/gimpbrightnesscontrastconfig.h"
|
||||
|
||||
#include "core/gimpdrawable.h"
|
||||
|
@ -51,8 +48,6 @@
|
|||
#define SLIDER_WIDTH 200
|
||||
|
||||
|
||||
static void gimp_brightness_contrast_tool_finalize (GObject *object);
|
||||
|
||||
static gboolean gimp_brightness_contrast_tool_initialize (GimpTool *tool,
|
||||
GimpDisplay *display,
|
||||
GError **error);
|
||||
|
@ -78,7 +73,6 @@ static void gimp_brightness_contrast_tool_motion (GimpTool
|
|||
static GeglNode *
|
||||
gimp_brightness_contrast_tool_get_operation (GimpImageMapTool *image_map_tool,
|
||||
GObject **config);
|
||||
static void gimp_brightness_contrast_tool_map (GimpImageMapTool *image_map_tool);
|
||||
static void gimp_brightness_contrast_tool_dialog (GimpImageMapTool *image_map_tool);
|
||||
|
||||
static void brightness_contrast_config_notify (GObject *object,
|
||||
|
@ -119,12 +113,9 @@ gimp_brightness_contrast_tool_register (GimpToolRegisterCallback callback,
|
|||
static void
|
||||
gimp_brightness_contrast_tool_class_init (GimpBrightnessContrastToolClass *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_brightness_contrast_tool_finalize;
|
||||
|
||||
tool_class->initialize = gimp_brightness_contrast_tool_initialize;
|
||||
tool_class->button_press = gimp_brightness_contrast_tool_button_press;
|
||||
tool_class->button_release = gimp_brightness_contrast_tool_button_release;
|
||||
|
@ -136,33 +127,12 @@ gimp_brightness_contrast_tool_class_init (GimpBrightnessContrastToolClass *klass
|
|||
im_tool_class->export_dialog_title = _("Export Brightness-Contrast settings");
|
||||
|
||||
im_tool_class->get_operation = gimp_brightness_contrast_tool_get_operation;
|
||||
im_tool_class->map = gimp_brightness_contrast_tool_map;
|
||||
im_tool_class->dialog = gimp_brightness_contrast_tool_dialog;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_brightness_contrast_tool_init (GimpBrightnessContrastTool *bc_tool)
|
||||
{
|
||||
GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (bc_tool);
|
||||
|
||||
bc_tool->lut = gimp_lut_new ();
|
||||
|
||||
im_tool->apply_func = (GimpImageMapApplyFunc) gimp_lut_process;
|
||||
im_tool->apply_data = bc_tool->lut;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_brightness_contrast_tool_finalize (GObject *object)
|
||||
{
|
||||
GimpBrightnessContrastTool *bc_tool = GIMP_BRIGHTNESS_CONTRAST_TOOL (object);
|
||||
|
||||
if (bc_tool->lut)
|
||||
{
|
||||
gimp_lut_free (bc_tool->lut);
|
||||
bc_tool->lut = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -216,17 +186,6 @@ gimp_brightness_contrast_tool_get_operation (GimpImageMapTool *im_tool,
|
|||
return node;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_brightness_contrast_tool_map (GimpImageMapTool *im_tool)
|
||||
{
|
||||
GimpBrightnessContrastTool *bc_tool = GIMP_BRIGHTNESS_CONTRAST_TOOL (im_tool);
|
||||
|
||||
brightness_contrast_lut_setup (bc_tool->lut,
|
||||
bc_tool->config->brightness / 2.0,
|
||||
bc_tool->config->contrast,
|
||||
gimp_drawable_bytes (im_tool->drawable));
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_brightness_contrast_tool_button_press (GimpTool *tool,
|
||||
const GimpCoords *coords,
|
||||
|
|
|
@ -38,7 +38,6 @@ struct _GimpBrightnessContrastTool
|
|||
GimpImageMapTool parent_instance;
|
||||
|
||||
GimpBrightnessContrastConfig *config;
|
||||
GimpLut *lut;
|
||||
|
||||
gdouble x, y;
|
||||
gdouble dx, dy;
|
||||
|
|
|
@ -38,17 +38,27 @@ HELP
|
|||
);
|
||||
|
||||
%invoke = (
|
||||
headers => [ qw("core/gimpdrawable-brightness-contrast.h") ],
|
||||
headers => [ qw("gegl/gimpbrightnesscontrastconfig.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) &&
|
||||
! gimp_drawable_is_indexed (drawable))
|
||||
{
|
||||
GObject *config = g_object_new (GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG,
|
||||
"brightness", brightness / 127.0,
|
||||
"contrast", contrast / 127.0,
|
||||
NULL);
|
||||
|
||||
if (success)
|
||||
gimp_drawable_brightness_contrast (drawable, progress,
|
||||
brightness, contrast);
|
||||
gimp_drawable_apply_operation_by_name (drawable, progress,
|
||||
C_("undo-type", "Brightness-Contrast"),
|
||||
"gimp:brightness-contrast",
|
||||
config, TRUE);
|
||||
|
||||
g_object_unref (config);
|
||||
}
|
||||
else
|
||||
success = FALSE;
|
||||
}
|
||||
CODE
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue