Commit d8228390 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

app/channel.[ch] app/gimpimage.[ch] use GimpRGB for the Channel's, the

2001-01-15  Michael Natterer  <mitch@gimp.org>

	* app/channel.[ch]
	* app/gimpimage.[ch]
	* app/layer.[ch]: use GimpRGB for the Channel's, the QuickMask's
	and the LayerMask's color.

	* app/channel_cmds.c
	* app/channel_ops.c
	* app/channels_dialog.c
	* app/qmask.c
	* app/xcf.c
	* tools/pdbgen/pdb/channel.pdb: changed accordingly.
parent dc9cf1a2
2001-01-15 Michael Natterer <mitch@gimp.org>
* app/channel.[ch]
* app/gimpimage.[ch]
* app/layer.[ch]: use GimpRGB for the Channel's, the QuickMask's
and the LayerMask's color.
* app/channel_cmds.c
* app/channel_ops.c
* app/channels_dialog.c
* app/qmask.c
* app/xcf.c
* tools/pdbgen/pdb/channel.pdb: changed accordingly.
2001-01-15 Michael Natterer <mitch@gimp.org>
* app/color_notebook.[ch]
......
......@@ -47,10 +47,10 @@ struct _EditQmaskOptions
{
GtkWidget *query_box;
GtkWidget *name_entry;
ColorPanel *color_panel;
GimpImage *gimage;
ColorPanel *color_panel;
gdouble opacity;
GimpRGB color;
};
typedef struct _EditQmaskOptions EditQmaskOptions;
......@@ -64,7 +64,7 @@ static void edit_qmask_query_ok_callback (GtkWidget *widget,
static void edit_qmask_query_cancel_callback (GtkWidget *widget,
gpointer client_data);
static void qmask_query_scale_update (GtkAdjustment *adjustment,
gdouble *scale_val);
gpointer data);
static void qmask_removed_callback (GtkObject *qmask,
gpointer data);
......@@ -72,9 +72,13 @@ static void qmask_removed_callback (GtkObject *qmask,
static void
qmask_query_scale_update (GtkAdjustment *adjustment,
gdouble *scale_val)
gpointer data)
{
*scale_val = adjustment->value;
GimpRGB *color;
color = (GimpRGB *) data;
color->a = adjustment->value / 100.0;
}
static void
......@@ -131,12 +135,13 @@ qmask_click_handler (GtkWidget *widget,
gpointer data)
{
GDisplay *gdisp;
gdisp = (GDisplay *)data;
gdisp = (GDisplay *) data;
if ((event->type == GDK_2BUTTON_PRESS) &&
(event->button == 1))
{
edit_qmask_channel_query(gdisp);
edit_qmask_channel_query (gdisp);
}
}
......@@ -182,9 +187,7 @@ qmask_activate (GtkWidget *widget,
GimpImage *gimg;
GimpChannel *gmask;
GimpLayer *layer;
gdouble opacity;
guchar *color;
GimpRGB color;
if (gdisp)
{
......@@ -196,7 +199,6 @@ qmask_activate (GtkWidget *widget,
return; /* If already set, do nothing */
/* Set the defaults */
opacity = (gdouble) gimg->qmask_opacity;
color = gimg->qmask_color;
if ( (gmask = gimp_image_get_channel_by_name (gimg, "Qmask")) )
......@@ -219,18 +221,16 @@ qmask_activate (GtkWidget *widget,
gimg->width,
gimg->height,
"Qmask",
(gint)(255*opacity)/100,
color);
&color);
gimp_image_add_channel (gimg, gmask, 0);
gimp_drawable_fill (GIMP_DRAWABLE (gmask), 0, 0, 0, 0);
}
else
else
{ /* if selection */
gmask = channel_copy (gimp_image_get_mask (gimg));
gimp_image_add_channel (gimg, gmask, 0);
channel_set_color (gmask, color);
channel_set_color (gmask, &color);
gimp_object_set_name (GIMP_OBJECT (gmask), "Qmask");
channel_set_opacity (gmask, opacity);
gimage_mask_none (gimg); /* Clear the selection */
}
......@@ -249,27 +249,20 @@ static void
edit_qmask_channel_query (GDisplay * gdisp)
{
EditQmaskOptions *options;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *table;
GtkWidget *label;
GtkWidget *opacity_scale;
GtkObject *opacity_scale_data;
GimpRGB color;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *table;
GtkWidget *label;
GtkWidget *opacity_scale;
GtkObject *opacity_scale_data;
/* channel = gimp_image_get_channel_by_name (gdisp->gimage, "Qmask"); */
/* the new options structure */
options = g_new (EditQmaskOptions, 1);
options->gimage = gdisp->gimage;
options->opacity = (gdouble) options->gimage->qmask_opacity;
options->gimage = gdisp->gimage;
options->color = options->gimage->qmask_color;
gimp_rgba_set_uchar (&color,
options->gimage->qmask_color[0],
options->gimage->qmask_color[1],
options->gimage->qmask_color[2],
255);
options->color_panel = color_panel_new (&color, FALSE, 48, 64);
options->color_panel = color_panel_new (&options->color, FALSE, 48, 64);
/* The dialog */
options->query_box =
......@@ -308,13 +301,13 @@ edit_qmask_channel_query (GDisplay * gdisp)
gtk_widget_show (label);
opacity_scale_data =
gtk_adjustment_new (options->opacity, 0.0, 100.0, 1.0, 1.0, 0.0);
gtk_adjustment_new (options->color.a * 100.0, 0.0, 100.0, 1.0, 1.0, 0.0);
opacity_scale = gtk_hscale_new (GTK_ADJUSTMENT (opacity_scale_data));
gtk_table_attach_defaults (GTK_TABLE (table), opacity_scale, 1, 2, 1, 2);
gtk_scale_set_value_pos (GTK_SCALE (opacity_scale), GTK_POS_TOP);
gtk_signal_connect (GTK_OBJECT (opacity_scale_data), "value_changed",
(GtkSignalFunc) qmask_query_scale_update,
&options->opacity);
GTK_SIGNAL_FUNC (qmask_query_scale_update),
&options->color);
gtk_widget_show (opacity_scale);
/* The color panel */
......@@ -334,54 +327,24 @@ edit_qmask_query_ok_callback (GtkWidget *widget,
{
EditQmaskOptions *options;
Channel *channel;
const guchar *channel_color;
GimpRGB color;
gboolean update = FALSE;
gint opacity;
options = (EditQmaskOptions *) client_data;
channel = gimp_image_get_channel_by_name (options->gimage, "Qmask");
opacity = (gint) (255 * options->opacity / 100);
if (options->gimage && channel)
{ /* don't update if opacity hasn't changed */
if (channel_get_opacity (channel) != opacity)
{
update = TRUE;
}
channel_color = channel_get_color (channel);
options->color_panel->color.a = options->color.a;
gimp_rgb_set_uchar (&color,
channel_color[0],
channel_color[1],
channel_color[2]);
if (gimp_rgb_distance (&color, &options->color_panel->color) > 0.0001)
update = TRUE;
if (update)
if (options->gimage && channel)
{
if (gimp_rgba_distance (&channel->color,
&options->color_panel->color) > 0.0001)
{
guchar col[0];
gimp_rgb_get_uchar (&options->color_panel->color,
&col[0],
&col[1],
&col[2]);
channel_set_opacity (channel, 100 * opacity / 255);
channel_set_color (channel, col);
channel_set_color (channel, &options->color_panel->color);
channel_update (channel);
}
}
/* update the qmask color no matter what */
gimp_rgb_get_uchar (&options->color_panel->color,
&options->gimage->qmask_color[0],
&options->gimage->qmask_color[1],
&options->gimage->qmask_color[2]);
options->gimage->qmask_opacity = (gint) 100 * opacity / 255;
options->gimage->qmask_color = options->color_panel->color;
gtk_widget_destroy (options->query_box);
g_free (options);
......@@ -398,8 +361,3 @@ edit_qmask_query_cancel_callback (GtkWidget *widget,
gtk_widget_destroy (options->query_box);
g_free (options);
}
......@@ -47,10 +47,10 @@ struct _EditQmaskOptions
{
GtkWidget *query_box;
GtkWidget *name_entry;
ColorPanel *color_panel;
GimpImage *gimage;
ColorPanel *color_panel;
gdouble opacity;
GimpRGB color;
};
typedef struct _EditQmaskOptions EditQmaskOptions;
......@@ -64,7 +64,7 @@ static void edit_qmask_query_ok_callback (GtkWidget *widget,
static void edit_qmask_query_cancel_callback (GtkWidget *widget,
gpointer client_data);
static void qmask_query_scale_update (GtkAdjustment *adjustment,
gdouble *scale_val);
gpointer data);
static void qmask_removed_callback (GtkObject *qmask,
gpointer data);
......@@ -72,9 +72,13 @@ static void qmask_removed_callback (GtkObject *qmask,
static void
qmask_query_scale_update (GtkAdjustment *adjustment,
gdouble *scale_val)
gpointer data)
{
*scale_val = adjustment->value;
GimpRGB *color;
color = (GimpRGB *) data;
color->a = adjustment->value / 100.0;
}
static void
......@@ -131,12 +135,13 @@ qmask_click_handler (GtkWidget *widget,
gpointer data)
{
GDisplay *gdisp;
gdisp = (GDisplay *)data;
gdisp = (GDisplay *) data;
if ((event->type == GDK_2BUTTON_PRESS) &&
(event->button == 1))
{
edit_qmask_channel_query(gdisp);
edit_qmask_channel_query (gdisp);
}
}
......@@ -182,9 +187,7 @@ qmask_activate (GtkWidget *widget,
GimpImage *gimg;
GimpChannel *gmask;
GimpLayer *layer;
gdouble opacity;
guchar *color;
GimpRGB color;
if (gdisp)
{
......@@ -196,7 +199,6 @@ qmask_activate (GtkWidget *widget,
return; /* If already set, do nothing */
/* Set the defaults */
opacity = (gdouble) gimg->qmask_opacity;
color = gimg->qmask_color;
if ( (gmask = gimp_image_get_channel_by_name (gimg, "Qmask")) )
......@@ -219,18 +221,16 @@ qmask_activate (GtkWidget *widget,
gimg->width,
gimg->height,
"Qmask",
(gint)(255*opacity)/100,
color);
&color);
gimp_image_add_channel (gimg, gmask, 0);
gimp_drawable_fill (GIMP_DRAWABLE (gmask), 0, 0, 0, 0);
}
else
else
{ /* if selection */
gmask = channel_copy (gimp_image_get_mask (gimg));
gimp_image_add_channel (gimg, gmask, 0);
channel_set_color (gmask, color);
channel_set_color (gmask, &color);
gimp_object_set_name (GIMP_OBJECT (gmask), "Qmask");
channel_set_opacity (gmask, opacity);
gimage_mask_none (gimg); /* Clear the selection */
}
......@@ -249,27 +249,20 @@ static void
edit_qmask_channel_query (GDisplay * gdisp)
{
EditQmaskOptions *options;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *table;
GtkWidget *label;
GtkWidget *opacity_scale;
GtkObject *opacity_scale_data;
GimpRGB color;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *table;
GtkWidget *label;
GtkWidget *opacity_scale;
GtkObject *opacity_scale_data;
/* channel = gimp_image_get_channel_by_name (gdisp->gimage, "Qmask"); */
/* the new options structure */
options = g_new (EditQmaskOptions, 1);
options->gimage = gdisp->gimage;
options->opacity = (gdouble) options->gimage->qmask_opacity;
options->gimage = gdisp->gimage;
options->color = options->gimage->qmask_color;
gimp_rgba_set_uchar (&color,
options->gimage->qmask_color[0],
options->gimage->qmask_color[1],
options->gimage->qmask_color[2],
255);
options->color_panel = color_panel_new (&color, FALSE, 48, 64);
options->color_panel = color_panel_new (&options->color, FALSE, 48, 64);
/* The dialog */
options->query_box =
......@@ -308,13 +301,13 @@ edit_qmask_channel_query (GDisplay * gdisp)
gtk_widget_show (label);
opacity_scale_data =
gtk_adjustment_new (options->opacity, 0.0, 100.0, 1.0, 1.0, 0.0);
gtk_adjustment_new (options->color.a * 100.0, 0.0, 100.0, 1.0, 1.0, 0.0);
opacity_scale = gtk_hscale_new (GTK_ADJUSTMENT (opacity_scale_data));
gtk_table_attach_defaults (GTK_TABLE (table), opacity_scale, 1, 2, 1, 2);
gtk_scale_set_value_pos (GTK_SCALE (opacity_scale), GTK_POS_TOP);
gtk_signal_connect (GTK_OBJECT (opacity_scale_data), "value_changed",
(GtkSignalFunc) qmask_query_scale_update,
&options->opacity);
GTK_SIGNAL_FUNC (qmask_query_scale_update),
&options->color);
gtk_widget_show (opacity_scale);
/* The color panel */
......@@ -334,54 +327,24 @@ edit_qmask_query_ok_callback (GtkWidget *widget,
{
EditQmaskOptions *options;
Channel *channel;
const guchar *channel_color;
GimpRGB color;
gboolean update = FALSE;
gint opacity;
options = (EditQmaskOptions *) client_data;
channel = gimp_image_get_channel_by_name (options->gimage, "Qmask");
opacity = (gint) (255 * options->opacity / 100);
if (options->gimage && channel)
{ /* don't update if opacity hasn't changed */
if (channel_get_opacity (channel) != opacity)
{
update = TRUE;
}
channel_color = channel_get_color (channel);
options->color_panel->color.a = options->color.a;
gimp_rgb_set_uchar (&color,
channel_color[0],
channel_color[1],
channel_color[2]);
if (gimp_rgb_distance (&color, &options->color_panel->color) > 0.0001)
update = TRUE;
if (update)
if (options->gimage && channel)
{
if (gimp_rgba_distance (&channel->color,
&options->color_panel->color) > 0.0001)
{
guchar col[0];
gimp_rgb_get_uchar (&options->color_panel->color,
&col[0],
&col[1],
&col[2]);
channel_set_opacity (channel, 100 * opacity / 255);
channel_set_color (channel, col);
channel_set_color (channel, &options->color_panel->color);
channel_update (channel);
}
}
/* update the qmask color no matter what */
gimp_rgb_get_uchar (&options->color_panel->color,
&options->gimage->qmask_color[0],
&options->gimage->qmask_color[1],
&options->gimage->qmask_color[2]);
options->gimage->qmask_opacity = (gint) 100 * opacity / 255;
options->gimage->qmask_color = options->color_panel->color;
gtk_widget_destroy (options->query_box);
g_free (options);
......@@ -398,8 +361,3 @@ edit_qmask_query_cancel_callback (GtkWidget *widget,
gtk_widget_destroy (options->query_box);
g_free (options);
}
......@@ -118,26 +118,24 @@ channel_validate (TileManager *tm,
}
Channel *
channel_new (GimpImage *gimage,
gint width,
gint height,
const gchar *name,
gint opacity,
const guchar *col)
channel_new (GimpImage *gimage,
gint width,
gint height,
const gchar *name,
const GimpRGB *color)
{
Channel * channel;
gint i;
Channel *channel;
g_return_val_if_fail (color != NULL, NULL);
channel = gtk_type_new (gimp_channel_get_type ());
channel = gtk_type_new (GIMP_TYPE_CHANNEL);
gimp_drawable_configure (GIMP_DRAWABLE (channel),
gimage, width, height, GRAY_GIMAGE, name);
/* set the channel color and opacity */
for (i = 0; i < 3; i++)
channel->col[i] = col[i];
channel->color = *color;
channel->opacity = opacity;
channel->show_masked = TRUE;
/* selection mask variables */
......@@ -185,7 +183,8 @@ channel_copy (const Channel *channel)
new_channel = channel_new (GIMP_DRAWABLE (channel)->gimage,
GIMP_DRAWABLE (channel)->width,
GIMP_DRAWABLE (channel)->height,
channel_name, channel->opacity, channel->col);
channel_name,
&channel->color);
GIMP_DRAWABLE (new_channel)->visible = GIMP_DRAWABLE (channel)->visible;
new_channel->show_masked = channel->show_masked;
......@@ -223,36 +222,44 @@ channel_get_name (const Channel *channel)
}
void
channel_set_color (Channel *channel,
const guchar *color)
channel_set_color (Channel *channel,
const GimpRGB *color)
{
gint i;
g_return_if_fail (channel != NULL);
g_return_if_fail (GIMP_IS_CHANNEL (channel));
g_return_if_fail (color != NULL);
if (color)
{
for (i = 0; i < 3; i++)
channel->col[i] = color[i];
}
channel->color = *color;
}
const guchar *
const GimpRGB *
channel_get_color (const Channel *channel)
{
return GIMP_CHANNEL (channel)->col;
g_return_val_if_fail (channel != NULL, NULL);
g_return_val_if_fail (GIMP_IS_CHANNEL (channel), NULL);
return &channel->color;
}
gint
channel_get_opacity (const Channel *channel)
{
return channel->opacity;
{
g_return_val_if_fail (channel != NULL, 0);
g_return_val_if_fail (GIMP_IS_CHANNEL (channel), 0);
return (gint) (channel->color.a * 100.999);
}
void
channel_set_opacity (Channel *channel,
gint opacity)
{
if (opacity >=0 && opacity <= 100)
channel->opacity = (gint) (opacity * 255) / 100;
g_return_if_fail (channel != NULL);
g_return_if_fail (GIMP_IS_CHANNEL (channel));
opacity = CLAMP (opacity, 0, 100);
channel->color.a = opacity / 100.0;
}
void
......@@ -579,12 +586,12 @@ channel_new_mask (GimpImage *gimage,
gint width,
gint height)
{
guchar black[3] = { 0, 0, 0 };
GimpRGB black = { 0.0, 0.0, 0.0, 0.5 };
Channel *new_channel;
/* Create the new channel */
new_channel = channel_new (gimage, width, height,
_("Selection Mask"), 127, black);
_("Selection Mask"), &black);
/* Set the validate procedure */
tile_manager_set_validate_proc (GIMP_DRAWABLE (new_channel)->tiles,
......@@ -1381,8 +1388,8 @@ channel_clear (Channel *mask)
void
channel_invert (Channel *mask)
{
PixelRegion maskPR;
GimpLut *lut;
PixelRegion maskPR;
GimpLut *lut;
/* push the current channel onto the undo stack */
channel_push_undo (mask);
......@@ -1403,8 +1410,8 @@ channel_invert (Channel *mask)
void
channel_sharpen (Channel *mask)
{
PixelRegion maskPR;
GimpLut *lut;
PixelRegion maskPR;
GimpLut *lut;
/* push the current channel onto the undo stack */
channel_push_undo (mask);
......@@ -1424,7 +1431,7 @@ void
channel_all (Channel *mask)
{
PixelRegion maskPR;
guchar bg = 255;
guchar bg = 255;
/* push the current channel onto the undo stack */
channel_push_undo (mask);
......
......@@ -43,8 +43,7 @@ struct _GimpChannel
{
GimpDrawable parent_instance;
guchar col[3]; /* RGB triplet for channel color */
gint opacity; /* Channel opacity */
GimpRGB color; /* Also stored the opacity */
gboolean show_masked; /* Show masked areas--as */
/* opposed to selected areas */
......@@ -95,21 +94,20 @@ Channel * channel_new (GimpImage *gimage,
gint width,
gint height,
const gchar *name,
gint opacity,
const guchar *col);
const GimpRGB *color);
Channel * channel_copy (const Channel *channel);
const gchar * channel_get_name (const Channel *channel);
void channel_set_name (Channel *channel,
const gchar *name);
gint channel_get_opacity (const Channel *channel);
void channel_set_opacity (Channel *channel,
gint channel_get_opacity (const Channel *channel);
void channel_set_opacity (Channel *channel,
gint opacity);
const guchar * channel_get_color (const Channel *channel);
const GimpRGB * channel_get_color (const Channel *channel);
void channel_set_color (Channel *channel,
const guchar *color);
const GimpRGB *color);
void channel_delete (Channel *channel);
void channel_scale (Channel *channel,
......@@ -219,6 +217,8 @@ void channel_load (Channel *mask,
void channel_invalidate_bounds (Channel *channel);
#define gimp_drawable_channel GIMP_IS_CHANNEL
#endif /* __CHANNEL_H__ */
......@@ -103,7 +103,14 @@ channel_new_invoker (Argument *args)
if (success)
{
channel = channel_new (gimage, width, height, name, opacity, color);
GimpRGB rgb_color;
gimp_rgb_set_uchar (&rgb_color,
color[0], color[1], color[2]);
rgb_color.a = opacity / 100.0;
channel = channel_new (gimage, width, height, name, &rgb_color);
success = channel != NULL;
}
......@@ -594,7 +601,7 @@ channel_get_opacity_invoker (Argument *args)
return_args = procedural_db_return_args (&channel_get_opacity_proc, success);
if (success)
return_args[1].value.pdb_float = (channel->opacity * 100.0) / 255.0;
return_args[1].value.pdb_float = channel->color.a * 100.0;
return return_args;
}
......@@ -649,7 +656,7 @@ channel_set_opacity_invoker (Argument *args)
success = FALSE;
if (success)
channel->opacity = (int) ((opacity * 255) / 100);
channel->color.a = opacity / 100.0;
return procedural_db_return_args (&channel_set_opacity_proc, success);
}
......@@ -699,9 +706,11 @@ channel_get_color_invoker (Argument *args)
if (success)
{
color = g_new (guchar, 3);
color[RED_PIX] = channel->col[RED_PIX];
color[GREEN_PIX] = channel->col[GREEN_PIX];
color[BLUE_PIX] = channel->col[BLUE_PIX];
gimp_rgb_get_uchar (&channel->color,
&color[RED_PIX],
&color[GREEN_PIX],
&color[BLUE_PIX]);
}
return_args = procedural_db_return_args (&channel_get_color_proc, success);
......@@ -760,7 +769,17 @@ channel_set_color_invoker (Argument *args)
color = (guchar *) args[1].value.pdb_pointer;
if (success)
channel_set_color(channel, color);
{
GimpRGB rgb_color;
gimp_rgba_set_uchar (&rgb_color,
color[0],
color[1],
color[2],
(guchar) (channel->color.a * 255.999));
channel_set_color(channel, &rgb_color);
}
return procedural_db_return_args (&channel_set_color_proc, success);
}
......
......@@ -700,22 +700,21 @@ duplicate (GimpImage *gimage)
switch (guide->orientation)
{
case ORIENTATION_HORIZONTAL:
new_guide = gimp_image_add_hguide(new_gimage);
new_guide = gimp_image_add_hguide (new_gimage);
new_guide->position = guide->position;
break;
case ORIENTATION_VERTICAL<