[gimp/gimp-2-10] 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/gimp-2-10] app: save the accurate color in the colormap palette when possible.
- Date: Fri, 8 Mar 2019 14:22:53 +0000 (UTC)
commit 812a0f66890bd6b301836c62a25c96bc4a882134
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).
(cherry picked from commit f1cca8ee2e62a19a3603ecd1acc8cc9d8fdc344f)
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 8dd666af7f..8bf40a923a 100644
--- a/app/core/gimpimage-colormap.c
+++ b/app/core/gimpimage-colormap.c
@@ -41,8 +41,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 */
@@ -213,7 +214,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));
@@ -293,7 +294,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);
}
@@ -323,7 +324,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);
}
@@ -332,18 +333,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]