Commit b1c437b4 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

use OPAQUE_OPACITY instead of 255.

2003-06-05  Sven Neumann  <sven@gimp.org>

	* app/core/gimpdrawable.c (gimp_drawable_get_color_at):
	* app/core/gimpimage-projection.c (gimp_image_projection_get_color_at):
	use OPAQUE_OPACITY instead of 255.

	* app/core/gimpimage-pick-color.[ch]: factored out code that
	averages over colors so it can be used from GimpImageTool.

	* app/tools/gimpimagemaptool.[ch]: derived from GimpColorTool and
	added a GimpColorTool::pick implementation.

	* app/tools/gimpcoloroptions.c
	* app/tools/gimpcolorpickeroptions.c: add the toggle for
	"sample_merged" in gimp_color_picker_options_gui().

	* app/tools/gimpcolortool.c (gimp_color_tool_cursor_update): check
	if the cursor is over the active drawable or if "sample_merged" is
	active.

	* app/tools/gimplevelstool.c: simplified since all color-picking is
	now handled by the parent classes. Fixes bug #112668.
parent 21b4aba9
2003-06-05 Sven Neumann <sven@gimp.org>
* app/core/gimpdrawable.c (gimp_drawable_get_color_at):
* app/core/gimpimage-projection.c (gimp_image_projection_get_color_at):
use OPAQUE_OPACITY instead of 255.
* app/core/gimpimage-pick-color.[ch]: factored out code that
averages over colors so it can be used from GimpImageTool.
* app/tools/gimpimagemaptool.[ch]: derived from GimpColorTool and
added a GimpColorTool::pick implementation.
* app/tools/gimpcoloroptions.c
* app/tools/gimpcolorpickeroptions.c: add the toggle for
"sample_merged" in gimp_color_picker_options_gui().
* app/tools/gimpcolortool.c (gimp_color_tool_cursor_update): check
if the cursor is over the active drawable or if "sample_merged" is
active.
* app/tools/gimplevelstool.c: simplified since all color-picking is
now handled by the parent classes. Fixes bug #112668.
2003-06-05 Sven Neumann <sven@gimp.org> 2003-06-05 Sven Neumann <sven@gimp.org>
* app/tools/gimpcoloroptions.c: changed the default radius. * app/tools/gimpcoloroptions.c: changed the default radius.
...@@ -1005,7 +1005,7 @@ gimp_drawable_get_color_at (GimpDrawable *drawable, ...@@ -1005,7 +1005,7 @@ gimp_drawable_get_color_at (GimpDrawable *drawable,
if (GIMP_IMAGE_TYPE_HAS_ALPHA (gimp_drawable_type (drawable))) if (GIMP_IMAGE_TYPE_HAS_ALPHA (gimp_drawable_type (drawable)))
dest[3] = src[gimp_drawable_bytes (drawable) - 1]; dest[3] = src[gimp_drawable_bytes (drawable) - 1];
else else
dest[3] = 255; dest[3] = OPAQUE_OPACITY;
if (gimp_drawable_is_indexed (drawable)) if (gimp_drawable_is_indexed (drawable))
dest[4] = src[0]; dest[4] = src[0];
......
...@@ -26,34 +26,26 @@ ...@@ -26,34 +26,26 @@
#include "core/gimpdrawable.h" #include "core/gimpdrawable.h"
#include "core/gimpimage.h" #include "core/gimpimage.h"
#include "core/gimpimage-pick-color.h"
#include "core/gimpimage-projection.h" #include "core/gimpimage-projection.h"
typedef guchar * (* GetColorFunc) (GimpObject *object,
gint x,
gint y);
gboolean gboolean
gimp_image_pick_color (GimpImage *gimage, gimp_image_pick_color (GimpImage *gimage,
GimpDrawable *drawable, GimpDrawable *drawable,
gboolean sample_merged,
gint x, gint x,
gint y, gint y,
gboolean sample_merged,
gboolean sample_average, gboolean sample_average,
gdouble average_radius, gdouble average_radius,
GimpImageType *sample_type, GimpImageType *sample_type,
GimpRGB *color, GimpRGB *color,
gint *color_index) gint *color_index)
{ {
GimpRGB rgb_color; GimpImageType my_sample_type;
guchar *col; gboolean is_indexed;
GimpImageType my_sample_type; GimpImagePickColorFunc color_func;
gint my_color_index; GimpObject *color_obj;
gboolean has_alpha;
gboolean is_indexed;
GetColorFunc get_color_func;
GimpObject *get_color_obj;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE); g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
g_return_val_if_fail (sample_merged || GIMP_IS_DRAWABLE (drawable), FALSE); g_return_val_if_fail (sample_merged || GIMP_IS_DRAWABLE (drawable), FALSE);
...@@ -61,7 +53,15 @@ gimp_image_pick_color (GimpImage *gimage, ...@@ -61,7 +53,15 @@ gimp_image_pick_color (GimpImage *gimage,
gimp_item_get_image (GIMP_ITEM (drawable)) == gimage, gimp_item_get_image (GIMP_ITEM (drawable)) == gimage,
FALSE); FALSE);
if (! sample_merged) if (sample_merged)
{
my_sample_type = gimp_image_projection_type (gimage);
is_indexed = FALSE;
color_func = (GimpImagePickColorFunc) gimp_image_projection_get_color_at;
color_obj = GIMP_OBJECT (gimage);
}
else
{ {
gint off_x, off_y; gint off_x, off_y;
...@@ -72,21 +72,31 @@ gimp_image_pick_color (GimpImage *gimage, ...@@ -72,21 +72,31 @@ gimp_image_pick_color (GimpImage *gimage,
my_sample_type = gimp_drawable_type (drawable); my_sample_type = gimp_drawable_type (drawable);
is_indexed = gimp_drawable_is_indexed (drawable); is_indexed = gimp_drawable_is_indexed (drawable);
get_color_func = (GetColorFunc) gimp_drawable_get_color_at; color_func = (GimpImagePickColorFunc) gimp_drawable_get_color_at;
get_color_obj = GIMP_OBJECT (drawable); color_obj = GIMP_OBJECT (drawable);
} }
else
{
my_sample_type = gimp_image_projection_type (gimage);
is_indexed = FALSE;
get_color_func = (GetColorFunc) gimp_image_projection_get_color_at; if (sample_type)
get_color_obj = GIMP_OBJECT (gimage); *sample_type = my_sample_type;
}
has_alpha = GIMP_IMAGE_TYPE_HAS_ALPHA (my_sample_type); return gimp_image_pick_color_by_func (color_obj, x, y, color_func,
sample_average, average_radius,
color, color_index);
}
gboolean
gimp_image_pick_color_by_func (GimpObject *object,
gint x,
gint y,
GimpImagePickColorFunc pick_color_func,
gboolean sample_average,
gdouble average_radius,
GimpRGB *color,
gint *color_index)
{
guchar *col;
if (! (col = (* get_color_func) (get_color_obj, x, y))) if (! (col = pick_color_func (object, x, y)))
return FALSE; return FALSE;
if (sample_average) if (sample_average)
...@@ -99,16 +109,14 @@ gimp_image_pick_color (GimpImage *gimage, ...@@ -99,16 +109,14 @@ gimp_image_pick_color (GimpImage *gimage,
for (i = x - radius; i <= x + radius; i++) for (i = x - radius; i <= x + radius; i++)
for (j = y - radius; j <= y + radius; j++) for (j = y - radius; j <= y + radius; j++)
if ((tmp_col = (* get_color_func) (get_color_obj, i, j))) if ((tmp_col = pick_color_func (object, i, j)))
{ {
count++; count++;
color_avg[RED_PIX] += tmp_col[RED_PIX]; color_avg[RED_PIX] += tmp_col[RED_PIX];
color_avg[GREEN_PIX] += tmp_col[GREEN_PIX]; color_avg[GREEN_PIX] += tmp_col[GREEN_PIX];
color_avg[BLUE_PIX] += tmp_col[BLUE_PIX]; color_avg[BLUE_PIX] += tmp_col[BLUE_PIX];
color_avg[ALPHA_PIX] += tmp_col[ALPHA_PIX];
if (has_alpha)
color_avg[ALPHA_PIX] += tmp_col[ALPHA_PIX];
g_free (tmp_col); g_free (tmp_col);
} }
...@@ -116,41 +124,20 @@ gimp_image_pick_color (GimpImage *gimage, ...@@ -116,41 +124,20 @@ gimp_image_pick_color (GimpImage *gimage,
col[RED_PIX] = (guchar) (color_avg[RED_PIX] / count); col[RED_PIX] = (guchar) (color_avg[RED_PIX] / count);
col[GREEN_PIX] = (guchar) (color_avg[GREEN_PIX] / count); col[GREEN_PIX] = (guchar) (color_avg[GREEN_PIX] / count);
col[BLUE_PIX] = (guchar) (color_avg[BLUE_PIX] / count); col[BLUE_PIX] = (guchar) (color_avg[BLUE_PIX] / count);
col[ALPHA_PIX] = (guchar) (color_avg[ALPHA_PIX] / count);
if (has_alpha)
col[ALPHA_PIX] = (guchar) (color_avg[ALPHA_PIX] / count);
is_indexed = FALSE;
} }
if (is_indexed) if (color)
my_color_index = col[4]; gimp_rgba_set_uchar (color,
else
my_color_index = -1;
if (has_alpha)
gimp_rgba_set_uchar (&rgb_color,
col[RED_PIX], col[RED_PIX],
col[GREEN_PIX], col[GREEN_PIX],
col[BLUE_PIX], col[BLUE_PIX],
col[ALPHA_PIX]); col[ALPHA_PIX]);
else
gimp_rgba_set_uchar (&rgb_color,
col[RED_PIX],
col[GREEN_PIX],
col[BLUE_PIX],
OPAQUE_OPACITY);
g_free (col);
if (sample_type)
*sample_type = my_sample_type;
if (color)
*color = rgb_color;
if (color_index) if (color_index)
*color_index = my_color_index; *color_index = sample_average ? -1 : col[4];
g_free (col);
return TRUE; return TRUE;
} }
...@@ -20,16 +20,30 @@ ...@@ -20,16 +20,30 @@
#define __GIMP_IMAGE_PICK_COLOR_H__ #define __GIMP_IMAGE_PICK_COLOR_H__
gboolean gimp_image_pick_color (GimpImage *gimage, typedef guchar * (* GimpImagePickColorFunc) (GimpObject *object,
GimpDrawable *drawable, gint x,
gboolean sample_merged, gint y);
gint x,
gint y,
gboolean sample_average, gboolean gimp_image_pick_color (GimpImage *gimage,
gdouble average_radius, GimpDrawable *drawable,
GimpImageType *sample_type, gint x,
GimpRGB *color, gint y,
gint *color_index); gboolean sample_merged,
gboolean sample_average,
gdouble average_radius,
GimpImageType *sample_type,
GimpRGB *color,
gint *color_index);
gboolean gimp_image_pick_color_by_func (GimpObject *object,
gint x,
gint y,
GimpImagePickColorFunc pick_color_func,
gboolean sample_average,
gdouble average_radius,
GimpRGB *color,
gint *color_index);
#endif /* __GIMP_IMAGE_PICK_COLOR_H__ */ #endif /* __GIMP_IMAGE_PICK_COLOR_H__ */
...@@ -198,7 +198,7 @@ gimp_image_projection_get_color_at (GimpImage *gimage, ...@@ -198,7 +198,7 @@ gimp_image_projection_get_color_at (GimpImage *gimage,
if (GIMP_IMAGE_TYPE_HAS_ALPHA (gimp_image_projection_type (gimage))) if (GIMP_IMAGE_TYPE_HAS_ALPHA (gimp_image_projection_type (gimage)))
dest[3] = src[gimp_image_projection_bytes (gimage) - 1]; dest[3] = src[gimp_image_projection_bytes (gimage) - 1];
else else
dest[3] = 255; dest[3] = OPAQUE_OPACITY;
dest[4] = 0; dest[4] = 0;
tile_release (tile, FALSE); tile_release (tile, FALSE);
......
...@@ -198,7 +198,7 @@ gimp_image_projection_get_color_at (GimpImage *gimage, ...@@ -198,7 +198,7 @@ gimp_image_projection_get_color_at (GimpImage *gimage,
if (GIMP_IMAGE_TYPE_HAS_ALPHA (gimp_image_projection_type (gimage))) if (GIMP_IMAGE_TYPE_HAS_ALPHA (gimp_image_projection_type (gimage)))
dest[3] = src[gimp_image_projection_bytes (gimage) - 1]; dest[3] = src[gimp_image_projection_bytes (gimage) - 1];
else else
dest[3] = 255; dest[3] = OPAQUE_OPACITY;
dest[4] = 0; dest[4] = 0;
tile_release (tile, FALSE); tile_release (tile, FALSE);
......
...@@ -184,12 +184,6 @@ gimp_color_options_gui (GimpToolOptions *tool_options) ...@@ -184,12 +184,6 @@ gimp_color_options_gui (GimpToolOptions *tool_options)
vbox = gimp_tool_options_gui (tool_options); vbox = gimp_tool_options_gui (tool_options);
/* the sample merged toggle button */
button = gimp_prop_check_button_new (config, "sample-merged",
_("Sample Merged"));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
/* the sample average options */ /* the sample average options */
frame = gtk_frame_new (NULL); frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
......
...@@ -163,6 +163,12 @@ gimp_color_picker_options_gui (GimpToolOptions *tool_options) ...@@ -163,6 +163,12 @@ gimp_color_picker_options_gui (GimpToolOptions *tool_options)
vbox = gimp_color_options_gui (tool_options); vbox = gimp_color_options_gui (tool_options);
/* the sample merged toggle button */
button = gimp_prop_check_button_new (config, "sample-merged",
_("Sample Merged"));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
/* the update active color toggle button */ /* the update active color toggle button */
button = gimp_prop_check_button_new (config, "update-active", button = gimp_prop_check_button_new (config, "update-active",
_("Update Active Color")); _("Update Active Color"));
......
...@@ -259,27 +259,30 @@ gimp_color_tool_cursor_update (GimpTool *tool, ...@@ -259,27 +259,30 @@ gimp_color_tool_cursor_update (GimpTool *tool,
GdkModifierType state, GdkModifierType state,
GimpDisplay *gdisp) GimpDisplay *gdisp)
{ {
if (GIMP_COLOR_TOOL (tool)->enabled) GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
if (color_tool->enabled)
{ {
GdkCursorType cursor = GIMP_BAD_CURSOR;
if (gdisp->gimage && if (gdisp->gimage &&
coords->x > 0 && coords->x > 0 &&
coords->x < gdisp->gimage->width && coords->x < gdisp->gimage->width &&
coords->y > 0 && coords->y > 0 &&
coords->y < gdisp->gimage->height) coords->y < gdisp->gimage->height &&
{
gimp_tool_set_cursor (tool, gdisp, (color_tool->options->sample_merged ||
GIMP_COLOR_PICKER_CURSOR, gimp_display_coords_in_active_drawable (gdisp, coords)))
GIMP_COLOR_PICKER_TOOL_CURSOR,
GIMP_CURSOR_MODIFIER_NONE);
}
else
{ {
gimp_tool_set_cursor (tool, gdisp, cursor = GIMP_COLOR_PICKER_CURSOR;
GIMP_BAD_CURSOR,
GIMP_COLOR_PICKER_TOOL_CURSOR,
GIMP_CURSOR_MODIFIER_NONE);
} }
gimp_tool_set_cursor (tool, gdisp,
cursor,
GIMP_COLOR_PICKER_TOOL_CURSOR,
GIMP_CURSOR_MODIFIER_NONE);
return; /* don't chain up */ return; /* don't chain up */
} }
...@@ -323,10 +326,8 @@ gimp_color_tool_real_pick (GimpColorTool *color_tool, ...@@ -323,10 +326,8 @@ gimp_color_tool_real_pick (GimpColorTool *color_tool,
g_return_val_if_fail (tool->gdisp != NULL, FALSE); g_return_val_if_fail (tool->gdisp != NULL, FALSE);
g_return_val_if_fail (tool->drawable != NULL, FALSE); g_return_val_if_fail (tool->drawable != NULL, FALSE);
return gimp_image_pick_color (tool->gdisp->gimage, return gimp_image_pick_color (tool->gdisp->gimage, tool->drawable, x, y,
tool->drawable,
color_tool->options->sample_merged, color_tool->options->sample_merged,
x, y,
color_tool->options->sample_average, color_tool->options->sample_average,
color_tool->options->average_radius, color_tool->options->average_radius,
sample_type, sample_type,
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "core/gimpdrawable.h" #include "core/gimpdrawable.h"
#include "core/gimpimage.h" #include "core/gimpimage.h"
#include "core/gimpimage-pick-color.h"
#include "core/gimpimagemap.h" #include "core/gimpimagemap.h"
#include "core/gimptoolinfo.h" #include "core/gimptoolinfo.h"
...@@ -36,6 +37,7 @@ ...@@ -36,6 +37,7 @@
#include "display/gimpdisplay.h" #include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h" #include "display/gimpdisplayshell.h"
#include "gimpcoloroptions.h"
#include "gimpimagemaptool.h" #include "gimpimagemaptool.h"
#include "gimptoolcontrol.h" #include "gimptoolcontrol.h"
...@@ -55,6 +57,12 @@ static void gimp_image_map_tool_control (GimpTool *tool, ...@@ -55,6 +57,12 @@ static void gimp_image_map_tool_control (GimpTool *tool,
GimpToolAction action, GimpToolAction action,
GimpDisplay *gdisp); GimpDisplay *gdisp);
static gboolean gimp_image_map_tool_pick_color (GimpColorTool *color_tool,
gint x,
gint y,
GimpImageType *sample_type,
GimpRGB *color,
gint *color_index);
static void gimp_image_map_tool_map (GimpImageMapTool *image_map_tool); static void gimp_image_map_tool_map (GimpImageMapTool *image_map_tool);
static void gimp_image_map_tool_dialog (GimpImageMapTool *image_map_tool); static void gimp_image_map_tool_dialog (GimpImageMapTool *image_map_tool);
static void gimp_image_map_tool_reset (GimpImageMapTool *image_map_tool); static void gimp_image_map_tool_reset (GimpImageMapTool *image_map_tool);
...@@ -95,7 +103,7 @@ gimp_image_map_tool_get_type (void) ...@@ -95,7 +103,7 @@ gimp_image_map_tool_get_type (void)
(GInstanceInitFunc) gimp_image_map_tool_init, (GInstanceInitFunc) gimp_image_map_tool_init,
}; };
tool_type = g_type_register_static (GIMP_TYPE_TOOL, tool_type = g_type_register_static (GIMP_TYPE_COLOR_TOOL,
"GimpImageMapTool", "GimpImageMapTool",
&tool_info, 0); &tool_info, 0);
} }
...@@ -106,11 +114,13 @@ gimp_image_map_tool_get_type (void) ...@@ -106,11 +114,13 @@ gimp_image_map_tool_get_type (void)
static void static void
gimp_image_map_tool_class_init (GimpImageMapToolClass *klass) gimp_image_map_tool_class_init (GimpImageMapToolClass *klass)
{ {
GObjectClass *object_class; GObjectClass *object_class;
GimpToolClass *tool_class; GimpToolClass *tool_class;
GimpColorToolClass *color_tool_class;
object_class = G_OBJECT_CLASS (klass); object_class = G_OBJECT_CLASS (klass);
tool_class = GIMP_TOOL_CLASS (klass); tool_class = GIMP_TOOL_CLASS (klass);
color_tool_class = GIMP_COLOR_TOOL_CLASS (klass);
parent_class = g_type_class_peek_parent (klass); parent_class = g_type_class_peek_parent (klass);
...@@ -119,6 +129,8 @@ gimp_image_map_tool_class_init (GimpImageMapToolClass *klass) ...@@ -119,6 +129,8 @@ gimp_image_map_tool_class_init (GimpImageMapToolClass *klass)
tool_class->initialize = gimp_image_map_tool_initialize; tool_class->initialize = gimp_image_map_tool_initialize;
tool_class->control = gimp_image_map_tool_control; tool_class->control = gimp_image_map_tool_control;
color_tool_class->pick = gimp_image_map_tool_pick_color;
klass->map = NULL; klass->map = NULL;
klass->dialog = NULL; klass->dialog = NULL;
klass->reset = NULL; klass->reset = NULL;
...@@ -288,18 +300,10 @@ gimp_image_map_tool_control (GimpTool *tool, ...@@ -288,18 +300,10 @@ gimp_image_map_tool_control (GimpTool *tool,
GimpToolAction action, GimpToolAction action,
GimpDisplay *gdisp) GimpDisplay *gdisp)
{ {
GimpImageMapTool *image_map_tool; GimpImageMapTool *image_map_tool = GIMP_IMAGE_MAP_TOOL (tool);
image_map_tool = GIMP_IMAGE_MAP_TOOL (tool);
switch (action) switch (action)
{ {
case PAUSE:
break;
case RESUME:
break;
case HALT: case HALT:
if (image_map_tool->shell) if (image_map_tool->shell)
gimp_image_map_tool_cancel_clicked (NULL, image_map_tool); gimp_image_map_tool_cancel_clicked (NULL, image_map_tool);
...@@ -312,6 +316,25 @@ gimp_image_map_tool_control (GimpTool *tool, ...@@ -312,6 +316,25 @@ gimp_image_map_tool_control (GimpTool *tool,
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp); GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
} }
static gboolean
gimp_image_map_tool_pick_color (GimpColorTool *color_tool,
gint x,
gint y,
GimpImageType *sample_type,
GimpRGB *color,
gint *color_index)
{
GimpImageMapTool *tool = GIMP_IMAGE_MAP_TOOL (color_tool);
*sample_type = gimp_drawable_type (tool->drawable);
return gimp_image_pick_color_by_func (GIMP_OBJECT (tool->image_map), x, y,
(GimpImagePickColorFunc) gimp_image_map_get_color_at,
color_tool->options->sample_average,
color_tool->options->average_radius,
color, color_index);
}
static void static void
gimp_image_map_tool_map (GimpImageMapTool *image_map_tool) gimp_image_map_tool_map (GimpImageMapTool *image_map_tool)
{ {
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#define __GIMP_IMAGE_MAP_TOOL_H__ #define __GIMP_IMAGE_MAP_TOOL_H__
#include "gimptool.h" #include "gimpcolortool.h"
#define GIMP_TYPE_IMAGE_MAP_TOOL (gimp_image_map_tool_get_type ()) #define GIMP_TYPE_IMAGE_MAP_TOOL (gimp_image_map_tool_get_type ())
...@@ -35,24 +35,24 @@ typedef struct _GimpImageMapToolClass GimpImageMapToolClass; ...@@ -35,24 +35,24 @@ typedef struct _GimpImageMapToolClass GimpImageMapToolClass;
struct _GimpImageMapTool struct _GimpImageMapTool
{ {
GimpTool parent_instance; GimpColorTool parent_instance;
GimpDrawable *drawable; GimpDrawable *drawable;
GimpImageMap *image_map; GimpImageMap *image_map;