1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
|
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpmath/gimpmath.h"
#include "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "display-types.h"
#include "config/gimpdisplayconfig.h"
#include "gegl/gimp-gegl-utils.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimppickable.h"
#include "core/gimpprojectable.h"
#include "gimpdisplay.h"
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-transform.h"
#include "gimpdisplayshell-filter.h"
#include "gimpdisplayshell-profile.h"
#include "gimpdisplayshell-render.h"
#include "gimpdisplayshell-scroll.h"
#include "gimpdisplayxfer.h"
void
gimp_display_shell_render (GimpDisplayShell *shell,
cairo_t *cr,
gint x,
gint y,
gint w,
gint h,
gdouble scale)
{
GimpImage *image;
GeglBuffer *buffer;
#ifdef USE_NODE_BLIT
GeglNode *node;
#endif
cairo_surface_t *xfer;
gint xfer_src_x;
gint xfer_src_y;
gint mask_src_x = 0;
gint mask_src_y = 0;
gint cairo_stride;
guchar *cairo_data;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (cr != NULL);
g_return_if_fail (w > 0 && w <= GIMP_DISPLAY_RENDER_BUF_WIDTH);
g_return_if_fail (h > 0 && h <= GIMP_DISPLAY_RENDER_BUF_HEIGHT);
g_return_if_fail (scale > 0.0);
image = gimp_display_get_image (shell->display);
buffer = gimp_pickable_get_buffer (GIMP_PICKABLE (image));
#ifdef USE_NODE_BLIT
node = gimp_projectable_get_graph (GIMP_PROJECTABLE (image));
gimp_projectable_begin_render (GIMP_PROJECTABLE (image));
#endif
xfer = gimp_display_xfer_get_surface (shell->xfer, w, h,
&xfer_src_x, &xfer_src_y);
cairo_stride = cairo_image_surface_get_stride (xfer);
cairo_data = cairo_image_surface_get_data (xfer) +
xfer_src_y * cairo_stride + xfer_src_x * 4;
if (shell->profile_transform ||
gimp_display_shell_has_filter (shell))
{
gboolean can_convert_to_u8;
/* if there is a profile transform or a display filter, we need
* to use temp buffers
*/
can_convert_to_u8 = gimp_display_shell_profile_can_convert_to_u8 (shell);
/* create the filter buffer if we have filters, or can't convert
* to u8 directly
*/
if ((gimp_display_shell_has_filter (shell) || ! can_convert_to_u8) &&
! shell->filter_buffer)
{
gint fw = GIMP_DISPLAY_RENDER_BUF_WIDTH;
gint fh = GIMP_DISPLAY_RENDER_BUF_HEIGHT;
shell->filter_data =
gegl_malloc (fw * fh *
babl_format_get_bytes_per_pixel (shell->filter_format));
shell->filter_stride =
fw * babl_format_get_bytes_per_pixel (shell->filter_format);
shell->filter_buffer =
gegl_buffer_linear_new_from_data (shell->filter_data,
shell->filter_format,
GEGL_RECTANGLE (0, 0, fw, fh),
GEGL_AUTO_ROWSTRIDE,
(GDestroyNotify) gegl_free,
shell->filter_data);
}
if (! gimp_display_shell_has_filter (shell) || shell->filter_transform)
{
/* if there are no filters, or there is a filter transform,
* load the projection pixels into the profile_buffer
*/
#ifndef USE_NODE_BLIT
gegl_buffer_get (buffer,
GEGL_RECTANGLE (x, y, w, h), scale,
gimp_projectable_get_format (GIMP_PROJECTABLE (image)),
shell->profile_data, shell->profile_stride,
GEGL_ABYSS_CLAMP);
#else
gegl_node_blit (node,
scale, GEGL_RECTANGLE (x, y, w, h),
gimp_projectable_get_format (GIMP_PROJECTABLE (image)),
shell->profile_data, shell->profile_stride,
GEGL_BLIT_CACHE);
#endif
}
else
{
/* otherwise, load the pixels directly into the filter_buffer
*/
#ifndef USE_NODE_BLIT
gegl_buffer_get (buffer,
GEGL_RECTANGLE (x, y, w, h), scale,
shell->filter_format,
shell->filter_data, shell->filter_stride,
GEGL_ABYSS_CLAMP);
#else
gegl_node_blit (node,
scale, GEGL_RECTANGLE (x, y, w, h),
shell->filter_format,
shell->filter_data, shell->filter_stride,
GEGL_BLIT_CACHE);
#endif
}
/* if there is a filter transform, convert the pixels from
* the profile_buffer to the filter_buffer
*/
if (shell->filter_transform)
{
gimp_color_transform_process_buffer (shell->filter_transform,
shell->profile_buffer,
GEGL_RECTANGLE (0, 0, w, h),
shell->filter_buffer,
GEGL_RECTANGLE (0, 0, w, h));
}
/* if there are filters, apply them
*/
if (gimp_display_shell_has_filter (shell))
{
GeglBuffer *filter_buffer;
/* shift the filter_buffer so that the area passed to
* the filters is the real render area, allowing for
* position-dependent filters
*/
filter_buffer = g_object_new (GEGL_TYPE_BUFFER,
"source", shell->filter_buffer,
"shift-x", -x,
"shift-y", -y,
NULL);
/* convert the filter_buffer in place
*/
gimp_color_display_stack_convert_buffer (shell->filter_stack,
filter_buffer,
GEGL_RECTANGLE (x, y, w, h));
g_object_unref (filter_buffer);
}
/* if there is a profile transform...
*/
if (shell->profile_transform)
{
if (gimp_display_shell_has_filter (shell))
{
/* if we have filters, convert the pixels in the filter_buffer
* in-place
*/
gimp_color_transform_process_buffer (shell->profile_transform,
shell->filter_buffer,
GEGL_RECTANGLE (0, 0, w, h),
shell->filter_buffer,
GEGL_RECTANGLE (0, 0, w, h));
}
else if (! can_convert_to_u8)
{
/* otherwise, if we can't convert to u8 directly, convert
* the pixels from the profile_buffer to the filter_buffer
*/
gimp_color_transform_process_buffer (shell->profile_transform,
shell->profile_buffer,
GEGL_RECTANGLE (0, 0, w, h),
shell->filter_buffer,
GEGL_RECTANGLE (0, 0, w, h));
}
else
{
GeglBuffer *buffer =
gegl_buffer_linear_new_from_data (cairo_data,
babl_format ("cairo-ARGB32"),
GEGL_RECTANGLE (0, 0, w, h),
cairo_stride,
NULL, NULL);
/* otherwise, convert the profile_buffer directly into
* the cairo_buffer
*/
gimp_color_transform_process_buffer (shell->profile_transform,
shell->profile_buffer,
GEGL_RECTANGLE (0, 0, w, h),
buffer,
GEGL_RECTANGLE (0, 0, w, h));
g_object_unref (buffer);
}
}
/* finally, copy the filter buffer to the cairo-ARGB32 buffer,
* if necessary
*/
if (gimp_display_shell_has_filter (shell) || ! can_convert_to_u8)
{
gegl_buffer_get (shell->filter_buffer,
GEGL_RECTANGLE (0, 0, w, h), 1.0,
babl_format ("cairo-ARGB32"),
cairo_data, cairo_stride,
GEGL_ABYSS_CLAMP);
}
}
else
{
/* otherwise we can copy the projection pixels straight to the
* cairo-ARGB32 buffer
*/
#ifndef USE_NODE_BLIT
gegl_buffer_get (buffer,
GEGL_RECTANGLE (x, y, w, h), scale,
babl_format ("cairo-ARGB32"),
cairo_data, cairo_stride,
GEGL_ABYSS_CLAMP);
#else
gegl_node_blit (node,
scale, GEGL_RECTANGLE (x, y, w, h),
babl_format ("cairo-ARGB32"),
cairo_data, cairo_stride,
GEGL_BLIT_CACHE);
#endif
}
#ifdef USE_NODE_BLIT
gimp_projectable_end_render (GIMP_PROJECTABLE (image));
#endif
if (shell->mask)
{
if (! shell->mask_surface)
{
shell->mask_surface =
cairo_image_surface_create (CAIRO_FORMAT_A8,
GIMP_DISPLAY_RENDER_BUF_WIDTH,
GIMP_DISPLAY_RENDER_BUF_HEIGHT);
}
cairo_surface_mark_dirty (shell->mask_surface);
cairo_stride = cairo_image_surface_get_stride (shell->mask_surface);
cairo_data = cairo_image_surface_get_data (shell->mask_surface) +
mask_src_y * cairo_stride + mask_src_x;
gegl_buffer_get (shell->mask,
GEGL_RECTANGLE (x - floor (shell->mask_offset_x * scale),
y - floor (shell->mask_offset_y * scale),
w, h),
scale,
babl_format ("Y u8"),
cairo_data, cairo_stride,
GEGL_ABYSS_NONE);
if (shell->mask_inverted)
{
gint mask_height = h;
while (mask_height--)
{
gint mask_width = w;
guchar *d = cairo_data;
while (mask_width--)
{
guchar inv = 255 - *d;
*d++ = inv;
}
cairo_data += cairo_stride;
}
}
}
/* put it to the screen */
cairo_set_source_surface (cr, xfer,
x - xfer_src_x,
y - xfer_src_y);
cairo_paint (cr);
if (shell->mask)
{
gimp_cairo_set_source_rgba (cr, &shell->mask_color);
cairo_mask_surface (cr, shell->mask_surface,
x - mask_src_x,
y - mask_src_y);
}
}
|