Commit 58dfa962 authored by Michael Natterer's avatar Michael Natterer 😴

app: port simple rotating and flipping to GEGL

Which requires making the entire copy/paste apparatus aware of the
Babl format of the passed around tile managers.
parent 2c62644f
......@@ -581,6 +581,7 @@ gimp_edit_extract (GimpImage *image,
GError **error)
{
TileManager *tiles;
const Babl *format;
gint offset_x;
gint offset_y;
......@@ -591,7 +592,7 @@ gimp_edit_extract (GimpImage *image,
tiles = gimp_selection_extract (GIMP_SELECTION (gimp_image_get_mask (image)),
pickable, context,
cut_pixels, FALSE, FALSE,
&offset_x, &offset_y, error);
&format, &offset_x, &offset_y, error);
if (cut_pixels)
gimp_image_undo_group_end (image);
......@@ -601,7 +602,7 @@ gimp_edit_extract (GimpImage *image,
GeglBuffer *temp;
GimpBuffer *buffer;
temp = gimp_tile_manager_create_buffer (tiles, NULL, TRUE);
temp = gimp_tile_manager_create_buffer (tiles, format, TRUE);
tile_manager_unref (tiles);
buffer = gimp_buffer_new (temp, _("Global Buffer"),
......
This diff is collapsed.
......@@ -22,6 +22,7 @@
TileManager * gimp_drawable_transform_tiles_affine (GimpDrawable *drawable,
GimpContext *context,
TileManager *orig_tiles,
const Babl *orig_format,
gint orig_offset_x,
gint orig_offset_y,
const GimpMatrix3 *matrix,
......@@ -35,6 +36,7 @@ TileManager * gimp_drawable_transform_tiles_affine (GimpDrawable *dra
TileManager * gimp_drawable_transform_tiles_flip (GimpDrawable *drawable,
GimpContext *context,
TileManager *orig_tiles,
const Babl *orig_format,
gint orig_offset_x,
gint orig_offset_y,
GimpOrientationType flip_type,
......@@ -46,6 +48,7 @@ TileManager * gimp_drawable_transform_tiles_flip (GimpDrawable *dra
TileManager * gimp_drawable_transform_tiles_rotate (GimpDrawable *drawable,
GimpContext *context,
TileManager *orig_tiles,
const Babl *orig_format,
gint orig_offset_x,
gint orig_offset_y,
GimpRotationType rotate_type,
......@@ -79,11 +82,13 @@ GimpDrawable * gimp_drawable_transform_rotate (GimpDrawable *dra
TileManager * gimp_drawable_transform_cut (GimpDrawable *drawable,
GimpContext *context,
const Babl **format,
gint *offset_x,
gint *offset_y,
gboolean *new_layer);
GimpDrawable * gimp_drawable_transform_paste (GimpDrawable *drawable,
TileManager *tiles,
const Babl *format,
gint offset_x,
gint offset_y,
gboolean new_layer);
......
......@@ -651,6 +651,7 @@ gimp_drawable_flip (GimpItem *item,
tiles = gimp_drawable_transform_tiles_flip (drawable, context,
gimp_drawable_get_tiles (drawable),
gimp_drawable_get_format (drawable),
off_x, off_y,
flip_type, axis,
clip_result,
......@@ -659,6 +660,7 @@ gimp_drawable_flip (GimpItem *item,
if (tiles)
{
gimp_drawable_transform_paste (drawable, tiles,
gimp_drawable_get_format (drawable),
new_off_x, new_off_y, FALSE);
tile_manager_unref (tiles);
}
......@@ -681,6 +683,7 @@ gimp_drawable_rotate (GimpItem *item,
tiles = gimp_drawable_transform_tiles_rotate (drawable, context,
gimp_drawable_get_tiles (drawable),
gimp_drawable_get_format (drawable),
off_x, off_y,
rotate_type, center_x, center_y,
clip_result,
......@@ -689,6 +692,7 @@ gimp_drawable_rotate (GimpItem *item,
if (tiles)
{
gimp_drawable_transform_paste (drawable, tiles,
gimp_drawable_get_format (drawable),
new_off_x, new_off_y, FALSE);
tile_manager_unref (tiles);
}
......@@ -713,6 +717,7 @@ gimp_drawable_transform (GimpItem *item,
tiles = gimp_drawable_transform_tiles_affine (drawable, context,
gimp_drawable_get_tiles (drawable),
gimp_drawable_get_format (drawable),
off_x, off_y,
matrix, direction,
interpolation_type,
......@@ -724,6 +729,7 @@ gimp_drawable_transform (GimpItem *item,
if (tiles)
{
gimp_drawable_transform_paste (drawable, tiles,
gimp_drawable_get_format (drawable),
new_off_x, new_off_y, FALSE);
tile_manager_unref (tiles);
}
......
......@@ -1138,6 +1138,7 @@ gimp_layer_new_from_buffer (GeglBuffer *buffer,
/**
* gimp_layer_new_from_tiles:
* @tiles: The buffer to make the new layer from.
* @format: The tiles' pixel format
* @dest_image: The image the new layer will be added to.
* @type: The #GimpImageType of the new layer.
* @name: The new layer's name.
......@@ -1152,6 +1153,7 @@ gimp_layer_new_from_buffer (GeglBuffer *buffer,
**/
GimpLayer *
gimp_layer_new_from_tiles (TileManager *tiles,
const Babl *format,
GimpImage *dest_image,
GimpImageType type,
const gchar *name,
......@@ -1162,9 +1164,10 @@ gimp_layer_new_from_tiles (TileManager *tiles,
GimpLayer *layer;
g_return_val_if_fail (tiles != NULL, NULL);
g_return_val_if_fail (format != NULL, NULL);
g_return_val_if_fail (GIMP_IS_IMAGE (dest_image), NULL);
buffer = gimp_tile_manager_create_buffer (tiles, NULL, FALSE);
buffer = gimp_tile_manager_create_buffer (tiles, format, FALSE);
layer = gimp_layer_new_from_buffer (buffer, dest_image, type,
name, opacity, mode);
......
......@@ -90,6 +90,7 @@ GimpLayer * gimp_layer_new_from_buffer (GeglBuffer *buffer,
gdouble opacity,
GimpLayerModeEffects mode);
GimpLayer * gimp_layer_new_from_tiles (TileManager *tiles,
const Babl *format,
GimpImage *dest_image,
GimpImageType type,
const gchar *name,
......
......@@ -620,6 +620,7 @@ gimp_selection_extract (GimpSelection *selection,
gboolean cut_image,
gboolean keep_indexed,
gboolean add_alpha,
const Babl **format,
gint *offset_x,
gint *offset_y,
GError **error)
......@@ -640,6 +641,7 @@ gimp_selection_extract (GimpSelection *selection,
if (GIMP_IS_ITEM (pickable))
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (pickable)), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (format != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
image = gimp_pickable_get_image (pickable);
......@@ -675,25 +677,41 @@ gimp_selection_extract (GimpSelection *selection,
switch (GIMP_IMAGE_TYPE_BASE_TYPE (gimp_pickable_get_image_type (pickable)))
{
case GIMP_RGB:
bytes = add_alpha ? 4 : gimp_pickable_get_bytes (pickable);
if (add_alpha)
*format = gimp_pickable_get_format_with_alpha (pickable);
else
*format = gimp_pickable_get_format (pickable);
base_type = GIMP_RGB;
break;
case GIMP_GRAY:
bytes = add_alpha ? 2 : gimp_pickable_get_bytes (pickable);
if (add_alpha)
*format = gimp_pickable_get_format_with_alpha (pickable);
else
*format = gimp_pickable_get_format (pickable);
base_type = GIMP_GRAY;
break;
case GIMP_INDEXED:
if (keep_indexed)
{
bytes = add_alpha ? 2 : gimp_pickable_get_bytes (pickable);
if (add_alpha)
*format = gimp_pickable_get_format_with_alpha (pickable);
else
*format = gimp_pickable_get_format (pickable);
base_type = GIMP_GRAY;
}
else
{
bytes = (add_alpha ||
GIMP_IMAGE_TYPE_HAS_ALPHA (gimp_pickable_get_image_type (pickable))) ? 4 : 3;
if (add_alpha ||
GIMP_IMAGE_TYPE_HAS_ALPHA (gimp_pickable_get_image_type (pickable)))
*format = babl_format ("RGBA u8");
else
*format = babl_format ("RGB u8");
base_type = GIMP_INDEXED;
}
break;
......@@ -703,6 +721,8 @@ gimp_selection_extract (GimpSelection *selection,
break;
}
bytes = babl_format_get_bytes_per_pixel (*format);
gimp_image_get_background (image, context,
gimp_pickable_get_image_type (pickable),
bg_color);
......@@ -821,6 +841,7 @@ gimp_selection_float (GimpSelection *selection,
GimpImage *image;
GimpLayer *layer;
TileManager *tiles;
const Babl *format;
gint x1, y1;
gint x2, y2;
......@@ -848,7 +869,8 @@ gimp_selection_float (GimpSelection *selection,
/* Cut or copy the selected region */
tiles = gimp_selection_extract (selection, GIMP_PICKABLE (drawable), context,
cut_image, FALSE, TRUE, &x1, &y1, NULL);
cut_image, FALSE, TRUE,
&format, &x1, &y1, NULL);
/* Clear the selection */
gimp_channel_clear (GIMP_CHANNEL (selection), NULL, TRUE);
......@@ -857,7 +879,7 @@ gimp_selection_float (GimpSelection *selection,
* because it may be different from the image's type if we cut from
* a channel or layer mask
*/
layer = gimp_layer_new_from_tiles (tiles,
layer = gimp_layer_new_from_tiles (tiles, format,
image,
gimp_drawable_type_with_alpha (drawable),
_("Floated Layer"),
......
......@@ -64,6 +64,7 @@ TileManager * gimp_selection_extract (GimpSelection *selection,
gboolean cut_image,
gboolean keep_indexed,
gboolean add_alpha,
const Babl **format,
gint *offset_x,
gint *offset_y,
GError **error);
......
......@@ -61,6 +61,7 @@ static gchar * gimp_flip_tool_get_undo_desc (GimpTransformTool *tool);
static TileManager * gimp_flip_tool_transform (GimpTransformTool *tool,
GimpItem *item,
TileManager *orig_tiles,
const Babl *orig_format,
gint orig_offset_x,
gint orig_offset_y,
gint *new_offset_x,
......@@ -201,6 +202,7 @@ static TileManager *
gimp_flip_tool_transform (GimpTransformTool *trans_tool,
GimpItem *active_item,
TileManager *orig_tiles,
const Babl *orig_format,
gint orig_offset_x,
gint orig_offset_y,
gint *new_offset_x,
......@@ -240,6 +242,7 @@ gimp_flip_tool_transform (GimpTransformTool *trans_tool,
ret = gimp_drawable_transform_tiles_flip (GIMP_DRAWABLE (active_item),
context,
orig_tiles,
orig_format,
orig_offset_x,
orig_offset_y,
options->flip_type, axis,
......
......@@ -17,6 +17,7 @@
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
......
......@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <string.h>
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpmath/gimpmath.h"
......
......@@ -17,6 +17,7 @@
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpconfig/gimpconfig.h"
......
......@@ -126,6 +126,7 @@ static TileManager *
gimp_transform_tool_real_transform (GimpTransformTool *tr_tool,
GimpItem *item,
TileManager *orig_tiles,
const Babl *orig_format,
gint orig_offset_x,
gint orig_offset_y,
gint *new_offset_x,
......@@ -963,6 +964,7 @@ static TileManager *
gimp_transform_tool_real_transform (GimpTransformTool *tr_tool,
GimpItem *active_item,
TileManager *orig_tiles,
const Babl *orig_format,
gint orig_offset_x,
gint orig_offset_y,
gint *new_offset_x,
......@@ -1003,6 +1005,7 @@ gimp_transform_tool_real_transform (GimpTransformTool *tr_tool,
ret = gimp_drawable_transform_tiles_affine (GIMP_DRAWABLE (active_item),
context,
orig_tiles,
orig_format,
orig_offset_x,
orig_offset_y,
&tr_tool->transform,
......@@ -1048,6 +1051,7 @@ gimp_transform_tool_transform (GimpTransformTool *tr_tool,
GimpImage *image = gimp_display_get_image (display);
GimpItem *active_item = NULL;
TileManager *orig_tiles = NULL;
const Babl *orig_format = NULL;
gint orig_offset_x;
gint orig_offset_y;
TileManager *new_tiles;
......@@ -1117,6 +1121,7 @@ gimp_transform_tool_transform (GimpTransformTool *tr_tool,
{
orig_tiles = gimp_drawable_transform_cut (tool->drawable,
context,
&orig_format,
&orig_offset_x,
&orig_offset_y,
&new_layer);
......@@ -1138,6 +1143,7 @@ gimp_transform_tool_transform (GimpTransformTool *tr_tool,
new_tiles = GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->transform (tr_tool,
active_item,
orig_tiles,
orig_format,
orig_offset_x,
orig_offset_y,
&new_offset_x,
......@@ -1155,7 +1161,7 @@ gimp_transform_tool_transform (GimpTransformTool *tr_tool,
* undo...
*/
gimp_drawable_transform_paste (tool->drawable,
new_tiles,
new_tiles, orig_format,
new_offset_x, new_offset_y,
new_layer);
tile_manager_unref (new_tiles);
......
......@@ -108,6 +108,7 @@ struct _GimpTransformToolClass
TileManager * (* transform) (GimpTransformTool *tool,
GimpItem *item,
TileManager *orig_tiles,
const Babl *orig_format,
gint orig_offset_x,
gint orig_offset_y,
gint *new_offset_x,
......
......@@ -17,6 +17,7 @@
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "tools-types.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