gimp/app/display/gimpdisplayshell-render.c

171 lines
5.7 KiB
C
Raw Normal View History

/* GIMP - The GNU Image Manipulation Program
1997-11-25 06:05:25 +08:00
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1997-11-25 06:05:25 +08:00
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "display-types.h"
#include "config/gimpdisplayconfig.h"
2012-05-06 10:39:23 +08:00
#include "gegl/gimp-gegl-utils.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimppickable.h"
#include "core/gimpprojectable.h"
2004-07-14 00:36:29 +08:00
#include "core/gimpprojection.h"
#include "gimpdisplay.h"
2001-11-01 05:20:09 +08:00
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-transform.h"
#include "gimpdisplayshell-filter.h"
app/display/Makefile.am app/display/gimpdisplay-callbacks.[ch] 2001-11-01 Michael Natterer <mitch@gimp.org> * app/display/Makefile.am * app/display/gimpdisplay-callbacks.[ch] * app/display/gimpdisplay-render.[ch] * app/display/gimpdisplay-scale.[ch] * app/display/gimpdisplay-scroll.[ch]: removed and added as gimpdisplayshell-foo.[ch] because they are all methods of the shell. * app/display/gimpdisplay.[ch] * app/display/gimpdisplayshell.[ch]: moved the "offset" and "size" variables from GimpDisplay to GimpDisplayShell. GimpDisplay should know nothing about screen coordinates. The gdisplay_[un]transform_foo() methods are still part of GimpDisplay but will be moved to GimpDisplayShell as soon as the tools' vitrual functions speak in image coordinates instead of GdkEvents. * app/display/gimpdisplayshell-callbacks.[ch]: prefixed all functions with gimp_display_shell_*. Moved some stuff to a "realize" callback File still has to be renamed. * app/display/gimpdisplay-foreach.[ch]: removed gdisplays_shrink_wrap(). * app/gui/menus.c * app/gui/view-commands.[ch] * app/display/gimpdisplayshell-scale.[ch]: implemented "Zoom to Fit Window" function (#57670). * app/nav_window.c * app/display/gimpdisplay-handlers.c * app/display/gimpdisplayshell-render.[ch] * app/display/gimpdisplayshell-scale.[ch] * app/display/gimpdisplayshell-scroll.[ch] * app/gui/colormap-dialog.c * app/gui/gui.c * app/gui/preferences-dialog.c * app/tools/gimpmagnifytool.c * app/tools/gimpmovetool.c * app/widgets/gimppreview.c: changed according to variable and filename changes. * app/tools/tool_manager.c: tool_manager_select_tool(): send the active tool a "HALT" command before selecting the new one. Fixes stale tool dialogs which were there because some other hack was removed (This is IMHO the right place to shut down the active tool). * app/tools/gimpcroptool.c: don't shrink wrap after cropping but let gimprc.allow_resize_windows decide. * app/tools/gimpselectiontool.c: gimage_mask_value() takes image, not screen coordinates. A good example of how braindead it is to pass GdkEvents to tools :-) Fixes incorrect cursor and oper update of the selection tools. * app/tools/gimptransformtool.c * app/undo.c: removed (#if 0 for now) some strange code which did manual exposing of GimpDisplayShell areas. This was definitely a hack and should not be there given the image emits correct "update" signals.
2001-11-02 17:31:21 +08:00
#include "gimpdisplayshell-render.h"
#include "gimpdisplayshell-scroll.h"
2010-09-29 04:39:50 +08:00
1997-11-25 06:05:25 +08:00
void
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
{
GimpImage *image;
GimpProjection *projection;
GeglBuffer *buffer;
gdouble window_scale = 1.0;
gint viewport_offset_x;
gint viewport_offset_y;
gint viewport_width;
gint viewport_height;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (cr != NULL);
g_return_if_fail (w > 0 && h > 0);
image = gimp_display_get_image (shell->display);
projection = gimp_image_get_projection (image);
buffer = gimp_pickable_get_buffer (GIMP_PICKABLE (projection));
#ifdef GIMP_DISPLAY_RENDER_ENABLE_SCALING
/* if we had this future API, things would look pretty on hires (retina) */
window_scale = gdk_window_get_scale_factor (gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (shell))));
#endif
window_scale = MIN (window_scale, GIMP_DISPLAY_RENDER_MAX_SCALE);
gimp_display_shell_scroll_get_scaled_viewport (shell,
&viewport_offset_x,
&viewport_offset_y,
&viewport_width,
&viewport_height);
gegl_buffer_get (buffer,
GEGL_RECTANGLE ((x + viewport_offset_x) * window_scale,
(y + viewport_offset_y) * window_scale,
w * window_scale,
h * window_scale),
shell->scale_x * window_scale,
babl_format ("cairo-ARGB32"),
cairo_image_surface_get_data (shell->render_surface),
cairo_image_surface_get_stride (shell->render_surface),
GEGL_ABYSS_NONE);
/* apply filters to the rendered projection */
if (shell->filter_stack)
{
cairo_surface_t *sub = shell->render_surface;
if (w != GIMP_DISPLAY_RENDER_BUF_WIDTH ||
h != GIMP_DISPLAY_RENDER_BUF_HEIGHT)
sub = cairo_image_surface_create_for_data (cairo_image_surface_get_data (sub),
CAIRO_FORMAT_ARGB32,
w * window_scale,
h * window_scale,
GIMP_DISPLAY_RENDER_BUF_WIDTH * 4);
gimp_color_display_stack_convert_surface (shell->filter_stack, sub);
if (sub != shell->render_surface)
cairo_surface_destroy (sub);
}
cairo_surface_mark_dirty_rectangle (shell->render_surface,
0, 0,
w * window_scale, h * window_scale);
#if 0
if (shell->mask)
{
2012-05-06 10:39:23 +08:00
GeglBuffer *buffer;
if (! shell->mask_surface)
{
shell->mask_surface =
cairo_image_surface_create (CAIRO_FORMAT_A8,
GIMP_DISPLAY_RENDER_BUF_WIDTH,
GIMP_DISPLAY_RENDER_BUF_HEIGHT);
}
2012-05-06 10:39:23 +08:00
buffer = gimp_drawable_get_buffer (shell->mask);
tiles = gimp_gegl_buffer_get_tiles (buffer);
/* The mask does not (yet) have an image pyramid, use 0 as level, */
gimp_display_shell_render_info_init (&info,
shell, x, y, w, h,
shell->mask_surface,
tiles, 0, FALSE);
render_image_alpha (&info);
cairo_surface_mark_dirty (shell->mask_surface);
}
#endif
/* put it to the screen */
cairo_save (cr);
cairo_rectangle (cr, x, y, w, h);
cairo_clip (cr);
cairo_scale (cr, 1.0 / window_scale, 1.0 / window_scale);
cairo_set_source_surface (cr, shell->render_surface,
x * window_scale,
y * window_scale);
cairo_paint (cr);
#if 0
if (shell->mask)
{
gimp_cairo_set_source_rgba (cr, &shell->mask_color);
cairo_mask_surface (cr, shell->mask_surface,
x + disp_xoffset, y + disp_yoffset);
}
#endif
cairo_restore (cr);
1997-11-25 06:05:25 +08:00
}