From d822839089445c6de4914587bbf8af325648df99 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Mon, 15 Jan 2001 04:37:01 +0000 Subject: [PATCH] app/channel.[ch] app/gimpimage.[ch] use GimpRGB for the Channel's, the 2001-01-15 Michael Natterer * 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. --- ChangeLog | 14 +++ app/actions/qmask-commands.c | 112 ++++++++---------------- app/actions/quick-mask-commands.c | 112 ++++++++---------------- app/channel.c | 75 ++++++++-------- app/channel.h | 16 ++-- app/channel_cmds.c | 33 +++++-- app/channel_ops.c | 17 ++-- app/channels_dialog.c | 123 +++++++++++---------------- app/core/gimpchannel-combine.c | 75 ++++++++-------- app/core/gimpchannel-combine.h | 16 ++-- app/core/gimpchannel.c | 75 ++++++++-------- app/core/gimpchannel.h | 16 ++-- app/core/gimpdrawable-offset.c | 17 ++-- app/core/gimpimage-duplicate.c | 17 ++-- app/core/gimpimage-guides.c | 82 ++++++++++++------ app/core/gimpimage-guides.h | 3 +- app/core/gimpimage-merge.c | 82 ++++++++++++------ app/core/gimpimage-merge.h | 3 +- app/core/gimpimage-projection.c | 82 ++++++++++++------ app/core/gimpimage-projection.h | 3 +- app/core/gimpimage-qmask.c | 112 ++++++++---------------- app/core/gimpimage-quick-mask.c | 112 ++++++++---------------- app/core/gimpimage-resize.c | 82 ++++++++++++------ app/core/gimpimage-resize.h | 3 +- app/core/gimpimage-scale.c | 82 ++++++++++++------ app/core/gimpimage-scale.h | 3 +- app/core/gimpimage.c | 82 ++++++++++++------ app/core/gimpimage.h | 3 +- app/core/gimplayer.c | 34 ++++---- app/core/gimplayer.h | 5 +- app/core/gimpprojection-construct.c | 82 ++++++++++++------ app/core/gimpprojection-construct.h | 3 +- app/display/gimpdisplayshell-qmask.c | 112 ++++++++---------------- app/gimpchannel.c | 75 ++++++++-------- app/gimpchannel.h | 16 ++-- app/gimpdrawable-offset.c | 17 ++-- app/gimpimage-duplicate.c | 17 ++-- app/gimpimage.c | 82 ++++++++++++------ app/gimpimage.h | 3 +- app/gimplayer.c | 34 ++++---- app/gimplayer.h | 5 +- app/gui/channels-dialog.c | 123 +++++++++++---------------- app/gui/qmask-commands.c | 112 ++++++++---------------- app/layer.c | 34 ++++---- app/layer.h | 5 +- app/qmask.c | 112 ++++++++---------------- app/xcf.c | 57 ++++++++----- app/xcf/xcf.c | 57 ++++++++----- tools/pdbgen/pdb/channel.pdb | 48 +++++++++-- 49 files changed, 1239 insertions(+), 1246 deletions(-) diff --git a/ChangeLog b/ChangeLog index 29d78b0d88..63e9e64f20 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2001-01-15 Michael Natterer + + * 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 * app/color_notebook.[ch] diff --git a/app/actions/qmask-commands.c b/app/actions/qmask-commands.c index 81f5d5d534..cbc81a0e26 100644 --- a/app/actions/qmask-commands.c +++ b/app/actions/qmask-commands.c @@ -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); + + options->color_panel->color.a = options->color.a; 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); - - 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 (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); } - - - - - diff --git a/app/actions/quick-mask-commands.c b/app/actions/quick-mask-commands.c index 81f5d5d534..cbc81a0e26 100644 --- a/app/actions/quick-mask-commands.c +++ b/app/actions/quick-mask-commands.c @@ -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); + + options->color_panel->color.a = options->color.a; 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); - - 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 (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); } - - - - - diff --git a/app/channel.c b/app/channel.c index 6b59f5add9..477ab9054b 100644 --- a/app/channel.c +++ b/app/channel.c @@ -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; - channel = gtk_type_new (gimp_channel_get_type ()); + g_return_val_if_fail (color != NULL, NULL); + + 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); diff --git a/app/channel.h b/app/channel.h index 5a7bcf653e..e7ccc22532 100644 --- a/app/channel.h +++ b/app/channel.h @@ -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__ */ diff --git a/app/channel_cmds.c b/app/channel_cmds.c index b1e7654431..fbdca97a4d 100644 --- a/app/channel_cmds.c +++ b/app/channel_cmds.c @@ -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); } diff --git a/app/channel_ops.c b/app/channel_ops.c index 232a1eac1c..bb503f7640 100644 --- a/app/channel_ops.c +++ b/app/channel_ops.c @@ -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: - new_guide = gimp_image_add_vguide(new_gimage); + new_guide = gimp_image_add_vguide (new_gimage); new_guide->position = guide->position; break; default: - g_error("Unknown guide orientation.\n"); + g_error ("Unknown guide orientation.\n"); } } + /* Copy the qmask info */ new_gimage->qmask_state = gimage->qmask_state; - for (count=0;count<3;count++) - new_gimage->qmask_color[count] = gimage->qmask_color[count]; - new_gimage->qmask_opacity = gimage->qmask_opacity; + new_gimage->qmask_color = gimage->qmask_color; /* Copy parasites */ parasites = gimage->parasites; @@ -726,9 +725,9 @@ duplicate (GimpImage *gimage) paths = gimp_image_get_paths (gimage); if (paths) { - GSList *plist = NULL; - GSList *new_plist = NULL; - Path *path; + GSList *plist = NULL; + GSList *new_plist = NULL; + Path *path; PathList *new_paths; for (plist = paths->bz_paths; plist; plist = plist->next) diff --git a/app/channels_dialog.c b/app/channels_dialog.c index 9a361b4cba..2fb6582f82 100644 --- a/app/channels_dialog.c +++ b/app/channels_dialog.c @@ -202,6 +202,9 @@ static void channel_widget_exclusive_visible (ChannelWidget *cw); static void channel_widget_channel_flush (GtkWidget *widget, gpointer data); +static void channels_dialog_opacity_update (GtkAdjustment *adjustment, + gpointer data); + /* assorted query dialogs */ static void channels_dialog_new_channel_query (GimpImage *gimage); static void channels_dialog_edit_channel_query (ChannelWidget *cw); @@ -1210,8 +1213,7 @@ channels_dialog_drag_new_channel_callback (GtkWidget *widget, channel = channel_new (gimage, width, height, _("Empty Channel Copy"), - src->channel->opacity, - src->channel->col); + &src->channel->color); if (channel) { drawable_fill (GIMP_DRAWABLE (channel), TRANSPARENT_FILL); @@ -1757,20 +1759,13 @@ channel_widget_drop_color (GtkWidget *widget, { ChannelWidget *channel_widget; Channel *channel; - guchar r, g, b, a; channel_widget = (ChannelWidget *) data; channel = channel_widget->channel; - gimp_rgba_get_uchar (color, &r, &g, &b, &a); - - if (r != channel->col[0] || - g != channel->col[1] || - b != channel->col[2]) + if (gimp_rgba_distance (color, &channel->color) > 0.0001) { - channel->col[0] = r; - channel->col[1] = g; - channel->col[2] = b; + channel->color = *color; drawable_update (GIMP_DRAWABLE (channel), 0, 0, GIMP_DRAWABLE (channel)->width, @@ -2464,6 +2459,17 @@ channel_widget_channel_flush (GtkWidget *widget, gtk_widget_queue_draw (channel_widget->channel_preview); } +static void +channels_dialog_opacity_update (GtkAdjustment *adjustment, + gpointer data) +{ + GimpRGB *color; + + color = (GimpRGB *) data; + + color->a = adjustment->value / 100.0; +} + /**********************************/ /* The new channel query dialog */ /**********************************/ @@ -2476,12 +2482,12 @@ struct _NewChannelOptions GtkWidget *name_entry; ColorPanel *color_panel; - GimpImage *gimage; - gdouble opacity; + GimpImage *gimage; + GimpRGB color; }; static gchar *channel_name = NULL; -static GimpRGB channel_color = { 0.0, 0.0, 0.0, 1.0 }; +static GimpRGB channel_color = { 0.0, 0.0, 0.0, 0.5 }; static void @@ -2500,15 +2506,12 @@ new_channel_query_ok_callback (GtkWidget *widget, if ((gimage = options->gimage)) { - guchar rgba[4]; - - gimp_rgba_get_uchar (&options->color_panel->color, - &rgba[0], &rgba[1], &rgba[2], &rgba[3]); + options->color_panel->color.a = options->color.a; new_channel = channel_new (gimage, gimage->width, gimage->height, channel_name, - (gint) (255 * options->opacity) / 100, - rgba); + &options->color_panel->color); + drawable_fill (GIMP_DRAWABLE (new_channel), TRANSPARENT_FILL); channel_color = options->color_panel->color; @@ -2524,17 +2527,17 @@ static void channels_dialog_new_channel_query (GimpImage* gimage) { NewChannelOptions *options; - GtkWidget *hbox; - GtkWidget *vbox; - GtkWidget *table; - GtkWidget *label; - GtkWidget *opacity_scale; - GtkObject *opacity_scale_data; + GtkWidget *hbox; + GtkWidget *vbox; + GtkWidget *table; + GtkWidget *label; + GtkWidget *opacity_scale; + GtkObject *opacity_scale_data; /* the new options structure */ options = g_new (NewChannelOptions, 1); options->gimage = gimage; - options->opacity = 50.0; + options->color = channel_color; options->color_panel = color_panel_new (&channel_color, FALSE, 48, 64); @@ -2596,14 +2599,14 @@ channels_dialog_new_channel_query (GimpImage* gimage) 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_range_set_update_policy (GTK_RANGE (opacity_scale), GTK_UPDATE_DELAYED); gtk_signal_connect (GTK_OBJECT (opacity_scale_data), "value_changed", - GTK_SIGNAL_FUNC (gimp_double_adjustment_update), - &options->opacity); + GTK_SIGNAL_FUNC (channels_dialog_opacity_update), + &options->color); gtk_widget_show (opacity_scale); /* The color panel */ @@ -2625,13 +2628,13 @@ typedef struct _EditChannelOptions EditChannelOptions; struct _EditChannelOptions { - GtkWidget *query_box; - GtkWidget *name_entry; + GtkWidget *query_box; + GtkWidget *name_entry; + ColorPanel *color_panel; ChannelWidget *channel_widget; GimpImage *gimage; - ColorPanel *color_panel; - gdouble opacity; + GimpRGB color; }; static void @@ -2640,13 +2643,9 @@ edit_channel_query_ok_callback (GtkWidget *widget, { EditChannelOptions *options; Channel *channel; - GimpRGB color; - gint opacity; - gint update = FALSE; options = (EditChannelOptions *) data; channel = options->channel_widget->channel; - opacity = (gint) (255 * options->opacity) / 100; if (options->gimage) { @@ -2656,28 +2655,13 @@ edit_channel_query_ok_callback (GtkWidget *widget, gtk_label_set_text (GTK_LABEL (options->channel_widget->label), gimp_object_get_name (GIMP_OBJECT (channel))); - if (channel->opacity != opacity) - { - channel->opacity = opacity; - update = TRUE; - } + options->color_panel->color.a = options->color.a; - gimp_rgb_set_uchar (&color, - channel->col[0], - channel->col[1], - channel->col[2]); - - if (gimp_rgb_distance (&options->color_panel->color, &color) > 0.0001) + if (gimp_rgba_distance (&options->color_panel->color, + &channel->color) > 0.0001) { - gimp_rgb_get_uchar (&options->color_panel->color, - &channel->col[0], - &channel->col[1], - &channel->col[2]); - update = TRUE; - } + channel->color = options->color_panel->color; - if (update) - { drawable_update (GIMP_DRAWABLE (channel), 0, 0, GIMP_DRAWABLE (channel)->width, GIMP_DRAWABLE (channel)->height); @@ -2692,23 +2676,20 @@ static void channels_dialog_edit_channel_query (ChannelWidget *channel_widget) { EditChannelOptions *options; - GtkWidget *hbox; - GtkWidget *vbox; - GtkWidget *table; - GtkWidget *label; - GtkWidget *opacity_scale; - GtkObject *opacity_scale_data; + GtkWidget *hbox; + GtkWidget *vbox; + GtkWidget *table; + GtkWidget *label; + GtkWidget *opacity_scale; + GtkObject *opacity_scale_data; /* the new options structure */ options = g_new (EditChannelOptions, 1); options->channel_widget = channel_widget; options->gimage = channel_widget->gimage; - options->opacity = (gdouble) channel_widget->channel->opacity / 2.55; + options->color = channel_widget->channel->color; - gimp_rgb_set_uchar (&channel_color, - channel_widget->channel->col[0], - channel_widget->channel->col[1], - channel_widget->channel->col[2]); + channel_color = options->color; options->color_panel = color_panel_new (&channel_color, FALSE, @@ -2772,13 +2753,13 @@ channels_dialog_edit_channel_query (ChannelWidget *channel_widget) 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", - GTK_SIGNAL_FUNC (gimp_double_adjustment_update), - &options->opacity); + GTK_SIGNAL_FUNC (channels_dialog_opacity_update), + &options->color); gtk_widget_show (opacity_scale); /* The color panel */ diff --git a/app/core/gimpchannel-combine.c b/app/core/gimpchannel-combine.c index 6b59f5add9..477ab9054b 100644 --- a/app/core/gimpchannel-combine.c +++ b/app/core/gimpchannel-combine.c @@ -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; - channel = gtk_type_new (gimp_channel_get_type ()); + g_return_val_if_fail (color != NULL, NULL); + + 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); diff --git a/app/core/gimpchannel-combine.h b/app/core/gimpchannel-combine.h index 5a7bcf653e..e7ccc22532 100644 --- a/app/core/gimpchannel-combine.h +++ b/app/core/gimpchannel-combine.h @@ -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__ */ diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c index 6b59f5add9..477ab9054b 100644 --- a/app/core/gimpchannel.c +++ b/app/core/gimpchannel.c @@ -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; - channel = gtk_type_new (gimp_channel_get_type ()); + g_return_val_if_fail (color != NULL, NULL); + + 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); diff --git a/app/core/gimpchannel.h b/app/core/gimpchannel.h index 5a7bcf653e..e7ccc22532 100644 --- a/app/core/gimpchannel.h +++ b/app/core/gimpchannel.h @@ -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__ */ diff --git a/app/core/gimpdrawable-offset.c b/app/core/gimpdrawable-offset.c index 232a1eac1c..bb503f7640 100644 --- a/app/core/gimpdrawable-offset.c +++ b/app/core/gimpdrawable-offset.c @@ -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: - new_guide = gimp_image_add_vguide(new_gimage); + new_guide = gimp_image_add_vguide (new_gimage); new_guide->position = guide->position; break; default: - g_error("Unknown guide orientation.\n"); + g_error ("Unknown guide orientation.\n"); } } + /* Copy the qmask info */ new_gimage->qmask_state = gimage->qmask_state; - for (count=0;count<3;count++) - new_gimage->qmask_color[count] = gimage->qmask_color[count]; - new_gimage->qmask_opacity = gimage->qmask_opacity; + new_gimage->qmask_color = gimage->qmask_color; /* Copy parasites */ parasites = gimage->parasites; @@ -726,9 +725,9 @@ duplicate (GimpImage *gimage) paths = gimp_image_get_paths (gimage); if (paths) { - GSList *plist = NULL; - GSList *new_plist = NULL; - Path *path; + GSList *plist = NULL; + GSList *new_plist = NULL; + Path *path; PathList *new_paths; for (plist = paths->bz_paths; plist; plist = plist->next) diff --git a/app/core/gimpimage-duplicate.c b/app/core/gimpimage-duplicate.c index 232a1eac1c..bb503f7640 100644 --- a/app/core/gimpimage-duplicate.c +++ b/app/core/gimpimage-duplicate.c @@ -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: - new_guide = gimp_image_add_vguide(new_gimage); + new_guide = gimp_image_add_vguide (new_gimage); new_guide->position = guide->position; break; default: - g_error("Unknown guide orientation.\n"); + g_error ("Unknown guide orientation.\n"); } } + /* Copy the qmask info */ new_gimage->qmask_state = gimage->qmask_state; - for (count=0;count<3;count++) - new_gimage->qmask_color[count] = gimage->qmask_color[count]; - new_gimage->qmask_opacity = gimage->qmask_opacity; + new_gimage->qmask_color = gimage->qmask_color; /* Copy parasites */ parasites = gimage->parasites; @@ -726,9 +725,9 @@ duplicate (GimpImage *gimage) paths = gimp_image_get_paths (gimage); if (paths) { - GSList *plist = NULL; - GSList *new_plist = NULL; - Path *path; + GSList *plist = NULL; + GSList *new_plist = NULL; + Path *path; PathList *new_paths; for (plist = paths->bz_paths; plist; plist = plist->next) diff --git a/app/core/gimpimage-guides.c b/app/core/gimpimage-guides.c index 532e1287d3..5cce116eeb 100644 --- a/app/core/gimpimage-guides.c +++ b/app/core/gimpimage-guides.c @@ -259,36 +259,67 @@ gimp_image_class_init (GimpImageClass *klass) static void gimp_image_init (GimpImage *gimage) { - gimage->num_cols = 0; + gimage->save_proc = NULL; + + gimage->width = 0; + gimage->height = 0; + gimage->xresolution = default_xresolution; + gimage->yresolution = default_yresolution; + gimage->unit = default_units; + gimage->base_type = RGB; + gimage->cmap = NULL; - gimage->disp_count = 0; - gimage->instance_count = 0; - gimage->shadow = NULL; + gimage->num_cols = 0; + gimage->dirty = 1; gimage->undo_on = TRUE; - gimage->construct_flag = -1; + + gimage->instance_count = 0; + gimage->disp_count = 0; + gimage->tattoo_state = 0; + + gimage->shadow = NULL; + + gimage->construct_flag = -1; + gimage->proj_type = RGBA_GIMAGE; gimage->projection = NULL; + gimage->guides = NULL; + gimage->layers = NULL; gimage->channels = NULL; gimage->layer_stack = NULL; + + gimage->active_layer = NULL; + gimage->active_channel = NULL; + gimage->floating_sel = NULL; + gimage->selection_mask = NULL; + + gimage->parasites = parasite_list_new (); + + gimage->paths = NULL; + + gimage->by_color_select = FALSE; + + gimage->qmask_state = FALSE; + gimage->qmask_color.r = 1.0; + gimage->qmask_color.g = 0.0; + gimage->qmask_color.b = 0.0; + gimage->qmask_color.a = 0.5; + gimage->undo_stack = NULL; gimage->redo_stack = NULL; gimage->undo_bytes = 0; gimage->undo_levels = 0; gimage->group_count = 0; gimage->pushing_undo_group = UNDO_NULL; + gimage->undo_history = NULL; + + gimage->comp_preview = NULL; gimage->comp_preview_valid[0] = FALSE; gimage->comp_preview_valid[1] = FALSE; gimage->comp_preview_valid[2] = FALSE; - gimage->comp_preview = NULL; - gimage->parasites = parasite_list_new (); - gimage->xresolution = default_xresolution; - gimage->yresolution = default_yresolution; - gimage->unit = default_units; - gimage->save_proc = NULL; - gimage->paths = NULL; } GtkType @@ -342,7 +373,8 @@ gimp_image_allocate_projection (GimpImage *gimage) } /* allocate the new projection */ - gimage->projection = tile_manager_new (gimage->width, gimage->height, gimage->proj_bytes); + gimage->projection = tile_manager_new (gimage->width, gimage->height, + gimage->proj_bytes); tile_manager_set_user_data (gimage->projection, (void *) gimage); tile_manager_set_validate_proc (gimage->projection, gimp_image_validate); } @@ -395,11 +427,6 @@ gimp_image_new (gint width, break; } - /* configure the active pointers */ - gimage->active_layer = NULL; - gimage->active_channel = NULL; /* no default active channel */ - gimage->floating_sel = NULL; - /* set all color channels visible and active */ for (i = 0; i < MAX_CHANNELS; i++) { @@ -411,12 +438,6 @@ gimp_image_new (gint width, gimage->selection_mask = channel_new_mask (gimage, gimage->width, gimage->height); - /* set the qmask properties */ - gimage->qmask_state = FALSE; - gimage->qmask_opacity = 50; - gimage->qmask_color[0] = 255; - gimage->qmask_color[1] = 0; - gimage->qmask_color[2] = 0; return gimage; } @@ -1524,20 +1545,27 @@ project_channel (GimpImage *gimage, PixelRegion *src, PixelRegion *src2) { - gint type; + guchar col[3]; + guchar opacity; + gint type; + + gimp_rgba_get_uchar (&channel->color, + &col[0], &col[1], &col[2], &opacity); if (! gimage->construct_flag) { type = (channel->show_masked) ? INITIAL_CHANNEL_MASK : INITIAL_CHANNEL_SELECTION; - initial_region (src2, src, NULL, channel->col, channel->opacity, + + initial_region (src2, src, NULL, col, opacity, NORMAL_MODE, NULL, type); } else { type = (channel->show_masked) ? COMBINE_INTEN_A_CHANNEL_MASK : COMBINE_INTEN_A_CHANNEL_SELECTION; - combine_regions (src, src2, src, NULL, channel->col, channel->opacity, + + combine_regions (src, src2, src, NULL, col, opacity, NORMAL_MODE, NULL, type); } } diff --git a/app/core/gimpimage-guides.h b/app/core/gimpimage-guides.h index d478c732db..08d850d8a0 100644 --- a/app/core/gimpimage-guides.h +++ b/app/core/gimpimage-guides.h @@ -100,8 +100,7 @@ struct _GimpImage /* "by color" selection dialog */ gboolean qmask_state; /* TRUE if qmask is on */ - gdouble qmask_opacity; /* opacity of the qmask channel */ - guchar qmask_color[3]; /* rgb triplet of the color */ + GimpRGB qmask_color; /* rgba triplet of the color */ /* Undo apparatus */ GSList *undo_stack; /* stack for undo operations */ diff --git a/app/core/gimpimage-merge.c b/app/core/gimpimage-merge.c index 532e1287d3..5cce116eeb 100644 --- a/app/core/gimpimage-merge.c +++ b/app/core/gimpimage-merge.c @@ -259,36 +259,67 @@ gimp_image_class_init (GimpImageClass *klass) static void gimp_image_init (GimpImage *gimage) { - gimage->num_cols = 0; + gimage->save_proc = NULL; + + gimage->width = 0; + gimage->height = 0; + gimage->xresolution = default_xresolution; + gimage->yresolution = default_yresolution; + gimage->unit = default_units; + gimage->base_type = RGB; + gimage->cmap = NULL; - gimage->disp_count = 0; - gimage->instance_count = 0; - gimage->shadow = NULL; + gimage->num_cols = 0; + gimage->dirty = 1; gimage->undo_on = TRUE; - gimage->construct_flag = -1; + + gimage->instance_count = 0; + gimage->disp_count = 0; + gimage->tattoo_state = 0; + + gimage->shadow = NULL; + + gimage->construct_flag = -1; + gimage->proj_type = RGBA_GIMAGE; gimage->projection = NULL; + gimage->guides = NULL; + gimage->layers = NULL; gimage->channels = NULL; gimage->layer_stack = NULL; + + gimage->active_layer = NULL; + gimage->active_channel = NULL; + gimage->floating_sel = NULL; + gimage->selection_mask = NULL; + + gimage->parasites = parasite_list_new (); + + gimage->paths = NULL; + + gimage->by_color_select = FALSE; + + gimage->qmask_state = FALSE; + gimage->qmask_color.r = 1.0; + gimage->qmask_color.g = 0.0; + gimage->qmask_color.b = 0.0; + gimage->qmask_color.a = 0.5; + gimage->undo_stack = NULL; gimage->redo_stack = NULL; gimage->undo_bytes = 0; gimage->undo_levels = 0; gimage->group_count = 0; gimage->pushing_undo_group = UNDO_NULL; + gimage->undo_history = NULL; + + gimage->comp_preview = NULL; gimage->comp_preview_valid[0] = FALSE; gimage->comp_preview_valid[1] = FALSE; gimage->comp_preview_valid[2] = FALSE; - gimage->comp_preview = NULL; - gimage->parasites = parasite_list_new (); - gimage->xresolution = default_xresolution; - gimage->yresolution = default_yresolution; - gimage->unit = default_units; - gimage->save_proc = NULL; - gimage->paths = NULL; } GtkType @@ -342,7 +373,8 @@ gimp_image_allocate_projection (GimpImage *gimage) } /* allocate the new projection */ - gimage->projection = tile_manager_new (gimage->width, gimage->height, gimage->proj_bytes); + gimage->projection = tile_manager_new (gimage->width, gimage->height, + gimage->proj_bytes); tile_manager_set_user_data (gimage->projection, (void *) gimage); tile_manager_set_validate_proc (gimage->projection, gimp_image_validate); } @@ -395,11 +427,6 @@ gimp_image_new (gint width, break; } - /* configure the active pointers */ - gimage->active_layer = NULL; - gimage->active_channel = NULL; /* no default active channel */ - gimage->floating_sel = NULL; - /* set all color channels visible and active */ for (i = 0; i < MAX_CHANNELS; i++) { @@ -411,12 +438,6 @@ gimp_image_new (gint width, gimage->selection_mask = channel_new_mask (gimage, gimage->width, gimage->height); - /* set the qmask properties */ - gimage->qmask_state = FALSE; - gimage->qmask_opacity = 50; - gimage->qmask_color[0] = 255; - gimage->qmask_color[1] = 0; - gimage->qmask_color[2] = 0; return gimage; } @@ -1524,20 +1545,27 @@ project_channel (GimpImage *gimage, PixelRegion *src, PixelRegion *src2) { - gint type; + guchar col[3]; + guchar opacity; + gint type; + + gimp_rgba_get_uchar (&channel->color, + &col[0], &col[1], &col[2], &opacity); if (! gimage->construct_flag) { type = (channel->show_masked) ? INITIAL_CHANNEL_MASK : INITIAL_CHANNEL_SELECTION; - initial_region (src2, src, NULL, channel->col, channel->opacity, + + initial_region (src2, src, NULL, col, opacity, NORMAL_MODE, NULL, type); } else { type = (channel->show_masked) ? COMBINE_INTEN_A_CHANNEL_MASK : COMBINE_INTEN_A_CHANNEL_SELECTION; - combine_regions (src, src2, src, NULL, channel->col, channel->opacity, + + combine_regions (src, src2, src, NULL, col, opacity, NORMAL_MODE, NULL, type); } } diff --git a/app/core/gimpimage-merge.h b/app/core/gimpimage-merge.h index d478c732db..08d850d8a0 100644 --- a/app/core/gimpimage-merge.h +++ b/app/core/gimpimage-merge.h @@ -100,8 +100,7 @@ struct _GimpImage /* "by color" selection dialog */ gboolean qmask_state; /* TRUE if qmask is on */ - gdouble qmask_opacity; /* opacity of the qmask channel */ - guchar qmask_color[3]; /* rgb triplet of the color */ + GimpRGB qmask_color; /* rgba triplet of the color */ /* Undo apparatus */ GSList *undo_stack; /* stack for undo operations */ diff --git a/app/core/gimpimage-projection.c b/app/core/gimpimage-projection.c index 532e1287d3..5cce116eeb 100644 --- a/app/core/gimpimage-projection.c +++ b/app/core/gimpimage-projection.c @@ -259,36 +259,67 @@ gimp_image_class_init (GimpImageClass *klass) static void gimp_image_init (GimpImage *gimage) { - gimage->num_cols = 0; + gimage->save_proc = NULL; + + gimage->width = 0; + gimage->height = 0; + gimage->xresolution = default_xresolution; + gimage->yresolution = default_yresolution; + gimage->unit = default_units; + gimage->base_type = RGB; + gimage->cmap = NULL; - gimage->disp_count = 0; - gimage->instance_count = 0; - gimage->shadow = NULL; + gimage->num_cols = 0; + gimage->dirty = 1; gimage->undo_on = TRUE; - gimage->construct_flag = -1; + + gimage->instance_count = 0; + gimage->disp_count = 0; + gimage->tattoo_state = 0; + + gimage->shadow = NULL; + + gimage->construct_flag = -1; + gimage->proj_type = RGBA_GIMAGE; gimage->projection = NULL; + gimage->guides = NULL; + gimage->layers = NULL; gimage->channels = NULL; gimage->layer_stack = NULL; + + gimage->active_layer = NULL; + gimage->active_channel = NULL; + gimage->floating_sel = NULL; + gimage->selection_mask = NULL; + + gimage->parasites = parasite_list_new (); + + gimage->paths = NULL; + + gimage->by_color_select = FALSE; + + gimage->qmask_state = FALSE; + gimage->qmask_color.r = 1.0; + gimage->qmask_color.g = 0.0; + gimage->qmask_color.b = 0.0; + gimage->qmask_color.a = 0.5; + gimage->undo_stack = NULL; gimage->redo_stack = NULL; gimage->undo_bytes = 0; gimage->undo_levels = 0; gimage->group_count = 0; gimage->pushing_undo_group = UNDO_NULL; + gimage->undo_history = NULL; + + gimage->comp_preview = NULL; gimage->comp_preview_valid[0] = FALSE; gimage->comp_preview_valid[1] = FALSE; gimage->comp_preview_valid[2] = FALSE; - gimage->comp_preview = NULL; - gimage->parasites = parasite_list_new (); - gimage->xresolution = default_xresolution; - gimage->yresolution = default_yresolution; - gimage->unit = default_units; - gimage->save_proc = NULL; - gimage->paths = NULL; } GtkType @@ -342,7 +373,8 @@ gimp_image_allocate_projection (GimpImage *gimage) } /* allocate the new projection */ - gimage->projection = tile_manager_new (gimage->width, gimage->height, gimage->proj_bytes); + gimage->projection = tile_manager_new (gimage->width, gimage->height, + gimage->proj_bytes); tile_manager_set_user_data (gimage->projection, (void *) gimage); tile_manager_set_validate_proc (gimage->projection, gimp_image_validate); } @@ -395,11 +427,6 @@ gimp_image_new (gint width, break; } - /* configure the active pointers */ - gimage->active_layer = NULL; - gimage->active_channel = NULL; /* no default active channel */ - gimage->floating_sel = NULL; - /* set all color channels visible and active */ for (i = 0; i < MAX_CHANNELS; i++) { @@ -411,12 +438,6 @@ gimp_image_new (gint width, gimage->selection_mask = channel_new_mask (gimage, gimage->width, gimage->height); - /* set the qmask properties */ - gimage->qmask_state = FALSE; - gimage->qmask_opacity = 50; - gimage->qmask_color[0] = 255; - gimage->qmask_color[1] = 0; - gimage->qmask_color[2] = 0; return gimage; } @@ -1524,20 +1545,27 @@ project_channel (GimpImage *gimage, PixelRegion *src, PixelRegion *src2) { - gint type; + guchar col[3]; + guchar opacity; + gint type; + + gimp_rgba_get_uchar (&channel->color, + &col[0], &col[1], &col[2], &opacity); if (! gimage->construct_flag) { type = (channel->show_masked) ? INITIAL_CHANNEL_MASK : INITIAL_CHANNEL_SELECTION; - initial_region (src2, src, NULL, channel->col, channel->opacity, + + initial_region (src2, src, NULL, col, opacity, NORMAL_MODE, NULL, type); } else { type = (channel->show_masked) ? COMBINE_INTEN_A_CHANNEL_MASK : COMBINE_INTEN_A_CHANNEL_SELECTION; - combine_regions (src, src2, src, NULL, channel->col, channel->opacity, + + combine_regions (src, src2, src, NULL, col, opacity, NORMAL_MODE, NULL, type); } } diff --git a/app/core/gimpimage-projection.h b/app/core/gimpimage-projection.h index d478c732db..08d850d8a0 100644 --- a/app/core/gimpimage-projection.h +++ b/app/core/gimpimage-projection.h @@ -100,8 +100,7 @@ struct _GimpImage /* "by color" selection dialog */ gboolean qmask_state; /* TRUE if qmask is on */ - gdouble qmask_opacity; /* opacity of the qmask channel */ - guchar qmask_color[3]; /* rgb triplet of the color */ + GimpRGB qmask_color; /* rgba triplet of the color */ /* Undo apparatus */ GSList *undo_stack; /* stack for undo operations */ diff --git a/app/core/gimpimage-qmask.c b/app/core/gimpimage-qmask.c index 81f5d5d534..cbc81a0e26 100644 --- a/app/core/gimpimage-qmask.c +++ b/app/core/gimpimage-qmask.c @@ -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); + + options->color_panel->color.a = options->color.a; 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); - - 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 (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); } - - - - - diff --git a/app/core/gimpimage-quick-mask.c b/app/core/gimpimage-quick-mask.c index 81f5d5d534..cbc81a0e26 100644 --- a/app/core/gimpimage-quick-mask.c +++ b/app/core/gimpimage-quick-mask.c @@ -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); + + options->color_panel->color.a = options->color.a; 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); - - 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 (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); } - - - - - diff --git a/app/core/gimpimage-resize.c b/app/core/gimpimage-resize.c index 532e1287d3..5cce116eeb 100644 --- a/app/core/gimpimage-resize.c +++ b/app/core/gimpimage-resize.c @@ -259,36 +259,67 @@ gimp_image_class_init (GimpImageClass *klass) static void gimp_image_init (GimpImage *gimage) { - gimage->num_cols = 0; + gimage->save_proc = NULL; + + gimage->width = 0; + gimage->height = 0; + gimage->xresolution = default_xresolution; + gimage->yresolution = default_yresolution; + gimage->unit = default_units; + gimage->base_type = RGB; + gimage->cmap = NULL; - gimage->disp_count = 0; - gimage->instance_count = 0; - gimage->shadow = NULL; + gimage->num_cols = 0; + gimage->dirty = 1; gimage->undo_on = TRUE; - gimage->construct_flag = -1; + + gimage->instance_count = 0; + gimage->disp_count = 0; + gimage->tattoo_state = 0; + + gimage->shadow = NULL; + + gimage->construct_flag = -1; + gimage->proj_type = RGBA_GIMAGE; gimage->projection = NULL; + gimage->guides = NULL; + gimage->layers = NULL; gimage->channels = NULL; gimage->layer_stack = NULL; + + gimage->active_layer = NULL; + gimage->active_channel = NULL; + gimage->floating_sel = NULL; + gimage->selection_mask = NULL; + + gimage->parasites = parasite_list_new (); + + gimage->paths = NULL; + + gimage->by_color_select = FALSE; + + gimage->qmask_state = FALSE; + gimage->qmask_color.r = 1.0; + gimage->qmask_color.g = 0.0; + gimage->qmask_color.b = 0.0; + gimage->qmask_color.a = 0.5; + gimage->undo_stack = NULL; gimage->redo_stack = NULL; gimage->undo_bytes = 0; gimage->undo_levels = 0; gimage->group_count = 0; gimage->pushing_undo_group = UNDO_NULL; + gimage->undo_history = NULL; + + gimage->comp_preview = NULL; gimage->comp_preview_valid[0] = FALSE; gimage->comp_preview_valid[1] = FALSE; gimage->comp_preview_valid[2] = FALSE; - gimage->comp_preview = NULL; - gimage->parasites = parasite_list_new (); - gimage->xresolution = default_xresolution; - gimage->yresolution = default_yresolution; - gimage->unit = default_units; - gimage->save_proc = NULL; - gimage->paths = NULL; } GtkType @@ -342,7 +373,8 @@ gimp_image_allocate_projection (GimpImage *gimage) } /* allocate the new projection */ - gimage->projection = tile_manager_new (gimage->width, gimage->height, gimage->proj_bytes); + gimage->projection = tile_manager_new (gimage->width, gimage->height, + gimage->proj_bytes); tile_manager_set_user_data (gimage->projection, (void *) gimage); tile_manager_set_validate_proc (gimage->projection, gimp_image_validate); } @@ -395,11 +427,6 @@ gimp_image_new (gint width, break; } - /* configure the active pointers */ - gimage->active_layer = NULL; - gimage->active_channel = NULL; /* no default active channel */ - gimage->floating_sel = NULL; - /* set all color channels visible and active */ for (i = 0; i < MAX_CHANNELS; i++) { @@ -411,12 +438,6 @@ gimp_image_new (gint width, gimage->selection_mask = channel_new_mask (gimage, gimage->width, gimage->height); - /* set the qmask properties */ - gimage->qmask_state = FALSE; - gimage->qmask_opacity = 50; - gimage->qmask_color[0] = 255; - gimage->qmask_color[1] = 0; - gimage->qmask_color[2] = 0; return gimage; } @@ -1524,20 +1545,27 @@ project_channel (GimpImage *gimage, PixelRegion *src, PixelRegion *src2) { - gint type; + guchar col[3]; + guchar opacity; + gint type; + + gimp_rgba_get_uchar (&channel->color, + &col[0], &col[1], &col[2], &opacity); if (! gimage->construct_flag) { type = (channel->show_masked) ? INITIAL_CHANNEL_MASK : INITIAL_CHANNEL_SELECTION; - initial_region (src2, src, NULL, channel->col, channel->opacity, + + initial_region (src2, src, NULL, col, opacity, NORMAL_MODE, NULL, type); } else { type = (channel->show_masked) ? COMBINE_INTEN_A_CHANNEL_MASK : COMBINE_INTEN_A_CHANNEL_SELECTION; - combine_regions (src, src2, src, NULL, channel->col, channel->opacity, + + combine_regions (src, src2, src, NULL, col, opacity, NORMAL_MODE, NULL, type); } } diff --git a/app/core/gimpimage-resize.h b/app/core/gimpimage-resize.h index d478c732db..08d850d8a0 100644 --- a/app/core/gimpimage-resize.h +++ b/app/core/gimpimage-resize.h @@ -100,8 +100,7 @@ struct _GimpImage /* "by color" selection dialog */ gboolean qmask_state; /* TRUE if qmask is on */ - gdouble qmask_opacity; /* opacity of the qmask channel */ - guchar qmask_color[3]; /* rgb triplet of the color */ + GimpRGB qmask_color; /* rgba triplet of the color */ /* Undo apparatus */ GSList *undo_stack; /* stack for undo operations */ diff --git a/app/core/gimpimage-scale.c b/app/core/gimpimage-scale.c index 532e1287d3..5cce116eeb 100644 --- a/app/core/gimpimage-scale.c +++ b/app/core/gimpimage-scale.c @@ -259,36 +259,67 @@ gimp_image_class_init (GimpImageClass *klass) static void gimp_image_init (GimpImage *gimage) { - gimage->num_cols = 0; + gimage->save_proc = NULL; + + gimage->width = 0; + gimage->height = 0; + gimage->xresolution = default_xresolution; + gimage->yresolution = default_yresolution; + gimage->unit = default_units; + gimage->base_type = RGB; + gimage->cmap = NULL; - gimage->disp_count = 0; - gimage->instance_count = 0; - gimage->shadow = NULL; + gimage->num_cols = 0; + gimage->dirty = 1; gimage->undo_on = TRUE; - gimage->construct_flag = -1; + + gimage->instance_count = 0; + gimage->disp_count = 0; + gimage->tattoo_state = 0; + + gimage->shadow = NULL; + + gimage->construct_flag = -1; + gimage->proj_type = RGBA_GIMAGE; gimage->projection = NULL; + gimage->guides = NULL; + gimage->layers = NULL; gimage->channels = NULL; gimage->layer_stack = NULL; + + gimage->active_layer = NULL; + gimage->active_channel = NULL; + gimage->floating_sel = NULL; + gimage->selection_mask = NULL; + + gimage->parasites = parasite_list_new (); + + gimage->paths = NULL; + + gimage->by_color_select = FALSE; + + gimage->qmask_state = FALSE; + gimage->qmask_color.r = 1.0; + gimage->qmask_color.g = 0.0; + gimage->qmask_color.b = 0.0; + gimage->qmask_color.a = 0.5; + gimage->undo_stack = NULL; gimage->redo_stack = NULL; gimage->undo_bytes = 0; gimage->undo_levels = 0; gimage->group_count = 0; gimage->pushing_undo_group = UNDO_NULL; + gimage->undo_history = NULL; + + gimage->comp_preview = NULL; gimage->comp_preview_valid[0] = FALSE; gimage->comp_preview_valid[1] = FALSE; gimage->comp_preview_valid[2] = FALSE; - gimage->comp_preview = NULL; - gimage->parasites = parasite_list_new (); - gimage->xresolution = default_xresolution; - gimage->yresolution = default_yresolution; - gimage->unit = default_units; - gimage->save_proc = NULL; - gimage->paths = NULL; } GtkType @@ -342,7 +373,8 @@ gimp_image_allocate_projection (GimpImage *gimage) } /* allocate the new projection */ - gimage->projection = tile_manager_new (gimage->width, gimage->height, gimage->proj_bytes); + gimage->projection = tile_manager_new (gimage->width, gimage->height, + gimage->proj_bytes); tile_manager_set_user_data (gimage->projection, (void *) gimage); tile_manager_set_validate_proc (gimage->projection, gimp_image_validate); } @@ -395,11 +427,6 @@ gimp_image_new (gint width, break; } - /* configure the active pointers */ - gimage->active_layer = NULL; - gimage->active_channel = NULL; /* no default active channel */ - gimage->floating_sel = NULL; - /* set all color channels visible and active */ for (i = 0; i < MAX_CHANNELS; i++) { @@ -411,12 +438,6 @@ gimp_image_new (gint width, gimage->selection_mask = channel_new_mask (gimage, gimage->width, gimage->height); - /* set the qmask properties */ - gimage->qmask_state = FALSE; - gimage->qmask_opacity = 50; - gimage->qmask_color[0] = 255; - gimage->qmask_color[1] = 0; - gimage->qmask_color[2] = 0; return gimage; } @@ -1524,20 +1545,27 @@ project_channel (GimpImage *gimage, PixelRegion *src, PixelRegion *src2) { - gint type; + guchar col[3]; + guchar opacity; + gint type; + + gimp_rgba_get_uchar (&channel->color, + &col[0], &col[1], &col[2], &opacity); if (! gimage->construct_flag) { type = (channel->show_masked) ? INITIAL_CHANNEL_MASK : INITIAL_CHANNEL_SELECTION; - initial_region (src2, src, NULL, channel->col, channel->opacity, + + initial_region (src2, src, NULL, col, opacity, NORMAL_MODE, NULL, type); } else { type = (channel->show_masked) ? COMBINE_INTEN_A_CHANNEL_MASK : COMBINE_INTEN_A_CHANNEL_SELECTION; - combine_regions (src, src2, src, NULL, channel->col, channel->opacity, + + combine_regions (src, src2, src, NULL, col, opacity, NORMAL_MODE, NULL, type); } } diff --git a/app/core/gimpimage-scale.h b/app/core/gimpimage-scale.h index d478c732db..08d850d8a0 100644 --- a/app/core/gimpimage-scale.h +++ b/app/core/gimpimage-scale.h @@ -100,8 +100,7 @@ struct _GimpImage /* "by color" selection dialog */ gboolean qmask_state; /* TRUE if qmask is on */ - gdouble qmask_opacity; /* opacity of the qmask channel */ - guchar qmask_color[3]; /* rgb triplet of the color */ + GimpRGB qmask_color; /* rgba triplet of the color */ /* Undo apparatus */ GSList *undo_stack; /* stack for undo operations */ diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c index 532e1287d3..5cce116eeb 100644 --- a/app/core/gimpimage.c +++ b/app/core/gimpimage.c @@ -259,36 +259,67 @@ gimp_image_class_init (GimpImageClass *klass) static void gimp_image_init (GimpImage *gimage) { - gimage->num_cols = 0; + gimage->save_proc = NULL; + + gimage->width = 0; + gimage->height = 0; + gimage->xresolution = default_xresolution; + gimage->yresolution = default_yresolution; + gimage->unit = default_units; + gimage->base_type = RGB; + gimage->cmap = NULL; - gimage->disp_count = 0; - gimage->instance_count = 0; - gimage->shadow = NULL; + gimage->num_cols = 0; + gimage->dirty = 1; gimage->undo_on = TRUE; - gimage->construct_flag = -1; + + gimage->instance_count = 0; + gimage->disp_count = 0; + gimage->tattoo_state = 0; + + gimage->shadow = NULL; + + gimage->construct_flag = -1; + gimage->proj_type = RGBA_GIMAGE; gimage->projection = NULL; + gimage->guides = NULL; + gimage->layers = NULL; gimage->channels = NULL; gimage->layer_stack = NULL; + + gimage->active_layer = NULL; + gimage->active_channel = NULL; + gimage->floating_sel = NULL; + gimage->selection_mask = NULL; + + gimage->parasites = parasite_list_new (); + + gimage->paths = NULL; + + gimage->by_color_select = FALSE; + + gimage->qmask_state = FALSE; + gimage->qmask_color.r = 1.0; + gimage->qmask_color.g = 0.0; + gimage->qmask_color.b = 0.0; + gimage->qmask_color.a = 0.5; + gimage->undo_stack = NULL; gimage->redo_stack = NULL; gimage->undo_bytes = 0; gimage->undo_levels = 0; gimage->group_count = 0; gimage->pushing_undo_group = UNDO_NULL; + gimage->undo_history = NULL; + + gimage->comp_preview = NULL; gimage->comp_preview_valid[0] = FALSE; gimage->comp_preview_valid[1] = FALSE; gimage->comp_preview_valid[2] = FALSE; - gimage->comp_preview = NULL; - gimage->parasites = parasite_list_new (); - gimage->xresolution = default_xresolution; - gimage->yresolution = default_yresolution; - gimage->unit = default_units; - gimage->save_proc = NULL; - gimage->paths = NULL; } GtkType @@ -342,7 +373,8 @@ gimp_image_allocate_projection (GimpImage *gimage) } /* allocate the new projection */ - gimage->projection = tile_manager_new (gimage->width, gimage->height, gimage->proj_bytes); + gimage->projection = tile_manager_new (gimage->width, gimage->height, + gimage->proj_bytes); tile_manager_set_user_data (gimage->projection, (void *) gimage); tile_manager_set_validate_proc (gimage->projection, gimp_image_validate); } @@ -395,11 +427,6 @@ gimp_image_new (gint width, break; } - /* configure the active pointers */ - gimage->active_layer = NULL; - gimage->active_channel = NULL; /* no default active channel */ - gimage->floating_sel = NULL; - /* set all color channels visible and active */ for (i = 0; i < MAX_CHANNELS; i++) { @@ -411,12 +438,6 @@ gimp_image_new (gint width, gimage->selection_mask = channel_new_mask (gimage, gimage->width, gimage->height); - /* set the qmask properties */ - gimage->qmask_state = FALSE; - gimage->qmask_opacity = 50; - gimage->qmask_color[0] = 255; - gimage->qmask_color[1] = 0; - gimage->qmask_color[2] = 0; return gimage; } @@ -1524,20 +1545,27 @@ project_channel (GimpImage *gimage, PixelRegion *src, PixelRegion *src2) { - gint type; + guchar col[3]; + guchar opacity; + gint type; + + gimp_rgba_get_uchar (&channel->color, + &col[0], &col[1], &col[2], &opacity); if (! gimage->construct_flag) { type = (channel->show_masked) ? INITIAL_CHANNEL_MASK : INITIAL_CHANNEL_SELECTION; - initial_region (src2, src, NULL, channel->col, channel->opacity, + + initial_region (src2, src, NULL, col, opacity, NORMAL_MODE, NULL, type); } else { type = (channel->show_masked) ? COMBINE_INTEN_A_CHANNEL_MASK : COMBINE_INTEN_A_CHANNEL_SELECTION; - combine_regions (src, src2, src, NULL, channel->col, channel->opacity, + + combine_regions (src, src2, src, NULL, col, opacity, NORMAL_MODE, NULL, type); } } diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h index d478c732db..08d850d8a0 100644 --- a/app/core/gimpimage.h +++ b/app/core/gimpimage.h @@ -100,8 +100,7 @@ struct _GimpImage /* "by color" selection dialog */ gboolean qmask_state; /* TRUE if qmask is on */ - gdouble qmask_opacity; /* opacity of the qmask channel */ - guchar qmask_color[3]; /* rgb triplet of the color */ + GimpRGB qmask_color; /* rgba triplet of the color */ /* Undo apparatus */ GSList *undo_stack; /* stack for undo operations */ diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c index 046c3959ab..5359490d2e 100644 --- a/app/core/gimplayer.c +++ b/app/core/gimplayer.c @@ -500,7 +500,7 @@ layer_create_mask (Layer *layer, PixelRegion layerPR; LayerMask *mask; gchar *mask_name; - guchar black[3] = {0, 0, 0}; + GimpRGB black = { 0.0, 0.0, 0.0, 1.0 }; guchar white_mask = OPAQUE_OPACITY; guchar black_mask = TRANSPARENT_OPACITY; @@ -511,7 +511,7 @@ layer_create_mask (Layer *layer, mask = layer_mask_new (GIMP_DRAWABLE (layer)->gimage, GIMP_DRAWABLE (layer)->width, GIMP_DRAWABLE (layer)->height, - mask_name, OPAQUE_OPACITY, black); + mask_name, &black); GIMP_DRAWABLE (mask)->offset_x = GIMP_DRAWABLE (layer)->offset_x; GIMP_DRAWABLE (mask)->offset_y = GIMP_DRAWABLE (layer)->offset_y; @@ -1708,15 +1708,13 @@ gimp_layer_mask_destroy (GtkObject *object) } LayerMask * -layer_mask_new (GimpImage *gimage, - gint width, - gint height, - gchar *name, - gint opacity, - guchar *col) +layer_mask_new (GimpImage *gimage, + gint width, + gint height, + const gchar *name, + const GimpRGB *color) { LayerMask *layer_mask; - gint i; layer_mask = gtk_type_new (GIMP_TYPE_LAYER_MASK); @@ -1724,10 +1722,8 @@ layer_mask_new (GimpImage *gimage, gimage, width, height, GRAY_GIMAGE, name); /* set the layer_mask color and opacity */ - for (i = 0; i < 3; i++) - GIMP_CHANNEL (layer_mask)->col[i] = col[i]; + GIMP_CHANNEL (layer_mask)->color = *color; - GIMP_CHANNEL (layer_mask)->opacity = opacity; GIMP_CHANNEL (layer_mask)->show_masked = TRUE; /* selection mask variables */ @@ -1738,7 +1734,8 @@ layer_mask_new (GimpImage *gimage, GIMP_CHANNEL (layer_mask)->num_segs_out = 0; GIMP_CHANNEL (layer_mask)->bounds_known = TRUE; GIMP_CHANNEL (layer_mask)->boundary_known = TRUE; - GIMP_CHANNEL (layer_mask)->x1 = GIMP_CHANNEL (layer_mask)->y1 = 0; + GIMP_CHANNEL (layer_mask)->x1 = 0; + GIMP_CHANNEL (layer_mask)->y1 = 0; GIMP_CHANNEL (layer_mask)->x2 = width; GIMP_CHANNEL (layer_mask)->y2 = height; @@ -1758,12 +1755,11 @@ layer_mask_copy (LayerMask *layer_mask) gimp_object_get_name (GIMP_OBJECT (layer_mask))); /* allocate a new layer_mask object */ - new_layer_mask = layer_mask_new (GIMP_DRAWABLE(layer_mask)->gimage, - GIMP_DRAWABLE(layer_mask)->width, - GIMP_DRAWABLE(layer_mask)->height, - layer_mask_name, - GIMP_CHANNEL(layer_mask)->opacity, - GIMP_CHANNEL(layer_mask)->col); + new_layer_mask = layer_mask_new (GIMP_DRAWABLE (layer_mask)->gimage, + GIMP_DRAWABLE (layer_mask)->width, + GIMP_DRAWABLE (layer_mask)->height, + layer_mask_name, + &GIMP_CHANNEL (layer_mask)->color); GIMP_DRAWABLE(new_layer_mask)->visible = GIMP_DRAWABLE(layer_mask)->visible; GIMP_DRAWABLE(new_layer_mask)->offset_x = diff --git a/app/core/gimplayer.h b/app/core/gimplayer.h index 2165c1b3a6..b8085bac07 100644 --- a/app/core/gimplayer.h +++ b/app/core/gimplayer.h @@ -170,9 +170,8 @@ GtkType gimp_layer_mask_get_type (void); LayerMask * layer_mask_new (GimpImage *gimage, gint width, gint height, - gchar *name, - gint opacity, - guchar *col); + const gchar *name, + const GimpRGB *color); LayerMask * layer_mask_copy (LayerMask *layer_mask); void layer_mask_delete (LayerMask *layer_mask); LayerMask * layer_mask_ref (LayerMask *layer_mask); diff --git a/app/core/gimpprojection-construct.c b/app/core/gimpprojection-construct.c index 532e1287d3..5cce116eeb 100644 --- a/app/core/gimpprojection-construct.c +++ b/app/core/gimpprojection-construct.c @@ -259,36 +259,67 @@ gimp_image_class_init (GimpImageClass *klass) static void gimp_image_init (GimpImage *gimage) { - gimage->num_cols = 0; + gimage->save_proc = NULL; + + gimage->width = 0; + gimage->height = 0; + gimage->xresolution = default_xresolution; + gimage->yresolution = default_yresolution; + gimage->unit = default_units; + gimage->base_type = RGB; + gimage->cmap = NULL; - gimage->disp_count = 0; - gimage->instance_count = 0; - gimage->shadow = NULL; + gimage->num_cols = 0; + gimage->dirty = 1; gimage->undo_on = TRUE; - gimage->construct_flag = -1; + + gimage->instance_count = 0; + gimage->disp_count = 0; + gimage->tattoo_state = 0; + + gimage->shadow = NULL; + + gimage->construct_flag = -1; + gimage->proj_type = RGBA_GIMAGE; gimage->projection = NULL; + gimage->guides = NULL; + gimage->layers = NULL; gimage->channels = NULL; gimage->layer_stack = NULL; + + gimage->active_layer = NULL; + gimage->active_channel = NULL; + gimage->floating_sel = NULL; + gimage->selection_mask = NULL; + + gimage->parasites = parasite_list_new (); + + gimage->paths = NULL; + + gimage->by_color_select = FALSE; + + gimage->qmask_state = FALSE; + gimage->qmask_color.r = 1.0; + gimage->qmask_color.g = 0.0; + gimage->qmask_color.b = 0.0; + gimage->qmask_color.a = 0.5; + gimage->undo_stack = NULL; gimage->redo_stack = NULL; gimage->undo_bytes = 0; gimage->undo_levels = 0; gimage->group_count = 0; gimage->pushing_undo_group = UNDO_NULL; + gimage->undo_history = NULL; + + gimage->comp_preview = NULL; gimage->comp_preview_valid[0] = FALSE; gimage->comp_preview_valid[1] = FALSE; gimage->comp_preview_valid[2] = FALSE; - gimage->comp_preview = NULL; - gimage->parasites = parasite_list_new (); - gimage->xresolution = default_xresolution; - gimage->yresolution = default_yresolution; - gimage->unit = default_units; - gimage->save_proc = NULL; - gimage->paths = NULL; } GtkType @@ -342,7 +373,8 @@ gimp_image_allocate_projection (GimpImage *gimage) } /* allocate the new projection */ - gimage->projection = tile_manager_new (gimage->width, gimage->height, gimage->proj_bytes); + gimage->projection = tile_manager_new (gimage->width, gimage->height, + gimage->proj_bytes); tile_manager_set_user_data (gimage->projection, (void *) gimage); tile_manager_set_validate_proc (gimage->projection, gimp_image_validate); } @@ -395,11 +427,6 @@ gimp_image_new (gint width, break; } - /* configure the active pointers */ - gimage->active_layer = NULL; - gimage->active_channel = NULL; /* no default active channel */ - gimage->floating_sel = NULL; - /* set all color channels visible and active */ for (i = 0; i < MAX_CHANNELS; i++) { @@ -411,12 +438,6 @@ gimp_image_new (gint width, gimage->selection_mask = channel_new_mask (gimage, gimage->width, gimage->height); - /* set the qmask properties */ - gimage->qmask_state = FALSE; - gimage->qmask_opacity = 50; - gimage->qmask_color[0] = 255; - gimage->qmask_color[1] = 0; - gimage->qmask_color[2] = 0; return gimage; } @@ -1524,20 +1545,27 @@ project_channel (GimpImage *gimage, PixelRegion *src, PixelRegion *src2) { - gint type; + guchar col[3]; + guchar opacity; + gint type; + + gimp_rgba_get_uchar (&channel->color, + &col[0], &col[1], &col[2], &opacity); if (! gimage->construct_flag) { type = (channel->show_masked) ? INITIAL_CHANNEL_MASK : INITIAL_CHANNEL_SELECTION; - initial_region (src2, src, NULL, channel->col, channel->opacity, + + initial_region (src2, src, NULL, col, opacity, NORMAL_MODE, NULL, type); } else { type = (channel->show_masked) ? COMBINE_INTEN_A_CHANNEL_MASK : COMBINE_INTEN_A_CHANNEL_SELECTION; - combine_regions (src, src2, src, NULL, channel->col, channel->opacity, + + combine_regions (src, src2, src, NULL, col, opacity, NORMAL_MODE, NULL, type); } } diff --git a/app/core/gimpprojection-construct.h b/app/core/gimpprojection-construct.h index d478c732db..08d850d8a0 100644 --- a/app/core/gimpprojection-construct.h +++ b/app/core/gimpprojection-construct.h @@ -100,8 +100,7 @@ struct _GimpImage /* "by color" selection dialog */ gboolean qmask_state; /* TRUE if qmask is on */ - gdouble qmask_opacity; /* opacity of the qmask channel */ - guchar qmask_color[3]; /* rgb triplet of the color */ + GimpRGB qmask_color; /* rgba triplet of the color */ /* Undo apparatus */ GSList *undo_stack; /* stack for undo operations */ diff --git a/app/display/gimpdisplayshell-qmask.c b/app/display/gimpdisplayshell-qmask.c index 81f5d5d534..cbc81a0e26 100644 --- a/app/display/gimpdisplayshell-qmask.c +++ b/app/display/gimpdisplayshell-qmask.c @@ -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); + + options->color_panel->color.a = options->color.a; 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); - - 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 (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); } - - - - - diff --git a/app/gimpchannel.c b/app/gimpchannel.c index 6b59f5add9..477ab9054b 100644 --- a/app/gimpchannel.c +++ b/app/gimpchannel.c @@ -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; - channel = gtk_type_new (gimp_channel_get_type ()); + g_return_val_if_fail (color != NULL, NULL); + + 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); diff --git a/app/gimpchannel.h b/app/gimpchannel.h index 5a7bcf653e..e7ccc22532 100644 --- a/app/gimpchannel.h +++ b/app/gimpchannel.h @@ -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__ */ diff --git a/app/gimpdrawable-offset.c b/app/gimpdrawable-offset.c index 232a1eac1c..bb503f7640 100644 --- a/app/gimpdrawable-offset.c +++ b/app/gimpdrawable-offset.c @@ -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: - new_guide = gimp_image_add_vguide(new_gimage); + new_guide = gimp_image_add_vguide (new_gimage); new_guide->position = guide->position; break; default: - g_error("Unknown guide orientation.\n"); + g_error ("Unknown guide orientation.\n"); } } + /* Copy the qmask info */ new_gimage->qmask_state = gimage->qmask_state; - for (count=0;count<3;count++) - new_gimage->qmask_color[count] = gimage->qmask_color[count]; - new_gimage->qmask_opacity = gimage->qmask_opacity; + new_gimage->qmask_color = gimage->qmask_color; /* Copy parasites */ parasites = gimage->parasites; @@ -726,9 +725,9 @@ duplicate (GimpImage *gimage) paths = gimp_image_get_paths (gimage); if (paths) { - GSList *plist = NULL; - GSList *new_plist = NULL; - Path *path; + GSList *plist = NULL; + GSList *new_plist = NULL; + Path *path; PathList *new_paths; for (plist = paths->bz_paths; plist; plist = plist->next) diff --git a/app/gimpimage-duplicate.c b/app/gimpimage-duplicate.c index 232a1eac1c..bb503f7640 100644 --- a/app/gimpimage-duplicate.c +++ b/app/gimpimage-duplicate.c @@ -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: - new_guide = gimp_image_add_vguide(new_gimage); + new_guide = gimp_image_add_vguide (new_gimage); new_guide->position = guide->position; break; default: - g_error("Unknown guide orientation.\n"); + g_error ("Unknown guide orientation.\n"); } } + /* Copy the qmask info */ new_gimage->qmask_state = gimage->qmask_state; - for (count=0;count<3;count++) - new_gimage->qmask_color[count] = gimage->qmask_color[count]; - new_gimage->qmask_opacity = gimage->qmask_opacity; + new_gimage->qmask_color = gimage->qmask_color; /* Copy parasites */ parasites = gimage->parasites; @@ -726,9 +725,9 @@ duplicate (GimpImage *gimage) paths = gimp_image_get_paths (gimage); if (paths) { - GSList *plist = NULL; - GSList *new_plist = NULL; - Path *path; + GSList *plist = NULL; + GSList *new_plist = NULL; + Path *path; PathList *new_paths; for (plist = paths->bz_paths; plist; plist = plist->next) diff --git a/app/gimpimage.c b/app/gimpimage.c index 532e1287d3..5cce116eeb 100644 --- a/app/gimpimage.c +++ b/app/gimpimage.c @@ -259,36 +259,67 @@ gimp_image_class_init (GimpImageClass *klass) static void gimp_image_init (GimpImage *gimage) { - gimage->num_cols = 0; + gimage->save_proc = NULL; + + gimage->width = 0; + gimage->height = 0; + gimage->xresolution = default_xresolution; + gimage->yresolution = default_yresolution; + gimage->unit = default_units; + gimage->base_type = RGB; + gimage->cmap = NULL; - gimage->disp_count = 0; - gimage->instance_count = 0; - gimage->shadow = NULL; + gimage->num_cols = 0; + gimage->dirty = 1; gimage->undo_on = TRUE; - gimage->construct_flag = -1; + + gimage->instance_count = 0; + gimage->disp_count = 0; + gimage->tattoo_state = 0; + + gimage->shadow = NULL; + + gimage->construct_flag = -1; + gimage->proj_type = RGBA_GIMAGE; gimage->projection = NULL; + gimage->guides = NULL; + gimage->layers = NULL; gimage->channels = NULL; gimage->layer_stack = NULL; + + gimage->active_layer = NULL; + gimage->active_channel = NULL; + gimage->floating_sel = NULL; + gimage->selection_mask = NULL; + + gimage->parasites = parasite_list_new (); + + gimage->paths = NULL; + + gimage->by_color_select = FALSE; + + gimage->qmask_state = FALSE; + gimage->qmask_color.r = 1.0; + gimage->qmask_color.g = 0.0; + gimage->qmask_color.b = 0.0; + gimage->qmask_color.a = 0.5; + gimage->undo_stack = NULL; gimage->redo_stack = NULL; gimage->undo_bytes = 0; gimage->undo_levels = 0; gimage->group_count = 0; gimage->pushing_undo_group = UNDO_NULL; + gimage->undo_history = NULL; + + gimage->comp_preview = NULL; gimage->comp_preview_valid[0] = FALSE; gimage->comp_preview_valid[1] = FALSE; gimage->comp_preview_valid[2] = FALSE; - gimage->comp_preview = NULL; - gimage->parasites = parasite_list_new (); - gimage->xresolution = default_xresolution; - gimage->yresolution = default_yresolution; - gimage->unit = default_units; - gimage->save_proc = NULL; - gimage->paths = NULL; } GtkType @@ -342,7 +373,8 @@ gimp_image_allocate_projection (GimpImage *gimage) } /* allocate the new projection */ - gimage->projection = tile_manager_new (gimage->width, gimage->height, gimage->proj_bytes); + gimage->projection = tile_manager_new (gimage->width, gimage->height, + gimage->proj_bytes); tile_manager_set_user_data (gimage->projection, (void *) gimage); tile_manager_set_validate_proc (gimage->projection, gimp_image_validate); } @@ -395,11 +427,6 @@ gimp_image_new (gint width, break; } - /* configure the active pointers */ - gimage->active_layer = NULL; - gimage->active_channel = NULL; /* no default active channel */ - gimage->floating_sel = NULL; - /* set all color channels visible and active */ for (i = 0; i < MAX_CHANNELS; i++) { @@ -411,12 +438,6 @@ gimp_image_new (gint width, gimage->selection_mask = channel_new_mask (gimage, gimage->width, gimage->height); - /* set the qmask properties */ - gimage->qmask_state = FALSE; - gimage->qmask_opacity = 50; - gimage->qmask_color[0] = 255; - gimage->qmask_color[1] = 0; - gimage->qmask_color[2] = 0; return gimage; } @@ -1524,20 +1545,27 @@ project_channel (GimpImage *gimage, PixelRegion *src, PixelRegion *src2) { - gint type; + guchar col[3]; + guchar opacity; + gint type; + + gimp_rgba_get_uchar (&channel->color, + &col[0], &col[1], &col[2], &opacity); if (! gimage->construct_flag) { type = (channel->show_masked) ? INITIAL_CHANNEL_MASK : INITIAL_CHANNEL_SELECTION; - initial_region (src2, src, NULL, channel->col, channel->opacity, + + initial_region (src2, src, NULL, col, opacity, NORMAL_MODE, NULL, type); } else { type = (channel->show_masked) ? COMBINE_INTEN_A_CHANNEL_MASK : COMBINE_INTEN_A_CHANNEL_SELECTION; - combine_regions (src, src2, src, NULL, channel->col, channel->opacity, + + combine_regions (src, src2, src, NULL, col, opacity, NORMAL_MODE, NULL, type); } } diff --git a/app/gimpimage.h b/app/gimpimage.h index d478c732db..08d850d8a0 100644 --- a/app/gimpimage.h +++ b/app/gimpimage.h @@ -100,8 +100,7 @@ struct _GimpImage /* "by color" selection dialog */ gboolean qmask_state; /* TRUE if qmask is on */ - gdouble qmask_opacity; /* opacity of the qmask channel */ - guchar qmask_color[3]; /* rgb triplet of the color */ + GimpRGB qmask_color; /* rgba triplet of the color */ /* Undo apparatus */ GSList *undo_stack; /* stack for undo operations */ diff --git a/app/gimplayer.c b/app/gimplayer.c index 046c3959ab..5359490d2e 100644 --- a/app/gimplayer.c +++ b/app/gimplayer.c @@ -500,7 +500,7 @@ layer_create_mask (Layer *layer, PixelRegion layerPR; LayerMask *mask; gchar *mask_name; - guchar black[3] = {0, 0, 0}; + GimpRGB black = { 0.0, 0.0, 0.0, 1.0 }; guchar white_mask = OPAQUE_OPACITY; guchar black_mask = TRANSPARENT_OPACITY; @@ -511,7 +511,7 @@ layer_create_mask (Layer *layer, mask = layer_mask_new (GIMP_DRAWABLE (layer)->gimage, GIMP_DRAWABLE (layer)->width, GIMP_DRAWABLE (layer)->height, - mask_name, OPAQUE_OPACITY, black); + mask_name, &black); GIMP_DRAWABLE (mask)->offset_x = GIMP_DRAWABLE (layer)->offset_x; GIMP_DRAWABLE (mask)->offset_y = GIMP_DRAWABLE (layer)->offset_y; @@ -1708,15 +1708,13 @@ gimp_layer_mask_destroy (GtkObject *object) } LayerMask * -layer_mask_new (GimpImage *gimage, - gint width, - gint height, - gchar *name, - gint opacity, - guchar *col) +layer_mask_new (GimpImage *gimage, + gint width, + gint height, + const gchar *name, + const GimpRGB *color) { LayerMask *layer_mask; - gint i; layer_mask = gtk_type_new (GIMP_TYPE_LAYER_MASK); @@ -1724,10 +1722,8 @@ layer_mask_new (GimpImage *gimage, gimage, width, height, GRAY_GIMAGE, name); /* set the layer_mask color and opacity */ - for (i = 0; i < 3; i++) - GIMP_CHANNEL (layer_mask)->col[i] = col[i]; + GIMP_CHANNEL (layer_mask)->color = *color; - GIMP_CHANNEL (layer_mask)->opacity = opacity; GIMP_CHANNEL (layer_mask)->show_masked = TRUE; /* selection mask variables */ @@ -1738,7 +1734,8 @@ layer_mask_new (GimpImage *gimage, GIMP_CHANNEL (layer_mask)->num_segs_out = 0; GIMP_CHANNEL (layer_mask)->bounds_known = TRUE; GIMP_CHANNEL (layer_mask)->boundary_known = TRUE; - GIMP_CHANNEL (layer_mask)->x1 = GIMP_CHANNEL (layer_mask)->y1 = 0; + GIMP_CHANNEL (layer_mask)->x1 = 0; + GIMP_CHANNEL (layer_mask)->y1 = 0; GIMP_CHANNEL (layer_mask)->x2 = width; GIMP_CHANNEL (layer_mask)->y2 = height; @@ -1758,12 +1755,11 @@ layer_mask_copy (LayerMask *layer_mask) gimp_object_get_name (GIMP_OBJECT (layer_mask))); /* allocate a new layer_mask object */ - new_layer_mask = layer_mask_new (GIMP_DRAWABLE(layer_mask)->gimage, - GIMP_DRAWABLE(layer_mask)->width, - GIMP_DRAWABLE(layer_mask)->height, - layer_mask_name, - GIMP_CHANNEL(layer_mask)->opacity, - GIMP_CHANNEL(layer_mask)->col); + new_layer_mask = layer_mask_new (GIMP_DRAWABLE (layer_mask)->gimage, + GIMP_DRAWABLE (layer_mask)->width, + GIMP_DRAWABLE (layer_mask)->height, + layer_mask_name, + &GIMP_CHANNEL (layer_mask)->color); GIMP_DRAWABLE(new_layer_mask)->visible = GIMP_DRAWABLE(layer_mask)->visible; GIMP_DRAWABLE(new_layer_mask)->offset_x = diff --git a/app/gimplayer.h b/app/gimplayer.h index 2165c1b3a6..b8085bac07 100644 --- a/app/gimplayer.h +++ b/app/gimplayer.h @@ -170,9 +170,8 @@ GtkType gimp_layer_mask_get_type (void); LayerMask * layer_mask_new (GimpImage *gimage, gint width, gint height, - gchar *name, - gint opacity, - guchar *col); + const gchar *name, + const GimpRGB *color); LayerMask * layer_mask_copy (LayerMask *layer_mask); void layer_mask_delete (LayerMask *layer_mask); LayerMask * layer_mask_ref (LayerMask *layer_mask); diff --git a/app/gui/channels-dialog.c b/app/gui/channels-dialog.c index 9a361b4cba..2fb6582f82 100644 --- a/app/gui/channels-dialog.c +++ b/app/gui/channels-dialog.c @@ -202,6 +202,9 @@ static void channel_widget_exclusive_visible (ChannelWidget *cw); static void channel_widget_channel_flush (GtkWidget *widget, gpointer data); +static void channels_dialog_opacity_update (GtkAdjustment *adjustment, + gpointer data); + /* assorted query dialogs */ static void channels_dialog_new_channel_query (GimpImage *gimage); static void channels_dialog_edit_channel_query (ChannelWidget *cw); @@ -1210,8 +1213,7 @@ channels_dialog_drag_new_channel_callback (GtkWidget *widget, channel = channel_new (gimage, width, height, _("Empty Channel Copy"), - src->channel->opacity, - src->channel->col); + &src->channel->color); if (channel) { drawable_fill (GIMP_DRAWABLE (channel), TRANSPARENT_FILL); @@ -1757,20 +1759,13 @@ channel_widget_drop_color (GtkWidget *widget, { ChannelWidget *channel_widget; Channel *channel; - guchar r, g, b, a; channel_widget = (ChannelWidget *) data; channel = channel_widget->channel; - gimp_rgba_get_uchar (color, &r, &g, &b, &a); - - if (r != channel->col[0] || - g != channel->col[1] || - b != channel->col[2]) + if (gimp_rgba_distance (color, &channel->color) > 0.0001) { - channel->col[0] = r; - channel->col[1] = g; - channel->col[2] = b; + channel->color = *color; drawable_update (GIMP_DRAWABLE (channel), 0, 0, GIMP_DRAWABLE (channel)->width, @@ -2464,6 +2459,17 @@ channel_widget_channel_flush (GtkWidget *widget, gtk_widget_queue_draw (channel_widget->channel_preview); } +static void +channels_dialog_opacity_update (GtkAdjustment *adjustment, + gpointer data) +{ + GimpRGB *color; + + color = (GimpRGB *) data; + + color->a = adjustment->value / 100.0; +} + /**********************************/ /* The new channel query dialog */ /**********************************/ @@ -2476,12 +2482,12 @@ struct _NewChannelOptions GtkWidget *name_entry; ColorPanel *color_panel; - GimpImage *gimage; - gdouble opacity; + GimpImage *gimage; + GimpRGB color; }; static gchar *channel_name = NULL; -static GimpRGB channel_color = { 0.0, 0.0, 0.0, 1.0 }; +static GimpRGB channel_color = { 0.0, 0.0, 0.0, 0.5 }; static void @@ -2500,15 +2506,12 @@ new_channel_query_ok_callback (GtkWidget *widget, if ((gimage = options->gimage)) { - guchar rgba[4]; - - gimp_rgba_get_uchar (&options->color_panel->color, - &rgba[0], &rgba[1], &rgba[2], &rgba[3]); + options->color_panel->color.a = options->color.a; new_channel = channel_new (gimage, gimage->width, gimage->height, channel_name, - (gint) (255 * options->opacity) / 100, - rgba); + &options->color_panel->color); + drawable_fill (GIMP_DRAWABLE (new_channel), TRANSPARENT_FILL); channel_color = options->color_panel->color; @@ -2524,17 +2527,17 @@ static void channels_dialog_new_channel_query (GimpImage* gimage) { NewChannelOptions *options; - GtkWidget *hbox; - GtkWidget *vbox; - GtkWidget *table; - GtkWidget *label; - GtkWidget *opacity_scale; - GtkObject *opacity_scale_data; + GtkWidget *hbox; + GtkWidget *vbox; + GtkWidget *table; + GtkWidget *label; + GtkWidget *opacity_scale; + GtkObject *opacity_scale_data; /* the new options structure */ options = g_new (NewChannelOptions, 1); options->gimage = gimage; - options->opacity = 50.0; + options->color = channel_color; options->color_panel = color_panel_new (&channel_color, FALSE, 48, 64); @@ -2596,14 +2599,14 @@ channels_dialog_new_channel_query (GimpImage* gimage) 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_range_set_update_policy (GTK_RANGE (opacity_scale), GTK_UPDATE_DELAYED); gtk_signal_connect (GTK_OBJECT (opacity_scale_data), "value_changed", - GTK_SIGNAL_FUNC (gimp_double_adjustment_update), - &options->opacity); + GTK_SIGNAL_FUNC (channels_dialog_opacity_update), + &options->color); gtk_widget_show (opacity_scale); /* The color panel */ @@ -2625,13 +2628,13 @@ typedef struct _EditChannelOptions EditChannelOptions; struct _EditChannelOptions { - GtkWidget *query_box; - GtkWidget *name_entry; + GtkWidget *query_box; + GtkWidget *name_entry; + ColorPanel *color_panel; ChannelWidget *channel_widget; GimpImage *gimage; - ColorPanel *color_panel; - gdouble opacity; + GimpRGB color; }; static void @@ -2640,13 +2643,9 @@ edit_channel_query_ok_callback (GtkWidget *widget, { EditChannelOptions *options; Channel *channel; - GimpRGB color; - gint opacity; - gint update = FALSE; options = (EditChannelOptions *) data; channel = options->channel_widget->channel; - opacity = (gint) (255 * options->opacity) / 100; if (options->gimage) { @@ -2656,28 +2655,13 @@ edit_channel_query_ok_callback (GtkWidget *widget, gtk_label_set_text (GTK_LABEL (options->channel_widget->label), gimp_object_get_name (GIMP_OBJECT (channel))); - if (channel->opacity != opacity) - { - channel->opacity = opacity; - update = TRUE; - } + options->color_panel->color.a = options->color.a; - gimp_rgb_set_uchar (&color, - channel->col[0], - channel->col[1], - channel->col[2]); - - if (gimp_rgb_distance (&options->color_panel->color, &color) > 0.0001) + if (gimp_rgba_distance (&options->color_panel->color, + &channel->color) > 0.0001) { - gimp_rgb_get_uchar (&options->color_panel->color, - &channel->col[0], - &channel->col[1], - &channel->col[2]); - update = TRUE; - } + channel->color = options->color_panel->color; - if (update) - { drawable_update (GIMP_DRAWABLE (channel), 0, 0, GIMP_DRAWABLE (channel)->width, GIMP_DRAWABLE (channel)->height); @@ -2692,23 +2676,20 @@ static void channels_dialog_edit_channel_query (ChannelWidget *channel_widget) { EditChannelOptions *options; - GtkWidget *hbox; - GtkWidget *vbox; - GtkWidget *table; - GtkWidget *label; - GtkWidget *opacity_scale; - GtkObject *opacity_scale_data; + GtkWidget *hbox; + GtkWidget *vbox; + GtkWidget *table; + GtkWidget *label; + GtkWidget *opacity_scale; + GtkObject *opacity_scale_data; /* the new options structure */ options = g_new (EditChannelOptions, 1); options->channel_widget = channel_widget; options->gimage = channel_widget->gimage; - options->opacity = (gdouble) channel_widget->channel->opacity / 2.55; + options->color = channel_widget->channel->color; - gimp_rgb_set_uchar (&channel_color, - channel_widget->channel->col[0], - channel_widget->channel->col[1], - channel_widget->channel->col[2]); + channel_color = options->color; options->color_panel = color_panel_new (&channel_color, FALSE, @@ -2772,13 +2753,13 @@ channels_dialog_edit_channel_query (ChannelWidget *channel_widget) 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", - GTK_SIGNAL_FUNC (gimp_double_adjustment_update), - &options->opacity); + GTK_SIGNAL_FUNC (channels_dialog_opacity_update), + &options->color); gtk_widget_show (opacity_scale); /* The color panel */ diff --git a/app/gui/qmask-commands.c b/app/gui/qmask-commands.c index 81f5d5d534..cbc81a0e26 100644 --- a/app/gui/qmask-commands.c +++ b/app/gui/qmask-commands.c @@ -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); + + options->color_panel->color.a = options->color.a; 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); - - 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 (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); } - - - - - diff --git a/app/layer.c b/app/layer.c index 046c3959ab..5359490d2e 100644 --- a/app/layer.c +++ b/app/layer.c @@ -500,7 +500,7 @@ layer_create_mask (Layer *layer, PixelRegion layerPR; LayerMask *mask; gchar *mask_name; - guchar black[3] = {0, 0, 0}; + GimpRGB black = { 0.0, 0.0, 0.0, 1.0 }; guchar white_mask = OPAQUE_OPACITY; guchar black_mask = TRANSPARENT_OPACITY; @@ -511,7 +511,7 @@ layer_create_mask (Layer *layer, mask = layer_mask_new (GIMP_DRAWABLE (layer)->gimage, GIMP_DRAWABLE (layer)->width, GIMP_DRAWABLE (layer)->height, - mask_name, OPAQUE_OPACITY, black); + mask_name, &black); GIMP_DRAWABLE (mask)->offset_x = GIMP_DRAWABLE (layer)->offset_x; GIMP_DRAWABLE (mask)->offset_y = GIMP_DRAWABLE (layer)->offset_y; @@ -1708,15 +1708,13 @@ gimp_layer_mask_destroy (GtkObject *object) } LayerMask * -layer_mask_new (GimpImage *gimage, - gint width, - gint height, - gchar *name, - gint opacity, - guchar *col) +layer_mask_new (GimpImage *gimage, + gint width, + gint height, + const gchar *name, + const GimpRGB *color) { LayerMask *layer_mask; - gint i; layer_mask = gtk_type_new (GIMP_TYPE_LAYER_MASK); @@ -1724,10 +1722,8 @@ layer_mask_new (GimpImage *gimage, gimage, width, height, GRAY_GIMAGE, name); /* set the layer_mask color and opacity */ - for (i = 0; i < 3; i++) - GIMP_CHANNEL (layer_mask)->col[i] = col[i]; + GIMP_CHANNEL (layer_mask)->color = *color; - GIMP_CHANNEL (layer_mask)->opacity = opacity; GIMP_CHANNEL (layer_mask)->show_masked = TRUE; /* selection mask variables */ @@ -1738,7 +1734,8 @@ layer_mask_new (GimpImage *gimage, GIMP_CHANNEL (layer_mask)->num_segs_out = 0; GIMP_CHANNEL (layer_mask)->bounds_known = TRUE; GIMP_CHANNEL (layer_mask)->boundary_known = TRUE; - GIMP_CHANNEL (layer_mask)->x1 = GIMP_CHANNEL (layer_mask)->y1 = 0; + GIMP_CHANNEL (layer_mask)->x1 = 0; + GIMP_CHANNEL (layer_mask)->y1 = 0; GIMP_CHANNEL (layer_mask)->x2 = width; GIMP_CHANNEL (layer_mask)->y2 = height; @@ -1758,12 +1755,11 @@ layer_mask_copy (LayerMask *layer_mask) gimp_object_get_name (GIMP_OBJECT (layer_mask))); /* allocate a new layer_mask object */ - new_layer_mask = layer_mask_new (GIMP_DRAWABLE(layer_mask)->gimage, - GIMP_DRAWABLE(layer_mask)->width, - GIMP_DRAWABLE(layer_mask)->height, - layer_mask_name, - GIMP_CHANNEL(layer_mask)->opacity, - GIMP_CHANNEL(layer_mask)->col); + new_layer_mask = layer_mask_new (GIMP_DRAWABLE (layer_mask)->gimage, + GIMP_DRAWABLE (layer_mask)->width, + GIMP_DRAWABLE (layer_mask)->height, + layer_mask_name, + &GIMP_CHANNEL (layer_mask)->color); GIMP_DRAWABLE(new_layer_mask)->visible = GIMP_DRAWABLE(layer_mask)->visible; GIMP_DRAWABLE(new_layer_mask)->offset_x = diff --git a/app/layer.h b/app/layer.h index 2165c1b3a6..b8085bac07 100644 --- a/app/layer.h +++ b/app/layer.h @@ -170,9 +170,8 @@ GtkType gimp_layer_mask_get_type (void); LayerMask * layer_mask_new (GimpImage *gimage, gint width, gint height, - gchar *name, - gint opacity, - guchar *col); + const gchar *name, + const GimpRGB *color); LayerMask * layer_mask_copy (LayerMask *layer_mask); void layer_mask_delete (LayerMask *layer_mask); LayerMask * layer_mask_ref (LayerMask *layer_mask); diff --git a/app/qmask.c b/app/qmask.c index 81f5d5d534..cbc81a0e26 100644 --- a/app/qmask.c +++ b/app/qmask.c @@ -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); + + options->color_panel->color.a = options->color.a; 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); - - 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 (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); } - - - - - diff --git a/app/xcf.c b/app/xcf.c index aa283fc947..6bba46d2d6 100644 --- a/app/xcf.c +++ b/app/xcf.c @@ -680,10 +680,17 @@ xcf_save_channel_props (XcfInfo *info, if (channel == gimage->selection_mask) xcf_save_prop (info, PROP_SELECTION); - xcf_save_prop (info, PROP_OPACITY, channel->opacity); + xcf_save_prop (info, PROP_OPACITY, (gint) (channel->color.a * 255.999)); xcf_save_prop (info, PROP_VISIBLE, GIMP_DRAWABLE(channel)->visible); xcf_save_prop (info, PROP_SHOW_MASKED, channel->show_masked); - xcf_save_prop (info, PROP_COLOR, channel->col); + + { + guchar col[3]; + + gimp_rgb_get_uchar (&channel->color, &col[0], &col[1], &col[2]); + xcf_save_prop (info, PROP_COLOR, col); + } + xcf_save_prop (info, PROP_TATTOO, GIMP_DRAWABLE(channel)->tattoo); if (parasite_list_length (GIMP_DRAWABLE(channel)->parasites) > 0) xcf_save_prop (info, PROP_PARASITES, GIMP_DRAWABLE(channel)->parasites); @@ -2135,7 +2142,12 @@ xcf_load_channel_props (XcfInfo *info, channel->bounds_known = FALSE; break; case PROP_OPACITY: - info->cp += xcf_read_int32 (info->fp, (guint32*) &channel->opacity, 1); + { + guint32 opacity; + + info->cp += xcf_read_int32 (info->fp, &opacity, 1); + channel->color.a = opacity / 255.0; + } break; case PROP_VISIBLE: info->cp += xcf_read_int32 (info->fp, (guint32*) &GIMP_DRAWABLE(channel)->visible, 1); @@ -2144,7 +2156,14 @@ xcf_load_channel_props (XcfInfo *info, info->cp += xcf_read_int32 (info->fp, (guint32*) &channel->show_masked, 1); break; case PROP_COLOR: - info->cp += xcf_read_int8 (info->fp, (guint8*) channel->col, 3); + { + guchar col[3]; + + info->cp += xcf_read_int8 (info->fp, (guint8*) col, 3); + + gimp_rgb_set_uchar (&channel->color, col[0], col[1], col[2]); + + } break; case PROP_TATTOO: info->cp += xcf_read_int32 (info->fp, &GIMP_DRAWABLE(channel)->tattoo, @@ -2273,7 +2292,7 @@ xcf_load_layer (XcfInfo *info, Layer *floating_sel; floating_sel = info->floating_sel; - floating_sel_attach (floating_sel, GIMP_DRAWABLE(layer)); + floating_sel_attach (floating_sel, GIMP_DRAWABLE (layer)); } return layer; @@ -2288,12 +2307,12 @@ xcf_load_channel (XcfInfo *info, GImage *gimage) { Channel *channel; - guint32 hierarchy_offset; - gint width; - gint height; - gint add_floating_sel; - gchar *name; - guchar color[3] = { 0, 0, 0 }; + guint32 hierarchy_offset; + gint width; + gint height; + gint add_floating_sel; + gchar *name; + GimpRGB color = { 0.0, 0.0, 0.0, 1.0 }; /* check and see if this is the drawable the floating selection * is attached to. if it is then we'll do the attachment at @@ -2307,7 +2326,7 @@ xcf_load_channel (XcfInfo *info, info->cp += xcf_read_string (info->fp, &name, 1); /* create a new channel */ - channel = channel_new (gimage, width, height, name, 255, color); + channel = channel_new (gimage, width, height, name, &color); g_free (name); if (!channel) return NULL; @@ -2345,12 +2364,12 @@ xcf_load_layer_mask (XcfInfo *info, GImage *gimage) { LayerMask *layer_mask; - guint32 hierarchy_offset; - gint width; - gint height; - gint add_floating_sel; - gchar *name; - guchar color[3] = { 0, 0, 0 }; + guint32 hierarchy_offset; + gint width; + gint height; + gint add_floating_sel; + gchar *name; + GimpRGB color = { 0.0, 0.0, 0.0, 1.0 }; /* check and see if this is the drawable the floating selection * is attached to. if it is then we'll do the attachment at @@ -2364,7 +2383,7 @@ xcf_load_layer_mask (XcfInfo *info, info->cp += xcf_read_string (info->fp, &name, 1); /* create a new layer mask */ - layer_mask = layer_mask_new (gimage, width, height, name, 255, color); + layer_mask = layer_mask_new (gimage, width, height, name, &color); g_free (name); if (!layer_mask) return NULL; diff --git a/app/xcf/xcf.c b/app/xcf/xcf.c index aa283fc947..6bba46d2d6 100644 --- a/app/xcf/xcf.c +++ b/app/xcf/xcf.c @@ -680,10 +680,17 @@ xcf_save_channel_props (XcfInfo *info, if (channel == gimage->selection_mask) xcf_save_prop (info, PROP_SELECTION); - xcf_save_prop (info, PROP_OPACITY, channel->opacity); + xcf_save_prop (info, PROP_OPACITY, (gint) (channel->color.a * 255.999)); xcf_save_prop (info, PROP_VISIBLE, GIMP_DRAWABLE(channel)->visible); xcf_save_prop (info, PROP_SHOW_MASKED, channel->show_masked); - xcf_save_prop (info, PROP_COLOR, channel->col); + + { + guchar col[3]; + + gimp_rgb_get_uchar (&channel->color, &col[0], &col[1], &col[2]); + xcf_save_prop (info, PROP_COLOR, col); + } + xcf_save_prop (info, PROP_TATTOO, GIMP_DRAWABLE(channel)->tattoo); if (parasite_list_length (GIMP_DRAWABLE(channel)->parasites) > 0) xcf_save_prop (info, PROP_PARASITES, GIMP_DRAWABLE(channel)->parasites); @@ -2135,7 +2142,12 @@ xcf_load_channel_props (XcfInfo *info, channel->bounds_known = FALSE; break; case PROP_OPACITY: - info->cp += xcf_read_int32 (info->fp, (guint32*) &channel->opacity, 1); + { + guint32 opacity; + + info->cp += xcf_read_int32 (info->fp, &opacity, 1); + channel->color.a = opacity / 255.0; + } break; case PROP_VISIBLE: info->cp += xcf_read_int32 (info->fp, (guint32*) &GIMP_DRAWABLE(channel)->visible, 1); @@ -2144,7 +2156,14 @@ xcf_load_channel_props (XcfInfo *info, info->cp += xcf_read_int32 (info->fp, (guint32*) &channel->show_masked, 1); break; case PROP_COLOR: - info->cp += xcf_read_int8 (info->fp, (guint8*) channel->col, 3); + { + guchar col[3]; + + info->cp += xcf_read_int8 (info->fp, (guint8*) col, 3); + + gimp_rgb_set_uchar (&channel->color, col[0], col[1], col[2]); + + } break; case PROP_TATTOO: info->cp += xcf_read_int32 (info->fp, &GIMP_DRAWABLE(channel)->tattoo, @@ -2273,7 +2292,7 @@ xcf_load_layer (XcfInfo *info, Layer *floating_sel; floating_sel = info->floating_sel; - floating_sel_attach (floating_sel, GIMP_DRAWABLE(layer)); + floating_sel_attach (floating_sel, GIMP_DRAWABLE (layer)); } return layer; @@ -2288,12 +2307,12 @@ xcf_load_channel (XcfInfo *info, GImage *gimage) { Channel *channel; - guint32 hierarchy_offset; - gint width; - gint height; - gint add_floating_sel; - gchar *name; - guchar color[3] = { 0, 0, 0 }; + guint32 hierarchy_offset; + gint width; + gint height; + gint add_floating_sel; + gchar *name; + GimpRGB color = { 0.0, 0.0, 0.0, 1.0 }; /* check and see if this is the drawable the floating selection * is attached to. if it is then we'll do the attachment at @@ -2307,7 +2326,7 @@ xcf_load_channel (XcfInfo *info, info->cp += xcf_read_string (info->fp, &name, 1); /* create a new channel */ - channel = channel_new (gimage, width, height, name, 255, color); + channel = channel_new (gimage, width, height, name, &color); g_free (name); if (!channel) return NULL; @@ -2345,12 +2364,12 @@ xcf_load_layer_mask (XcfInfo *info, GImage *gimage) { LayerMask *layer_mask; - guint32 hierarchy_offset; - gint width; - gint height; - gint add_floating_sel; - gchar *name; - guchar color[3] = { 0, 0, 0 }; + guint32 hierarchy_offset; + gint width; + gint height; + gint add_floating_sel; + gchar *name; + GimpRGB color = { 0.0, 0.0, 0.0, 1.0 }; /* check and see if this is the drawable the floating selection * is attached to. if it is then we'll do the attachment at @@ -2364,7 +2383,7 @@ xcf_load_layer_mask (XcfInfo *info, info->cp += xcf_read_string (info->fp, &name, 1); /* create a new layer mask */ - layer_mask = layer_mask_new (gimage, width, height, name, 255, color); + layer_mask = layer_mask_new (gimage, width, height, name, &color); g_free (name); if (!layer_mask) return NULL; diff --git a/tools/pdbgen/pdb/channel.pdb b/tools/pdbgen/pdb/channel.pdb index 40f3914ed8..d3594199ae 100644 --- a/tools/pdbgen/pdb/channel.pdb +++ b/tools/pdbgen/pdb/channel.pdb @@ -49,11 +49,16 @@ sub channel_get_prop_proc { $invoke{headers} = [ qw("gimpimage.h") ]; - $invoke{code} = "{\n color = g_new (guchar, 3);\n"; - foreach (map { "${_}_PIX" } qw(RED GREEN BLUE)) { - $invoke{code} .= " $prop\[$_] = channel->col[$_];\n"; - } - $invoke{code} .= "}\n"; + $invoke{code} = <<'CODE' +{ + color = g_new (guchar, 3); + + gimp_rgb_get_uchar (&channel->color, + &color[RED_PIX], + &color[GREEN_PIX], + &color[BLUE_PIX]); +} +CODE } } @@ -81,7 +86,25 @@ sub channel_set_prop_proc { if ($type eq 'color') { %invoke = ( - code => "channel_set_color(channel, $prop);" + code => <<'CODE' +{ + 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); +} +CODE + ); + } + + if ($prop eq 'opacity') { + %invoke = ( + code => "channel->color.a = $prop / 100.0;" ); } } @@ -144,7 +167,14 @@ HELP %invoke = ( code => <<'CODE' { - 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; } CODE @@ -208,9 +238,9 @@ CODE &channel_accessors('opacity', '0 <= float <= 100', 'opacity', 0, [ '$outargs[0]->{alias} = - "(channel->opacity * 100.0) / 255.0"', + "channel->color.a * 100.0"', '$invoke{code} =~ - s%(opacity);$%(int) (($1 * 255) / 100);%' ]); + s%(color.a);$%(($1 / 100.0);%' ]); &channel_accessors('color', 'color', 'compositing color', 0);