Commit 8c80ee14 authored by Michael Natterer's avatar Michael Natterer 😴

Bug 748749 - picked colors don't match image colors...

...when a color profile is active

This commit doesn't fix anything, but it prepares the code to do the
right thing:

It passes the actual raw image pixels through the entire color picking
mechanism to the widgets which display colors, particularly
GimpColorFrame.

This is needed for GimpColorFrame's "Pixel" mode (as opposed to its
RGB, HSV etc. modes) which is supposed to show the raw pixel values
from the image.

Before this commit, it was recreating the raw pixel values from the
GimpRGB value it knows, which will become impossible when we correctly
pick color managed GimpRGB values soon.
parent 8fb01734
......@@ -37,8 +37,8 @@ gimp_image_pick_color (GimpImage *image,
gboolean sample_average,
gdouble average_radius,
const Babl **sample_format,
GimpRGB *color,
gint *color_index)
gpointer pixel,
GimpRGB *color)
{
GimpPickable *pickable;
......@@ -82,5 +82,5 @@ gimp_image_pick_color (GimpImage *image,
return gimp_pickable_pick_color (pickable, x, y,
sample_average, average_radius,
color, color_index);
pixel, color);
}
......@@ -27,8 +27,8 @@ gboolean gimp_image_pick_color (GimpImage *image,
gboolean sample_average,
gdouble average_radius,
const Babl **sample_format,
GimpRGB *color,
gint *color_index);
gpointer pixel,
GimpRGB *color);
#endif /* __GIMP_IMAGE_PICK_COLOR_H__ */
......@@ -38,7 +38,7 @@ VOID: DOUBLE
VOID: DOUBLE, DOUBLE
VOID: DOUBLE, DOUBLE, DOUBLE, DOUBLE
VOID: ENUM
VOID: ENUM, DOUBLE, DOUBLE, POINTER, BOXED, INT
VOID: ENUM, DOUBLE, DOUBLE, POINTER, POINTER, BOXED
VOID: ENUM, INT
VOID: ENUM, INT, BOOLEAN
VOID: ENUM, OBJECT
......
......@@ -26,6 +26,8 @@
#include "config.h"
#include <string.h>
#include <cairo.h>
#include <gegl.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
......@@ -222,19 +224,24 @@ gimp_pickable_pick_color (GimpPickable *pickable,
gint y,
gboolean sample_average,
gdouble average_radius,
GimpRGB *color,
gint *color_index)
gpointer pixel,
GimpRGB *color)
{
const Babl *format;
gdouble pixel[4];
gdouble sample[4];
g_return_val_if_fail (GIMP_IS_PICKABLE (pickable), FALSE);
format = babl_format ("RGBA double");
format = gimp_pickable_get_format (pickable);
if (! gimp_pickable_get_pixel_at (pickable, x, y, format, pixel))
if (! gimp_pickable_get_pixel_at (pickable, x, y, format, sample))
return FALSE;
gimp_rgba_set_pixel (color, format, sample);
if (pixel)
memcpy (pixel, sample, babl_format_get_bytes_per_pixel (format));
if (sample_average)
{
gint count = 0;
......@@ -242,42 +249,26 @@ gimp_pickable_pick_color (GimpPickable *pickable,
gint radius = (gint) average_radius;
gint i, j;
format = babl_format ("RGBA double");
for (i = x - radius; i <= x + radius; i++)
for (j = y - radius; j <= y + radius; j++)
if (gimp_pickable_get_pixel_at (pickable, i, j, format, pixel))
if (gimp_pickable_get_pixel_at (pickable, i, j, format, sample))
{
count++;
color_avg[RED] += pixel[RED];
color_avg[GREEN] += pixel[GREEN];
color_avg[BLUE] += pixel[BLUE];
color_avg[ALPHA] += pixel[ALPHA];
color_avg[RED] += sample[RED];
color_avg[GREEN] += sample[GREEN];
color_avg[BLUE] += sample[BLUE];
color_avg[ALPHA] += sample[ALPHA];
}
pixel[RED] = color_avg[RED] / count;
pixel[GREEN] = color_avg[GREEN] / count;
pixel[BLUE] = color_avg[BLUE] / count;
pixel[ALPHA] = color_avg[ALPHA] / count;
}
gimp_rgba_set_pixel (color, format, pixel);
if (color_index)
{
format = gimp_pickable_get_format (pickable);
if (babl_format_is_palette (format) && ! sample_average)
{
guchar indexed_pixel[4];
gimp_pickable_get_pixel_at (pickable, x, y, format, indexed_pixel);
sample[RED] = color_avg[RED] / count;
sample[GREEN] = color_avg[GREEN] / count;
sample[BLUE] = color_avg[BLUE] / count;
sample[ALPHA] = color_avg[ALPHA] / count;
*color_index = indexed_pixel[0];
}
else
{
*color_index = -1;
}
gimp_rgba_set_pixel (color, format, sample);
}
return TRUE;
......
......@@ -76,8 +76,8 @@ gboolean gimp_pickable_pick_color (GimpPickable *pickable,
gint y,
gboolean sample_average,
gdouble average_radius,
GimpRGB *color,
gint *color_index);
gpointer pixel,
GimpRGB *color);
#endif /* __GIMP_PICKABLE_H__ */
......@@ -722,8 +722,8 @@ gimp_cursor_view_update_cursor (GimpCursorView *view,
gboolean in_image;
gchar buf[32];
const Babl *sample_format;
guchar pixel[32];
GimpRGB color;
gint color_index;
gdouble xres;
gdouble yres;
......@@ -759,12 +759,12 @@ gimp_cursor_view_update_cursor (GimpCursorView *view,
(gint) floor (y),
view->priv->sample_merged,
FALSE, 0.0,
&sample_format, &color, &color_index))
&sample_format, pixel, &color))
{
gimp_color_frame_set_color (GIMP_COLOR_FRAME (view->priv->color_frame_1),
sample_format, &color, color_index);
FALSE, sample_format, pixel, &color);
gimp_color_frame_set_color (GIMP_COLOR_FRAME (view->priv->color_frame_2),
sample_format, &color, color_index);
FALSE, sample_format, pixel, &color);
}
else
{
......
......@@ -711,8 +711,8 @@ image_pick_color_invoker (GimpProcedure *procedure,
sample_average,
average_radius,
NULL,
&color,
NULL);
NULL,
&color);
}
}
......
......@@ -64,17 +64,18 @@ static void gimp_color_picker_tool_picked (GimpColorTool *color_t
gdouble x,
gdouble y,
const Babl *sample_format,
const GimpRGB *color,
gint color_index);
gpointer pixel,
const GimpRGB *color);
static void gimp_color_picker_tool_info_create (GimpColorPickerTool *picker_tool);
static void gimp_color_picker_tool_info_response (GimpToolGui *gui,
gint response_id,
GimpColorPickerTool *picker_tool);
static void gimp_color_picker_tool_info_update (GimpColorPickerTool *picker_tool,
gboolean sample_average,
const Babl *sample_format,
const GimpRGB *color,
gint color_index);
gpointer pixel,
const GimpRGB *color);
G_DEFINE_TYPE (GimpColorPickerTool, gimp_color_picker_tool,
......@@ -277,8 +278,8 @@ gimp_color_picker_tool_picked (GimpColorTool *color_tool,
gdouble x,
gdouble y,
const Babl *sample_format,
const GimpRGB *color,
gint color_index)
gpointer pixel,
const GimpRGB *color)
{
GimpColorPickerTool *picker_tool = GIMP_COLOR_PICKER_TOOL (color_tool);
GimpColorPickerOptions *options;
......@@ -289,13 +290,14 @@ gimp_color_picker_tool_picked (GimpColorTool *color_tool,
gimp_color_picker_tool_info_create (picker_tool);
if (picker_tool->gui)
gimp_color_picker_tool_info_update (picker_tool, sample_format,
color, color_index);
gimp_color_picker_tool_info_update (picker_tool,
GIMP_COLOR_OPTIONS (options)->sample_average,
sample_format, pixel, color);
GIMP_COLOR_TOOL_CLASS (parent_class)->picked (color_tool, pick_state,
x, y,
sample_format, color,
color_index);
sample_format,
pixel, color);
}
static void
......@@ -380,9 +382,10 @@ gimp_color_picker_tool_info_response (GimpToolGui *gui,
static void
gimp_color_picker_tool_info_update (GimpColorPickerTool *picker_tool,
gboolean sample_average,
const Babl *sample_format,
const GimpRGB *color,
gint color_index)
gpointer pixel,
const GimpRGB *color)
{
GimpTool *tool = GIMP_TOOL (picker_tool);
......@@ -395,9 +398,9 @@ gimp_color_picker_tool_info_update (GimpColorPickerTool *picker_tool,
color);
gimp_color_frame_set_color (GIMP_COLOR_FRAME (picker_tool->color_frame1),
sample_format, color, color_index);
sample_average, sample_format, pixel, color);
gimp_color_frame_set_color (GIMP_COLOR_FRAME (picker_tool->color_frame2),
sample_format, color, color_index);
sample_average, sample_format, pixel, color);
gimp_tool_gui_show (picker_tool->gui);
}
......@@ -106,15 +106,15 @@ static gboolean gimp_color_tool_real_pick (GimpColorTool *color_tool,
gint x,
gint y,
const Babl **sample_format,
GimpRGB *color,
gint *color_index);
gpointer pixel,
GimpRGB *color);
static void gimp_color_tool_real_picked (GimpColorTool *color_tool,
GimpColorPickState pick_state,
gdouble x,
gdouble y,
const Babl *sample_format,
const GimpRGB *color,
gint color_index);
gpointer pixel,
const GimpRGB *color);
static void gimp_color_tool_pick (GimpColorTool *tool,
GimpColorPickState pick_state,
......@@ -142,14 +142,14 @@ gimp_color_tool_class_init (GimpColorToolClass *klass)
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpColorToolClass, picked),
NULL, NULL,
gimp_marshal_VOID__ENUM_DOUBLE_DOUBLE_POINTER_BOXED_INT,
gimp_marshal_VOID__ENUM_DOUBLE_DOUBLE_POINTER_POINTER_BOXED,
G_TYPE_NONE, 6,
GIMP_TYPE_COLOR_PICK_STATE,
G_TYPE_DOUBLE,
G_TYPE_DOUBLE,
G_TYPE_POINTER,
GIMP_TYPE_RGB | G_SIGNAL_TYPE_STATIC_SCOPE,
G_TYPE_INT);
G_TYPE_POINTER,
GIMP_TYPE_RGB | G_SIGNAL_TYPE_STATIC_SCOPE);
object_class->finalize = gimp_color_tool_finalize;
......@@ -583,8 +583,8 @@ gimp_color_tool_real_pick (GimpColorTool *color_tool,
gint x,
gint y,
const Babl **sample_format,
GimpRGB *color,
gint *color_index)
gpointer pixel,
GimpRGB *color)
{
GimpTool *tool = GIMP_TOOL (color_tool);
GimpImage *image = gimp_display_get_image (tool->display);
......@@ -597,8 +597,8 @@ gimp_color_tool_real_pick (GimpColorTool *color_tool,
color_tool->options->sample_average,
color_tool->options->average_radius,
sample_format,
color,
color_index);
pixel,
color);
}
static void
......@@ -607,8 +607,8 @@ gimp_color_tool_real_picked (GimpColorTool *color_tool,
gdouble x,
gdouble y,
const Babl *sample_format,
const GimpRGB *color,
gint color_index)
gpointer pixel,
const GimpRGB *color)
{
GimpTool *tool = GIMP_TOOL (color_tool);
GimpContext *context;
......@@ -628,9 +628,10 @@ gimp_color_tool_real_picked (GimpColorTool *color_tool,
if (widget)
{
GtkWidget *editor = gtk_bin_get_child (GTK_BIN (widget));
guchar *index = pixel;
gimp_colormap_editor_set_index (GIMP_COLORMAP_EDITOR (editor),
color_index, NULL);
*index, NULL);
}
}
......@@ -714,18 +715,18 @@ gimp_color_tool_pick (GimpColorTool *tool,
{
GimpColorToolClass *klass;
const Babl *sample_format;
guchar pixel[32];
GimpRGB color;
gint color_index;
klass = GIMP_COLOR_TOOL_GET_CLASS (tool);
if (klass->pick &&
klass->pick (tool, x, y, &sample_format, &color, &color_index))
klass->pick (tool, x, y, &sample_format, pixel, &color))
{
g_signal_emit (tool, gimp_color_tool_signals[PICKED], 0,
pick_state,
(gdouble) x, (gdouble) y,
sample_format, &color, color_index);
sample_format, pixel, &color);
}
}
......
......@@ -60,8 +60,8 @@ struct _GimpColorToolClass
gint x,
gint y,
const Babl **sample_format,
GimpRGB *color,
gint *color_index);
gpointer pixel,
GimpRGB *color);
/* signals */
void (* picked) (GimpColorTool *tool,
......@@ -69,8 +69,8 @@ struct _GimpColorToolClass
gdouble x,
gdouble y,
const Babl *sample_format,
const GimpRGB *color,
gint color_index);
gpointer pixel,
const GimpRGB *color);
};
......
......@@ -94,15 +94,15 @@ static gboolean gimp_image_map_tool_pick_color (GimpColorTool *color_too
gint x,
gint y,
const Babl **sample_format,
GimpRGB *color,
gint *color_index);
gpointer pixel,
GimpRGB *color);
static void gimp_image_map_tool_color_picked (GimpColorTool *color_tool,
GimpColorPickState pick_state,
gdouble x,
gdouble y,
const Babl *sample_format,
const GimpRGB *color,
gint color_index);
gpointer pixel,
const GimpRGB *color);
static void gimp_image_map_tool_real_reset (GimpImageMapTool *im_tool);
......@@ -550,8 +550,8 @@ gimp_image_map_tool_pick_color (GimpColorTool *color_tool,
gint x,
gint y,
const Babl **sample_format,
GimpRGB *color,
gint *color_index)
gpointer pixel,
GimpRGB *color)
{
GimpImageMapTool *tool = GIMP_IMAGE_MAP_TOOL (color_tool);
gint off_x, off_y;
......@@ -565,7 +565,7 @@ gimp_image_map_tool_pick_color (GimpColorTool *color_tool,
y - off_y,
color_tool->options->sample_average,
color_tool->options->average_radius,
color, color_index);
pixel, color);
}
static void
......@@ -574,8 +574,8 @@ gimp_image_map_tool_color_picked (GimpColorTool *color_tool,
gdouble x,
gdouble y,
const Babl *sample_format,
const GimpRGB *color,
gint color_index)
gpointer pixel,
const GimpRGB *color)
{
GimpImageMapTool *tool = GIMP_IMAGE_MAP_TOOL (color_tool);
gpointer identifier;
......
......@@ -409,37 +409,42 @@ gimp_color_frame_set_has_color_area (GimpColorFrame *frame,
/**
* gimp_color_frame_set_color:
* @frame: The #GimpColorFrame.
* @sample_format: The format of the #GimpDrawable or #GimpImage the @color
* was picked from.
* @color: The @color to set.
* @color_index: The @color's index. This value is ignored unless
* @sample_format is an indexed format.
* @frame: The #GimpColorFrame.
* @sample_average: The set @color is the result of averaging
* @sample_format: The format of the #GimpDrawable or #GimpImage the @color
* was picked from.
* @pixel: The raw pixel in @sample_format.
* @color: The @color to set.
*
* Sets the color sample to display in the #GimpColorFrame.
* Sets the color sample to display in the #GimpColorFrame. if
* @sample_average is %TRUE, @pixel represents the sample at the
* center of the average area and will not be displayed.
**/
void
gimp_color_frame_set_color (GimpColorFrame *frame,
gboolean sample_average,
const Babl *sample_format,
const GimpRGB *color,
gint color_index)
gpointer pixel,
const GimpRGB *color)
{
g_return_if_fail (GIMP_IS_COLOR_FRAME (frame));
g_return_if_fail (color != NULL);
if (frame->sample_valid &&
frame->sample_format == sample_format &&
frame->color_index == color_index &&
if (frame->sample_valid &&
frame->sample_average == sample_average &&
frame->sample_format == sample_format &&
gimp_rgba_distance (&frame->color, color) < 0.0001)
{
frame->color = *color;
return;
}
frame->sample_valid = TRUE;
frame->sample_format = sample_format;
frame->color = *color;
frame->color_index = color_index;
frame->sample_valid = TRUE;
frame->sample_average = sample_average;
frame->sample_format = sample_format;
frame->color = *color;
memcpy (frame->pixel, pixel, babl_format_get_bytes_per_pixel (sample_format));
gimp_color_frame_update (frame);
}
......@@ -549,7 +554,19 @@ gimp_color_frame_update (GimpColorFrame *frame)
break;
}
gimp_rgba_get_pixel (&frame->color, print_format, print_pixel);
if (frame->sample_average)
{
/* FIXME: this is broken: can't use the averaged sRGB GimpRGB
* value for displaying pixel values when color management
* is enabled
*/
gimp_rgba_get_pixel (&frame->color, print_format, print_pixel);
}
else
{
babl_process (babl_fish (frame->sample_format, print_format),
frame->pixel, print_pixel, 1);
}
values = gimp_babl_print_pixel (print_format, print_pixel);
}
......@@ -584,9 +601,8 @@ gimp_color_frame_update (GimpColorFrame *frame)
g_free (tmp);
/* color_index will be -1 for an averaged sample */
if (frame->color_index >= 0)
values[4] = g_strdup_printf ("%d", frame->color_index);
if (! frame->sample_average)
values[4] = g_strdup_printf ("%d", frame->pixel[0]);
}
}
}
......
......@@ -37,9 +37,10 @@ struct _GimpColorFrame
GimpFrame parent_instance;
gboolean sample_valid;
gboolean sample_average;
const Babl *sample_format;
guchar pixel[32];
GimpRGB color;
gint color_index;
GimpColorFrameMode frame_mode;
......@@ -78,9 +79,10 @@ void gimp_color_frame_set_has_color_area (GimpColorFrame *frame,
gboolean has_color_area);
void gimp_color_frame_set_color (GimpColorFrame *frame,
gboolean sample_average,
const Babl *format,
const GimpRGB *color,
gint color_index);
gpointer pixel,
const GimpRGB *color);
void gimp_color_frame_set_invalid (GimpColorFrame *frame);
......
......@@ -467,8 +467,8 @@ gimp_sample_point_editor_update (GimpSamplePointEditor *editor)
GimpSamplePoint *sample_point = list->data;
GimpColorFrame *color_frame;
const Babl *format;
guchar pixel[32];
GimpRGB color;
gint color_index;
editor->dirty[i] = FALSE;
......@@ -480,11 +480,11 @@ gimp_sample_point_editor_update (GimpSamplePointEditor *editor)
editor->sample_merged,
FALSE, 0.0,
&format,
&color,
&color_index))
pixel,
&color))
{
gimp_color_frame_set_color (color_frame, format,
&color, color_index);
gimp_color_frame_set_color (color_frame, FALSE,
format, pixel, &color);
}
else
{
......
......@@ -278,7 +278,7 @@ gimp_selection_view_button_press (GtkWidget *widget,
options->sample_merged,
FALSE, 0.0,
NULL,
&color, NULL))
NULL, &color))
{
gimp_channel_select_by_color (gimp_image_get_mask (image_editor->image),
drawable,
......
......@@ -483,8 +483,8 @@ HELP
sample_average,
average_radius,
NULL,
&color,
NULL);
NULL,
&color);
}
}
CODE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment