Commit 6c44e51b authored by Ell's avatar Ell

libgimp: add GIMP_EXPORT_NEEDS_CROP export capability

Add a new GIMP_EXPORT_NEEDS_CROP export capability, which causes
gimp_export_image() to crop the exported image content to the image
bounds; this is useful for formats that support layers, but have no
concept of global image bounds, hence cropping is the only way to
enforce the image bounds.

When showing the export dialog, give an option to either crop the
layers to the image bounds, or to resize the image to fit the
layers.
parent 00d1a21b
......@@ -261,6 +261,23 @@ export_add_alpha (gint32 image_ID,
g_free (layers);
}
static void
export_crop_image (gint32 image_ID,
gint32 *drawable_ID)
{
gimp_image_crop (image_ID,
gimp_image_width (image_ID),
gimp_image_height (image_ID),
0, 0);
}
static void
export_resize_image (gint32 image_ID,
gint32 *drawable_ID)
{
gimp_image_resize_to_layers (image_ID);
}
static void
export_void (gint32 image_ID,
gint32 *drawable_ID)
......@@ -420,6 +437,15 @@ static ExportAction export_action_add_alpha =
0
};
static ExportAction export_action_crop_or_resize =
{
export_crop_image,
export_resize_image,
N_("%s plug-in needs to crop the layers to the image bounds"),
{ N_("Crop Layers"), N_("Resize Image to Layers")},
0
};
static ExportFunc
export_action_get_func (const ExportAction *action)
......@@ -846,6 +872,42 @@ gimp_export_image (gint32 *image_ID,
children = gimp_item_get_children (layers[0], &n_children);
if ((capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS) &&
(capabilities & GIMP_EXPORT_NEEDS_CROP))
{
GeglRectangle image_bounds;
gboolean needs_crop = FALSE;
image_bounds.x = 0;
image_bounds.y = 0;
image_bounds.width = gimp_image_width (*image_ID);
image_bounds.height = gimp_image_height (*image_ID);
for (i = 0; i < n_layers; i++)
{
GeglRectangle layer_bounds;
gimp_drawable_offsets (layers[i],
&layer_bounds.x, &layer_bounds.y);
layer_bounds.width = gimp_drawable_width (layers[i]);
layer_bounds.height = gimp_drawable_height (layers[i]);
if (! gegl_rectangle_contains (&image_bounds, &layer_bounds))
{
needs_crop = TRUE;
break;
}
}
if (needs_crop)
{
actions = g_slist_prepend (actions,
&export_action_crop_or_resize);
}
}
/* check if layer size != canvas size, opacity != 100%, or offsets != 0 */
if (n_layers == 1 &&
! children &&
......
......@@ -42,6 +42,7 @@ G_BEGIN_DECLS
* @GIMP_EXPORT_CAN_HANDLE_LAYERS_AS_ANIMATION: Handles aminations of layers
* @GIMP_EXPORT_CAN_HANDLE_LAYER_MASKS: Handles layer masks
* @GIMP_EXPORT_NEEDS_ALPHA: Needs alpha channels
* @GIMP_EXPORT_NEEDS_CROP: Needs to crop content to image bounds
*
* The types of images and layers an export procedure can handle
**/
......@@ -55,7 +56,8 @@ typedef enum
GIMP_EXPORT_CAN_HANDLE_LAYERS = 1 << 5,
GIMP_EXPORT_CAN_HANDLE_LAYERS_AS_ANIMATION = 1 << 6,
GIMP_EXPORT_CAN_HANDLE_LAYER_MASKS = 1 << 7,
GIMP_EXPORT_NEEDS_ALPHA = 1 << 8
GIMP_EXPORT_NEEDS_ALPHA = 1 << 8,
GIMP_EXPORT_NEEDS_CROP = 1 << 9
} GimpExportCapabilities;
......
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