2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-01-29 13:51:23 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2004-08-26 14:20:30 +00:00
|
|
|
* gimpviewrendererdrawable.c
|
2003-03-03 17:19:30 +00:00
|
|
|
* Copyright (C) 2003 Michael Natterer <mitch@gimp.org>
|
2001-02-07 00:06:58 +00:00
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-01-29 13:51:23 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-01-29 13:51:23 +00: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-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2001-01-29 13:51:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2001-01-29 13:51:23 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2006-09-01 09:04:03 +00:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-02-19 22:54:12 +00:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2001-05-08 03:48:54 +00:00
|
|
|
#include "widgets-types.h"
|
2001-01-29 13:51:23 +00:00
|
|
|
|
2018-07-01 13:02:00 -04:00
|
|
|
#include "config/gimpcoreconfig.h"
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpasync.h"
|
|
|
|
#include "core/gimpcancelable.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
#include "core/gimpdrawable.h"
|
2004-12-11 01:22:58 +00:00
|
|
|
#include "core/gimpdrawable-preview.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
#include "core/gimpimage.h"
|
2012-04-09 00:59:20 +02:00
|
|
|
#include "core/gimptempbuf.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
|
2004-08-26 14:20:30 +00:00
|
|
|
#include "gimpviewrendererdrawable.h"
|
2001-05-08 03:48:54 +00:00
|
|
|
|
2001-01-29 13:51:23 +00:00
|
|
|
|
2018-07-01 13:02:00 -04:00
|
|
|
struct _GimpViewRendererDrawablePrivate
|
|
|
|
{
|
|
|
|
GimpAsync *render_async;
|
|
|
|
GtkWidget *render_widget;
|
|
|
|
gint render_buf_x;
|
|
|
|
gint render_buf_y;
|
|
|
|
gboolean render_update;
|
|
|
|
|
|
|
|
gint prev_width;
|
|
|
|
gint prev_height;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
|
|
|
static void gimp_view_renderer_drawable_dispose (GObject *object);
|
|
|
|
|
|
|
|
static void gimp_view_renderer_drawable_invalidate (GimpViewRenderer *renderer);
|
|
|
|
static void gimp_view_renderer_drawable_render (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget);
|
|
|
|
|
|
|
|
static void gimp_view_renderer_drawable_cancel_render (GimpViewRendererDrawable *renderdrawable);
|
2001-01-29 13:51:23 +00:00
|
|
|
|
2001-02-07 02:37:49 +00:00
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-18 12:09:39 -04:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GimpViewRendererDrawable,
|
|
|
|
gimp_view_renderer_drawable,
|
|
|
|
GIMP_TYPE_VIEW_RENDERER)
|
2001-01-29 13:51:23 +00:00
|
|
|
|
2005-12-19 22:37:49 +00:00
|
|
|
#define parent_class gimp_view_renderer_drawable_parent_class
|
2001-01-29 13:51:23 +00:00
|
|
|
|
|
|
|
|
2018-07-01 13:02:00 -04:00
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
|
2001-02-07 00:06:58 +00:00
|
|
|
static void
|
2004-08-26 14:20:30 +00:00
|
|
|
gimp_view_renderer_drawable_class_init (GimpViewRendererDrawableClass *klass)
|
2001-01-29 13:51:23 +00:00
|
|
|
{
|
2018-07-01 13:02:00 -04:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2004-09-09 11:58:49 +00:00
|
|
|
GimpViewRendererClass *renderer_class = GIMP_VIEW_RENDERER_CLASS (klass);
|
2001-01-29 13:51:23 +00:00
|
|
|
|
2018-07-01 13:02:00 -04:00
|
|
|
object_class->dispose = gimp_view_renderer_drawable_dispose;
|
|
|
|
|
|
|
|
renderer_class->invalidate = gimp_view_renderer_drawable_invalidate;
|
|
|
|
renderer_class->render = gimp_view_renderer_drawable_render;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_view_renderer_drawable_init (GimpViewRendererDrawable *renderdrawable)
|
|
|
|
{
|
|
|
|
renderdrawable->priv =
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-18 12:09:39 -04:00
|
|
|
gimp_view_renderer_drawable_get_instance_private (renderdrawable);
|
2018-07-01 13:02:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_view_renderer_drawable_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GimpViewRendererDrawable *renderdrawable = GIMP_VIEW_RENDERER_DRAWABLE (object);
|
|
|
|
|
|
|
|
gimp_view_renderer_drawable_cancel_render (renderdrawable);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_view_renderer_drawable_invalidate (GimpViewRenderer *renderer)
|
|
|
|
{
|
|
|
|
GimpViewRendererDrawable *renderdrawable = GIMP_VIEW_RENDERER_DRAWABLE (renderer);
|
|
|
|
|
|
|
|
gimp_view_renderer_drawable_cancel_render (renderdrawable);
|
|
|
|
|
|
|
|
GIMP_VIEW_RENDERER_CLASS (parent_class)->invalidate (renderer);
|
2001-01-29 13:51:23 +00:00
|
|
|
}
|
|
|
|
|
2005-12-19 22:37:49 +00:00
|
|
|
static void
|
2018-07-01 13:02:00 -04:00
|
|
|
gimp_view_renderer_drawable_render_async_callback (GimpAsync *async,
|
|
|
|
GimpViewRendererDrawable *renderdrawable)
|
2005-12-19 22:37:49 +00:00
|
|
|
{
|
2018-07-01 13:02:00 -04:00
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
/* rendering was canceled, and the view renderer is potentially dead (see
|
|
|
|
* gimp_view_renderer_drawable_cancel_render()). bail.
|
|
|
|
*/
|
|
|
|
if (gimp_async_is_canceled (async))
|
|
|
|
return;
|
|
|
|
|
|
|
|
widget = renderdrawable->priv->render_widget;
|
|
|
|
|
|
|
|
renderdrawable->priv->render_async = NULL;
|
|
|
|
renderdrawable->priv->render_widget = NULL;
|
|
|
|
|
|
|
|
if (gimp_async_is_finished (async))
|
|
|
|
{
|
|
|
|
GimpViewRenderer *renderer = GIMP_VIEW_RENDERER (renderdrawable);
|
|
|
|
GimpTempBuf *render_buf = gimp_async_get_result (async);
|
|
|
|
|
|
|
|
gimp_view_renderer_render_temp_buf (
|
|
|
|
renderer,
|
|
|
|
widget,
|
|
|
|
render_buf,
|
|
|
|
renderdrawable->priv->render_buf_x,
|
|
|
|
renderdrawable->priv->render_buf_y,
|
|
|
|
-1,
|
|
|
|
GIMP_VIEW_BG_CHECKS,
|
|
|
|
GIMP_VIEW_BG_CHECKS);
|
|
|
|
|
|
|
|
if (renderdrawable->priv->render_update)
|
|
|
|
gimp_view_renderer_update (renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (widget);
|
2005-12-19 22:37:49 +00:00
|
|
|
}
|
|
|
|
|
2001-02-07 20:35:18 +00:00
|
|
|
static void
|
2004-08-26 14:20:30 +00:00
|
|
|
gimp_view_renderer_drawable_render (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget)
|
2001-02-07 02:37:49 +00:00
|
|
|
{
|
2018-07-01 13:02:00 -04:00
|
|
|
GimpViewRendererDrawable *renderdrawable = GIMP_VIEW_RENDERER_DRAWABLE (renderer);
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
GimpItem *item;
|
|
|
|
GimpImage *image;
|
|
|
|
const gchar *icon_name;
|
|
|
|
GimpAsync *async;
|
2018-11-02 22:15:20 -04:00
|
|
|
gint image_width;
|
|
|
|
gint image_height;
|
2018-07-01 13:02:00 -04:00
|
|
|
gint view_width;
|
|
|
|
gint view_height;
|
2018-11-02 22:15:20 -04:00
|
|
|
gint src_x;
|
|
|
|
gint src_y;
|
|
|
|
gint src_width;
|
|
|
|
gint src_height;
|
|
|
|
gint dst_x;
|
|
|
|
gint dst_y;
|
|
|
|
gint dst_width;
|
|
|
|
gint dst_height;
|
|
|
|
gdouble xres = 1.0;
|
|
|
|
gdouble yres = 1.0;
|
|
|
|
gboolean empty = FALSE;
|
2018-07-01 13:02:00 -04:00
|
|
|
|
|
|
|
/* render is already in progress */
|
|
|
|
if (renderdrawable->priv->render_async)
|
|
|
|
return;
|
|
|
|
|
|
|
|
drawable = GIMP_DRAWABLE (renderer->viewable);
|
|
|
|
item = GIMP_ITEM (drawable);
|
|
|
|
image = gimp_item_get_image (item);
|
|
|
|
icon_name = gimp_viewable_get_icon_name (renderer->viewable);
|
|
|
|
|
|
|
|
if (image && ! image->gimp->config->layer_previews)
|
|
|
|
{
|
|
|
|
renderdrawable->priv->prev_width = 0;
|
|
|
|
renderdrawable->priv->prev_height = 0;
|
|
|
|
|
|
|
|
gimp_view_renderer_render_icon (renderer, widget, icon_name);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2008-11-03 21:17:50 +00:00
|
|
|
|
2007-12-26 17:33:41 +00:00
|
|
|
if (image)
|
|
|
|
gimp_image_get_resolution (image, &xres, &yres);
|
|
|
|
|
2018-11-02 22:15:20 -04:00
|
|
|
if (renderer->is_popup)
|
|
|
|
image = NULL;
|
|
|
|
|
|
|
|
if (image)
|
2001-02-19 22:54:12 +00:00
|
|
|
{
|
2018-11-02 22:15:20 -04:00
|
|
|
image_width = gimp_image_get_width (image);
|
|
|
|
image_height = gimp_image_get_height (image);
|
2001-02-19 22:54:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-02 22:15:20 -04:00
|
|
|
image_width = gimp_item_get_width (item);
|
|
|
|
image_height = gimp_item_get_height (item);
|
2001-02-19 22:54:12 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 22:15:20 -04:00
|
|
|
gimp_viewable_calc_preview_size (image_width,
|
|
|
|
image_height,
|
|
|
|
renderer->width,
|
|
|
|
renderer->height,
|
|
|
|
renderer->dot_for_dot,
|
|
|
|
xres,
|
|
|
|
yres,
|
|
|
|
&view_width,
|
|
|
|
&view_height,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
src_x = 0;
|
|
|
|
src_y = 0;
|
|
|
|
src_width = gimp_item_get_width (item);
|
|
|
|
src_height = gimp_item_get_height (item);
|
2004-12-11 01:22:58 +00:00
|
|
|
|
2018-11-02 22:15:20 -04:00
|
|
|
if (image)
|
2001-02-19 22:54:12 +00:00
|
|
|
{
|
2018-11-02 22:15:20 -04:00
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
|
|
|
|
|
|
|
gimp_item_get_offset (item, &offset_x, &offset_y);
|
2018-07-01 13:02:00 -04:00
|
|
|
|
2018-11-02 22:15:20 -04:00
|
|
|
if (gimp_rectangle_intersect (src_x, src_y,
|
|
|
|
src_width, src_height,
|
2018-07-01 13:02:00 -04:00
|
|
|
-offset_x, -offset_y,
|
2018-11-02 22:15:20 -04:00
|
|
|
image_width, image_height,
|
2018-07-01 13:02:00 -04:00
|
|
|
&src_x, &src_y,
|
|
|
|
&src_width, &src_height))
|
2004-12-11 01:22:58 +00:00
|
|
|
{
|
2018-11-02 22:15:20 -04:00
|
|
|
offset_x += src_x;
|
|
|
|
offset_y += src_y;
|
|
|
|
|
|
|
|
dst_x = ROUND (((gdouble) view_width / image_width) *
|
|
|
|
offset_x);
|
|
|
|
dst_y = ROUND (((gdouble) view_height / image_height) *
|
|
|
|
offset_y);
|
|
|
|
dst_width = ROUND (((gdouble) view_width / image_width) *
|
|
|
|
src_width);
|
|
|
|
dst_height = ROUND (((gdouble) view_height / image_height) *
|
|
|
|
src_height);
|
2004-12-11 01:22:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-02 22:15:20 -04:00
|
|
|
dst_x = 0;
|
|
|
|
dst_y = 0;
|
|
|
|
dst_width = 1;
|
|
|
|
dst_height = 1;
|
2001-02-19 22:54:12 +00:00
|
|
|
|
2018-11-02 22:15:20 -04:00
|
|
|
empty = TRUE;
|
2003-03-06 16:47:34 +00:00
|
|
|
}
|
2001-02-19 22:54:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-02 22:15:20 -04:00
|
|
|
dst_x = (renderer->width - view_width) / 2;
|
|
|
|
dst_y = (renderer->height - view_height) / 2;
|
|
|
|
dst_width = view_width;
|
|
|
|
dst_height = view_height;
|
2001-02-19 22:54:12 +00:00
|
|
|
}
|
|
|
|
|
2018-11-03 04:28:15 -04:00
|
|
|
dst_width = MAX (dst_width, 1);
|
|
|
|
dst_height = MAX (dst_height, 1);
|
|
|
|
|
2018-11-02 22:15:20 -04:00
|
|
|
if (! empty)
|
2001-02-19 22:54:12 +00:00
|
|
|
{
|
2018-11-02 22:15:20 -04:00
|
|
|
async = gimp_drawable_get_sub_preview_async (drawable,
|
|
|
|
src_x, src_y,
|
|
|
|
src_width, src_height,
|
|
|
|
dst_width, dst_height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const Babl *format = gimp_drawable_get_preview_format (drawable);
|
|
|
|
GimpTempBuf *render_buf;
|
2012-04-10 15:50:36 +02:00
|
|
|
|
2018-11-02 22:15:20 -04:00
|
|
|
async = gimp_async_new ();
|
2003-03-06 16:47:34 +00:00
|
|
|
|
2018-11-02 22:15:20 -04:00
|
|
|
render_buf = gimp_temp_buf_new (dst_width, dst_height, format);
|
|
|
|
gimp_temp_buf_data_clear (render_buf);
|
|
|
|
|
|
|
|
gimp_async_finish_full (async,
|
|
|
|
render_buf,
|
|
|
|
(GDestroyNotify) gimp_temp_buf_unref);
|
|
|
|
}
|
2003-03-06 16:47:34 +00:00
|
|
|
|
2018-11-02 22:15:20 -04:00
|
|
|
if (async)
|
|
|
|
{
|
2018-07-01 13:02:00 -04:00
|
|
|
renderdrawable->priv->render_async = async;
|
|
|
|
renderdrawable->priv->render_widget = g_object_ref (widget);
|
2018-11-02 22:15:20 -04:00
|
|
|
renderdrawable->priv->render_buf_x = dst_x;
|
|
|
|
renderdrawable->priv->render_buf_y = dst_y;
|
2018-07-01 13:02:00 -04:00
|
|
|
renderdrawable->priv->render_update = FALSE;
|
|
|
|
|
2018-11-30 03:32:33 -05:00
|
|
|
gimp_async_add_callback_for_object (
|
2018-07-01 13:02:00 -04:00
|
|
|
async,
|
|
|
|
(GimpAsyncCallback) gimp_view_renderer_drawable_render_async_callback,
|
2018-11-30 03:32:33 -05:00
|
|
|
renderdrawable,
|
2018-07-01 13:02:00 -04:00
|
|
|
renderdrawable);
|
|
|
|
|
|
|
|
/* if rendering isn't done yet, update the render-view once it is, and
|
|
|
|
* either keep the old drawable preview for now, or, if size changed (or
|
|
|
|
* there's no old preview,) render an icon in the meantime.
|
|
|
|
*/
|
|
|
|
if (renderdrawable->priv->render_async)
|
|
|
|
{
|
|
|
|
renderdrawable->priv->render_update = TRUE;
|
|
|
|
|
2018-11-02 22:15:20 -04:00
|
|
|
if (renderer->width != renderdrawable->priv->prev_width ||
|
|
|
|
renderer->height != renderdrawable->priv->prev_height)
|
2018-07-01 13:02:00 -04:00
|
|
|
{
|
|
|
|
gimp_view_renderer_render_icon (renderer, widget, icon_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-02 22:15:20 -04:00
|
|
|
renderdrawable->priv->prev_width = renderer->width;
|
|
|
|
renderdrawable->priv->prev_height = renderer->height;
|
2018-07-01 13:02:00 -04:00
|
|
|
|
|
|
|
g_object_unref (async);
|
2001-02-19 22:54:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-01 13:02:00 -04:00
|
|
|
renderdrawable->priv->prev_width = 0;
|
|
|
|
renderdrawable->priv->prev_height = 0;
|
2001-02-19 22:54:12 +00:00
|
|
|
|
2014-05-07 01:01:56 +02:00
|
|
|
gimp_view_renderer_render_icon (renderer, widget, icon_name);
|
2003-03-06 16:47:34 +00:00
|
|
|
}
|
2001-02-07 02:37:49 +00:00
|
|
|
}
|
2018-07-01 13:02:00 -04:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_view_renderer_drawable_cancel_render (GimpViewRendererDrawable *renderdrawable)
|
|
|
|
{
|
|
|
|
/* cancel the async render operation (if one is ongoing) without actually
|
|
|
|
* waiting for it. if the actual rendering hasn't started yet, it will be
|
|
|
|
* immediately aborted; otherwise, it can't really be interrupted, so we just
|
|
|
|
* let it go on without blocking the main thread.
|
|
|
|
* gimp_drawable_get_sub_preview_async() can continue rendering safely even
|
|
|
|
* after the drawable had died, and our completion callback is prepared to
|
2019-04-19 22:51:06 -04:00
|
|
|
* handle cancellation.
|
2018-07-01 13:02:00 -04:00
|
|
|
*/
|
2018-09-18 16:17:36 -04:00
|
|
|
if (renderdrawable->priv->render_async)
|
|
|
|
{
|
|
|
|
gimp_cancelable_cancel (
|
|
|
|
GIMP_CANCELABLE (renderdrawable->priv->render_async));
|
|
|
|
|
|
|
|
renderdrawable->priv->render_async = NULL;
|
|
|
|
}
|
2018-07-01 13:02:00 -04:00
|
|
|
|
|
|
|
g_clear_object (&renderdrawable->priv->render_widget);
|
|
|
|
}
|