2004-07-30 01:10:28 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
|
|
|
#include "gimpwidgetstypes.h"
|
|
|
|
|
|
|
|
#include "gimppreviewarea.h"
|
|
|
|
|
|
|
|
|
2004-09-01 09:18:19 +08:00
|
|
|
#define CHECK_COLOR(area, row, col) \
|
2004-09-01 16:50:52 +08:00
|
|
|
(((((area)->offset_y + (row)) & GIMP_CHECK_SIZE) ^ \
|
|
|
|
(((area)->offset_x + (col)) & GIMP_CHECK_SIZE)) ? \
|
2004-09-01 09:18:19 +08:00
|
|
|
(GIMP_CHECK_LIGHT * 255) : \
|
2004-07-30 20:01:44 +08:00
|
|
|
(GIMP_CHECK_DARK * 255))
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void gimp_preview_area_class_init (GimpPreviewAreaClass *klass);
|
|
|
|
static void gimp_preview_area_init (GimpPreviewArea *area);
|
|
|
|
|
|
|
|
static void gimp_preview_area_finalize (GObject *object);
|
|
|
|
|
|
|
|
static void gimp_preview_area_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
|
|
|
static gboolean gimp_preview_area_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event);
|
|
|
|
|
|
|
|
|
|
|
|
static GtkDrawingAreaClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gimp_preview_area_get_type (void)
|
|
|
|
{
|
|
|
|
static GType view_type = 0;
|
|
|
|
|
|
|
|
if (! view_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo view_info =
|
|
|
|
{
|
|
|
|
sizeof (GimpPreviewAreaClass),
|
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
(GClassInitFunc) gimp_preview_area_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpPreviewArea),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_preview_area_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
view_type = g_type_register_static (GTK_TYPE_DRAWING_AREA,
|
|
|
|
"GimpPreviewArea",
|
|
|
|
&view_info, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return view_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_area_class_init (GimpPreviewAreaClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
|
|
|
object_class->finalize = gimp_preview_area_finalize;
|
|
|
|
|
|
|
|
widget_class->size_allocate = gimp_preview_area_size_allocate;
|
|
|
|
widget_class->expose_event = gimp_preview_area_expose;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_area_init (GimpPreviewArea *area)
|
|
|
|
{
|
|
|
|
area->buf = NULL;
|
|
|
|
area->cmap = NULL;
|
2004-09-01 09:18:19 +08:00
|
|
|
area->offset_x = 0;
|
|
|
|
area->offset_y = 0;
|
2004-07-30 01:10:28 +08:00
|
|
|
area->width = 0;
|
|
|
|
area->height = 0;
|
|
|
|
area->rowstride = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_area_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpPreviewArea *area = GIMP_PREVIEW_AREA (object);
|
|
|
|
|
|
|
|
if (area->buf)
|
|
|
|
{
|
|
|
|
g_free (area->buf);
|
|
|
|
area->buf = NULL;
|
|
|
|
}
|
|
|
|
if (area->cmap)
|
|
|
|
{
|
|
|
|
g_free (area->cmap);
|
|
|
|
area->cmap = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_area_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
|
|
|
GimpPreviewArea *area = GIMP_PREVIEW_AREA (widget);
|
|
|
|
|
|
|
|
if (GTK_WIDGET_CLASS (parent_class)->size_allocate)
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
|
|
|
|
|
|
|
|
if (widget->allocation.width != area->width ||
|
|
|
|
widget->allocation.height != area->height)
|
|
|
|
{
|
|
|
|
if (area->buf)
|
2004-07-30 05:08:13 +08:00
|
|
|
{
|
|
|
|
g_free (area->buf);
|
2004-07-30 01:10:28 +08:00
|
|
|
|
2004-07-30 05:08:13 +08:00
|
|
|
area->buf = NULL;
|
|
|
|
area->rowstride = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
area->width = widget->allocation.width;
|
|
|
|
area->height = widget->allocation.height;
|
2004-07-30 01:10:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_preview_area_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event)
|
|
|
|
{
|
|
|
|
GimpPreviewArea *area;
|
|
|
|
guchar *buf;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PREVIEW_AREA (widget), FALSE);
|
|
|
|
|
|
|
|
area = GIMP_PREVIEW_AREA (widget);
|
|
|
|
|
2004-07-31 09:03:00 +08:00
|
|
|
if (! area->buf)
|
2004-07-30 01:10:28 +08:00
|
|
|
return FALSE;
|
|
|
|
|
2004-07-30 05:08:13 +08:00
|
|
|
buf = area->buf + event->area.x * 3 + event->area.y * area->rowstride;
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
gdk_draw_rgb_image_dithalign (widget->window,
|
|
|
|
widget->style->fg_gc[widget->state],
|
|
|
|
event->area.x,
|
|
|
|
event->area.y,
|
|
|
|
event->area.width,
|
|
|
|
event->area.height,
|
|
|
|
GDK_RGB_DITHER_MAX,
|
|
|
|
buf,
|
|
|
|
area->rowstride,
|
2004-09-01 09:18:19 +08:00
|
|
|
area->offset_x - event->area.x,
|
|
|
|
area->offset_y - event->area.y);
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_preview_area_new:
|
|
|
|
*
|
|
|
|
* Return value: a new #GimpPreviewArea widget.
|
|
|
|
*
|
|
|
|
* Since GIMP 2.2
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_preview_area_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GIMP_TYPE_PREVIEW_AREA, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_preview_area_draw:
|
|
|
|
* @area: a #GimpPreviewArea widget.
|
|
|
|
* @x: x offset in preview
|
|
|
|
* @y: y offset in preview
|
|
|
|
* @width: buffer width
|
|
|
|
* @height: buffer height
|
2004-07-31 09:03:00 +08:00
|
|
|
* @type: the #GimpImageType of @buf
|
2004-07-30 01:10:28 +08:00
|
|
|
* @buf: a #guchar buffer that contains the preview pixel data.
|
2004-07-31 09:03:00 +08:00
|
|
|
* @rowstride: rowstride of @buf
|
2004-07-30 01:10:28 +08:00
|
|
|
*
|
|
|
|
* Draws @buf on @area and queues a redraw on the rectangle that
|
|
|
|
* changed.
|
|
|
|
*
|
|
|
|
* Since GIMP 2.2
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_area_draw (GimpPreviewArea *area,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpImageType type,
|
|
|
|
const guchar *buf,
|
|
|
|
gint rowstride)
|
|
|
|
{
|
|
|
|
const guchar *src;
|
|
|
|
guchar *dest;
|
|
|
|
gint row;
|
|
|
|
gint col;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW_AREA (area));
|
|
|
|
g_return_if_fail (width > 0 && height > 0);
|
|
|
|
g_return_if_fail (buf != NULL);
|
|
|
|
g_return_if_fail (rowstride > 0);
|
|
|
|
|
|
|
|
if (x + width < 0 || x >= area->width)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (y + height < 0 || y >= area->height)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (x < 0)
|
|
|
|
{
|
|
|
|
gint bpp;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GIMP_GRAY_IMAGE:
|
|
|
|
case GIMP_INDEXED_IMAGE:
|
|
|
|
bpp = 1;
|
|
|
|
break;
|
|
|
|
case GIMP_GRAYA_IMAGE:
|
|
|
|
case GIMP_INDEXEDA_IMAGE:
|
|
|
|
bpp = 2;
|
|
|
|
break;
|
|
|
|
case GIMP_RGB_IMAGE:
|
|
|
|
bpp = 3;
|
|
|
|
break;
|
|
|
|
case GIMP_RGBA_IMAGE:
|
|
|
|
bpp = 4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_return_if_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf += x * bpp;
|
|
|
|
width -= x;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x + width > area->width)
|
|
|
|
width = area->width - x;
|
|
|
|
|
|
|
|
if (y < 0)
|
|
|
|
{
|
|
|
|
buf += y * rowstride;
|
|
|
|
height -= y;
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y + height > area->height)
|
|
|
|
height = area->height - y;
|
|
|
|
|
2004-07-31 09:03:00 +08:00
|
|
|
if (! area->buf)
|
|
|
|
{
|
|
|
|
area->rowstride = ((area->width * 3) + 3) & ~3;
|
|
|
|
area->buf = g_new (guchar, area->rowstride * area->height);
|
|
|
|
}
|
|
|
|
|
2004-07-30 01:10:28 +08:00
|
|
|
src = buf;
|
|
|
|
dest = area->buf + x * 3 + y * area->rowstride;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GIMP_RGB_IMAGE:
|
|
|
|
for (row = 0; row < height; row++)
|
|
|
|
{
|
|
|
|
memcpy (dest, src, 3 * width);
|
|
|
|
|
|
|
|
src += rowstride;
|
|
|
|
dest += area->rowstride;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RGBA_IMAGE:
|
|
|
|
for (row = y; row < y + height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s = src;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
|
|
|
for (col = x; col < x + width; col++, s += 4, d+= 3)
|
|
|
|
{
|
|
|
|
switch (s[3])
|
|
|
|
{
|
|
|
|
case 0:
|
2004-09-01 09:18:19 +08:00
|
|
|
d[0] = d[1] = d[2] = CHECK_COLOR (area, row, col);
|
2004-07-30 01:10:28 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
d[0] = s[0];
|
|
|
|
d[1] = s[1];
|
|
|
|
d[2] = s[2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-07-30 20:01:44 +08:00
|
|
|
{
|
|
|
|
register guint alpha = s[3] + 1;
|
2004-09-01 09:18:19 +08:00
|
|
|
register guint check = CHECK_COLOR (area, row, col);
|
2004-07-30 20:01:44 +08:00
|
|
|
|
|
|
|
d[0] = ((check << 8) + (s[0] - check) * alpha) >> 8;
|
|
|
|
d[1] = ((check << 8) + (s[1] - check) * alpha) >> 8;
|
|
|
|
d[2] = ((check << 8) + (s[2] - check) * alpha) >> 8;
|
|
|
|
}
|
2004-07-30 01:10:28 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
src += rowstride;
|
|
|
|
dest += area->rowstride;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRAY_IMAGE:
|
|
|
|
for (row = 0; row < height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s = src;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
|
|
|
for (col = 0; col < width; col++, s++, d += 3)
|
|
|
|
{
|
2004-07-30 22:38:11 +08:00
|
|
|
d[0] = d[1] = d[2] = s[0];
|
2004-07-30 01:10:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
src += rowstride;
|
|
|
|
dest += area->rowstride;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRAYA_IMAGE:
|
|
|
|
for (row = y; row < y + height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s = src;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
|
|
|
for (col = x; col < x + width; col++, s += 2, d+= 3)
|
|
|
|
{
|
|
|
|
switch (s[1])
|
|
|
|
{
|
|
|
|
case 0:
|
2004-09-01 09:18:19 +08:00
|
|
|
d[0] = d[1] = d[2] = CHECK_COLOR (area, row, col);
|
2004-07-30 01:10:28 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
d[0] = d[1] = d[2] = s[0];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-07-30 20:01:44 +08:00
|
|
|
{
|
|
|
|
register guint alpha = s[1] + 1;
|
2004-09-01 09:18:19 +08:00
|
|
|
register guint check = CHECK_COLOR (area, row, col);
|
2004-07-30 20:01:44 +08:00
|
|
|
|
|
|
|
d[0] = d[1] = d[2] =
|
|
|
|
((check << 8) + (s[0] - check) * alpha) >> 8;
|
|
|
|
}
|
2004-07-30 01:10:28 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
src += rowstride;
|
|
|
|
dest += area->rowstride;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_INDEXED_IMAGE:
|
|
|
|
g_return_if_fail (area->cmap != NULL);
|
|
|
|
for (row = 0; row < height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s = src;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
|
|
|
for (col = 0; col < width; col++, s++, d += 3)
|
|
|
|
{
|
2004-08-07 08:04:16 +08:00
|
|
|
const guchar *cmap = area->cmap + 3 * s[0];
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
d[0] = cmap[0];
|
|
|
|
d[1] = cmap[1];
|
|
|
|
d[2] = cmap[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
src += rowstride;
|
|
|
|
dest += area->rowstride;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_INDEXEDA_IMAGE:
|
|
|
|
g_return_if_fail (area->cmap != NULL);
|
|
|
|
for (row = y; row < y + height; row++)
|
|
|
|
{
|
|
|
|
const guchar *s = src;
|
|
|
|
guchar *d = dest;
|
|
|
|
|
2004-08-07 08:04:16 +08:00
|
|
|
for (col = x; col < x + width; col++, s += 2, d += 3)
|
2004-07-30 01:10:28 +08:00
|
|
|
{
|
2004-08-07 08:04:16 +08:00
|
|
|
const guchar *cmap = area->cmap + 3 * s[0];
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
switch (s[1])
|
|
|
|
{
|
|
|
|
case 0:
|
2004-09-01 09:18:19 +08:00
|
|
|
d[0] = d[1] = d[2] = CHECK_COLOR (area, row, col);
|
2004-07-30 01:10:28 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 255:
|
|
|
|
d[0] = cmap[0];
|
|
|
|
d[1] = cmap[1];
|
|
|
|
d[2] = cmap[2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-07-30 20:01:44 +08:00
|
|
|
{
|
|
|
|
register guint alpha = s[3] + 1;
|
2004-09-01 09:18:19 +08:00
|
|
|
register guint check = CHECK_COLOR (area, row, col);
|
2004-07-30 20:01:44 +08:00
|
|
|
|
|
|
|
d[0] = ((check << 8) + (cmap[0] - check) * alpha) >> 8;
|
|
|
|
d[1] = ((check << 8) + (cmap[1] - check) * alpha) >> 8;
|
|
|
|
d[2] = ((check << 8) + (cmap[2] - check) * alpha) >> 8;
|
|
|
|
}
|
2004-07-30 01:10:28 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
src += rowstride;
|
|
|
|
dest += area->rowstride;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_queue_draw_area (GTK_WIDGET (area), x, y, width, height);
|
|
|
|
}
|
|
|
|
|
2004-07-31 09:03:00 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_area_fill:
|
|
|
|
* @area: a #GimpPreviewArea widget.
|
|
|
|
* @x: x offset in preview
|
|
|
|
* @y: y offset in preview
|
|
|
|
* @width: buffer width
|
|
|
|
* @height: buffer height
|
|
|
|
* @red:
|
|
|
|
* @green:
|
|
|
|
* @blue:
|
|
|
|
*
|
|
|
|
* Fills the @area in the given color.
|
|
|
|
*
|
|
|
|
* Since GIMP 2.2
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_area_fill (GimpPreviewArea *area,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
guchar red,
|
|
|
|
guchar green,
|
|
|
|
guchar blue)
|
|
|
|
{
|
|
|
|
guchar *dest;
|
|
|
|
gint row;
|
|
|
|
gint col;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW_AREA (area));
|
|
|
|
g_return_if_fail (width > 0 && height > 0);
|
|
|
|
|
|
|
|
if (x + width < 0 || x >= area->width)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (y + height < 0 || y >= area->height)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (x < 0)
|
|
|
|
{
|
|
|
|
width -= x;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x + width > area->width)
|
|
|
|
width = area->width - x;
|
|
|
|
|
|
|
|
if (y < 0)
|
|
|
|
{
|
|
|
|
height -= y;
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y + height > area->height)
|
|
|
|
height = area->height - y;
|
|
|
|
|
|
|
|
if (! area->buf)
|
|
|
|
{
|
|
|
|
area->rowstride = ((area->width * 3) + 3) & ~3;
|
|
|
|
area->buf = g_new (guchar, area->rowstride * area->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
dest = area->buf + x * 3 + y * area->rowstride;
|
|
|
|
|
|
|
|
for (row = 0; row < height; row++)
|
|
|
|
{
|
|
|
|
guchar *d = dest;
|
|
|
|
|
|
|
|
for (col = 0; col < width; col++, d+= 3)
|
|
|
|
{
|
|
|
|
d[0] = red;
|
|
|
|
d[1] = green;
|
|
|
|
d[2] = blue;
|
|
|
|
}
|
|
|
|
|
|
|
|
dest += area->rowstride;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_queue_draw_area (GTK_WIDGET (area), x, y, width, height);
|
|
|
|
}
|
|
|
|
|
2004-09-01 09:18:19 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_area_set_offsets:
|
|
|
|
* @area: a #GimpPreviewArea
|
|
|
|
* @x: horizontal offset
|
|
|
|
* @y: vertical offset
|
|
|
|
*
|
|
|
|
* Sets the offsets of the previewed area. This information is used
|
|
|
|
* when drawing the checkerboard and to determine the dither offsets.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.2
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_area_set_offsets (GimpPreviewArea *area,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW_AREA (area));
|
|
|
|
|
|
|
|
area->offset_x = x;
|
|
|
|
area->offset_y = y;
|
|
|
|
}
|
2004-07-31 09:03:00 +08:00
|
|
|
|
2004-07-30 01:10:28 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_area_set_cmap:
|
|
|
|
* @area: a #GimpPreviewArea
|
|
|
|
* @cmap: a #guchar buffer that contains the colormap
|
|
|
|
* @num_colors: the number of colors in the colormap
|
|
|
|
*
|
|
|
|
* Sets the colormap for the #GimpPreviewArea widget. You need to
|
|
|
|
* call this function before you use gimp_preview_area_draw() with
|
|
|
|
* an image type of %GIMP_INDEXED_IMAGE or %GIMP_INDEXEDA_IMAGE.
|
|
|
|
*
|
|
|
|
* Since GIMP 2.2
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_area_set_cmap (GimpPreviewArea *area,
|
|
|
|
const guchar *cmap,
|
|
|
|
gint num_colors)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW_AREA (area));
|
|
|
|
g_return_if_fail (cmap != NULL || num_colors == 0);
|
2004-07-30 05:08:13 +08:00
|
|
|
g_return_if_fail (num_colors >= 0 && num_colors <= 256);
|
2004-07-30 01:10:28 +08:00
|
|
|
|
|
|
|
if (num_colors > 0)
|
|
|
|
{
|
|
|
|
if (! area->cmap)
|
|
|
|
area->cmap = g_new0 (guchar, 3 * 256);
|
|
|
|
|
|
|
|
memcpy (area->cmap, cmap, 3 * num_colors);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_free (area->cmap);
|
|
|
|
area->cmap = NULL;
|
|
|
|
}
|
|
|
|
}
|