Commit 36e982e2 authored by Michael Natterer's avatar Michael Natterer 😴

app: port gimp_image_pick_color() to return a Babl format

instead of a GimpImageType.
parent c8481fd1
......@@ -35,7 +35,7 @@ gimp_image_pick_color (GimpImage *image,
gboolean sample_merged,
gboolean sample_average,
gdouble average_radius,
GimpImageType *sample_type,
const Babl **sample_format,
GimpRGB *color,
gint *color_index)
{
......@@ -76,8 +76,8 @@ gimp_image_pick_color (GimpImage *image,
* Instead, call gimp_pickable_flush() in the callers if needed.
*/
if (sample_type)
*sample_type = gimp_pickable_get_image_type (pickable);
if (sample_format)
*sample_format = gimp_pickable_get_format (pickable);
return gimp_pickable_pick_color (pickable, x, y,
sample_average, average_radius,
......
......@@ -26,7 +26,7 @@ gboolean gimp_image_pick_color (GimpImage *image,
gboolean sample_merged,
gboolean sample_average,
gdouble average_radius,
GimpImageType *sample_type,
const Babl **sample_format,
GimpRGB *color,
gint *color_index);
......
......@@ -37,7 +37,7 @@ VOID: DOUBLE
VOID: DOUBLE, DOUBLE
VOID: DOUBLE, DOUBLE, DOUBLE, DOUBLE
VOID: ENUM
VOID: ENUM, ENUM, BOXED, INT
VOID: ENUM, POINTER, BOXED, INT
VOID: ENUM, INT
VOID: ENUM, INT, BOOLEAN
VOID: ENUM, OBJECT
......
......@@ -725,7 +725,7 @@ gimp_cursor_view_update_cursor (GimpCursorView *view,
GimpUnit unit = shell_unit;
gboolean in_image;
gchar buf[32];
GimpImageType sample_type;
const Babl *sample_format;
GimpRGB color;
gint color_index;
gdouble xres;
......@@ -763,12 +763,12 @@ gimp_cursor_view_update_cursor (GimpCursorView *view,
(gint) floor (y),
view->priv->sample_merged,
FALSE, 0.0,
&sample_type, &color, &color_index))
&sample_format, &color, &color_index))
{
gimp_color_frame_set_color (GIMP_COLOR_FRAME (view->priv->color_frame_1),
sample_type, &color, color_index);
sample_format, &color, color_index);
gimp_color_frame_set_color (GIMP_COLOR_FRAME (view->priv->color_frame_2),
sample_type, &color, color_index);
sample_format, &color, color_index);
}
else
{
......
......@@ -17,6 +17,7 @@
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
......
......@@ -61,7 +61,7 @@ static void gimp_color_picker_tool_oper_update (GimpTool *tool,
static void gimp_color_picker_tool_picked (GimpColorTool *color_tool,
GimpColorPickState pick_state,
GimpImageType sample_type,
const Babl *sample_format,
const GimpRGB *color,
gint color_index);
......@@ -70,7 +70,7 @@ static void gimp_color_picker_tool_info_response (GtkWidget *widget,
gint response_id,
GimpColorPickerTool *picker_tool);
static void gimp_color_picker_tool_info_update (GimpColorPickerTool *picker_tool,
GimpImageType sample_type,
const Babl *sample_format,
const GimpRGB *color,
gint color_index);
......@@ -272,7 +272,7 @@ gimp_color_picker_tool_oper_update (GimpTool *tool,
static void
gimp_color_picker_tool_picked (GimpColorTool *color_tool,
GimpColorPickState pick_state,
GimpImageType sample_type,
const Babl *sample_format,
const GimpRGB *color,
gint color_index)
{
......@@ -285,11 +285,11 @@ gimp_color_picker_tool_picked (GimpColorTool *color_tool,
gimp_color_picker_tool_info_create (picker_tool);
if (picker_tool->dialog)
gimp_color_picker_tool_info_update (picker_tool, sample_type,
gimp_color_picker_tool_info_update (picker_tool, sample_format,
color, color_index);
GIMP_COLOR_TOOL_CLASS (parent_class)->picked (color_tool, pick_state,
sample_type, color,
sample_format, color,
color_index);
}
......@@ -374,7 +374,7 @@ gimp_color_picker_tool_info_response (GtkWidget *widget,
static void
gimp_color_picker_tool_info_update (GimpColorPickerTool *picker_tool,
GimpImageType sample_type,
const Babl *sample_format,
const GimpRGB *color,
gint color_index)
{
......@@ -390,9 +390,9 @@ gimp_color_picker_tool_info_update (GimpColorPickerTool *picker_tool,
color);
gimp_color_frame_set_color (GIMP_COLOR_FRAME (picker_tool->color_frame1),
sample_type, color, color_index);
sample_format, color, color_index);
gimp_color_frame_set_color (GIMP_COLOR_FRAME (picker_tool->color_frame2),
sample_type, color, color_index);
sample_format, color, color_index);
/* don't use gtk_window_present() because it would focus the dialog */
if (gtk_widget_get_visible (picker_tool->dialog))
......
......@@ -104,7 +104,7 @@ static void gimp_color_tool_draw (GimpDrawTool *draw_tool);
static gboolean gimp_color_tool_real_pick (GimpColorTool *color_tool,
gint x,
gint y,
GimpImageType *sample_type,
const Babl **sample_format,
GimpRGB *color,
gint *color_index);
static void gimp_color_tool_pick (GimpColorTool *tool,
......@@ -113,7 +113,7 @@ static void gimp_color_tool_pick (GimpColorTool *tool,
gint y);
static void gimp_color_tool_real_picked (GimpColorTool *color_tool,
GimpColorPickState pick_state,
GimpImageType sample_type,
const Babl *sample_format,
const GimpRGB *color,
gint color_index);
......@@ -138,7 +138,7 @@ gimp_color_tool_class_init (GimpColorToolClass *klass)
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpColorToolClass, picked),
NULL, NULL,
gimp_marshal_VOID__ENUM_ENUM_BOXED_INT,
gimp_marshal_VOID__ENUM_POINTER_BOXED_INT,
G_TYPE_NONE, 4,
GIMP_TYPE_COLOR_PICK_STATE,
GIMP_TYPE_IMAGE_TYPE,
......@@ -570,12 +570,12 @@ gimp_color_tool_draw (GimpDrawTool *draw_tool)
}
static gboolean
gimp_color_tool_real_pick (GimpColorTool *color_tool,
gint x,
gint y,
GimpImageType *sample_type,
GimpRGB *color,
gint *color_index)
gimp_color_tool_real_pick (GimpColorTool *color_tool,
gint x,
gint y,
const Babl **sample_format,
GimpRGB *color,
gint *color_index)
{
GimpTool *tool = GIMP_TOOL (color_tool);
GimpImage *image = gimp_display_get_image (tool->display);
......@@ -587,7 +587,7 @@ gimp_color_tool_real_pick (GimpColorTool *color_tool,
color_tool->options->sample_merged,
color_tool->options->sample_average,
color_tool->options->average_radius,
sample_type,
sample_format,
color,
color_index);
}
......@@ -595,7 +595,7 @@ gimp_color_tool_real_pick (GimpColorTool *color_tool,
static void
gimp_color_tool_real_picked (GimpColorTool *color_tool,
GimpColorPickState pick_state,
GimpImageType sample_type,
const Babl *sample_format,
const GimpRGB *color,
gint color_index)
{
......@@ -610,7 +610,7 @@ gimp_color_tool_real_picked (GimpColorTool *color_tool,
{
GtkWidget *widget;
if (GIMP_IMAGE_TYPE_IS_INDEXED (sample_type))
if (babl_format_is_palette (sample_format))
{
widget = gimp_dialog_factory_find_widget (gimp_dialog_factory_get_singleton (),
"gimp-indexed-palette");
......@@ -704,17 +704,17 @@ gimp_color_tool_pick (GimpColorTool *tool,
gint y)
{
GimpColorToolClass *klass;
GimpImageType sample_type;
const Babl *sample_format;
GimpRGB color;
gint color_index;
klass = GIMP_COLOR_TOOL_GET_CLASS (tool);
if (klass->pick &&
klass->pick (tool, x, y, &sample_type, &color, &color_index))
klass->pick (tool, x, y, &sample_format, &color, &color_index))
{
g_signal_emit (tool, gimp_color_tool_signals[PICKED], 0,
pick_state, sample_type, &color, color_index);
pick_state, sample_format, &color, color_index);
}
}
......
......@@ -59,14 +59,14 @@ struct _GimpColorToolClass
gboolean (* pick) (GimpColorTool *tool,
gint x,
gint y,
GimpImageType *sample_type,
const Babl **sample_format,
GimpRGB *color,
gint *color_index);
/* signals */
void (* picked) (GimpColorTool *tool,
GimpColorPickState pick_state,
GimpImageType sample_type,
const Babl *sample_format,
const GimpRGB *color,
gint color_index);
};
......
......@@ -17,6 +17,7 @@
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
......
......@@ -82,7 +82,7 @@ static void gimp_curves_tool_oper_update (GimpTool *tool,
static void gimp_curves_tool_color_picked (GimpColorTool *color_tool,
GimpColorPickState pick_state,
GimpImageType sample_type,
const Babl *sample_format,
const GimpRGB *color,
gint color_index);
static GeglNode * gimp_curves_tool_get_operation (GimpImageMapTool *image_map_tool,
......@@ -326,7 +326,7 @@ gimp_curves_tool_oper_update (GimpTool *tool,
static void
gimp_curves_tool_color_picked (GimpColorTool *color_tool,
GimpColorPickState pick_state,
GimpImageType sample_type,
const Babl *sample_format,
const GimpRGB *color,
gint color_index)
{
......
......@@ -17,6 +17,7 @@
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
......
......@@ -17,6 +17,7 @@
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
......
......@@ -17,6 +17,7 @@
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
......
......@@ -17,6 +17,7 @@
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
......
......@@ -73,7 +73,7 @@ static gboolean gimp_levels_tool_initialize (GimpTool *tool,
static void gimp_levels_tool_color_picked (GimpColorTool *color_tool,
GimpColorPickState pick_state,
GimpImageType sample_type,
const Babl *sample_format,
const GimpRGB *color,
gint color_index);
......@@ -1159,7 +1159,7 @@ levels_input_adjust_by_color (GimpLevelsConfig *config,
static void
gimp_levels_tool_color_picked (GimpColorTool *color_tool,
GimpColorPickState pick_state,
GimpImageType sample_type,
const Babl *sample_format,
const GimpRGB *color,
gint color_index)
{
......@@ -1169,7 +1169,9 @@ gimp_levels_tool_color_picked (GimpColorTool *color_tool,
value = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (tool->active_picker),
"pick-value"));
if (value & PICK_ALL_CHANNELS && GIMP_IMAGE_TYPE_IS_RGB (sample_type))
if (value & PICK_ALL_CHANNELS &&
(sample_format == babl_format ("R'G'B' u8") ||
sample_format == babl_format ("R'G'B'A u8")))
{
GimpHistogramChannel channel;
......
......@@ -17,6 +17,7 @@
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
......
......@@ -17,6 +17,7 @@
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
......
......@@ -17,6 +17,7 @@
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
......
......@@ -116,8 +116,8 @@ gimp_color_frame_init (GimpColorFrame *frame)
GtkWidget *vbox2;
gint i;
frame->sample_valid = FALSE;
frame->sample_type = GIMP_RGB_IMAGE;
frame->sample_valid = FALSE;
frame->sample_format = babl_format ("R'G'B' u8");
gimp_rgba_set (&frame->color, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
......@@ -407,38 +407,37 @@ gimp_color_frame_set_has_color_area (GimpColorFrame *frame,
/**
* gimp_color_frame_set_color:
* @frame: The #GimpColorFrame.
* @sample_type: The type 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_type equals to #GIMP_INDEXED_IMAGE or
* #GIMP_INDEXEDA_IMAGE.
* @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.
*
* Sets the color sample to display in the #GimpColorFrame.
**/
void
gimp_color_frame_set_color (GimpColorFrame *frame,
GimpImageType sample_type,
const Babl *sample_format,
const GimpRGB *color,
gint color_index)
{
g_return_if_fail (GIMP_IS_COLOR_FRAME (frame));
g_return_if_fail (color != NULL);
if (frame->sample_valid &&
frame->sample_type == sample_type &&
frame->color_index == color_index &&
if (frame->sample_valid &&
frame->sample_format == sample_format &&
frame->color_index == color_index &&
gimp_rgba_distance (&frame->color, color) < 0.0001)
{
frame->color = *color;
return;
}
frame->sample_valid = TRUE;
frame->sample_type = sample_type;
frame->color = *color;
frame->color_index = color_index;
frame->sample_valid = TRUE;
frame->sample_format = sample_format;
frame->color = *color;
frame->color_index = color_index;
gimp_color_frame_update (frame);
}
......@@ -492,7 +491,7 @@ gimp_color_frame_update (GimpColorFrame *frame)
guchar r, g, b, a;
gint i;
has_alpha = GIMP_IMAGE_TYPE_HAS_ALPHA (frame->sample_type);
has_alpha = babl_format_has_alpha (frame->sample_format);
if (frame->sample_valid)
{
......@@ -505,22 +504,18 @@ gimp_color_frame_update (GimpColorFrame *frame)
switch (frame->frame_mode)
{
case GIMP_COLOR_FRAME_MODE_PIXEL:
switch (GIMP_IMAGE_TYPE_BASE_TYPE (frame->sample_type))
if (frame->sample_format == babl_format ("Y' u8") ||
frame->sample_format == babl_format ("Y'A u8"))
{
case GIMP_INDEXED:
names[4] = _("Index:");
names[0] = _("Value:");
if (frame->sample_valid)
{
/* color_index will be -1 for an averaged sample */
if (frame->color_index < 0)
names[4] = NULL;
else
values[4] = g_strdup_printf ("%d", frame->color_index);
}
/* fallthrough */
values[0] = g_strdup_printf ("%d", r);
case GIMP_RGB:
alpha_row = 1;
}
else
{
names[0] = _("Red:");
names[1] = _("Green:");
names[2] = _("Blue:");
......@@ -533,16 +528,20 @@ gimp_color_frame_update (GimpColorFrame *frame)
}
alpha_row = 3;
break;
case GIMP_GRAY:
names[0] = _("Value:");
if (frame->sample_valid)
values[0] = g_strdup_printf ("%d", r);
alpha_row = 1;
break;
if (babl_format_is_palette (frame->sample_format))
{
names[4] = _("Index:");
if (frame->sample_valid)
{
/* color_index will be -1 for an averaged sample */
if (frame->color_index < 0)
names[4] = NULL;
else
values[4] = g_strdup_printf ("%d", frame->color_index);
}
}
}
break;
......
......@@ -37,7 +37,7 @@ struct _GimpColorFrame
GimpFrame parent_instance;
gboolean sample_valid;
GimpImageType sample_type;
const Babl *sample_format;
GimpRGB color;
gint color_index;
......@@ -78,7 +78,7 @@ void gimp_color_frame_set_has_color_area (GimpColorFrame *frame,
gboolean has_color_area);
void gimp_color_frame_set_color (GimpColorFrame *frame,
GimpImageType sample_type,
const Babl *format,
const GimpRGB *color,
gint color_index);
void gimp_color_frame_set_invalid (GimpColorFrame *frame);
......
......@@ -467,7 +467,7 @@ gimp_sample_point_editor_update (GimpSamplePointEditor *editor)
{
GimpSamplePoint *sample_point = list->data;
GimpColorFrame *color_frame;
GimpImageType image_type;
const Babl *format;
GimpRGB color;
gint color_index;
......@@ -480,11 +480,11 @@ gimp_sample_point_editor_update (GimpSamplePointEditor *editor)
sample_point->y,
editor->sample_merged,
FALSE, 0.0,
&image_type,
&format,
&color,
&color_index))
{
gimp_color_frame_set_color (color_frame, image_type,
gimp_color_frame_set_color (color_frame, format,
&color, color_index);
}
else
......
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