Commit 91a947bb authored by Ell's avatar Ell

app: don't allow setting NULL buffer to drawables; modify steal_buffer()

Revert commit 24fcabc1, which
allowed passing a NULL buffer to gimp_drawable_set_buffer[_full](),
leaving the drawable without a buffer in a semi-functional state --
this is too risky.

Instead, have gimp_drawable_steal_buffer() assign an empty 1x1
buffer to the stolen-from drawable, rather than leaving it without
a buffer at all.
parent 18a5e41e
......@@ -1009,25 +1009,22 @@ gimp_channel_set_buffer (GimpDrawable *drawable,
buffer,
offset_x, offset_y);
if (buffer)
{
gegl_buffer_signal_connect (buffer, "changed",
G_CALLBACK (gimp_channel_buffer_changed),
channel);
gegl_buffer_signal_connect (buffer, "changed",
G_CALLBACK (gimp_channel_buffer_changed),
channel);
if (gimp_filter_peek_node (GIMP_FILTER (channel)))
{
const Babl *color_format;
if (gimp_filter_peek_node (GIMP_FILTER (channel)))
{
const Babl *color_format;
if (gimp_drawable_get_linear (drawable))
color_format = babl_format ("RGBA float");
else
color_format = babl_format ("R'G'B'A float");
if (gimp_drawable_get_linear (drawable))
color_format = babl_format ("RGBA float");
else
color_format = babl_format ("R'G'B'A float");
gegl_node_set (channel->color_node,
"format", color_format,
NULL);
}
gegl_node_set (channel->color_node,
"format", color_format,
NULL);
}
}
......
......@@ -772,22 +772,17 @@ gimp_drawable_real_set_buffer (GimpDrawable *drawable,
{
GimpItem *item = GIMP_ITEM (drawable);
gint old_has_alpha = -1;
gint width = 0;
gint height = 0;
g_object_freeze_notify (G_OBJECT (drawable));
gimp_drawable_invalidate_boundary (drawable);
if (push_undo)
{
gimp_image_undo_push_drawable_mod (gimp_item_get_image (item), undo_desc,
drawable, FALSE);
}
gimp_image_undo_push_drawable_mod (gimp_item_get_image (item), undo_desc,
drawable, FALSE);
/* ref new before unrefing old, they might be the same */
if (buffer)
g_object_ref (buffer);
g_object_ref (buffer);
if (drawable->private->buffer)
{
......@@ -803,22 +798,13 @@ gimp_drawable_real_set_buffer (GimpDrawable *drawable,
"buffer", gimp_drawable_get_buffer (drawable),
NULL);
if (buffer)
{
width = gegl_buffer_get_width (buffer);
height = gegl_buffer_get_height (buffer);
}
gimp_item_set_offset (item, offset_x, offset_y);
gimp_item_set_size (item, width, height);
gimp_item_set_size (item,
gegl_buffer_get_width (buffer),
gegl_buffer_get_height (buffer));
if (buffer)
{
gboolean new_has_alpha = gimp_drawable_has_alpha (drawable);
if (new_has_alpha != old_has_alpha)
gimp_drawable_alpha_changed (drawable);
}
if (gimp_drawable_has_alpha (drawable) != old_has_alpha)
gimp_drawable_alpha_changed (drawable);
g_object_notify (G_OBJECT (drawable), "buffer");
......@@ -1140,11 +1126,6 @@ gimp_drawable_get_buffer (GimpDrawable *drawable)
return GIMP_DRAWABLE_GET_CLASS (drawable)->get_buffer (drawable);
}
/* note: you may pass a NULL buffer to gimp_drawable_set_buffer() and
* gimp_drawable_set_buffer_full(), in order to clear the drawable's current
* buffer, however, push_undo must be FALSE in that case, and you may only use
* the drawable in a very limited way while it has no buffer.
*/
void
gimp_drawable_set_buffer (GimpDrawable *drawable,
gboolean push_undo,
......@@ -1154,8 +1135,7 @@ gimp_drawable_set_buffer (GimpDrawable *drawable,
gint offset_x, offset_y;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (buffer == NULL || GEGL_IS_BUFFER (buffer));
g_return_if_fail (buffer != NULL || ! push_undo);
g_return_if_fail (GEGL_IS_BUFFER (buffer));
if (! gimp_item_is_attached (GIMP_ITEM (drawable)))
push_undo = FALSE;
......@@ -1175,27 +1155,18 @@ gimp_drawable_set_buffer_full (GimpDrawable *drawable,
gint offset_y)
{
GimpItem *item;
gint width = 0;
gint height = 0;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (buffer == NULL || GEGL_IS_BUFFER (buffer));
g_return_if_fail (buffer != NULL || ! push_undo);
g_return_if_fail (GEGL_IS_BUFFER (buffer));
item = GIMP_ITEM (drawable);
if (! gimp_item_is_attached (GIMP_ITEM (drawable)))
push_undo = FALSE;
if (buffer)
{
width = gegl_buffer_get_width (buffer);
height = gegl_buffer_get_height (buffer);
}
if (gimp_item_get_width (item) != width ||
gimp_item_get_height (item) != height ||
gimp_item_get_offset_x (item) != offset_x ||
if (gimp_item_get_width (item) != gegl_buffer_get_width (buffer) ||
gimp_item_get_height (item) != gegl_buffer_get_height (buffer) ||
gimp_item_get_offset_x (item) != offset_x ||
gimp_item_get_offset_y (item) != offset_y)
{
gimp_drawable_update (drawable, 0, 0, -1, -1);
......@@ -1210,8 +1181,7 @@ gimp_drawable_set_buffer_full (GimpDrawable *drawable,
g_object_thaw_notify (G_OBJECT (drawable));
if (buffer)
gimp_drawable_update (drawable, 0, 0, -1, -1);
gimp_drawable_update (drawable, 0, 0, -1, -1);
}
void
......@@ -1219,20 +1189,25 @@ gimp_drawable_steal_buffer (GimpDrawable *drawable,
GimpDrawable *src_drawable)
{
GeglBuffer *buffer;
GeglBuffer *replacement_buffer;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (GIMP_IS_DRAWABLE (src_drawable));
buffer = gimp_drawable_get_buffer (src_drawable);
if (buffer)
g_object_ref (buffer);
g_return_if_fail (buffer != NULL);
g_object_ref (buffer);
gimp_drawable_set_buffer (src_drawable, FALSE, NULL, NULL);
replacement_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, 1, 1),
gegl_buffer_get_format (buffer));
gimp_drawable_set_buffer (src_drawable, FALSE, NULL, replacement_buffer);
gimp_drawable_set_buffer (drawable, FALSE, NULL, buffer);
if (buffer)
g_object_unref (buffer);
g_object_unref (replacement_buffer);
g_object_unref (buffer);
}
GeglNode *
......
......@@ -1395,11 +1395,9 @@ gimp_layer_set_buffer (GimpDrawable *drawable,
buffer,
offset_x, offset_y);
if (buffer && gimp_filter_peek_node (GIMP_FILTER (drawable)))
if (gimp_filter_peek_node (GIMP_FILTER (drawable)))
{
gboolean new_linear = gimp_drawable_get_linear (drawable);
if (new_linear != old_linear)
if (gimp_drawable_get_linear (drawable) != old_linear)
gimp_layer_update_mode_node (GIMP_LAYER (drawable));
}
}
......
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