app: GimpFgBgEditor displays the out-of-gamut color for indexed images.

If a color is not within the indexed image's palette, we can consider it
to be out-of-gamut too (the gamut of such image being its palette).

This is a first step towards fixing #2938. Basically currently opening
indexed images is not made obvious and you can end up thinking GIMP is
broken as when you try to paint with a given FG or BG color, you may get
a completely different color on the canvas. And it is not obvious to
realize why. Now at least, the FG/BG color will tell you when the color
you are trying to paint with is not within the accepted palette.
This commit is contained in:
Jehan 2019-02-13 15:19:07 +01:00
parent dbca709fe8
commit 7b4c96d03d
2 changed files with 48 additions and 5 deletions

View File

@ -35,7 +35,10 @@
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpimage-colormap.h"
#include "core/gimpmarshal.h"
#include "core/gimppalette.h"
#include "gimpdnd.h"
#include "gimpfgbgeditor.h"
@ -105,6 +108,8 @@ static void gimp_fg_bg_editor_drop_color (GtkWidget *widget,
static void gimp_fg_bg_editor_create_transform (GimpFgBgEditor *editor);
static void gimp_fg_bg_editor_destroy_transform (GimpFgBgEditor *editor);
static void gimp_fg_bg_editor_image_changed (GimpFgBgEditor *editor,
GimpImage *image);
G_DEFINE_TYPE (GimpFgBgEditor, gimp_fg_bg_editor, GTK_TYPE_EVENT_BOX)
@ -284,6 +289,7 @@ gimp_fg_bg_editor_draw (GtkWidget *widget,
{
GimpFgBgEditor *editor = GIMP_FG_BG_EDITOR (widget);
GtkStyleContext *style = gtk_widget_get_style_context (widget);
GimpPalette *colormap_palette = NULL;
GtkBorder border;
GtkBorder padding;
GdkRectangle rect;
@ -377,6 +383,10 @@ gimp_fg_bg_editor_draw (GtkWidget *widget,
if (! editor->transform)
gimp_fg_bg_editor_create_transform (editor);
if (gimp_context_get_image (editor->context) &&
gimp_image_get_base_type (gimp_context_get_image (editor->context)) == GIMP_INDEXED)
colormap_palette = gimp_image_get_colormap_palette (editor->active_image);
/* draw the background area */
rect.x = width - rect.width - border.right;
@ -401,10 +411,12 @@ gimp_fg_bg_editor_draw (GtkWidget *widget,
cairo_rectangle (cr, rect.x, rect.y, rect.width, rect.height);
cairo_fill (cr);
if (editor->color_config &&
(color.r < 0.0 || color.r > 1.0 ||
color.g < 0.0 || color.g > 1.0 ||
color.b < 0.0 || color.b > 1.0))
((color.r < 0.0 || color.r > 1.0 ||
color.g < 0.0 || color.g > 1.0 ||
color.b < 0.0 || color.b > 1.0) ||
(colormap_palette && ! gimp_palette_find_entry (colormap_palette, &color, NULL))))
{
GimpRGB color;
gint side = MIN (rect.width, rect.height) * 2 / 3;
@ -458,9 +470,10 @@ gimp_fg_bg_editor_draw (GtkWidget *widget,
cairo_fill (cr);
if (editor->color_config &&
(color.r < 0.0 || color.r > 1.0 ||
((color.r < 0.0 || color.r > 1.0 ||
color.g < 0.0 || color.g > 1.0 ||
color.b < 0.0 || color.b > 1.0))
color.b < 0.0 || color.b > 1.0) ||
(colormap_palette && ! gimp_palette_find_entry (colormap_palette, &color, NULL))))
{
GimpRGB color;
gint side = MIN (rect.width, rect.height) * 2 / 3;
@ -712,6 +725,9 @@ gimp_fg_bg_editor_set_context (GimpFgBgEditor *editor,
g_signal_handlers_disconnect_by_func (editor->context,
gtk_widget_queue_draw,
editor);
g_signal_handlers_disconnect_by_func (editor->context,
G_CALLBACK (gimp_fg_bg_editor_image_changed),
editor);
g_object_unref (editor->context);
g_signal_handlers_disconnect_by_func (editor->color_config,
@ -732,6 +748,9 @@ gimp_fg_bg_editor_set_context (GimpFgBgEditor *editor,
g_signal_connect_swapped (context, "background-changed",
G_CALLBACK (gtk_widget_queue_draw),
editor);
g_signal_connect_swapped (context, "image-changed",
G_CALLBACK (gimp_fg_bg_editor_image_changed),
editor);
editor->color_config = g_object_ref (context->gimp->config->color_management);
@ -835,3 +854,25 @@ gimp_fg_bg_editor_destroy_transform (GimpFgBgEditor *editor)
gtk_widget_queue_draw (GTK_WIDGET (editor));
}
static void
gimp_fg_bg_editor_image_changed (GimpFgBgEditor *editor,
GimpImage *image)
{
gtk_widget_queue_draw (GTK_WIDGET (editor));
if (editor->active_image)
g_signal_handlers_disconnect_by_func (editor->active_image,
G_CALLBACK (gtk_widget_queue_draw),
editor);
editor->active_image = image;
if (image)
{
g_signal_connect_swapped (image, "notify::base-type",
G_CALLBACK (gtk_widget_queue_draw),
editor);
g_signal_connect_swapped (image, "colormap-changed",
G_CALLBACK (gtk_widget_queue_draw),
editor);
}
}

View File

@ -52,6 +52,8 @@ struct _GimpFgBgEditor
GimpActiveColor active_color;
GimpImage *active_image;
GdkPixbuf *default_icon;
GdkPixbuf *swap_icon;