[gimp] app: save the accurate color in the colormap palette when possible.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: save the accurate color in the colormap palette when possible.
- Date: Wed, 6 Mar 2019 23:11:28 +0000 (UTC)
commit f1cca8ee2e62a19a3603ecd1acc8cc9d8fdc344f
Author: Jehan <jehan girinstud io>
Date: Thu Mar 7 00:02:56 2019 +0100
app: save the accurate color in the colormap palette when possible.
The colormap saves colors as unsigned char, which can be very inaccurate
compared to high precision colors. When adding colors from GimpRGB into
the colormap, use the original value to fill the colormap palette
instead of making a round trip conversion from double to uchar, then
back to double.
This also fixes a direct bug I encountered when adding the current
foreground color in the image colormap. Yet the GimpFgBgEditor or the
GimpColorHistory would still show the color out-of-gamut in cases when
the returned RGB after the roundtrip was not close enough to the
original RGB (even despite using an epsilon in GimpPalette code).
app/core/gimpimage-colormap.c | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)
---
diff --git a/app/core/gimpimage-colormap.c b/app/core/gimpimage-colormap.c
index 3a07fd6a9d..2762935674 100644
--- a/app/core/gimpimage-colormap.c
+++ b/app/core/gimpimage-colormap.c
@@ -43,8 +43,9 @@
/* local function prototype */
-static void gimp_image_colormap_set_palette_entry (GimpImage *image,
- gint index);
+static void gimp_image_colormap_set_palette_entry (GimpImage *image,
+ const GimpRGB *color,
+ gint index);
/* public functions */
@@ -244,7 +245,7 @@ gimp_image_set_colormap (GimpImage *image,
gimp_palette_delete_entry (private->palette, entry);
for (i = 0; i < private->n_colors; i++)
- gimp_image_colormap_set_palette_entry (image, i);
+ gimp_image_colormap_set_palette_entry (image, NULL, i);
gimp_data_thaw (GIMP_DATA (private->palette));
@@ -324,7 +325,7 @@ gimp_image_set_colormap_entry (GimpImage *image,
&private->colormap[color_index * 3 + 2]);
if (private->palette)
- gimp_image_colormap_set_palette_entry (image, color_index);
+ gimp_image_colormap_set_palette_entry (image, color, color_index);
gimp_image_colormap_changed (image, color_index);
}
@@ -354,7 +355,7 @@ gimp_image_add_colormap_entry (GimpImage *image,
private->n_colors++;
if (private->palette)
- gimp_image_colormap_set_palette_entry (image, private->n_colors - 1);
+ gimp_image_colormap_set_palette_entry (image, color, private->n_colors - 1);
gimp_image_colormap_changed (image, -1);
}
@@ -363,18 +364,25 @@ gimp_image_add_colormap_entry (GimpImage *image,
/* private functions */
static void
-gimp_image_colormap_set_palette_entry (GimpImage *image,
- gint index)
+gimp_image_colormap_set_palette_entry (GimpImage *image,
+ const GimpRGB *c,
+ gint index)
{
GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
GimpRGB color;
gchar name[64];
- gimp_rgba_set_uchar (&color,
- private->colormap[3 * index + 0],
- private->colormap[3 * index + 1],
- private->colormap[3 * index + 2],
- 255);
+ /* Avoid converting to char then back to double if we have the
+ * original GimpRGB color.
+ */
+ if (c)
+ color = *c;
+ else
+ gimp_rgba_set_uchar (&color,
+ private->colormap[3 * index + 0],
+ private->colormap[3 * index + 1],
+ private->colormap[3 * index + 2],
+ 255);
g_snprintf (name, sizeof (name), "#%d", index);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]