Commit 536cc853 authored by Michael Natterer's avatar Michael Natterer 😴
Browse files

app: keep the src image's resolution and unit in copied/cut GimpBuffers

and use them for the new image in "Paste as new image". We were using
the resolution and unit of the image the paste command was invoked
from, which is entirely random and useless.
parent 80ec8683
......@@ -92,7 +92,7 @@ buffers_paste_as_new_image_cmd_callback (GtkAction *action,
GtkWidget *widget = GTK_WIDGET (editor);
GimpImage *new_image;
new_image = gimp_image_new_from_buffer (context->gimp, NULL, buffer);
new_image = gimp_image_new_from_buffer (context->gimp, buffer);
gimp_create_display (context->gimp, new_image,
GIMP_UNIT_PIXEL, 1.0,
G_OBJECT (gtk_widget_get_screen (widget)),
......
......@@ -384,9 +384,7 @@ edit_paste_as_new_image_cmd_callback (GtkAction *action,
}
else if (GIMP_IS_BUFFER (paste))
{
image = gimp_image_new_from_buffer (gimp,
action_data_get_image (data),
GIMP_BUFFER (paste));
image = gimp_image_new_from_buffer (gimp, GIMP_BUFFER (paste));
}
g_object_unref (paste);
......
......@@ -707,10 +707,18 @@ gimp_edit_extract (GimpImage *image,
if (buffer)
{
GimpBuffer *gimp_buffer = gimp_buffer_new (buffer, _("Global Buffer"),
offset_x, offset_y, FALSE);
GimpBuffer *gimp_buffer;
gdouble res_x;
gdouble res_y;
gimp_buffer = gimp_buffer_new (buffer, _("Global Buffer"),
offset_x, offset_y, FALSE);
g_object_unref (buffer);
gimp_image_get_resolution (image, &res_x, &res_y);
gimp_buffer_set_resolution (gimp_buffer, res_x, res_y);
gimp_buffer_set_unit (gimp_buffer, gimp_image_get_unit (image));
if (GIMP_IS_COLOR_MANAGED (pickable))
{
GimpColorProfile *profile =
......
......@@ -21,6 +21,7 @@
#include <gegl.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "core-types.h"
......@@ -468,6 +469,56 @@ gimp_buffer_get_buffer (GimpBuffer *buffer)
return buffer->buffer;
}
void
gimp_buffer_set_resolution (GimpBuffer *buffer,
gdouble resolution_x,
gdouble resolution_y)
{
g_return_if_fail (GIMP_IS_BUFFER (buffer));
g_return_if_fail (resolution_x >= 0.0 && resolution_x <= GIMP_MAX_RESOLUTION);
g_return_if_fail (resolution_y >= 0.0 && resolution_y <= GIMP_MAX_RESOLUTION);
buffer->resolution_x = resolution_x;
buffer->resolution_y = resolution_y;
}
gboolean
gimp_buffer_get_resolution (GimpBuffer *buffer,
gdouble *resolution_x,
gdouble *resolution_y)
{
g_return_val_if_fail (GIMP_IS_BUFFER (buffer), FALSE);
if (buffer->resolution_x > 0.0 &&
buffer->resolution_y > 0.0)
{
if (resolution_x) *resolution_x = buffer->resolution_x;
if (resolution_y) *resolution_y = buffer->resolution_y;
return TRUE;
}
return FALSE;
}
void
gimp_buffer_set_unit (GimpBuffer *buffer,
GimpUnit unit)
{
g_return_if_fail (GIMP_IS_BUFFER (buffer));
g_return_if_fail (unit > GIMP_UNIT_PIXEL);
buffer->unit = unit;
}
GimpUnit
gimp_buffer_get_unit (GimpBuffer *buffer)
{
g_return_val_if_fail (GIMP_IS_BUFFER (buffer), GIMP_UNIT_PIXEL);
return buffer->unit;
}
void
gimp_buffer_set_color_profile (GimpBuffer *buffer,
GimpColorProfile *profile)
......
......@@ -40,6 +40,10 @@ struct _GimpBuffer
gint offset_x;
gint offset_y;
gdouble resolution_x;
gdouble resolution_y;
GimpUnit unit;
GimpColorProfile *color_profile;
};
......@@ -67,6 +71,17 @@ const Babl * gimp_buffer_get_format (GimpBuffer *buffer);
GeglBuffer * gimp_buffer_get_buffer (GimpBuffer *buffer);
void gimp_buffer_set_resolution (GimpBuffer *buffer,
gdouble resolution_x,
gdouble resolution_y);
gboolean gimp_buffer_get_resolution (GimpBuffer *buffer,
gdouble *resolution_x,
gdouble *resolution_y);
void gimp_buffer_set_unit (GimpBuffer *buffer,
GimpUnit unit);
GimpUnit gimp_buffer_get_unit (GimpBuffer *buffer);
void gimp_buffer_set_color_profile (GimpBuffer *buffer,
GimpColorProfile *profile);
GimpColorProfile * gimp_buffer_get_color_profile (GimpBuffer *buffer);
......
......@@ -284,44 +284,40 @@ gimp_image_new_from_component (Gimp *gimp,
GimpImage *
gimp_image_new_from_buffer (Gimp *gimp,
GimpImage *invoke,
GimpBuffer *paste)
GimpBuffer *buffer)
{
GimpImage *image;
GimpLayer *layer;
const Babl *format;
gboolean has_alpha;
gdouble res_x;
gdouble res_y;
GimpColorProfile *profile;
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);
g_return_val_if_fail (GIMP_IS_BUFFER (buffer), NULL);
format = gimp_buffer_get_format (paste);
format = gimp_buffer_get_format (buffer);
has_alpha = babl_format_has_alpha (format);
image = gimp_create_image (gimp,
gimp_buffer_get_width (paste),
gimp_buffer_get_height (paste),
gimp_buffer_get_width (buffer),
gimp_buffer_get_height (buffer),
gimp_babl_format_get_base_type (format),
gimp_babl_format_get_precision (format),
TRUE);
gimp_image_undo_disable (image);
if (invoke)
if (gimp_buffer_get_resolution (buffer, &res_x, &res_y))
{
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));
gimp_image_set_resolution (image, res_x, res_y);
gimp_image_set_unit (image, gimp_buffer_get_unit (buffer));
}
profile = gimp_buffer_get_color_profile (paste);
profile = gimp_buffer_get_color_profile (buffer);
gimp_image_set_color_profile (image, profile, NULL);
layer = gimp_layer_new_from_buffer (paste, image,
layer = gimp_layer_new_from_buffer (buffer, image,
gimp_image_get_layer_format (image,
has_alpha),
_("Pasted Layer"),
......
......@@ -33,8 +33,7 @@ GimpImage * gimp_image_new_from_component (Gimp *gimp,
GimpImage *image,
GimpChannelType component);
GimpImage * gimp_image_new_from_buffer (Gimp *gimp,
GimpImage *invoke,
GimpBuffer *paste);
GimpBuffer *buffer);
GimpImage * gimp_image_new_from_pixbuf (Gimp *gimp,
GdkPixbuf *pixbuf,
const gchar *layer_name);
......
......@@ -458,7 +458,7 @@ gimp_display_shell_drop_buffer (GtkWidget *widget,
if (! image)
{
image = gimp_image_new_from_buffer (shell->display->gimp, NULL,
image = gimp_image_new_from_buffer (shell->display->gimp,
GIMP_BUFFER (viewable));
gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0,
G_OBJECT (gtk_widget_get_screen (widget)),
......
......@@ -257,7 +257,7 @@ edit_paste_as_new_image_invoker (GimpProcedure *procedure,
}
else if (GIMP_IS_BUFFER (paste))
{
image = gimp_image_new_from_buffer (gimp, NULL, GIMP_BUFFER (paste));
image = gimp_image_new_from_buffer (gimp, GIMP_BUFFER (paste));
}
if (! image)
......@@ -500,7 +500,7 @@ edit_named_paste_as_new_image_invoker (GimpProcedure *procedure,
if (buffer)
{
image = gimp_image_new_from_buffer (gimp, NULL, buffer);
image = gimp_image_new_from_buffer (gimp, buffer);
if (! image)
success = FALSE;
......
......@@ -225,7 +225,7 @@ gimp_toolbox_drop_buffer (GtkWidget *widget,
if (context->gimp->busy)
return;
image = gimp_image_new_from_buffer (context->gimp, NULL,
image = gimp_image_new_from_buffer (context->gimp,
GIMP_BUFFER (viewable));
gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0,
G_OBJECT (gtk_widget_get_screen (widget)),
......
......@@ -254,7 +254,7 @@ HELP
}
else if (GIMP_IS_BUFFER (paste))
{
image = gimp_image_new_from_buffer (gimp, NULL, GIMP_BUFFER (paste));
image = gimp_image_new_from_buffer (gimp, GIMP_BUFFER (paste));
}
if (! image)
......@@ -505,7 +505,7 @@ HELP
if (buffer)
{
image = gimp_image_new_from_buffer (gimp, NULL, buffer);
image = gimp_image_new_from_buffer (gimp, buffer);
if (! image)
success = FALSE;
......
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