mirror of https://github.com/GNOME/gimp.git
app: remove drawable->private->format, its buffer has a format already
Also, make group layer type conversion much less hackish by using the same kind of temporary states that are used for reallocating its projection on size change.
This commit is contained in:
parent
49de3d5292
commit
87b7af7fa5
|
@ -20,8 +20,6 @@
|
|||
|
||||
struct _GimpDrawablePrivate
|
||||
{
|
||||
const Babl *format; /* format of drawable */
|
||||
|
||||
GeglBuffer *buffer; /* buffer for drawable data */
|
||||
GeglBuffer *shadow; /* shadow buffer */
|
||||
|
||||
|
|
|
@ -409,9 +409,6 @@ gimp_drawable_duplicate (GimpItem *item,
|
|||
{
|
||||
GimpDrawable *drawable = GIMP_DRAWABLE (item);
|
||||
GimpDrawable *new_drawable = GIMP_DRAWABLE (new_item);
|
||||
const Babl *format = gimp_drawable_get_format (drawable);
|
||||
|
||||
new_drawable->private->format = format;
|
||||
|
||||
if (new_drawable->private->buffer)
|
||||
g_object_unref (new_drawable->private->buffer);
|
||||
|
@ -797,7 +794,6 @@ gimp_drawable_real_set_buffer (GimpDrawable *drawable,
|
|||
if (drawable->private->buffer)
|
||||
g_object_unref (drawable->private->buffer);
|
||||
|
||||
drawable->private->format = gegl_buffer_get_format (buffer);
|
||||
drawable->private->buffer = buffer;
|
||||
|
||||
gimp_item_set_offset (item, offset_x, offset_y);
|
||||
|
@ -1131,7 +1127,6 @@ gimp_drawable_new (GType type,
|
|||
offset_x, offset_y,
|
||||
width, height));
|
||||
|
||||
drawable->private->format = format;
|
||||
drawable->private->buffer = gimp_gegl_buffer_new (GIMP_GEGL_RECT (0, 0,
|
||||
width, height),
|
||||
format);
|
||||
|
@ -1649,7 +1644,7 @@ gimp_drawable_get_format (const GimpDrawable *drawable)
|
|||
{
|
||||
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
||||
|
||||
return drawable->private->format;
|
||||
return gegl_buffer_get_format (drawable->private->buffer);
|
||||
}
|
||||
|
||||
const Babl *
|
||||
|
@ -1673,9 +1668,13 @@ gimp_drawable_get_format_without_alpha (const GimpDrawable *drawable)
|
|||
gboolean
|
||||
gimp_drawable_has_alpha (const GimpDrawable *drawable)
|
||||
{
|
||||
const Babl *format;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
|
||||
|
||||
return babl_format_has_alpha (drawable->private->format);
|
||||
format = gegl_buffer_get_format (drawable->private->buffer);
|
||||
|
||||
return babl_format_has_alpha (format);
|
||||
}
|
||||
|
||||
GimpImageType
|
||||
|
@ -1685,7 +1684,7 @@ gimp_drawable_type (const GimpDrawable *drawable)
|
|||
|
||||
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), -1);
|
||||
|
||||
format = drawable->private->format;
|
||||
format = gegl_buffer_get_format (drawable->private->buffer);
|
||||
|
||||
if (format == babl_format ("Y' u8"))
|
||||
return GIMP_GRAY_IMAGE;
|
||||
|
@ -1751,9 +1750,13 @@ gimp_drawable_is_indexed (const GimpDrawable *drawable)
|
|||
gint
|
||||
gimp_drawable_bytes (const GimpDrawable *drawable)
|
||||
{
|
||||
const Babl *format;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), -1);
|
||||
|
||||
return babl_format_get_bytes_per_pixel (drawable->private->format);
|
||||
format = gegl_buffer_get_format (drawable->private->buffer);
|
||||
|
||||
return babl_format_get_bytes_per_pixel (format);
|
||||
}
|
||||
|
||||
gint
|
||||
|
|
|
@ -29,14 +29,11 @@
|
|||
|
||||
#include "core-types.h"
|
||||
|
||||
#include "base/tile-manager.h"
|
||||
|
||||
#include "gegl/gimp-gegl-utils.h"
|
||||
|
||||
#include "gimpgrouplayer.h"
|
||||
#include "gimpimage.h"
|
||||
#include "gimpimage-undo-push.h"
|
||||
#include "gimpdrawable-private.h" /* eek */
|
||||
#include "gimpdrawablestack.h"
|
||||
#include "gimppickable.h"
|
||||
#include "gimpprojectable.h"
|
||||
|
@ -57,6 +54,7 @@ struct _GimpGroupLayerPrivate
|
|||
gboolean expanded;
|
||||
|
||||
/* hackish temp states to make the projection/tiles stuff work */
|
||||
const Babl *convert_format;
|
||||
gboolean reallocate_projection;
|
||||
gint reallocate_width;
|
||||
gint reallocate_height;
|
||||
|
@ -825,59 +823,11 @@ gimp_group_layer_estimate_memsize (const GimpDrawable *drawable,
|
|||
height);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_group_layer_convert_type (GimpDrawable *drawable,
|
||||
GimpImage *dest_image,
|
||||
GimpImageBaseType new_base_type,
|
||||
gboolean push_undo)
|
||||
{
|
||||
GimpGroupLayer *group = GIMP_GROUP_LAYER (drawable);
|
||||
GimpGroupLayerPrivate *private = GET_PRIVATE (drawable);
|
||||
TileManager *tiles;
|
||||
GeglBuffer *buffer;
|
||||
GimpImageType new_type;
|
||||
|
||||
if (push_undo)
|
||||
{
|
||||
GimpImage *image = gimp_item_get_image (GIMP_ITEM (group));
|
||||
|
||||
gimp_image_undo_push_group_layer_convert (image, NULL, group);
|
||||
}
|
||||
|
||||
new_type = GIMP_IMAGE_TYPE_FROM_BASE_TYPE (new_base_type);
|
||||
|
||||
if (gimp_drawable_has_alpha (drawable))
|
||||
new_type = GIMP_IMAGE_TYPE_WITH_ALPHA (new_type);
|
||||
|
||||
/* FIXME: find a better way to do this: need to set the drawable's
|
||||
* format to the new values so the projection will create its tiles
|
||||
* with the right depth
|
||||
*/
|
||||
drawable->private->format = gimp_image_get_format (gimp_item_get_image (GIMP_ITEM (drawable)),
|
||||
new_type);
|
||||
|
||||
gimp_projectable_structure_changed (GIMP_PROJECTABLE (drawable));
|
||||
|
||||
tiles = gimp_projection_get_tiles_at_level (private->projection,
|
||||
0, NULL);
|
||||
|
||||
buffer = gimp_tile_manager_create_buffer (tiles, gimp_drawable_get_format (drawable));
|
||||
|
||||
gimp_drawable_set_buffer_full (drawable,
|
||||
FALSE, NULL,
|
||||
buffer,
|
||||
gimp_item_get_offset_x (GIMP_ITEM (drawable)),
|
||||
gimp_item_get_offset_y (GIMP_ITEM (drawable)));
|
||||
|
||||
g_object_unref (buffer);
|
||||
}
|
||||
|
||||
static const Babl *
|
||||
gimp_group_layer_get_format (GimpProjectable *projectable)
|
||||
get_projection_format (GimpProjectable *projectable,
|
||||
GimpImageBaseType base_type)
|
||||
{
|
||||
GimpDrawable *drawable = GIMP_DRAWABLE (projectable);
|
||||
|
||||
switch (GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (drawable)))
|
||||
switch (base_type)
|
||||
{
|
||||
case GIMP_RGB:
|
||||
case GIMP_INDEXED:
|
||||
|
@ -892,6 +842,57 @@ gimp_group_layer_get_format (GimpProjectable *projectable)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_group_layer_convert_type (GimpDrawable *drawable,
|
||||
GimpImage *dest_image,
|
||||
GimpImageBaseType new_base_type,
|
||||
gboolean push_undo)
|
||||
{
|
||||
GimpGroupLayer *group = GIMP_GROUP_LAYER (drawable);
|
||||
GimpGroupLayerPrivate *private = GET_PRIVATE (drawable);
|
||||
GeglBuffer *buffer;
|
||||
|
||||
if (push_undo)
|
||||
{
|
||||
GimpImage *image = gimp_item_get_image (GIMP_ITEM (group));
|
||||
|
||||
gimp_image_undo_push_group_layer_convert (image, NULL, group);
|
||||
}
|
||||
|
||||
/* Need to temporarily set the projectable's format to the new
|
||||
* values so the projection will create its tiles with the right
|
||||
* depth
|
||||
*/
|
||||
private->convert_format = get_projection_format (GIMP_PROJECTABLE (drawable),
|
||||
new_base_type);
|
||||
gimp_projectable_structure_changed (GIMP_PROJECTABLE (drawable));
|
||||
|
||||
buffer = gimp_pickable_get_buffer (GIMP_PICKABLE (private->projection));
|
||||
|
||||
gimp_drawable_set_buffer_full (drawable,
|
||||
FALSE, NULL,
|
||||
buffer,
|
||||
gimp_item_get_offset_x (GIMP_ITEM (drawable)),
|
||||
gimp_item_get_offset_y (GIMP_ITEM (drawable)));
|
||||
|
||||
/* reset, the actual format is right now */
|
||||
private->convert_format = NULL;
|
||||
}
|
||||
|
||||
static const Babl *
|
||||
gimp_group_layer_get_format (GimpProjectable *projectable)
|
||||
{
|
||||
GimpGroupLayerPrivate *private = GET_PRIVATE (projectable);
|
||||
GimpImageBaseType base_type;
|
||||
|
||||
if (private->convert_format)
|
||||
return private->convert_format;
|
||||
|
||||
base_type = GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (GIMP_DRAWABLE (projectable)));
|
||||
|
||||
return get_projection_format (projectable, base_type);
|
||||
}
|
||||
|
||||
static GeglNode *
|
||||
gimp_group_layer_get_graph (GimpProjectable *projectable)
|
||||
{
|
||||
|
@ -1126,8 +1127,7 @@ gimp_group_layer_update_size (GimpGroupLayer *group)
|
|||
width != old_width ||
|
||||
height != old_height)
|
||||
{
|
||||
TileManager *tiles;
|
||||
GeglBuffer *buffer;
|
||||
GeglBuffer *buffer;
|
||||
|
||||
private->reallocate_projection = FALSE;
|
||||
|
||||
|
@ -1139,20 +1139,16 @@ gimp_group_layer_update_size (GimpGroupLayer *group)
|
|||
|
||||
gimp_projectable_structure_changed (GIMP_PROJECTABLE (group));
|
||||
|
||||
tiles = gimp_projection_get_tiles_at_level (private->projection,
|
||||
0, NULL);
|
||||
|
||||
private->reallocate_width = 0;
|
||||
private->reallocate_height = 0;
|
||||
|
||||
buffer = gimp_tile_manager_create_buffer (tiles, gimp_drawable_get_format (GIMP_DRAWABLE (group)));
|
||||
buffer = gimp_pickable_get_buffer (GIMP_PICKABLE (private->projection));
|
||||
|
||||
gimp_drawable_set_buffer_full (GIMP_DRAWABLE (group),
|
||||
FALSE, NULL,
|
||||
buffer,
|
||||
x, y);
|
||||
|
||||
g_object_unref (buffer);
|
||||
/* reset, the actual size is correct now */
|
||||
private->reallocate_width = 0;
|
||||
private->reallocate_height = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1004,6 +1004,12 @@ gimp_image_convert (GimpImage *image,
|
|||
else
|
||||
new_format = gimp_image_get_format (image, GIMP_INDEXED_IMAGE);
|
||||
|
||||
g_printerr ("old: %s %d new: %s %d\n",
|
||||
babl_get_name (gimp_drawable_get_format (GIMP_DRAWABLE (layer))),
|
||||
babl_format_has_alpha (gimp_drawable_get_format (GIMP_DRAWABLE (layer))),
|
||||
babl_get_name (new_format),
|
||||
babl_format_has_alpha (new_format));
|
||||
|
||||
new_buffer =
|
||||
gimp_gegl_buffer_new (GIMP_GEGL_RECT (0, 0,
|
||||
gimp_item_get_width (GIMP_ITEM (layer)),
|
||||
|
|
|
@ -194,7 +194,6 @@ gimp_text_layer_from_layer (GimpLayer *layer,
|
|||
|
||||
drawable = GIMP_DRAWABLE (text_layer);
|
||||
|
||||
drawable->private->format = gimp_drawable_get_format (GIMP_DRAWABLE (layer));
|
||||
drawable->private->buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
|
||||
GIMP_DRAWABLE (layer)->private->buffer = NULL;
|
||||
|
||||
|
|
|
@ -865,9 +865,6 @@ xcf_load_layer_props (XcfInfo *info,
|
|||
gimp_object_set_name (GIMP_OBJECT (group),
|
||||
gimp_object_get_name (*layer));
|
||||
|
||||
GIMP_DRAWABLE (group)->private->format =
|
||||
gimp_drawable_get_format (GIMP_DRAWABLE (*layer));
|
||||
|
||||
g_object_ref_sink (*layer);
|
||||
g_object_unref (*layer);
|
||||
*layer = group;
|
||||
|
|
Loading…
Reference in New Issue