diff --git a/ChangeLog b/ChangeLog index fae491eb817a4612b716efa7403c4d0c650c950b..dc61750597a279e4de59d5fff419282c4cb061ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-08-07 Michael Natterer + + * app/core/gimplayer.[ch] (gimp_layer_flatten): new function. + + * app/actions/layers-actions.c + * app/actions/layers-commands.[ch] + * app/widgets/gimphelp-ids.h + * menus/image-menu.xml.in + * menus/layers-menu.xml: added "Remove Alpha Channel" action, + action callback, help ID and menu items. Fixes bug #309762. + 2005-08-07 Sven Neumann * app/base/siox.c (siox_foreground_extract): micro optimizations. @@ -12,7 +23,6 @@ * app/tools/gimpforegroundselecttool.c (gimp_foreground_select_tool_draw): show the extents of the working area if the user moves the mouse out of it. Is this useful? - * app/tools/gimpforegroundselectoptions.c: removed colons from labels. diff --git a/app/actions/layers-actions.c b/app/actions/layers-actions.c index bd38961bfc6080d99b0477335f7649d98f9bcd20..c0b57ce88beb1a869aea949d057e9a580785cfe0 100644 --- a/app/actions/layers-actions.c +++ b/app/actions/layers-actions.c @@ -172,7 +172,12 @@ static GimpActionEntry layers_actions[] = { "layers-alpha-add", GIMP_STOCK_TRANSPARENCY, N_("Add Alpha C_hannel"), NULL, NULL, G_CALLBACK (layers_alpha_add_cmd_callback), - GIMP_HELP_LAYER_ALPHA_ADD } + GIMP_HELP_LAYER_ALPHA_ADD }, + + { "layers-alpha-remove", NULL, + N_("_Remove Alpha Channel"), NULL, NULL, + G_CALLBACK (layers_alpha_remove_cmd_callback), + GIMP_HELP_LAYER_ALPHA_REMOVE } }; static GimpToggleActionEntry layers_toggle_actions[] = @@ -464,6 +469,7 @@ layers_actions_update (GimpActionGroup *group, SET_SENSITIVE ("layers-crop", layer && sel); SET_SENSITIVE ("layers-alpha-add", layer && !fs && !alpha); + SET_SENSITIVE ("layers-alpha-remove", layer && !fs && alpha); SET_SENSITIVE ("layers-lock-alpha", layer); SET_ACTIVE ("layers-lock-alpha", lock_alpha); diff --git a/app/actions/layers-commands.c b/app/actions/layers-commands.c index 9806e11e104edcc6a65c6761cacca4f6d18d5350..a403e17396e96b356763a7b1496cfcfd85522eac 100644 --- a/app/actions/layers-commands.c +++ b/app/actions/layers-commands.c @@ -705,6 +705,21 @@ layers_alpha_add_cmd_callback (GtkAction *action, } } +void +layers_alpha_remove_cmd_callback (GtkAction *action, + gpointer data) +{ + GimpImage *gimage; + GimpLayer *layer; + return_if_no_layer (gimage, layer, data); + + if (gimp_drawable_has_alpha (GIMP_DRAWABLE (layer))) + { + gimp_layer_flatten (layer, action_data_get_context (data)); + gimp_image_flush (gimage); + } +} + void layers_alpha_to_selection_cmd_callback (GtkAction *action, gint value, diff --git a/app/actions/layers-commands.h b/app/actions/layers-commands.h index d96febb760fb997beaa96912398cb8dd2b392ca7..db2a45727b0d071a6679323b9a1ab397f23e6f42 100644 --- a/app/actions/layers-commands.h +++ b/app/actions/layers-commands.h @@ -79,6 +79,8 @@ void layers_mask_to_selection_cmd_callback (GtkAction *action, void layers_alpha_add_cmd_callback (GtkAction *action, gpointer data); +void layers_alpha_remove_cmd_callback (GtkAction *action, + gpointer data); void layers_alpha_to_selection_cmd_callback (GtkAction *action, gint value, gpointer data); diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c index c22cab63b8a54473aa161e305d474b32e345c88d..b9f6fb0f76be862e0905782227e7573c32e00b29 100644 --- a/app/core/gimplayer.c +++ b/app/core/gimplayer.c @@ -1651,6 +1651,57 @@ gimp_layer_add_alpha (GimpLayer *layer) tile_manager_unref (new_tiles); } +void +gimp_layer_flatten (GimpLayer *layer, + GimpContext *context) +{ + PixelRegion srcPR, destPR; + TileManager *new_tiles; + GimpImageType new_type; + guchar bg[4]; + + g_return_if_fail (GIMP_IS_LAYER (layer)); + g_return_if_fail (GIMP_IS_CONTEXT (context)); + + if (! gimp_drawable_has_alpha (GIMP_DRAWABLE (layer))) + return; + + new_type = gimp_drawable_type_without_alpha (GIMP_DRAWABLE (layer)); + + gimp_image_get_background (gimp_item_get_image (GIMP_ITEM (layer)), + GIMP_DRAWABLE (layer), + context, bg); + + /* Allocate the new tiles */ + new_tiles = tile_manager_new (GIMP_ITEM (layer)->width, + GIMP_ITEM (layer)->height, + GIMP_IMAGE_TYPE_BYTES (new_type)); + + /* Configure the pixel regions */ + pixel_region_init (&srcPR, GIMP_DRAWABLE (layer)->tiles, + 0, 0, + GIMP_ITEM (layer)->width, + GIMP_ITEM (layer)->height, + FALSE); + pixel_region_init (&destPR, new_tiles, + 0, 0, + GIMP_ITEM (layer)->width, + GIMP_ITEM (layer)->height, + TRUE); + + /* Remove alpha channel */ + flatten_region (&srcPR, &destPR, bg); + + /* Set the new tiles */ + gimp_drawable_set_tiles_full (GIMP_DRAWABLE (layer), + gimp_item_is_attached (GIMP_ITEM (layer)), + _("Remove Alpha Channel"), + new_tiles, new_type, + GIMP_ITEM (layer)->offset_x, + GIMP_ITEM (layer)->offset_y); + tile_manager_unref (new_tiles); +} + void gimp_layer_resize_to_image (GimpLayer *layer, GimpContext *context) diff --git a/app/core/gimplayer.h b/app/core/gimplayer.h index 96592c18b4e9ba2210e272b1f660ef0f2ebb3421..e71c2e8d066dccece3c9e48ea9c360279c2f7600 100644 --- a/app/core/gimplayer.h +++ b/app/core/gimplayer.h @@ -107,6 +107,8 @@ void gimp_layer_apply_mask (GimpLayer *layer, GimpMaskApplyMode mode, gboolean push_undo); void gimp_layer_add_alpha (GimpLayer *layer); +void gimp_layer_flatten (GimpLayer *layer, + GimpContext *context); void gimp_layer_resize_to_image (GimpLayer *layer, GimpContext *context); diff --git a/app/widgets/gimphelp-ids.h b/app/widgets/gimphelp-ids.h index 0157c5a9ea7dd034df91c0a5c99ff5ec860b240d..e497d32747220d6abcb822dc8441313fc3cc5a95 100644 --- a/app/widgets/gimphelp-ids.h +++ b/app/widgets/gimphelp-ids.h @@ -164,6 +164,7 @@ #define GIMP_HELP_LAYER_MASK_SELECTION_SUBTRACT "gimp-layer-mask-selection-subtract" #define GIMP_HELP_LAYER_MASK_SELECTION_INTERSECT "gimp-layer-mask-selection-intersect" #define GIMP_HELP_LAYER_ALPHA_ADD "gimp-layer-alpha-add" +#define GIMP_HELP_LAYER_ALPHA_REMOVE "gimp-layer-alpha-remove" #define GIMP_HELP_LAYER_ALPHA_SELECTION_REPLACE "gimp-layer-alpha-selection-replace" #define GIMP_HELP_LAYER_ALPHA_SELECTION_ADD "gimp-layer-alpha-selection-add" #define GIMP_HELP_LAYER_ALPHA_SELECTION_SUBTRACT "gimp-layer-alpha-selection-subtract" diff --git a/menus/image-menu.xml.in b/menus/image-menu.xml.in index 6745ee94c24d46424fd9c2499453742c3b64b757..dfdc3991253308ed0263107dd9455f3cbf75d038 100644 --- a/menus/image-menu.xml.in +++ b/menus/image-menu.xml.in @@ -386,6 +386,7 @@ + diff --git a/menus/layers-menu.xml b/menus/layers-menu.xml index 8fd2b43d91cac8d67a574bef11fb5c9fd67dc5a1..c5f8e486e7119a0b52140a18c5f81ea9524361e1 100644 --- a/menus/layers-menu.xml +++ b/menus/layers-menu.xml @@ -33,6 +33,7 @@ +