From 3bfda4f1191da72946e555394a3de567e5a67a31 Mon Sep 17 00:00:00 2001 From: Jehan Date: Mon, 23 Sep 2024 16:21:24 +0200 Subject: [PATCH] Issue #9477: remove gimp_image_[gs]et_colormap() from libgimp API. They are now replaced by the more generic gimp_palette_[gs]et_colormap(), hence making less of a particular concept of "image colormap". It's just a palette attached to the image (and restricted to the image format). --- app/pdb/image-cmds.c | 127 +--------------------------------- app/pdb/internal-procs.c | 2 +- libgimp/gimp.def | 2 - libgimp/gimpdrawable.c | 11 ++- libgimp/gimpdrawablepreview.c | 2 +- libgimp/gimpexportoptions.c | 2 +- libgimp/gimpimage.c | 64 ----------------- libgimp/gimpimage.h | 7 -- libgimp/gimpimage_pdb.c | 90 ++---------------------- libgimp/gimpimage_pdb.h | 3 - pdb/groups/image.pdb | 84 ++-------------------- 11 files changed, 21 insertions(+), 373 deletions(-) diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c index f724940b52..099d4b26f6 100644 --- a/app/pdb/image-cmds.c +++ b/app/pdb/image-cmds.c @@ -1679,69 +1679,6 @@ image_merge_down_invoker (GimpProcedure *procedure, return return_vals; } -static GimpValueArray * -image_get_colormap_invoker (GimpProcedure *procedure, - Gimp *gimp, - GimpContext *context, - GimpProgress *progress, - const GimpValueArray *args, - GError **error) -{ - gboolean success = TRUE; - GimpValueArray *return_vals; - GimpImage *image; - GBytes *colormap = NULL; - - image = g_value_get_object (gimp_value_array_index (args, 0)); - - if (success) - { - guchar *colormap_data; - gint n_colors; - - if (gimp_image_get_base_type (image) == GIMP_INDEXED) - { - colormap_data = _gimp_image_get_colormap (image, &n_colors); - colormap = g_bytes_new_take (colormap_data, 3 * n_colors); - } - } - - return_vals = gimp_procedure_get_return_values (procedure, success, - error ? *error : NULL); - - if (success) - g_value_take_boxed (gimp_value_array_index (return_vals, 1), colormap); - - return return_vals; -} - -static GimpValueArray * -image_set_colormap_invoker (GimpProcedure *procedure, - Gimp *gimp, - GimpContext *context, - GimpProgress *progress, - const GimpValueArray *args, - GError **error) -{ - gboolean success = TRUE; - GimpImage *image; - GBytes *colormap; - - image = g_value_get_object (gimp_value_array_index (args, 0)); - colormap = g_value_get_boxed (gimp_value_array_index (args, 1)); - - if (success) - { - _gimp_image_set_colormap (image, - g_bytes_get_data (colormap, NULL), - g_bytes_get_size (colormap) / 3, - TRUE); - } - - return gimp_procedure_get_return_values (procedure, success, - error ? *error : NULL); -} - static GimpValueArray * image_get_palette_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -3244,7 +3181,7 @@ register_image_procs (GimpPDB *pdb) "Creates a new image with the specified width, height, and type.", "Creates a new image, undisplayed, with the specified extents and type. A layer should be created and added before this image is displayed, or subsequent calls to 'gimp-display-new' with this image as an argument will fail. Layers can be created using the 'gimp-layer-new' commands. They can be added to an image using the 'gimp-image-insert-layer' command.\n" "\n" - "If your image's type if INDEXED, a colormap must also be added with 'gimp-image-set-colormap'. An indexed image without a colormap will output unexpected colors.", + "If your image's type if INDEXED, a palette must also be set with [method@Gimp.Image.set_palette]. An indexed image without a palette will output unexpected colors.", NULL); gimp_procedure_set_static_attribution (procedure, "Spencer Kimball & Peter Mattis", @@ -4676,64 +4613,6 @@ register_image_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); - /* - * gimp-image-get-colormap - */ - procedure = gimp_procedure_new (image_get_colormap_invoker); - gimp_object_set_static_name (GIMP_OBJECT (procedure), - "gimp-image-get-colormap"); - gimp_procedure_set_static_help (procedure, - "Returns the image's colormap", - "This procedure returns an actual pointer to the image's colormap, as well as the number of bytes contained in the colormap. The actual number of colors in the transmitted colormap will be 'num-bytes' / 3. If the image is not in Indexed color mode, no colormap is returned.", - NULL); - gimp_procedure_set_static_attribution (procedure, - "Spencer Kimball & Peter Mattis", - "Spencer Kimball & Peter Mattis", - "1995-1996"); - gimp_procedure_add_argument (procedure, - gimp_param_spec_image ("image", - "image", - "The image", - FALSE, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_return_value (procedure, - g_param_spec_boxed ("colormap", - "colormap", - "The image's colormap.", - G_TYPE_BYTES, - GIMP_PARAM_READWRITE)); - gimp_pdb_register_procedure (pdb, procedure); - g_object_unref (procedure); - - /* - * gimp-image-set-colormap - */ - procedure = gimp_procedure_new (image_set_colormap_invoker); - gimp_object_set_static_name (GIMP_OBJECT (procedure), - "gimp-image-set-colormap"); - gimp_procedure_set_static_help (procedure, - "Sets the entries in the image's colormap.", - "This procedure sets the entries in the specified image's colormap. The number of entries is specified by the 'num-bytes' parameter and corresponds to the number of INT8 triples that must be contained in the 'colormap' array. The actual number of colors in the transmitted colormap is 'num-bytes' / 3.", - NULL); - gimp_procedure_set_static_attribution (procedure, - "Spencer Kimball & Peter Mattis", - "Spencer Kimball & Peter Mattis", - "1995-1996"); - gimp_procedure_add_argument (procedure, - gimp_param_spec_image ("image", - "image", - "The image", - FALSE, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_argument (procedure, - g_param_spec_boxed ("colormap", - "colormap", - "The new colormap values", - G_TYPE_BYTES, - GIMP_PARAM_READWRITE)); - gimp_pdb_register_procedure (pdb, procedure); - g_object_unref (procedure); - /* * gimp-image-get-palette */ @@ -4742,7 +4621,7 @@ register_image_procs (GimpPDB *pdb) "gimp-image-get-palette"); gimp_procedure_set_static_help (procedure, "Returns the image's colormap", - "This procedure returns the image's colormap as a GimpPalette. If the image is not in Indexed color mode, %NULL is returned.", + "This procedure returns the image's colormap as a %GimpPalette. If the image is not in Indexed color mode, %NULL is returned.", NULL); gimp_procedure_set_static_attribution (procedure, "Jehan", @@ -4773,7 +4652,7 @@ register_image_procs (GimpPDB *pdb) "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" + "This procedure changes the image's colormap to an exact copy of @palette and returns the 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, diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c index a70062d34f..bdb3648066 100644 --- a/app/pdb/internal-procs.c +++ b/app/pdb/internal-procs.c @@ -30,7 +30,7 @@ #include "internal-procs.h" -/* 781 procedures registered total */ +/* 779 procedures registered total */ void internal_procs_init (GimpPDB *pdb) diff --git a/libgimp/gimp.def b/libgimp/gimp.def index 2a7e9a4e35..07db2b4eb3 100644 --- a/libgimp/gimp.def +++ b/libgimp/gimp.def @@ -413,7 +413,6 @@ EXPORTS gimp_image_get_channel_by_tattoo gimp_image_get_channels gimp_image_get_color_profile - gimp_image_get_colormap gimp_image_get_component_active gimp_image_get_component_visible gimp_image_get_default_new_layer_mode @@ -518,7 +517,6 @@ EXPORTS gimp_image_select_round_rectangle gimp_image_set_color_profile gimp_image_set_color_profile_from_file - gimp_image_set_colormap gimp_image_set_component_active gimp_image_set_component_visible gimp_image_set_file diff --git a/libgimp/gimpdrawable.c b/libgimp/gimpdrawable.c index f9cf85deb5..a08f2f0981 100644 --- a/libgimp/gimpdrawable.c +++ b/libgimp/gimpdrawable.c @@ -378,8 +378,9 @@ gimp_drawable_get_format (GimpDrawable *drawable) { const Babl *palette; const Babl *palette_alpha; + const Babl *color_format; guchar *colormap; - gint colormap_len, n_colors; + gint n_colors; babl_new_palette_with_space (format_str, space, &palette, &palette_alpha); @@ -389,14 +390,12 @@ gimp_drawable_get_format (GimpDrawable *drawable) else format = palette; - colormap = gimp_image_get_colormap (image, &colormap_len, &n_colors); + color_format = babl_format_with_space ("R'G'B' u8", space); + colormap = gimp_palette_get_colormap (gimp_image_get_palette (image), color_format, &n_colors, NULL); if (colormap) { - babl_palette_set_palette (format, - babl_format_with_space ("R'G'B' u8", - space), - colormap, n_colors); + babl_palette_set_palette (format, color_format, colormap, n_colors); g_free (colormap); } } diff --git a/libgimp/gimpdrawablepreview.c b/libgimp/gimpdrawablepreview.c index a6b47e46ff..0f67df01c0 100644 --- a/libgimp/gimpdrawablepreview.c +++ b/libgimp/gimpdrawablepreview.c @@ -557,7 +557,7 @@ gimp_drawable_preview_set_drawable (GimpDrawablePreview *drawable_preview, guchar *cmap; gint num_colors; - cmap = gimp_image_get_colormap (image, NULL, &num_colors); + cmap = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &num_colors, NULL); gimp_preview_area_set_colormap (GIMP_PREVIEW_AREA (area), cmap, num_colors); g_free (cmap); diff --git a/libgimp/gimpexportoptions.c b/libgimp/gimpexportoptions.c index 5ffae2a1b1..f43d32c7d1 100644 --- a/libgimp/gimpexportoptions.c +++ b/libgimp/gimpexportoptions.c @@ -831,7 +831,7 @@ gimp_export_options_get_image (GimpExportOptions *options, { gint n_colors; - g_free (gimp_image_get_colormap (*image, NULL, &n_colors)); + n_colors = gimp_palette_get_color_count (gimp_image_get_palette (*image)); if (n_colors > 2) actions = g_slist_prepend (actions, diff --git a/libgimp/gimpimage.c b/libgimp/gimpimage.c index 700955c403..22251f45a0 100644 --- a/libgimp/gimpimage.c +++ b/libgimp/gimpimage.c @@ -561,70 +561,6 @@ gimp_image_list_selected_drawables (GimpImage *image) return g_list_reverse (list); } -/** - * gimp_image_get_colormap: - * @image: The image. - * @colormap_len: (out) (optional): The size (in bytes) of the returned colormap - * @num_colors: (out) (optional): Returns the number of colors in the colormap array. - * - * Returns the image's colormap - * - * This procedure returns an actual pointer to the image's colormap, as - * well as the number of colors contained in the colormap. If the image - * is not of base type INDEXED, this pointer will be NULL. - * - * Returns: (array length=colormap_len): The image's colormap. - */ -guchar * -gimp_image_get_colormap (GimpImage *image, - gint *colormap_len, - gint *num_colors) -{ - GBytes *bytes; - gsize num_bytes; - guchar *cmap; - - bytes = _gimp_image_get_colormap (image); - cmap = g_bytes_unref_to_data (bytes, &num_bytes); - - if (colormap_len) - *colormap_len = num_bytes; - if (num_colors) - *num_colors = num_bytes / 3; - - return cmap; -} - -/** - * gimp_image_set_colormap: - * @image: The image. - * @colormap: (array): The new colormap values. - * @num_colors: Number of colors in the colormap array. - * - * Sets the entries in the image's colormap. - * - * This procedure sets the entries in the specified image's colormap. - * The number of colors is specified by the "num_colors" parameter - * and corresponds to the number of INT8 triples that must be contained - * in the "cmap" array. - * - * Returns: TRUE on success. - */ -gboolean -gimp_image_set_colormap (GimpImage *image, - const guchar *colormap, - gint num_colors) -{ - GBytes *bytes; - gboolean ret; - - bytes = g_bytes_new_static (colormap, num_colors * 3); - ret = _gimp_image_set_colormap (image, bytes); - g_bytes_unref (bytes); - - return ret; -} - /** * gimp_image_get_thumbnail_data: * @image: The image. diff --git a/libgimp/gimpimage.h b/libgimp/gimpimage.h index bf29933832..ad709c35f3 100644 --- a/libgimp/gimpimage.h +++ b/libgimp/gimpimage.h @@ -58,13 +58,6 @@ gboolean gimp_image_take_selected_paths (GimpImage *image, GList * gimp_image_list_selected_drawables (GimpImage *image); -guchar * gimp_image_get_colormap (GimpImage *image, - gint *colormap_len, - gint *num_colors); -gboolean gimp_image_set_colormap (GimpImage *image, - const guchar *colormap, - gint num_colors); - GBytes * gimp_image_get_thumbnail_data (GimpImage *image, gint *width, gint *height, diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c index 63e700d946..931d9c4cf1 100644 --- a/libgimp/gimpimage_pdb.c +++ b/libgimp/gimpimage_pdb.c @@ -129,9 +129,9 @@ gimp_get_images (gint *num_images) * gimp_layer_new() commands. They can be added to an image using the * gimp_image_insert_layer() command. * - * If your image's type if INDEXED, a colormap must also be added with - * gimp_image_set_colormap(). An indexed image without a colormap will - * output unexpected colors. + * If your image's type if INDEXED, a palette must also be set with + * [method@Gimp.Image.set_palette]. An indexed image without a palette + * will output unexpected colors. * * Returns: (transfer none): The newly created image. **/ @@ -1912,92 +1912,14 @@ gimp_image_merge_down (GimpImage *image, return layer; } -/** - * _gimp_image_get_colormap: - * @image: The image. - * - * Returns the image's colormap - * - * This procedure returns an actual pointer to the image's colormap, as - * well as the number of bytes contained in the colormap. The actual - * number of colors in the transmitted colormap will be 'num-bytes' / - * 3. If the image is not in Indexed color mode, no colormap is - * returned. - * - * Returns: (transfer full): The image's colormap. - **/ -GBytes * -_gimp_image_get_colormap (GimpImage *image) -{ - GimpValueArray *args; - GimpValueArray *return_vals; - GBytes *colormap = NULL; - - args = gimp_value_array_new_from_types (NULL, - GIMP_TYPE_IMAGE, image, - G_TYPE_NONE); - - return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), - "gimp-image-get-colormap", - args); - gimp_value_array_unref (args); - - if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) - colormap = GIMP_VALUES_DUP_BYTES (return_vals, 1); - - gimp_value_array_unref (return_vals); - - return colormap; -} - -/** - * _gimp_image_set_colormap: - * @image: The image. - * @colormap: The new colormap values. - * - * Sets the entries in the image's colormap. - * - * This procedure sets the entries in the specified image's colormap. - * The number of entries is specified by the 'num-bytes' parameter and - * corresponds to the number of INT8 triples that must be contained in - * the 'colormap' array. The actual number of colors in the transmitted - * colormap is 'num-bytes' / 3. - * - * Returns: TRUE on success. - **/ -gboolean -_gimp_image_set_colormap (GimpImage *image, - GBytes *colormap) -{ - GimpValueArray *args; - GimpValueArray *return_vals; - gboolean success = TRUE; - - args = gimp_value_array_new_from_types (NULL, - GIMP_TYPE_IMAGE, image, - G_TYPE_BYTES, colormap, - G_TYPE_NONE); - - return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), - "gimp-image-set-colormap", - args); - gimp_value_array_unref (args); - - success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS; - - gimp_value_array_unref (return_vals); - - return success; -} - /** * gimp_image_get_palette: * @image: The image. * * Returns the image's colormap * - * This procedure returns the image's colormap as a GimpPalette. If the - * image is not in Indexed color mode, %NULL is returned. + * 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 palette. * @@ -2035,7 +1957,7 @@ gimp_image_get_palette (GimpImage *image) * 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. + * @palette and returns the palette of @image. * If the image is not in Indexed color mode, nothing happens and %NULL * is returned. * diff --git a/libgimp/gimpimage_pdb.h b/libgimp/gimpimage_pdb.h index 24b76f6b22..37cb911082 100644 --- a/libgimp/gimpimage_pdb.h +++ b/libgimp/gimpimage_pdb.h @@ -131,9 +131,6 @@ GimpLayer* gimp_image_merge_visible_layers (GimpImage GimpLayer* gimp_image_merge_down (GimpImage *image, GimpLayer *merge_layer, GimpMergeType merge_type); -G_GNUC_INTERNAL GBytes* _gimp_image_get_colormap (GimpImage *image); -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); diff --git a/pdb/groups/image.pdb b/pdb/groups/image.pdb index 9c9969a261..c37acd7c69 100644 --- a/pdb/groups/image.pdb +++ b/pdb/groups/image.pdb @@ -94,8 +94,8 @@ gimp_layer_new() commands. They can be added to an image using the gimp_image_insert_layer() command. -If your image's type if INDEXED, a colormap must also be added with -gimp_image_set_colormap(). An indexed image without a colormap will +If your image's type if INDEXED, a palette must also be set with +[method@Gimp.Image.set_palette]. An indexed image without a palette will output unexpected colors. HELP @@ -1658,86 +1658,11 @@ CODE ); } -sub image_get_colormap { - $blurb = "Returns the image's colormap"; - - $help = <<'HELP'; -This procedure returns an actual pointer to the image's colormap, as well as -the number of bytes contained in the colormap. The actual number of colors in -the transmitted colormap will be 'num-bytes' / 3. If the image is not in -Indexed color mode, no colormap is returned. -HELP - - &std_pdb_misc; - - $lib_private = 1; - - @inargs = ( - { name => 'image', type => 'image', - desc => 'The image' } - ); - - @outargs = ( - { name => 'colormap', type => 'bytes', - desc => "The image's colormap." } - ); - - %invoke = ( - headers => [ qw("core/gimpimage-colormap.h") ], - code => <<'CODE' -{ - guchar *colormap_data; - gint n_colors; - - if (gimp_image_get_base_type (image) == GIMP_INDEXED) - { - colormap_data = _gimp_image_get_colormap (image, &n_colors); - colormap = g_bytes_new_take (colormap_data, 3 * n_colors); - } -} -CODE - ); -} - -sub image_set_colormap { - $blurb = "Sets the entries in the image's colormap."; - - $help = <<'HELP'; -This procedure sets the entries in the specified image's colormap. The number -of entries is specified by the 'num-bytes' parameter and corresponds to the -number of INT8 triples that must be contained in the 'colormap' array. The -actual number of colors in the transmitted colormap is 'num-bytes' / 3. -HELP - - &std_pdb_misc; - - $lib_private = 1; - - @inargs = ( - { name => 'image', type => 'image', - desc => 'The image' }, - { name => 'colormap', type => 'bytes', - desc => 'The new colormap values' } - ); - - %invoke = ( - headers => [ qw("core/gimpimage-colormap.h") ], - code => <<'CODE' -{ - _gimp_image_set_colormap (image, - g_bytes_get_data (colormap, NULL), - g_bytes_get_size (colormap) / 3, - TRUE); -} -CODE - ); -} - sub image_get_palette { $blurb = "Returns the image's colormap"; $help = <<'HELP'; -This procedure returns the image's colormap as a GimpPalette. +This procedure returns the image's colormap as a %GimpPalette. If the image is not in Indexed color mode, %NULL is returned. HELP @@ -1768,7 +1693,7 @@ sub image_set_palette { $help = <<'HELP'; This procedure changes the image's colormap to an exact copy of @palette -and returns the new palette of @image. +and returns the palette of @image. If the image is not in Indexed color mode, nothing happens and %NULL is returned. @@ -3440,7 +3365,6 @@ CODE image_raise_item_to_top image_lower_item_to_bottom image_reorder_item image_flatten image_merge_visible_layers image_merge_down - image_get_colormap image_set_colormap image_get_palette image_set_palette image_get_metadata image_set_metadata image_clean_all image_is_dirty