mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-04 09:53:25 +00:00
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.
(cherry picked from commit 7b4c96d03d
)
This commit is contained in:
parent
3fd78441ba
commit
e48c239459
2 changed files with 48 additions and 5 deletions
|
@ -35,7 +35,10 @@
|
||||||
|
|
||||||
#include "core/gimp.h"
|
#include "core/gimp.h"
|
||||||
#include "core/gimpcontext.h"
|
#include "core/gimpcontext.h"
|
||||||
|
#include "core/gimpimage.h"
|
||||||
|
#include "core/gimpimage-colormap.h"
|
||||||
#include "core/gimpmarshal.h"
|
#include "core/gimpmarshal.h"
|
||||||
|
#include "core/gimppalette.h"
|
||||||
|
|
||||||
#include "gimpdnd.h"
|
#include "gimpdnd.h"
|
||||||
#include "gimpfgbgeditor.h"
|
#include "gimpfgbgeditor.h"
|
||||||
|
@ -98,6 +101,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_create_transform (GimpFgBgEditor *editor);
|
||||||
static void gimp_fg_bg_editor_destroy_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)
|
G_DEFINE_TYPE (GimpFgBgEditor, gimp_fg_bg_editor, GTK_TYPE_EVENT_BOX)
|
||||||
|
|
||||||
|
@ -257,6 +262,7 @@ gimp_fg_bg_editor_expose (GtkWidget *widget,
|
||||||
GtkStyle *style = gtk_widget_get_style (widget);
|
GtkStyle *style = gtk_widget_get_style (widget);
|
||||||
GdkWindow *window = gtk_widget_get_window (widget);
|
GdkWindow *window = gtk_widget_get_window (widget);
|
||||||
cairo_t *cr;
|
cairo_t *cr;
|
||||||
|
GimpPalette *colormap_palette = NULL;
|
||||||
GtkAllocation allocation;
|
GtkAllocation allocation;
|
||||||
gint width, height;
|
gint width, height;
|
||||||
gint default_w, default_h;
|
gint default_w, default_h;
|
||||||
|
@ -331,6 +337,10 @@ gimp_fg_bg_editor_expose (GtkWidget *widget,
|
||||||
if (! editor->transform)
|
if (! editor->transform)
|
||||||
gimp_fg_bg_editor_create_transform (editor);
|
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 */
|
/* draw the background area */
|
||||||
|
|
||||||
if (editor->context)
|
if (editor->context)
|
||||||
|
@ -356,10 +366,12 @@ gimp_fg_bg_editor_expose (GtkWidget *widget,
|
||||||
rect_h);
|
rect_h);
|
||||||
cairo_fill (cr);
|
cairo_fill (cr);
|
||||||
|
|
||||||
|
|
||||||
if (editor->color_config &&
|
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.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))))
|
||||||
{
|
{
|
||||||
gint side = MIN (rect_w, rect_h) * 2 / 3;
|
gint side = MIN (rect_w, rect_h) * 2 / 3;
|
||||||
|
|
||||||
|
@ -407,9 +419,10 @@ gimp_fg_bg_editor_expose (GtkWidget *widget,
|
||||||
cairo_fill (cr);
|
cairo_fill (cr);
|
||||||
|
|
||||||
if (editor->color_config &&
|
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.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))))
|
||||||
{
|
{
|
||||||
gint side = MIN (rect_w, rect_h) * 2 / 3;
|
gint side = MIN (rect_w, rect_h) * 2 / 3;
|
||||||
|
|
||||||
|
@ -633,6 +646,9 @@ gimp_fg_bg_editor_set_context (GimpFgBgEditor *editor,
|
||||||
g_signal_handlers_disconnect_by_func (editor->context,
|
g_signal_handlers_disconnect_by_func (editor->context,
|
||||||
gtk_widget_queue_draw,
|
gtk_widget_queue_draw,
|
||||||
editor);
|
editor);
|
||||||
|
g_signal_handlers_disconnect_by_func (editor->context,
|
||||||
|
G_CALLBACK (gimp_fg_bg_editor_image_changed),
|
||||||
|
editor);
|
||||||
g_object_unref (editor->context);
|
g_object_unref (editor->context);
|
||||||
|
|
||||||
g_signal_handlers_disconnect_by_func (editor->color_config,
|
g_signal_handlers_disconnect_by_func (editor->color_config,
|
||||||
|
@ -653,6 +669,9 @@ gimp_fg_bg_editor_set_context (GimpFgBgEditor *editor,
|
||||||
g_signal_connect_swapped (context, "background-changed",
|
g_signal_connect_swapped (context, "background-changed",
|
||||||
G_CALLBACK (gtk_widget_queue_draw),
|
G_CALLBACK (gtk_widget_queue_draw),
|
||||||
editor);
|
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);
|
editor->color_config = g_object_ref (context->gimp->config->color_management);
|
||||||
|
|
||||||
|
@ -756,3 +775,25 @@ gimp_fg_bg_editor_destroy_transform (GimpFgBgEditor *editor)
|
||||||
|
|
||||||
gtk_widget_queue_draw (GTK_WIDGET (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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -52,6 +52,8 @@ struct _GimpFgBgEditor
|
||||||
|
|
||||||
GimpActiveColor active_color;
|
GimpActiveColor active_color;
|
||||||
|
|
||||||
|
GimpImage *active_image;
|
||||||
|
|
||||||
GdkPixbuf *default_icon;
|
GdkPixbuf *default_icon;
|
||||||
GdkPixbuf *swap_icon;
|
GdkPixbuf *swap_icon;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue