PIKApp/app/pdb/image-transform-cmds.c

453 lines
20 KiB
C

/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* NOTE: This file is auto-generated by pdbgen.pl. */
#include "config.h"
#include "stamp-pdbgen.h"
#include <gegl.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "libpikabase/pikabase.h"
#include "pdb-types.h"
#include "core/pikaimage-crop.h"
#include "core/pikaimage-flip.h"
#include "core/pikaimage-resize.h"
#include "core/pikaimage-rotate.h"
#include "core/pikaimage-scale.h"
#include "core/pikaimage.h"
#include "core/pikaparamspecs.h"
#include "core/pikaprogress.h"
#include "pikapdb.h"
#include "pikapdbcontext.h"
#include "pikaprocedure.h"
#include "internal-procs.h"
#include "pika-intl.h"
static PikaValueArray *
image_resize_invoker (PikaProcedure *procedure,
Pika *pika,
PikaContext *context,
PikaProgress *progress,
const PikaValueArray *args,
GError **error)
{
gboolean success = TRUE;
PikaImage *image;
gint new_width;
gint new_height;
gint offx;
gint offy;
image = g_value_get_object (pika_value_array_index (args, 0));
new_width = g_value_get_int (pika_value_array_index (args, 1));
new_height = g_value_get_int (pika_value_array_index (args, 2));
offx = g_value_get_int (pika_value_array_index (args, 3));
offy = g_value_get_int (pika_value_array_index (args, 4));
if (success)
{
pika_image_resize (image, context,
new_width, new_height, offx, offy, NULL);
}
return pika_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static PikaValueArray *
image_resize_to_layers_invoker (PikaProcedure *procedure,
Pika *pika,
PikaContext *context,
PikaProgress *progress,
const PikaValueArray *args,
GError **error)
{
gboolean success = TRUE;
PikaImage *image;
image = g_value_get_object (pika_value_array_index (args, 0));
if (success)
{
pika_image_resize_to_layers (image, context, NULL, NULL, NULL, NULL, NULL);
}
return pika_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static PikaValueArray *
image_scale_invoker (PikaProcedure *procedure,
Pika *pika,
PikaContext *context,
PikaProgress *progress,
const PikaValueArray *args,
GError **error)
{
gboolean success = TRUE;
PikaImage *image;
gint new_width;
gint new_height;
image = g_value_get_object (pika_value_array_index (args, 0));
new_width = g_value_get_int (pika_value_array_index (args, 1));
new_height = g_value_get_int (pika_value_array_index (args, 2));
if (success)
{
PikaPDBContext *pdb_context = PIKA_PDB_CONTEXT (context);
if (progress)
pika_progress_start (progress, FALSE, _("Scaling"));
pika_image_scale (image, new_width, new_height,
pdb_context->interpolation,
progress);
if (progress)
pika_progress_end (progress);
}
return pika_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static PikaValueArray *
image_crop_invoker (PikaProcedure *procedure,
Pika *pika,
PikaContext *context,
PikaProgress *progress,
const PikaValueArray *args,
GError **error)
{
gboolean success = TRUE;
PikaImage *image;
gint new_width;
gint new_height;
gint offx;
gint offy;
image = g_value_get_object (pika_value_array_index (args, 0));
new_width = g_value_get_int (pika_value_array_index (args, 1));
new_height = g_value_get_int (pika_value_array_index (args, 2));
offx = g_value_get_int (pika_value_array_index (args, 3));
offy = g_value_get_int (pika_value_array_index (args, 4));
if (success)
{
if (new_width > pika_image_get_width (image) ||
new_height > pika_image_get_height (image) ||
offx > (pika_image_get_width (image) - new_width) ||
offy > (pika_image_get_height (image) - new_height))
success = FALSE;
else
pika_image_crop (image, context, PIKA_FILL_TRANSPARENT,
offx, offy, new_width, new_height,
TRUE);
}
return pika_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static PikaValueArray *
image_flip_invoker (PikaProcedure *procedure,
Pika *pika,
PikaContext *context,
PikaProgress *progress,
const PikaValueArray *args,
GError **error)
{
gboolean success = TRUE;
PikaImage *image;
gint flip_type;
image = g_value_get_object (pika_value_array_index (args, 0));
flip_type = g_value_get_enum (pika_value_array_index (args, 1));
if (success)
{
pika_image_flip (image, context, flip_type, NULL);
}
return pika_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static PikaValueArray *
image_rotate_invoker (PikaProcedure *procedure,
Pika *pika,
PikaContext *context,
PikaProgress *progress,
const PikaValueArray *args,
GError **error)
{
gboolean success = TRUE;
PikaImage *image;
gint rotate_type;
image = g_value_get_object (pika_value_array_index (args, 0));
rotate_type = g_value_get_enum (pika_value_array_index (args, 1));
if (success)
{
if (progress)
pika_progress_start (progress, FALSE, _("Rotating"));
pika_image_rotate (image, context, rotate_type, progress);
if (progress)
pika_progress_end (progress);
}
return pika_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
void
register_image_transform_procs (PikaPDB *pdb)
{
PikaProcedure *procedure;
/*
* pika-image-resize
*/
procedure = pika_procedure_new (image_resize_invoker);
pika_object_set_static_name (PIKA_OBJECT (procedure),
"pika-image-resize");
pika_procedure_set_static_help (procedure,
"Resize the image to the specified extents.",
"This procedure resizes the image so that it's new width and height are equal to the supplied parameters. Offsets are also provided which describe the position of the previous image's content. All channels within the image are resized according to the specified parameters; this includes the image selection mask. All layers within the image are repositioned according to the specified offsets.",
NULL);
pika_procedure_set_static_attribution (procedure,
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996");
pika_procedure_add_argument (procedure,
pika_param_spec_image ("image",
"image",
"The image",
FALSE,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_int ("new-width",
"new width",
"New image width",
1, PIKA_MAX_IMAGE_SIZE, 1,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_int ("new-height",
"new height",
"New image height",
1, PIKA_MAX_IMAGE_SIZE, 1,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_int ("offx",
"offx",
"x offset between upper left corner of old and new images: (new - old)",
G_MININT32, G_MAXINT32, 0,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_int ("offy",
"offy",
"y offset between upper left corner of old and new images: (new - old)",
G_MININT32, G_MAXINT32, 0,
PIKA_PARAM_READWRITE));
pika_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* pika-image-resize-to-layers
*/
procedure = pika_procedure_new (image_resize_to_layers_invoker);
pika_object_set_static_name (PIKA_OBJECT (procedure),
"pika-image-resize-to-layers");
pika_procedure_set_static_help (procedure,
"Resize the image to fit all layers.",
"This procedure resizes the image to the bounding box of all layers of the image. All channels within the image are resized to the new size; this includes the image selection mask. All layers within the image are repositioned to the new image area.",
NULL);
pika_procedure_set_static_attribution (procedure,
"Simon Budig",
"Simon Budig",
"2004");
pika_procedure_add_argument (procedure,
pika_param_spec_image ("image",
"image",
"The image",
FALSE,
PIKA_PARAM_READWRITE));
pika_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* pika-image-scale
*/
procedure = pika_procedure_new (image_scale_invoker);
pika_object_set_static_name (PIKA_OBJECT (procedure),
"pika-image-scale");
pika_procedure_set_static_help (procedure,
"Scale the image using the default interpolation method.",
"This procedure scales the image so that its new width and height are equal to the supplied parameters. All layers and channels within the image are scaled according to the specified parameters; this includes the image selection mask. The interpolation method used can be set with 'pika-context-set-interpolation'.",
NULL);
pika_procedure_set_static_attribution (procedure,
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996");
pika_procedure_add_argument (procedure,
pika_param_spec_image ("image",
"image",
"The image",
FALSE,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_int ("new-width",
"new width",
"New image width",
1, PIKA_MAX_IMAGE_SIZE, 1,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_int ("new-height",
"new height",
"New image height",
1, PIKA_MAX_IMAGE_SIZE, 1,
PIKA_PARAM_READWRITE));
pika_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* pika-image-crop
*/
procedure = pika_procedure_new (image_crop_invoker);
pika_object_set_static_name (PIKA_OBJECT (procedure),
"pika-image-crop");
pika_procedure_set_static_help (procedure,
"Crop the image to the specified extents.",
"This procedure crops the image so that it's new width and height are equal to the supplied parameters. Offsets are also provided which describe the position of the previous image's content. All channels and layers within the image are cropped to the new image extents; this includes the image selection mask. If any parameters are out of range, an error is returned.",
NULL);
pika_procedure_set_static_attribution (procedure,
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996");
pika_procedure_add_argument (procedure,
pika_param_spec_image ("image",
"image",
"The image",
FALSE,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_int ("new-width",
"new width",
"New image width: (0 < new_width <= width)",
1, PIKA_MAX_IMAGE_SIZE, 1,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_int ("new-height",
"new height",
"New image height: (0 < new_height <= height)",
1, PIKA_MAX_IMAGE_SIZE, 1,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_int ("offx",
"offx",
"X offset: (0 <= offx <= (width - new_width))",
0, G_MAXINT32, 0,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_int ("offy",
"offy",
"Y offset: (0 <= offy <= (height - new_height))",
0, G_MAXINT32, 0,
PIKA_PARAM_READWRITE));
pika_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* pika-image-flip
*/
procedure = pika_procedure_new (image_flip_invoker);
pika_object_set_static_name (PIKA_OBJECT (procedure),
"pika-image-flip");
pika_procedure_set_static_help (procedure,
"Flips the image horizontally or vertically.",
"This procedure flips (mirrors) the image.",
NULL);
pika_procedure_set_static_attribution (procedure,
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996");
pika_procedure_add_argument (procedure,
pika_param_spec_image ("image",
"image",
"The image",
FALSE,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
pika_param_spec_enum ("flip-type",
"flip type",
"Type of flip",
PIKA_TYPE_ORIENTATION_TYPE,
PIKA_ORIENTATION_HORIZONTAL,
PIKA_PARAM_READWRITE));
pika_param_spec_enum_exclude_value (PIKA_PARAM_SPEC_ENUM (procedure->args[1]),
PIKA_ORIENTATION_UNKNOWN);
pika_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* pika-image-rotate
*/
procedure = pika_procedure_new (image_rotate_invoker);
pika_object_set_static_name (PIKA_OBJECT (procedure),
"pika-image-rotate");
pika_procedure_set_static_help (procedure,
"Rotates the image by the specified degrees.",
"This procedure rotates the image.",
NULL);
pika_procedure_set_static_attribution (procedure,
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2003");
pika_procedure_add_argument (procedure,
pika_param_spec_image ("image",
"image",
"The image",
FALSE,
PIKA_PARAM_READWRITE));
pika_procedure_add_argument (procedure,
g_param_spec_enum ("rotate-type",
"rotate type",
"Angle of rotation",
PIKA_TYPE_ROTATION_TYPE,
PIKA_ROTATE_90,
PIKA_PARAM_READWRITE));
pika_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
}