app, libgimp, pdb: new gimp_image_set_palette() procedure.
When we want to set a full palette based on an existing one, no need to request the full colormap from core to libgimp then back. Just set the palette which is nothing more than an empty shell around a resource ID.
This commit is contained in:
@ -1753,20 +1753,56 @@ image_get_palette_invoker (GimpProcedure *procedure,
|
||||
gboolean success = TRUE;
|
||||
GimpValueArray *return_vals;
|
||||
GimpImage *image;
|
||||
GimpPalette *colormap = NULL;
|
||||
GimpPalette *palette = NULL;
|
||||
|
||||
image = g_value_get_object (gimp_value_array_index (args, 0));
|
||||
|
||||
if (success)
|
||||
{
|
||||
colormap = gimp_image_get_colormap_palette (image);
|
||||
palette = gimp_image_get_colormap_palette (image);
|
||||
}
|
||||
|
||||
return_vals = gimp_procedure_get_return_values (procedure, success,
|
||||
error ? *error : NULL);
|
||||
|
||||
if (success)
|
||||
g_value_set_object (gimp_value_array_index (return_vals, 1), colormap);
|
||||
g_value_set_object (gimp_value_array_index (return_vals, 1), palette);
|
||||
|
||||
return return_vals;
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
image_set_palette_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
GimpContext *context,
|
||||
GimpProgress *progress,
|
||||
const GimpValueArray *args,
|
||||
GError **error)
|
||||
{
|
||||
gboolean success = TRUE;
|
||||
GimpValueArray *return_vals;
|
||||
GimpImage *image;
|
||||
GimpPalette *new_palette;
|
||||
GimpPalette *palette = NULL;
|
||||
|
||||
image = g_value_get_object (gimp_value_array_index (args, 0));
|
||||
new_palette = g_value_get_object (gimp_value_array_index (args, 1));
|
||||
|
||||
if (success)
|
||||
{
|
||||
palette = gimp_image_get_colormap_palette (image);
|
||||
|
||||
if (palette == NULL || new_palette == NULL)
|
||||
success = FALSE;
|
||||
else if (new_palette != palette)
|
||||
gimp_image_set_colormap_palette (image, new_palette, TRUE);
|
||||
}
|
||||
|
||||
return_vals = gimp_procedure_get_return_values (procedure, success,
|
||||
error ? *error : NULL);
|
||||
|
||||
if (success)
|
||||
g_value_set_object (gimp_value_array_index (return_vals, 1), palette);
|
||||
|
||||
return return_vals;
|
||||
}
|
||||
@ -4719,9 +4755,49 @@ register_image_procs (GimpPDB *pdb)
|
||||
FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_procedure_add_return_value (procedure,
|
||||
gimp_param_spec_palette ("colormap",
|
||||
"colormap",
|
||||
"The image's colormap.",
|
||||
gimp_param_spec_palette ("palette",
|
||||
"palette",
|
||||
"The image's colormap palette.",
|
||||
FALSE,
|
||||
NULL,
|
||||
FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_pdb_register_procedure (pdb, procedure);
|
||||
g_object_unref (procedure);
|
||||
|
||||
/*
|
||||
* gimp-image-set-palette
|
||||
*/
|
||||
procedure = gimp_procedure_new (image_set_palette_invoker);
|
||||
gimp_object_set_static_name (GIMP_OBJECT (procedure),
|
||||
"gimp-image-set-palette");
|
||||
gimp_procedure_set_static_help (procedure,
|
||||
"Set the image's colormap to a copy of",
|
||||
"This procedure changes the image's colormap to an exact copy of @palette and returns the new palette of @image.\n"
|
||||
"If the image is not in Indexed color mode, nothing happens and %NULL is returned.",
|
||||
NULL);
|
||||
gimp_procedure_set_static_attribution (procedure,
|
||||
"Jehan",
|
||||
"Jehan",
|
||||
"2024");
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_image ("image",
|
||||
"image",
|
||||
"The image",
|
||||
FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_palette ("new-palette",
|
||||
"new palette",
|
||||
"The palette to copy from.",
|
||||
FALSE,
|
||||
NULL,
|
||||
FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_procedure_add_return_value (procedure,
|
||||
gimp_param_spec_palette ("palette",
|
||||
"palette",
|
||||
"The image's colormap palette.",
|
||||
FALSE,
|
||||
NULL,
|
||||
FALSE,
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include "internal-procs.h"
|
||||
|
||||
|
||||
/* 780 procedures registered total */
|
||||
/* 781 procedures registered total */
|
||||
|
||||
void
|
||||
internal_procs_init (GimpPDB *pdb)
|
||||
|
@ -523,6 +523,7 @@ EXPORTS
|
||||
gimp_image_set_component_visible
|
||||
gimp_image_set_file
|
||||
gimp_image_set_metadata
|
||||
gimp_image_set_palette
|
||||
gimp_image_set_resolution
|
||||
gimp_image_set_selected_channels
|
||||
gimp_image_set_selected_layers
|
||||
|
@ -1999,7 +1999,7 @@ _gimp_image_set_colormap (GimpImage *image,
|
||||
* This procedure returns the image's colormap as a GimpPalette. If the
|
||||
* image is not in Indexed color mode, %NULL is returned.
|
||||
*
|
||||
* Returns: (transfer none): The image's colormap.
|
||||
* Returns: (transfer none): The image's colormap palette.
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
@ -2008,7 +2008,7 @@ gimp_image_get_palette (GimpImage *image)
|
||||
{
|
||||
GimpValueArray *args;
|
||||
GimpValueArray *return_vals;
|
||||
GimpPalette *colormap = NULL;
|
||||
GimpPalette *palette = NULL;
|
||||
|
||||
args = gimp_value_array_new_from_types (NULL,
|
||||
GIMP_TYPE_IMAGE, image,
|
||||
@ -2020,11 +2020,53 @@ gimp_image_get_palette (GimpImage *image)
|
||||
gimp_value_array_unref (args);
|
||||
|
||||
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
|
||||
colormap = GIMP_VALUES_GET_PALETTE (return_vals, 1);
|
||||
palette = GIMP_VALUES_GET_PALETTE (return_vals, 1);
|
||||
|
||||
gimp_value_array_unref (return_vals);
|
||||
|
||||
return colormap;
|
||||
return palette;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_image_set_palette:
|
||||
* @image: The image.
|
||||
* @new_palette: The palette to copy from.
|
||||
*
|
||||
* Set the image's colormap to a copy of
|
||||
*
|
||||
* This procedure changes the image's colormap to an exact copy of
|
||||
* @palette and returns the new palette of @image.
|
||||
* If the image is not in Indexed color mode, nothing happens and %NULL
|
||||
* is returned.
|
||||
*
|
||||
* Returns: (transfer none): The image's colormap palette.
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
GimpPalette *
|
||||
gimp_image_set_palette (GimpImage *image,
|
||||
GimpPalette *new_palette)
|
||||
{
|
||||
GimpValueArray *args;
|
||||
GimpValueArray *return_vals;
|
||||
GimpPalette *palette = NULL;
|
||||
|
||||
args = gimp_value_array_new_from_types (NULL,
|
||||
GIMP_TYPE_IMAGE, image,
|
||||
GIMP_TYPE_PALETTE, new_palette,
|
||||
G_TYPE_NONE);
|
||||
|
||||
return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (),
|
||||
"gimp-image-set-palette",
|
||||
args);
|
||||
gimp_value_array_unref (args);
|
||||
|
||||
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
|
||||
palette = GIMP_VALUES_GET_PALETTE (return_vals, 1);
|
||||
|
||||
gimp_value_array_unref (return_vals);
|
||||
|
||||
return palette;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -135,6 +135,8 @@ G_GNUC_INTERNAL GBytes* _gimp_image_get_colormap (GimpImage
|
||||
G_GNUC_INTERNAL gboolean _gimp_image_set_colormap (GimpImage *image,
|
||||
GBytes *colormap);
|
||||
GimpPalette* gimp_image_get_palette (GimpImage *image);
|
||||
GimpPalette* gimp_image_set_palette (GimpImage *image,
|
||||
GimpPalette *new_palette);
|
||||
G_GNUC_INTERNAL gchar* _gimp_image_get_metadata (GimpImage *image);
|
||||
G_GNUC_INTERNAL gboolean _gimp_image_set_metadata (GimpImage *image,
|
||||
const gchar *metadata_string);
|
||||
|
@ -1749,15 +1749,55 @@ HELP
|
||||
);
|
||||
|
||||
@outargs = (
|
||||
{ name => 'colormap', type => 'palette',
|
||||
desc => "The image's colormap." }
|
||||
{ name => 'palette', type => 'palette',
|
||||
desc => "The image's colormap palette." }
|
||||
);
|
||||
|
||||
%invoke = (
|
||||
headers => [ qw("core/gimpimage-colormap.h") ],
|
||||
code => <<'CODE'
|
||||
{
|
||||
colormap = gimp_image_get_colormap_palette (image);
|
||||
palette = gimp_image_get_colormap_palette (image);
|
||||
}
|
||||
CODE
|
||||
);
|
||||
}
|
||||
|
||||
sub image_set_palette {
|
||||
$blurb = "Set the image's colormap to a copy of @palette";
|
||||
|
||||
$help = <<'HELP';
|
||||
This procedure changes the image's colormap to an exact copy of @palette
|
||||
and returns the new palette of @image.
|
||||
|
||||
If the image is not in Indexed color mode, nothing happens and %NULL is
|
||||
returned.
|
||||
HELP
|
||||
|
||||
&jehan_pdb_misc('2024', '3.0');
|
||||
|
||||
@inargs = (
|
||||
{ name => 'image', type => 'image',
|
||||
desc => 'The image' },
|
||||
{ name => 'new_palette', type => 'palette',
|
||||
desc => "The palette to copy from." }
|
||||
);
|
||||
|
||||
@outargs = (
|
||||
{ name => 'palette', type => 'palette',
|
||||
desc => "The image's colormap palette." }
|
||||
);
|
||||
|
||||
%invoke = (
|
||||
headers => [ qw("core/gimpimage-colormap.h") ],
|
||||
code => <<'CODE'
|
||||
{
|
||||
palette = gimp_image_get_colormap_palette (image);
|
||||
|
||||
if (palette == NULL || new_palette == NULL)
|
||||
success = FALSE;
|
||||
else if (new_palette != palette)
|
||||
gimp_image_set_colormap_palette (image, new_palette, TRUE);
|
||||
}
|
||||
CODE
|
||||
);
|
||||
@ -3401,7 +3441,7 @@ CODE
|
||||
image_reorder_item
|
||||
image_flatten image_merge_visible_layers image_merge_down
|
||||
image_get_colormap image_set_colormap
|
||||
image_get_palette
|
||||
image_get_palette image_set_palette
|
||||
image_get_metadata image_set_metadata
|
||||
image_clean_all image_is_dirty
|
||||
image_thumbnail
|
||||
|
Reference in New Issue
Block a user