2004-08-31 06:10:26 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimpdrawablepreview.c
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2004-08-31 06:10:26 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2004-08-31 06:10:26 +08:00
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
2004-08-31 06:10:26 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2004-08-31 17:16:47 +08:00
|
|
|
#include "gimpuitypes.h"
|
|
|
|
|
|
|
|
#include "gimp.h"
|
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
#include "gimpdrawablepreview.h"
|
|
|
|
|
|
|
|
|
2010-07-07 17:48:10 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpdrawablepreview
|
|
|
|
* @title: GimpDrawablePreview
|
|
|
|
* @short_description: A widget providing a preview of a #GimpDrawable.
|
|
|
|
*
|
|
|
|
* A widget providing a preview of a #GimpDrawable.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2006-04-12 04:59:20 +08:00
|
|
|
#define SELECTION_BORDER 8
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2006-02-26 08:25:05 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_DRAWABLE
|
|
|
|
};
|
|
|
|
|
2005-01-06 06:33:44 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2007-09-21 21:27:33 +08:00
|
|
|
gint x;
|
|
|
|
gint y;
|
|
|
|
gboolean update;
|
2005-01-06 06:33:44 +08:00
|
|
|
} PreviewSettings;
|
2004-09-01 03:58:25 +08:00
|
|
|
|
|
|
|
|
2006-02-26 08:25:05 +08:00
|
|
|
static GObject * gimp_drawable_preview_constructor (GType type,
|
2006-04-12 18:53:28 +08:00
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params);
|
2006-02-26 08:25:05 +08:00
|
|
|
|
|
|
|
static void gimp_drawable_preview_get_property (GObject *object,
|
2006-04-12 18:53:28 +08:00
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2006-02-26 08:25:05 +08:00
|
|
|
static void gimp_drawable_preview_set_property (GObject *object,
|
2006-04-12 18:53:28 +08:00
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2005-12-21 04:35:23 +08:00
|
|
|
static void gimp_drawable_preview_destroy (GtkObject *object);
|
2005-01-06 06:33:44 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
static void gimp_drawable_preview_style_set (GtkWidget *widget,
|
|
|
|
GtkStyle *prev_style);
|
2004-09-10 05:36:52 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
static void gimp_drawable_preview_draw_original (GimpPreview *preview);
|
|
|
|
static void gimp_drawable_preview_draw_thumb (GimpPreview *preview,
|
|
|
|
GimpPreviewArea *area,
|
|
|
|
gint width,
|
|
|
|
gint height);
|
|
|
|
static void gimp_drawable_preview_draw_buffer (GimpPreview *preview,
|
|
|
|
const guchar *buffer,
|
|
|
|
gint rowstride);
|
2004-09-29 23:33:02 +08:00
|
|
|
|
2006-02-26 08:25:05 +08:00
|
|
|
static void gimp_drawable_preview_set_drawable (GimpDrawablePreview *preview,
|
2006-04-12 18:53:28 +08:00
|
|
|
GimpDrawable *drawable);
|
2006-02-26 08:25:05 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
G_DEFINE_TYPE (GimpDrawablePreview, gimp_drawable_preview,
|
2006-05-15 17:46:31 +08:00
|
|
|
GIMP_TYPE_SCROLLED_PREVIEW)
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
#define parent_class gimp_drawable_preview_parent_class
|
2004-09-29 21:39:23 +08:00
|
|
|
|
2007-09-21 21:27:33 +08:00
|
|
|
static gint gimp_drawable_preview_counter = 0;
|
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_drawable_preview_class_init (GimpDrawablePreviewClass *klass)
|
|
|
|
{
|
2006-02-26 08:25:05 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GimpPreviewClass *preview_class = GIMP_PREVIEW_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->constructor = gimp_drawable_preview_constructor;
|
|
|
|
object_class->get_property = gimp_drawable_preview_get_property;
|
|
|
|
object_class->set_property = gimp_drawable_preview_set_property;
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2006-02-26 08:25:05 +08:00
|
|
|
gtk_object_class->destroy = gimp_drawable_preview_destroy;
|
2005-01-06 06:33:44 +08:00
|
|
|
|
2004-09-29 23:33:02 +08:00
|
|
|
widget_class->style_set = gimp_drawable_preview_style_set;
|
2004-09-01 05:15:03 +08:00
|
|
|
|
2004-09-29 23:33:02 +08:00
|
|
|
preview_class->draw = gimp_drawable_preview_draw_original;
|
|
|
|
preview_class->draw_thumb = gimp_drawable_preview_draw_thumb;
|
|
|
|
preview_class->draw_buffer = gimp_drawable_preview_draw_buffer;
|
2006-02-26 08:25:05 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GimpDrawablePreview:drawable:
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class, PROP_DRAWABLE,
|
|
|
|
g_param_spec_pointer ("drawable", NULL, NULL,
|
2006-04-12 18:53:28 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2004-09-01 05:15:03 +08:00
|
|
|
}
|
|
|
|
|
2004-09-03 20:19:26 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_preview_init (GimpDrawablePreview *preview)
|
|
|
|
{
|
|
|
|
g_object_set (GIMP_PREVIEW (preview)->area,
|
|
|
|
"check-size", gimp_check_size (),
|
|
|
|
"check-type", gimp_check_type (),
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2006-02-26 08:25:05 +08:00
|
|
|
static GObject *
|
|
|
|
gimp_drawable_preview_constructor (GType type,
|
2006-04-12 18:53:28 +08:00
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
2006-02-26 08:25:05 +08:00
|
|
|
{
|
|
|
|
GObject *object;
|
2007-09-21 21:27:33 +08:00
|
|
|
gchar *data_name;
|
2006-02-26 08:25:05 +08:00
|
|
|
PreviewSettings settings;
|
2007-09-21 21:27:33 +08:00
|
|
|
|
|
|
|
data_name = g_strdup_printf ("%s-drawable-preview-%d",
|
|
|
|
g_get_prgname (),
|
|
|
|
++gimp_drawable_preview_counter);
|
2006-02-26 08:25:05 +08:00
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
|
|
|
|
|
|
|
|
if (gimp_get_data (data_name, &settings))
|
2007-09-21 21:27:33 +08:00
|
|
|
{
|
|
|
|
gimp_preview_set_update (GIMP_PREVIEW (object), settings.update);
|
|
|
|
gimp_scrolled_preview_set_position (GIMP_SCROLLED_PREVIEW (object),
|
|
|
|
settings.x, settings.y);
|
|
|
|
}
|
2006-02-26 08:25:05 +08:00
|
|
|
|
2007-09-21 21:27:33 +08:00
|
|
|
g_object_set_data_full (object, "gimp-drawable-preview-data-name",
|
|
|
|
data_name, (GDestroyNotify) g_free);
|
2006-02-26 08:25:05 +08:00
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_drawable_preview_get_property (GObject *object,
|
2006-04-12 18:53:28 +08:00
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2006-02-26 08:25:05 +08:00
|
|
|
{
|
|
|
|
GimpDrawablePreview *preview = GIMP_DRAWABLE_PREVIEW (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_DRAWABLE:
|
|
|
|
g_value_set_pointer (value,
|
2006-04-12 18:53:28 +08:00
|
|
|
gimp_drawable_preview_get_drawable (preview));
|
2006-02-26 08:25:05 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_drawable_preview_set_property (GObject *object,
|
2006-04-12 18:53:28 +08:00
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2006-02-26 08:25:05 +08:00
|
|
|
{
|
|
|
|
GimpDrawablePreview *preview = GIMP_DRAWABLE_PREVIEW (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_DRAWABLE:
|
|
|
|
gimp_drawable_preview_set_drawable (preview,
|
2006-04-12 18:53:28 +08:00
|
|
|
g_value_get_pointer (value));
|
2006-02-26 08:25:05 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-06 06:33:44 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_preview_destroy (GtkObject *object)
|
|
|
|
{
|
2007-09-21 21:27:33 +08:00
|
|
|
const gchar *data_name = g_object_get_data (G_OBJECT (object),
|
|
|
|
"gimp-drawable-preview-data-name");
|
|
|
|
|
|
|
|
if (data_name)
|
|
|
|
{
|
|
|
|
GimpPreview *preview = GIMP_PREVIEW (object);
|
|
|
|
PreviewSettings settings;
|
2005-01-06 06:33:44 +08:00
|
|
|
|
2007-09-21 21:27:33 +08:00
|
|
|
settings.x = preview->xoff + preview->xmin;
|
|
|
|
settings.y = preview->yoff + preview->ymin;
|
|
|
|
settings.update = gimp_preview_get_update (preview);
|
2005-01-06 06:33:44 +08:00
|
|
|
|
2007-09-21 21:27:33 +08:00
|
|
|
gimp_set_data (data_name, &settings, sizeof (PreviewSettings));
|
|
|
|
}
|
2005-01-06 06:33:44 +08:00
|
|
|
|
|
|
|
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
|
|
|
}
|
|
|
|
|
2004-09-01 05:15:03 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_preview_style_set (GtkWidget *widget,
|
|
|
|
GtkStyle *prev_style)
|
|
|
|
{
|
|
|
|
GimpPreview *preview = GIMP_PREVIEW (widget);
|
|
|
|
gint width = preview->xmax - preview->xmin;
|
|
|
|
gint height = preview->ymax - preview->ymin;
|
|
|
|
gint size;
|
|
|
|
|
|
|
|
if (GTK_WIDGET_CLASS (parent_class)->style_set)
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
|
|
|
|
|
|
|
|
gtk_widget_style_get (widget,
|
|
|
|
"size", &size,
|
2004-09-01 05:29:30 +08:00
|
|
|
NULL);
|
2004-09-01 05:15:03 +08:00
|
|
|
|
|
|
|
gtk_widget_set_size_request (GIMP_PREVIEW (preview)->area,
|
|
|
|
MIN (width, size), MIN (height, size));
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-31 22:29:25 +08:00
|
|
|
gimp_drawable_preview_draw_original (GimpPreview *preview)
|
2004-08-31 06:10:26 +08:00
|
|
|
{
|
2004-08-31 06:49:06 +08:00
|
|
|
GimpDrawablePreview *drawable_preview = GIMP_DRAWABLE_PREVIEW (preview);
|
|
|
|
GimpDrawable *drawable = drawable_preview->drawable;
|
2004-08-31 06:10:26 +08:00
|
|
|
guchar *buffer;
|
2004-08-31 06:49:06 +08:00
|
|
|
GimpPixelRgn srcPR;
|
|
|
|
guint rowstride;
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2004-09-01 20:10:09 +08:00
|
|
|
if (! drawable)
|
|
|
|
return;
|
|
|
|
|
2004-08-31 06:49:06 +08:00
|
|
|
rowstride = preview->width * drawable->bpp;
|
2004-08-31 06:10:26 +08:00
|
|
|
buffer = g_new (guchar, rowstride * preview->height);
|
|
|
|
|
2004-09-29 21:39:23 +08:00
|
|
|
preview->xoff = CLAMP (preview->xoff,
|
|
|
|
0, preview->xmax - preview->xmin - preview->width);
|
|
|
|
preview->yoff = CLAMP (preview->yoff,
|
|
|
|
0, preview->ymax - preview->ymin - preview->height);
|
2004-08-31 06:49:06 +08:00
|
|
|
|
|
|
|
gimp_pixel_rgn_init (&srcPR, drawable,
|
2004-09-29 21:39:23 +08:00
|
|
|
preview->xoff + preview->xmin,
|
|
|
|
preview->yoff + preview->ymin,
|
2004-08-31 06:10:26 +08:00
|
|
|
preview->width, preview->height,
|
|
|
|
FALSE, FALSE);
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
gimp_pixel_rgn_get_rect (&srcPR, buffer,
|
2004-09-29 21:39:23 +08:00
|
|
|
preview->xoff + preview->xmin,
|
|
|
|
preview->yoff + preview->ymin,
|
2004-08-31 06:10:26 +08:00
|
|
|
preview->width, preview->height);
|
|
|
|
|
|
|
|
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview->area),
|
|
|
|
0, 0, preview->width, preview->height,
|
2004-08-31 06:49:06 +08:00
|
|
|
gimp_drawable_type (drawable->drawable_id),
|
2004-08-31 06:10:26 +08:00
|
|
|
buffer,
|
|
|
|
rowstride);
|
|
|
|
g_free (buffer);
|
|
|
|
}
|
|
|
|
|
2004-09-10 05:36:52 +08:00
|
|
|
static void
|
2004-09-29 21:39:23 +08:00
|
|
|
gimp_drawable_preview_draw_thumb (GimpPreview *preview,
|
|
|
|
GimpPreviewArea *area,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
2004-09-10 05:36:52 +08:00
|
|
|
{
|
|
|
|
GimpDrawablePreview *drawable_preview = GIMP_DRAWABLE_PREVIEW (preview);
|
|
|
|
GimpDrawable *drawable = drawable_preview->drawable;
|
|
|
|
|
2006-02-07 23:36:17 +08:00
|
|
|
if (drawable)
|
|
|
|
_gimp_drawable_preview_area_draw_thumb (area, drawable, width, height);
|
|
|
|
}
|
2004-09-10 05:36:52 +08:00
|
|
|
|
2006-02-07 23:36:17 +08:00
|
|
|
void
|
|
|
|
_gimp_drawable_preview_area_draw_thumb (GimpPreviewArea *area,
|
2006-04-12 18:53:28 +08:00
|
|
|
GimpDrawable *drawable,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
2006-02-07 23:36:17 +08:00
|
|
|
{
|
|
|
|
guchar *buffer;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
gint bpp;
|
|
|
|
gint size = 100;
|
|
|
|
gint nav_width, nav_height;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW_AREA (area));
|
|
|
|
g_return_if_fail (drawable != NULL);
|
|
|
|
|
|
|
|
if (_gimp_drawable_preview_get_bounds (drawable, &x1, &y1, &x2, &y2))
|
2005-10-09 07:08:12 +08:00
|
|
|
{
|
|
|
|
width = x2 - x1;
|
|
|
|
height = y2 - y1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = gimp_drawable_width (drawable->drawable_id);
|
|
|
|
height = gimp_drawable_height (drawable->drawable_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width > height)
|
|
|
|
{
|
|
|
|
nav_width = MIN (width, size);
|
|
|
|
nav_height = (height * nav_width) / width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nav_height = MIN (height, size);
|
|
|
|
nav_width = (width * nav_height) / height;
|
|
|
|
}
|
|
|
|
|
2006-02-07 23:36:17 +08:00
|
|
|
if (_gimp_drawable_preview_get_bounds (drawable, &x1, &y1, &x2, &y2))
|
2005-04-23 19:53:09 +08:00
|
|
|
{
|
|
|
|
buffer = gimp_drawable_get_sub_thumbnail_data (drawable->drawable_id,
|
|
|
|
x1, y1, x2 - x1, y2 - y1,
|
2006-02-07 23:36:17 +08:00
|
|
|
&nav_width, &nav_height,
|
2006-04-12 18:53:28 +08:00
|
|
|
&bpp);
|
2005-04-23 19:53:09 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buffer = gimp_drawable_get_thumbnail_data (drawable->drawable_id,
|
2006-02-07 23:36:17 +08:00
|
|
|
&nav_width, &nav_height,
|
2006-04-12 18:53:28 +08:00
|
|
|
&bpp);
|
2005-04-23 19:53:09 +08:00
|
|
|
}
|
2004-09-10 05:36:52 +08:00
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
{
|
2004-09-10 17:30:06 +08:00
|
|
|
GimpImageType type;
|
|
|
|
|
2005-10-09 07:08:12 +08:00
|
|
|
gtk_widget_set_size_request (GTK_WIDGET (area), nav_width, nav_height);
|
2004-09-10 05:36:52 +08:00
|
|
|
gtk_widget_show (GTK_WIDGET (area));
|
|
|
|
gtk_widget_realize (GTK_WIDGET (area));
|
|
|
|
|
|
|
|
switch (bpp)
|
|
|
|
{
|
2004-09-10 17:30:06 +08:00
|
|
|
case 1: type = GIMP_GRAY_IMAGE; break;
|
|
|
|
case 2: type = GIMP_GRAYA_IMAGE; break;
|
|
|
|
case 3: type = GIMP_RGB_IMAGE; break;
|
|
|
|
case 4: type = GIMP_RGBA_IMAGE; break;
|
|
|
|
default:
|
|
|
|
g_free (buffer);
|
|
|
|
return;
|
2004-09-10 05:36:52 +08:00
|
|
|
}
|
|
|
|
|
2004-09-10 17:30:06 +08:00
|
|
|
gimp_preview_area_draw (area,
|
2005-10-09 07:08:12 +08:00
|
|
|
0, 0, nav_width, nav_height,
|
|
|
|
type, buffer, bpp * nav_width);
|
2004-09-10 17:30:06 +08:00
|
|
|
|
2004-09-10 05:36:52 +08:00
|
|
|
g_free (buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-16 03:56:01 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_preview_draw_area (GimpDrawablePreview *preview,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
const guchar *buf,
|
|
|
|
gint rowstride)
|
|
|
|
{
|
2004-09-29 21:39:23 +08:00
|
|
|
GimpPreview *gimp_preview = GIMP_PREVIEW (preview);
|
|
|
|
GimpDrawable *drawable = preview->drawable;
|
|
|
|
gint32 image_id;
|
2004-09-16 03:56:01 +08:00
|
|
|
|
2010-07-09 17:29:35 +08:00
|
|
|
image_id = gimp_item_get_image (drawable->drawable_id);
|
2004-09-16 03:56:01 +08:00
|
|
|
|
|
|
|
if (gimp_selection_is_empty (image_id))
|
|
|
|
{
|
|
|
|
gimp_preview_area_draw (GIMP_PREVIEW_AREA (gimp_preview->area),
|
2004-09-29 21:39:23 +08:00
|
|
|
x - gimp_preview->xoff - gimp_preview->xmin,
|
|
|
|
y - gimp_preview->yoff - gimp_preview->ymin,
|
2004-09-16 03:56:01 +08:00
|
|
|
width,
|
|
|
|
height,
|
|
|
|
gimp_drawable_type (drawable->drawable_id),
|
|
|
|
buf, rowstride);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-14 20:17:34 +08:00
|
|
|
gint offset_x, offset_y;
|
|
|
|
gint mask_x, mask_y;
|
|
|
|
gint mask_width, mask_height;
|
|
|
|
gint draw_x, draw_y;
|
|
|
|
gint draw_width, draw_height;
|
2004-09-16 03:56:01 +08:00
|
|
|
|
2004-10-05 03:38:26 +08:00
|
|
|
gimp_drawable_offsets (drawable->drawable_id, &offset_x, &offset_y);
|
|
|
|
|
2006-08-14 20:17:34 +08:00
|
|
|
if (gimp_drawable_mask_intersect (drawable->drawable_id,
|
|
|
|
&mask_x, &mask_y,
|
|
|
|
&mask_width, &mask_height) &&
|
|
|
|
gimp_rectangle_intersect (mask_x, mask_y,
|
|
|
|
mask_width, mask_height,
|
|
|
|
x, y, width, height,
|
|
|
|
&draw_x, &draw_y,
|
|
|
|
&draw_width, &draw_height))
|
|
|
|
{
|
|
|
|
GimpDrawable *selection;
|
|
|
|
GimpPixelRgn drawable_rgn;
|
|
|
|
GimpPixelRgn selection_rgn;
|
|
|
|
guchar *src;
|
|
|
|
guchar *sel;
|
|
|
|
|
|
|
|
selection = gimp_drawable_get (gimp_image_get_selection (image_id));
|
|
|
|
|
|
|
|
gimp_pixel_rgn_init (&drawable_rgn, drawable,
|
|
|
|
draw_x, draw_y, draw_width, draw_height,
|
|
|
|
FALSE, FALSE);
|
|
|
|
gimp_pixel_rgn_init (&selection_rgn, selection,
|
|
|
|
draw_x + offset_x, draw_y + offset_y,
|
|
|
|
draw_width, draw_height,
|
|
|
|
FALSE, FALSE);
|
|
|
|
|
|
|
|
src = g_new (guchar, draw_width * draw_height * drawable->bpp);
|
|
|
|
sel = g_new (guchar, draw_width * draw_height);
|
|
|
|
|
|
|
|
gimp_pixel_rgn_get_rect (&drawable_rgn, src,
|
|
|
|
draw_x, draw_y,
|
|
|
|
draw_width, draw_height);
|
|
|
|
gimp_pixel_rgn_get_rect (&selection_rgn, sel,
|
|
|
|
draw_x + offset_x, draw_y + offset_y,
|
|
|
|
draw_width, draw_height);
|
|
|
|
|
|
|
|
gimp_preview_area_mask (GIMP_PREVIEW_AREA (gimp_preview->area),
|
|
|
|
draw_x - gimp_preview->xoff - gimp_preview->xmin,
|
|
|
|
draw_y - gimp_preview->yoff - gimp_preview->ymin,
|
|
|
|
draw_width,
|
|
|
|
draw_height,
|
|
|
|
gimp_drawable_type (drawable->drawable_id),
|
|
|
|
src, draw_width * drawable->bpp,
|
2006-09-11 20:04:49 +08:00
|
|
|
(buf +
|
|
|
|
(draw_x - x) * drawable->bpp +
|
|
|
|
(draw_y - y) * rowstride),
|
2006-08-14 20:17:34 +08:00
|
|
|
rowstride,
|
|
|
|
sel, draw_width);
|
|
|
|
|
|
|
|
g_free (sel);
|
|
|
|
g_free (src);
|
|
|
|
|
|
|
|
gimp_drawable_detach (selection);
|
|
|
|
}
|
2004-09-16 03:56:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-29 23:33:02 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_preview_draw_buffer (GimpPreview *preview,
|
|
|
|
const guchar *buffer,
|
|
|
|
gint rowstride)
|
|
|
|
{
|
|
|
|
gimp_drawable_preview_draw_area (GIMP_DRAWABLE_PREVIEW (preview),
|
|
|
|
preview->xmin + preview->xoff,
|
|
|
|
preview->ymin + preview->yoff,
|
|
|
|
preview->width,
|
|
|
|
preview->height,
|
|
|
|
buffer, rowstride);
|
|
|
|
}
|
|
|
|
|
2004-09-01 03:58:25 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_preview_set_drawable (GimpDrawablePreview *drawable_preview,
|
|
|
|
GimpDrawable *drawable)
|
|
|
|
{
|
|
|
|
GimpPreview *preview = GIMP_PREVIEW (drawable_preview);
|
2005-04-23 19:53:09 +08:00
|
|
|
gint x1, y1, x2, y2;
|
2004-09-01 03:58:25 +08:00
|
|
|
|
|
|
|
drawable_preview->drawable = drawable;
|
|
|
|
|
2006-02-07 23:36:17 +08:00
|
|
|
_gimp_drawable_preview_get_bounds (drawable, &x1, &y1, &x2, &y2);
|
2004-09-01 10:10:40 +08:00
|
|
|
|
2005-04-23 19:53:09 +08:00
|
|
|
gimp_preview_set_bounds (preview, x1, y1, x2, y2);
|
2004-09-04 00:52:26 +08:00
|
|
|
|
|
|
|
if (gimp_drawable_is_indexed (drawable->drawable_id))
|
|
|
|
{
|
2010-07-09 17:29:35 +08:00
|
|
|
guint32 image = gimp_item_get_image (drawable->drawable_id);
|
2004-09-04 00:52:26 +08:00
|
|
|
guchar *cmap;
|
|
|
|
gint num_colors;
|
|
|
|
|
2004-11-02 19:30:49 +08:00
|
|
|
cmap = gimp_image_get_colormap (image, &num_colors);
|
|
|
|
gimp_preview_area_set_colormap (GIMP_PREVIEW_AREA (preview->area),
|
|
|
|
cmap, num_colors);
|
2004-09-04 00:52:26 +08:00
|
|
|
g_free (cmap);
|
|
|
|
}
|
2004-09-01 03:58:25 +08:00
|
|
|
}
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2005-04-23 19:53:09 +08:00
|
|
|
|
|
|
|
#define MAX3(a, b, c) (MAX (MAX ((a), (b)), (c)))
|
|
|
|
#define MIN3(a, b, c) (MIN (MIN ((a), (b)), (c)))
|
|
|
|
|
2006-02-07 23:36:17 +08:00
|
|
|
gboolean
|
|
|
|
_gimp_drawable_preview_get_bounds (GimpDrawable *drawable,
|
2006-04-12 18:53:28 +08:00
|
|
|
gint *xmin,
|
|
|
|
gint *ymin,
|
|
|
|
gint *xmax,
|
|
|
|
gint *ymax)
|
2005-04-23 19:53:09 +08:00
|
|
|
{
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
|
|
|
gint x1, y1;
|
|
|
|
gint x2, y2;
|
|
|
|
gboolean retval;
|
|
|
|
|
2006-02-07 23:36:17 +08:00
|
|
|
g_return_val_if_fail (drawable != NULL, FALSE);
|
|
|
|
|
2005-04-23 19:53:09 +08:00
|
|
|
width = gimp_drawable_width (drawable->drawable_id);
|
|
|
|
height = gimp_drawable_height (drawable->drawable_id);
|
|
|
|
|
|
|
|
retval = gimp_drawable_mask_bounds (drawable->drawable_id,
|
|
|
|
&x1, &y1, &x2, &y2);
|
|
|
|
|
|
|
|
gimp_drawable_offsets (drawable->drawable_id, &offset_x, &offset_y);
|
|
|
|
|
|
|
|
*xmin = MAX3 (x1 - SELECTION_BORDER, 0, - offset_x);
|
|
|
|
*ymin = MAX3 (y1 - SELECTION_BORDER, 0, - offset_y);
|
|
|
|
*xmax = MIN3 (x2 + SELECTION_BORDER, width, width + offset_x);
|
|
|
|
*ymax = MIN3 (y2 + SELECTION_BORDER, height, height + offset_y);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
/**
|
|
|
|
* gimp_drawable_preview_new:
|
2004-08-31 06:49:06 +08:00
|
|
|
* @drawable: a #GimpDrawable
|
2007-09-21 21:27:33 +08:00
|
|
|
* @toggle: unused
|
2004-08-31 06:10:26 +08:00
|
|
|
*
|
2007-09-21 21:27:33 +08:00
|
|
|
* Creates a new #GimpDrawablePreview widget for @drawable.
|
|
|
|
*
|
|
|
|
* In GIMP 2.2 the @toggle parameter was provided to conviently access
|
|
|
|
* the state of the "Preview" check-button. This is not any longer
|
|
|
|
* necessary as the preview itself now stores this state, as well as
|
|
|
|
* the scroll offset.
|
2004-08-31 06:10:26 +08:00
|
|
|
*
|
|
|
|
* Returns: A pointer to the new #GimpDrawablePreview widget.
|
2004-08-31 06:49:06 +08:00
|
|
|
*
|
|
|
|
* Since: GIMP 2.2
|
2004-08-31 06:10:26 +08:00
|
|
|
**/
|
|
|
|
GtkWidget *
|
2004-09-01 22:01:10 +08:00
|
|
|
gimp_drawable_preview_new (GimpDrawable *drawable,
|
|
|
|
gboolean *toggle)
|
2004-08-31 06:10:26 +08:00
|
|
|
{
|
2004-08-31 06:49:06 +08:00
|
|
|
g_return_val_if_fail (drawable != NULL, NULL);
|
|
|
|
|
2007-09-21 21:27:33 +08:00
|
|
|
return g_object_new (GIMP_TYPE_DRAWABLE_PREVIEW,
|
|
|
|
"drawable", drawable,
|
|
|
|
NULL);
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-09-16 03:56:01 +08:00
|
|
|
* gimp_drawable_preview_get_drawable:
|
|
|
|
* @preview: a #GimpDrawablePreview widget
|
|
|
|
*
|
|
|
|
* Return value: the #GimpDrawable that has been passed to
|
|
|
|
* gimp_drawable_preview_new().
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.2
|
|
|
|
**/
|
|
|
|
GimpDrawable *
|
|
|
|
gimp_drawable_preview_get_drawable (GimpDrawablePreview *preview)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE_PREVIEW (preview), NULL);
|
|
|
|
|
|
|
|
return preview->drawable;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_drawable_preview_draw_region:
|
|
|
|
* @preview: a #GimpDrawablePreview widget
|
|
|
|
* @region: a #GimpPixelRgn
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.2
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_drawable_preview_draw_region (GimpDrawablePreview *preview,
|
|
|
|
const GimpPixelRgn *region)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE_PREVIEW (preview));
|
|
|
|
g_return_if_fail (preview->drawable != NULL);
|
|
|
|
g_return_if_fail (region != NULL);
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-09-16 03:56:01 +08:00
|
|
|
/* If the data field is initialized, this region is currently being
|
|
|
|
* processed and we can access it directly.
|
|
|
|
*/
|
|
|
|
if (region->data)
|
2004-09-08 04:20:13 +08:00
|
|
|
{
|
2004-09-16 03:56:01 +08:00
|
|
|
gimp_drawable_preview_draw_area (preview,
|
|
|
|
region->x,
|
|
|
|
region->y,
|
|
|
|
region->w,
|
|
|
|
region->h,
|
|
|
|
region->data,
|
|
|
|
region->rowstride);
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-16 03:56:01 +08:00
|
|
|
GimpPixelRgn src = *region;
|
|
|
|
gpointer iter;
|
2004-09-08 04:20:13 +08:00
|
|
|
|
2004-12-21 05:39:48 +08:00
|
|
|
src.dirty = FALSE; /* we don't dirty the tiles, just read them */
|
|
|
|
|
2004-09-16 03:56:01 +08:00
|
|
|
for (iter = gimp_pixel_rgns_register (1, &src);
|
|
|
|
iter != NULL;
|
|
|
|
iter = gimp_pixel_rgns_process (iter))
|
|
|
|
{
|
|
|
|
gimp_drawable_preview_draw_area (preview,
|
|
|
|
src.x,
|
|
|
|
src.y,
|
|
|
|
src.w,
|
|
|
|
src.h,
|
|
|
|
src.data,
|
|
|
|
src.rowstride);
|
|
|
|
}
|
2004-09-08 04:20:13 +08:00
|
|
|
}
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|