2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +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
|
1997-11-25 06:05:25 +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
|
1997-11-25 06:05:25 +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/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2014-04-21 00:06:52 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2011-04-28 21:50:39 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2010-09-29 06:10:37 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2007-10-08 21:30:49 +08:00
|
|
|
#include "config/gimpdisplayconfig.h"
|
|
|
|
|
2012-05-06 10:39:23 +08:00
|
|
|
#include "gegl/gimp-gegl-utils.h"
|
|
|
|
|
2005-07-31 02:19:54 +08:00
|
|
|
#include "core/gimpdrawable.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
2008-11-04 20:07:17 +08:00
|
|
|
#include "core/gimppickable.h"
|
2014-07-04 02:52:02 +08:00
|
|
|
#ifdef USE_NODE_BLIT
|
2012-06-21 03:44:09 +08:00
|
|
|
#include "core/gimpprojectable.h"
|
2014-07-04 02:52:02 +08:00
|
|
|
#endif
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "gimpdisplay.h"
|
2001-11-01 05:20:09 +08:00
|
|
|
#include "gimpdisplayshell.h"
|
2012-06-21 03:44:09 +08:00
|
|
|
#include "gimpdisplayshell-transform.h"
|
2002-03-15 06:42:50 +08:00
|
|
|
#include "gimpdisplayshell-filter.h"
|
2001-11-02 17:31:21 +08:00
|
|
|
#include "gimpdisplayshell-render.h"
|
2008-07-12 15:00:46 +08:00
|
|
|
#include "gimpdisplayshell-scroll.h"
|
2013-02-03 20:26:32 +08:00
|
|
|
#include "gimpdisplayxfer.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
|
2013-02-02 21:10:23 +08:00
|
|
|
|
2014-04-21 00:06:52 +08:00
|
|
|
/* #define GIMP_DISPLAY_RENDER_ENABLE_SCALING 1 */
|
|
|
|
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
void
|
2010-09-29 04:26:05 +08:00
|
|
|
gimp_display_shell_render (GimpDisplayShell *shell,
|
|
|
|
cairo_t *cr,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2013-02-02 21:10:23 +08:00
|
|
|
GimpImage *image;
|
|
|
|
GeglBuffer *buffer;
|
2014-07-04 02:52:02 +08:00
|
|
|
#ifdef USE_NODE_BLIT
|
|
|
|
GeglNode *node;
|
|
|
|
#endif
|
2014-04-21 00:06:52 +08:00
|
|
|
gdouble scale_x = 1.0;
|
|
|
|
gdouble scale_y = 1.0;
|
|
|
|
gdouble buffer_scale = 1.0;
|
2013-02-02 21:10:23 +08:00
|
|
|
gint viewport_offset_x;
|
|
|
|
gint viewport_offset_y;
|
|
|
|
gint viewport_width;
|
|
|
|
gint viewport_height;
|
2014-04-21 00:06:52 +08:00
|
|
|
gint scaled_x;
|
|
|
|
gint scaled_y;
|
|
|
|
gint scaled_width;
|
|
|
|
gint scaled_height;
|
2013-01-30 17:50:54 +08:00
|
|
|
cairo_surface_t *xfer;
|
2013-11-02 10:11:44 +08:00
|
|
|
gint xfer_src_x;
|
|
|
|
gint xfer_src_y;
|
2013-04-30 05:15:37 +08:00
|
|
|
gint mask_src_x = 0;
|
|
|
|
gint mask_src_y = 0;
|
2013-02-02 21:10:23 +08:00
|
|
|
gint stride;
|
|
|
|
guchar *data;
|
2001-12-01 02:23:49 +08:00
|
|
|
|
2007-10-08 21:30:49 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
2010-08-28 01:32:16 +08:00
|
|
|
g_return_if_fail (cr != NULL);
|
2005-04-28 07:27:10 +08:00
|
|
|
g_return_if_fail (w > 0 && h > 0);
|
|
|
|
|
2014-06-30 05:11:53 +08:00
|
|
|
image = gimp_display_get_image (shell->display);
|
|
|
|
buffer = gimp_pickable_get_buffer (GIMP_PICKABLE (image));
|
2014-07-04 02:52:02 +08:00
|
|
|
#ifdef USE_NODE_BLIT
|
|
|
|
node = gimp_projectable_get_graph (GIMP_PROJECTABLE (image));
|
|
|
|
#endif
|
2012-07-06 03:42:26 +08:00
|
|
|
|
2013-01-18 23:36:22 +08:00
|
|
|
#ifdef GIMP_DISPLAY_RENDER_ENABLE_SCALING
|
|
|
|
/* if we had this future API, things would look pretty on hires (retina) */
|
2014-04-21 00:06:52 +08:00
|
|
|
scale_x = gdk_window_get_scale_factor (gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (shell))));
|
2013-01-18 23:36:22 +08:00
|
|
|
#endif
|
|
|
|
|
2014-04-21 00:06:52 +08:00
|
|
|
scale_x = MIN (scale_x, GIMP_DISPLAY_RENDER_MAX_SCALE);
|
|
|
|
scale_y = scale_x;
|
|
|
|
|
|
|
|
if (shell->scale_x > shell->scale_y)
|
|
|
|
{
|
|
|
|
scale_y *= (shell->scale_x / shell->scale_y);
|
|
|
|
|
|
|
|
buffer_scale = shell->scale_y * scale_y;
|
|
|
|
}
|
|
|
|
else if (shell->scale_y > shell->scale_x)
|
|
|
|
{
|
|
|
|
scale_x *= (shell->scale_y / shell->scale_x);
|
|
|
|
|
|
|
|
buffer_scale = shell->scale_x * scale_x;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buffer_scale = shell->scale_x * scale_x;
|
|
|
|
}
|
2013-01-18 23:36:22 +08:00
|
|
|
|
2012-07-06 03:42:26 +08:00
|
|
|
gimp_display_shell_scroll_get_scaled_viewport (shell,
|
|
|
|
&viewport_offset_x,
|
|
|
|
&viewport_offset_y,
|
|
|
|
&viewport_width,
|
|
|
|
&viewport_height);
|
2014-04-21 00:06:52 +08:00
|
|
|
|
|
|
|
scaled_x = floor ((x + viewport_offset_x) * scale_x);
|
|
|
|
scaled_y = floor ((y + viewport_offset_y) * scale_y);
|
|
|
|
scaled_width = ceil (w * scale_x);
|
|
|
|
scaled_height = ceil (h * scale_y);
|
|
|
|
|
2013-04-21 08:08:16 +08:00
|
|
|
if (shell->rotate_transform)
|
|
|
|
{
|
|
|
|
xfer = cairo_surface_create_similar_image (cairo_get_target (cr),
|
|
|
|
CAIRO_FORMAT_ARGB32,
|
2014-04-21 00:06:52 +08:00
|
|
|
scaled_width,
|
|
|
|
scaled_height);
|
2013-04-21 08:08:16 +08:00
|
|
|
cairo_surface_mark_dirty (xfer);
|
2013-11-02 10:11:44 +08:00
|
|
|
xfer_src_x = 0;
|
|
|
|
xfer_src_y = 0;
|
2013-04-21 08:08:16 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xfer = gimp_display_xfer_get_surface (shell->xfer,
|
2014-04-21 00:06:52 +08:00
|
|
|
scaled_width,
|
|
|
|
scaled_height,
|
2013-11-02 10:11:44 +08:00
|
|
|
&xfer_src_x,
|
|
|
|
&xfer_src_y);
|
2013-04-21 08:08:16 +08:00
|
|
|
}
|
2013-01-30 17:50:54 +08:00
|
|
|
|
2013-02-02 21:10:23 +08:00
|
|
|
stride = cairo_image_surface_get_stride (xfer);
|
2013-01-30 17:50:54 +08:00
|
|
|
data = cairo_image_surface_get_data (xfer);
|
2013-11-02 10:11:44 +08:00
|
|
|
data += xfer_src_y * stride + xfer_src_x * 4;
|
2012-06-21 03:44:09 +08:00
|
|
|
|
2001-12-01 02:23:49 +08:00
|
|
|
/* apply filters to the rendered projection */
|
2003-11-22 06:52:36 +08:00
|
|
|
if (shell->filter_stack)
|
2012-06-09 21:36:34 +08:00
|
|
|
{
|
2013-11-03 03:56:25 +08:00
|
|
|
const Babl *filter_format = babl_format ("R'G'B'A float");
|
2013-11-02 07:48:02 +08:00
|
|
|
|
2013-11-03 03:56:25 +08:00
|
|
|
if (! shell->filter_buffer)
|
|
|
|
{
|
|
|
|
gint w = GIMP_DISPLAY_RENDER_BUF_WIDTH * GIMP_DISPLAY_RENDER_MAX_SCALE;
|
|
|
|
gint h = GIMP_DISPLAY_RENDER_BUF_HEIGHT * GIMP_DISPLAY_RENDER_MAX_SCALE;
|
|
|
|
|
|
|
|
shell->filter_data =
|
|
|
|
gegl_malloc (w * h * babl_format_get_bytes_per_pixel (filter_format));
|
|
|
|
|
|
|
|
shell->filter_stride = w * babl_format_get_bytes_per_pixel (filter_format);
|
|
|
|
|
|
|
|
shell->filter_buffer =
|
|
|
|
gegl_buffer_linear_new_from_data (shell->filter_data,
|
|
|
|
filter_format,
|
|
|
|
GEGL_RECTANGLE (0, 0, w, h),
|
|
|
|
GEGL_AUTO_ROWSTRIDE,
|
|
|
|
(GDestroyNotify) gegl_free,
|
|
|
|
shell->filter_data);
|
|
|
|
}
|
2013-11-02 07:48:02 +08:00
|
|
|
|
2014-07-04 02:52:02 +08:00
|
|
|
#ifndef USE_NODE_BLIT
|
2013-11-02 07:48:02 +08:00
|
|
|
gegl_buffer_get (buffer,
|
2014-04-21 00:06:52 +08:00
|
|
|
GEGL_RECTANGLE (scaled_x, scaled_y,
|
|
|
|
scaled_width, scaled_height),
|
|
|
|
buffer_scale,
|
2014-07-04 02:52:02 +08:00
|
|
|
filter_format,
|
|
|
|
shell->filter_data, shell->filter_stride,
|
|
|
|
GEGL_ABYSS_CLAMP);
|
|
|
|
#else
|
|
|
|
gegl_node_blit (node,
|
|
|
|
buffer_scale,
|
|
|
|
GEGL_RECTANGLE (scaled_x, scaled_y,
|
|
|
|
scaled_width, scaled_height),
|
|
|
|
filter_format,
|
|
|
|
shell->filter_data, shell->filter_stride,
|
|
|
|
GEGL_BLIT_CACHE);
|
|
|
|
#endif
|
2013-11-02 07:48:02 +08:00
|
|
|
|
|
|
|
gimp_color_display_stack_convert_buffer (shell->filter_stack,
|
2013-11-03 03:56:25 +08:00
|
|
|
shell->filter_buffer,
|
2013-11-02 07:48:02 +08:00
|
|
|
GEGL_RECTANGLE (0, 0,
|
2014-04-21 00:06:52 +08:00
|
|
|
scaled_width,
|
|
|
|
scaled_height));
|
2013-11-02 07:48:02 +08:00
|
|
|
|
2013-11-03 03:56:25 +08:00
|
|
|
gegl_buffer_get (shell->filter_buffer,
|
2013-11-02 07:48:02 +08:00
|
|
|
GEGL_RECTANGLE (0, 0,
|
2014-04-21 00:06:52 +08:00
|
|
|
scaled_width,
|
|
|
|
scaled_height),
|
2013-11-02 07:48:02 +08:00
|
|
|
1.0,
|
|
|
|
babl_format ("cairo-ARGB32"),
|
|
|
|
data, stride,
|
2014-03-15 02:34:28 +08:00
|
|
|
GEGL_ABYSS_CLAMP);
|
2013-11-02 07:48:02 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-04 02:52:02 +08:00
|
|
|
#ifndef USE_NODE_BLIT
|
2013-11-02 07:48:02 +08:00
|
|
|
gegl_buffer_get (buffer,
|
2014-04-21 00:06:52 +08:00
|
|
|
GEGL_RECTANGLE (scaled_x, scaled_y,
|
|
|
|
scaled_width, scaled_height),
|
|
|
|
buffer_scale,
|
2013-11-02 07:48:02 +08:00
|
|
|
babl_format ("cairo-ARGB32"),
|
|
|
|
data, stride,
|
2014-03-15 02:34:28 +08:00
|
|
|
GEGL_ABYSS_CLAMP);
|
2014-07-04 02:52:02 +08:00
|
|
|
#else
|
|
|
|
gegl_node_blit (node,
|
|
|
|
buffer_scale,
|
|
|
|
GEGL_RECTANGLE (scaled_x, scaled_y,
|
|
|
|
scaled_width, scaled_height),
|
|
|
|
babl_format ("cairo-ARGB32"),
|
|
|
|
data, stride,
|
|
|
|
GEGL_BLIT_CACHE);
|
|
|
|
#endif
|
2012-06-09 21:36:34 +08:00
|
|
|
}
|
|
|
|
|
2010-09-29 04:04:07 +08:00
|
|
|
if (shell->mask)
|
2005-07-31 02:19:54 +08:00
|
|
|
{
|
2010-09-29 05:49:22 +08:00
|
|
|
if (! shell->mask_surface)
|
|
|
|
{
|
|
|
|
shell->mask_surface =
|
2013-04-30 05:15:37 +08:00
|
|
|
cairo_image_surface_create (CAIRO_FORMAT_A8,
|
|
|
|
GIMP_DISPLAY_RENDER_BUF_WIDTH *
|
|
|
|
GIMP_DISPLAY_RENDER_MAX_SCALE,
|
|
|
|
GIMP_DISPLAY_RENDER_BUF_HEIGHT *
|
|
|
|
GIMP_DISPLAY_RENDER_MAX_SCALE);
|
2010-09-29 05:49:22 +08:00
|
|
|
}
|
|
|
|
|
2013-04-30 05:15:37 +08:00
|
|
|
cairo_surface_mark_dirty (shell->mask_surface);
|
|
|
|
|
2013-04-26 16:33:10 +08:00
|
|
|
stride = cairo_image_surface_get_stride (shell->mask_surface);
|
|
|
|
data = cairo_image_surface_get_data (shell->mask_surface);
|
2013-04-30 05:15:37 +08:00
|
|
|
data += mask_src_y * stride + mask_src_x * 4;
|
2005-07-31 06:29:02 +08:00
|
|
|
|
2013-06-23 04:26:46 +08:00
|
|
|
gegl_buffer_get (shell->mask,
|
2014-04-21 00:06:52 +08:00
|
|
|
GEGL_RECTANGLE (scaled_x, scaled_y,
|
|
|
|
scaled_width, scaled_height),
|
|
|
|
buffer_scale,
|
2013-04-26 16:33:10 +08:00
|
|
|
babl_format ("Y u8"),
|
|
|
|
data, stride,
|
2014-03-15 02:34:28 +08:00
|
|
|
GEGL_ABYSS_CLAMP);
|
2013-07-15 07:57:00 +08:00
|
|
|
|
2014-06-12 03:33:57 +08:00
|
|
|
if (shell->mask_inverted)
|
2013-07-15 07:57:00 +08:00
|
|
|
{
|
2014-06-12 03:33:57 +08:00
|
|
|
gint mask_height = scaled_height;
|
2013-07-15 07:57:00 +08:00
|
|
|
|
2014-06-12 03:33:57 +08:00
|
|
|
while (mask_height--)
|
2013-07-15 07:57:00 +08:00
|
|
|
{
|
2014-06-12 03:33:57 +08:00
|
|
|
gint mask_width = scaled_width;
|
|
|
|
guchar *d = data;
|
2013-07-15 07:57:00 +08:00
|
|
|
|
2014-06-12 03:33:57 +08:00
|
|
|
while (mask_width--)
|
|
|
|
{
|
|
|
|
guchar inv = 255 - *d;
|
2013-07-15 07:57:00 +08:00
|
|
|
|
2014-06-12 03:33:57 +08:00
|
|
|
*d++ = inv;
|
|
|
|
}
|
|
|
|
|
|
|
|
data += stride;
|
|
|
|
}
|
2013-07-15 07:57:00 +08:00
|
|
|
}
|
2010-09-29 05:49:22 +08:00
|
|
|
}
|
2010-08-28 01:32:16 +08:00
|
|
|
|
2001-12-01 02:23:49 +08:00
|
|
|
/* put it to the screen */
|
2012-07-06 03:42:26 +08:00
|
|
|
cairo_save (cr);
|
2010-09-29 05:49:22 +08:00
|
|
|
|
2012-07-06 03:42:26 +08:00
|
|
|
cairo_rectangle (cr, x, y, w, h);
|
2010-09-29 05:49:22 +08:00
|
|
|
|
2014-04-21 00:06:52 +08:00
|
|
|
cairo_scale (cr, 1.0 / scale_x, 1.0 / scale_y);
|
2013-01-18 23:36:22 +08:00
|
|
|
|
2013-01-30 17:50:54 +08:00
|
|
|
cairo_set_source_surface (cr, xfer,
|
2014-04-21 00:06:52 +08:00
|
|
|
x * scale_x - xfer_src_x,
|
|
|
|
y * scale_y - xfer_src_y);
|
2013-01-18 23:36:22 +08:00
|
|
|
|
2013-04-21 08:08:16 +08:00
|
|
|
if (shell->rotate_transform)
|
|
|
|
{
|
|
|
|
cairo_pattern_t *pattern;
|
|
|
|
|
|
|
|
pattern = cairo_get_source (cr);
|
|
|
|
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD);
|
|
|
|
|
|
|
|
cairo_set_line_width (cr, 1.0);
|
|
|
|
cairo_stroke_preserve (cr);
|
|
|
|
|
|
|
|
cairo_surface_destroy (xfer);
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_clip (cr);
|
2012-07-06 03:42:26 +08:00
|
|
|
cairo_paint (cr);
|
2010-09-29 05:49:22 +08:00
|
|
|
|
2012-07-06 03:42:26 +08:00
|
|
|
if (shell->mask)
|
|
|
|
{
|
|
|
|
gimp_cairo_set_source_rgba (cr, &shell->mask_color);
|
|
|
|
cairo_mask_surface (cr, shell->mask_surface,
|
2014-04-21 00:06:52 +08:00
|
|
|
(x - mask_src_x) * scale_x,
|
|
|
|
(y - mask_src_y) * scale_y);
|
2012-07-06 03:42:26 +08:00
|
|
|
}
|
2010-09-29 05:49:22 +08:00
|
|
|
|
2012-07-06 03:42:26 +08:00
|
|
|
cairo_restore (cr);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|