From f90da765b5e1ed5195acf23ae55a94a0daf2895f Mon Sep 17 00:00:00 2001 From: Ell Date: Wed, 4 Sep 2019 17:20:00 +0300 Subject: [PATCH] app: handle GimpImageViewable in GimpViewRendererImage Allow using a GimpImageViewable as the source for a GimpViewRenderer, by allowing GimpViewRendererImage to handle this type of viewables. --- app/widgets/gimpviewrenderer-utils.c | 4 +++- app/widgets/gimpviewrendererimage.c | 28 +++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/widgets/gimpviewrenderer-utils.c b/app/widgets/gimpviewrenderer-utils.c index 9034cf4f49..d2d7ee5026 100644 --- a/app/widgets/gimpviewrenderer-utils.c +++ b/app/widgets/gimpviewrenderer-utils.c @@ -30,6 +30,7 @@ #include "core/gimpgradient.h" #include "core/gimpimage.h" #include "core/gimpimagefile.h" +#include "core/gimpimageviewable.h" #include "core/gimplayer.h" #include "core/gimppalette.h" @@ -62,7 +63,8 @@ gimp_view_renderer_type_from_viewable_type (GType viewable_type) { type = GIMP_TYPE_VIEW_RENDERER_BUFFER; } - else if (g_type_is_a (viewable_type, GIMP_TYPE_IMAGE)) + else if (g_type_is_a (viewable_type, GIMP_TYPE_IMAGE) || + g_type_is_a (viewable_type, GIMP_TYPE_IMAGE_VIEWABLE)) { type = GIMP_TYPE_VIEW_RENDERER_IMAGE; } diff --git a/app/widgets/gimpviewrendererimage.c b/app/widgets/gimpviewrendererimage.c index 04a7135907..6c619e0f96 100644 --- a/app/widgets/gimpviewrendererimage.c +++ b/app/widgets/gimpviewrendererimage.c @@ -28,6 +28,7 @@ #include "widgets-types.h" #include "core/gimpimage.h" +#include "core/gimpimageviewable.h" #include "core/gimptempbuf.h" #include "gimpviewrendererimage.h" @@ -62,8 +63,26 @@ gimp_view_renderer_image_render (GimpViewRenderer *renderer, GtkWidget *widget) { GimpViewRendererImage *rendererimage = GIMP_VIEW_RENDERER_IMAGE (renderer); - GimpImage *image = GIMP_IMAGE (renderer->viewable); + GimpImage *image; const gchar *icon_name; + gint width; + gint height; + + if (GIMP_IS_IMAGE (renderer->viewable)) + { + image = GIMP_IMAGE (renderer->viewable); + } + else if (GIMP_IS_IMAGE_VIEWABLE (renderer->viewable)) + { + image = gimp_image_viewable_get_image ( + GIMP_IMAGE_VIEWABLE (renderer->viewable)); + } + else + { + g_return_if_reached (); + } + + gimp_viewable_get_size (renderer->viewable, &width, &height); /* The conditions checked here are mostly a hack to hide the fact that * we are creating the channel preview from the image preview and turning @@ -82,8 +101,8 @@ gimp_view_renderer_image_render (GimpViewRenderer *renderer, gimp_image_get_resolution (image, &xres, &yres); - gimp_viewable_calc_preview_size (gimp_image_get_width (image), - gimp_image_get_height (image), + gimp_viewable_calc_preview_size (width, + height, renderer->width, renderer->height, renderer->dot_for_dot, @@ -99,8 +118,7 @@ gimp_view_renderer_image_render (GimpViewRenderer *renderer, temp_buf = gimp_viewable_get_new_preview (renderer->viewable, renderer->context, - gimp_image_get_width (image), - gimp_image_get_height (image)); + width, height); if (temp_buf) {