mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-03 17:33:25 +00:00
app: when creating a palette from an image, colors must be space-aware.
This commit is contained in:
parent
b6c1b20737
commit
91d3b51bf2
1 changed files with 25 additions and 15 deletions
|
@ -203,6 +203,7 @@ gimp_palette_import_create_image_palette (gpointer data,
|
|||
{
|
||||
GimpPalette *palette = user_data;
|
||||
ImgColors *color_tab = data;
|
||||
const Babl *format;
|
||||
gint n_colors;
|
||||
gchar *lab;
|
||||
GeglColor *color;
|
||||
|
@ -214,6 +215,8 @@ gimp_palette_import_create_image_palette (gpointer data,
|
|||
if (gimp_palette_get_n_colors (palette) >= n_colors)
|
||||
return;
|
||||
|
||||
format = gimp_palette_get_restriction (palette);
|
||||
|
||||
/* TRANSLATORS: the "%s" is an item title and "%u" is the number of
|
||||
occurrences for this item. */
|
||||
lab = g_strdup_printf (_("%s (occurs %u)"),
|
||||
|
@ -226,8 +229,7 @@ gimp_palette_import_create_image_palette (gpointer data,
|
|||
rgb[1] = (guchar) color_tab->g + (color_tab->g_adj / color_tab->count);
|
||||
rgb[2] = (guchar) color_tab->b + (color_tab->b_adj / color_tab->count);
|
||||
|
||||
/* TODO: what format should I use? */
|
||||
gegl_color_set_pixel (color, babl_format ("R'G'B' u8"), rgb);
|
||||
gegl_color_set_pixel (color, format, rgb);
|
||||
|
||||
gimp_palette_add_entry (palette, -1, lab, color);
|
||||
|
||||
|
@ -237,6 +239,7 @@ gimp_palette_import_create_image_palette (gpointer data,
|
|||
|
||||
static GimpPalette *
|
||||
gimp_palette_import_make_palette (GHashTable *table,
|
||||
const Babl *format,
|
||||
const gchar *palette_name,
|
||||
GimpContext *context,
|
||||
gint n_colors)
|
||||
|
@ -250,6 +253,7 @@ gimp_palette_import_make_palette (GHashTable *table,
|
|||
if (! table)
|
||||
return palette;
|
||||
|
||||
gimp_palette_restrict_format (palette, format);
|
||||
g_hash_table_foreach (table, gimp_palette_import_create_list, &list);
|
||||
list = g_slist_sort (list, gimp_palette_import_sort_colors);
|
||||
|
||||
|
@ -271,12 +275,15 @@ gimp_palette_import_make_palette (GHashTable *table,
|
|||
|
||||
g_slist_free (list);
|
||||
|
||||
gimp_palette_restrict_format (palette, NULL);
|
||||
|
||||
return palette;
|
||||
}
|
||||
|
||||
static GHashTable *
|
||||
gimp_palette_import_extract (GimpImage *image,
|
||||
GHashTable *colors,
|
||||
const Babl **format,
|
||||
GimpPickable *pickable,
|
||||
gint pickable_off_x,
|
||||
gint pickable_off_y,
|
||||
|
@ -292,32 +299,33 @@ gimp_palette_import_extract (GimpImage *image,
|
|||
GeglBufferIterator *iter;
|
||||
GeglRectangle *mask_roi = NULL;
|
||||
GeglRectangle rect = { x, y, width, height };
|
||||
const Babl *format;
|
||||
gint bpp;
|
||||
gint mask_bpp = 0;
|
||||
|
||||
buffer = gimp_pickable_get_buffer (pickable);
|
||||
format = babl_format ("R'G'B'A u8");
|
||||
if (*format == NULL)
|
||||
*format = babl_format_with_space ("R'G'B'A u8", gimp_image_get_layer_space (image));
|
||||
|
||||
iter = gegl_buffer_iterator_new (buffer, &rect, 0, format,
|
||||
iter = gegl_buffer_iterator_new (buffer, &rect, 0, *format,
|
||||
GEGL_ACCESS_READ, GEGL_ABYSS_NONE, 2);
|
||||
bpp = babl_format_get_bytes_per_pixel (format);
|
||||
bpp = babl_format_get_bytes_per_pixel (*format);
|
||||
|
||||
if (selection_only &&
|
||||
! gimp_channel_is_empty (gimp_image_get_mask (image)))
|
||||
{
|
||||
GimpDrawable *mask = GIMP_DRAWABLE (gimp_image_get_mask (image));
|
||||
const Babl *selection_format;
|
||||
|
||||
rect.x = x + pickable_off_x;
|
||||
rect.y = y + pickable_off_y;
|
||||
|
||||
buffer = gimp_drawable_get_buffer (mask);
|
||||
format = babl_format ("Y u8");
|
||||
selection_format = babl_format ("Y u8");
|
||||
|
||||
gegl_buffer_iterator_add (iter, buffer, &rect, 0, format,
|
||||
gegl_buffer_iterator_add (iter, buffer, &rect, 0, selection_format,
|
||||
GEGL_ACCESS_READ, GEGL_ABYSS_NONE);
|
||||
mask_roi = &iter->items[1].roi;
|
||||
mask_bpp = babl_format_get_bytes_per_pixel (format);
|
||||
mask_bpp = babl_format_get_bytes_per_pixel (selection_format);
|
||||
}
|
||||
|
||||
while (gegl_buffer_iterator_next (iter))
|
||||
|
@ -368,6 +376,7 @@ gimp_palette_import_from_image (GimpImage *image,
|
|||
gboolean selection_only)
|
||||
{
|
||||
GHashTable *colors;
|
||||
const Babl *format = NULL;
|
||||
gint x, y;
|
||||
gint width, height;
|
||||
|
||||
|
@ -393,15 +402,15 @@ gimp_palette_import_from_image (GimpImage *image,
|
|||
}
|
||||
|
||||
colors = gimp_palette_import_extract (image,
|
||||
NULL,
|
||||
NULL, &format,
|
||||
GIMP_PICKABLE (image),
|
||||
0, 0,
|
||||
selection_only,
|
||||
x, y, width, height,
|
||||
n_colors, threshold);
|
||||
|
||||
return gimp_palette_import_make_palette (colors, palette_name, context,
|
||||
n_colors);
|
||||
return gimp_palette_import_make_palette (colors, format, palette_name,
|
||||
context, n_colors);
|
||||
}
|
||||
|
||||
|
||||
|
@ -438,6 +447,7 @@ gimp_palette_import_from_drawables (GList *drawables,
|
|||
gboolean selection_only)
|
||||
{
|
||||
GHashTable *colors = NULL;
|
||||
const Babl *format = NULL;
|
||||
GList *iter;
|
||||
gint x, y;
|
||||
gint width, height;
|
||||
|
@ -473,7 +483,7 @@ gimp_palette_import_from_drawables (GList *drawables,
|
|||
|
||||
colors =
|
||||
gimp_palette_import_extract (gimp_item_get_image (GIMP_ITEM (drawable)),
|
||||
colors,
|
||||
colors, &format,
|
||||
GIMP_PICKABLE (drawable),
|
||||
off_x, off_y,
|
||||
selection_only,
|
||||
|
@ -481,8 +491,8 @@ gimp_palette_import_from_drawables (GList *drawables,
|
|||
n_colors, threshold);
|
||||
}
|
||||
|
||||
return gimp_palette_import_make_palette (colors, palette_name, context,
|
||||
n_colors);
|
||||
return gimp_palette_import_make_palette (colors, format, palette_name,
|
||||
context, n_colors);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue