2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-07-05 23:34:26 +08:00
|
|
|
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
|
2003-10-11 22:30:18 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-07-05 23:34:26 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-07-05 23:34:26 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2001-07-05 23:34:26 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2015-06-17 15:55:08 +08:00
|
|
|
#include <cairo.h>
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2001-07-05 23:34:26 +08:00
|
|
|
|
2010-02-08 21:47:45 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2015-06-17 15:55:08 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2001-07-05 23:34:26 +08:00
|
|
|
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "core-types.h"
|
2002-11-19 04:50:31 +08:00
|
|
|
|
2007-07-16 21:49:17 +08:00
|
|
|
#include "config/gimpcoreconfig.h"
|
|
|
|
|
2012-04-22 05:55:40 +08:00
|
|
|
#include "gegl/gimp-babl.h"
|
2020-05-06 21:46:51 +08:00
|
|
|
#include "gegl/gimp-gegl-utils.h"
|
2012-04-07 08:43:18 +08:00
|
|
|
|
2001-07-05 23:34:26 +08:00
|
|
|
#include "gimp.h"
|
2010-02-08 22:19:03 +08:00
|
|
|
#include "gimpbuffer.h"
|
2010-02-08 21:47:45 +08:00
|
|
|
#include "gimpchannel.h"
|
2010-06-06 04:42:00 +08:00
|
|
|
#include "gimpcontext.h"
|
2016-03-08 08:38:05 +08:00
|
|
|
#include "gimpdrawable-fill.h"
|
app: rework and fix the logic for copy-pasting multiple drawables.
There were a lot of incertainty of what should happen when we copy layers being
descendant of each other (i.e. when you select a group layer and some of its
children), then when you paste such data. So we sat down with Aryeom and tried
to come up with some consistent behavior which is somewhat expectable, but also
which would allow the most use-case.
Otherwise it was making very weird result when pasting the data, duplicating
some layers and whatnot, which was obviously a buggy behavior and never the
expected result.
We decided that if you select one leaf item, then even if you also selected a
parent item, it would be as though the parent was not selected. This is very
often what you expect anyway when you select a whole bunch of layers and would
work well if, say, you shift-click over many layers in sub-groups. Then you
wouldn't have to manually ctrl-click to unselect every group.
Then what if you were instead expecting to copy many groups? Then you could
shift-click the group arrow, closing all same-level groups. Once they are all
closed, you can shift-click the groups to only select group layers, not their
contents.
This way, both use cases are still quite doable easily with this default choice.
2022-11-13 01:28:58 +08:00
|
|
|
#include "gimpgrouplayer.h"
|
2001-07-05 23:34:26 +08:00
|
|
|
#include "gimpimage.h"
|
2015-08-03 04:18:43 +08:00
|
|
|
#include "gimpimage-color-profile.h"
|
2010-02-08 21:47:45 +08:00
|
|
|
#include "gimpimage-colormap.h"
|
2001-07-05 23:34:26 +08:00
|
|
|
#include "gimpimage-new.h"
|
2010-02-08 21:47:45 +08:00
|
|
|
#include "gimpimage-undo.h"
|
|
|
|
#include "gimplayer.h"
|
2015-06-17 19:21:01 +08:00
|
|
|
#include "gimplayer-new.h"
|
2020-05-06 21:46:51 +08:00
|
|
|
#include "gimplist.h"
|
2003-04-04 01:50:56 +08:00
|
|
|
#include "gimptemplate.h"
|
2001-07-05 23:34:26 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-07-05 23:34:26 +08:00
|
|
|
|
|
|
|
|
2003-04-04 01:50:56 +08:00
|
|
|
GimpTemplate *
|
2003-04-04 23:11:30 +08:00
|
|
|
gimp_image_new_get_last_template (Gimp *gimp,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image)
|
2001-07-05 23:34:26 +08:00
|
|
|
{
|
2003-04-04 01:50:56 +08:00
|
|
|
GimpTemplate *template;
|
2001-07-05 23:34:26 +08:00
|
|
|
|
2003-04-04 01:50:56 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_val_if_fail (image == NULL || GIMP_IS_IMAGE (image), NULL);
|
2001-07-05 23:34:26 +08:00
|
|
|
|
2003-04-04 01:50:56 +08:00
|
|
|
template = gimp_template_new ("image new values");
|
2001-07-05 23:34:26 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (image)
|
2007-07-16 21:49:17 +08:00
|
|
|
{
|
|
|
|
gimp_config_sync (G_OBJECT (gimp->config->default_image),
|
|
|
|
G_OBJECT (template), 0);
|
|
|
|
gimp_template_set_from_image (template, image);
|
|
|
|
}
|
2001-07-05 23:34:26 +08:00
|
|
|
else
|
2007-07-16 21:49:17 +08:00
|
|
|
{
|
|
|
|
gimp_config_sync (G_OBJECT (gimp->image_new_last_template),
|
|
|
|
G_OBJECT (template), 0);
|
|
|
|
}
|
2001-07-05 23:34:26 +08:00
|
|
|
|
2003-04-04 01:50:56 +08:00
|
|
|
return template;
|
2001-07-05 23:34:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-04-04 01:50:56 +08:00
|
|
|
gimp_image_new_set_last_template (Gimp *gimp,
|
|
|
|
GimpTemplate *template)
|
2001-07-05 23:34:26 +08:00
|
|
|
{
|
2003-04-04 01:50:56 +08:00
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
g_return_if_fail (GIMP_IS_TEMPLATE (template));
|
2001-07-05 23:34:26 +08:00
|
|
|
|
2005-04-07 18:05:54 +08:00
|
|
|
gimp_config_sync (G_OBJECT (template),
|
|
|
|
G_OBJECT (gimp->image_new_last_template), 0);
|
2001-07-05 23:34:26 +08:00
|
|
|
}
|
2010-02-08 21:47:45 +08:00
|
|
|
|
2010-06-06 04:42:00 +08:00
|
|
|
GimpImage *
|
|
|
|
gimp_image_new_from_template (Gimp *gimp,
|
|
|
|
GimpTemplate *template,
|
|
|
|
GimpContext *context)
|
|
|
|
{
|
2022-08-06 12:42:46 +08:00
|
|
|
GimpImage *image;
|
|
|
|
GimpLayer *layer;
|
|
|
|
GimpColorProfile *profile;
|
|
|
|
GimpColorRenderingIntent intent;
|
|
|
|
gboolean bpc;
|
|
|
|
gint width, height;
|
|
|
|
gboolean has_alpha;
|
|
|
|
const gchar *comment;
|
2010-06-06 04:42:00 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_TEMPLATE (template), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
|
|
|
|
|
|
|
image = gimp_create_image (gimp,
|
2011-03-02 17:16:43 +08:00
|
|
|
gimp_template_get_width (template),
|
|
|
|
gimp_template_get_height (template),
|
2012-04-22 23:35:47 +08:00
|
|
|
gimp_template_get_base_type (template),
|
2012-04-22 23:42:39 +08:00
|
|
|
gimp_template_get_precision (template),
|
2010-06-06 04:42:00 +08:00
|
|
|
FALSE);
|
2023-07-12 09:59:38 +08:00
|
|
|
gimp_context_set_image (context, image);
|
2010-06-06 04:42:00 +08:00
|
|
|
|
|
|
|
gimp_image_undo_disable (image);
|
|
|
|
|
2011-03-02 17:16:43 +08:00
|
|
|
comment = gimp_template_get_comment (template);
|
|
|
|
|
|
|
|
if (comment)
|
2010-06-06 04:42:00 +08:00
|
|
|
{
|
|
|
|
GimpParasite *parasite;
|
|
|
|
|
|
|
|
parasite = gimp_parasite_new ("gimp-comment",
|
|
|
|
GIMP_PARASITE_PERSISTENT,
|
2011-03-02 17:16:43 +08:00
|
|
|
strlen (comment) + 1,
|
|
|
|
comment);
|
2019-05-30 22:44:23 +08:00
|
|
|
gimp_image_parasite_attach (image, parasite, FALSE);
|
2010-06-06 04:42:00 +08:00
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_image_set_resolution (image,
|
2011-03-02 17:16:43 +08:00
|
|
|
gimp_template_get_resolution_x (template),
|
|
|
|
gimp_template_get_resolution_y (template));
|
|
|
|
gimp_image_set_unit (image, gimp_template_get_resolution_unit (template));
|
2010-06-06 04:42:00 +08:00
|
|
|
|
2016-05-09 05:20:26 +08:00
|
|
|
profile = gimp_template_get_color_profile (template);
|
|
|
|
gimp_image_set_color_profile (image, profile, NULL);
|
|
|
|
if (profile)
|
|
|
|
g_object_unref (profile);
|
|
|
|
|
2022-08-06 12:42:46 +08:00
|
|
|
profile = gimp_template_get_simulation_profile (template);
|
|
|
|
gimp_image_set_simulation_profile (image, profile);
|
|
|
|
if (profile)
|
|
|
|
g_object_unref (profile);
|
|
|
|
|
|
|
|
intent = gimp_template_get_simulation_intent (template);
|
|
|
|
gimp_image_set_simulation_intent (image, intent);
|
|
|
|
bpc = gimp_template_get_simulation_bpc (template);
|
|
|
|
gimp_image_set_simulation_bpc (image, bpc);
|
|
|
|
|
2010-06-06 04:42:00 +08:00
|
|
|
width = gimp_image_get_width (image);
|
|
|
|
height = gimp_image_get_height (image);
|
|
|
|
|
2014-06-03 07:11:32 +08:00
|
|
|
if (gimp_template_get_fill_type (template) == GIMP_FILL_TRANSPARENT)
|
2012-04-07 20:22:45 +08:00
|
|
|
has_alpha = TRUE;
|
|
|
|
else
|
|
|
|
has_alpha = FALSE;
|
2010-06-06 04:42:00 +08:00
|
|
|
|
2012-03-22 03:21:11 +08:00
|
|
|
layer = gimp_layer_new (image, width, height,
|
2012-04-07 20:22:45 +08:00
|
|
|
gimp_image_get_layer_format (image, has_alpha),
|
2010-06-06 04:42:00 +08:00
|
|
|
_("Background"),
|
2017-01-09 06:00:19 +08:00
|
|
|
GIMP_OPACITY_OPAQUE,
|
2017-08-22 02:04:25 +08:00
|
|
|
gimp_image_get_default_new_layer_mode (image));
|
2010-06-06 04:42:00 +08:00
|
|
|
|
2014-06-03 20:11:59 +08:00
|
|
|
gimp_drawable_fill (GIMP_DRAWABLE (layer),
|
|
|
|
context, gimp_template_get_fill_type (template));
|
2010-06-06 04:42:00 +08:00
|
|
|
|
|
|
|
gimp_image_add_layer (image, layer, NULL, 0, FALSE);
|
|
|
|
|
|
|
|
gimp_image_undo_enable (image);
|
|
|
|
gimp_image_clean_all (image);
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2010-02-08 21:47:45 +08:00
|
|
|
GimpImage *
|
|
|
|
gimp_image_new_from_drawable (Gimp *gimp,
|
|
|
|
GimpDrawable *drawable)
|
|
|
|
{
|
|
|
|
GimpItem *item;
|
|
|
|
GimpImage *image;
|
|
|
|
GimpImage *new_image;
|
|
|
|
GimpLayer *new_layer;
|
|
|
|
GType new_type;
|
|
|
|
gint off_x, off_y;
|
|
|
|
GimpImageBaseType type;
|
|
|
|
gdouble xres;
|
|
|
|
gdouble yres;
|
2016-05-03 18:51:52 +08:00
|
|
|
GimpColorProfile *profile;
|
2010-02-08 21:47:45 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
|
|
|
|
|
|
|
item = GIMP_ITEM (drawable);
|
|
|
|
image = gimp_item_get_image (item);
|
|
|
|
|
2012-04-07 07:51:08 +08:00
|
|
|
type = gimp_drawable_get_base_type (drawable);
|
2010-02-08 21:47:45 +08:00
|
|
|
|
|
|
|
new_image = gimp_create_image (gimp,
|
|
|
|
gimp_item_get_width (item),
|
|
|
|
gimp_item_get_height (item),
|
2012-04-22 23:31:32 +08:00
|
|
|
type,
|
|
|
|
gimp_drawable_get_precision (drawable),
|
|
|
|
TRUE);
|
2010-02-08 21:47:45 +08:00
|
|
|
gimp_image_undo_disable (new_image);
|
|
|
|
|
|
|
|
if (type == GIMP_INDEXED)
|
2019-11-08 17:50:32 +08:00
|
|
|
gimp_image_set_colormap_palette (new_image,
|
|
|
|
gimp_image_get_colormap_palette (image),
|
|
|
|
FALSE);
|
2010-02-08 21:47:45 +08:00
|
|
|
|
|
|
|
gimp_image_get_resolution (image, &xres, &yres);
|
|
|
|
gimp_image_set_resolution (new_image, xres, yres);
|
|
|
|
gimp_image_set_unit (new_image, gimp_image_get_unit (image));
|
|
|
|
|
2016-05-03 18:51:52 +08:00
|
|
|
profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (drawable));
|
|
|
|
gimp_image_set_color_profile (new_image, profile, NULL);
|
2015-06-17 15:55:08 +08:00
|
|
|
|
2016-05-03 18:51:52 +08:00
|
|
|
if (GIMP_IS_LAYER (drawable))
|
|
|
|
new_type = G_TYPE_FROM_INSTANCE (drawable);
|
2010-02-08 21:47:45 +08:00
|
|
|
else
|
2016-05-03 18:51:52 +08:00
|
|
|
new_type = GIMP_TYPE_LAYER;
|
2010-02-08 21:47:45 +08:00
|
|
|
|
|
|
|
new_layer = GIMP_LAYER (gimp_item_convert (GIMP_ITEM (drawable),
|
|
|
|
new_image, new_type));
|
|
|
|
|
|
|
|
gimp_object_set_name (GIMP_OBJECT (new_layer),
|
|
|
|
gimp_object_get_name (drawable));
|
|
|
|
|
|
|
|
gimp_item_get_offset (GIMP_ITEM (new_layer), &off_x, &off_y);
|
|
|
|
gimp_item_translate (GIMP_ITEM (new_layer), -off_x, -off_y, FALSE);
|
|
|
|
gimp_item_set_visible (GIMP_ITEM (new_layer), TRUE, FALSE);
|
2017-08-20 19:45:42 +08:00
|
|
|
gimp_layer_set_mode (new_layer,
|
2017-08-22 02:04:25 +08:00
|
|
|
gimp_image_get_default_new_layer_mode (new_image),
|
2017-08-20 19:45:42 +08:00
|
|
|
FALSE);
|
2010-02-08 21:47:45 +08:00
|
|
|
gimp_layer_set_opacity (new_layer, GIMP_OPACITY_OPAQUE, FALSE);
|
2016-09-18 01:19:30 +08:00
|
|
|
if (gimp_layer_can_lock_alpha (new_layer))
|
|
|
|
gimp_layer_set_lock_alpha (new_layer, FALSE, FALSE);
|
2010-02-08 21:47:45 +08:00
|
|
|
|
|
|
|
gimp_image_add_layer (new_image, new_layer, NULL, 0, TRUE);
|
|
|
|
|
|
|
|
gimp_image_undo_enable (new_image);
|
|
|
|
|
|
|
|
return new_image;
|
|
|
|
}
|
|
|
|
|
2020-05-06 21:46:51 +08:00
|
|
|
/**
|
|
|
|
* gimp_image_new_copy_drawables:
|
app: rework and fix the logic for copy-pasting multiple drawables.
There were a lot of incertainty of what should happen when we copy layers being
descendant of each other (i.e. when you select a group layer and some of its
children), then when you paste such data. So we sat down with Aryeom and tried
to come up with some consistent behavior which is somewhat expectable, but also
which would allow the most use-case.
Otherwise it was making very weird result when pasting the data, duplicating
some layers and whatnot, which was obviously a buggy behavior and never the
expected result.
We decided that if you select one leaf item, then even if you also selected a
parent item, it would be as though the parent was not selected. This is very
often what you expect anyway when you select a whole bunch of layers and would
work well if, say, you shift-click over many layers in sub-groups. Then you
wouldn't have to manually ctrl-click to unselect every group.
Then what if you were instead expecting to copy many groups? Then you could
shift-click the group arrow, closing all same-level groups. Once they are all
closed, you can shift-click the groups to only select group layers, not their
contents.
This way, both use cases are still quite doable easily with this default choice.
2022-11-13 01:28:58 +08:00
|
|
|
* @image: the image where @drawables belong to.
|
|
|
|
* @drawables: the drawables to copy into @new_image.
|
|
|
|
* @new_image: the image to insert to.
|
|
|
|
* @tag_copies: tag copies of @drawable with "gimp-image-copied-layer".
|
|
|
|
* @copied_drawables:
|
|
|
|
* @tagged_drawables:
|
2020-05-06 21:46:51 +08:00
|
|
|
* @parent:
|
|
|
|
* @new_parent:
|
|
|
|
*
|
|
|
|
* This recursive function will create copies of all @drawables
|
|
|
|
* belonging to the same @image, and will insert them into @new_image
|
|
|
|
* with the same layer order and hierarchy (adding layer groups when
|
|
|
|
* needed).
|
|
|
|
* If a single drawable is selected, it will be copied visible, with
|
|
|
|
* full opacity and default layer mode. Otherwise, visibility, opacity
|
|
|
|
* and layer mode will be copied as-is, allowing proper compositing.
|
|
|
|
*
|
app: rework and fix the logic for copy-pasting multiple drawables.
There were a lot of incertainty of what should happen when we copy layers being
descendant of each other (i.e. when you select a group layer and some of its
children), then when you paste such data. So we sat down with Aryeom and tried
to come up with some consistent behavior which is somewhat expectable, but also
which would allow the most use-case.
Otherwise it was making very weird result when pasting the data, duplicating
some layers and whatnot, which was obviously a buggy behavior and never the
expected result.
We decided that if you select one leaf item, then even if you also selected a
parent item, it would be as though the parent was not selected. This is very
often what you expect anyway when you select a whole bunch of layers and would
work well if, say, you shift-click over many layers in sub-groups. Then you
wouldn't have to manually ctrl-click to unselect every group.
Then what if you were instead expecting to copy many groups? Then you could
shift-click the group arrow, closing all same-level groups. Once they are all
closed, you can shift-click the groups to only select group layers, not their
contents.
This way, both use cases are still quite doable easily with this default choice.
2022-11-13 01:28:58 +08:00
|
|
|
* The @copied_drawables, @tagged_drawables, @parent and @new_parent arguments
|
|
|
|
* are only used internally for recursive calls and must be set to NULL for the
|
|
|
|
* initial call.
|
2020-05-06 21:46:51 +08:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gimp_image_new_copy_drawables (GimpImage *image,
|
|
|
|
GList *drawables,
|
|
|
|
GimpImage *new_image,
|
app: rework and fix the logic for copy-pasting multiple drawables.
There were a lot of incertainty of what should happen when we copy layers being
descendant of each other (i.e. when you select a group layer and some of its
children), then when you paste such data. So we sat down with Aryeom and tried
to come up with some consistent behavior which is somewhat expectable, but also
which would allow the most use-case.
Otherwise it was making very weird result when pasting the data, duplicating
some layers and whatnot, which was obviously a buggy behavior and never the
expected result.
We decided that if you select one leaf item, then even if you also selected a
parent item, it would be as though the parent was not selected. This is very
often what you expect anyway when you select a whole bunch of layers and would
work well if, say, you shift-click over many layers in sub-groups. Then you
wouldn't have to manually ctrl-click to unselect every group.
Then what if you were instead expecting to copy many groups? Then you could
shift-click the group arrow, closing all same-level groups. Once they are all
closed, you can shift-click the groups to only select group layers, not their
contents.
This way, both use cases are still quite doable easily with this default choice.
2022-11-13 01:28:58 +08:00
|
|
|
gboolean tag_copies,
|
|
|
|
GList *copied_drawables,
|
|
|
|
GList *tagged_drawables,
|
2020-05-06 21:46:51 +08:00
|
|
|
GimpLayer *parent,
|
|
|
|
GimpLayer *new_parent)
|
|
|
|
{
|
|
|
|
GList *layers;
|
|
|
|
GList *iter;
|
|
|
|
gint n_drawables;
|
|
|
|
gint index;
|
|
|
|
|
|
|
|
n_drawables = g_list_length (drawables);
|
|
|
|
if (parent == NULL)
|
|
|
|
{
|
app: rework and fix the logic for copy-pasting multiple drawables.
There were a lot of incertainty of what should happen when we copy layers being
descendant of each other (i.e. when you select a group layer and some of its
children), then when you paste such data. So we sat down with Aryeom and tried
to come up with some consistent behavior which is somewhat expectable, but also
which would allow the most use-case.
Otherwise it was making very weird result when pasting the data, duplicating
some layers and whatnot, which was obviously a buggy behavior and never the
expected result.
We decided that if you select one leaf item, then even if you also selected a
parent item, it would be as though the parent was not selected. This is very
often what you expect anyway when you select a whole bunch of layers and would
work well if, say, you shift-click over many layers in sub-groups. Then you
wouldn't have to manually ctrl-click to unselect every group.
Then what if you were instead expecting to copy many groups? Then you could
shift-click the group arrow, closing all same-level groups. Once they are all
closed, you can shift-click the groups to only select group layers, not their
contents.
This way, both use cases are still quite doable easily with this default choice.
2022-11-13 01:28:58 +08:00
|
|
|
/* Root layers. */
|
|
|
|
layers = gimp_image_get_layer_iter (image);
|
|
|
|
|
|
|
|
copied_drawables = g_list_copy (drawables);
|
|
|
|
for (iter = copied_drawables; iter; iter = iter->next)
|
2020-05-06 21:46:51 +08:00
|
|
|
{
|
app: rework and fix the logic for copy-pasting multiple drawables.
There were a lot of incertainty of what should happen when we copy layers being
descendant of each other (i.e. when you select a group layer and some of its
children), then when you paste such data. So we sat down with Aryeom and tried
to come up with some consistent behavior which is somewhat expectable, but also
which would allow the most use-case.
Otherwise it was making very weird result when pasting the data, duplicating
some layers and whatnot, which was obviously a buggy behavior and never the
expected result.
We decided that if you select one leaf item, then even if you also selected a
parent item, it would be as though the parent was not selected. This is very
often what you expect anyway when you select a whole bunch of layers and would
work well if, say, you shift-click over many layers in sub-groups. Then you
wouldn't have to manually ctrl-click to unselect every group.
Then what if you were instead expecting to copy many groups? Then you could
shift-click the group arrow, closing all same-level groups. Once they are all
closed, you can shift-click the groups to only select group layers, not their
contents.
This way, both use cases are still quite doable easily with this default choice.
2022-11-13 01:28:58 +08:00
|
|
|
/* Tagged drawables are the explicitly copied drawables which have no
|
|
|
|
* explicitly copied descendant items.
|
|
|
|
*/
|
|
|
|
GList *iter2;
|
|
|
|
|
|
|
|
for (iter2 = iter; iter2; iter2 = iter2->next)
|
|
|
|
if (gimp_viewable_is_ancestor (iter->data, iter2->data))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (iter2 == NULL)
|
|
|
|
tagged_drawables = g_list_prepend (tagged_drawables, iter->data);
|
2020-05-06 21:46:51 +08:00
|
|
|
}
|
app: rework and fix the logic for copy-pasting multiple drawables.
There were a lot of incertainty of what should happen when we copy layers being
descendant of each other (i.e. when you select a group layer and some of its
children), then when you paste such data. So we sat down with Aryeom and tried
to come up with some consistent behavior which is somewhat expectable, but also
which would allow the most use-case.
Otherwise it was making very weird result when pasting the data, duplicating
some layers and whatnot, which was obviously a buggy behavior and never the
expected result.
We decided that if you select one leaf item, then even if you also selected a
parent item, it would be as though the parent was not selected. This is very
often what you expect anyway when you select a whole bunch of layers and would
work well if, say, you shift-click over many layers in sub-groups. Then you
wouldn't have to manually ctrl-click to unselect every group.
Then what if you were instead expecting to copy many groups? Then you could
shift-click the group arrow, closing all same-level groups. Once they are all
closed, you can shift-click the groups to only select group layers, not their
contents.
This way, both use cases are still quite doable easily with this default choice.
2022-11-13 01:28:58 +08:00
|
|
|
|
|
|
|
/* Add any item parent. */
|
|
|
|
for (iter = copied_drawables; iter; iter = iter->next)
|
2020-05-06 21:46:51 +08:00
|
|
|
{
|
app: rework and fix the logic for copy-pasting multiple drawables.
There were a lot of incertainty of what should happen when we copy layers being
descendant of each other (i.e. when you select a group layer and some of its
children), then when you paste such data. So we sat down with Aryeom and tried
to come up with some consistent behavior which is somewhat expectable, but also
which would allow the most use-case.
Otherwise it was making very weird result when pasting the data, duplicating
some layers and whatnot, which was obviously a buggy behavior and never the
expected result.
We decided that if you select one leaf item, then even if you also selected a
parent item, it would be as though the parent was not selected. This is very
often what you expect anyway when you select a whole bunch of layers and would
work well if, say, you shift-click over many layers in sub-groups. Then you
wouldn't have to manually ctrl-click to unselect every group.
Then what if you were instead expecting to copy many groups? Then you could
shift-click the group arrow, closing all same-level groups. Once they are all
closed, you can shift-click the groups to only select group layers, not their
contents.
This way, both use cases are still quite doable easily with this default choice.
2022-11-13 01:28:58 +08:00
|
|
|
GimpItem *item = iter->data;
|
|
|
|
while ((item = gimp_item_get_parent (item)))
|
|
|
|
if (! g_list_find (copied_drawables, item))
|
|
|
|
copied_drawables = g_list_prepend (copied_drawables, item);
|
2020-05-06 21:46:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GimpContainer *container;
|
|
|
|
|
|
|
|
container = gimp_viewable_get_children (GIMP_VIEWABLE (parent));
|
|
|
|
layers = GIMP_LIST (container)->queue->head;
|
|
|
|
}
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
for (iter = layers; iter; iter = iter->next)
|
|
|
|
{
|
app: rework and fix the logic for copy-pasting multiple drawables.
There were a lot of incertainty of what should happen when we copy layers being
descendant of each other (i.e. when you select a group layer and some of its
children), then when you paste such data. So we sat down with Aryeom and tried
to come up with some consistent behavior which is somewhat expectable, but also
which would allow the most use-case.
Otherwise it was making very weird result when pasting the data, duplicating
some layers and whatnot, which was obviously a buggy behavior and never the
expected result.
We decided that if you select one leaf item, then even if you also selected a
parent item, it would be as though the parent was not selected. This is very
often what you expect anyway when you select a whole bunch of layers and would
work well if, say, you shift-click over many layers in sub-groups. Then you
wouldn't have to manually ctrl-click to unselect every group.
Then what if you were instead expecting to copy many groups? Then you could
shift-click the group arrow, closing all same-level groups. Once they are all
closed, you can shift-click the groups to only select group layers, not their
contents.
This way, both use cases are still quite doable easily with this default choice.
2022-11-13 01:28:58 +08:00
|
|
|
if (g_list_find (copied_drawables, iter->data))
|
2020-05-06 21:46:51 +08:00
|
|
|
{
|
|
|
|
GimpLayer *new_layer;
|
|
|
|
GType new_type;
|
app: rework and fix the logic for copy-pasting multiple drawables.
There were a lot of incertainty of what should happen when we copy layers being
descendant of each other (i.e. when you select a group layer and some of its
children), then when you paste such data. So we sat down with Aryeom and tried
to come up with some consistent behavior which is somewhat expectable, but also
which would allow the most use-case.
Otherwise it was making very weird result when pasting the data, duplicating
some layers and whatnot, which was obviously a buggy behavior and never the
expected result.
We decided that if you select one leaf item, then even if you also selected a
parent item, it would be as though the parent was not selected. This is very
often what you expect anyway when you select a whole bunch of layers and would
work well if, say, you shift-click over many layers in sub-groups. Then you
wouldn't have to manually ctrl-click to unselect every group.
Then what if you were instead expecting to copy many groups? Then you could
shift-click the group arrow, closing all same-level groups. Once they are all
closed, you can shift-click the groups to only select group layers, not their
contents.
This way, both use cases are still quite doable easily with this default choice.
2022-11-13 01:28:58 +08:00
|
|
|
gboolean is_group;
|
|
|
|
gboolean is_tagged;
|
2020-05-06 21:46:51 +08:00
|
|
|
|
|
|
|
if (GIMP_IS_LAYER (iter->data))
|
|
|
|
new_type = G_TYPE_FROM_INSTANCE (iter->data);
|
|
|
|
else
|
|
|
|
new_type = GIMP_TYPE_LAYER;
|
|
|
|
|
app: rework and fix the logic for copy-pasting multiple drawables.
There were a lot of incertainty of what should happen when we copy layers being
descendant of each other (i.e. when you select a group layer and some of its
children), then when you paste such data. So we sat down with Aryeom and tried
to come up with some consistent behavior which is somewhat expectable, but also
which would allow the most use-case.
Otherwise it was making very weird result when pasting the data, duplicating
some layers and whatnot, which was obviously a buggy behavior and never the
expected result.
We decided that if you select one leaf item, then even if you also selected a
parent item, it would be as though the parent was not selected. This is very
often what you expect anyway when you select a whole bunch of layers and would
work well if, say, you shift-click over many layers in sub-groups. Then you
wouldn't have to manually ctrl-click to unselect every group.
Then what if you were instead expecting to copy many groups? Then you could
shift-click the group arrow, closing all same-level groups. Once they are all
closed, you can shift-click the groups to only select group layers, not their
contents.
This way, both use cases are still quite doable easily with this default choice.
2022-11-13 01:28:58 +08:00
|
|
|
is_group = (gimp_viewable_get_children (iter->data) != NULL);
|
|
|
|
is_tagged = (g_list_find (tagged_drawables, iter->data) != NULL);
|
|
|
|
|
|
|
|
if (is_group && ! is_tagged)
|
|
|
|
new_layer = gimp_group_layer_new (new_image);
|
|
|
|
else
|
|
|
|
new_layer = GIMP_LAYER (gimp_item_convert (GIMP_ITEM (iter->data),
|
|
|
|
new_image, new_type));
|
|
|
|
|
|
|
|
if (tag_copies && is_tagged)
|
|
|
|
g_object_set_data (G_OBJECT (new_layer),
|
|
|
|
"gimp-image-copied-layer",
|
|
|
|
GINT_TO_POINTER (TRUE));
|
2020-05-06 21:46:51 +08:00
|
|
|
|
|
|
|
gimp_object_set_name (GIMP_OBJECT (new_layer),
|
|
|
|
gimp_object_get_name (iter->data));
|
|
|
|
|
2021-02-24 19:33:03 +08:00
|
|
|
/* Visibility, mode and opacity mimic the source image if
|
2020-05-06 21:46:51 +08:00
|
|
|
* multiple items are copied. Otherwise we just set them to
|
|
|
|
* defaults.
|
|
|
|
*/
|
|
|
|
gimp_item_set_visible (GIMP_ITEM (new_layer),
|
|
|
|
n_drawables > 1 ?
|
|
|
|
gimp_item_get_visible (iter->data) : TRUE,
|
|
|
|
FALSE);
|
|
|
|
gimp_layer_set_mode (new_layer,
|
|
|
|
n_drawables > 1 && GIMP_IS_LAYER (iter->data) ?
|
|
|
|
gimp_layer_get_mode (iter->data) :
|
|
|
|
gimp_image_get_default_new_layer_mode (new_image),
|
|
|
|
FALSE);
|
|
|
|
gimp_layer_set_opacity (new_layer,
|
|
|
|
n_drawables > 1 && GIMP_IS_LAYER (iter->data) ?
|
|
|
|
gimp_layer_get_opacity (iter->data) : GIMP_OPACITY_OPAQUE, FALSE);
|
|
|
|
|
|
|
|
if (gimp_layer_can_lock_alpha (new_layer))
|
|
|
|
gimp_layer_set_lock_alpha (new_layer, FALSE, FALSE);
|
|
|
|
|
|
|
|
gimp_image_add_layer (new_image, new_layer, new_parent, index++, TRUE);
|
|
|
|
|
|
|
|
/* If a group, loop through children. */
|
app: rework and fix the logic for copy-pasting multiple drawables.
There were a lot of incertainty of what should happen when we copy layers being
descendant of each other (i.e. when you select a group layer and some of its
children), then when you paste such data. So we sat down with Aryeom and tried
to come up with some consistent behavior which is somewhat expectable, but also
which would allow the most use-case.
Otherwise it was making very weird result when pasting the data, duplicating
some layers and whatnot, which was obviously a buggy behavior and never the
expected result.
We decided that if you select one leaf item, then even if you also selected a
parent item, it would be as though the parent was not selected. This is very
often what you expect anyway when you select a whole bunch of layers and would
work well if, say, you shift-click over many layers in sub-groups. Then you
wouldn't have to manually ctrl-click to unselect every group.
Then what if you were instead expecting to copy many groups? Then you could
shift-click the group arrow, closing all same-level groups. Once they are all
closed, you can shift-click the groups to only select group layers, not their
contents.
This way, both use cases are still quite doable easily with this default choice.
2022-11-13 01:28:58 +08:00
|
|
|
if (is_group && ! is_tagged)
|
|
|
|
gimp_image_new_copy_drawables (image, drawables, new_image, tag_copies,
|
|
|
|
copied_drawables, tagged_drawables,
|
|
|
|
iter->data, new_layer);
|
2020-05-06 21:46:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
app: rework and fix the logic for copy-pasting multiple drawables.
There were a lot of incertainty of what should happen when we copy layers being
descendant of each other (i.e. when you select a group layer and some of its
children), then when you paste such data. So we sat down with Aryeom and tried
to come up with some consistent behavior which is somewhat expectable, but also
which would allow the most use-case.
Otherwise it was making very weird result when pasting the data, duplicating
some layers and whatnot, which was obviously a buggy behavior and never the
expected result.
We decided that if you select one leaf item, then even if you also selected a
parent item, it would be as though the parent was not selected. This is very
often what you expect anyway when you select a whole bunch of layers and would
work well if, say, you shift-click over many layers in sub-groups. Then you
wouldn't have to manually ctrl-click to unselect every group.
Then what if you were instead expecting to copy many groups? Then you could
shift-click the group arrow, closing all same-level groups. Once they are all
closed, you can shift-click the groups to only select group layers, not their
contents.
This way, both use cases are still quite doable easily with this default choice.
2022-11-13 01:28:58 +08:00
|
|
|
if (parent == NULL)
|
|
|
|
{
|
|
|
|
g_list_free (copied_drawables);
|
|
|
|
g_list_free (tagged_drawables);
|
|
|
|
}
|
2020-05-06 21:46:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpImage *
|
|
|
|
gimp_image_new_from_drawables (Gimp *gimp,
|
|
|
|
GList *drawables,
|
app: rework and fix the logic for copy-pasting multiple drawables.
There were a lot of incertainty of what should happen when we copy layers being
descendant of each other (i.e. when you select a group layer and some of its
children), then when you paste such data. So we sat down with Aryeom and tried
to come up with some consistent behavior which is somewhat expectable, but also
which would allow the most use-case.
Otherwise it was making very weird result when pasting the data, duplicating
some layers and whatnot, which was obviously a buggy behavior and never the
expected result.
We decided that if you select one leaf item, then even if you also selected a
parent item, it would be as though the parent was not selected. This is very
often what you expect anyway when you select a whole bunch of layers and would
work well if, say, you shift-click over many layers in sub-groups. Then you
wouldn't have to manually ctrl-click to unselect every group.
Then what if you were instead expecting to copy many groups? Then you could
shift-click the group arrow, closing all same-level groups. Once they are all
closed, you can shift-click the groups to only select group layers, not their
contents.
This way, both use cases are still quite doable easily with this default choice.
2022-11-13 01:28:58 +08:00
|
|
|
gboolean copy_selection,
|
|
|
|
gboolean tag_copies)
|
2020-05-06 21:46:51 +08:00
|
|
|
{
|
|
|
|
GimpImage *image = NULL;
|
|
|
|
GimpImage *new_image;
|
|
|
|
GList *iter;
|
|
|
|
GimpImageBaseType type;
|
|
|
|
GimpPrecision precision;
|
|
|
|
gdouble xres;
|
|
|
|
gdouble yres;
|
|
|
|
GimpColorProfile *profile = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (drawables != NULL, NULL);
|
|
|
|
|
|
|
|
for (iter = drawables; iter; iter = iter->next)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (iter->data), NULL);
|
|
|
|
|
|
|
|
if (iter == drawables)
|
|
|
|
image = gimp_item_get_image (iter->data);
|
|
|
|
else
|
|
|
|
/* We only accept list of drawables for a same origin image. */
|
|
|
|
g_return_val_if_fail (gimp_item_get_image (iter->data) == image, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
type = gimp_drawable_get_base_type (drawables->data);
|
|
|
|
precision = gimp_drawable_get_precision (drawables->data);
|
|
|
|
profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (drawables->data));
|
|
|
|
|
|
|
|
new_image = gimp_create_image (gimp,
|
|
|
|
gimp_image_get_width (image),
|
|
|
|
gimp_image_get_height (image),
|
|
|
|
type, precision,
|
|
|
|
TRUE);
|
|
|
|
gimp_image_undo_disable (new_image);
|
|
|
|
|
|
|
|
if (type == GIMP_INDEXED)
|
2019-11-08 17:50:32 +08:00
|
|
|
gimp_image_set_colormap_palette (new_image,
|
|
|
|
gimp_image_get_colormap_palette (image),
|
|
|
|
FALSE);
|
2020-05-06 21:46:51 +08:00
|
|
|
|
|
|
|
gimp_image_get_resolution (image, &xres, &yres);
|
|
|
|
gimp_image_set_resolution (new_image, xres, yres);
|
|
|
|
gimp_image_set_unit (new_image, gimp_image_get_unit (image));
|
|
|
|
if (profile)
|
|
|
|
gimp_image_set_color_profile (new_image, profile, NULL);
|
|
|
|
|
|
|
|
if (copy_selection)
|
|
|
|
{
|
|
|
|
GimpChannel *selection;
|
|
|
|
|
|
|
|
selection = gimp_image_get_mask (image);
|
|
|
|
if (! gimp_channel_is_empty (selection))
|
|
|
|
{
|
|
|
|
GimpChannel *new_selection;
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
|
|
|
|
new_selection = gimp_image_get_mask (new_image);
|
|
|
|
buffer = gimp_gegl_buffer_dup (gimp_drawable_get_buffer (GIMP_DRAWABLE (selection)));
|
|
|
|
gimp_drawable_set_buffer (GIMP_DRAWABLE (new_selection),
|
|
|
|
FALSE, NULL, buffer);
|
|
|
|
g_object_unref (buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
app: rework and fix the logic for copy-pasting multiple drawables.
There were a lot of incertainty of what should happen when we copy layers being
descendant of each other (i.e. when you select a group layer and some of its
children), then when you paste such data. So we sat down with Aryeom and tried
to come up with some consistent behavior which is somewhat expectable, but also
which would allow the most use-case.
Otherwise it was making very weird result when pasting the data, duplicating
some layers and whatnot, which was obviously a buggy behavior and never the
expected result.
We decided that if you select one leaf item, then even if you also selected a
parent item, it would be as though the parent was not selected. This is very
often what you expect anyway when you select a whole bunch of layers and would
work well if, say, you shift-click over many layers in sub-groups. Then you
wouldn't have to manually ctrl-click to unselect every group.
Then what if you were instead expecting to copy many groups? Then you could
shift-click the group arrow, closing all same-level groups. Once they are all
closed, you can shift-click the groups to only select group layers, not their
contents.
This way, both use cases are still quite doable easily with this default choice.
2022-11-13 01:28:58 +08:00
|
|
|
gimp_image_new_copy_drawables (image, drawables, new_image, tag_copies, NULL, NULL, NULL, NULL);
|
2020-05-06 21:46:51 +08:00
|
|
|
gimp_image_undo_enable (new_image);
|
|
|
|
|
|
|
|
return new_image;
|
|
|
|
}
|
|
|
|
|
2010-02-08 21:47:45 +08:00
|
|
|
GimpImage *
|
|
|
|
gimp_image_new_from_component (Gimp *gimp,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpChannelType component)
|
|
|
|
{
|
|
|
|
GimpImage *new_image;
|
|
|
|
GimpChannel *channel;
|
|
|
|
GimpLayer *layer;
|
|
|
|
const gchar *desc;
|
|
|
|
gdouble xres;
|
|
|
|
gdouble yres;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
|
|
|
|
|
|
|
new_image = gimp_create_image (gimp,
|
|
|
|
gimp_image_get_width (image),
|
|
|
|
gimp_image_get_height (image),
|
2012-04-22 23:31:32 +08:00
|
|
|
GIMP_GRAY,
|
|
|
|
gimp_image_get_precision (image),
|
|
|
|
TRUE);
|
2010-02-08 21:47:45 +08:00
|
|
|
|
|
|
|
gimp_image_undo_disable (new_image);
|
|
|
|
|
|
|
|
gimp_image_get_resolution (image, &xres, &yres);
|
|
|
|
gimp_image_set_resolution (new_image, xres, yres);
|
|
|
|
gimp_image_set_unit (new_image, gimp_image_get_unit (image));
|
|
|
|
|
|
|
|
channel = gimp_channel_new_from_component (image, component, NULL, NULL);
|
|
|
|
|
|
|
|
layer = GIMP_LAYER (gimp_item_convert (GIMP_ITEM (channel),
|
|
|
|
new_image, GIMP_TYPE_LAYER));
|
|
|
|
g_object_unref (channel);
|
|
|
|
|
|
|
|
gimp_enum_get_value (GIMP_TYPE_CHANNEL_TYPE, component,
|
|
|
|
NULL, NULL, &desc, NULL);
|
|
|
|
gimp_object_take_name (GIMP_OBJECT (layer),
|
|
|
|
g_strdup_printf (_("%s Channel Copy"), desc));
|
|
|
|
|
|
|
|
gimp_image_add_layer (new_image, layer, NULL, 0, TRUE);
|
|
|
|
|
|
|
|
gimp_image_undo_enable (new_image);
|
|
|
|
|
|
|
|
return new_image;
|
|
|
|
}
|
|
|
|
|
2010-02-08 22:19:03 +08:00
|
|
|
GimpImage *
|
|
|
|
gimp_image_new_from_buffer (Gimp *gimp,
|
2017-05-02 00:36:33 +08:00
|
|
|
GimpBuffer *buffer)
|
2010-02-08 22:19:03 +08:00
|
|
|
{
|
2015-08-16 19:14:56 +08:00
|
|
|
GimpImage *image;
|
|
|
|
GimpLayer *layer;
|
|
|
|
const Babl *format;
|
|
|
|
gboolean has_alpha;
|
2017-05-02 00:36:33 +08:00
|
|
|
gdouble res_x;
|
|
|
|
gdouble res_y;
|
2015-08-16 19:14:56 +08:00
|
|
|
GimpColorProfile *profile;
|
2010-02-08 22:19:03 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
2017-05-02 00:36:33 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_BUFFER (buffer), NULL);
|
2010-02-08 22:19:03 +08:00
|
|
|
|
2017-05-02 00:36:33 +08:00
|
|
|
format = gimp_buffer_get_format (buffer);
|
2012-04-07 08:43:18 +08:00
|
|
|
has_alpha = babl_format_has_alpha (format);
|
2010-02-08 22:19:03 +08:00
|
|
|
|
|
|
|
image = gimp_create_image (gimp,
|
2017-05-02 00:36:33 +08:00
|
|
|
gimp_buffer_get_width (buffer),
|
|
|
|
gimp_buffer_get_height (buffer),
|
2012-04-07 08:43:18 +08:00
|
|
|
gimp_babl_format_get_base_type (format),
|
2012-04-22 23:31:32 +08:00
|
|
|
gimp_babl_format_get_precision (format),
|
2010-02-08 22:19:03 +08:00
|
|
|
TRUE);
|
|
|
|
gimp_image_undo_disable (image);
|
|
|
|
|
2017-05-02 00:36:33 +08:00
|
|
|
if (gimp_buffer_get_resolution (buffer, &res_x, &res_y))
|
2010-02-08 22:19:03 +08:00
|
|
|
{
|
2017-05-02 00:36:33 +08:00
|
|
|
gimp_image_set_resolution (image, res_x, res_y);
|
|
|
|
gimp_image_set_unit (image, gimp_buffer_get_unit (buffer));
|
2010-02-08 22:19:03 +08:00
|
|
|
}
|
|
|
|
|
2017-05-02 00:36:33 +08:00
|
|
|
profile = gimp_buffer_get_color_profile (buffer);
|
2016-05-03 18:51:52 +08:00
|
|
|
gimp_image_set_color_profile (image, profile, NULL);
|
2015-06-17 15:55:08 +08:00
|
|
|
|
2017-05-02 00:36:33 +08:00
|
|
|
layer = gimp_layer_new_from_buffer (buffer, image,
|
2012-04-07 08:43:18 +08:00
|
|
|
gimp_image_get_layer_format (image,
|
|
|
|
has_alpha),
|
2012-03-15 06:09:36 +08:00
|
|
|
_("Pasted Layer"),
|
2017-01-09 06:00:19 +08:00
|
|
|
GIMP_OPACITY_OPAQUE,
|
2017-08-22 02:04:25 +08:00
|
|
|
gimp_image_get_default_new_layer_mode (image));
|
2010-02-08 22:19:03 +08:00
|
|
|
|
|
|
|
gimp_image_add_layer (image, layer, NULL, 0, TRUE);
|
|
|
|
|
|
|
|
gimp_image_undo_enable (image);
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2010-02-08 21:47:45 +08:00
|
|
|
GimpImage *
|
|
|
|
gimp_image_new_from_pixbuf (Gimp *gimp,
|
|
|
|
GdkPixbuf *pixbuf,
|
|
|
|
const gchar *layer_name)
|
|
|
|
{
|
2012-04-07 07:51:08 +08:00
|
|
|
GimpImage *new_image;
|
|
|
|
GimpLayer *layer;
|
|
|
|
GimpImageBaseType base_type;
|
2016-02-13 05:48:59 +08:00
|
|
|
gboolean has_alpha = FALSE;
|
2015-06-17 15:55:08 +08:00
|
|
|
guint8 *icc_data;
|
|
|
|
gsize icc_len;
|
2010-02-08 21:47:45 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
|
|
|
|
|
|
|
|
switch (gdk_pixbuf_get_n_channels (pixbuf))
|
|
|
|
{
|
2012-04-07 07:51:08 +08:00
|
|
|
case 2: has_alpha = TRUE;
|
|
|
|
case 1: base_type = GIMP_GRAY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4: has_alpha = TRUE;
|
|
|
|
case 3: base_type = GIMP_RGB;
|
2010-02-08 21:47:45 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_return_val_if_reached (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
new_image = gimp_create_image (gimp,
|
|
|
|
gdk_pixbuf_get_width (pixbuf),
|
|
|
|
gdk_pixbuf_get_height (pixbuf),
|
2012-04-07 07:51:08 +08:00
|
|
|
base_type,
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 20:23:01 +08:00
|
|
|
GIMP_PRECISION_U8_NON_LINEAR,
|
2010-02-08 21:47:45 +08:00
|
|
|
FALSE);
|
|
|
|
|
|
|
|
gimp_image_undo_disable (new_image);
|
|
|
|
|
2015-06-17 15:55:08 +08:00
|
|
|
icc_data = gimp_pixbuf_get_icc_profile (pixbuf, &icc_len);
|
|
|
|
if (icc_data)
|
|
|
|
{
|
2022-07-26 20:18:40 +08:00
|
|
|
gimp_image_set_icc_profile (new_image, icc_data, icc_len,
|
|
|
|
GIMP_ICC_PROFILE_PARASITE_NAME,
|
|
|
|
NULL);
|
2015-06-17 15:55:08 +08:00
|
|
|
g_free (icc_data);
|
|
|
|
}
|
|
|
|
|
2012-03-22 03:21:11 +08:00
|
|
|
layer = gimp_layer_new_from_pixbuf (pixbuf, new_image,
|
2012-04-07 07:51:08 +08:00
|
|
|
gimp_image_get_layer_format (new_image,
|
|
|
|
has_alpha),
|
2010-02-08 21:47:45 +08:00
|
|
|
layer_name,
|
2017-01-09 06:00:19 +08:00
|
|
|
GIMP_OPACITY_OPAQUE,
|
2017-08-22 02:04:25 +08:00
|
|
|
gimp_image_get_default_new_layer_mode (new_image));
|
2010-02-08 21:47:45 +08:00
|
|
|
|
|
|
|
gimp_image_add_layer (new_image, layer, NULL, 0, TRUE);
|
|
|
|
|
|
|
|
gimp_image_undo_enable (new_image);
|
|
|
|
|
|
|
|
return new_image;
|
|
|
|
}
|