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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
app/appenv.h New file. Includes <math.h>. Move G_PI, RINT(), ROUND() etc
1999-09-01 Tor Lillqvist <tml@iki.fi>
* app/appenv.h
* libgimp/gimpmath.h: New file. Includes <math.h>. Move G_PI,
RINT(), ROUND() etc from app/appenv.h here, so plug-ins can
use them, too. Remove some commented-out old stuff in appenv.h.
* libgimp/gimp.h: Include gimpmath.h.
* libgimp/gimp.c (gimp_main): Win32: Don't install signal
handlers, we can't do anything useful in the handler ourselves
anyway (it would be nice to print out a backtrace, but that seems
pretty hard to do, even if not impossible). Let Windows inform the
user about the crash. If the plug-in was compiled with MSVC, and
the user also has it, she is offered a chance to start the
debugger automatically anyway.
* app/*several*.c: Include gimpmath.h for G_PI etc. Don't include
<math.h>, as gimpmath.h includes it.
* plug-ins/*/*many*.c: Include config.h. Don't include <math.h>.
Remove all the duplicated definitions of G_PI and rint(). Use
RINT() instead of rint().
* app/app_procs.[ch]: app_exit() takes a gboolean.
* app/batch.c
* app/commands.c
* app/interface.c: Call app_exit() with FALSE or TRUE.
* app/main.c (on_error): Call gimp_fatal_error. (main): Don't
install any signal handler on Win32 here, either.
* app/errors.c (gimp_fatal_error, gimp_terminate): Win32: Format
the message and call MessageBox with it. g_on_error_query doesn't
do anything useful on Win32, and printf'ing a message to stdout or
stderr doesn't do anything, either, in a windowing application.
1999-09-02 04:30:56 +08:00
|
|
|
#include "config.h"
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2014-06-04 07:23:41 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-07-06 03:42:26 +08:00
|
|
|
#include <cairo.h>
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2014-06-02 03:30:11 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2018-03-31 20:13:36 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2014-06-02 03:30:11 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
#include "core-types.h"
|
2002-05-03 20:45:22 +08:00
|
|
|
|
2012-08-25 04:16:02 +08:00
|
|
|
#include "gegl/gimp-babl.h"
|
2018-05-19 02:57:19 +08:00
|
|
|
#include "gegl/gimp-gegl-loops.h"
|
2012-03-15 04:16:58 +08:00
|
|
|
#include "gegl/gimp-gegl-utils.h"
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
#include "gimp.h"
|
2014-08-12 19:57:57 +08:00
|
|
|
#include "gimp-memsize.h"
|
2004-07-14 00:36:29 +08:00
|
|
|
#include "gimpimage.h"
|
|
|
|
#include "gimpmarshal.h"
|
2004-07-14 07:04:05 +08:00
|
|
|
#include "gimppickable.h"
|
2008-11-05 02:06:36 +08:00
|
|
|
#include "gimpprojectable.h"
|
2004-07-14 00:36:29 +08:00
|
|
|
#include "gimpprojection.h"
|
2017-04-23 02:22:06 +08:00
|
|
|
#include "gimptilehandlerprojectable.h"
|
2000-04-28 01:27:28 +08:00
|
|
|
|
2013-08-10 02:20:02 +08:00
|
|
|
#include "gimp-log.h"
|
2014-07-02 10:47:24 +08:00
|
|
|
#include "gimp-priorities.h"
|
2013-08-10 02:20:02 +08:00
|
|
|
|
2001-07-31 19:33:13 +08:00
|
|
|
|
2013-07-28 21:57:28 +08:00
|
|
|
/* chunk size for one iteration of the chunk renderer */
|
2014-06-04 07:23:41 +08:00
|
|
|
static gint GIMP_PROJECTION_CHUNK_WIDTH = 256;
|
|
|
|
static gint GIMP_PROJECTION_CHUNK_HEIGHT = 128;
|
2008-01-23 04:27:13 +08:00
|
|
|
|
2018-03-31 20:13:36 +08:00
|
|
|
/* chunk size for area updates */
|
|
|
|
static gint GIMP_PROJECTION_UPDATE_CHUNK_WIDTH = 32;
|
|
|
|
static gint GIMP_PROJECTION_UPDATE_CHUNK_HEIGHT = 32;
|
|
|
|
|
2014-06-03 07:30:59 +08:00
|
|
|
/* how much time, in seconds, do we allow chunk rendering to take,
|
|
|
|
* aiming for 15fps
|
|
|
|
*/
|
2014-06-22 22:38:44 +08:00
|
|
|
static gdouble GIMP_PROJECTION_CHUNK_TIME = 0.0666;
|
2013-08-10 02:20:02 +08:00
|
|
|
|
2008-01-23 04:27:13 +08:00
|
|
|
|
2002-05-10 21:09:19 +08:00
|
|
|
enum
|
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
UPDATE,
|
|
|
|
LAST_SIGNAL
|
2002-05-10 21:09:19 +08:00
|
|
|
};
|
|
|
|
|
2013-09-05 16:37:09 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_BUFFER
|
|
|
|
};
|
|
|
|
|
2002-05-10 21:09:19 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
typedef struct _GimpProjectionChunkRender GimpProjectionChunkRender;
|
|
|
|
|
|
|
|
struct _GimpProjectionChunkRender
|
|
|
|
{
|
2014-05-31 07:42:28 +08:00
|
|
|
guint idle_id;
|
|
|
|
|
2014-05-31 07:22:54 +08:00
|
|
|
gint x;
|
|
|
|
gint y;
|
2014-05-31 07:42:28 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
|
|
|
|
gint work_x;
|
|
|
|
gint work_y;
|
|
|
|
|
2014-05-31 07:22:54 +08:00
|
|
|
cairo_region_t *update_region; /* flushed update region */
|
2014-05-31 06:08:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GimpProjectionPrivate
|
|
|
|
{
|
|
|
|
GimpProjectable *projectable;
|
|
|
|
|
|
|
|
GeglBuffer *buffer;
|
2015-03-11 15:14:00 +08:00
|
|
|
GimpTileHandlerValidate *validate_handler;
|
2014-05-31 06:08:43 +08:00
|
|
|
|
2017-12-02 22:48:14 +08:00
|
|
|
gint priority;
|
|
|
|
|
2014-05-31 07:22:54 +08:00
|
|
|
cairo_region_t *update_region;
|
2014-05-31 06:08:43 +08:00
|
|
|
GimpProjectionChunkRender chunk_render;
|
2014-05-31 08:34:56 +08:00
|
|
|
cairo_rectangle_int_t priority_rect;
|
2014-05-31 06:08:43 +08:00
|
|
|
|
|
|
|
gboolean invalidate_preview;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
/* local function prototypes */
|
2001-07-31 19:33:13 +08:00
|
|
|
|
2008-11-04 20:07:17 +08:00
|
|
|
static void gimp_projection_pickable_iface_init (GimpPickableInterface *iface);
|
|
|
|
|
|
|
|
static void gimp_projection_finalize (GObject *object);
|
2013-09-05 16:37:09 +08:00
|
|
|
static void gimp_projection_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_projection_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2008-11-04 20:07:17 +08:00
|
|
|
|
|
|
|
static gint64 gimp_projection_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size);
|
|
|
|
|
|
|
|
static void gimp_projection_pickable_flush (GimpPickable *pickable);
|
|
|
|
static GimpImage * gimp_projection_get_image (GimpPickable *pickable);
|
2012-03-18 23:20:01 +08:00
|
|
|
static const Babl * gimp_projection_get_format (GimpPickable *pickable);
|
2012-06-26 22:09:29 +08:00
|
|
|
static GeglBuffer * gimp_projection_get_buffer (GimpPickable *pickable);
|
2008-11-04 20:07:17 +08:00
|
|
|
static gboolean gimp_projection_get_pixel_at (GimpPickable *pickable,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
2012-04-21 16:03:32 +08:00
|
|
|
const Babl *format,
|
|
|
|
gpointer pixel);
|
2012-04-21 22:05:49 +08:00
|
|
|
static gdouble gimp_projection_get_opacity_at (GimpPickable *pickable,
|
2008-11-04 20:07:17 +08:00
|
|
|
gint x,
|
|
|
|
gint y);
|
2018-05-19 02:57:19 +08:00
|
|
|
static void gimp_projection_get_pixel_average (GimpPickable *pickable,
|
|
|
|
const GeglRectangle *rect,
|
|
|
|
const Babl *format,
|
|
|
|
gpointer pixel);
|
2016-05-23 05:28:31 +08:00
|
|
|
static void gimp_projection_pixel_to_srgb (GimpPickable *pickable,
|
|
|
|
const Babl *format,
|
|
|
|
gpointer pixel,
|
|
|
|
GimpRGB *color);
|
2016-05-23 07:25:35 +08:00
|
|
|
static void gimp_projection_srgb_to_pixel (GimpPickable *pickable,
|
|
|
|
const GimpRGB *color,
|
|
|
|
const Babl *format,
|
|
|
|
gpointer pixel);
|
2008-11-04 20:07:17 +08:00
|
|
|
|
2018-08-04 00:34:47 +08:00
|
|
|
static void gimp_projection_allocate_buffer (GimpProjection *proj);
|
2012-07-06 03:42:26 +08:00
|
|
|
static void gimp_projection_free_buffer (GimpProjection *proj);
|
2008-11-04 20:07:17 +08:00
|
|
|
static void gimp_projection_add_update_area (GimpProjection *proj,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h);
|
|
|
|
static void gimp_projection_flush_whenever (GimpProjection *proj,
|
|
|
|
gboolean now);
|
2013-07-28 21:57:28 +08:00
|
|
|
static void gimp_projection_chunk_render_start (GimpProjection *proj);
|
|
|
|
static void gimp_projection_chunk_render_stop (GimpProjection *proj);
|
|
|
|
static gboolean gimp_projection_chunk_render_callback (gpointer data);
|
|
|
|
static void gimp_projection_chunk_render_init (GimpProjection *proj);
|
2018-08-20 15:00:10 +08:00
|
|
|
static gboolean gimp_projection_chunk_render_iteration(GimpProjection *proj,
|
|
|
|
gboolean chunk);
|
2013-07-28 21:57:28 +08:00
|
|
|
static gboolean gimp_projection_chunk_render_next_area(GimpProjection *proj);
|
2008-11-04 20:07:17 +08:00
|
|
|
static void gimp_projection_paint_area (GimpProjection *proj,
|
|
|
|
gboolean now,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h);
|
2008-11-05 02:06:36 +08:00
|
|
|
|
2009-08-26 19:06:55 +08:00
|
|
|
static void gimp_projection_projectable_invalidate(GimpProjectable *projectable,
|
2008-11-04 20:07:17 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
GimpProjection *proj);
|
2008-11-05 02:06:36 +08:00
|
|
|
static void gimp_projection_projectable_flush (GimpProjectable *projectable,
|
2008-11-04 20:07:17 +08:00
|
|
|
gboolean invalidate_preview,
|
|
|
|
GimpProjection *proj);
|
2018-08-04 00:34:47 +08:00
|
|
|
static void
|
|
|
|
gimp_projection_projectable_structure_changed (GimpProjectable *projectable,
|
|
|
|
GimpProjection *proj);
|
|
|
|
static void gimp_projection_projectable_bounds_changed (GimpProjectable *projectable,
|
|
|
|
gint old_x,
|
|
|
|
gint old_y,
|
|
|
|
gint old_w,
|
|
|
|
gint old_h,
|
2008-11-05 02:06:36 +08:00
|
|
|
GimpProjection *proj);
|
2004-07-14 00:36:29 +08:00
|
|
|
|
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpProjection, gimp_projection, GIMP_TYPE_OBJECT,
|
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_PICKABLE,
|
2006-05-15 17:46:31 +08:00
|
|
|
gimp_projection_pickable_iface_init))
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
#define parent_class gimp_projection_parent_class
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
static guint projection_signals[LAST_SIGNAL] = { 0 };
|
2001-02-02 02:44:22 +08:00
|
|
|
|
2001-09-26 01:44:03 +08:00
|
|
|
|
|
|
|
static void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_class_init (GimpProjectionClass *klass)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
2014-06-04 07:23:41 +08:00
|
|
|
const gchar *env;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
projection_signals[UPDATE] =
|
|
|
|
g_signal_new ("update",
|
2006-04-12 20:49:29 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpProjectionClass, update),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__BOOLEAN_INT_INT_INT_INT,
|
|
|
|
G_TYPE_NONE, 5,
|
2004-07-14 00:36:29 +08:00
|
|
|
G_TYPE_BOOLEAN,
|
2006-04-12 20:49:29 +08:00
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT);
|
2004-07-14 00:36:29 +08:00
|
|
|
|
|
|
|
object_class->finalize = gimp_projection_finalize;
|
2013-09-05 16:37:09 +08:00
|
|
|
object_class->set_property = gimp_projection_set_property;
|
|
|
|
object_class->get_property = gimp_projection_get_property;
|
2004-07-14 00:36:29 +08:00
|
|
|
|
|
|
|
gimp_object_class->get_memsize = gimp_projection_get_memsize;
|
2013-09-05 16:37:09 +08:00
|
|
|
|
|
|
|
g_object_class_override_property (object_class, PROP_BUFFER, "buffer");
|
2014-05-31 06:08:43 +08:00
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (GimpProjectionPrivate));
|
2014-06-04 07:23:41 +08:00
|
|
|
|
|
|
|
env = g_getenv ("GIMP_DISPLAY_RENDER_BUF_SIZE");
|
|
|
|
if (env)
|
|
|
|
{
|
|
|
|
gint width = atoi (env);
|
|
|
|
gint height = width;
|
|
|
|
|
|
|
|
env = strchr (env, 'x');
|
|
|
|
if (env)
|
2014-06-04 08:06:55 +08:00
|
|
|
height = atoi (env + 1);
|
2014-06-04 07:23:41 +08:00
|
|
|
|
|
|
|
if (width > 0 && width <= 8192 &&
|
|
|
|
height > 0 && height <= 8192)
|
|
|
|
{
|
|
|
|
GIMP_PROJECTION_CHUNK_WIDTH = width;
|
|
|
|
GIMP_PROJECTION_CHUNK_HEIGHT = height;
|
|
|
|
}
|
|
|
|
}
|
2001-09-26 01:44:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_init (GimpProjection *proj)
|
2001-09-26 01:44:03 +08:00
|
|
|
{
|
2014-05-31 06:08:43 +08:00
|
|
|
proj->priv = G_TYPE_INSTANCE_GET_PRIVATE (proj,
|
|
|
|
GIMP_TYPE_PROJECTION,
|
|
|
|
GimpProjectionPrivate);
|
2001-09-26 01:44:03 +08:00
|
|
|
}
|
|
|
|
|
2004-07-14 07:04:05 +08:00
|
|
|
static void
|
2005-12-11 03:24:36 +08:00
|
|
|
gimp_projection_pickable_iface_init (GimpPickableInterface *iface)
|
2004-07-14 07:04:05 +08:00
|
|
|
{
|
2012-03-18 23:20:01 +08:00
|
|
|
iface->flush = gimp_projection_pickable_flush;
|
|
|
|
iface->get_image = gimp_projection_get_image;
|
|
|
|
iface->get_format = gimp_projection_get_format;
|
|
|
|
iface->get_format_with_alpha = gimp_projection_get_format; /* sic */
|
|
|
|
iface->get_buffer = gimp_projection_get_buffer;
|
|
|
|
iface->get_pixel_at = gimp_projection_get_pixel_at;
|
|
|
|
iface->get_opacity_at = gimp_projection_get_opacity_at;
|
2018-05-19 02:57:19 +08:00
|
|
|
iface->get_pixel_average = gimp_projection_get_pixel_average;
|
2016-05-23 05:28:31 +08:00
|
|
|
iface->pixel_to_srgb = gimp_projection_pixel_to_srgb;
|
2016-05-23 07:25:35 +08:00
|
|
|
iface->srgb_to_pixel = gimp_projection_srgb_to_pixel;
|
2004-07-14 07:04:05 +08:00
|
|
|
}
|
|
|
|
|
2002-05-10 21:09:19 +08:00
|
|
|
static void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_finalize (GObject *object)
|
2002-05-10 21:09:19 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
GimpProjection *proj = GIMP_PROJECTION (object);
|
2004-07-12 19:43:00 +08:00
|
|
|
|
2012-07-06 03:42:26 +08:00
|
|
|
gimp_projection_free_buffer (proj);
|
2008-11-11 06:15:40 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2002-05-10 21:09:19 +08:00
|
|
|
}
|
|
|
|
|
2013-09-05 16:37:09 +08:00
|
|
|
static void
|
|
|
|
gimp_projection_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_BUFFER:
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_projection_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpProjection *projection = GIMP_PROJECTION (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_BUFFER:
|
2014-05-31 06:08:43 +08:00
|
|
|
g_value_set_object (value, projection->priv->buffer);
|
2013-09-05 16:37:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
static gint64
|
|
|
|
gimp_projection_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size)
|
2001-09-26 01:44:03 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
GimpProjection *projection = GIMP_PROJECTION (object);
|
2007-06-21 00:15:16 +08:00
|
|
|
gint64 memsize = 0;
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2014-06-16 00:21:05 +08:00
|
|
|
memsize += gimp_gegl_pyramid_get_memsize (projection->priv->buffer);
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
|
|
|
|
gui_size);
|
|
|
|
}
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2007-06-06 18:03:17 +08:00
|
|
|
/**
|
|
|
|
* gimp_projection_estimate_memsize:
|
2014-06-15 05:20:52 +08:00
|
|
|
* @type: the projectable's base type
|
|
|
|
* @component_type: the projectable's component type
|
|
|
|
* @width: projection width
|
|
|
|
* @height: projection height
|
2007-06-06 18:03:17 +08:00
|
|
|
*
|
|
|
|
* Calculates a rough estimate of the memory that is required for the
|
|
|
|
* projection of an image with the given @width and @height.
|
|
|
|
*
|
|
|
|
* Return value: a rough estimate of the memory requirements.
|
|
|
|
**/
|
|
|
|
gint64
|
|
|
|
gimp_projection_estimate_memsize (GimpImageBaseType type,
|
2014-06-15 05:20:52 +08:00
|
|
|
GimpComponentType component_type,
|
2007-06-06 18:03:17 +08:00
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
2012-08-25 04:16:02 +08:00
|
|
|
const Babl *format;
|
|
|
|
gint64 bytes;
|
2007-06-06 18:48:00 +08:00
|
|
|
|
2012-08-25 04:16:02 +08:00
|
|
|
if (type == GIMP_INDEXED)
|
|
|
|
type = GIMP_RGB;
|
|
|
|
|
2014-06-15 05:20:52 +08:00
|
|
|
format = gimp_babl_format (type,
|
|
|
|
gimp_babl_precision (component_type, FALSE),
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 20:23:01 +08:00
|
|
|
TRUE, NULL);
|
2012-08-25 04:16:02 +08:00
|
|
|
bytes = babl_format_get_bytes_per_pixel (format);
|
2007-06-06 18:48:00 +08:00
|
|
|
|
2007-06-21 00:15:16 +08:00
|
|
|
/* The pyramid levels constitute a geometric sum with a ratio of 1/4. */
|
2007-06-06 21:45:44 +08:00
|
|
|
return bytes * (gint64) width * (gint64) height * 1.33;
|
2007-06-06 18:03:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-03 03:30:59 +08:00
|
|
|
static void
|
|
|
|
gimp_projection_pickable_flush (GimpPickable *pickable)
|
|
|
|
{
|
|
|
|
GimpProjection *proj = GIMP_PROJECTION (pickable);
|
|
|
|
|
2012-12-19 02:30:33 +08:00
|
|
|
/* create the buffer if it doesn't exist */
|
|
|
|
gimp_projection_get_buffer (pickable);
|
|
|
|
|
2006-03-03 03:30:59 +08:00
|
|
|
gimp_projection_finish_draw (proj);
|
|
|
|
gimp_projection_flush_now (proj);
|
2007-08-02 22:54:29 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
if (proj->priv->invalidate_preview)
|
2007-08-02 22:54:29 +08:00
|
|
|
{
|
|
|
|
/* invalidate the preview here since it is constructed from
|
|
|
|
* the projection
|
|
|
|
*/
|
2014-05-31 06:08:43 +08:00
|
|
|
proj->priv->invalidate_preview = FALSE;
|
2007-08-02 22:54:29 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
gimp_projectable_invalidate_preview (proj->priv->projectable);
|
2007-08-02 22:54:29 +08:00
|
|
|
}
|
2006-03-03 03:30:59 +08:00
|
|
|
}
|
|
|
|
|
2008-11-04 20:07:17 +08:00
|
|
|
static GimpImage *
|
|
|
|
gimp_projection_get_image (GimpPickable *pickable)
|
|
|
|
{
|
|
|
|
GimpProjection *proj = GIMP_PROJECTION (pickable);
|
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
return gimp_projectable_get_image (proj->priv->projectable);
|
2008-11-04 20:07:17 +08:00
|
|
|
}
|
|
|
|
|
2012-03-17 22:21:11 +08:00
|
|
|
static const Babl *
|
2012-03-18 23:20:01 +08:00
|
|
|
gimp_projection_get_format (GimpPickable *pickable)
|
2012-03-17 22:21:11 +08:00
|
|
|
{
|
|
|
|
GimpProjection *proj = GIMP_PROJECTION (pickable);
|
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
return gimp_projectable_get_format (proj->priv->projectable);
|
2012-03-17 22:21:11 +08:00
|
|
|
}
|
|
|
|
|
2012-03-15 21:38:54 +08:00
|
|
|
static GeglBuffer *
|
|
|
|
gimp_projection_get_buffer (GimpPickable *pickable)
|
|
|
|
{
|
|
|
|
GimpProjection *proj = GIMP_PROJECTION (pickable);
|
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
if (! proj->priv->buffer)
|
2012-03-15 21:38:54 +08:00
|
|
|
{
|
2018-08-04 00:34:47 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
2012-06-21 03:44:09 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
gimp_projectable_get_size (proj->priv->projectable, &width, &height);
|
2012-03-15 21:38:54 +08:00
|
|
|
|
2018-08-04 00:34:47 +08:00
|
|
|
gimp_projection_allocate_buffer (proj);
|
2015-03-11 15:14:00 +08:00
|
|
|
|
|
|
|
/* This used to call gimp_tile_handler_validate_invalidate()
|
2012-12-16 02:33:21 +08:00
|
|
|
* which forced the entire projection to be constructed in one
|
|
|
|
* go for new images, causing a potentially huge delay. Now we
|
|
|
|
* initially validate stuff the normal way, which makes the
|
|
|
|
* image appear incrementally, but it keeps everything
|
|
|
|
* responsive.
|
|
|
|
*/
|
|
|
|
gimp_projection_add_update_area (proj, 0, 0, width, height);
|
2014-05-31 06:08:43 +08:00
|
|
|
proj->priv->invalidate_preview = TRUE;
|
2012-12-16 02:33:21 +08:00
|
|
|
gimp_projection_flush (proj);
|
2012-03-15 21:38:54 +08:00
|
|
|
}
|
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
return proj->priv->buffer;
|
2012-03-15 21:38:54 +08:00
|
|
|
}
|
|
|
|
|
2007-04-28 00:07:49 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_projection_get_pixel_at (GimpPickable *pickable,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
2012-04-21 16:03:32 +08:00
|
|
|
const Babl *format,
|
|
|
|
gpointer pixel)
|
2007-04-28 00:07:49 +08:00
|
|
|
{
|
2012-03-19 17:46:47 +08:00
|
|
|
GeglBuffer *buffer = gimp_projection_get_buffer (pickable);
|
2007-04-28 00:07:49 +08:00
|
|
|
|
2012-03-19 17:46:47 +08:00
|
|
|
if (x < 0 ||
|
|
|
|
y < 0 ||
|
|
|
|
x >= gegl_buffer_get_width (buffer) ||
|
|
|
|
y >= gegl_buffer_get_height (buffer))
|
2007-04-28 00:07:49 +08:00
|
|
|
return FALSE;
|
|
|
|
|
2012-04-21 16:03:32 +08:00
|
|
|
gegl_buffer_sample (buffer, x, y, NULL, pixel, format,
|
2012-03-26 08:17:24 +08:00
|
|
|
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
|
2007-04-28 00:07:49 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-04-21 22:05:49 +08:00
|
|
|
static gdouble
|
2005-07-12 03:21:52 +08:00
|
|
|
gimp_projection_get_opacity_at (GimpPickable *pickable,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
|
|
|
{
|
2012-04-21 22:05:49 +08:00
|
|
|
return GIMP_OPACITY_OPAQUE;
|
2005-07-12 03:21:52 +08:00
|
|
|
}
|
|
|
|
|
2018-05-19 02:57:19 +08:00
|
|
|
static void
|
|
|
|
gimp_projection_get_pixel_average (GimpPickable *pickable,
|
|
|
|
const GeglRectangle *rect,
|
|
|
|
const Babl *format,
|
|
|
|
gpointer pixel)
|
|
|
|
{
|
|
|
|
GeglBuffer *buffer = gimp_projection_get_buffer (pickable);
|
|
|
|
|
|
|
|
return gimp_gegl_average_color (buffer, rect, TRUE, GEGL_ABYSS_NONE, format,
|
|
|
|
pixel);
|
|
|
|
}
|
|
|
|
|
2016-05-23 05:28:31 +08:00
|
|
|
static void
|
|
|
|
gimp_projection_pixel_to_srgb (GimpPickable *pickable,
|
|
|
|
const Babl *format,
|
|
|
|
gpointer pixel,
|
|
|
|
GimpRGB *color)
|
|
|
|
{
|
|
|
|
GimpProjection *proj = GIMP_PROJECTION (pickable);
|
|
|
|
GimpImage *image = gimp_projectable_get_image (proj->priv->projectable);
|
|
|
|
|
|
|
|
gimp_pickable_pixel_to_srgb (GIMP_PICKABLE (image), format, pixel, color);
|
|
|
|
}
|
|
|
|
|
2016-05-23 07:25:35 +08:00
|
|
|
static void
|
|
|
|
gimp_projection_srgb_to_pixel (GimpPickable *pickable,
|
|
|
|
const GimpRGB *color,
|
|
|
|
const Babl *format,
|
|
|
|
gpointer pixel)
|
|
|
|
{
|
|
|
|
GimpProjection *proj = GIMP_PROJECTION (pickable);
|
|
|
|
GimpImage *image = gimp_projectable_get_image (proj->priv->projectable);
|
|
|
|
|
|
|
|
gimp_pickable_srgb_to_pixel (GIMP_PICKABLE (image), color, format, pixel);
|
|
|
|
}
|
|
|
|
|
2016-05-23 05:28:31 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
GimpProjection *
|
2008-11-05 02:06:36 +08:00
|
|
|
gimp_projection_new (GimpProjectable *projectable)
|
2004-07-14 00:36:29 +08:00
|
|
|
{
|
|
|
|
GimpProjection *proj;
|
|
|
|
|
2008-11-05 02:06:36 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PROJECTABLE (projectable), NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
proj = g_object_new (GIMP_TYPE_PROJECTION, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
proj->priv->projectable = projectable;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2009-08-26 19:06:55 +08:00
|
|
|
g_signal_connect_object (projectable, "invalidate",
|
|
|
|
G_CALLBACK (gimp_projection_projectable_invalidate),
|
|
|
|
proj, 0);
|
2008-11-05 02:06:36 +08:00
|
|
|
g_signal_connect_object (projectable, "flush",
|
|
|
|
G_CALLBACK (gimp_projection_projectable_flush),
|
2004-07-14 00:36:29 +08:00
|
|
|
proj, 0);
|
2008-11-05 07:22:45 +08:00
|
|
|
g_signal_connect_object (projectable, "structure-changed",
|
2018-08-04 00:34:47 +08:00
|
|
|
G_CALLBACK (gimp_projection_projectable_structure_changed),
|
|
|
|
proj, 0);
|
|
|
|
g_signal_connect_object (projectable, "bounds-changed",
|
|
|
|
G_CALLBACK (gimp_projection_projectable_bounds_changed),
|
2004-07-14 00:36:29 +08:00
|
|
|
proj, 0);
|
2001-11-10 00:54:56 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
return proj;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2017-12-02 22:48:14 +08:00
|
|
|
void
|
|
|
|
gimp_projection_set_priority (GimpProjection *proj,
|
|
|
|
gint priority)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
|
|
|
|
|
|
|
proj->priv->priority = priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
gimp_projection_get_priority (GimpProjection *proj)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_PROJECTION (proj), 0);
|
|
|
|
|
|
|
|
return proj->priv->priority;
|
|
|
|
}
|
|
|
|
|
2014-05-31 08:34:56 +08:00
|
|
|
void
|
|
|
|
gimp_projection_set_priority_rect (GimpProjection *proj,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
2014-05-31 21:13:32 +08:00
|
|
|
gint w,
|
|
|
|
gint h)
|
2014-05-31 08:34:56 +08:00
|
|
|
{
|
2014-06-02 03:30:11 +08:00
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
gint off_x, off_y;
|
2014-06-30 05:57:22 +08:00
|
|
|
gint width, height;
|
2014-05-31 08:34:56 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
|
|
|
|
|
|
|
gimp_projectable_get_offset (proj->priv->projectable, &off_x, &off_y);
|
2014-05-31 21:13:32 +08:00
|
|
|
gimp_projectable_get_size (proj->priv->projectable, &width, &height);
|
2014-05-31 08:34:56 +08:00
|
|
|
|
|
|
|
/* subtract the projectable's offsets because the list of update
|
|
|
|
* areas is in tile-pyramid coordinates, but our external API is
|
|
|
|
* always in terms of image coordinates.
|
|
|
|
*/
|
|
|
|
x -= off_x;
|
|
|
|
y -= off_y;
|
|
|
|
|
2014-06-02 03:30:11 +08:00
|
|
|
if (gimp_rectangle_intersect (x, y, w, h,
|
|
|
|
0, 0, width, height,
|
|
|
|
&rect.x, &rect.y, &rect.width, &rect.height))
|
|
|
|
{
|
|
|
|
proj->priv->priority_rect = rect;
|
2014-05-31 08:34:56 +08:00
|
|
|
|
2014-06-02 03:30:11 +08:00
|
|
|
if (proj->priv->chunk_render.idle_id)
|
|
|
|
gimp_projection_chunk_render_init (proj);
|
|
|
|
}
|
2014-05-31 08:34:56 +08:00
|
|
|
}
|
|
|
|
|
2014-06-30 05:57:22 +08:00
|
|
|
void
|
|
|
|
gimp_projection_stop_rendering (GimpProjection *proj)
|
|
|
|
{
|
|
|
|
GimpProjectionChunkRender *chunk_render;
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
|
|
|
|
|
|
|
chunk_render = &proj->priv->chunk_render;
|
|
|
|
|
|
|
|
if (! chunk_render->idle_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (chunk_render->update_region)
|
|
|
|
{
|
|
|
|
if (proj->priv->update_region)
|
|
|
|
{
|
|
|
|
cairo_region_union (proj->priv->update_region,
|
|
|
|
chunk_render->update_region);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
proj->priv->update_region =
|
|
|
|
cairo_region_copy (chunk_render->update_region);
|
|
|
|
}
|
|
|
|
|
2017-07-16 00:38:01 +08:00
|
|
|
g_clear_pointer (&chunk_render->update_region, cairo_region_destroy);
|
2014-06-30 05:57:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rect.x = chunk_render->x;
|
|
|
|
rect.y = chunk_render->work_y;
|
|
|
|
rect.width = chunk_render->width;
|
|
|
|
rect.height = chunk_render->height - (chunk_render->work_y - chunk_render->y);
|
|
|
|
|
|
|
|
/* FIXME this is too much, the entire current row */
|
|
|
|
if (proj->priv->update_region)
|
|
|
|
cairo_region_union_rectangle (proj->priv->update_region, &rect);
|
|
|
|
else
|
|
|
|
proj->priv->update_region = cairo_region_create_rectangle (&rect);
|
|
|
|
|
|
|
|
gimp_projection_chunk_render_stop (proj);
|
|
|
|
}
|
|
|
|
|
1998-10-02 00:22:28 +08:00
|
|
|
void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_flush (GimpProjection *proj)
|
1998-10-02 00:22:28 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2013-07-28 21:57:28 +08:00
|
|
|
/* Construct in chunks */
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_flush_whenever (proj, FALSE);
|
1998-10-02 00:22:28 +08:00
|
|
|
}
|
|
|
|
|
2001-02-20 23:15:30 +08:00
|
|
|
void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_flush_now (GimpProjection *proj)
|
2001-02-20 23:15:30 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
2001-02-20 23:15:30 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
/* Construct NOW */
|
|
|
|
gimp_projection_flush_whenever (proj, TRUE);
|
2001-11-01 05:20:09 +08:00
|
|
|
}
|
2001-02-20 23:15:30 +08:00
|
|
|
|
2004-07-14 18:31:59 +08:00
|
|
|
void
|
|
|
|
gimp_projection_finish_draw (GimpProjection *proj)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
|
|
|
|
2014-05-31 07:42:28 +08:00
|
|
|
if (proj->priv->chunk_render.idle_id)
|
2004-07-14 18:31:59 +08:00
|
|
|
{
|
2013-07-28 21:57:28 +08:00
|
|
|
gimp_projection_chunk_render_stop (proj);
|
2004-07-14 18:31:59 +08:00
|
|
|
|
2017-04-23 02:22:06 +08:00
|
|
|
gimp_projectable_begin_render (proj->priv->projectable);
|
|
|
|
|
2018-08-20 15:00:10 +08:00
|
|
|
while (gimp_projection_chunk_render_iteration (proj, FALSE));
|
2017-04-23 02:22:06 +08:00
|
|
|
|
|
|
|
gimp_projectable_end_render (proj->priv->projectable);
|
2004-07-14 18:31:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-14 21:39:35 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
/* private functions */
|
2002-10-14 21:39:35 +08:00
|
|
|
|
2018-08-04 00:34:47 +08:00
|
|
|
static void
|
|
|
|
gimp_projection_allocate_buffer (GimpProjection *proj)
|
|
|
|
{
|
|
|
|
const Babl *format;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
|
|
|
|
if (proj->priv->buffer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
format = gimp_projection_get_format (GIMP_PICKABLE (proj));
|
|
|
|
gimp_projectable_get_size (proj->priv->projectable, &width, &height);
|
|
|
|
|
|
|
|
proj->priv->buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, width, height),
|
|
|
|
format);
|
|
|
|
|
|
|
|
proj->priv->validate_handler =
|
|
|
|
GIMP_TILE_HANDLER_VALIDATE (
|
|
|
|
gimp_tile_handler_projectable_new (proj->priv->projectable));
|
|
|
|
|
|
|
|
gimp_tile_handler_validate_assign (proj->priv->validate_handler,
|
|
|
|
proj->priv->buffer);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (proj), "buffer");
|
|
|
|
}
|
|
|
|
|
2012-07-06 03:42:26 +08:00
|
|
|
static void
|
|
|
|
gimp_projection_free_buffer (GimpProjection *proj)
|
|
|
|
{
|
2014-05-31 21:13:32 +08:00
|
|
|
if (proj->priv->chunk_render.idle_id)
|
|
|
|
gimp_projection_chunk_render_stop (proj);
|
|
|
|
|
2017-07-16 00:38:01 +08:00
|
|
|
g_clear_pointer (&proj->priv->update_region, cairo_region_destroy);
|
|
|
|
g_clear_pointer (&proj->priv->chunk_render.update_region, cairo_region_destroy);
|
2014-05-31 21:13:32 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
if (proj->priv->buffer)
|
2012-07-06 03:42:26 +08:00
|
|
|
{
|
2014-05-31 06:08:43 +08:00
|
|
|
if (proj->priv->validate_handler)
|
2018-08-04 00:03:12 +08:00
|
|
|
{
|
|
|
|
gimp_tile_handler_validate_unassign (proj->priv->validate_handler,
|
|
|
|
proj->priv->buffer);
|
|
|
|
}
|
2012-07-06 03:42:26 +08:00
|
|
|
|
2017-07-16 00:38:01 +08:00
|
|
|
g_clear_object (&proj->priv->buffer);
|
2012-07-06 03:42:26 +08:00
|
|
|
}
|
|
|
|
|
2017-07-16 00:38:01 +08:00
|
|
|
g_clear_object (&proj->priv->validate_handler);
|
2012-07-06 03:42:26 +08:00
|
|
|
}
|
|
|
|
|
2004-07-14 18:31:59 +08:00
|
|
|
static void
|
|
|
|
gimp_projection_add_update_area (GimpProjection *proj,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
|
|
|
{
|
2018-08-10 14:36:29 +08:00
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
gint width, height;
|
2004-07-14 18:31:59 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
gimp_projectable_get_size (proj->priv->projectable, &width, &height);
|
2009-08-24 21:59:14 +08:00
|
|
|
|
2018-03-31 20:13:36 +08:00
|
|
|
/* align the rectangle to the UPDATE_CHUNK_WIDTH x UPDATE_CHUNK_HEIGHT grid,
|
|
|
|
* to decrease the complexity of the update area.
|
|
|
|
*/
|
|
|
|
w = ceil ((gdouble) (x + w) / GIMP_PROJECTION_UPDATE_CHUNK_WIDTH ) * GIMP_PROJECTION_UPDATE_CHUNK_WIDTH;
|
|
|
|
h = ceil ((gdouble) (y + h) / GIMP_PROJECTION_UPDATE_CHUNK_HEIGHT) * GIMP_PROJECTION_UPDATE_CHUNK_HEIGHT;
|
|
|
|
x = floor ((gdouble) x / GIMP_PROJECTION_UPDATE_CHUNK_WIDTH ) * GIMP_PROJECTION_UPDATE_CHUNK_WIDTH;
|
|
|
|
y = floor ((gdouble) y / GIMP_PROJECTION_UPDATE_CHUNK_HEIGHT) * GIMP_PROJECTION_UPDATE_CHUNK_HEIGHT;
|
|
|
|
|
|
|
|
w -= x;
|
|
|
|
h -= y;
|
|
|
|
|
2014-06-02 03:30:11 +08:00
|
|
|
if (gimp_rectangle_intersect (x, y, w, h,
|
|
|
|
0, 0, width, height,
|
|
|
|
&rect.x, &rect.y, &rect.width, &rect.height))
|
|
|
|
{
|
|
|
|
if (proj->priv->update_region)
|
|
|
|
cairo_region_union_rectangle (proj->priv->update_region, &rect);
|
|
|
|
else
|
|
|
|
proj->priv->update_region = cairo_region_create_rectangle (&rect);
|
|
|
|
}
|
2004-07-14 18:31:59 +08:00
|
|
|
}
|
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
static void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_flush_whenever (GimpProjection *proj,
|
|
|
|
gboolean now)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2014-05-31 07:22:54 +08:00
|
|
|
if (proj->priv->update_region)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2004-07-12 19:43:00 +08:00
|
|
|
if (now) /* Synchronous */
|
2003-07-30 00:36:56 +08:00
|
|
|
{
|
2014-05-31 07:22:54 +08:00
|
|
|
gint n_rects = cairo_region_num_rectangles (proj->priv->update_region);
|
|
|
|
gint i;
|
2003-07-30 00:36:56 +08:00
|
|
|
|
2014-05-31 07:22:54 +08:00
|
|
|
for (i = 0; i < n_rects; i++)
|
2003-07-30 00:36:56 +08:00
|
|
|
{
|
2014-05-31 07:22:54 +08:00
|
|
|
cairo_rectangle_int_t rect;
|
2003-07-30 00:36:56 +08:00
|
|
|
|
2014-05-31 07:22:54 +08:00
|
|
|
cairo_region_get_rectangle (proj->priv->update_region,
|
|
|
|
i, &rect);
|
|
|
|
|
|
|
|
gimp_projection_paint_area (proj,
|
|
|
|
FALSE, /* sic! */
|
|
|
|
rect.x,
|
|
|
|
rect.y,
|
|
|
|
rect.width,
|
|
|
|
rect.height);
|
2003-07-30 00:36:56 +08:00
|
|
|
}
|
|
|
|
}
|
2004-07-12 19:43:00 +08:00
|
|
|
else /* Asynchronous */
|
2003-07-30 00:36:56 +08:00
|
|
|
{
|
2013-07-28 21:57:28 +08:00
|
|
|
gimp_projection_chunk_render_init (proj);
|
2003-07-30 00:36:56 +08:00
|
|
|
}
|
|
|
|
|
2014-05-31 07:22:54 +08:00
|
|
|
/* Free the update region */
|
2017-07-16 00:38:01 +08:00
|
|
|
g_clear_pointer (&proj->priv->update_region, cairo_region_destroy);
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
2014-05-31 06:08:43 +08:00
|
|
|
else if (! now && proj->priv->invalidate_preview)
|
2007-06-27 05:39:51 +08:00
|
|
|
{
|
|
|
|
/* invalidate the preview here since it is constructed from
|
|
|
|
* the projection
|
|
|
|
*/
|
2014-05-31 06:08:43 +08:00
|
|
|
proj->priv->invalidate_preview = FALSE;
|
2007-06-27 05:39:51 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
gimp_projectable_invalidate_preview (proj->priv->projectable);
|
2007-06-27 05:39:51 +08:00
|
|
|
}
|
2004-07-14 00:36:29 +08:00
|
|
|
}
|
2001-11-11 07:03:22 +08:00
|
|
|
|
|
|
|
static void
|
2013-07-28 21:57:28 +08:00
|
|
|
gimp_projection_chunk_render_start (GimpProjection *proj)
|
|
|
|
{
|
2014-05-31 07:42:28 +08:00
|
|
|
g_return_if_fail (proj->priv->chunk_render.idle_id == 0);
|
2013-07-28 21:57:28 +08:00
|
|
|
|
2014-05-31 07:42:28 +08:00
|
|
|
proj->priv->chunk_render.idle_id =
|
2017-12-02 22:48:14 +08:00
|
|
|
g_idle_add_full (GIMP_PRIORITY_PROJECTION_IDLE + proj->priv->priority,
|
2013-07-28 21:57:28 +08:00
|
|
|
gimp_projection_chunk_render_callback, proj,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_projection_chunk_render_stop (GimpProjection *proj)
|
|
|
|
{
|
2014-05-31 07:42:28 +08:00
|
|
|
g_return_if_fail (proj->priv->chunk_render.idle_id != 0);
|
2013-07-28 21:57:28 +08:00
|
|
|
|
2014-05-31 07:42:28 +08:00
|
|
|
g_source_remove (proj->priv->chunk_render.idle_id);
|
|
|
|
proj->priv->chunk_render.idle_id = 0;
|
2013-07-28 21:57:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_projection_chunk_render_callback (gpointer data)
|
|
|
|
{
|
2013-08-10 02:20:02 +08:00
|
|
|
GimpProjection *proj = data;
|
|
|
|
GTimer *timer = g_timer_new ();
|
|
|
|
gint chunks = 0;
|
|
|
|
gboolean retval = TRUE;
|
2013-07-28 21:57:28 +08:00
|
|
|
|
2017-04-23 02:22:06 +08:00
|
|
|
gimp_projectable_begin_render (proj->priv->projectable);
|
|
|
|
|
2013-08-10 02:20:02 +08:00
|
|
|
do
|
2013-07-28 21:57:28 +08:00
|
|
|
{
|
2018-08-20 15:00:10 +08:00
|
|
|
if (! gimp_projection_chunk_render_iteration (proj, TRUE))
|
2013-08-10 02:20:02 +08:00
|
|
|
{
|
|
|
|
gimp_projection_chunk_render_stop (proj);
|
|
|
|
|
|
|
|
retval = FALSE;
|
2013-07-28 21:57:28 +08:00
|
|
|
|
2013-08-10 02:20:02 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
chunks++;
|
2013-07-28 21:57:28 +08:00
|
|
|
}
|
2013-08-10 02:20:02 +08:00
|
|
|
while (g_timer_elapsed (timer, NULL) < GIMP_PROJECTION_CHUNK_TIME);
|
2013-07-28 21:57:28 +08:00
|
|
|
|
2017-04-23 02:22:06 +08:00
|
|
|
gimp_projectable_end_render (proj->priv->projectable);
|
|
|
|
|
2013-08-10 02:20:02 +08:00
|
|
|
GIMP_LOG (PROJECTION, "%d chunks in %f seconds\n",
|
|
|
|
chunks, g_timer_elapsed (timer, NULL));
|
|
|
|
g_timer_destroy (timer);
|
|
|
|
|
|
|
|
return retval;
|
2013-07-28 21:57:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_projection_chunk_render_init (GimpProjection *proj)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
GimpProjectionChunkRender *chunk_render = &proj->priv->chunk_render;
|
|
|
|
|
2013-07-28 21:57:28 +08:00
|
|
|
/* We need to merge the ChunkRender's and the GimpProjection's
|
2014-05-31 07:22:54 +08:00
|
|
|
* update_regions list to keep track of which of the updates have
|
|
|
|
* been flushed and hence need to be drawn.
|
2001-11-11 07:03:22 +08:00
|
|
|
*/
|
2014-05-31 07:22:54 +08:00
|
|
|
if (proj->priv->update_region)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
if (chunk_render->update_region)
|
2014-05-31 07:22:54 +08:00
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
cairo_region_union (chunk_render->update_region,
|
2014-05-31 07:22:54 +08:00
|
|
|
proj->priv->update_region);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
chunk_render->update_region =
|
2014-05-31 07:22:54 +08:00
|
|
|
cairo_region_copy (proj->priv->update_region);
|
|
|
|
}
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
|
|
|
|
2013-07-28 21:57:28 +08:00
|
|
|
/* If a chunk renderer was already running, merge the remainder of
|
|
|
|
* its unrendered area with the update_areas list, and make it start
|
|
|
|
* work on the next unrendered area in the list.
|
2001-11-11 07:03:22 +08:00
|
|
|
*/
|
2014-05-31 08:58:21 +08:00
|
|
|
if (chunk_render->idle_id)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2014-05-31 07:22:54 +08:00
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
rect.x = chunk_render->x;
|
|
|
|
rect.y = chunk_render->work_y;
|
|
|
|
rect.width = chunk_render->width;
|
|
|
|
rect.height = (chunk_render->height -
|
|
|
|
(chunk_render->work_y - chunk_render->y));
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
if (chunk_render->update_region)
|
|
|
|
cairo_region_union_rectangle (chunk_render->update_region, &rect);
|
2014-05-31 08:34:56 +08:00
|
|
|
else
|
2014-05-31 08:58:21 +08:00
|
|
|
chunk_render->update_region = cairo_region_create_rectangle (&rect);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2013-07-28 21:57:28 +08:00
|
|
|
gimp_projection_chunk_render_next_area (proj);
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
if (chunk_render->update_region == NULL)
|
2004-07-14 00:36:29 +08:00
|
|
|
{
|
2014-05-31 07:22:54 +08:00
|
|
|
g_warning ("%s: wanted to start chunk render with no update_region",
|
2004-07-14 18:31:59 +08:00
|
|
|
G_STRFUNC);
|
2004-07-14 00:36:29 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-28 21:57:28 +08:00
|
|
|
gimp_projection_chunk_render_next_area (proj);
|
2004-07-14 00:36:29 +08:00
|
|
|
|
2013-07-28 21:57:28 +08:00
|
|
|
gimp_projection_chunk_render_start (proj);
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
/* Unless specified otherwise, projection re-rendering is organised by
|
2013-07-28 21:57:28 +08:00
|
|
|
* ChunkRender, which amalgamates areas to be re-rendered and breaks
|
|
|
|
* them into bite-sized chunks which are chewed on in an idle
|
|
|
|
* function. This greatly improves responsiveness for many GIMP
|
2001-11-11 07:03:22 +08:00
|
|
|
* operations. -- Adam
|
|
|
|
*/
|
|
|
|
static gboolean
|
2018-08-20 15:00:10 +08:00
|
|
|
gimp_projection_chunk_render_iteration (GimpProjection *proj,
|
|
|
|
gboolean chunk)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
GimpProjectionChunkRender *chunk_render = &proj->priv->chunk_render;
|
|
|
|
gint work_x = chunk_render->work_x;
|
|
|
|
gint work_y = chunk_render->work_y;
|
|
|
|
gint work_w;
|
|
|
|
gint work_h;
|
2004-07-14 18:31:59 +08:00
|
|
|
|
2018-08-20 15:00:10 +08:00
|
|
|
work_w = chunk_render->x + chunk_render->width - work_x;
|
|
|
|
work_h = chunk_render->y + chunk_render->height - work_y;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2018-08-20 15:00:10 +08:00
|
|
|
if (chunk)
|
|
|
|
work_w = MIN (work_w, GIMP_PROJECTION_CHUNK_WIDTH);
|
|
|
|
|
|
|
|
if (chunk || work_x != chunk_render->x)
|
|
|
|
work_h = MIN (work_h, GIMP_PROJECTION_CHUNK_HEIGHT);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 18:31:59 +08:00
|
|
|
gimp_projection_paint_area (proj, TRUE /* sic! */,
|
2014-05-31 07:42:28 +08:00
|
|
|
work_x, work_y, work_w, work_h);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-07-01 05:12:53 +08:00
|
|
|
chunk_render->work_x += work_w;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
if (chunk_render->work_x >= chunk_render->x + chunk_render->width)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
chunk_render->work_x = chunk_render->x;
|
2014-05-31 07:42:28 +08:00
|
|
|
|
2014-07-01 05:12:53 +08:00
|
|
|
chunk_render->work_y += work_h;
|
2004-07-14 00:36:29 +08:00
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
if (chunk_render->work_y >= chunk_render->y + chunk_render->height)
|
2004-07-14 00:36:29 +08:00
|
|
|
{
|
2013-07-28 21:57:28 +08:00
|
|
|
if (! gimp_projection_chunk_render_next_area (proj))
|
2004-07-14 00:36:29 +08:00
|
|
|
{
|
2014-05-31 06:08:43 +08:00
|
|
|
if (proj->priv->invalidate_preview)
|
2007-06-27 05:39:51 +08:00
|
|
|
{
|
|
|
|
/* invalidate the preview here since it is constructed from
|
|
|
|
* the projection
|
|
|
|
*/
|
2014-05-31 06:08:43 +08:00
|
|
|
proj->priv->invalidate_preview = FALSE;
|
2007-06-27 05:39:51 +08:00
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
gimp_projectable_invalidate_preview (proj->priv->projectable);
|
2007-06-27 05:39:51 +08:00
|
|
|
}
|
|
|
|
|
2013-07-28 21:57:28 +08:00
|
|
|
/* FINISHED */
|
2004-07-14 00:36:29 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Still work to do. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2013-07-28 21:57:28 +08:00
|
|
|
gimp_projection_chunk_render_next_area (GimpProjection *proj)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2014-05-31 08:58:21 +08:00
|
|
|
GimpProjectionChunkRender *chunk_render = &proj->priv->chunk_render;
|
|
|
|
cairo_region_t *next_region;
|
|
|
|
cairo_rectangle_int_t rect;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
if (! chunk_render->update_region)
|
2001-11-16 23:08:59 +08:00
|
|
|
return FALSE;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
if (cairo_region_is_empty (chunk_render->update_region))
|
2014-05-31 07:22:54 +08:00
|
|
|
{
|
2017-07-16 00:38:01 +08:00
|
|
|
g_clear_pointer (&chunk_render->update_region, cairo_region_destroy);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-05-31 07:22:54 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
next_region = cairo_region_copy (chunk_render->update_region);
|
2014-05-31 08:34:56 +08:00
|
|
|
cairo_region_intersect_rectangle (next_region, &proj->priv->priority_rect);
|
|
|
|
|
|
|
|
if (cairo_region_is_empty (next_region))
|
2014-05-31 08:58:21 +08:00
|
|
|
cairo_region_get_rectangle (chunk_render->update_region, 0, &rect);
|
2014-05-31 08:34:56 +08:00
|
|
|
else
|
2014-05-31 08:58:21 +08:00
|
|
|
cairo_region_get_rectangle (next_region, 0, &rect);
|
2014-05-31 08:34:56 +08:00
|
|
|
|
|
|
|
cairo_region_destroy (next_region);
|
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
cairo_region_subtract_rectangle (chunk_render->update_region, &rect);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
if (cairo_region_is_empty (chunk_render->update_region))
|
2014-05-31 07:22:54 +08:00
|
|
|
{
|
2017-07-16 00:38:01 +08:00
|
|
|
g_clear_pointer (&chunk_render->update_region, cairo_region_destroy);
|
2014-05-31 07:22:54 +08:00
|
|
|
}
|
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
chunk_render->x = rect.x;
|
|
|
|
chunk_render->y = rect.y;
|
|
|
|
chunk_render->width = rect.width;
|
|
|
|
chunk_render->height = rect.height;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-05-31 08:58:21 +08:00
|
|
|
chunk_render->work_x = chunk_render->x;
|
|
|
|
chunk_render->work_y = chunk_render->y;
|
2014-05-31 07:42:28 +08:00
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_paint_area (GimpProjection *proj,
|
|
|
|
gboolean now,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2009-08-24 21:59:14 +08:00
|
|
|
gint off_x, off_y;
|
2008-11-05 02:06:36 +08:00
|
|
|
gint width, height;
|
|
|
|
|
2014-05-31 06:08:43 +08:00
|
|
|
gimp_projectable_get_offset (proj->priv->projectable, &off_x, &off_y);
|
|
|
|
gimp_projectable_get_size (proj->priv->projectable, &width, &height);
|
2008-08-13 00:30:44 +08:00
|
|
|
|
2014-06-02 03:30:11 +08:00
|
|
|
if (gimp_rectangle_intersect (x, y, w, h,
|
|
|
|
0, 0, width, height,
|
|
|
|
&x, &y, &w, &h))
|
2013-08-03 02:43:44 +08:00
|
|
|
{
|
2014-05-31 06:08:43 +08:00
|
|
|
if (proj->priv->validate_handler)
|
2015-03-11 15:14:00 +08:00
|
|
|
gimp_tile_handler_validate_invalidate (proj->priv->validate_handler,
|
2017-08-05 21:43:41 +08:00
|
|
|
GEGL_RECTANGLE (x, y, w, h));
|
2014-06-02 03:30:11 +08:00
|
|
|
if (now)
|
|
|
|
{
|
|
|
|
GeglNode *graph = gimp_projectable_get_graph (proj->priv->projectable);
|
2013-08-11 14:49:38 +08:00
|
|
|
|
2014-06-02 03:30:11 +08:00
|
|
|
if (proj->priv->validate_handler)
|
2015-03-11 15:14:00 +08:00
|
|
|
gimp_tile_handler_validate_undo_invalidate (proj->priv->validate_handler,
|
2017-08-05 21:43:41 +08:00
|
|
|
GEGL_RECTANGLE (x, y, w, h));
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2014-06-02 03:30:11 +08:00
|
|
|
gegl_node_blit_buffer (graph, proj->priv->buffer,
|
2015-11-21 10:18:56 +08:00
|
|
|
GEGL_RECTANGLE (x, y, w, h), 0, GEGL_ABYSS_NONE);
|
2014-06-02 03:30:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* add the projectable's offsets because the list of update areas
|
|
|
|
* is in tile-pyramid coordinates, but our external API is always
|
|
|
|
* in terms of image coordinates.
|
|
|
|
*/
|
|
|
|
g_signal_emit (proj, projection_signals[UPDATE], 0,
|
|
|
|
now,
|
|
|
|
x + off_x,
|
|
|
|
y + off_y,
|
|
|
|
w,
|
|
|
|
h);
|
|
|
|
}
|
2004-07-14 00:36:29 +08:00
|
|
|
}
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2012-06-21 03:44:09 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
/* image callbacks */
|
|
|
|
|
|
|
|
static void
|
2009-08-26 19:06:55 +08:00
|
|
|
gimp_projection_projectable_invalidate (GimpProjectable *projectable,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
GimpProjection *proj)
|
2004-07-14 00:36:29 +08:00
|
|
|
{
|
2018-08-10 14:36:29 +08:00
|
|
|
gint off_x, off_y;
|
|
|
|
|
|
|
|
gimp_projectable_get_offset (proj->priv->projectable, &off_x, &off_y);
|
|
|
|
|
|
|
|
/* subtract the projectable's offsets because the list of update
|
|
|
|
* areas is in tile-pyramid coordinates, but our external API is
|
|
|
|
* always in terms of image coordinates.
|
|
|
|
*/
|
|
|
|
x -= off_x;
|
|
|
|
y -= off_y;
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_add_update_area (proj, x, y, w, h);
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
2004-07-14 00:36:29 +08:00
|
|
|
|
|
|
|
static void
|
2008-11-05 02:06:36 +08:00
|
|
|
gimp_projection_projectable_flush (GimpProjectable *projectable,
|
|
|
|
gboolean invalidate_preview,
|
|
|
|
GimpProjection *proj)
|
2004-07-14 00:36:29 +08:00
|
|
|
{
|
2008-11-05 02:06:36 +08:00
|
|
|
if (invalidate_preview)
|
2014-05-31 06:08:43 +08:00
|
|
|
proj->priv->invalidate_preview = TRUE;
|
2007-06-21 00:15:16 +08:00
|
|
|
|
2008-11-05 02:06:36 +08:00
|
|
|
gimp_projection_flush (proj);
|
2004-07-14 00:36:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-08-04 00:34:47 +08:00
|
|
|
gimp_projection_projectable_structure_changed (GimpProjectable *projectable,
|
|
|
|
GimpProjection *proj)
|
2004-07-14 00:36:29 +08:00
|
|
|
{
|
2008-11-05 02:06:36 +08:00
|
|
|
gint width, height;
|
|
|
|
|
2012-07-06 03:42:26 +08:00
|
|
|
gimp_projection_free_buffer (proj);
|
2012-03-15 21:38:54 +08:00
|
|
|
|
2018-08-10 14:36:29 +08:00
|
|
|
gimp_projectable_get_size (projectable, &width, &height);
|
2007-06-27 05:39:51 +08:00
|
|
|
|
2018-08-10 14:36:29 +08:00
|
|
|
gimp_projection_add_update_area (proj, 0, 0, width, height);
|
2014-05-31 08:34:56 +08:00
|
|
|
|
|
|
|
proj->priv->priority_rect.x = 0;
|
|
|
|
proj->priv->priority_rect.y = 0;
|
|
|
|
proj->priv->priority_rect.width = width;
|
|
|
|
proj->priv->priority_rect.height = height;
|
2004-07-14 00:36:29 +08:00
|
|
|
}
|
2018-08-04 00:34:47 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_projection_projectable_bounds_changed (GimpProjectable *projectable,
|
|
|
|
gint old_x,
|
|
|
|
gint old_y,
|
|
|
|
gint old_w,
|
|
|
|
gint old_h,
|
|
|
|
GimpProjection *proj)
|
|
|
|
{
|
|
|
|
GeglBuffer *old_buffer = proj->priv->buffer;
|
|
|
|
GimpTileHandlerValidate *old_validate_handler;
|
|
|
|
gint x, y, w, h;
|
|
|
|
gint dx, dy;
|
|
|
|
|
|
|
|
if (! old_buffer)
|
|
|
|
{
|
|
|
|
gimp_projection_projectable_structure_changed (projectable, proj);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_projectable_get_offset (projectable, &x, &y);
|
|
|
|
gimp_projectable_get_size (projectable, &w, &h);
|
|
|
|
|
|
|
|
if (x == old_x && y == old_y && w == old_w && h == old_h)
|
|
|
|
return;
|
|
|
|
|
2018-08-04 09:58:16 +08:00
|
|
|
if (! gimp_rectangle_intersect (x, y, w, h,
|
|
|
|
old_x, old_y, old_w, old_h,
|
|
|
|
NULL, NULL, NULL, NULL))
|
|
|
|
{
|
|
|
|
gimp_projection_projectable_structure_changed (projectable, proj);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-04 00:34:47 +08:00
|
|
|
dx = old_x - x;
|
|
|
|
dy = old_y - y;
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
/* FIXME: when there's an offset between the new bounds and the old bounds,
|
|
|
|
* use gimp_projection_projectable_structure_changed(), instead of copying a
|
|
|
|
* shifted version of the old buffer, since the synchronous copy can take a
|
|
|
|
* notable amount of time for big buffers, when the offset is such that tiles
|
|
|
|
* are not COW-ed. while gimp_projection_projectable_structure_changed()
|
|
|
|
* causes the projection to be re-rendered, which is overall slower, it's
|
|
|
|
* done asynchronously.
|
|
|
|
*
|
|
|
|
* this needs to be improved.
|
|
|
|
*/
|
|
|
|
if (dx || dy)
|
|
|
|
{
|
|
|
|
gimp_projection_projectable_structure_changed (projectable, proj);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* reallocate the buffer, and copy the old buffer to the corresponding
|
|
|
|
* region of the new buffer. additionally, shift and clip all outstanding
|
|
|
|
* update regions as necessary.
|
|
|
|
*/
|
|
|
|
|
|
|
|
old_validate_handler = proj->priv->validate_handler;
|
|
|
|
|
|
|
|
proj->priv->buffer = NULL;
|
|
|
|
proj->priv->validate_handler = NULL;
|
|
|
|
|
|
|
|
gimp_projection_allocate_buffer (proj);
|
|
|
|
|
|
|
|
gimp_tile_handler_validate_buffer_copy (old_buffer,
|
|
|
|
GEGL_RECTANGLE (0, 0, old_w, old_h),
|
|
|
|
proj->priv->buffer,
|
|
|
|
GEGL_RECTANGLE (dx, dy, old_w, old_h));
|
|
|
|
|
|
|
|
if (old_validate_handler)
|
|
|
|
{
|
|
|
|
gimp_tile_handler_validate_unassign (old_validate_handler, old_buffer);
|
|
|
|
|
|
|
|
g_object_unref (old_validate_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (old_buffer);
|
|
|
|
|
|
|
|
if (proj->priv->update_region)
|
|
|
|
{
|
|
|
|
const cairo_rectangle_int_t bounds = {0, 0, w, h};
|
|
|
|
|
|
|
|
cairo_region_translate (proj->priv->update_region, dx, dy);
|
|
|
|
cairo_region_intersect_rectangle (proj->priv->update_region, &bounds);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (proj->priv->chunk_render.idle_id)
|
|
|
|
{
|
|
|
|
const cairo_rectangle_int_t bounds = {0, 0, w, h};
|
|
|
|
|
|
|
|
proj->priv->chunk_render.x += dx;
|
|
|
|
proj->priv->chunk_render.y += dy;
|
|
|
|
|
|
|
|
proj->priv->chunk_render.work_x += dx;
|
|
|
|
proj->priv->chunk_render.work_y += dx;
|
|
|
|
|
|
|
|
if (proj->priv->chunk_render.update_region)
|
|
|
|
{
|
|
|
|
cairo_region_translate
|
|
|
|
(proj->priv->chunk_render.update_region, dx, dy);
|
|
|
|
cairo_region_intersect_rectangle
|
|
|
|
(proj->priv->chunk_render.update_region, &bounds);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! gimp_rectangle_intersect (proj->priv->chunk_render.x,
|
|
|
|
proj->priv->chunk_render.y,
|
|
|
|
proj->priv->chunk_render.width,
|
|
|
|
proj->priv->chunk_render.height,
|
|
|
|
|
|
|
|
0, 0, w, h,
|
|
|
|
|
|
|
|
&proj->priv->chunk_render.x,
|
|
|
|
&proj->priv->chunk_render.y,
|
|
|
|
&proj->priv->chunk_render.width,
|
|
|
|
&proj->priv->chunk_render.height))
|
|
|
|
{
|
|
|
|
if (! gimp_projection_chunk_render_next_area (proj))
|
|
|
|
gimp_projection_chunk_render_stop (proj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (proj->priv->priority_rect.width > 0 &&
|
|
|
|
proj->priv->priority_rect.height > 0)
|
|
|
|
{
|
|
|
|
proj->priv->priority_rect.x += dx;
|
|
|
|
proj->priv->priority_rect.y += dy;
|
|
|
|
|
|
|
|
gimp_rectangle_intersect (proj->priv->priority_rect.x,
|
|
|
|
proj->priv->priority_rect.y,
|
|
|
|
proj->priv->priority_rect.width,
|
|
|
|
proj->priv->priority_rect.height,
|
|
|
|
|
|
|
|
0, 0, w, h,
|
|
|
|
|
|
|
|
&proj->priv->priority_rect.x,
|
|
|
|
&proj->priv->priority_rect.y,
|
|
|
|
&proj->priv->priority_rect.width,
|
|
|
|
&proj->priv->priority_rect.height);
|
|
|
|
}
|
|
|
|
|
2018-08-04 09:45:06 +08:00
|
|
|
if (dx > 0)
|
|
|
|
gimp_projection_add_update_area (proj, 0, 0, dx, h);
|
|
|
|
if (dy > 0)
|
|
|
|
gimp_projection_add_update_area (proj, 0, 0, w, dy);
|
|
|
|
if (dx + old_w < w)
|
|
|
|
gimp_projection_add_update_area (proj, dx + old_w, 0, w - (dx + old_w), h);
|
|
|
|
if (dy + old_h < h)
|
|
|
|
gimp_projection_add_update_area (proj, 0, dy + old_h, w, h - (dy + old_h));
|
|
|
|
|
|
|
|
proj->priv->invalidate_preview = TRUE;
|
2018-08-04 00:34:47 +08:00
|
|
|
}
|