2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-01-04 02:01:30 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-01-04 02:01:30 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-01-04 02:01:30 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-01-04 02:01:30 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2003-01-04 02:01:30 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2007-03-09 21:00:01 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2003-01-04 02:01:30 +08:00
|
|
|
#include "display-types.h"
|
|
|
|
|
2006-08-09 22:05:00 +08:00
|
|
|
#include "base/boundary.h"
|
|
|
|
|
2003-01-04 02:01:30 +08:00
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
|
|
|
#include "gimpdisplay.h"
|
|
|
|
#include "gimpdisplayshell.h"
|
2008-07-12 03:31:45 +08:00
|
|
|
#include "gimpdisplayshell-scroll.h"
|
2003-01-04 02:01:30 +08:00
|
|
|
#include "gimpdisplayshell-transform.h"
|
|
|
|
|
|
|
|
|
2004-07-16 07:02:52 +08:00
|
|
|
/**
|
2011-02-20 23:29:20 +08:00
|
|
|
* gimp_display_shell_transform_coords:
|
2004-07-16 18:07:30 +08:00
|
|
|
* @shell: a #GimpDisplayShell
|
|
|
|
* @image_coords: image coordinates
|
|
|
|
* @display_coords: returns the corresponding display coordinates
|
2004-07-16 07:02:52 +08:00
|
|
|
*
|
2004-07-16 18:07:30 +08:00
|
|
|
* Transforms from image coordinates to display coordinates, so that
|
|
|
|
* objects can be rendered at the correct points on the display.
|
2004-07-16 07:02:52 +08:00
|
|
|
**/
|
2003-01-04 02:01:30 +08:00
|
|
|
void
|
2011-02-20 23:29:20 +08:00
|
|
|
gimp_display_shell_transform_coords (const GimpDisplayShell *shell,
|
|
|
|
const GimpCoords *image_coords,
|
|
|
|
GimpCoords *display_coords)
|
2003-01-04 02:01:30 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
g_return_if_fail (image_coords != NULL);
|
|
|
|
g_return_if_fail (display_coords != NULL);
|
|
|
|
|
|
|
|
*display_coords = *image_coords;
|
|
|
|
|
2007-12-29 07:13:46 +08:00
|
|
|
display_coords->x = SCALEX (shell, image_coords->x);
|
|
|
|
display_coords->y = SCALEY (shell, image_coords->y);
|
2003-01-04 02:01:30 +08:00
|
|
|
|
2008-11-14 07:16:11 +08:00
|
|
|
display_coords->x -= shell->offset_x;
|
|
|
|
display_coords->y -= shell->offset_y;
|
2003-01-04 02:01:30 +08:00
|
|
|
}
|
|
|
|
|
2004-07-16 07:02:52 +08:00
|
|
|
/**
|
2011-02-20 23:29:20 +08:00
|
|
|
* gimp_display_shell_untransform_coords:
|
2004-07-16 18:07:30 +08:00
|
|
|
* @shell: a #GimpDisplayShell
|
|
|
|
* @display_coords: display coordinates
|
2006-08-09 21:15:49 +08:00
|
|
|
* @image_coords: returns the corresponding image coordinates
|
2004-07-16 07:02:52 +08:00
|
|
|
*
|
2004-07-16 18:07:30 +08:00
|
|
|
* Transforms from display coordinates to image coordinates, so that
|
|
|
|
* points on the display can be mapped to points in the image.
|
2004-07-16 07:02:52 +08:00
|
|
|
**/
|
2003-01-04 02:01:30 +08:00
|
|
|
void
|
2011-02-20 23:29:20 +08:00
|
|
|
gimp_display_shell_untransform_coords (const GimpDisplayShell *shell,
|
|
|
|
const GimpCoords *display_coords,
|
|
|
|
GimpCoords *image_coords)
|
2003-01-04 02:01:30 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
g_return_if_fail (display_coords != NULL);
|
|
|
|
g_return_if_fail (image_coords != NULL);
|
|
|
|
|
|
|
|
*image_coords = *display_coords;
|
|
|
|
|
2008-11-14 07:16:11 +08:00
|
|
|
image_coords->x = display_coords->x + shell->offset_x;
|
|
|
|
image_coords->y = display_coords->y + shell->offset_y;
|
2003-01-04 02:01:30 +08:00
|
|
|
|
2007-03-14 18:26:19 +08:00
|
|
|
image_coords->x /= shell->scale_x;
|
|
|
|
image_coords->y /= shell->scale_y;
|
2003-01-04 02:01:30 +08:00
|
|
|
}
|
|
|
|
|
2010-06-15 03:14:19 +08:00
|
|
|
/**
|
|
|
|
* gimp_display_shell_transform_xy:
|
|
|
|
* @shell:
|
|
|
|
* @x:
|
|
|
|
* @y:
|
|
|
|
* @nx:
|
|
|
|
* @ny:
|
|
|
|
*
|
|
|
|
* Transforms an image coordinate to a shell coordinate.
|
|
|
|
**/
|
2003-01-04 02:01:30 +08:00
|
|
|
void
|
2008-08-10 18:09:03 +08:00
|
|
|
gimp_display_shell_transform_xy (const GimpDisplayShell *shell,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint *nx,
|
2010-09-23 16:50:39 +08:00
|
|
|
gint *ny)
|
2003-01-04 02:01:30 +08:00
|
|
|
{
|
2008-02-05 18:36:44 +08:00
|
|
|
gint64 tx;
|
|
|
|
gint64 ty;
|
2003-01-04 02:01:30 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
g_return_if_fail (nx != NULL);
|
|
|
|
g_return_if_fail (ny != NULL);
|
|
|
|
|
2008-02-05 18:36:44 +08:00
|
|
|
tx = ((gint64) x * shell->x_src_dec) / shell->x_dest_inc;
|
|
|
|
ty = ((gint64) y * shell->y_src_dec) / shell->y_dest_inc;
|
2007-10-01 01:24:47 +08:00
|
|
|
|
2008-11-14 07:16:11 +08:00
|
|
|
tx -= shell->offset_x;
|
|
|
|
ty -= shell->offset_y;
|
2004-03-21 05:59:41 +08:00
|
|
|
|
2007-10-01 01:24:47 +08:00
|
|
|
/* The projected coordinates might overflow a gint in the case of big
|
|
|
|
images at high zoom levels, so we clamp them here to avoid problems. */
|
|
|
|
*nx = CLAMP (tx, G_MININT, G_MAXINT);
|
|
|
|
*ny = CLAMP (ty, G_MININT, G_MAXINT);
|
2003-01-04 02:01:30 +08:00
|
|
|
}
|
|
|
|
|
2004-07-16 07:02:52 +08:00
|
|
|
/**
|
|
|
|
* gimp_display_shell_untransform_xy:
|
2004-07-16 18:07:30 +08:00
|
|
|
* @shell: a #GimpDisplayShell
|
2004-07-16 07:02:52 +08:00
|
|
|
* @x: x coordinate in display coordinates
|
|
|
|
* @y: y coordinate in display coordinates
|
2004-07-16 18:07:30 +08:00
|
|
|
* @nx: returns x oordinate in image coordinates
|
|
|
|
* @ny: returns y coordinate in image coordinates
|
2004-07-16 07:02:52 +08:00
|
|
|
* @round: if %TRUE, round the results to the nearest integer;
|
|
|
|
* if %FALSE, simply cast them to @gint.
|
|
|
|
*
|
|
|
|
* Transform from display coordinates to image coordinates, so that
|
|
|
|
* points on the display can be mapped to the corresponding points
|
|
|
|
* in the image.
|
|
|
|
**/
|
2003-01-04 02:01:30 +08:00
|
|
|
void
|
2008-08-10 18:09:03 +08:00
|
|
|
gimp_display_shell_untransform_xy (const GimpDisplayShell *shell,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint *nx,
|
|
|
|
gint *ny,
|
2010-09-23 16:50:39 +08:00
|
|
|
gboolean round)
|
2003-01-04 02:01:30 +08:00
|
|
|
{
|
2008-02-05 18:36:44 +08:00
|
|
|
gint64 tx;
|
|
|
|
gint64 ty;
|
2003-01-04 02:01:30 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
g_return_if_fail (nx != NULL);
|
|
|
|
g_return_if_fail (ny != NULL);
|
|
|
|
|
2008-11-14 07:16:11 +08:00
|
|
|
tx = (gint64) x + shell->offset_x;
|
|
|
|
ty = (gint64) y + shell->offset_y;
|
2007-10-01 01:24:47 +08:00
|
|
|
|
|
|
|
tx *= shell->x_dest_inc;
|
|
|
|
ty *= shell->y_dest_inc;
|
|
|
|
|
|
|
|
tx += round ? shell->x_dest_inc : shell->x_dest_inc >> 1;
|
|
|
|
ty += round ? shell->y_dest_inc : shell->y_dest_inc >> 1;
|
|
|
|
|
|
|
|
tx /= shell->x_src_dec;
|
|
|
|
ty /= shell->y_src_dec;
|
|
|
|
|
2010-09-23 16:50:39 +08:00
|
|
|
*nx = CLAMP (tx, G_MININT, G_MAXINT);
|
|
|
|
*ny = CLAMP (ty, G_MININT, G_MAXINT);
|
2003-01-04 02:01:30 +08:00
|
|
|
}
|
|
|
|
|
2004-07-16 07:02:52 +08:00
|
|
|
/**
|
|
|
|
* gimp_display_shell_transform_xy_f:
|
2010-10-25 20:14:01 +08:00
|
|
|
* @shell: a #GimpDisplayShell
|
|
|
|
* @x: image x coordinate of point
|
|
|
|
* @y: image y coordinate of point
|
|
|
|
* @nx: returned shell canvas x coordinate
|
|
|
|
* @ny: returned shell canvas y coordinate
|
2004-07-16 07:02:52 +08:00
|
|
|
*
|
2010-10-25 20:14:01 +08:00
|
|
|
* Transforms from image coordinates to display shell canvas
|
|
|
|
* coordinates.
|
2004-07-16 07:02:52 +08:00
|
|
|
**/
|
2003-01-04 02:01:30 +08:00
|
|
|
void
|
2008-08-10 18:09:03 +08:00
|
|
|
gimp_display_shell_transform_xy_f (const GimpDisplayShell *shell,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble *nx,
|
2010-09-23 16:50:39 +08:00
|
|
|
gdouble *ny)
|
2003-01-04 02:01:30 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
g_return_if_fail (nx != NULL);
|
|
|
|
g_return_if_fail (ny != NULL);
|
|
|
|
|
2010-09-23 16:50:39 +08:00
|
|
|
*nx = SCALEX (shell, x) - shell->offset_x;
|
|
|
|
*ny = SCALEY (shell, y) - shell->offset_y;
|
2003-01-04 02:01:30 +08:00
|
|
|
}
|
|
|
|
|
2004-07-16 07:02:52 +08:00
|
|
|
/**
|
|
|
|
* gimp_display_shell_untransform_xy_f:
|
2004-07-16 18:07:30 +08:00
|
|
|
* @shell: a #GimpDisplayShell
|
2004-07-16 07:02:52 +08:00
|
|
|
* @x: x coordinate in display coordinates
|
|
|
|
* @y: y coordinate in display coordinates
|
|
|
|
* @nx: place to return x coordinate in image coordinates
|
|
|
|
* @ny: place to return y coordinate in image coordinates
|
|
|
|
*
|
|
|
|
* This function is identical to gimp_display_shell_untransform_xy(),
|
|
|
|
* except that the input and output coordinates are doubles rather than
|
|
|
|
* ints, and consequently there is no option related to rounding.
|
|
|
|
**/
|
2003-01-04 02:01:30 +08:00
|
|
|
void
|
2008-08-10 18:09:03 +08:00
|
|
|
gimp_display_shell_untransform_xy_f (const GimpDisplayShell *shell,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble *nx,
|
2010-09-23 16:50:39 +08:00
|
|
|
gdouble *ny)
|
2003-01-04 02:01:30 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
g_return_if_fail (nx != NULL);
|
|
|
|
g_return_if_fail (ny != NULL);
|
|
|
|
|
2010-09-23 16:50:39 +08:00
|
|
|
*nx = (x + shell->offset_x) / shell->scale_x;
|
|
|
|
*ny = (y + shell->offset_y) / shell->scale_y;
|
2003-01-04 02:01:30 +08:00
|
|
|
}
|
2004-01-15 22:36:43 +08:00
|
|
|
|
2010-08-25 07:58:00 +08:00
|
|
|
/**
|
|
|
|
* gimp_display_shell_transform_segments:
|
|
|
|
* @shell: a #GimpDisplayShell
|
|
|
|
* @src_segs: array of segments in image coordinates
|
|
|
|
* @dest_segs: returns the corresponding segments in display coordinates
|
|
|
|
* @n_segs: number of segments
|
|
|
|
*
|
|
|
|
* Transforms from image coordinates to display coordinates, so that
|
|
|
|
* objects can be rendered at the correct points on the display.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_display_shell_transform_segments (const GimpDisplayShell *shell,
|
|
|
|
const BoundSeg *src_segs,
|
2010-10-15 18:37:36 +08:00
|
|
|
GimpSegment *dest_segs,
|
2010-09-27 04:41:04 +08:00
|
|
|
gint n_segs,
|
|
|
|
gdouble offset_x,
|
|
|
|
gdouble offset_y)
|
2010-08-25 07:58:00 +08:00
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
|
|
|
for (i = 0; i < n_segs ; i++)
|
|
|
|
{
|
2010-09-27 04:41:04 +08:00
|
|
|
gdouble x1, x2;
|
|
|
|
gdouble y1, y2;
|
|
|
|
|
|
|
|
x1 = src_segs[i].x1 + offset_x;
|
|
|
|
x2 = src_segs[i].x2 + offset_x;
|
|
|
|
y1 = src_segs[i].y1 + offset_y;
|
|
|
|
y2 = src_segs[i].y2 + offset_y;
|
|
|
|
|
|
|
|
dest_segs[i].x1 = SCALEX (shell, x1) - shell->offset_x;
|
|
|
|
dest_segs[i].x2 = SCALEX (shell, x2) - shell->offset_x;
|
|
|
|
dest_segs[i].y1 = SCALEY (shell, y1) - shell->offset_y;
|
|
|
|
dest_segs[i].y2 = SCALEY (shell, y2) - shell->offset_y;
|
2010-08-25 07:58:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-16 07:02:52 +08:00
|
|
|
/**
|
|
|
|
* gimp_display_shell_untransform_viewport:
|
2004-07-16 18:07:30 +08:00
|
|
|
* @shell: a #GimpDisplayShell
|
|
|
|
* @x: returns image x coordinate of display upper left corner
|
|
|
|
* @y: returns image y coordinate of display upper left corner
|
|
|
|
* @width: returns width of display measured in image coordinates
|
|
|
|
* @height: returns height of display measured in image coordinates
|
2004-07-16 07:02:52 +08:00
|
|
|
*
|
|
|
|
* This function calculates the part of the image, im image coordinates,
|
2004-07-16 20:41:05 +08:00
|
|
|
* that corresponds to the display viewport.
|
2004-07-16 07:02:52 +08:00
|
|
|
**/
|
2004-01-15 22:36:43 +08:00
|
|
|
void
|
2008-08-10 18:09:03 +08:00
|
|
|
gimp_display_shell_untransform_viewport (const GimpDisplayShell *shell,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gint *width,
|
|
|
|
gint *height)
|
2004-01-15 22:36:43 +08:00
|
|
|
{
|
2009-10-07 01:20:44 +08:00
|
|
|
GimpImage *image;
|
|
|
|
gint x1, y1, x2, y2;
|
2004-01-15 22:36:43 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
|
|
|
gimp_display_shell_untransform_xy (shell,
|
|
|
|
0, 0,
|
|
|
|
&x1, &y1,
|
2010-09-23 16:50:39 +08:00
|
|
|
FALSE);
|
2004-01-15 22:36:43 +08:00
|
|
|
gimp_display_shell_untransform_xy (shell,
|
|
|
|
shell->disp_width, shell->disp_height,
|
|
|
|
&x2, &y2,
|
2010-09-23 16:50:39 +08:00
|
|
|
FALSE);
|
2004-01-15 22:36:43 +08:00
|
|
|
|
2009-10-07 01:20:44 +08:00
|
|
|
image = gimp_display_get_image (shell->display);
|
|
|
|
|
|
|
|
if (x1 < 0)
|
|
|
|
x1 = 0;
|
|
|
|
|
|
|
|
if (y1 < 0)
|
|
|
|
y1 = 0;
|
|
|
|
|
|
|
|
if (x2 > gimp_image_get_width (image))
|
|
|
|
x2 = gimp_image_get_width (image);
|
|
|
|
|
|
|
|
if (y2 > gimp_image_get_height (image))
|
|
|
|
y2 = gimp_image_get_height (image);
|
2004-01-15 22:36:43 +08:00
|
|
|
|
|
|
|
if (x) *x = x1;
|
|
|
|
if (y) *y = y1;
|
|
|
|
if (width) *width = x2 - x1;
|
|
|
|
if (height) *height = y2 - y1;
|
|
|
|
}
|