gimp/plug-ins/common/rotate.c

544 lines
15 KiB
C
Raw Normal View History

/* GIMP - The GNU Image Manipulation Program
1997-11-25 06:05:25 +08:00
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* Rotate plug-in v1.0
* Copyright 1997-2000 by Sven Neumann <sven@gimp.org>
* & Adam D. Moss <adam@gimp.org>
*
1997-11-25 06:05:25 +08:00
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1997-11-25 06:05:25 +08:00
*/
/* Revision history
* (09/28/97) v0.1 first development release
1997-11-25 06:05:25 +08:00
* (09/29/97) v0.2 nicer dialog,
* changed the menu-location to Filters/Transforms
* (10/01/97) v0.3 now handles layered images and undo
* (10/13/97) v0.3a small bugfix, no real changes
* (10/17/97) v0.4 now handles selections
* (01/09/98) v0.5 a few fixes to support portability
* (01/15/98) v0.6 fixed a line that caused rotate to crash on some
* systems
* (05/28/98) v0.7 use the new gimp_message function for error output
1999-10-14 07:07:45 +08:00
* (10/09/99) v0.8 rotate guides too
* (11/13/99) v0.9 merge rotators and rotate plug-ins
* -> drop the dialog, register directly into menus instead
* (06/18/00) v1.0 speed up 180<EFBFBD> rotations,
* declare version 1.0 for gimp-1.2 release
1997-11-25 06:05:25 +08:00
*/
/* TODO List
* - handle channels and masks
* - rewrite the main function to make it work on tiles rather than
* process the image row by row. This should result in a significant
* speedup (thanks to quartic for this suggestion).
* - do something magical so that only one rotate can be occuring at a time!
*/
1997-11-25 06:05:25 +08:00
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <libgimp/gimp.h>
#include "libgimp/stdplugins-intl.h"
1997-11-25 06:05:25 +08:00
1997-11-25 06:05:25 +08:00
/* Defines */
#define PLUG_IN_PROC "plug-in-rotate"
#define PLUG_IN_VERSION "v1.0 (2000/06/18)"
1997-11-25 06:05:25 +08:00
#define PLUG_IN_IMAGE_TYPES "RGB*, INDEXED*, GRAY*"
#define PLUG_IN_AUTHOR "Sven Neumann <sven@gimp.org>, Adam D. Moss <adam@gimp.org>"
#define PLUG_IN_COPYRIGHT "Sven Neumann, Adam D. Moss"
1997-11-25 06:05:25 +08:00
typedef struct
{
1997-11-25 06:05:25 +08:00
gint angle;
gint everything;
} RotateValues;
typedef struct
1999-10-14 07:07:45 +08:00
{
gint32 ID;
gint32 orientation;
gint32 position;
} GuideInfo;
static RotateValues rotvals =
{
1, /* default to 90 degrees */
1997-11-25 06:05:25 +08:00
1 /* default to whole image */
};
1999-10-14 07:07:45 +08:00
static void query (void);
static void run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
1999-10-14 07:07:45 +08:00
static void rotate (void);
static void rotate_drawable (GimpDrawable *drawable);
static void rotate_compute_offsets (gint *offsetx,
gint *offsety,
gint image_width,
gint image_height,
gint width,
gint height);
1997-11-25 06:05:25 +08:00
/* Global Variables */
const GimpPlugInInfo PLUG_IN_INFO =
1997-11-25 06:05:25 +08:00
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run /* run_proc */
1997-11-25 06:05:25 +08:00
};
/* the image and drawable that will be used later */
static GimpDrawable *active_drawable = NULL;
static gint32 image_ID = -1;
1997-11-25 06:05:25 +08:00
/* Functions */
MAIN ()
static void
query (void)
1997-11-25 06:05:25 +08:00
{
static const GimpParamDef args[] =
{
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
{ GIMP_PDB_IMAGE, "image", "Input image" },
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
{ GIMP_PDB_INT32, "angle", "Angle { 90 (1), 180 (2), 270 (3) } degrees" },
{ GIMP_PDB_INT32, "everything", "Rotate the whole image? { TRUE, FALSE }" }
};
gimp_install_procedure (PLUG_IN_PROC,
"Rotates a layer or the whole image by 90, 180 or 270 degrees",
"This plug-in does rotate the active layer or the "
"whole image clockwise by multiples of 90 degrees. "
"When the whole image is choosen, the image is "
"resized if necessary.",
PLUG_IN_AUTHOR,
PLUG_IN_COPYRIGHT,
PLUG_IN_VERSION,
NULL,
PLUG_IN_IMAGE_TYPES,
GIMP_PLUGIN,
use the passed Gimp pointer instead of using "the_gimp". 2001-12-03 Michael Natterer <mitch@gimp.org> * app/devices.c: use the passed Gimp pointer instead of using "the_gimp". * app/base/temp-buf.c: indentation. * app/gui/preferences-dialog.c: prefs_toggle_callback(): fixed segfault when trying to find the prefs_dlg widget from a menu item callback (Fixes #65757). * app/gui/offset-dialog.[ch]: fixed public prototype, include the header in the .c file. * app/gui/menus.c: some menu cleanup: moved all functions which operate on the active layer/drawable to <Image>/Layer. Renamed "Layers" to "Layer". * app/display/gimpdisplayshell.c: changed menu update function accordingly. * app/gui/image-commands.[ch] * app/gui/layers-commands.[ch]: moved stuff from image-commands.* to layers-commads.*- * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcurvestool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/paint_options.c * app/tools/transform_options.c * plug-ins/common/align_layers.c * plug-ins/common/autocrop.c * plug-ins/common/autostretch_hsv.c * plug-ins/common/c_astretch.c * plug-ins/common/color_enhance.c * plug-ins/common/guillotine.c * plug-ins/common/normalize.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/zealouscrop.c * plug-ins/rcm/rcm.c * plug-ins/fp/fp.c: register under <Image>/Layer, some cosmetic fixes.
2001-12-04 01:59:48 +08:00
G_N_ELEMENTS (args), 0,
args, NULL);
1997-11-25 06:05:25 +08:00
}
static void
run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
1997-11-25 06:05:25 +08:00
{
GimpRunMode run_mode = param[0].data.d_int32;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
static GimpParam values[1];
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
1997-11-25 06:05:25 +08:00
values[0].data.d_status = status;
INIT_I18N ();
image_ID = param[1].data.d_int32;
1997-11-25 06:05:25 +08:00
active_drawable = gimp_drawable_get (param[2].data.d_drawable);
if (strcmp (name, PLUG_IN_PROC) == 0)
{
switch (run_mode)
1997-11-25 06:05:25 +08:00
{
case GIMP_RUN_INTERACTIVE:
case GIMP_RUN_NONINTERACTIVE:
/* check to see if invoked with the correct number of parameters */
if (nparams == 5)
{
rotvals.angle = (gint) param[3].data.d_int32;
rotvals.angle = rotvals.angle % 4;
rotvals.everything = (gint) param[4].data.d_int32;
/* Store variable states for next run */
gimp_set_data (PLUG_IN_PROC, &rotvals, sizeof (RotateValues));
}
else
status = GIMP_PDB_CALLING_ERROR;
break;
case GIMP_RUN_WITH_LAST_VALS:
/* Possibly retrieve data from a previous run */
gimp_get_data (PLUG_IN_PROC, &rotvals);
rotvals.angle = rotvals.angle % 4;
break;
default:
break;
1997-11-25 06:05:25 +08:00
}
}
else
{
status = GIMP_PDB_CALLING_ERROR;
}
1997-11-25 06:05:25 +08:00
if (status == GIMP_PDB_SUCCESS)
{
/* Run the main function */
rotate ();
/* If run mode is interactive, flush displays, else (script) don't
do it, as the screen updates would make the scripts slow */
if (run_mode != GIMP_RUN_NONINTERACTIVE)
gimp_displays_flush ();
}
values[0].data.d_status = status;
1997-11-25 06:05:25 +08:00
}
static void
1999-10-14 07:07:45 +08:00
rotate_compute_offsets (gint *offsetx,
gint *offsety,
gint image_width,
1999-10-14 07:07:45 +08:00
gint image_height,
gint width,
1999-10-14 07:07:45 +08:00
gint height)
1997-11-25 06:05:25 +08:00
{
gint buffer;
if (rotvals.everything) /* rotate around the image center */
{
switch (rotvals.angle)
1997-11-25 06:05:25 +08:00
{
case 1: /* 90<39> */
buffer = *offsetx;
*offsetx = image_height - *offsety - height;
*offsety = buffer;
break;
case 2: /* 180<38> */
*offsetx = image_width - *offsetx - width;
*offsety = image_height - *offsety - height;
break;
case 3: /* 270<37> */
buffer = *offsetx;
*offsetx = *offsety;
*offsety = image_width - buffer - width;
}
}
else /* rotate around the drawable center */
{
if (rotvals.angle != 2)
{
*offsetx = *offsetx + (width-height)/2 ;
*offsety = *offsety + (height-width)/2 ;
}
}
return;
}
static void
rotate_drawable (GimpDrawable *drawable)
1997-11-25 06:05:25 +08:00
{
GimpPixelRgn srcPR, destPR;
gint width, height;
gint longside;
gint bytes;
gint row, col;
gint offsetx, offsety;
app/actions/layers-actions.c app/actions/layers-commands.[ch] 2005-07-10 Michael Natterer <mitch@gimp.org> * app/actions/layers-actions.c * app/actions/layers-commands.[ch] * app/core/core-enums.[ch] * app/core/gimpimage-undo-push.[ch] * app/core/gimplayer-floating-sel.c * app/core/gimplayer.[ch] * app/text/gimptextlayer-xcf.c * app/widgets/gimphelp-ids.h * app/widgets/gimplayertreeview.[ch] * app/xcf/xcf-load.c * app/xcf/xcf-private.h * app/xcf/xcf-save.c * tools/pdbgen/pdb/layer.pdb * menus/image-menu.xml.in * libgimp/gimp.def: did a global s/preserve_trans/lock_alpha/ in preparation for more layer locking flags. * app/pdb/procedural_db.c * libgimp/gimplayer.[ch]: added compat stuff for preserve_trans. * app/pdb/layer_cmds.c * libgimp/gimplayer_pdb.[ch]: regenerated. * plug-ins/common/colortoalpha.c * plug-ins/common/iwarp.c * plug-ins/common/psd.c * plug-ins/common/psd_save.c * plug-ins/common/psp.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/vpropagate.c * plug-ins/script-fu/scripts/3d-outline.scm * plug-ins/script-fu/scripts/alien-glow-bar.scm * plug-ins/script-fu/scripts/alien-glow-bullet.scm * plug-ins/script-fu/scripts/alien-glow-logo.scm * plug-ins/script-fu/scripts/basic1-logo.scm * plug-ins/script-fu/scripts/basic2-logo.scm * plug-ins/script-fu/scripts/beveled-pattern-button.scm * plug-ins/script-fu/scripts/blend-anim.scm * plug-ins/script-fu/scripts/blended-logo.scm * plug-ins/script-fu/scripts/bovinated-logo.scm * plug-ins/script-fu/scripts/burn-in-anim.scm * plug-ins/script-fu/scripts/carved-logo.scm * plug-ins/script-fu/scripts/chalk.scm * plug-ins/script-fu/scripts/chip-away.scm * plug-ins/script-fu/scripts/comic-logo.scm * plug-ins/script-fu/scripts/coolmetal-logo.scm * plug-ins/script-fu/scripts/crystal-logo.scm * plug-ins/script-fu/scripts/drop-shadow.scm * plug-ins/script-fu/scripts/gimp-headers.scm * plug-ins/script-fu/scripts/gimp-labels.scm * plug-ins/script-fu/scripts/glowing-logo.scm * plug-ins/script-fu/scripts/gradient-bevel-logo.scm * plug-ins/script-fu/scripts/image-structure.scm * plug-ins/script-fu/scripts/neon-logo.scm * plug-ins/script-fu/scripts/perspective-shadow.scm * plug-ins/script-fu/scripts/starburst-logo.scm * plug-ins/script-fu/scripts/starscape-logo.scm * plug-ins/script-fu/scripts/textured-logo.scm * plug-ins/script-fu/scripts/title-header.scm * plug-ins/script-fu/scripts/waves-anim.scm * plug-ins/xjt/xjt.c: changed accordingly.
2005-07-11 05:17:22 +08:00
gboolean was_lock_alpha = FALSE;
guchar *buffer;
guchar *src_row, *dest_row;
1997-11-25 06:05:25 +08:00
/* initialize */
row = 0;
/* Get the size of the input drawable. */
width = drawable->width;
height = drawable->height;
bytes = drawable->bpp;
app/actions/layers-actions.c app/actions/layers-commands.[ch] 2005-07-10 Michael Natterer <mitch@gimp.org> * app/actions/layers-actions.c * app/actions/layers-commands.[ch] * app/core/core-enums.[ch] * app/core/gimpimage-undo-push.[ch] * app/core/gimplayer-floating-sel.c * app/core/gimplayer.[ch] * app/text/gimptextlayer-xcf.c * app/widgets/gimphelp-ids.h * app/widgets/gimplayertreeview.[ch] * app/xcf/xcf-load.c * app/xcf/xcf-private.h * app/xcf/xcf-save.c * tools/pdbgen/pdb/layer.pdb * menus/image-menu.xml.in * libgimp/gimp.def: did a global s/preserve_trans/lock_alpha/ in preparation for more layer locking flags. * app/pdb/procedural_db.c * libgimp/gimplayer.[ch]: added compat stuff for preserve_trans. * app/pdb/layer_cmds.c * libgimp/gimplayer_pdb.[ch]: regenerated. * plug-ins/common/colortoalpha.c * plug-ins/common/iwarp.c * plug-ins/common/psd.c * plug-ins/common/psd_save.c * plug-ins/common/psp.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/vpropagate.c * plug-ins/script-fu/scripts/3d-outline.scm * plug-ins/script-fu/scripts/alien-glow-bar.scm * plug-ins/script-fu/scripts/alien-glow-bullet.scm * plug-ins/script-fu/scripts/alien-glow-logo.scm * plug-ins/script-fu/scripts/basic1-logo.scm * plug-ins/script-fu/scripts/basic2-logo.scm * plug-ins/script-fu/scripts/beveled-pattern-button.scm * plug-ins/script-fu/scripts/blend-anim.scm * plug-ins/script-fu/scripts/blended-logo.scm * plug-ins/script-fu/scripts/bovinated-logo.scm * plug-ins/script-fu/scripts/burn-in-anim.scm * plug-ins/script-fu/scripts/carved-logo.scm * plug-ins/script-fu/scripts/chalk.scm * plug-ins/script-fu/scripts/chip-away.scm * plug-ins/script-fu/scripts/comic-logo.scm * plug-ins/script-fu/scripts/coolmetal-logo.scm * plug-ins/script-fu/scripts/crystal-logo.scm * plug-ins/script-fu/scripts/drop-shadow.scm * plug-ins/script-fu/scripts/gimp-headers.scm * plug-ins/script-fu/scripts/gimp-labels.scm * plug-ins/script-fu/scripts/glowing-logo.scm * plug-ins/script-fu/scripts/gradient-bevel-logo.scm * plug-ins/script-fu/scripts/image-structure.scm * plug-ins/script-fu/scripts/neon-logo.scm * plug-ins/script-fu/scripts/perspective-shadow.scm * plug-ins/script-fu/scripts/starburst-logo.scm * plug-ins/script-fu/scripts/starscape-logo.scm * plug-ins/script-fu/scripts/textured-logo.scm * plug-ins/script-fu/scripts/title-header.scm * plug-ins/script-fu/scripts/waves-anim.scm * plug-ins/xjt/xjt.c: changed accordingly.
2005-07-11 05:17:22 +08:00
if (gimp_layer_get_lock_alpha (drawable->drawable_id))
1997-11-25 06:05:25 +08:00
{
app/actions/layers-actions.c app/actions/layers-commands.[ch] 2005-07-10 Michael Natterer <mitch@gimp.org> * app/actions/layers-actions.c * app/actions/layers-commands.[ch] * app/core/core-enums.[ch] * app/core/gimpimage-undo-push.[ch] * app/core/gimplayer-floating-sel.c * app/core/gimplayer.[ch] * app/text/gimptextlayer-xcf.c * app/widgets/gimphelp-ids.h * app/widgets/gimplayertreeview.[ch] * app/xcf/xcf-load.c * app/xcf/xcf-private.h * app/xcf/xcf-save.c * tools/pdbgen/pdb/layer.pdb * menus/image-menu.xml.in * libgimp/gimp.def: did a global s/preserve_trans/lock_alpha/ in preparation for more layer locking flags. * app/pdb/procedural_db.c * libgimp/gimplayer.[ch]: added compat stuff for preserve_trans. * app/pdb/layer_cmds.c * libgimp/gimplayer_pdb.[ch]: regenerated. * plug-ins/common/colortoalpha.c * plug-ins/common/iwarp.c * plug-ins/common/psd.c * plug-ins/common/psd_save.c * plug-ins/common/psp.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/vpropagate.c * plug-ins/script-fu/scripts/3d-outline.scm * plug-ins/script-fu/scripts/alien-glow-bar.scm * plug-ins/script-fu/scripts/alien-glow-bullet.scm * plug-ins/script-fu/scripts/alien-glow-logo.scm * plug-ins/script-fu/scripts/basic1-logo.scm * plug-ins/script-fu/scripts/basic2-logo.scm * plug-ins/script-fu/scripts/beveled-pattern-button.scm * plug-ins/script-fu/scripts/blend-anim.scm * plug-ins/script-fu/scripts/blended-logo.scm * plug-ins/script-fu/scripts/bovinated-logo.scm * plug-ins/script-fu/scripts/burn-in-anim.scm * plug-ins/script-fu/scripts/carved-logo.scm * plug-ins/script-fu/scripts/chalk.scm * plug-ins/script-fu/scripts/chip-away.scm * plug-ins/script-fu/scripts/comic-logo.scm * plug-ins/script-fu/scripts/coolmetal-logo.scm * plug-ins/script-fu/scripts/crystal-logo.scm * plug-ins/script-fu/scripts/drop-shadow.scm * plug-ins/script-fu/scripts/gimp-headers.scm * plug-ins/script-fu/scripts/gimp-labels.scm * plug-ins/script-fu/scripts/glowing-logo.scm * plug-ins/script-fu/scripts/gradient-bevel-logo.scm * plug-ins/script-fu/scripts/image-structure.scm * plug-ins/script-fu/scripts/neon-logo.scm * plug-ins/script-fu/scripts/perspective-shadow.scm * plug-ins/script-fu/scripts/starburst-logo.scm * plug-ins/script-fu/scripts/starscape-logo.scm * plug-ins/script-fu/scripts/textured-logo.scm * plug-ins/script-fu/scripts/title-header.scm * plug-ins/script-fu/scripts/waves-anim.scm * plug-ins/xjt/xjt.c: changed accordingly.
2005-07-11 05:17:22 +08:00
was_lock_alpha = TRUE;
gimp_layer_set_lock_alpha (drawable->drawable_id, FALSE);
1997-11-25 06:05:25 +08:00
}
if (rotvals.angle == 2) /* we're rotating by 180<38> */
{
gimp_tile_cache_ntiles (2 * (width / gimp_tile_width() + 1));
1997-11-25 06:05:25 +08:00
gimp_pixel_rgn_init (&srcPR, drawable, 0, 0, width, height,
1997-11-25 06:05:25 +08:00
FALSE, FALSE);
gimp_pixel_rgn_init (&destPR, drawable, 0, 0, width, height,
TRUE, TRUE);
1997-11-25 06:05:25 +08:00
src_row = (guchar *) g_malloc (width * bytes);
dest_row = (guchar *) g_malloc (width * bytes);
1997-11-25 06:05:25 +08:00
for (row = 0; row < height; row++)
{
gimp_pixel_rgn_get_row (&srcPR, src_row, 0, row, width);
for (col = 0; col < width; col++)
{
memcpy (dest_row + col * bytes,
src_row + (width - 1 - col) * bytes,
bytes);
}
gimp_pixel_rgn_set_row (&destPR, dest_row, 0, (height - row - 1),
1997-11-25 06:05:25 +08:00
width);
1997-11-25 06:05:25 +08:00
if ((row % 5) == 0)
gimp_progress_update ((double) row / (double) height);
}
1997-11-25 06:05:25 +08:00
g_free (src_row);
g_free (dest_row);
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id, 0, 0, width, height);
1997-11-25 06:05:25 +08:00
}
else /* we're rotating by 90<39> or 270<37> */
{
1997-11-25 06:05:25 +08:00
(width > height) ? (longside = width) : (longside = height);
gimp_layer_resize (drawable->drawable_id, longside, longside, 0, 0);
drawable = gimp_drawable_get (drawable->drawable_id);
gimp_drawable_flush (drawable);
gimp_tile_cache_ntiles ((longside / gimp_tile_width () + 1) +
(longside / gimp_tile_height () + 1));
1997-11-25 06:05:25 +08:00
gimp_pixel_rgn_init (&srcPR, drawable, 0, 0, longside, longside,
1997-11-25 06:05:25 +08:00
FALSE, FALSE);
gimp_pixel_rgn_init (&destPR, drawable, 0, 0, longside, longside,
TRUE, TRUE);
1997-11-25 06:05:25 +08:00
buffer = g_malloc (longside * bytes);
1997-11-25 06:05:25 +08:00
if (rotvals.angle == 1) /* we're rotating by 90<39> */
{
for (row = 0; row < height; row++)
{
gimp_pixel_rgn_get_row (&srcPR, buffer, 0, row, width);
1997-11-25 06:05:25 +08:00
gimp_pixel_rgn_set_col (&destPR, buffer, (height - row - 1), 0,
width);
if ((row % 5) == 0)
gimp_progress_update ((double) row / (double) height);
}
}
else /* we're rotating by 270<37> */
{
for (col = 0; col < width; col++)
{
gimp_pixel_rgn_get_col (&srcPR, buffer, col, 0, height);
gimp_pixel_rgn_set_row (&destPR, buffer, 0, (width - col - 1),
1997-11-25 06:05:25 +08:00
height);
if ((col % 5) == 0)
gimp_progress_update ((double) col / (double) width);
1997-11-25 06:05:25 +08:00
}
}
1997-11-25 06:05:25 +08:00
g_free (buffer);
gimp_progress_update (1.0);
1997-11-25 06:05:25 +08:00
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id, 0, 0, height, width);
1997-11-25 06:05:25 +08:00
gimp_layer_resize (drawable->drawable_id, height, width, 0, 0);
drawable = gimp_drawable_get (drawable->drawable_id);
1997-11-25 06:05:25 +08:00
gimp_drawable_flush (drawable);
gimp_drawable_update (drawable->drawable_id, 0, 0, height, width);
1997-11-25 06:05:25 +08:00
}
gimp_drawable_offsets (drawable->drawable_id, &offsetx, &offsety);
rotate_compute_offsets (&offsetx, &offsety,
gimp_image_width (image_ID),
gimp_image_height (image_ID),
width, height);
gimp_layer_set_offsets (drawable->drawable_id, offsetx, offsety);
1997-11-25 06:05:25 +08:00
app/actions/layers-actions.c app/actions/layers-commands.[ch] 2005-07-10 Michael Natterer <mitch@gimp.org> * app/actions/layers-actions.c * app/actions/layers-commands.[ch] * app/core/core-enums.[ch] * app/core/gimpimage-undo-push.[ch] * app/core/gimplayer-floating-sel.c * app/core/gimplayer.[ch] * app/text/gimptextlayer-xcf.c * app/widgets/gimphelp-ids.h * app/widgets/gimplayertreeview.[ch] * app/xcf/xcf-load.c * app/xcf/xcf-private.h * app/xcf/xcf-save.c * tools/pdbgen/pdb/layer.pdb * menus/image-menu.xml.in * libgimp/gimp.def: did a global s/preserve_trans/lock_alpha/ in preparation for more layer locking flags. * app/pdb/procedural_db.c * libgimp/gimplayer.[ch]: added compat stuff for preserve_trans. * app/pdb/layer_cmds.c * libgimp/gimplayer_pdb.[ch]: regenerated. * plug-ins/common/colortoalpha.c * plug-ins/common/iwarp.c * plug-ins/common/psd.c * plug-ins/common/psd_save.c * plug-ins/common/psp.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/vpropagate.c * plug-ins/script-fu/scripts/3d-outline.scm * plug-ins/script-fu/scripts/alien-glow-bar.scm * plug-ins/script-fu/scripts/alien-glow-bullet.scm * plug-ins/script-fu/scripts/alien-glow-logo.scm * plug-ins/script-fu/scripts/basic1-logo.scm * plug-ins/script-fu/scripts/basic2-logo.scm * plug-ins/script-fu/scripts/beveled-pattern-button.scm * plug-ins/script-fu/scripts/blend-anim.scm * plug-ins/script-fu/scripts/blended-logo.scm * plug-ins/script-fu/scripts/bovinated-logo.scm * plug-ins/script-fu/scripts/burn-in-anim.scm * plug-ins/script-fu/scripts/carved-logo.scm * plug-ins/script-fu/scripts/chalk.scm * plug-ins/script-fu/scripts/chip-away.scm * plug-ins/script-fu/scripts/comic-logo.scm * plug-ins/script-fu/scripts/coolmetal-logo.scm * plug-ins/script-fu/scripts/crystal-logo.scm * plug-ins/script-fu/scripts/drop-shadow.scm * plug-ins/script-fu/scripts/gimp-headers.scm * plug-ins/script-fu/scripts/gimp-labels.scm * plug-ins/script-fu/scripts/glowing-logo.scm * plug-ins/script-fu/scripts/gradient-bevel-logo.scm * plug-ins/script-fu/scripts/image-structure.scm * plug-ins/script-fu/scripts/neon-logo.scm * plug-ins/script-fu/scripts/perspective-shadow.scm * plug-ins/script-fu/scripts/starburst-logo.scm * plug-ins/script-fu/scripts/starscape-logo.scm * plug-ins/script-fu/scripts/textured-logo.scm * plug-ins/script-fu/scripts/title-header.scm * plug-ins/script-fu/scripts/waves-anim.scm * plug-ins/xjt/xjt.c: changed accordingly.
2005-07-11 05:17:22 +08:00
if (was_lock_alpha)
gimp_layer_set_lock_alpha (drawable->drawable_id, TRUE);
1997-11-25 06:05:25 +08:00
return;
}
/* The main rotate function */
static void
1997-11-25 06:05:25 +08:00
rotate (void)
{
GimpDrawable *drawable;
gint32 *layers;
gint i;
gint nlayers;
gint32 guide_ID;
GuideInfo *guide;
GList *guides = NULL;
GList *list;
1997-11-25 06:05:25 +08:00
if (rotvals.angle == 0) return;
1997-11-25 06:05:25 +08:00
/* if there's a selection and we try to rotate the whole image */
/* create an error message and exit */
if (rotvals.everything)
1997-11-25 06:05:25 +08:00
{
if (! gimp_selection_is_empty (image_ID))
1997-11-25 06:05:25 +08:00
{
gimp_message (_("You can not rotate the whole image if there's a selection."));
1997-11-25 06:05:25 +08:00
gimp_drawable_detach (active_drawable);
return;
}
if (gimp_drawable_is_layer (active_drawable->drawable_id) &&
gimp_layer_is_floating_sel (active_drawable->drawable_id))
1997-11-25 06:05:25 +08:00
{
gimp_message (_("You can not rotate the whole image if there's a floating selection."));
1997-11-25 06:05:25 +08:00
gimp_drawable_detach (active_drawable);
return;
}
}
else
/* if we are trying to rotate a channel or a mask,
create an error message and exit */
{
if (! gimp_drawable_is_layer (active_drawable->drawable_id))
{
gimp_message (_("Sorry, channels and masks can not be rotated."));
gimp_drawable_detach (active_drawable);
return;
}
}
gimp_progress_init (_("Rotating"));
1997-11-25 06:05:25 +08:00
gimp_image_undo_group_start (image_ID);
1997-11-25 06:05:25 +08:00
if (rotvals.everything) /* rotate the whole image */
1999-10-14 07:07:45 +08:00
{
gint32 width = gimp_image_width (image_ID);
gint32 height = gimp_image_height (image_ID);
1997-11-25 06:05:25 +08:00
gimp_drawable_detach (active_drawable);
layers = gimp_image_get_layers (image_ID, &nlayers);
for (i = 0; i < nlayers; i++)
1997-11-25 06:05:25 +08:00
{
drawable = gimp_drawable_get (layers[i]);
rotate_drawable (drawable);
gimp_drawable_detach (drawable);
}
g_free (layers);
1999-10-14 07:07:45 +08:00
/* build a list of all guides and remove them */
guide_ID = 0;
while ((guide_ID = gimp_image_find_next_guide (image_ID, guide_ID)) != 0)
{
guide = g_new (GuideInfo, 1);
guide->ID = guide_ID;
guide->orientation = gimp_image_get_guide_orientation (image_ID,
guide_ID);
1999-10-14 07:07:45 +08:00
guide->position = gimp_image_get_guide_position (image_ID, guide_ID);
guides = g_list_prepend (guides, guide);
}
for (list = guides; list; list = list->next)
1999-10-14 07:07:45 +08:00
{
guide = (GuideInfo *) list->data;
1999-10-14 07:07:45 +08:00
gimp_image_delete_guide (image_ID, guide->ID);
}
/* if rotation is not 180 degrees, resize the image */
/* Do it now after the guides are removed, since */
/* gimp_image_resize() moves the guides. */
1999-10-14 07:07:45 +08:00
if (rotvals.angle != 2)
gimp_image_resize (image_ID, height, width, 0, 0);
/* add the guides back to the image */
if (guides)
1997-11-25 06:05:25 +08:00
{
1999-10-14 07:07:45 +08:00
switch (rotvals.angle)
{
case 1:
for (list = guides; list; list = list->next)
1999-10-14 07:07:45 +08:00
{
guide = (GuideInfo *)list->data;
if (guide->orientation == GIMP_ORIENTATION_HORIZONTAL)
1999-10-14 07:07:45 +08:00
gimp_image_add_vguide (image_ID, height - guide->position);
else
gimp_image_add_hguide (image_ID, guide->position);
g_free (guide);
}
1999-10-14 07:07:45 +08:00
break;
case 2:
for (list = guides; list; list = list->next)
1999-10-14 07:07:45 +08:00
{
guide = (GuideInfo *)list->data;
if (guide->orientation == GIMP_ORIENTATION_HORIZONTAL)
1999-10-14 07:07:45 +08:00
gimp_image_add_hguide (image_ID, height - guide->position);
else
gimp_image_add_vguide (image_ID, width - guide->position);
g_free (guide);
}
1999-10-14 07:07:45 +08:00
break;
case 3:
for (list = guides; list; list = list->next)
1999-10-14 07:07:45 +08:00
{
guide = (GuideInfo *)list->data;
if (guide->orientation == GIMP_ORIENTATION_HORIZONTAL)
1999-10-14 07:07:45 +08:00
gimp_image_add_vguide (image_ID, guide->position);
else
gimp_image_add_hguide (image_ID, width - guide->position);
g_free (guide);
}
1999-10-14 07:07:45 +08:00
break;
default:
1999-10-14 07:07:45 +08:00
break;
}
g_list_free (guides);
1997-11-25 06:05:25 +08:00
}
}
else /* rotate only the active layer */
{
/* check for active selection and float it */
if (! gimp_selection_is_empty (image_ID) &&
! gimp_layer_is_floating_sel (active_drawable->drawable_id))
{
active_drawable =
gimp_drawable_get (gimp_selection_float (image_ID,
active_drawable->drawable_id,
0, 0));
}
1997-11-25 06:05:25 +08:00
rotate_drawable (active_drawable);
gimp_drawable_detach (active_drawable);
}
gimp_image_undo_group_end (image_ID);
1997-11-25 06:05:25 +08:00
return;
}