Commit 6e49a0fa authored by Michael Natterer's avatar Michael Natterer 😴
Browse files

Move gimp_edit_paste_as_new() to gimp_image_new_from_buffer()

because it better fits there, and it's never actually been a "paste"
from the implementation point of view.
parent 90360411
......@@ -27,6 +27,7 @@
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpimage-new.h"
#include "widgets/gimpbufferview.h"
#include "widgets/gimpcontainerview.h"
......@@ -85,14 +86,10 @@ buffers_paste_as_new_cmd_callback (GtkAction *action,
{
GimpImage *new_image;
new_image = gimp_edit_paste_as_new (image->gimp, image, buffer);
if (new_image)
{
gimp_create_display (image->gimp, new_image,
GIMP_UNIT_PIXEL, 1.0);
g_object_unref (new_image);
}
new_image = gimp_image_new_from_buffer (image->gimp, image, buffer);
gimp_create_display (image->gimp, new_image,
GIMP_UNIT_PIXEL, 1.0);
g_object_unref (new_image);
}
}
}
......
......@@ -34,6 +34,7 @@
#include "core/gimpdrawable.h"
#include "core/gimplayer.h"
#include "core/gimpimage.h"
#include "core/gimpimage-new.h"
#include "core/gimpimage-undo.h"
#include "vectors/gimpvectors-import.h"
......@@ -311,15 +312,12 @@ edit_paste_as_new_cmd_callback (GtkAction *action,
{
GimpImage *image;
image = gimp_edit_paste_as_new (gimp, action_data_get_image (data),
buffer);
image = gimp_image_new_from_buffer (gimp, action_data_get_image (data),
buffer);
g_object_unref (buffer);
if (image)
{
gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0);
g_object_unref (image);
}
gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0);
g_object_unref (image);
}
else
{
......
......@@ -281,65 +281,6 @@ gimp_edit_paste (GimpImage *image,
return layer;
}
GimpImage *
gimp_edit_paste_as_new (Gimp *gimp,
GimpImage *invoke,
GimpBuffer *paste)
{
GimpImage *image;
GimpLayer *layer;
GimpImageType type;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (invoke == NULL || GIMP_IS_IMAGE (invoke), NULL);
g_return_val_if_fail (GIMP_IS_BUFFER (paste), NULL);
switch (tile_manager_bpp (paste->tiles))
{
case 1: type = GIMP_GRAY_IMAGE; break;
case 2: type = GIMP_GRAYA_IMAGE; break;
case 3: type = GIMP_RGB_IMAGE; break;
case 4: type = GIMP_RGBA_IMAGE; break;
default:
g_return_val_if_reached (NULL);
break;
}
/* create a new image (always of type GIMP_RGB) */
image = gimp_create_image (gimp,
gimp_buffer_get_width (paste),
gimp_buffer_get_height (paste),
GIMP_IMAGE_TYPE_BASE_TYPE (type),
TRUE);
gimp_image_undo_disable (image);
if (invoke)
{
gdouble xres;
gdouble yres;
gimp_image_get_resolution (invoke, &xres, &yres);
gimp_image_set_resolution (image, xres, yres);
gimp_image_set_unit (image, gimp_image_get_unit (invoke));
}
layer = gimp_layer_new_from_tiles (paste->tiles, image, type,
_("Pasted Layer"),
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
if (! layer)
{
g_object_unref (image);
return NULL;
}
gimp_image_add_layer (image, layer, NULL, 0, TRUE);
gimp_image_undo_enable (image);
return image;
}
const gchar *
gimp_edit_named_cut (GimpImage *image,
const gchar *name,
......
......@@ -38,9 +38,6 @@ GimpLayer * gimp_edit_paste (GimpImage *image,
gint viewport_y,
gint viewport_width,
gint viewport_height);
GimpImage * gimp_edit_paste_as_new (Gimp *gimp,
GimpImage *image,
GimpBuffer *paste);
const gchar * gimp_edit_named_cut (GimpImage *image,
const gchar *name,
......
......@@ -24,9 +24,12 @@
#include "core-types.h"
#include "base/tile-manager.h"
#include "config/gimpcoreconfig.h"
#include "gimp.h"
#include "gimpbuffer.h"
#include "gimpchannel.h"
#include "gimpimage.h"
#include "gimpimage-colormap.h"
......@@ -183,6 +186,59 @@ gimp_image_new_from_component (Gimp *gimp,
return new_image;
}
GimpImage *
gimp_image_new_from_buffer (Gimp *gimp,
GimpImage *invoke,
GimpBuffer *paste)
{
GimpImage *image;
GimpLayer *layer;
GimpImageType type;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (invoke == NULL || GIMP_IS_IMAGE (invoke), NULL);
g_return_val_if_fail (GIMP_IS_BUFFER (paste), NULL);
switch (tile_manager_bpp (paste->tiles))
{
case 1: type = GIMP_GRAY_IMAGE; break;
case 2: type = GIMP_GRAYA_IMAGE; break;
case 3: type = GIMP_RGB_IMAGE; break;
case 4: type = GIMP_RGBA_IMAGE; break;
default:
g_return_val_if_reached (NULL);
break;
}
/* create a new image (always of type GIMP_RGB) */
image = gimp_create_image (gimp,
gimp_buffer_get_width (paste),
gimp_buffer_get_height (paste),
GIMP_IMAGE_TYPE_BASE_TYPE (type),
TRUE);
gimp_image_undo_disable (image);
if (invoke)
{
gdouble xres;
gdouble yres;
gimp_image_get_resolution (invoke, &xres, &yres);
gimp_image_set_resolution (image, xres, yres);
gimp_image_set_unit (image, gimp_image_get_unit (invoke));
}
layer = gimp_layer_new_from_tiles (paste->tiles, image, type,
_("Pasted Layer"),
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
gimp_image_add_layer (image, layer, NULL, 0, TRUE);
gimp_image_undo_enable (image);
return image;
}
GimpImage *
gimp_image_new_from_pixbuf (Gimp *gimp,
GdkPixbuf *pixbuf,
......
......@@ -29,6 +29,9 @@ GimpImage * gimp_image_new_from_drawable (Gimp *gimp,
GimpImage * gimp_image_new_from_component (Gimp *gimp,
GimpImage *image,
GimpChannelType component);
GimpImage * gimp_image_new_from_buffer (Gimp *gimp,
GimpImage *invoke,
GimpBuffer *paste);
GimpImage * gimp_image_new_from_pixbuf (Gimp *gimp,
GdkPixbuf *pixbuf,
const gchar *layer_name);
......
......@@ -31,6 +31,7 @@
#include "core/gimpdrawable-blend.h"
#include "core/gimpdrawable-bucket-fill.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage-new.h"
#include "core/gimpimage.h"
#include "core/gimplayer.h"
#include "core/gimpparamspecs.h"
......@@ -233,7 +234,7 @@ edit_paste_as_new_invoker (GimpProcedure *procedure,
if (gimp->global_buffer)
{
image = gimp_edit_paste_as_new (gimp, NULL, gimp->global_buffer);
image = gimp_image_new_from_buffer (gimp, NULL, gimp->global_buffer);
if (! image)
success = FALSE;
......@@ -470,7 +471,7 @@ edit_named_paste_as_new_invoker (GimpProcedure *procedure,
if (buffer)
{
image = gimp_edit_paste_as_new (gimp, NULL, buffer);
image = gimp_image_new_from_buffer (gimp, NULL, buffer);
if (! image)
success = FALSE;
......
......@@ -27,7 +27,6 @@
#include "widgets-types.h"
#include "core/gimp.h"
#include "core/gimp-edit.h"
#include "core/gimpbuffer.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
......@@ -232,13 +231,10 @@ gimp_toolbox_drop_buffer (GtkWidget *widget,
if (context->gimp->busy)
return;
image = gimp_edit_paste_as_new (context->gimp, NULL, GIMP_BUFFER (viewable));
if (image)
{
gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0);
g_object_unref (image);
}
image = gimp_image_new_from_buffer (context->gimp, NULL,
GIMP_BUFFER (viewable));
gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0);
g_object_unref (image);
}
static void
......
......@@ -239,7 +239,7 @@ HELP
{
if (gimp->global_buffer)
{
image = gimp_edit_paste_as_new (gimp, NULL, gimp->global_buffer);
image = gimp_image_new_from_buffer (gimp, NULL, gimp->global_buffer);
if (! image)
success = FALSE;
......@@ -482,7 +482,7 @@ HELP
if (buffer)
{
image = gimp_edit_paste_as_new (gimp, NULL, buffer);
image = gimp_image_new_from_buffer (gimp, NULL, buffer);
if (! image)
success = FALSE;
......@@ -917,6 +917,7 @@ CODE
"core/gimp.h"
"core/gimp-edit.h"
"core/gimpimage.h"
"core/gimpimage-new.h"
"core/gimpprogress.h"
"gimppdb-utils.h"
"gimp-intl.h");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment