2001-03-09 15:09:12 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
2003-04-04 19:19:57 +08:00
|
|
|
* Copyright (C) 1995-2003 Spencer Kimball, Peter Mattis, and others
|
2001-03-01 14:56:57 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2003-04-04 21:33:08 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
#include <glib-object.h>
|
2001-03-01 14:56:57 +08:00
|
|
|
|
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
#include "core-types.h"
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/pixel-region.h"
|
|
|
|
#include "base/pixel-surround.h"
|
|
|
|
#include "base/tile-manager.h"
|
|
|
|
#include "base/tile.h"
|
|
|
|
|
2001-04-07 23:58:26 +08:00
|
|
|
#include "paint-funcs/paint-funcs.h"
|
2005-01-12 02:31:07 +08:00
|
|
|
#include "paint-funcs/scale-funcs.h"
|
2001-04-07 23:58:26 +08:00
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
#include "gimp.h"
|
2003-05-14 23:32:07 +08:00
|
|
|
#include "gimp-utils.h"
|
2001-11-20 02:23:43 +08:00
|
|
|
#include "gimpchannel.h"
|
|
|
|
#include "gimpcontext.h"
|
|
|
|
#include "gimpdrawable.h"
|
|
|
|
#include "gimpdrawable-transform.h"
|
|
|
|
#include "gimpimage.h"
|
2003-02-13 19:23:50 +08:00
|
|
|
#include "gimpimage-undo.h"
|
2003-02-14 22:14:29 +08:00
|
|
|
#include "gimpimage-undo-push.h"
|
2001-11-20 02:23:43 +08:00
|
|
|
#include "gimplayer.h"
|
2002-02-22 06:19:45 +08:00
|
|
|
#include "gimplayer-floating-sel.h"
|
2004-08-11 02:47:21 +08:00
|
|
|
#include "gimpprogress.h"
|
2003-10-06 20:17:11 +08:00
|
|
|
#include "gimpselection.h"
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2001-04-18 05:43:29 +08:00
|
|
|
|
2004-03-31 20:40:23 +08:00
|
|
|
#if defined (HAVE_FINITE)
|
|
|
|
#define FINITE(x) finite(x)
|
|
|
|
#elif defined (HAVE_ISFINITE)
|
|
|
|
#define FINITE(x) isfinite(x)
|
|
|
|
#elif defined (G_OS_WIN32)
|
|
|
|
#define FINITE(x) _finite(x)
|
|
|
|
#else
|
|
|
|
#error "no FINITE() implementation available?!"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2003-04-04 19:19:57 +08:00
|
|
|
#define MIN4(a,b,c,d) MIN(MIN(a,b),MIN(c,d))
|
|
|
|
#define MAX4(a,b,c,d) MAX(MAX(a,b),MAX(c,d))
|
2001-03-01 14:56:57 +08:00
|
|
|
|
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
/* forward function prototypes */
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2003-04-04 19:19:57 +08:00
|
|
|
static gboolean supersample_dtest (gdouble u0, gdouble v0,
|
|
|
|
gdouble u1, gdouble v1,
|
|
|
|
gdouble u2, gdouble v2,
|
|
|
|
gdouble u3, gdouble v3);
|
|
|
|
|
2004-03-14 01:45:58 +08:00
|
|
|
static void sample_adapt (TileManager *tm,
|
|
|
|
gdouble uc, gdouble vc,
|
|
|
|
gdouble u0, gdouble v0,
|
|
|
|
gdouble u1, gdouble v1,
|
|
|
|
gdouble u2, gdouble v2,
|
|
|
|
gdouble u3, gdouble v3,
|
|
|
|
gint level,
|
|
|
|
guchar *color,
|
|
|
|
guchar *bg_color,
|
|
|
|
gint bpp,
|
|
|
|
gint alpha);
|
|
|
|
|
|
|
|
static void sample_cubic (PixelSurround *surround,
|
|
|
|
gdouble u,
|
|
|
|
gdouble v,
|
|
|
|
guchar *color,
|
|
|
|
gint bytes,
|
|
|
|
gint alpha);
|
|
|
|
|
|
|
|
static void sample_linear (PixelSurround *surround,
|
|
|
|
gdouble u,
|
|
|
|
gdouble v,
|
|
|
|
guchar *color,
|
|
|
|
gint bytes,
|
|
|
|
gint alpha);
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2005-01-12 02:31:07 +08:00
|
|
|
static void sample_lanczos (const gdouble *kernel,
|
|
|
|
gint su,
|
|
|
|
gint sv,
|
|
|
|
guchar *color,
|
2005-01-16 04:46:21 +08:00
|
|
|
const guchar *buffer,
|
2005-01-12 02:31:07 +08:00
|
|
|
gint bytes,
|
|
|
|
gint alpha);
|
|
|
|
|
|
|
|
static gdouble * kernel_lanczos (void);
|
|
|
|
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
/* public functions */
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2001-03-25 12:08:51 +08:00
|
|
|
TileManager *
|
2001-11-20 02:23:43 +08:00
|
|
|
gimp_drawable_transform_tiles_affine (GimpDrawable *drawable,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2003-05-14 18:51:14 +08:00
|
|
|
TileManager *orig_tiles,
|
2003-07-07 21:50:48 +08:00
|
|
|
const GimpMatrix3 *matrix,
|
2001-11-20 02:23:43 +08:00
|
|
|
GimpTransformDirection direction,
|
2003-05-12 23:56:36 +08:00
|
|
|
GimpInterpolationType interpolation_type,
|
2004-03-13 19:24:25 +08:00
|
|
|
gboolean supersample,
|
2004-03-14 01:45:58 +08:00
|
|
|
gint recursion_level,
|
2003-05-12 23:56:36 +08:00
|
|
|
gboolean clip_result,
|
2004-08-11 02:47:21 +08:00
|
|
|
GimpProgress *progress)
|
2001-03-01 14:56:57 +08:00
|
|
|
{
|
2003-05-13 21:57:11 +08:00
|
|
|
GimpImage *gimage;
|
|
|
|
PixelRegion destPR;
|
2003-05-14 18:51:14 +08:00
|
|
|
TileManager *new_tiles;
|
2004-03-14 01:45:58 +08:00
|
|
|
GimpMatrix3 m;
|
|
|
|
GimpMatrix3 inv;
|
2003-05-13 21:57:11 +08:00
|
|
|
PixelSurround surround;
|
2003-04-04 19:19:57 +08:00
|
|
|
|
|
|
|
gint x1, y1, x2, y2; /* target bounding box */
|
|
|
|
gint x, y; /* target coordinates */
|
|
|
|
gint u1, v1, u2, v2; /* source bounding box */
|
2003-10-06 20:17:11 +08:00
|
|
|
gdouble uinc, vinc, winc; /* increments in source coordinates
|
2003-04-04 19:19:57 +08:00
|
|
|
pr horizontal target coordinate */
|
|
|
|
|
2003-10-06 20:17:11 +08:00
|
|
|
gdouble u[5],v[5]; /* source coordinates,
|
2003-04-04 19:19:57 +08:00
|
|
|
2
|
2003-05-06 02:45:58 +08:00
|
|
|
/ \ 0 is sample in the centre of pixel
|
2003-04-04 19:19:57 +08:00
|
|
|
1 0 3 1..4 is offset 1 pixel in each
|
2003-05-06 02:45:58 +08:00
|
|
|
\ / direction (in target space)
|
2003-04-04 19:19:57 +08:00
|
|
|
4
|
|
|
|
*/
|
|
|
|
|
|
|
|
gdouble tu[5],tv[5],tw[5]; /* undivided source coordinates and
|
|
|
|
divisor */
|
|
|
|
|
2005-01-12 02:31:07 +08:00
|
|
|
gdouble *kernel = NULL; /* Lanczos kernel */
|
|
|
|
gint su, sv; /* Lanczos kernel position */
|
|
|
|
guchar *buffer = NULL; /* Holds sliding window buffer */
|
|
|
|
|
|
|
|
|
2003-05-06 02:45:58 +08:00
|
|
|
gint coords;
|
2003-04-04 19:19:57 +08:00
|
|
|
gint width;
|
|
|
|
gint alpha;
|
|
|
|
gint bytes;
|
|
|
|
guchar *dest, *d;
|
|
|
|
guchar bg_color[MAX_CHANNELS];
|
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
2004-11-16 21:41:55 +08:00
|
|
|
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
|
2004-04-15 07:37:34 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2003-05-14 18:51:14 +08:00
|
|
|
g_return_val_if_fail (orig_tiles != NULL, NULL);
|
2003-05-12 23:56:36 +08:00
|
|
|
g_return_val_if_fail (matrix != NULL, NULL);
|
2004-08-11 02:47:21 +08:00
|
|
|
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2002-02-26 01:58:50 +08:00
|
|
|
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2004-03-14 01:45:58 +08:00
|
|
|
m = *matrix;
|
|
|
|
inv = *matrix;
|
|
|
|
|
2001-03-01 14:56:57 +08:00
|
|
|
alpha = 0;
|
|
|
|
|
|
|
|
/* turn interpolation off for simple transformations (e.g. rot90) */
|
2002-02-12 10:31:45 +08:00
|
|
|
if (gimp_matrix3_is_simple (matrix))
|
2002-02-12 11:30:52 +08:00
|
|
|
interpolation_type = GIMP_INTERPOLATION_NONE;
|
2001-03-01 14:56:57 +08:00
|
|
|
|
|
|
|
/* Get the background color */
|
2004-04-15 07:37:34 +08:00
|
|
|
gimp_image_get_background (gimage, drawable, context, bg_color);
|
2003-04-04 19:19:57 +08:00
|
|
|
|
2001-12-14 23:30:31 +08:00
|
|
|
switch (GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (drawable)))
|
2001-03-01 14:56:57 +08:00
|
|
|
{
|
2001-12-14 23:30:31 +08:00
|
|
|
case GIMP_RGB:
|
2003-04-04 19:19:57 +08:00
|
|
|
bg_color[ALPHA_PIX] = TRANSPARENT_OPACITY;
|
2001-03-01 14:56:57 +08:00
|
|
|
alpha = ALPHA_PIX;
|
|
|
|
break;
|
2001-12-14 23:30:31 +08:00
|
|
|
case GIMP_GRAY:
|
2003-04-04 19:19:57 +08:00
|
|
|
bg_color[ALPHA_G_PIX] = TRANSPARENT_OPACITY;
|
2001-03-01 14:56:57 +08:00
|
|
|
alpha = ALPHA_G_PIX;
|
|
|
|
break;
|
2001-12-14 23:30:31 +08:00
|
|
|
case GIMP_INDEXED:
|
2003-04-04 19:19:57 +08:00
|
|
|
bg_color[ALPHA_I_PIX] = TRANSPARENT_OPACITY;
|
2001-03-01 14:56:57 +08:00
|
|
|
alpha = ALPHA_I_PIX;
|
2002-02-12 11:30:52 +08:00
|
|
|
/* If the gimage is indexed color, ignore interpolation value */
|
|
|
|
interpolation_type = GIMP_INTERPOLATION_NONE;
|
2001-03-01 14:56:57 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-05-13 21:57:11 +08:00
|
|
|
/* "Outside" a channel is transparency, not the bg color */
|
|
|
|
if (GIMP_IS_CHANNEL (drawable))
|
|
|
|
bg_color[0] = TRANSPARENT_OPACITY;
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2003-05-13 21:57:11 +08:00
|
|
|
/* setting alpha = 0 will cause the channel's value to be treated
|
|
|
|
* as alpha and the color channel loops never to be entered
|
|
|
|
*/
|
2003-05-14 18:51:14 +08:00
|
|
|
if (tile_manager_bpp (orig_tiles) == 1)
|
2003-05-13 21:57:11 +08:00
|
|
|
alpha = 0;
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
if (direction == GIMP_TRANSFORM_BACKWARD)
|
2001-03-01 14:56:57 +08:00
|
|
|
{
|
|
|
|
/* keep the original matrix here, so we dont need to recalculate
|
2001-11-20 02:23:43 +08:00
|
|
|
* the inverse later
|
|
|
|
*/
|
2003-07-07 21:50:48 +08:00
|
|
|
gimp_matrix3_invert (&inv);
|
2001-03-01 14:56:57 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Find the inverse of the transformation matrix */
|
2003-07-07 21:50:48 +08:00
|
|
|
gimp_matrix3_invert (&m);
|
2001-03-01 14:56:57 +08:00
|
|
|
}
|
|
|
|
|
2003-05-14 18:51:14 +08:00
|
|
|
tile_manager_get_offsets (orig_tiles, &u1, &v1);
|
|
|
|
u2 = u1 + tile_manager_width (orig_tiles);
|
|
|
|
v2 = v1 + tile_manager_height (orig_tiles);
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2004-11-02 01:21:55 +08:00
|
|
|
/* Always clip unfloated tiles since they must keep their size */
|
2003-05-13 21:57:11 +08:00
|
|
|
if (G_TYPE_FROM_INSTANCE (drawable) == GIMP_TYPE_CHANNEL && alpha == 0)
|
|
|
|
clip_result = TRUE;
|
|
|
|
|
2003-04-04 19:19:57 +08:00
|
|
|
/* Find the bounding coordinates of target */
|
2003-05-13 21:57:11 +08:00
|
|
|
if (clip_result)
|
2001-03-01 14:56:57 +08:00
|
|
|
{
|
2003-04-04 19:19:57 +08:00
|
|
|
x1 = u1;
|
|
|
|
y1 = v1;
|
|
|
|
x2 = u2;
|
|
|
|
y2 = v2;
|
2001-03-01 14:56:57 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
gdouble dx1, dy1;
|
|
|
|
gdouble dx2, dy2;
|
|
|
|
gdouble dx3, dy3;
|
|
|
|
gdouble dx4, dy4;
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2003-07-07 21:50:48 +08:00
|
|
|
gimp_matrix3_transform_point (&inv, u1, v1, &dx1, &dy1);
|
|
|
|
gimp_matrix3_transform_point (&inv, u2, v1, &dx2, &dy2);
|
|
|
|
gimp_matrix3_transform_point (&inv, u1, v2, &dx3, &dy3);
|
|
|
|
gimp_matrix3_transform_point (&inv, u2, v2, &dx4, &dy4);
|
2002-02-20 00:35:13 +08:00
|
|
|
|
2004-03-31 20:40:23 +08:00
|
|
|
if (! FINITE (dx1) || ! FINITE (dy1) ||
|
|
|
|
! FINITE (dx2) || ! FINITE (dy2) ||
|
|
|
|
! FINITE (dx3) || ! FINITE (dy3) ||
|
|
|
|
! FINITE (dx4) || ! FINITE (dy4))
|
|
|
|
{
|
|
|
|
/* fallback to clip_result if the passed matrix is broken */
|
|
|
|
|
|
|
|
x1 = u1;
|
|
|
|
y1 = v1;
|
|
|
|
x2 = u2;
|
|
|
|
y2 = v2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x1 = (gint) floor (MIN4 (dx1, dx2, dx3, dx4));
|
|
|
|
y1 = (gint) floor (MIN4 (dy1, dy2, dy3, dy4));
|
|
|
|
|
|
|
|
x2 = (gint) ceil (MAX4 (dx1, dx2, dx3, dx4));
|
|
|
|
y2 = (gint) ceil (MAX4 (dy1, dy2, dy3, dy4));
|
|
|
|
|
|
|
|
if (x1 == x2)
|
|
|
|
x2++;
|
|
|
|
|
|
|
|
if (y1 == y2)
|
|
|
|
y2++;
|
|
|
|
}
|
2001-03-01 14:56:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the new temporary buffer for the transformed result */
|
2003-05-14 18:51:14 +08:00
|
|
|
new_tiles = tile_manager_new (x2 - x1, y2 - y1,
|
|
|
|
tile_manager_bpp (orig_tiles));
|
|
|
|
pixel_region_init (&destPR, new_tiles,
|
2003-05-16 05:01:02 +08:00
|
|
|
0, 0, x2 - x1, y2 - y1, TRUE);
|
2003-05-14 18:51:14 +08:00
|
|
|
tile_manager_set_offsets (new_tiles, x1, y1);
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2005-01-12 02:31:07 +08:00
|
|
|
width = tile_manager_width (new_tiles);
|
|
|
|
bytes = tile_manager_bpp (new_tiles);
|
|
|
|
|
|
|
|
/* If the image is too small for lanczos, switch to cubic interpolation */
|
|
|
|
if (interpolation_type == GIMP_INTERPOLATION_LANCZOS &&
|
|
|
|
(x2 - x1 < LANCZOS_WIDTH2 || y2 - y1 < LANCZOS_WIDTH2))
|
|
|
|
interpolation_type = GIMP_INTERPOLATION_CUBIC;
|
|
|
|
|
2003-04-04 19:19:57 +08:00
|
|
|
/* initialise the pixel_surround and pixel_cache accessors */
|
2002-02-12 10:31:45 +08:00
|
|
|
switch (interpolation_type)
|
2001-03-01 14:56:57 +08:00
|
|
|
{
|
2002-02-12 11:30:52 +08:00
|
|
|
case GIMP_INTERPOLATION_NONE:
|
2002-02-12 10:31:45 +08:00
|
|
|
break;
|
2002-02-12 11:30:52 +08:00
|
|
|
case GIMP_INTERPOLATION_CUBIC:
|
2003-05-14 18:51:14 +08:00
|
|
|
pixel_surround_init (&surround, orig_tiles, 4, 4, bg_color);
|
2002-02-12 10:31:45 +08:00
|
|
|
break;
|
2002-02-12 11:30:52 +08:00
|
|
|
case GIMP_INTERPOLATION_LINEAR:
|
2003-05-14 18:51:14 +08:00
|
|
|
pixel_surround_init (&surround, orig_tiles, 2, 2, bg_color);
|
2002-02-12 10:31:45 +08:00
|
|
|
break;
|
2005-01-12 02:31:07 +08:00
|
|
|
case GIMP_INTERPOLATION_LANCZOS:
|
|
|
|
kernel = kernel_lanczos ();
|
2005-01-16 04:46:21 +08:00
|
|
|
buffer = g_new0 (guchar, SQR (LANCZOS_WIDTH2) * bytes);
|
2005-01-12 02:31:07 +08:00
|
|
|
break;
|
2001-03-01 14:56:57 +08:00
|
|
|
}
|
|
|
|
|
2003-05-14 18:51:14 +08:00
|
|
|
dest = g_new (guchar, tile_manager_width (new_tiles) * bytes);
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2003-07-07 21:50:48 +08:00
|
|
|
uinc = m.coeff[0][0];
|
|
|
|
vinc = m.coeff[1][0];
|
|
|
|
winc = m.coeff[2][0];
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2003-05-13 21:57:11 +08:00
|
|
|
coords = (interpolation_type != GIMP_INTERPOLATION_NONE) ? 5 : 1;
|
2003-05-06 02:45:58 +08:00
|
|
|
|
2001-03-01 14:56:57 +08:00
|
|
|
/* these loops could be rearranged, depending on which bit of code
|
|
|
|
* you'd most like to write more than once.
|
|
|
|
*/
|
|
|
|
|
2003-04-04 19:19:57 +08:00
|
|
|
for (y = y1; y < y2; y++)
|
2001-03-01 14:56:57 +08:00
|
|
|
{
|
2004-08-11 02:47:21 +08:00
|
|
|
if (progress && !(y & 0xf))
|
|
|
|
gimp_progress_set_value (progress,
|
2005-01-16 04:46:21 +08:00
|
|
|
(gdouble) (y - y1) / (gdouble) (y2 - y1));
|
2001-03-01 14:56:57 +08:00
|
|
|
|
|
|
|
/* set up inverse transform steps */
|
2004-06-17 14:42:07 +08:00
|
|
|
tu[0] = uinc * x1 + m.coeff[0][1] * y + m.coeff[0][2];
|
|
|
|
tv[0] = vinc * x1 + m.coeff[1][1] * y + m.coeff[1][2];
|
|
|
|
tw[0] = winc * x1 + m.coeff[2][1] * y + m.coeff[2][2];
|
2003-05-06 02:45:58 +08:00
|
|
|
|
|
|
|
if (interpolation_type != GIMP_INTERPOLATION_NONE)
|
2002-02-20 17:59:50 +08:00
|
|
|
{
|
2004-06-17 14:42:07 +08:00
|
|
|
gdouble xx = x1;
|
|
|
|
gdouble yy = y;
|
2003-04-04 19:19:57 +08:00
|
|
|
|
2004-04-10 19:48:07 +08:00
|
|
|
tu[1] = uinc * (xx - 1) + m.coeff[0][1] * (yy ) + m.coeff[0][2];
|
|
|
|
tv[1] = vinc * (xx - 1) + m.coeff[1][1] * (yy ) + m.coeff[1][2];
|
2003-07-07 21:50:48 +08:00
|
|
|
tw[1] = winc * (xx - 1) + m.coeff[2][1] * (yy ) + m.coeff[2][2];
|
2003-04-04 19:19:57 +08:00
|
|
|
|
2004-04-10 19:48:07 +08:00
|
|
|
tu[2] = uinc * (xx ) + m.coeff[0][1] * (yy - 1) + m.coeff[0][2];
|
|
|
|
tv[2] = vinc * (xx ) + m.coeff[1][1] * (yy - 1) + m.coeff[1][2];
|
2003-07-07 21:50:48 +08:00
|
|
|
tw[2] = winc * (xx ) + m.coeff[2][1] * (yy - 1) + m.coeff[2][2];
|
2003-04-04 19:19:57 +08:00
|
|
|
|
2004-04-10 19:48:07 +08:00
|
|
|
tu[3] = uinc * (xx + 1) + m.coeff[0][1] * (yy ) + m.coeff[0][2];
|
|
|
|
tv[3] = vinc * (xx + 1) + m.coeff[1][1] * (yy ) + m.coeff[1][2];
|
2003-07-07 21:50:48 +08:00
|
|
|
tw[3] = winc * (xx + 1) + m.coeff[2][1] * (yy ) + m.coeff[2][2];
|
2003-04-04 19:19:57 +08:00
|
|
|
|
2004-04-10 19:48:07 +08:00
|
|
|
tu[4] = uinc * (xx ) + m.coeff[0][1] * (yy + 1) + m.coeff[0][2];
|
|
|
|
tv[4] = vinc * (xx ) + m.coeff[1][1] * (yy + 1) + m.coeff[1][2];
|
2003-07-07 21:50:48 +08:00
|
|
|
tw[4] = winc * (xx ) + m.coeff[2][1] * (yy + 1) + m.coeff[2][2];
|
2002-02-20 17:59:50 +08:00
|
|
|
}
|
2001-03-01 14:56:57 +08:00
|
|
|
|
|
|
|
d = dest;
|
2002-02-20 00:35:13 +08:00
|
|
|
|
2003-04-04 19:19:57 +08:00
|
|
|
for (x = x1; x < x2; x++)
|
|
|
|
{
|
|
|
|
gint i; /* normalize homogeneous coords */
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2003-04-04 19:19:57 +08:00
|
|
|
for (i = 0; i < coords; i++)
|
2002-02-12 10:31:45 +08:00
|
|
|
{
|
2003-05-06 02:45:58 +08:00
|
|
|
if (tw[i] == 1.0)
|
2002-02-12 10:31:45 +08:00
|
|
|
{
|
2003-05-06 02:45:58 +08:00
|
|
|
u[i] = tu[i];
|
|
|
|
v[i] = tv[i];
|
2002-02-12 10:31:45 +08:00
|
|
|
}
|
2003-05-06 02:45:58 +08:00
|
|
|
else if (tw[i] != 0.0)
|
2002-02-12 10:31:45 +08:00
|
|
|
{
|
2003-04-04 19:19:57 +08:00
|
|
|
u[i] = tu[i] / tw[i];
|
|
|
|
v[i] = tv[i] / tw[i];
|
2001-03-01 14:56:57 +08:00
|
|
|
}
|
2003-04-04 19:19:57 +08:00
|
|
|
else
|
2001-03-01 14:56:57 +08:00
|
|
|
{
|
2003-05-06 02:45:58 +08:00
|
|
|
g_warning ("homogeneous coordinate = 0...\n");
|
2003-04-04 19:19:57 +08:00
|
|
|
}
|
|
|
|
}
|
2002-02-12 10:31:45 +08:00
|
|
|
|
2003-04-04 19:19:57 +08:00
|
|
|
/* Set the destination pixels */
|
|
|
|
if (interpolation_type == GIMP_INTERPOLATION_NONE)
|
|
|
|
{
|
|
|
|
guchar color[MAX_CHANNELS];
|
2005-01-16 04:46:21 +08:00
|
|
|
gint iu = (gint) u[0];
|
|
|
|
gint iv = (gint) v[0];
|
2003-05-13 21:57:11 +08:00
|
|
|
gint b;
|
2002-02-12 10:31:45 +08:00
|
|
|
|
2003-04-04 19:19:57 +08:00
|
|
|
if (iu >= u1 && iu < u2 &&
|
|
|
|
iv >= v1 && iv < v2)
|
|
|
|
{
|
|
|
|
/* u, v coordinates into source tiles */
|
|
|
|
gint u = iu - u1;
|
|
|
|
gint v = iv - v1;
|
2002-02-12 10:31:45 +08:00
|
|
|
|
2003-05-14 18:51:14 +08:00
|
|
|
read_pixel_data_1 (orig_tiles, u, v, color);
|
2002-02-12 10:31:45 +08:00
|
|
|
|
2003-04-04 19:19:57 +08:00
|
|
|
for (b = 0; b < bytes; b++)
|
|
|
|
*d++ = color[b];
|
2002-02-12 10:31:45 +08:00
|
|
|
}
|
|
|
|
else /* not in source range */
|
|
|
|
{
|
|
|
|
/* increment the destination pointers */
|
|
|
|
|
2003-04-04 19:19:57 +08:00
|
|
|
for (b = 0; b < bytes; b++)
|
|
|
|
*d++ = bg_color[b];
|
2003-05-06 02:45:58 +08:00
|
|
|
}
|
2003-04-04 19:19:57 +08:00
|
|
|
}
|
2005-01-12 02:31:07 +08:00
|
|
|
else if (interpolation_type == GIMP_INTERPOLATION_LANCZOS)
|
|
|
|
{
|
|
|
|
guchar color[MAX_CHANNELS];
|
2005-01-16 04:46:21 +08:00
|
|
|
gint iu = (gint) u[0];
|
|
|
|
gint iv = (gint) v[0];
|
2005-01-12 02:31:07 +08:00
|
|
|
gint b;
|
|
|
|
|
|
|
|
if (iu >= u1 && iu < u2 &&
|
|
|
|
iv >= v1 && iv < v2)
|
|
|
|
{
|
|
|
|
/* u, v coordinates into source tiles */
|
|
|
|
gint u = iu - u1;
|
|
|
|
gint v = iv - v1;
|
|
|
|
|
|
|
|
read_pixel_data (orig_tiles,
|
2005-01-16 04:46:21 +08:00
|
|
|
u - LANCZOS_WIDTH + 1,
|
|
|
|
v - LANCZOS_WIDTH + 1,
|
|
|
|
u + LANCZOS_WIDTH,
|
|
|
|
v + LANCZOS_WIDTH,
|
2005-01-12 02:31:07 +08:00
|
|
|
buffer,
|
2005-01-16 04:46:21 +08:00
|
|
|
bytes * LANCZOS_WIDTH2);
|
2005-01-12 02:31:07 +08:00
|
|
|
|
2005-01-16 04:46:21 +08:00
|
|
|
su = (gint) ((u - iu) * LANCZOS_SPP);
|
|
|
|
sv = (gint) ((v - iv) * LANCZOS_SPP);
|
2005-01-12 02:31:07 +08:00
|
|
|
|
|
|
|
sample_lanczos (kernel, su, sv, color, buffer, bytes, alpha);
|
|
|
|
|
|
|
|
for (b = 0; b < bytes; b++)
|
|
|
|
*d++ = color[b];
|
|
|
|
}
|
|
|
|
else /* not in source range */
|
|
|
|
{
|
|
|
|
/* increment the destination pointers */
|
|
|
|
|
|
|
|
for (b = 0; b < bytes; b++)
|
|
|
|
*d++ = bg_color[b];
|
|
|
|
}
|
|
|
|
}
|
2003-05-06 02:45:58 +08:00
|
|
|
else
|
2003-04-04 19:19:57 +08:00
|
|
|
{
|
|
|
|
gint b;
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2004-06-17 14:42:07 +08:00
|
|
|
if (u [0] < u1 || v [0] < v1 ||
|
|
|
|
u [0] >= u2 || v [0] >= v2 )
|
2001-03-01 14:56:57 +08:00
|
|
|
{
|
2003-04-04 19:19:57 +08:00
|
|
|
/* not in source range */
|
|
|
|
/* increment the destination pointers */
|
2001-03-01 14:56:57 +08:00
|
|
|
|
|
|
|
for (b = 0; b < bytes; b++)
|
2003-04-04 19:19:57 +08:00
|
|
|
*d++ = bg_color[b];
|
2002-02-12 10:31:45 +08:00
|
|
|
}
|
2003-10-06 20:17:11 +08:00
|
|
|
else
|
2001-03-01 14:56:57 +08:00
|
|
|
{
|
2003-04-04 19:19:57 +08:00
|
|
|
guchar color[MAX_CHANNELS];
|
|
|
|
|
2004-06-17 14:42:07 +08:00
|
|
|
/* clamp texture coordinates */
|
|
|
|
for (b = 0; b < 5; b++)
|
|
|
|
{
|
|
|
|
u[b] = CLAMP (u[b], u1, u2 - 1);
|
|
|
|
v[b] = CLAMP (v[b], v1, v2 - 1);
|
|
|
|
}
|
|
|
|
|
2004-03-13 19:24:25 +08:00
|
|
|
if (supersample &&
|
2003-04-04 19:19:57 +08:00
|
|
|
supersample_dtest (u[1], v[1], u[2], v[2],
|
|
|
|
u[3], v[3], u[4], v[4]))
|
|
|
|
{
|
2003-05-14 18:51:14 +08:00
|
|
|
sample_adapt (orig_tiles,
|
2003-04-04 19:19:57 +08:00
|
|
|
u[0]-u1, v[0]-v1,
|
|
|
|
u[1]-u1, v[1]-v1,
|
|
|
|
u[2]-u1, v[2]-v1,
|
|
|
|
u[3]-u1, v[3]-v1,
|
|
|
|
u[4]-u1, v[4]-v1,
|
2004-03-14 01:45:58 +08:00
|
|
|
recursion_level,
|
2003-04-04 19:19:57 +08:00
|
|
|
color, bg_color, bytes, alpha);
|
|
|
|
}
|
|
|
|
else
|
2003-05-06 02:45:58 +08:00
|
|
|
{
|
2003-04-04 19:19:57 +08:00
|
|
|
if (interpolation_type == GIMP_INTERPOLATION_LINEAR)
|
|
|
|
sample_linear (&surround, u[0] - u1, v[0] - v1,
|
|
|
|
color, bytes, alpha);
|
|
|
|
else
|
|
|
|
sample_cubic (&surround, u[0] - u1, v[0] - v1,
|
|
|
|
color, bytes, alpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the destination pixel */
|
2001-03-01 14:56:57 +08:00
|
|
|
for (b = 0; b < bytes; b++)
|
2003-04-04 19:19:57 +08:00
|
|
|
*d++ = color[b];
|
2003-05-06 02:45:58 +08:00
|
|
|
}
|
2002-02-12 10:31:45 +08:00
|
|
|
}
|
2001-03-31 22:10:22 +08:00
|
|
|
|
2003-04-04 19:19:57 +08:00
|
|
|
for (i = 0; i < coords; i++)
|
|
|
|
{
|
|
|
|
tu[i] += uinc;
|
|
|
|
tv[i] += vinc;
|
|
|
|
tw[i] += winc;
|
|
|
|
}
|
|
|
|
}
|
2001-03-01 14:56:57 +08:00
|
|
|
|
|
|
|
/* set the pixel region row */
|
2003-04-04 19:19:57 +08:00
|
|
|
pixel_region_set_row (&destPR, 0, (y - y1), width, dest);
|
2001-03-01 14:56:57 +08:00
|
|
|
}
|
2003-10-06 20:17:11 +08:00
|
|
|
|
2005-01-12 02:31:07 +08:00
|
|
|
switch (interpolation_type)
|
|
|
|
{
|
|
|
|
case GIMP_INTERPOLATION_NONE:
|
|
|
|
break;
|
|
|
|
case GIMP_INTERPOLATION_CUBIC:
|
|
|
|
case GIMP_INTERPOLATION_LINEAR:
|
|
|
|
pixel_surround_clear (&surround);
|
|
|
|
break;
|
|
|
|
case GIMP_INTERPOLATION_LANCZOS:
|
|
|
|
g_free (kernel);
|
|
|
|
g_free (buffer);
|
|
|
|
break;
|
|
|
|
}
|
2001-03-01 14:56:57 +08:00
|
|
|
|
|
|
|
g_free (dest);
|
2001-03-31 22:10:22 +08:00
|
|
|
|
2003-05-14 18:51:14 +08:00
|
|
|
return new_tiles;
|
|
|
|
}
|
|
|
|
|
2001-03-01 14:56:57 +08:00
|
|
|
TileManager *
|
2003-02-08 01:12:21 +08:00
|
|
|
gimp_drawable_transform_tiles_flip (GimpDrawable *drawable,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2003-05-14 18:51:14 +08:00
|
|
|
TileManager *orig_tiles,
|
2003-05-12 23:56:36 +08:00
|
|
|
GimpOrientationType flip_type,
|
2003-05-13 21:57:11 +08:00
|
|
|
gdouble axis,
|
|
|
|
gboolean clip_result)
|
2001-03-01 14:56:57 +08:00
|
|
|
{
|
2003-05-14 18:51:14 +08:00
|
|
|
GimpImage *gimage;
|
|
|
|
TileManager *new_tiles;
|
2001-11-20 02:23:43 +08:00
|
|
|
PixelRegion srcPR, destPR;
|
|
|
|
gint orig_x, orig_y;
|
2003-05-14 18:51:14 +08:00
|
|
|
gint orig_width, orig_height;
|
|
|
|
gint orig_bpp;
|
|
|
|
gint new_x, new_y;
|
|
|
|
gint new_width, new_height;
|
2001-11-20 02:23:43 +08:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
2004-11-16 21:41:55 +08:00
|
|
|
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
|
2004-04-15 07:37:34 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2003-05-14 18:51:14 +08:00
|
|
|
g_return_val_if_fail (orig_tiles != NULL, NULL);
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2003-05-14 18:51:14 +08:00
|
|
|
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
|
2003-05-13 21:57:11 +08:00
|
|
|
|
2003-05-14 18:51:14 +08:00
|
|
|
orig_width = tile_manager_width (orig_tiles);
|
|
|
|
orig_height = tile_manager_height (orig_tiles);
|
|
|
|
orig_bpp = tile_manager_bpp (orig_tiles);
|
|
|
|
tile_manager_get_offsets (orig_tiles, &orig_x, &orig_y);
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2003-05-14 18:51:14 +08:00
|
|
|
new_x = orig_x;
|
|
|
|
new_y = orig_y;
|
|
|
|
new_width = orig_width;
|
|
|
|
new_height = orig_height;
|
2003-05-12 23:56:36 +08:00
|
|
|
|
|
|
|
switch (flip_type)
|
|
|
|
{
|
|
|
|
case GIMP_ORIENTATION_HORIZONTAL:
|
2004-01-21 23:02:02 +08:00
|
|
|
new_x = RINT (-((gdouble) orig_x +
|
|
|
|
(gdouble) orig_width - axis) + axis);
|
2003-05-12 23:56:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ORIENTATION_VERTICAL:
|
2004-01-21 23:02:02 +08:00
|
|
|
new_y = RINT (-((gdouble) orig_y +
|
|
|
|
(gdouble) orig_height - axis) + axis);
|
2003-05-12 23:56:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-05-14 18:51:14 +08:00
|
|
|
new_tiles = tile_manager_new (new_width, new_height, orig_bpp);
|
|
|
|
|
|
|
|
if (clip_result && (new_x != orig_y || new_y != orig_y))
|
|
|
|
{
|
|
|
|
guchar bg_color[MAX_CHANNELS];
|
|
|
|
gint clip_x, clip_y;
|
|
|
|
gint clip_width, clip_height;
|
|
|
|
|
|
|
|
tile_manager_set_offsets (new_tiles, orig_x, orig_y);
|
|
|
|
|
2004-04-15 07:37:34 +08:00
|
|
|
gimp_image_get_background (gimage, drawable, context, bg_color);
|
2003-05-14 18:51:14 +08:00
|
|
|
|
|
|
|
/* "Outside" a channel is transparency, not the bg color */
|
|
|
|
if (GIMP_IS_CHANNEL (drawable))
|
|
|
|
bg_color[0] = TRANSPARENT_OPACITY;
|
|
|
|
|
|
|
|
pixel_region_init (&destPR, new_tiles,
|
|
|
|
0, 0, new_width, new_height, TRUE);
|
|
|
|
color_region (&destPR, bg_color);
|
|
|
|
|
|
|
|
if (gimp_rectangle_intersect (orig_x, orig_y, orig_width, orig_height,
|
|
|
|
new_x, new_y, new_width, new_height,
|
|
|
|
&clip_x, &clip_y,
|
|
|
|
&clip_width, &clip_height))
|
|
|
|
{
|
|
|
|
orig_x = new_x = clip_x - orig_x;
|
|
|
|
orig_y = new_y = clip_y - orig_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
orig_width = new_width = clip_width;
|
|
|
|
orig_height = new_height = clip_height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tile_manager_set_offsets (new_tiles, new_x, new_y);
|
|
|
|
|
|
|
|
orig_x = 0;
|
|
|
|
orig_y = 0;
|
|
|
|
new_x = 0;
|
|
|
|
new_y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_width == 0 && new_height == 0)
|
|
|
|
return new_tiles;
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
if (flip_type == GIMP_ORIENTATION_HORIZONTAL)
|
2001-11-20 02:23:43 +08:00
|
|
|
{
|
|
|
|
for (i = 0; i < orig_width; i++)
|
|
|
|
{
|
2003-05-14 18:51:14 +08:00
|
|
|
pixel_region_init (&srcPR, orig_tiles,
|
|
|
|
i + orig_x, orig_y,
|
|
|
|
1, orig_height, FALSE);
|
|
|
|
pixel_region_init (&destPR, new_tiles,
|
|
|
|
new_x + new_width - i - 1, new_y,
|
|
|
|
1, new_height, TRUE);
|
2003-10-06 20:17:11 +08:00
|
|
|
copy_region (&srcPR, &destPR);
|
2001-11-20 02:23:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < orig_height; i++)
|
|
|
|
{
|
2003-05-14 18:51:14 +08:00
|
|
|
pixel_region_init (&srcPR, orig_tiles,
|
|
|
|
orig_x, i + orig_y,
|
|
|
|
orig_width, 1, FALSE);
|
|
|
|
pixel_region_init (&destPR, new_tiles,
|
|
|
|
new_x, new_y + new_height - i - 1,
|
|
|
|
new_width, 1, TRUE);
|
2001-11-20 02:23:43 +08:00
|
|
|
copy_region (&srcPR, &destPR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-14 18:51:14 +08:00
|
|
|
return new_tiles;
|
2001-11-20 02:23:43 +08:00
|
|
|
}
|
|
|
|
|
2003-05-21 02:13:07 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_transform_rotate_point (gint x,
|
|
|
|
gint y,
|
|
|
|
GimpRotationType rotate_type,
|
|
|
|
gdouble center_x,
|
|
|
|
gdouble center_y,
|
|
|
|
gint *new_x,
|
|
|
|
gint *new_y)
|
|
|
|
{
|
|
|
|
g_return_if_fail (new_x != NULL);
|
|
|
|
g_return_if_fail (new_y != NULL);
|
|
|
|
|
|
|
|
switch (rotate_type)
|
|
|
|
{
|
|
|
|
case GIMP_ROTATE_90:
|
2004-01-21 23:02:02 +08:00
|
|
|
*new_x = RINT (center_x - (gdouble) y + center_y);
|
|
|
|
*new_y = RINT (center_y + (gdouble) x - center_x);
|
2003-05-21 02:13:07 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ROTATE_180:
|
2004-01-21 23:02:02 +08:00
|
|
|
*new_x = RINT (center_x - ((gdouble) x - center_x));
|
|
|
|
*new_y = RINT (center_y - ((gdouble) y - center_y));
|
2003-05-21 02:13:07 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ROTATE_270:
|
2004-01-21 23:02:02 +08:00
|
|
|
*new_x = RINT (center_x + (gdouble) y - center_y);
|
|
|
|
*new_y = RINT (center_y - (gdouble) x + center_x);
|
2003-05-21 02:13:07 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-20 18:36:29 +08:00
|
|
|
TileManager *
|
|
|
|
gimp_drawable_transform_tiles_rotate (GimpDrawable *drawable,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2003-05-20 18:36:29 +08:00
|
|
|
TileManager *orig_tiles,
|
|
|
|
GimpRotationType rotate_type,
|
|
|
|
gdouble center_x,
|
|
|
|
gdouble center_y,
|
|
|
|
gboolean clip_result)
|
|
|
|
{
|
|
|
|
GimpImage *gimage;
|
|
|
|
TileManager *new_tiles;
|
|
|
|
PixelRegion srcPR, destPR;
|
|
|
|
guchar *buf = NULL;
|
|
|
|
gint orig_x, orig_y;
|
|
|
|
gint orig_width, orig_height;
|
|
|
|
gint orig_bpp;
|
|
|
|
gint new_x, new_y;
|
|
|
|
gint new_width, new_height;
|
|
|
|
gint i, j, k;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
2004-11-16 21:41:55 +08:00
|
|
|
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
|
2004-04-15 07:37:34 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2003-05-20 18:36:29 +08:00
|
|
|
g_return_val_if_fail (orig_tiles != NULL, NULL);
|
|
|
|
|
|
|
|
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
|
|
|
|
|
|
|
|
orig_width = tile_manager_width (orig_tiles);
|
|
|
|
orig_height = tile_manager_height (orig_tiles);
|
|
|
|
orig_bpp = tile_manager_bpp (orig_tiles);
|
|
|
|
tile_manager_get_offsets (orig_tiles, &orig_x, &orig_y);
|
|
|
|
|
|
|
|
switch (rotate_type)
|
|
|
|
{
|
|
|
|
case GIMP_ROTATE_90:
|
2003-05-21 02:13:07 +08:00
|
|
|
gimp_drawable_transform_rotate_point (orig_x,
|
|
|
|
orig_y + orig_height,
|
|
|
|
rotate_type, center_x, center_y,
|
|
|
|
&new_x, &new_y);
|
2003-05-20 18:36:29 +08:00
|
|
|
new_width = orig_height;
|
|
|
|
new_height = orig_width;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ROTATE_180:
|
2003-05-21 02:13:07 +08:00
|
|
|
gimp_drawable_transform_rotate_point (orig_x + orig_width,
|
|
|
|
orig_y + orig_height,
|
|
|
|
rotate_type, center_x, center_y,
|
|
|
|
&new_x, &new_y);
|
2003-05-20 18:36:29 +08:00
|
|
|
new_width = orig_width;
|
|
|
|
new_height = orig_height;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ROTATE_270:
|
2003-05-21 02:13:07 +08:00
|
|
|
gimp_drawable_transform_rotate_point (orig_x + orig_width,
|
|
|
|
orig_y,
|
|
|
|
rotate_type, center_x, center_y,
|
|
|
|
&new_x, &new_y);
|
2003-05-20 18:36:29 +08:00
|
|
|
new_width = orig_height;
|
|
|
|
new_height = orig_width;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-05-21 02:13:07 +08:00
|
|
|
if (clip_result && (new_x != orig_x || new_y != orig_y ||
|
|
|
|
new_width != orig_width || new_height != orig_height))
|
2003-10-06 20:17:11 +08:00
|
|
|
|
2003-05-20 18:36:29 +08:00
|
|
|
{
|
|
|
|
guchar bg_color[MAX_CHANNELS];
|
|
|
|
gint clip_x, clip_y;
|
|
|
|
gint clip_width, clip_height;
|
|
|
|
|
2003-05-21 02:13:07 +08:00
|
|
|
new_tiles = tile_manager_new (orig_width, orig_height, orig_bpp);
|
|
|
|
|
2003-05-20 18:36:29 +08:00
|
|
|
tile_manager_set_offsets (new_tiles, orig_x, orig_y);
|
|
|
|
|
2004-04-15 07:37:34 +08:00
|
|
|
gimp_image_get_background (gimage, drawable, context, bg_color);
|
2003-05-20 18:36:29 +08:00
|
|
|
|
|
|
|
/* "Outside" a channel is transparency, not the bg color */
|
|
|
|
if (GIMP_IS_CHANNEL (drawable))
|
|
|
|
bg_color[0] = TRANSPARENT_OPACITY;
|
|
|
|
|
|
|
|
pixel_region_init (&destPR, new_tiles,
|
2003-05-21 02:13:07 +08:00
|
|
|
0, 0, orig_width, orig_height, TRUE);
|
2003-05-20 18:36:29 +08:00
|
|
|
color_region (&destPR, bg_color);
|
|
|
|
|
|
|
|
if (gimp_rectangle_intersect (orig_x, orig_y, orig_width, orig_height,
|
|
|
|
new_x, new_y, new_width, new_height,
|
|
|
|
&clip_x, &clip_y,
|
|
|
|
&clip_width, &clip_height))
|
|
|
|
{
|
2003-05-21 02:13:07 +08:00
|
|
|
gint saved_orig_x = orig_x;
|
|
|
|
gint saved_orig_y = orig_y;
|
|
|
|
|
|
|
|
new_x = clip_x - orig_x;
|
|
|
|
new_y = clip_y - orig_y;
|
|
|
|
|
|
|
|
switch (rotate_type)
|
|
|
|
{
|
|
|
|
case GIMP_ROTATE_90:
|
|
|
|
gimp_drawable_transform_rotate_point (clip_x + clip_width,
|
|
|
|
clip_y,
|
|
|
|
GIMP_ROTATE_270,
|
|
|
|
center_x,
|
|
|
|
center_y,
|
|
|
|
&orig_x,
|
|
|
|
&orig_y);
|
|
|
|
orig_x -= saved_orig_x;
|
|
|
|
orig_y -= saved_orig_y;
|
|
|
|
orig_width = clip_height;
|
|
|
|
orig_height = clip_width;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ROTATE_180:
|
|
|
|
orig_x = clip_x - orig_x;
|
|
|
|
orig_y = clip_y - orig_y;
|
|
|
|
orig_width = clip_width;
|
|
|
|
orig_height = clip_height;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ROTATE_270:
|
|
|
|
gimp_drawable_transform_rotate_point (clip_x,
|
|
|
|
clip_y + clip_height,
|
|
|
|
GIMP_ROTATE_90,
|
|
|
|
center_x,
|
|
|
|
center_y,
|
|
|
|
&orig_x,
|
|
|
|
&orig_y);
|
|
|
|
orig_x -= saved_orig_x;
|
|
|
|
orig_y -= saved_orig_y;
|
|
|
|
orig_width = clip_height;
|
|
|
|
orig_height = clip_width;
|
|
|
|
break;
|
|
|
|
}
|
2003-05-20 18:36:29 +08:00
|
|
|
}
|
|
|
|
|
2003-05-21 02:13:07 +08:00
|
|
|
new_width = clip_width;
|
|
|
|
new_height = clip_height;
|
2003-05-20 18:36:29 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-05-21 02:13:07 +08:00
|
|
|
new_tiles = tile_manager_new (new_width, new_height, orig_bpp);
|
|
|
|
|
2003-05-20 18:36:29 +08:00
|
|
|
tile_manager_set_offsets (new_tiles, new_x, new_y);
|
|
|
|
|
|
|
|
orig_x = 0;
|
|
|
|
orig_y = 0;
|
|
|
|
new_x = 0;
|
|
|
|
new_y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_width == 0 && new_height == 0)
|
|
|
|
return new_tiles;
|
|
|
|
|
|
|
|
pixel_region_init (&srcPR, orig_tiles,
|
|
|
|
orig_x, orig_y, orig_width, orig_height, FALSE);
|
|
|
|
pixel_region_init (&destPR, new_tiles,
|
|
|
|
new_x, new_y, new_width, new_height, TRUE);
|
|
|
|
|
|
|
|
switch (rotate_type)
|
|
|
|
{
|
|
|
|
case GIMP_ROTATE_90:
|
|
|
|
g_assert (new_height == orig_width);
|
|
|
|
buf = g_new (guchar, new_height * orig_bpp);
|
|
|
|
|
|
|
|
for (i = 0; i < orig_height; i++)
|
|
|
|
{
|
|
|
|
pixel_region_get_row (&srcPR, orig_x, orig_y + orig_height - 1 - i,
|
|
|
|
orig_width, buf, 1);
|
|
|
|
pixel_region_set_col (&destPR, new_x + i, new_y, new_height, buf);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ROTATE_180:
|
2003-10-06 20:17:11 +08:00
|
|
|
g_assert (new_width == orig_width);
|
2003-05-20 18:36:29 +08:00
|
|
|
buf = g_new (guchar, new_width * orig_bpp);
|
|
|
|
|
|
|
|
for (i = 0; i < orig_height; i++)
|
|
|
|
{
|
|
|
|
pixel_region_get_row (&srcPR, orig_x, orig_y + orig_height - 1 - i,
|
|
|
|
orig_width, buf, 1);
|
2003-10-06 20:17:11 +08:00
|
|
|
|
2003-05-20 18:36:29 +08:00
|
|
|
for (j = 0; j < orig_width / 2; j++)
|
2003-05-20 21:40:33 +08:00
|
|
|
{
|
|
|
|
guchar *left = buf + j * orig_bpp;
|
|
|
|
guchar *right = buf + (orig_width - 1 - j) * orig_bpp;
|
2003-10-06 20:17:11 +08:00
|
|
|
|
2003-05-20 21:40:33 +08:00
|
|
|
for (k = 0; k < orig_bpp; k++)
|
|
|
|
{
|
|
|
|
guchar tmp = left[k];
|
|
|
|
left[k] = right[k];
|
|
|
|
right[k] = tmp;
|
|
|
|
}
|
|
|
|
}
|
2003-05-20 18:36:29 +08:00
|
|
|
|
|
|
|
pixel_region_set_row (&destPR, new_x, new_y + i, new_width, buf);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ROTATE_270:
|
|
|
|
g_assert (new_width == orig_height);
|
|
|
|
buf = g_new (guchar, new_width * orig_bpp);
|
|
|
|
|
|
|
|
for (i = 0; i < orig_width; i++)
|
|
|
|
{
|
|
|
|
pixel_region_get_col (&srcPR, orig_x + orig_width - 1 - i, orig_y,
|
|
|
|
orig_height, buf, 1);
|
|
|
|
pixel_region_set_row (&destPR, new_x, new_y + i, new_width, buf);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (buf);
|
|
|
|
|
|
|
|
return new_tiles;
|
|
|
|
}
|
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
gboolean
|
|
|
|
gimp_drawable_transform_affine (GimpDrawable *drawable,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2003-07-07 21:50:48 +08:00
|
|
|
const GimpMatrix3 *matrix,
|
2003-05-12 23:56:36 +08:00
|
|
|
GimpTransformDirection direction,
|
|
|
|
GimpInterpolationType interpolation_type,
|
2004-03-13 19:24:25 +08:00
|
|
|
gboolean supersample,
|
2004-03-14 01:45:58 +08:00
|
|
|
gint recursion_level,
|
2004-08-31 22:17:33 +08:00
|
|
|
gboolean clip_result,
|
|
|
|
GimpProgress *progress)
|
2001-11-20 02:23:43 +08:00
|
|
|
{
|
|
|
|
GimpImage *gimage;
|
2003-05-14 18:51:14 +08:00
|
|
|
TileManager *orig_tiles;
|
2001-11-20 02:23:43 +08:00
|
|
|
gboolean new_layer;
|
|
|
|
gboolean success = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
|
2004-01-27 00:18:16 +08:00
|
|
|
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE);
|
2004-11-16 21:41:55 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
|
2003-05-12 23:56:36 +08:00
|
|
|
g_return_val_if_fail (matrix != NULL, FALSE);
|
2004-08-31 22:17:33 +08:00
|
|
|
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE);
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2002-02-26 01:58:50 +08:00
|
|
|
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
|
2001-11-20 02:23:43 +08:00
|
|
|
|
|
|
|
/* Start a transform undo group */
|
2003-05-16 05:01:02 +08:00
|
|
|
gimp_image_undo_group_start (gimage,
|
|
|
|
GIMP_UNDO_GROUP_TRANSFORM, _("Transform"));
|
2001-11-20 02:23:43 +08:00
|
|
|
|
|
|
|
/* Cut/Copy from the specified drawable */
|
2004-04-15 07:37:34 +08:00
|
|
|
orig_tiles = gimp_drawable_transform_cut (drawable, context, &new_layer);
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2003-05-14 18:51:14 +08:00
|
|
|
if (orig_tiles)
|
2001-11-20 02:23:43 +08:00
|
|
|
{
|
|
|
|
TileManager *new_tiles;
|
|
|
|
|
2004-11-02 01:21:55 +08:00
|
|
|
/* always clip unfloated tiles so they keep their size */
|
2003-05-14 18:51:14 +08:00
|
|
|
if (GIMP_IS_CHANNEL (drawable) && tile_manager_bpp (orig_tiles) == 1)
|
2003-05-13 21:57:11 +08:00
|
|
|
clip_result = TRUE;
|
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
/* transform the buffer */
|
2004-04-15 07:37:34 +08:00
|
|
|
new_tiles = gimp_drawable_transform_tiles_affine (drawable, context,
|
2003-05-14 18:51:14 +08:00
|
|
|
orig_tiles,
|
2001-11-20 02:23:43 +08:00
|
|
|
matrix,
|
|
|
|
GIMP_TRANSFORM_FORWARD,
|
2003-10-06 20:17:11 +08:00
|
|
|
interpolation_type,
|
2004-03-13 19:24:25 +08:00
|
|
|
supersample,
|
2004-03-14 01:45:58 +08:00
|
|
|
recursion_level,
|
2004-11-02 01:21:55 +08:00
|
|
|
clip_result,
|
2004-08-31 22:17:33 +08:00
|
|
|
progress);
|
2001-11-20 02:23:43 +08:00
|
|
|
|
|
|
|
/* Free the cut/copied buffer */
|
2003-05-27 01:02:06 +08:00
|
|
|
tile_manager_unref (orig_tiles);
|
2001-11-20 02:23:43 +08:00
|
|
|
|
|
|
|
if (new_tiles)
|
2003-05-27 01:02:06 +08:00
|
|
|
{
|
|
|
|
success = gimp_drawable_transform_paste (drawable, new_tiles,
|
|
|
|
new_layer);
|
|
|
|
tile_manager_unref (new_tiles);
|
|
|
|
}
|
2001-11-20 02:23:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* push the undo group end */
|
2003-02-13 19:23:50 +08:00
|
|
|
gimp_image_undo_group_end (gimage);
|
2001-11-20 02:23:43 +08:00
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2003-02-08 01:12:21 +08:00
|
|
|
gimp_drawable_transform_flip (GimpDrawable *drawable,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2004-10-27 01:50:52 +08:00
|
|
|
GimpOrientationType flip_type,
|
2004-11-02 01:21:55 +08:00
|
|
|
gboolean auto_center,
|
2004-10-27 01:50:52 +08:00
|
|
|
gdouble axis,
|
|
|
|
gboolean clip_result)
|
2001-11-20 02:23:43 +08:00
|
|
|
{
|
|
|
|
GimpImage *gimage;
|
2003-05-14 18:51:14 +08:00
|
|
|
TileManager *orig_tiles;
|
2001-11-20 02:23:43 +08:00
|
|
|
gboolean new_layer;
|
|
|
|
gboolean success = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
|
2004-01-27 00:18:16 +08:00
|
|
|
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE);
|
2004-11-16 21:41:55 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2002-02-26 01:58:50 +08:00
|
|
|
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
|
2001-11-20 02:23:43 +08:00
|
|
|
|
|
|
|
/* Start a transform undo group */
|
2003-05-20 18:36:29 +08:00
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_TRANSFORM, _("Flip"));
|
2001-11-20 02:23:43 +08:00
|
|
|
|
|
|
|
/* Cut/Copy from the specified drawable */
|
2004-04-15 07:37:34 +08:00
|
|
|
orig_tiles = gimp_drawable_transform_cut (drawable, context, &new_layer);
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2003-05-14 18:51:14 +08:00
|
|
|
if (orig_tiles)
|
2001-11-20 02:23:43 +08:00
|
|
|
{
|
|
|
|
TileManager *new_tiles;
|
2003-05-12 23:56:36 +08:00
|
|
|
|
2004-11-02 01:21:55 +08:00
|
|
|
if (auto_center)
|
2003-05-12 23:56:36 +08:00
|
|
|
{
|
2004-11-02 01:21:55 +08:00
|
|
|
gint off_x, off_y;
|
|
|
|
gint width, height;
|
|
|
|
|
|
|
|
tile_manager_get_offsets (orig_tiles, &off_x, &off_y);
|
|
|
|
width = tile_manager_width (orig_tiles);
|
|
|
|
height = tile_manager_height (orig_tiles);
|
|
|
|
|
2004-10-27 01:50:52 +08:00
|
|
|
switch (flip_type)
|
|
|
|
{
|
|
|
|
case GIMP_ORIENTATION_HORIZONTAL:
|
|
|
|
axis = ((gdouble) off_x + (gdouble) width / 2.0);
|
|
|
|
break;
|
2003-05-12 23:56:36 +08:00
|
|
|
|
2004-10-27 01:50:52 +08:00
|
|
|
case GIMP_ORIENTATION_VERTICAL:
|
|
|
|
axis = ((gdouble) off_y + (gdouble) height / 2.0);
|
|
|
|
break;
|
2003-05-12 23:56:36 +08:00
|
|
|
|
2004-10-27 01:50:52 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-05-12 23:56:36 +08:00
|
|
|
}
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2004-11-02 01:21:55 +08:00
|
|
|
/* always clip unfloated tiles so they keep their size */
|
|
|
|
if (GIMP_IS_CHANNEL (drawable) && tile_manager_bpp (orig_tiles) == 1)
|
|
|
|
clip_result = TRUE;
|
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
/* transform the buffer */
|
2004-04-15 07:37:34 +08:00
|
|
|
new_tiles = gimp_drawable_transform_tiles_flip (drawable, context,
|
|
|
|
orig_tiles,
|
2004-10-27 01:50:52 +08:00
|
|
|
flip_type, axis,
|
|
|
|
clip_result);
|
2001-11-20 02:23:43 +08:00
|
|
|
|
|
|
|
/* Free the cut/copied buffer */
|
2003-05-27 01:02:06 +08:00
|
|
|
tile_manager_unref (orig_tiles);
|
2001-11-20 02:23:43 +08:00
|
|
|
|
|
|
|
if (new_tiles)
|
2003-05-27 01:02:06 +08:00
|
|
|
{
|
|
|
|
success = gimp_drawable_transform_paste (drawable, new_tiles,
|
|
|
|
new_layer);
|
|
|
|
tile_manager_unref (new_tiles);
|
|
|
|
}
|
2001-11-20 02:23:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* push the undo group end */
|
2003-02-13 19:23:50 +08:00
|
|
|
gimp_image_undo_group_end (gimage);
|
2001-11-20 02:23:43 +08:00
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2003-05-20 18:36:29 +08:00
|
|
|
gboolean
|
|
|
|
gimp_drawable_transform_rotate (GimpDrawable *drawable,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2004-11-02 01:21:55 +08:00
|
|
|
GimpRotationType rotate_type,
|
|
|
|
gboolean auto_center,
|
|
|
|
gdouble center_x,
|
|
|
|
gdouble center_y,
|
|
|
|
gboolean clip_result)
|
2003-05-20 18:36:29 +08:00
|
|
|
{
|
|
|
|
GimpImage *gimage;
|
|
|
|
TileManager *orig_tiles;
|
|
|
|
gboolean new_layer;
|
|
|
|
gboolean success = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
|
2004-01-27 00:18:16 +08:00
|
|
|
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE);
|
2004-11-16 21:41:55 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
|
2003-05-20 18:36:29 +08:00
|
|
|
|
|
|
|
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
|
|
|
|
|
|
|
|
/* Start a transform undo group */
|
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_TRANSFORM, _("Rotate"));
|
|
|
|
|
|
|
|
/* Cut/Copy from the specified drawable */
|
2004-04-15 07:37:34 +08:00
|
|
|
orig_tiles = gimp_drawable_transform_cut (drawable, context, &new_layer);
|
2003-05-20 18:36:29 +08:00
|
|
|
|
|
|
|
if (orig_tiles)
|
|
|
|
{
|
|
|
|
TileManager *new_tiles;
|
|
|
|
|
2004-11-02 01:21:55 +08:00
|
|
|
if (auto_center)
|
|
|
|
{
|
|
|
|
gint off_x, off_y;
|
|
|
|
gint width, height;
|
|
|
|
|
|
|
|
tile_manager_get_offsets (orig_tiles, &off_x, &off_y);
|
|
|
|
width = tile_manager_width (orig_tiles);
|
|
|
|
height = tile_manager_height (orig_tiles);
|
|
|
|
|
|
|
|
center_x = (gdouble) off_x + (gdouble) width / 2.0;
|
|
|
|
center_y = (gdouble) off_y + (gdouble) height / 2.0;
|
|
|
|
}
|
2003-05-20 18:36:29 +08:00
|
|
|
|
2004-11-02 01:21:55 +08:00
|
|
|
/* always clip unfloated tiles so they keep their size */
|
|
|
|
if (GIMP_IS_CHANNEL (drawable) && tile_manager_bpp (orig_tiles) == 1)
|
|
|
|
clip_result = TRUE;
|
2003-05-20 18:36:29 +08:00
|
|
|
|
|
|
|
/* transform the buffer */
|
2004-04-15 07:37:34 +08:00
|
|
|
new_tiles = gimp_drawable_transform_tiles_rotate (drawable, context,
|
|
|
|
orig_tiles,
|
2003-05-20 18:36:29 +08:00
|
|
|
rotate_type,
|
|
|
|
center_x, center_y,
|
2004-11-02 01:21:55 +08:00
|
|
|
clip_result);
|
2003-05-20 18:36:29 +08:00
|
|
|
|
|
|
|
/* Free the cut/copied buffer */
|
2003-05-27 01:02:06 +08:00
|
|
|
tile_manager_unref (orig_tiles);
|
2003-05-20 18:36:29 +08:00
|
|
|
|
|
|
|
if (new_tiles)
|
2003-05-27 01:02:06 +08:00
|
|
|
{
|
|
|
|
success = gimp_drawable_transform_paste (drawable, new_tiles,
|
|
|
|
new_layer);
|
|
|
|
tile_manager_unref (new_tiles);
|
|
|
|
}
|
2003-05-20 18:36:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* push the undo group end */
|
|
|
|
gimp_image_undo_group_end (gimage);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
TileManager *
|
|
|
|
gimp_drawable_transform_cut (GimpDrawable *drawable,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2001-11-20 02:23:43 +08:00
|
|
|
gboolean *new_layer)
|
|
|
|
{
|
|
|
|
GimpImage *gimage;
|
2001-03-01 14:56:57 +08:00
|
|
|
TileManager *tiles;
|
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
2004-11-16 21:41:55 +08:00
|
|
|
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
|
2004-04-15 07:37:34 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2001-11-20 02:23:43 +08:00
|
|
|
g_return_val_if_fail (new_layer != NULL, NULL);
|
|
|
|
|
2002-02-26 01:58:50 +08:00
|
|
|
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2001-03-01 14:56:57 +08:00
|
|
|
/* extract the selected mask if there is a selection */
|
2003-09-03 23:13:19 +08:00
|
|
|
if (! gimp_channel_is_empty (gimp_image_get_mask (gimage)))
|
2001-03-01 14:56:57 +08:00
|
|
|
{
|
|
|
|
/* set the keep_indexed flag to FALSE here, since we use
|
2001-11-20 02:23:43 +08:00
|
|
|
* gimp_layer_new_from_tiles() later which assumes that the tiles
|
|
|
|
* are either RGB or GRAY. Eeek!!! (Sven)
|
2001-03-01 14:56:57 +08:00
|
|
|
*/
|
2003-10-06 20:17:11 +08:00
|
|
|
tiles = gimp_selection_extract (gimp_image_get_mask (gimage),
|
2004-04-15 07:37:34 +08:00
|
|
|
drawable, context, TRUE, FALSE, TRUE);
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2001-03-01 14:56:57 +08:00
|
|
|
*new_layer = TRUE;
|
|
|
|
}
|
2003-05-14 18:51:14 +08:00
|
|
|
else /* otherwise, just copy the layer */
|
2001-03-01 14:56:57 +08:00
|
|
|
{
|
|
|
|
if (GIMP_IS_LAYER (drawable))
|
2003-10-06 20:17:11 +08:00
|
|
|
tiles = gimp_selection_extract (gimp_image_get_mask (gimage),
|
2004-04-15 07:37:34 +08:00
|
|
|
drawable, context, FALSE, TRUE, TRUE);
|
2001-03-01 14:56:57 +08:00
|
|
|
else
|
2003-10-06 20:17:11 +08:00
|
|
|
tiles = gimp_selection_extract (gimp_image_get_mask (gimage),
|
2004-04-15 07:37:34 +08:00
|
|
|
drawable, context, FALSE, TRUE, FALSE);
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2001-03-01 14:56:57 +08:00
|
|
|
*new_layer = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2001-11-20 02:23:43 +08:00
|
|
|
gimp_drawable_transform_paste (GimpDrawable *drawable,
|
|
|
|
TileManager *tiles,
|
|
|
|
gboolean new_layer)
|
2001-03-01 14:56:57 +08:00
|
|
|
{
|
2001-11-20 02:23:43 +08:00
|
|
|
GimpImage *gimage;
|
2004-03-17 23:06:06 +08:00
|
|
|
GimpLayer *layer = NULL;
|
|
|
|
const gchar *undo_desc = NULL;
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
|
2004-01-27 00:18:16 +08:00
|
|
|
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE);
|
2001-11-20 02:23:43 +08:00
|
|
|
g_return_val_if_fail (tiles != NULL, FALSE);
|
|
|
|
|
2002-02-26 01:58:50 +08:00
|
|
|
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2004-03-17 23:06:06 +08:00
|
|
|
if (GIMP_IS_LAYER (drawable))
|
|
|
|
undo_desc = _("Transform Layer");
|
|
|
|
else if (GIMP_IS_CHANNEL (drawable))
|
|
|
|
undo_desc = _("Transform Channel");
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
tile_manager_get_offsets (tiles, &offset_x, &offset_y);
|
|
|
|
|
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_PASTE, undo_desc);
|
|
|
|
|
2001-03-01 14:56:57 +08:00
|
|
|
if (new_layer)
|
|
|
|
{
|
|
|
|
layer =
|
2004-03-17 23:06:06 +08:00
|
|
|
gimp_layer_new_from_tiles (tiles, gimage,
|
2002-11-10 07:15:22 +08:00
|
|
|
gimp_drawable_type_with_alpha (drawable),
|
2003-05-13 21:57:11 +08:00
|
|
|
_("Transformation"),
|
|
|
|
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2004-03-17 23:06:06 +08:00
|
|
|
GIMP_ITEM (layer)->offset_x = offset_x;
|
|
|
|
GIMP_ITEM (layer)->offset_y = offset_y;
|
2001-03-01 14:56:57 +08:00
|
|
|
|
|
|
|
floating_sel_attach (layer, drawable);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-04-13 21:54:54 +08:00
|
|
|
GimpImageType drawable_type;
|
2004-03-13 21:56:09 +08:00
|
|
|
|
2004-03-17 23:06:06 +08:00
|
|
|
if (GIMP_IS_LAYER (drawable) && (tile_manager_bpp (tiles) == 2 ||
|
|
|
|
tile_manager_bpp (tiles) == 4))
|
2004-03-13 21:56:09 +08:00
|
|
|
{
|
2004-03-17 23:06:06 +08:00
|
|
|
drawable_type = gimp_drawable_type_with_alpha (drawable);
|
2004-03-13 21:56:09 +08:00
|
|
|
}
|
2001-03-01 14:56:57 +08:00
|
|
|
else
|
2004-03-13 21:56:09 +08:00
|
|
|
{
|
2004-03-17 23:06:06 +08:00
|
|
|
drawable_type = gimp_drawable_type (drawable);
|
2003-05-19 02:48:36 +08:00
|
|
|
}
|
2001-03-01 14:56:57 +08:00
|
|
|
|
2004-03-17 23:06:06 +08:00
|
|
|
gimp_drawable_set_tiles_full (drawable, TRUE, NULL,
|
|
|
|
tiles, drawable_type,
|
2004-03-16 03:34:35 +08:00
|
|
|
offset_x, offset_y);
|
2001-03-01 14:56:57 +08:00
|
|
|
}
|
2004-01-21 19:38:53 +08:00
|
|
|
|
2004-03-17 23:06:06 +08:00
|
|
|
gimp_image_undo_group_end (gimage);
|
|
|
|
|
2004-01-21 19:38:53 +08:00
|
|
|
return TRUE;
|
2001-03-01 14:56:57 +08:00
|
|
|
}
|
|
|
|
|
2003-04-04 19:19:57 +08:00
|
|
|
#define BILINEAR(jk, j1k, jk1, j1k1, dx, dy) \
|
|
|
|
((1 - dy) * (jk + dx * (j1k - jk)) + \
|
|
|
|
dy * (jk1 + dx * (j1k1 - jk1)))
|
|
|
|
|
|
|
|
/* u & v are the subpixel coordinates of the point in
|
|
|
|
* the original selection's floating buffer.
|
|
|
|
* We need the two pixel coords around them:
|
|
|
|
* iu to iu + 1, iv to iv + 1
|
|
|
|
*/
|
2003-10-06 20:17:11 +08:00
|
|
|
static void
|
|
|
|
sample_linear (PixelSurround *surround,
|
2003-04-04 19:19:57 +08:00
|
|
|
gdouble u,
|
2003-10-06 20:17:11 +08:00
|
|
|
gdouble v,
|
2003-04-04 19:19:57 +08:00
|
|
|
guchar *color,
|
|
|
|
gint bytes,
|
|
|
|
gint alpha)
|
|
|
|
{
|
|
|
|
gdouble a_val, a_recip;
|
|
|
|
gint i;
|
|
|
|
gint iu = floor (u);
|
|
|
|
gint iv = floor (v);
|
|
|
|
gint row;
|
|
|
|
gdouble du,dv;
|
|
|
|
guchar *alphachan;
|
|
|
|
guchar *data;
|
|
|
|
|
|
|
|
/* lock the pixel surround */
|
|
|
|
data = pixel_surround_lock (surround, iu, iv);
|
|
|
|
|
|
|
|
row = pixel_surround_rowstride (surround);
|
|
|
|
|
|
|
|
/* the fractional error */
|
|
|
|
du = u - iu;
|
|
|
|
dv = v - iv;
|
|
|
|
|
|
|
|
/* calculate alpha value of result pixel */
|
|
|
|
alphachan = &data[alpha];
|
2003-10-06 20:17:11 +08:00
|
|
|
a_val = BILINEAR (alphachan[0], alphachan[bytes],
|
2003-04-04 19:19:57 +08:00
|
|
|
alphachan[row], alphachan[row+bytes], du, dv);
|
|
|
|
if (a_val <= 0.0)
|
|
|
|
{
|
|
|
|
a_recip = 0.0;
|
|
|
|
color[alpha] = 0.0;
|
|
|
|
}
|
|
|
|
else if (a_val >= 255.0)
|
|
|
|
{
|
|
|
|
a_recip = 1.0 / a_val;
|
|
|
|
color[alpha] = 255;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
a_recip = 1.0 / a_val;
|
|
|
|
color[alpha] = RINT (a_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for colour channels c,
|
|
|
|
* result = bilinear (c * alpha) / bilinear (alpha)
|
|
|
|
*
|
|
|
|
* never entered for alpha == 0
|
|
|
|
*/
|
|
|
|
for (i = 0; i < alpha; i++)
|
|
|
|
{
|
|
|
|
gint newval = (a_recip *
|
|
|
|
BILINEAR (alphachan[0] * data[i],
|
|
|
|
alphachan[bytes] * data[bytes+i],
|
|
|
|
alphachan[row] * data[row+i],
|
|
|
|
alphachan[row+bytes] * data[row+bytes+i],
|
|
|
|
du, dv));
|
|
|
|
|
|
|
|
color[i] = CLAMP (newval, 0, 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
pixel_surround_release (surround);
|
|
|
|
}
|
|
|
|
|
2004-10-28 03:25:50 +08:00
|
|
|
/* macros to handle conversion to/from fixed point, this fixed point code
|
|
|
|
* uses signed integers, by using 8 bits for the fractional part we have
|
|
|
|
*
|
|
|
|
* 1 bit sign
|
|
|
|
* 21 bits integer part
|
|
|
|
* 8 bit fractional part
|
|
|
|
*
|
|
|
|
* 1023 discrete subpixel sample positions should be enough for the needs
|
|
|
|
* of the supersampling algorithm, drawables where the dimensions have a need
|
|
|
|
* exceeding 2^21 ( 2097152px, will typically use terabytes of memory, when
|
|
|
|
* that is the common need, we can probably assume 64 bit integers and adjust
|
|
|
|
* FIXED_SHIFT accordingly.
|
|
|
|
*/
|
|
|
|
#define FIXED_SHIFT 10
|
|
|
|
#define FIXED_UNIT (1 << FIXED_SHIFT)
|
|
|
|
#define DOUBLE2FIXED(val) ((val) * FIXED_UNIT)
|
|
|
|
#define FIXED2DOUBLE(val) ((val) / FIXED_UNIT)
|
2003-04-04 19:19:57 +08:00
|
|
|
|
|
|
|
/*
|
2004-10-28 03:25:50 +08:00
|
|
|
bilinear interpolation of a fixed point pixel
|
2003-04-04 19:19:57 +08:00
|
|
|
*/
|
2003-10-06 20:17:11 +08:00
|
|
|
static void
|
2003-04-04 19:19:57 +08:00
|
|
|
sample_bi (TileManager *tm,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
guchar *color,
|
|
|
|
guchar *bg_color,
|
|
|
|
gint bpp,
|
|
|
|
gint alpha)
|
|
|
|
{
|
|
|
|
guchar C[4][4];
|
|
|
|
gint i;
|
2004-10-28 03:25:50 +08:00
|
|
|
gint xscale = (x & (FIXED_UNIT-1));
|
|
|
|
gint yscale = (y & (FIXED_UNIT-1));
|
2003-10-06 20:17:11 +08:00
|
|
|
|
2004-10-28 03:25:50 +08:00
|
|
|
gint x0 = x >> FIXED_SHIFT;
|
|
|
|
gint y0 = y >> FIXED_SHIFT;
|
2003-04-04 19:19:57 +08:00
|
|
|
gint x1 = x0 + 1;
|
|
|
|
gint y1 = y0 + 1;
|
|
|
|
|
|
|
|
|
|
|
|
/* fill the color with default values, since read_pixel_data_1
|
|
|
|
* does nothing, when accesses are out of bounds.
|
|
|
|
*/
|
2003-10-06 20:17:11 +08:00
|
|
|
for (i = 0; i < 4; i++)
|
2003-04-04 19:19:57 +08:00
|
|
|
*(guint*) (&C[i]) = *(guint*) (bg_color);
|
|
|
|
|
|
|
|
read_pixel_data_1 (tm, x0, y0, C[0]);
|
|
|
|
read_pixel_data_1 (tm, x1, y0, C[2]);
|
|
|
|
read_pixel_data_1 (tm, x0, y1, C[1]);
|
|
|
|
read_pixel_data_1 (tm, x1, y1, C[3]);
|
2003-10-06 20:17:11 +08:00
|
|
|
|
2003-04-04 19:19:57 +08:00
|
|
|
#define lerp(v1,v2,r) \
|
2004-10-28 03:25:50 +08:00
|
|
|
(((guint)(v1) * (FIXED_UNIT - (guint)(r)) + \
|
|
|
|
(guint)(v2) * (guint)(r)) >> FIXED_SHIFT)
|
2003-04-04 19:19:57 +08:00
|
|
|
|
|
|
|
color[alpha]= lerp (lerp (C[0][alpha], C[1][alpha], yscale),
|
|
|
|
lerp (C[2][alpha], C[3][alpha], yscale), xscale);
|
|
|
|
|
|
|
|
if (color[alpha])
|
|
|
|
{ /* to avoid problems, calculate with premultiplied alpha */
|
|
|
|
for (i=0; i<alpha; i++)
|
|
|
|
{
|
|
|
|
C[0][i] = (C[0][i] * C[0][alpha] / 255);
|
|
|
|
C[1][i] = (C[1][i] * C[1][alpha] / 255);
|
|
|
|
C[2][i] = (C[2][i] * C[2][alpha] / 255);
|
|
|
|
C[3][i] = (C[3][i] * C[3][alpha] / 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < alpha; i++)
|
|
|
|
color[i] = lerp (lerp (C[0][i], C[1][i], yscale),
|
|
|
|
lerp (C[2][i], C[3][i], yscale), xscale);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-10-06 20:17:11 +08:00
|
|
|
for (i = 0; i < alpha; i++)
|
2003-04-04 19:19:57 +08:00
|
|
|
color[i] = 0;
|
|
|
|
}
|
|
|
|
#undef lerp
|
|
|
|
}
|
|
|
|
|
2004-10-28 03:25:50 +08:00
|
|
|
|
|
|
|
|
2003-10-06 20:17:11 +08:00
|
|
|
/*
|
2003-04-04 19:19:57 +08:00
|
|
|
* Returns TRUE if one of the deltas of the
|
|
|
|
* quad edge is > 1.0 (16.16 fixed values).
|
|
|
|
*/
|
2003-10-06 20:17:11 +08:00
|
|
|
static gboolean
|
2003-04-04 19:19:57 +08:00
|
|
|
supersample_test (gint x0, gint y0,
|
|
|
|
gint x1, gint y1,
|
|
|
|
gint x2, gint y2,
|
|
|
|
gint x3, gint y3)
|
|
|
|
{
|
2004-10-28 03:25:50 +08:00
|
|
|
if (abs (x0 - x1) > FIXED_UNIT ||
|
|
|
|
abs (x1 - x2) > FIXED_UNIT ||
|
|
|
|
abs (x2 - x3) > FIXED_UNIT ||
|
|
|
|
abs (x3 - x0) > FIXED_UNIT ||
|
2003-10-06 20:17:11 +08:00
|
|
|
|
2004-10-28 03:25:50 +08:00
|
|
|
abs (y0 - y1) > FIXED_UNIT ||
|
|
|
|
abs (y1 - y2) > FIXED_UNIT ||
|
|
|
|
abs (y2 - y3) > FIXED_UNIT ||
|
|
|
|
abs (y3 - y0) > FIXED_UNIT) return TRUE;
|
2003-04-04 19:19:57 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-10-06 20:17:11 +08:00
|
|
|
/*
|
2003-04-04 19:19:57 +08:00
|
|
|
* Returns TRUE if one of the deltas of the
|
|
|
|
* quad edge is > 1.0 (double values).
|
|
|
|
*/
|
2003-10-06 20:17:11 +08:00
|
|
|
static gboolean
|
2003-04-04 19:19:57 +08:00
|
|
|
supersample_dtest (gdouble x0, gdouble y0,
|
|
|
|
gdouble x1, gdouble y1,
|
|
|
|
gdouble x2, gdouble y2,
|
|
|
|
gdouble x3, gdouble y3)
|
|
|
|
{
|
2004-10-28 03:25:50 +08:00
|
|
|
if (fabs (x0 - x1) > 1.0 ||
|
|
|
|
fabs (x1 - x2) > 1.0 ||
|
|
|
|
fabs (x2 - x3) > 1.0 ||
|
|
|
|
fabs (x3 - x0) > 1.0 ||
|
2003-10-06 20:17:11 +08:00
|
|
|
|
2004-10-28 03:25:50 +08:00
|
|
|
fabs (y0 - y1) > 1.0 ||
|
|
|
|
fabs (y1 - y2) > 1.0 ||
|
|
|
|
fabs (y2 - y3) > 1.0 ||
|
|
|
|
fabs (y3 - y0) > 1.0)
|
|
|
|
return TRUE;
|
2003-04-04 19:19:57 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
sample a grid that is spaced according to the quadraliteral's edges,
|
|
|
|
it subdivides a maximum of level times before sampling.
|
|
|
|
0..3 is a cycle around the quad
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
get_sample (TileManager *tm,
|
|
|
|
gint xc, gint yc,
|
|
|
|
gint x0, gint y0,
|
|
|
|
gint x1, gint y1,
|
|
|
|
gint x2, gint y2,
|
|
|
|
gint x3, gint y3,
|
|
|
|
gint *cc,
|
|
|
|
gint level,
|
|
|
|
guint *color,
|
|
|
|
guchar *bg_color,
|
|
|
|
gint bpp,
|
|
|
|
gint alpha)
|
|
|
|
{
|
|
|
|
if (!level || !supersample_test (x0, y0, x1, y1, x2, y2, x3, y3))
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
guchar C[4];
|
2003-10-06 20:17:11 +08:00
|
|
|
|
2003-04-04 19:19:57 +08:00
|
|
|
sample_bi (tm, xc, yc, C, bg_color, bpp, alpha);
|
|
|
|
|
|
|
|
for (i = 0; i < bpp; i++)
|
|
|
|
color[i]+= C[i];
|
|
|
|
|
|
|
|
(*cc)++; /* increase number of samples taken */
|
|
|
|
}
|
2003-10-06 20:17:11 +08:00
|
|
|
else
|
2003-04-04 19:19:57 +08:00
|
|
|
{
|
|
|
|
gint tx, lx, rx, bx, tlx, trx, blx, brx;
|
|
|
|
gint ty, ly, ry, by, tly, try, bly, bry;
|
|
|
|
|
|
|
|
/* calculate subdivided corner coordinates (including centercoords
|
2003-10-06 20:17:11 +08:00
|
|
|
thus using a bilinear interpolation,. almost as good as
|
2003-04-04 19:19:57 +08:00
|
|
|
doing the perspective transform for each subpixel coordinate*/
|
|
|
|
|
2004-10-28 03:25:50 +08:00
|
|
|
tx = (x0 + x1) / 2;
|
|
|
|
tlx = (x0 + xc) / 2;
|
|
|
|
trx = (x1 + xc) / 2;
|
|
|
|
lx = (x0 + x3) / 2;
|
|
|
|
rx = (x1 + x2) / 2;
|
|
|
|
blx = (x3 + xc) / 2;
|
|
|
|
brx = (x2 + xc) / 2;
|
|
|
|
bx = (x3 + x2) / 2;
|
|
|
|
|
|
|
|
ty = (y0 + y1) / 2;
|
|
|
|
tly = (y0 + yc) / 2;
|
|
|
|
try = (y1 + yc) / 2;
|
|
|
|
ly = (y0 + y3) / 2;
|
|
|
|
ry = (y1 + y2) / 2;
|
|
|
|
bly = (y3 + yc) / 2;
|
|
|
|
bry = (y2 + yc) / 2;
|
|
|
|
by = (y3 + y2) / 2;
|
2003-04-04 19:19:57 +08:00
|
|
|
|
|
|
|
get_sample (tm,
|
2003-10-06 20:17:11 +08:00
|
|
|
tlx,tly,
|
2003-04-04 19:19:57 +08:00
|
|
|
x0,y0, tx,ty, xc,yc, lx,ly,
|
|
|
|
cc, level-1, color, bg_color, bpp, alpha);
|
|
|
|
|
|
|
|
get_sample (tm,
|
|
|
|
trx,try,
|
|
|
|
tx,ty, x1,y1, rx,ry, xc,yc,
|
|
|
|
cc, level-1, color, bg_color, bpp, alpha);
|
|
|
|
|
|
|
|
get_sample (tm,
|
|
|
|
brx,bry,
|
|
|
|
xc,yc, rx,ry, x2,y2, bx,by,
|
|
|
|
cc, level-1, color, bg_color, bpp, alpha);
|
|
|
|
|
|
|
|
get_sample (tm,
|
|
|
|
blx,bly,
|
|
|
|
lx,ly, xc,yc, bx,by, x3,y3,
|
|
|
|
cc, level-1, color, bg_color, bpp, alpha);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-06 20:17:11 +08:00
|
|
|
static void
|
2003-04-04 19:19:57 +08:00
|
|
|
sample_adapt (TileManager *tm,
|
|
|
|
gdouble xc, gdouble yc,
|
|
|
|
gdouble x0, gdouble y0,
|
|
|
|
gdouble x1, gdouble y1,
|
|
|
|
gdouble x2, gdouble y2,
|
|
|
|
gdouble x3, gdouble y3,
|
|
|
|
gint level,
|
|
|
|
guchar *color,
|
|
|
|
guchar *bg_color,
|
|
|
|
gint bpp,
|
|
|
|
gint alpha)
|
|
|
|
{
|
|
|
|
gint cc = 0;
|
|
|
|
gint i;
|
|
|
|
guint C[MAX_CHANNELS];
|
|
|
|
|
|
|
|
C[0] = C[1] = C[2] = C[3] = 0;
|
|
|
|
|
|
|
|
get_sample (tm,
|
2004-10-28 03:25:50 +08:00
|
|
|
DOUBLE2FIXED (xc), DOUBLE2FIXED (yc),
|
|
|
|
DOUBLE2FIXED (x0), DOUBLE2FIXED (y0),
|
|
|
|
DOUBLE2FIXED (x1), DOUBLE2FIXED (y1),
|
|
|
|
DOUBLE2FIXED (x2), DOUBLE2FIXED (y2),
|
|
|
|
DOUBLE2FIXED (x3), DOUBLE2FIXED (y3),
|
2003-04-04 19:19:57 +08:00
|
|
|
&cc, level, C, bg_color, bpp, alpha);
|
2003-05-06 02:45:58 +08:00
|
|
|
|
2003-04-04 19:19:57 +08:00
|
|
|
if (!cc)
|
|
|
|
cc=1;
|
|
|
|
|
|
|
|
color[alpha] = C[alpha] / cc;
|
|
|
|
|
|
|
|
if (color[alpha])
|
|
|
|
{
|
|
|
|
/* go from premultiplied to postmultiplied alpha */
|
|
|
|
for (i = 0; i < alpha; i++)
|
|
|
|
color[i] = ((C[i] / cc) * 255) / color[alpha];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < alpha; i++)
|
|
|
|
color[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* access interleaved pixels */
|
|
|
|
#define CUBIC_ROW(dx, row, step) \
|
|
|
|
gimp_drawable_transform_cubic(dx,\
|
|
|
|
(row)[0], (row)[step], (row)[step+step], (row)[step+step+step])
|
|
|
|
|
|
|
|
#define CUBIC_SCALED_ROW(dx, row, arow, step) \
|
|
|
|
gimp_drawable_transform_cubic(dx, \
|
|
|
|
(arow)[0] * (row)[0], \
|
|
|
|
(arow)[step] * (row)[step], \
|
|
|
|
(arow)[step+step] * (row)[step+step], \
|
|
|
|
(arow)[step+step+step] * (row)[step+step+step])
|
|
|
|
|
|
|
|
|
2004-06-14 21:38:31 +08:00
|
|
|
/* Note: cubic function no longer clips result. */
|
|
|
|
/* Inlining this function makes sample_cubic() run about 10% faster. (Sven) */
|
|
|
|
static inline gdouble
|
2001-11-20 02:23:43 +08:00
|
|
|
gimp_drawable_transform_cubic (gdouble dx,
|
|
|
|
gint jm1,
|
|
|
|
gint j,
|
|
|
|
gint jp1,
|
|
|
|
gint jp2)
|
2001-03-01 14:56:57 +08:00
|
|
|
{
|
|
|
|
gdouble result;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Equivalent to Gimp 1.1.1 and earlier - some ringing */
|
|
|
|
result = ((( ( - jm1 + j - jp1 + jp2 ) * dx +
|
|
|
|
( jm1 + jm1 - j - j + jp1 - jp2 ) ) * dx +
|
|
|
|
( - jm1 + jp1 ) ) * dx + j );
|
|
|
|
/* Recommended by Mitchell and Netravali - too blurred? */
|
|
|
|
result = ((( ( - 7 * jm1 + 21 * j - 21 * jp1 + 7 * jp2 ) * dx +
|
|
|
|
( 15 * jm1 - 36 * j + 27 * jp1 - 6 * jp2 ) ) * dx +
|
|
|
|
( - 9 * jm1 + 9 * jp1 ) ) * dx + (jm1 + 16 * j + jp1) ) / 18.0;
|
2001-08-01 08:35:59 +08:00
|
|
|
#endif
|
2001-03-01 14:56:57 +08:00
|
|
|
|
|
|
|
/* Catmull-Rom - not bad */
|
|
|
|
result = ((( ( - jm1 + 3 * j - 3 * jp1 + jp2 ) * dx +
|
|
|
|
( 2 * jm1 - 5 * j + 4 * jp1 - jp2 ) ) * dx +
|
|
|
|
( - jm1 + jp1 ) ) * dx + (j + j) ) / 2.0;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2003-04-04 19:19:57 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* u & v are the subpixel coordinates of the point in
|
|
|
|
* the original selection's floating buffer.
|
|
|
|
* We need the four integer pixel coords around them:
|
|
|
|
* iu to iu + 3, iv to iv + 3
|
|
|
|
*/
|
2003-10-06 20:17:11 +08:00
|
|
|
static void
|
|
|
|
sample_cubic (PixelSurround *surround,
|
2003-04-04 19:19:57 +08:00
|
|
|
gdouble u,
|
2003-10-06 20:17:11 +08:00
|
|
|
gdouble v,
|
2003-04-04 19:19:57 +08:00
|
|
|
guchar *color,
|
|
|
|
gint bytes,
|
|
|
|
gint alpha)
|
|
|
|
{
|
|
|
|
gdouble a_val, a_recip;
|
|
|
|
gint i;
|
|
|
|
gint iu = floor(u);
|
|
|
|
gint iv = floor(v);
|
|
|
|
gint row;
|
|
|
|
gdouble du,dv;
|
|
|
|
guchar *data;
|
|
|
|
|
|
|
|
/* lock the pixel surround */
|
|
|
|
data = pixel_surround_lock (surround, iu - 1 , iv - 1 );
|
|
|
|
|
|
|
|
row = pixel_surround_rowstride (surround);
|
|
|
|
|
|
|
|
/* the fractional error */
|
|
|
|
du = u - iu;
|
|
|
|
dv = v - iv;
|
|
|
|
|
|
|
|
/* calculate alpha of result */
|
|
|
|
a_val = gimp_drawable_transform_cubic
|
|
|
|
(dv,
|
|
|
|
CUBIC_ROW (du, data + alpha + row * 0, bytes),
|
|
|
|
CUBIC_ROW (du, data + alpha + row * 1, bytes),
|
|
|
|
CUBIC_ROW (du, data + alpha + row * 2, bytes),
|
|
|
|
CUBIC_ROW (du, data + alpha + row * 3, bytes));
|
|
|
|
|
|
|
|
if (a_val <= 0.0)
|
|
|
|
{
|
|
|
|
a_recip = 0.0;
|
|
|
|
color[alpha] = 0;
|
|
|
|
}
|
|
|
|
else if (a_val > 255.0)
|
|
|
|
{
|
|
|
|
a_recip = 1.0 / a_val;
|
|
|
|
color[alpha] = 255;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
a_recip = 1.0 / a_val;
|
|
|
|
color[alpha] = RINT (a_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for colour channels c,
|
|
|
|
* result = bicubic (c * alpha) / bicubic (alpha)
|
|
|
|
*
|
|
|
|
* never entered for alpha == 0
|
|
|
|
*/
|
|
|
|
for (i = 0; i < alpha; i++)
|
|
|
|
{
|
|
|
|
gint newval = (a_recip *
|
|
|
|
gimp_drawable_transform_cubic
|
|
|
|
(dv,
|
|
|
|
CUBIC_SCALED_ROW (du, i + data + row * 0, data + alpha + row * 0, bytes),
|
|
|
|
CUBIC_SCALED_ROW (du, i + data + row * 1, data + alpha + row * 1, bytes),
|
|
|
|
CUBIC_SCALED_ROW (du, i + data + row * 2, data + alpha + row * 2, bytes),
|
|
|
|
CUBIC_SCALED_ROW (du, i + data + row * 3, data + alpha + row * 3, bytes)));
|
|
|
|
|
|
|
|
color[i] = CLAMP (newval, 0, 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
pixel_surround_release (surround);
|
|
|
|
}
|
2005-01-12 02:31:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* Lanczos */
|
|
|
|
|
|
|
|
static inline gdouble
|
|
|
|
sinc (gdouble x)
|
|
|
|
{
|
|
|
|
gdouble y = x * G_PI;
|
|
|
|
|
|
|
|
if (ABS (x) < EPSILON)
|
|
|
|
return 1.0;
|
|
|
|
|
|
|
|
return sin (y) / y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline gdouble
|
|
|
|
lanczos_sum (const guchar *buffer,
|
|
|
|
gdouble *l,
|
|
|
|
gint row,
|
|
|
|
gint bytes,
|
|
|
|
gint byte)
|
|
|
|
{
|
|
|
|
gdouble sum = 0;
|
|
|
|
gint j, k, p;
|
|
|
|
|
|
|
|
p = row * bytes * LANCZOS_WIDTH2;
|
|
|
|
|
|
|
|
for (k = 0, j = 0; j < LANCZOS_WIDTH2; j++, k++)
|
|
|
|
sum += l[k] * (buffer + p)[j * bytes + byte];
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline gdouble
|
2005-01-16 04:46:21 +08:00
|
|
|
lanczos_sum_mul (const guchar *buffer,
|
|
|
|
const gdouble *l,
|
|
|
|
gint row,
|
|
|
|
gint bytes,
|
|
|
|
gint byte,
|
|
|
|
gint alpha)
|
2005-01-12 02:31:07 +08:00
|
|
|
{
|
|
|
|
gdouble sum = 0;
|
|
|
|
gint j, k, p;
|
|
|
|
|
|
|
|
p = row * bytes * LANCZOS_WIDTH2;
|
2005-01-16 04:46:21 +08:00
|
|
|
|
2005-01-12 02:31:07 +08:00
|
|
|
for (k = 0, j = 0; j < LANCZOS_WIDTH2; j++, k++)
|
|
|
|
sum += (l[k] *
|
|
|
|
(buffer + p)[j * bytes + byte] *
|
|
|
|
(buffer + p)[j * bytes + alpha]);
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gdouble *
|
|
|
|
kernel_lanczos (void)
|
|
|
|
{
|
|
|
|
gdouble *kernel ;
|
|
|
|
gdouble x = 0.0;
|
|
|
|
gdouble dx = (gdouble) LANCZOS_WIDTH / (gdouble) (LANCZOS_SAMPLES - 1);
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
kernel = g_new (gdouble, LANCZOS_SAMPLES);
|
|
|
|
|
|
|
|
for (i = 0 ;i < LANCZOS_SAMPLES; i++)
|
|
|
|
{
|
|
|
|
kernel[i] = ((ABS (x) < LANCZOS_WIDTH) ?
|
|
|
|
(sinc (x) * sinc (x / LANCZOS_WIDTH)) : 0.0);
|
|
|
|
x += dx;
|
|
|
|
}
|
|
|
|
|
|
|
|
return kernel;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sample_lanczos (const gdouble *kernel,
|
|
|
|
gint su,
|
|
|
|
gint sv,
|
|
|
|
guchar *color,
|
2005-01-16 04:46:21 +08:00
|
|
|
const guchar *buffer,
|
2005-01-12 02:31:07 +08:00
|
|
|
gint bytes,
|
|
|
|
gint alpha)
|
|
|
|
{
|
|
|
|
|
|
|
|
gdouble lu[LANCZOS_WIDTH2]; /* Lanczos sample value */
|
|
|
|
gdouble lv[LANCZOS_WIDTH2]; /* Lanczos sample value */
|
|
|
|
gdouble lusum, lvsum, weight; /* Lanczos weighting vars */
|
|
|
|
gint i,j,row, byte; /* loop vars to fill source window */
|
|
|
|
|
|
|
|
gdouble aval, arecip; /* Handle alpha values */
|
|
|
|
gdouble newval; /* New interpolated RGB value */
|
|
|
|
|
|
|
|
|
|
|
|
for (lusum = lvsum = i = 0, j = LANCZOS_WIDTH - 1;
|
|
|
|
j >= - LANCZOS_WIDTH;
|
|
|
|
j--, i++)
|
|
|
|
{
|
|
|
|
lusum += lu[i] = kernel[ABS (j * LANCZOS_SPP + su)];
|
|
|
|
lvsum += lv[i] = kernel[ABS (j * LANCZOS_SPP + sv)];
|
|
|
|
}
|
|
|
|
|
|
|
|
weight = lusum * lvsum;
|
|
|
|
|
|
|
|
if (alpha != 0)
|
|
|
|
{
|
|
|
|
for ( aval = 0, row = 0 ; row < LANCZOS_WIDTH2 ; row ++ )
|
|
|
|
aval += lv[row] * lanczos_sum (buffer, lu, row, bytes, alpha);
|
|
|
|
|
|
|
|
/* calculate alpha of result */
|
|
|
|
aval /= weight;
|
|
|
|
|
|
|
|
if ( aval <= 0.0 )
|
|
|
|
{
|
|
|
|
arecip = 0.0;
|
|
|
|
color[alpha] = 0;
|
|
|
|
}
|
|
|
|
else if ( aval > 255.0 )
|
|
|
|
{
|
|
|
|
arecip = 1.0 / aval;
|
|
|
|
color[alpha] = 255;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
arecip = 1.0 / aval;
|
|
|
|
color[alpha] = RINT (aval);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (byte = 0; byte < alpha; byte++)
|
|
|
|
{
|
|
|
|
for (newval = 0, row = 0; row < LANCZOS_WIDTH2; row ++)
|
|
|
|
newval += lv[row] * lanczos_sum_mul (buffer, lu,
|
|
|
|
row, bytes, byte, alpha);
|
|
|
|
newval *= arecip;
|
|
|
|
color[byte] = CLAMP (newval, 0, 255);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (byte = 0; byte < bytes; byte++)
|
|
|
|
{
|
|
|
|
for (newval = 0, row = 0 ; row < LANCZOS_WIDTH2 ; row++ )
|
|
|
|
newval += lv[row] * lanczos_sum (buffer, lu, row, bytes, byte);
|
|
|
|
|
|
|
|
newval /= weight;
|
|
|
|
color[byte] = CLAMP ((gint) newval, 0, 255);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/* Lanczos */
|