mirror of https://github.com/GNOME/gimp.git
app,pdb: add a compatibility wrapper for contrast-stretch-hsv
... and remove the old plugin
This commit is contained in:
parent
fe3b80d617
commit
c41c2452c5
|
@ -28,7 +28,7 @@
|
|||
#include "internal-procs.h"
|
||||
|
||||
|
||||
/* 704 procedures registered total */
|
||||
/* 705 procedures registered total */
|
||||
|
||||
void
|
||||
internal_procs_init (GimpPDB *pdb)
|
||||
|
|
|
@ -257,6 +257,43 @@ plug_in_autocrop_layer_invoker (GimpProcedure *procedure,
|
|||
error ? *error : NULL);
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
plug_in_autostretch_hsv_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
GimpContext *context,
|
||||
GimpProgress *progress,
|
||||
const GimpValueArray *args,
|
||||
GError **error)
|
||||
{
|
||||
gboolean success = TRUE;
|
||||
GimpDrawable *drawable;
|
||||
|
||||
drawable = gimp_value_get_drawable (gimp_value_array_index (args, 2), gimp);
|
||||
|
||||
if (success)
|
||||
{
|
||||
if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
|
||||
GIMP_PDB_ITEM_CONTENT, error) &&
|
||||
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
|
||||
{
|
||||
GeglNode *node =
|
||||
gegl_node_new_child (NULL,
|
||||
"operation", "gegl:stretch-contrast-hsv",
|
||||
NULL);
|
||||
|
||||
gimp_drawable_apply_operation (drawable, progress,
|
||||
C_("undo-type", "Stretch Contrast HSV"),
|
||||
node);
|
||||
g_object_unref (node);
|
||||
}
|
||||
else
|
||||
success = FALSE;
|
||||
}
|
||||
|
||||
return gimp_procedure_get_return_values (procedure, success,
|
||||
error ? *error : NULL);
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
plug_in_c_astretch_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
|
@ -1858,6 +1895,42 @@ register_plug_in_compat_procs (GimpPDB *pdb)
|
|||
gimp_pdb_register_procedure (pdb, procedure);
|
||||
g_object_unref (procedure);
|
||||
|
||||
/*
|
||||
* gimp-plug-in-autostretch-hsv
|
||||
*/
|
||||
procedure = gimp_procedure_new (plug_in_autostretch_hsv_invoker);
|
||||
gimp_object_set_static_name (GIMP_OBJECT (procedure),
|
||||
"plug-in-autostretch-hsv");
|
||||
gimp_procedure_set_static_strings (procedure,
|
||||
"plug-in-autostretch-hsv",
|
||||
"Stretch contrast to cover the maximum possible range",
|
||||
"This simple plug-in does an automatic contrast stretch. For each channel in the image, it finds the minimum and maximum values... it uses those values to stretch the individual histograms to the full contrast range. For some images it may do just what you want; for others it may be total crap :). This version differs from Contrast Autostretch in that it works in HSV space, and preserves hue.",
|
||||
"Compatibility procedure. Please see 'gegl:stretch-contrast-hsv' for credits.",
|
||||
"Compatibility procedure. Please see 'gegl:stretch-contrast-hsv' for credits.",
|
||||
"2013",
|
||||
NULL);
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_enum ("run-mode",
|
||||
"run mode",
|
||||
"The run mode",
|
||||
GIMP_TYPE_RUN_MODE,
|
||||
GIMP_RUN_INTERACTIVE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_image_id ("image",
|
||||
"image",
|
||||
"Input image (unused)",
|
||||
pdb->gimp, FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_drawable_id ("drawable",
|
||||
"drawable",
|
||||
"Input drawable",
|
||||
pdb->gimp, FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_pdb_register_procedure (pdb, procedure);
|
||||
g_object_unref (procedure);
|
||||
|
||||
/*
|
||||
* gimp-plug-in-c-astretch
|
||||
*/
|
||||
|
|
|
@ -44,8 +44,6 @@
|
|||
/contrast-normalize.exe
|
||||
/contrast-retinex
|
||||
/contrast-retinex.exe
|
||||
/contrast-stretch-hsv
|
||||
/contrast-stretch-hsv.exe
|
||||
/convolution-matrix
|
||||
/convolution-matrix.exe
|
||||
/crop-zealous
|
||||
|
|
|
@ -65,7 +65,6 @@ libexec_PROGRAMS = \
|
|||
compose \
|
||||
contrast-normalize \
|
||||
contrast-retinex \
|
||||
contrast-stretch-hsv \
|
||||
convolution-matrix \
|
||||
crop-zealous \
|
||||
curve-bend \
|
||||
|
@ -555,21 +554,6 @@ contrast_retinex_LDADD = \
|
|||
$(INTLLIBS) \
|
||||
$(contrast_retinex_RC)
|
||||
|
||||
contrast_stretch_hsv_SOURCES = \
|
||||
contrast-stretch-hsv.c
|
||||
|
||||
contrast_stretch_hsv_LDADD = \
|
||||
$(libgimp) \
|
||||
$(libgimpmath) \
|
||||
$(libgimpconfig) \
|
||||
$(libgimpcolor) \
|
||||
$(libgimpbase) \
|
||||
$(CAIRO_LIBS) \
|
||||
$(GDK_PIXBUF_LIBS) \
|
||||
$(RT_LIBS) \
|
||||
$(INTLLIBS) \
|
||||
$(contrast_stretch_hsv_RC)
|
||||
|
||||
convolution_matrix_SOURCES = \
|
||||
convolution-matrix.c
|
||||
|
||||
|
|
|
@ -1,216 +0,0 @@
|
|||
/* Autostretch HSV 0.10 --- image filter plug-in for GIMP
|
||||
*
|
||||
* Copyright (C) 1997 Scott Goehring
|
||||
* Copyright (C) 1996 Federico Mena Quintero
|
||||
*
|
||||
* You can contact me at scott@poverty.bloomington.in.us
|
||||
*
|
||||
* 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 <libgimp/gimp.h>
|
||||
|
||||
#include "libgimp/stdplugins-intl.h"
|
||||
|
||||
|
||||
#define PLUG_IN_PROC "plug-in-autostretch-hsv"
|
||||
|
||||
|
||||
/* Declare local functions.
|
||||
*/
|
||||
static void query (void);
|
||||
static void run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
|
||||
static void autostretch_hsv (GimpDrawable *drawable);
|
||||
static void indexed_autostretch_hsv (gint32 image_ID);
|
||||
|
||||
|
||||
const GimpPlugInInfo PLUG_IN_INFO =
|
||||
{
|
||||
NULL, /* init_proc */
|
||||
NULL, /* quit_proc */
|
||||
query, /* query_proc */
|
||||
run, /* run_proc */
|
||||
};
|
||||
|
||||
|
||||
MAIN ()
|
||||
|
||||
static void
|
||||
query (void)
|
||||
{
|
||||
static const GimpParamDef args[] =
|
||||
{
|
||||
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
|
||||
{ GIMP_PDB_IMAGE, "image", "Input image" },
|
||||
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" }
|
||||
};
|
||||
|
||||
gimp_install_procedure (PLUG_IN_PROC,
|
||||
N_("Stretch image contrast to cover the maximum possible range"),
|
||||
"This simple plug-in does an automatic contrast "
|
||||
"stretch. For each channel in the image, it finds "
|
||||
"the minimum and maximum values... it uses those "
|
||||
"values to stretch the individual histograms to the "
|
||||
"full contrast range. For some images it may do "
|
||||
"just what you want; for others it may be total "
|
||||
"crap :). This version differs from Contrast "
|
||||
"Autostretch in that it works in HSV space, and "
|
||||
"preserves hue.",
|
||||
"Scott Goehring and Federico Mena Quintero",
|
||||
"Scott Goehring and Federico Mena Quintero",
|
||||
"1997",
|
||||
N_("Stretch _HSV"),
|
||||
"RGB*, INDEXED*",
|
||||
GIMP_PLUGIN,
|
||||
G_N_ELEMENTS (args), 0,
|
||||
args, NULL);
|
||||
|
||||
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Colors/Auto");
|
||||
}
|
||||
|
||||
static void
|
||||
run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals)
|
||||
{
|
||||
static GimpParam values[1];
|
||||
GimpDrawable *drawable;
|
||||
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
||||
GimpRunMode run_mode;
|
||||
|
||||
gint32 image_ID;
|
||||
|
||||
INIT_I18N();
|
||||
|
||||
run_mode = param[0].data.d_int32;
|
||||
|
||||
/* Get the specified drawable */
|
||||
drawable = gimp_drawable_get (param[2].data.d_drawable);
|
||||
image_ID = param[1].data.d_image;
|
||||
|
||||
/* Make sure that the drawable is gray or RGB color */
|
||||
if (gimp_drawable_is_rgb (drawable->drawable_id) ||
|
||||
gimp_drawable_is_gray (drawable->drawable_id))
|
||||
{
|
||||
gimp_progress_init (_("Auto-Stretching HSV"));
|
||||
gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1));
|
||||
autostretch_hsv (drawable);
|
||||
|
||||
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
||||
gimp_displays_flush ();
|
||||
}
|
||||
else if (gimp_drawable_is_indexed (drawable->drawable_id))
|
||||
{
|
||||
indexed_autostretch_hsv (image_ID);
|
||||
|
||||
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
||||
gimp_displays_flush ();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* gimp_message ("autostretch_hsv: cannot operate on indexed color images"); */
|
||||
status = GIMP_PDB_EXECUTION_ERROR;
|
||||
}
|
||||
|
||||
*nreturn_vals = 1;
|
||||
*return_vals = values;
|
||||
|
||||
values[0].type = GIMP_PDB_STATUS;
|
||||
values[0].data.d_status = status;
|
||||
|
||||
gimp_drawable_detach (drawable);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
double shi;
|
||||
double slo;
|
||||
double vhi;
|
||||
double vlo;
|
||||
} AutostretchData;
|
||||
|
||||
static void
|
||||
find_max (guchar *src, gint bpp, AutostretchData *data)
|
||||
{
|
||||
double h, s, v;
|
||||
|
||||
gimp_rgb_to_hsv4(src, &h, &s, &v);
|
||||
if (s > data->shi) data->shi = s;
|
||||
if (s < data->slo) data->slo = s;
|
||||
if (v > data->vhi) data->vhi = v;
|
||||
if (v < data->vlo) data->vlo = v;
|
||||
}
|
||||
|
||||
static void
|
||||
autostretch_hsv_func (guchar *src, guchar *dest, gint bpp,
|
||||
AutostretchData *data)
|
||||
{
|
||||
double h, s, v;
|
||||
|
||||
gimp_rgb_to_hsv4(src, &h, &s, &v);
|
||||
if (data->shi != data->slo)
|
||||
s = (s - data->slo) / (data->shi - data->slo);
|
||||
if (data->vhi != data->vlo)
|
||||
v = (v - data->vlo) / (data->vhi - data->vlo);
|
||||
gimp_hsv_to_rgb4(dest, h, s, v);
|
||||
|
||||
if (bpp == 4)
|
||||
dest[3] = src[3];
|
||||
}
|
||||
|
||||
static void
|
||||
indexed_autostretch_hsv (gint32 image_ID)
|
||||
{
|
||||
guchar *cmap;
|
||||
AutostretchData data = {0.0, 1.0, 0.0, 1.0};
|
||||
gint ncols, i;
|
||||
|
||||
cmap = gimp_image_get_colormap (image_ID, &ncols);
|
||||
|
||||
if (!cmap)
|
||||
{
|
||||
g_message (_("autostretch_hsv: cmap was NULL! Quitting...\n"));
|
||||
gimp_quit ();
|
||||
}
|
||||
|
||||
for (i = 0; i < ncols; i++)
|
||||
{
|
||||
find_max (&cmap[i * 3], 3, &data);
|
||||
}
|
||||
|
||||
for (i = 0; i < ncols; i++)
|
||||
{
|
||||
autostretch_hsv_func (&cmap[i * 3], &cmap[i * 3], 3, &data);
|
||||
}
|
||||
|
||||
gimp_image_set_colormap (image_ID, cmap, ncols);
|
||||
}
|
||||
|
||||
static void
|
||||
autostretch_hsv (GimpDrawable *drawable)
|
||||
{
|
||||
AutostretchData data = {0.0, 1.0, 0.0, 1.0};
|
||||
|
||||
gimp_rgn_iterate1 (drawable, 0 /* unused */, (GimpRgnFunc1) find_max, &data);
|
||||
gimp_rgn_iterate2 (drawable, 0 /* unused */, (GimpRgnFunc2) autostretch_hsv_func,
|
||||
&data);
|
||||
}
|
|
@ -19,7 +19,6 @@ colormap_remap_RC = colormap-remap.rc.o
|
|||
compose_RC = compose.rc.o
|
||||
contrast_normalize_RC = contrast-normalize.rc.o
|
||||
contrast_retinex_RC = contrast-retinex.rc.o
|
||||
contrast_stretch_hsv_RC = contrast-stretch-hsv.rc.o
|
||||
convolution_matrix_RC = convolution-matrix.rc.o
|
||||
crop_zealous_RC = crop-zealous.rc.o
|
||||
curve_bend_RC = curve-bend.rc.o
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
'compose' => { ui => 1, gegl => 1 },
|
||||
'contrast-normalize' => {},
|
||||
'contrast-retinex' => { ui => 1 },
|
||||
'contrast-stretch-hsv' => {},
|
||||
'convolution-matrix' => { ui => 1 },
|
||||
'crop-zealous' => {},
|
||||
'curve-bend' => { ui => 1 },
|
||||
|
|
|
@ -27,7 +27,6 @@ plug-ins/common/colormap-remap.c
|
|||
plug-ins/common/compose.c
|
||||
plug-ins/common/contrast-normalize.c
|
||||
plug-ins/common/contrast-retinex.c
|
||||
plug-ins/common/contrast-stretch-hsv.c
|
||||
plug-ins/common/convolution-matrix.c
|
||||
plug-ins/common/crop-zealous.c
|
||||
plug-ins/common/curve-bend.c
|
||||
|
|
|
@ -242,6 +242,54 @@ CODE
|
|||
);
|
||||
}
|
||||
|
||||
sub plug_in_autostretch_hsv {
|
||||
$blurb = 'Stretch contrast to cover the maximum possible range';
|
||||
|
||||
$help = <<'HELP';
|
||||
This simple plug-in does an automatic contrast stretch. For each
|
||||
channel in the image, it finds the minimum and maximum values... it
|
||||
uses those values to stretch the individual histograms to the full
|
||||
contrast range. For some images it may do just what you want; for
|
||||
others it may be total crap :). This version differs from Contrast
|
||||
Autostretch in that it works in HSV space, and preserves hue.
|
||||
HELP
|
||||
|
||||
&std_pdb_compat('gegl:stretch-contrast-hsv');
|
||||
$date = '2013';
|
||||
|
||||
@inargs = (
|
||||
{ name => 'run_mode', type => 'enum GimpRunMode', dead => 1,
|
||||
desc => 'The run mode' },
|
||||
{ name => 'image', type => 'image', dead => 1,
|
||||
desc => 'Input image (unused)' },
|
||||
{ name => 'drawable', type => 'drawable',
|
||||
desc => 'Input drawable' }
|
||||
);
|
||||
|
||||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
|
||||
GIMP_PDB_ITEM_CONTENT, error) &&
|
||||
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
|
||||
{
|
||||
GeglNode *node =
|
||||
gegl_node_new_child (NULL,
|
||||
"operation", "gegl:stretch-contrast-hsv",
|
||||
NULL);
|
||||
|
||||
gimp_drawable_apply_operation (drawable, progress,
|
||||
C_("undo-type", "Stretch Contrast HSV"),
|
||||
node);
|
||||
g_object_unref (node);
|
||||
}
|
||||
else
|
||||
success = FALSE;
|
||||
}
|
||||
CODE
|
||||
);
|
||||
}
|
||||
|
||||
sub plug_in_c_astretch {
|
||||
$blurb = 'Stretch contrast to cover the maximum possible range';
|
||||
|
||||
|
@ -1850,6 +1898,7 @@ CODE
|
|||
plug_in_antialias
|
||||
plug_in_autocrop
|
||||
plug_in_autocrop_layer
|
||||
plug_in_autostretch_hsv
|
||||
plug_in_c_astretch
|
||||
plug_in_colors_channel_mixer
|
||||
plug_in_colortoalpha
|
||||
|
|
Loading…
Reference in New Issue