2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* Gradient Map plug-in
|
|
|
|
* Copyright (C) 1997 Eiichi Takamori <taka@ma1.seikyou.ne.jp>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06:05:25 +08:00
|
|
|
* (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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
|
2000-05-01 05:03:44 +08:00
|
|
|
#include "config.h"
|
2005-01-02 03:31:03 +08:00
|
|
|
#include <string.h>
|
2000-05-01 05:03:44 +08:00
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
|
1999-12-26 05:49:51 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-05-01 05:03:44 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Some useful macros */
|
2005-08-14 06:52:41 +08:00
|
|
|
#define GRADMAP_PROC "plug-in-gradmap"
|
|
|
|
#define PALETTEMAP_PROC "plug-in-palettemap"
|
2008-03-24 23:29:55 +08:00
|
|
|
#define PLUG_IN_BINARY "gradient-map"
|
2011-04-09 02:31:34 +08:00
|
|
|
#define PLUG_IN_ROLE "gimp-gradient-map"
|
2013-07-21 23:59:50 +08:00
|
|
|
#define NSAMPLES 2048
|
2003-01-31 05:58:11 +08:00
|
|
|
|
2005-01-02 03:31:03 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
GRADIENT_MODE = 1,
|
|
|
|
PALETTE_MODE
|
|
|
|
} MapMode;
|
|
|
|
|
2019-08-30 17:11:16 +08:00
|
|
|
|
|
|
|
typedef struct _Map Map;
|
|
|
|
typedef struct _MapClass MapClass;
|
|
|
|
|
|
|
|
struct _Map
|
|
|
|
{
|
|
|
|
GimpPlugIn parent_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _MapClass
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2019-08-30 17:11:16 +08:00
|
|
|
GimpPlugInClass parent_class;
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
2019-08-30 17:11:16 +08:00
|
|
|
|
|
|
|
#define MAP_TYPE (map_get_type ())
|
|
|
|
#define MAP (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAP_TYPE, Map))
|
|
|
|
|
|
|
|
GType map_get_type (void) G_GNUC_CONST;
|
|
|
|
|
|
|
|
static GList * map_query_procedures (GimpPlugIn *plug_in);
|
|
|
|
static GimpProcedure * map_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name);
|
|
|
|
|
|
|
|
static GimpValueArray * map_run (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
2021-04-02 08:55:46 +08:00
|
|
|
gint n_drawables,
|
|
|
|
GimpDrawable **drawables,
|
2019-08-30 17:11:16 +08:00
|
|
|
const GimpValueArray *args,
|
|
|
|
gpointer run_data);
|
|
|
|
|
|
|
|
static void map (GeglBuffer *buffer,
|
|
|
|
GeglBuffer *shadow_buffer,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
MapMode mode);
|
|
|
|
static gdouble * get_samples_gradient (GimpDrawable *drawable);
|
|
|
|
static gdouble * get_samples_palette (GimpDrawable *drawable);
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (Map, map, GIMP_TYPE_PLUG_IN)
|
|
|
|
|
|
|
|
GIMP_MAIN (MAP_TYPE)
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2019-08-30 17:11:16 +08:00
|
|
|
map_class_init (MapClass *klass)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2019-08-30 17:11:16 +08:00
|
|
|
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
|
|
|
|
|
|
|
plug_in_class->query_procedures = map_query_procedures;
|
|
|
|
plug_in_class->create_procedure = map_create_procedure;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-30 17:11:16 +08:00
|
|
|
map_init (Map *map)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2019-08-30 17:11:16 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-30 17:11:16 +08:00
|
|
|
static GList *
|
|
|
|
map_query_procedures (GimpPlugIn *plug_in)
|
|
|
|
{
|
|
|
|
GList *list = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-30 17:11:16 +08:00
|
|
|
list = g_list_append (list, g_strdup (GRADMAP_PROC));
|
|
|
|
list = g_list_append (list, g_strdup (PALETTEMAP_PROC));
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
1999-12-26 05:49:51 +08:00
|
|
|
|
2019-08-30 17:11:16 +08:00
|
|
|
static GimpProcedure *
|
|
|
|
map_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GimpProcedure *procedure = NULL;
|
|
|
|
|
|
|
|
if (! strcmp (name, GRADMAP_PROC))
|
|
|
|
{
|
2019-08-30 18:52:28 +08:00
|
|
|
procedure = gimp_image_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
2019-08-30 17:11:16 +08:00
|
|
|
map_run,
|
|
|
|
GINT_TO_POINTER (GRADIENT_MODE),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_procedure_set_image_types (procedure, "RGB*, GRAY*");
|
2021-04-02 08:55:46 +08:00
|
|
|
gimp_procedure_set_sensitivity_mask (procedure,
|
|
|
|
GIMP_PROCEDURE_SENSITIVE_DRAWABLE);
|
2019-08-30 17:11:16 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_menu_label (procedure, N_("_Gradient Map"));
|
|
|
|
gimp_procedure_add_menu_path (procedure, "<Image>/Colors/Map");
|
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
|
|
|
N_("Recolor the image using colors "
|
|
|
|
"from the active gradient"),
|
|
|
|
"This plug-in maps the contents of "
|
|
|
|
"the specified drawable with active "
|
|
|
|
"gradient. It calculates luminosity "
|
|
|
|
"of each pixel and replaces the pixel "
|
|
|
|
"by the sample of active gradient at "
|
|
|
|
"the position proportional to that "
|
|
|
|
"luminosity. Complete black pixel "
|
|
|
|
"becomes the leftmost color of the "
|
|
|
|
"gradient, and complete white becomes "
|
|
|
|
"the rightmost. Works on both "
|
|
|
|
"Grayscale and RGB image "
|
|
|
|
"with/without alpha channel.",
|
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Eiichi Takamori",
|
|
|
|
"Eiichi Takamori",
|
|
|
|
"1997");
|
|
|
|
}
|
|
|
|
else if (! strcmp (name, PALETTEMAP_PROC))
|
|
|
|
{
|
2019-08-30 18:52:28 +08:00
|
|
|
procedure = gimp_image_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
2019-08-30 17:11:16 +08:00
|
|
|
map_run,
|
|
|
|
GINT_TO_POINTER (PALETTE_MODE),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_procedure_set_image_types (procedure, "RGB*, GRAY*");
|
2021-04-02 08:55:46 +08:00
|
|
|
gimp_procedure_set_sensitivity_mask (procedure,
|
|
|
|
GIMP_PROCEDURE_SENSITIVE_DRAWABLE);
|
2019-08-30 17:11:16 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_menu_label (procedure, N_("_Palette Map"));
|
|
|
|
gimp_procedure_add_menu_path (procedure, "<Image>/Colors/Map");
|
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
|
|
|
N_("Recolor the image using colors "
|
|
|
|
"from the active palette"),
|
|
|
|
"This plug-in maps the contents of "
|
|
|
|
"the specified drawable with the "
|
|
|
|
"active palette. It calculates "
|
|
|
|
"luminosity of each pixel and "
|
|
|
|
"replaces the pixel by the palette "
|
|
|
|
"sample at the corresponding index. "
|
|
|
|
"A complete black pixel becomes the "
|
|
|
|
"lowest palette entry, and complete "
|
|
|
|
"white becomes the highest. Works on "
|
|
|
|
"both Grayscale and RGB image "
|
|
|
|
"with/without alpha channel.",
|
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Bill Skaggs",
|
|
|
|
"Bill Skaggs",
|
|
|
|
"2004");
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-30 17:11:16 +08:00
|
|
|
return procedure;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpValueArray *
|
2021-04-02 08:55:46 +08:00
|
|
|
map_run (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
|
|
|
gint n_drawables,
|
|
|
|
GimpDrawable **drawables,
|
|
|
|
const GimpValueArray *args,
|
|
|
|
gpointer run_data)
|
2019-08-30 17:11:16 +08:00
|
|
|
{
|
2021-04-02 08:55:46 +08:00
|
|
|
MapMode mode = GPOINTER_TO_INT (run_data);
|
|
|
|
GeglBuffer *shadow_buffer;
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
GimpDrawable *drawable;
|
2019-08-30 17:11:16 +08:00
|
|
|
|
|
|
|
INIT_I18N ();
|
|
|
|
gegl_init (NULL, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2021-04-02 08:55:46 +08:00
|
|
|
if (n_drawables != 1)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
g_set_error (&error, GIMP_PLUG_IN_ERROR, 0,
|
|
|
|
_("Procedure '%s' only works with one drawable."),
|
|
|
|
gimp_procedure_get_name (procedure));
|
|
|
|
|
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_CALLING_ERROR,
|
|
|
|
error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
drawable = drawables[0];
|
|
|
|
}
|
|
|
|
|
2019-08-30 17:11:16 +08:00
|
|
|
shadow_buffer = gimp_drawable_get_shadow_buffer (drawable);
|
|
|
|
buffer = gimp_drawable_get_buffer (drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-09-29 07:08:17 +08:00
|
|
|
/* Make sure that the drawable is gray or RGB color */
|
2019-08-30 17:11:16 +08:00
|
|
|
if (gimp_drawable_is_rgb (drawable) ||
|
|
|
|
gimp_drawable_is_gray (drawable))
|
2000-05-01 05:03:44 +08:00
|
|
|
{
|
2019-08-30 17:11:16 +08:00
|
|
|
if (mode == GRADIENT_MODE)
|
2005-01-02 03:31:03 +08:00
|
|
|
{
|
2005-09-30 16:16:10 +08:00
|
|
|
gimp_progress_init (_("Gradient Map"));
|
2005-01-02 03:31:03 +08:00
|
|
|
}
|
|
|
|
else
|
2005-08-14 06:52:41 +08:00
|
|
|
{
|
2019-08-30 17:11:16 +08:00
|
|
|
gimp_progress_init (_("Palette Map"));
|
2005-08-14 06:52:41 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-30 17:11:16 +08:00
|
|
|
map (buffer, shadow_buffer, drawable, mode);
|
2000-05-01 05:03:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-30 17:11:16 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_EXECUTION_ERROR,
|
|
|
|
NULL);
|
2000-05-01 05:03:44 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2013-07-21 23:59:50 +08:00
|
|
|
g_object_unref (buffer);
|
|
|
|
g_object_unref (shadow_buffer);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-30 17:11:16 +08:00
|
|
|
gimp_drawable_merge_shadow (drawable, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-30 17:11:16 +08:00
|
|
|
gimp_drawable_update (drawable, 0, 0,
|
2021-04-06 20:28:40 +08:00
|
|
|
gimp_drawable_get_width (drawable),
|
|
|
|
gimp_drawable_get_height (drawable));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2013-07-21 23:59:50 +08:00
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
|
|
|
gimp_displays_flush ();
|
2019-08-30 17:11:16 +08:00
|
|
|
|
|
|
|
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
|
2003-01-31 05:58:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-07-21 23:59:50 +08:00
|
|
|
map (GeglBuffer *buffer,
|
|
|
|
GeglBuffer *shadow_buffer,
|
2019-08-30 17:11:16 +08:00
|
|
|
GimpDrawable *drawable,
|
2005-01-02 03:31:03 +08:00
|
|
|
MapMode mode)
|
2003-01-31 05:58:11 +08:00
|
|
|
{
|
2013-07-21 23:59:50 +08:00
|
|
|
GeglBufferIterator *gi;
|
|
|
|
gint nb_color_chan;
|
|
|
|
gint nb_chan;
|
|
|
|
gint nb_chan2;
|
|
|
|
gint nb_chan_samp;
|
|
|
|
gint index_iter;
|
|
|
|
gboolean interpolate;
|
|
|
|
gdouble *samples;
|
|
|
|
gboolean is_rgb;
|
|
|
|
gboolean has_alpha;
|
|
|
|
const Babl *format_shadow;
|
|
|
|
const Babl *format_buffer;
|
|
|
|
|
2019-08-30 17:11:16 +08:00
|
|
|
is_rgb = gimp_drawable_is_rgb (drawable);
|
|
|
|
has_alpha = gimp_drawable_has_alpha (drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-01-02 03:31:03 +08:00
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case GRADIENT_MODE:
|
2019-08-30 17:11:16 +08:00
|
|
|
samples = get_samples_gradient (drawable);
|
2013-07-21 23:59:50 +08:00
|
|
|
interpolate = TRUE;
|
2005-01-02 03:31:03 +08:00
|
|
|
break;
|
|
|
|
case PALETTE_MODE:
|
2019-08-30 17:11:16 +08:00
|
|
|
samples = get_samples_palette (drawable);
|
2013-07-21 23:59:50 +08:00
|
|
|
interpolate = FALSE;
|
2005-01-02 03:31:03 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_error ("plug_in_gradmap: invalid mode");
|
|
|
|
}
|
|
|
|
|
2013-07-21 23:59:50 +08:00
|
|
|
if (is_rgb)
|
|
|
|
{
|
|
|
|
nb_color_chan = 3;
|
|
|
|
nb_chan_samp = 4;
|
|
|
|
if (has_alpha)
|
|
|
|
format_shadow = babl_format ("R'G'B'A float");
|
|
|
|
else
|
|
|
|
format_shadow = babl_format ("R'G'B' float");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nb_color_chan = 1;
|
|
|
|
nb_chan_samp = 2;
|
|
|
|
if (has_alpha)
|
|
|
|
format_shadow = babl_format ("Y'A float");
|
|
|
|
else
|
|
|
|
format_shadow = babl_format ("Y' float");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (has_alpha)
|
|
|
|
{
|
|
|
|
nb_chan = nb_color_chan + 1;
|
|
|
|
nb_chan2 = 2;
|
|
|
|
format_buffer = babl_format ("Y'A float");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nb_chan = nb_color_chan;
|
|
|
|
nb_chan2 = 1;
|
|
|
|
format_buffer = babl_format ("Y' float");
|
|
|
|
}
|
|
|
|
|
|
|
|
gi = gegl_buffer_iterator_new (shadow_buffer, NULL, 0, format_shadow,
|
2018-09-11 08:02:13 +08:00
|
|
|
GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE, 2);
|
2013-07-21 23:59:50 +08:00
|
|
|
|
|
|
|
index_iter = gegl_buffer_iterator_add (gi, buffer, NULL,
|
|
|
|
0, format_buffer,
|
2014-07-02 08:00:35 +08:00
|
|
|
GEGL_ACCESS_READ, GEGL_ABYSS_NONE);
|
2013-07-21 23:59:50 +08:00
|
|
|
|
|
|
|
while (gegl_buffer_iterator_next (gi))
|
|
|
|
{
|
|
|
|
guint k;
|
|
|
|
gfloat *data;
|
|
|
|
gfloat *data2;
|
|
|
|
|
2018-09-11 08:02:13 +08:00
|
|
|
data = (gfloat*) gi->items[0].data;
|
|
|
|
data2 = (gfloat*) gi->items[index_iter].data;
|
2013-07-21 23:59:50 +08:00
|
|
|
|
|
|
|
if (interpolate)
|
|
|
|
{
|
|
|
|
for (k = 0; k < gi->length; k++)
|
|
|
|
{
|
|
|
|
gint b, ind1, ind2;
|
|
|
|
gdouble *samp1, *samp2;
|
|
|
|
gfloat c1, c2, val;
|
|
|
|
|
|
|
|
val = data2[0] * (NSAMPLES-1);
|
|
|
|
|
|
|
|
ind1 = CLAMP (floor (val), 0, NSAMPLES-1);
|
|
|
|
ind2 = CLAMP (ceil (val), 0, NSAMPLES-1);
|
|
|
|
|
|
|
|
c1 = 1.0 - (val - ind1);
|
|
|
|
c2 = 1.0 - c1;
|
|
|
|
|
|
|
|
samp1 = &(samples[ind1 * nb_chan_samp]);
|
|
|
|
samp2 = &(samples[ind2 * nb_chan_samp]);
|
|
|
|
|
|
|
|
for (b = 0; b < nb_color_chan; b++)
|
|
|
|
data[b] = (samp1[b] * c1 + samp2[b] * c2);
|
|
|
|
|
|
|
|
if (has_alpha)
|
|
|
|
{
|
|
|
|
float alpha = (samp1[b] * c1 + samp2[b] * c2);
|
|
|
|
data[b] = alpha * data2[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
data += nb_chan;
|
|
|
|
data2 += nb_chan2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (k = 0; k < gi->length; k++)
|
|
|
|
{
|
|
|
|
gint b, ind;
|
|
|
|
gdouble *samp;
|
|
|
|
ind = CLAMP (data2[0] * (NSAMPLES-1), 0, NSAMPLES-1);
|
|
|
|
|
|
|
|
samp = &(samples[ind * nb_chan_samp]);
|
|
|
|
|
|
|
|
for (b = 0; b < nb_color_chan; b++)
|
|
|
|
data[b] = samp[b];
|
|
|
|
|
|
|
|
if (has_alpha)
|
|
|
|
{
|
|
|
|
data[b] = samp[b] * data2[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
data += nb_chan;
|
|
|
|
data2 += nb_chan2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (samples);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-07-21 23:59:50 +08:00
|
|
|
Returns 2048 samples of the gradient.
|
|
|
|
Each sample is (R'G'B'A float) or (Y'A float), depending on the drawable
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2013-07-21 23:59:50 +08:00
|
|
|
static gdouble *
|
2019-08-30 17:11:16 +08:00
|
|
|
get_samples_gradient (GimpDrawable *drawable)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-10-06 07:28:17 +08:00
|
|
|
gchar *gradient_name;
|
2013-07-21 23:59:50 +08:00
|
|
|
gint n_d_samples;
|
|
|
|
gdouble *d_samples = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-10-06 07:28:17 +08:00
|
|
|
gradient_name = gimp_context_get_gradient ();
|
|
|
|
|
2009-07-20 17:53:02 +08:00
|
|
|
/* FIXME: "reverse" hardcoded to FALSE. */
|
2004-10-06 07:28:17 +08:00
|
|
|
gimp_gradient_get_uniform_samples (gradient_name, NSAMPLES, FALSE,
|
2013-07-21 23:59:50 +08:00
|
|
|
&n_d_samples, &d_samples);
|
2011-05-07 09:14:22 +08:00
|
|
|
g_free (gradient_name);
|
|
|
|
|
2019-08-30 17:11:16 +08:00
|
|
|
if (! gimp_drawable_is_rgb (drawable))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2013-07-21 23:59:50 +08:00
|
|
|
const Babl *format_src = babl_format ("R'G'B'A double");
|
|
|
|
const Babl *format_dst = babl_format ("Y'A double");
|
|
|
|
const Babl *fish = babl_fish (format_src, format_dst);
|
2019-08-30 17:11:16 +08:00
|
|
|
|
2013-07-21 23:59:50 +08:00
|
|
|
babl_process (fish, d_samples, d_samples, NSAMPLES);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2013-07-21 23:59:50 +08:00
|
|
|
return d_samples;
|
2005-01-02 03:31:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-07-21 23:59:50 +08:00
|
|
|
Returns 2048 samples of the palette.
|
|
|
|
Each sample is (R'G'B'A float) or (Y'A float), depending on the drawable
|
2005-01-02 03:31:03 +08:00
|
|
|
*/
|
2013-07-21 23:59:50 +08:00
|
|
|
static gdouble *
|
2019-08-30 17:11:16 +08:00
|
|
|
get_samples_palette (GimpDrawable *drawable)
|
2005-01-02 03:31:03 +08:00
|
|
|
{
|
2013-07-21 23:59:50 +08:00
|
|
|
gchar *palette_name;
|
|
|
|
GimpRGB color_sample;
|
|
|
|
gdouble *d_samples, *d_samp;
|
|
|
|
gboolean is_rgb;
|
|
|
|
gdouble factor;
|
|
|
|
gint pal_entry, num_colors;
|
|
|
|
gint nb_color_chan, nb_chan, i;
|
|
|
|
const Babl *format;
|
2005-01-02 03:31:03 +08:00
|
|
|
|
|
|
|
palette_name = gimp_context_get_palette ();
|
|
|
|
gimp_palette_get_info (palette_name, &num_colors);
|
|
|
|
|
2019-08-30 17:11:16 +08:00
|
|
|
is_rgb = gimp_drawable_is_rgb (drawable);
|
2005-01-02 03:31:03 +08:00
|
|
|
|
2013-07-21 23:59:50 +08:00
|
|
|
factor = ((double) num_colors) / NSAMPLES;
|
|
|
|
format = is_rgb ? babl_format ("R'G'B'A double") : babl_format ("Y'A double");
|
|
|
|
nb_color_chan = is_rgb ? 3 : 1;
|
|
|
|
nb_chan = nb_color_chan + 1;
|
|
|
|
|
|
|
|
d_samples = g_new (gdouble, NSAMPLES * nb_chan);
|
2005-01-02 03:31:03 +08:00
|
|
|
|
|
|
|
for (i = 0; i < NSAMPLES; i++)
|
|
|
|
{
|
2013-07-21 23:59:50 +08:00
|
|
|
d_samp = &d_samples[i * nb_chan];
|
|
|
|
pal_entry = CLAMP ((int)(i * factor), 0, num_colors - 1);
|
2005-01-02 03:31:03 +08:00
|
|
|
|
2005-08-28 02:09:20 +08:00
|
|
|
gimp_palette_entry_get_color (palette_name, pal_entry, &color_sample);
|
2013-07-21 23:59:50 +08:00
|
|
|
gimp_rgb_get_pixel (&color_sample,
|
|
|
|
format,
|
|
|
|
d_samp);
|
2005-01-02 03:31:03 +08:00
|
|
|
}
|
|
|
|
|
2013-07-21 23:59:50 +08:00
|
|
|
g_free (palette_name);
|
|
|
|
return d_samples;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|