2001-10-05 18:51:47 +00:00
|
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
|
1999-10-20 21:20:49 +00:00
|
|
|
|
/* GdkPixbuf library - Basic memory management
|
1999-01-04 23:53:12 +00:00
|
|
|
|
*
|
1999-10-18 19:29:45 +00:00
|
|
|
|
* Copyright (C) 1999 The Free Software Foundation
|
|
|
|
|
*
|
|
|
|
|
* Authors: Mark Crichton <crichton@gimp.org>
|
|
|
|
|
* Miguel de Icaza <miguel@gnu.org>
|
|
|
|
|
* Federico Mena-Quintero <federico@gimp.org>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1999-10-18 19:29:45 +00:00
|
|
|
|
* 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
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* Lesser General Public License for more details.
|
1999-10-18 19:29:45 +00:00
|
|
|
|
*
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1999-10-18 19:29:45 +00:00
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
* Boston, MA 02111-1307, USA.
|
1999-01-04 23:53:12 +00:00
|
|
|
|
*/
|
1999-08-09 06:09:24 +00:00
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
|
#include "config.h"
|
1999-07-19 02:13:34 +00:00
|
|
|
|
#include <math.h>
|
2000-04-11 07:03:25 +00:00
|
|
|
|
#include <stdlib.h>
|
2000-07-14 20:24:14 +00:00
|
|
|
|
#include <string.h>
|
2008-05-27 12:50:45 +00:00
|
|
|
|
#define GDK_PIXBUF_C_COMPILATION
|
1999-12-02 20:44:43 +00:00
|
|
|
|
#include "gdk-pixbuf.h"
|
2000-04-11 07:03:25 +00:00
|
|
|
|
#include "gdk-pixbuf-private.h"
|
2006-09-10 06:39:16 +00:00
|
|
|
|
/* Include the marshallers */
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
#include "gdk-pixbuf-marshal.c"
|
2005-03-14 19:37:00 +00:00
|
|
|
|
#include "gdk-pixbuf-alias.h"
|
1999-01-04 23:53:12 +00:00
|
|
|
|
|
2004-01-03 23:45:06 +00:00
|
|
|
|
static void gdk_pixbuf_finalize (GObject *object);
|
|
|
|
|
static void gdk_pixbuf_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
static void gdk_pixbuf_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
2000-06-22 15:36:12 +00:00
|
|
|
|
|
1999-10-18 19:29:45 +00:00
|
|
|
|
|
2004-01-03 23:45:06 +00:00
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_COLORSPACE,
|
|
|
|
|
PROP_N_CHANNELS,
|
|
|
|
|
PROP_HAS_ALPHA,
|
|
|
|
|
PROP_BITS_PER_SAMPLE,
|
|
|
|
|
PROP_WIDTH,
|
|
|
|
|
PROP_HEIGHT,
|
|
|
|
|
PROP_ROWSTRIDE,
|
|
|
|
|
PROP_PIXELS
|
|
|
|
|
};
|
1999-01-04 23:53:12 +00:00
|
|
|
|
|
2006-05-14 04:25:34 +00:00
|
|
|
|
G_DEFINE_TYPE (GdkPixbuf, gdk_pixbuf, G_TYPE_OBJECT)
|
2000-06-22 15:36:12 +00:00
|
|
|
|
|
2006-04-04 13:35:59 +00:00
|
|
|
|
static void
|
|
|
|
|
gdk_pixbuf_init (GdkPixbuf *pixbuf)
|
2000-06-22 15:36:12 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gdk_pixbuf_class_init (GdkPixbufClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
|
|
object_class->finalize = gdk_pixbuf_finalize;
|
2004-01-03 23:45:06 +00:00
|
|
|
|
object_class->set_property = gdk_pixbuf_set_property;
|
|
|
|
|
object_class->get_property = gdk_pixbuf_get_property;
|
2005-03-21 05:07:20 +00:00
|
|
|
|
|
|
|
|
|
#define PIXBUF_PARAM_FLAGS G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|\
|
|
|
|
|
G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
|
2004-11-05 01:43:31 +00:00
|
|
|
|
/**
|
|
|
|
|
* GdkPixbuf:n-channels:
|
|
|
|
|
*
|
|
|
|
|
* The number of samples per pixel.
|
|
|
|
|
* Currently, only 3 or 4 samples per pixel are supported.
|
|
|
|
|
*/
|
2004-01-03 23:45:06 +00:00
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_N_CHANNELS,
|
2005-03-09 02:49:27 +00:00
|
|
|
|
g_param_spec_int ("n-channels",
|
2004-01-16 23:10:05 +00:00
|
|
|
|
P_("Number of Channels"),
|
|
|
|
|
P_("The number of samples per pixel"),
|
2004-01-03 23:45:06 +00:00
|
|
|
|
0,
|
|
|
|
|
G_MAXINT,
|
|
|
|
|
3,
|
2005-03-21 05:07:20 +00:00
|
|
|
|
PIXBUF_PARAM_FLAGS));
|
2004-01-03 23:45:06 +00:00
|
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_COLORSPACE,
|
|
|
|
|
g_param_spec_enum ("colorspace",
|
2004-01-16 23:10:05 +00:00
|
|
|
|
P_("Colorspace"),
|
|
|
|
|
P_("The colorspace in which the samples are interpreted"),
|
2004-01-03 23:45:06 +00:00
|
|
|
|
GDK_TYPE_COLORSPACE,
|
|
|
|
|
GDK_COLORSPACE_RGB,
|
2005-03-21 05:07:20 +00:00
|
|
|
|
PIXBUF_PARAM_FLAGS));
|
2004-01-03 23:45:06 +00:00
|
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_HAS_ALPHA,
|
2005-03-09 02:49:27 +00:00
|
|
|
|
g_param_spec_boolean ("has-alpha",
|
2004-01-16 23:10:05 +00:00
|
|
|
|
P_("Has Alpha"),
|
|
|
|
|
P_("Whether the pixbuf has an alpha channel"),
|
2004-01-03 23:45:06 +00:00
|
|
|
|
FALSE,
|
2005-03-21 05:07:20 +00:00
|
|
|
|
PIXBUF_PARAM_FLAGS));
|
2004-01-03 23:45:06 +00:00
|
|
|
|
|
2004-11-05 01:43:31 +00:00
|
|
|
|
/**
|
|
|
|
|
* GdkPixbuf:bits-per-sample:
|
|
|
|
|
*
|
|
|
|
|
* The number of bits per sample.
|
|
|
|
|
* Currently only 8 bit per sample are supported.
|
|
|
|
|
*/
|
2004-01-03 23:45:06 +00:00
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_BITS_PER_SAMPLE,
|
2005-03-09 02:49:27 +00:00
|
|
|
|
g_param_spec_int ("bits-per-sample",
|
2004-01-16 23:10:05 +00:00
|
|
|
|
P_("Bits per Sample"),
|
|
|
|
|
P_("The number of bits per sample"),
|
2004-01-03 23:45:06 +00:00
|
|
|
|
1,
|
|
|
|
|
16,
|
|
|
|
|
8,
|
2005-03-21 05:07:20 +00:00
|
|
|
|
PIXBUF_PARAM_FLAGS));
|
2004-01-03 23:45:06 +00:00
|
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_WIDTH,
|
|
|
|
|
g_param_spec_int ("width",
|
2004-01-16 23:10:05 +00:00
|
|
|
|
P_("Width"),
|
|
|
|
|
P_("The number of columns of the pixbuf"),
|
2004-01-03 23:45:06 +00:00
|
|
|
|
1,
|
|
|
|
|
G_MAXINT,
|
|
|
|
|
1,
|
2005-03-21 05:07:20 +00:00
|
|
|
|
PIXBUF_PARAM_FLAGS));
|
2004-01-03 23:45:06 +00:00
|
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_HEIGHT,
|
|
|
|
|
g_param_spec_int ("height",
|
2004-01-16 23:10:05 +00:00
|
|
|
|
P_("Height"),
|
|
|
|
|
P_("The number of rows of the pixbuf"),
|
2004-01-03 23:45:06 +00:00
|
|
|
|
1,
|
|
|
|
|
G_MAXINT,
|
|
|
|
|
1,
|
2005-03-21 05:07:20 +00:00
|
|
|
|
PIXBUF_PARAM_FLAGS));
|
2004-01-03 23:45:06 +00:00
|
|
|
|
|
2004-11-05 01:43:31 +00:00
|
|
|
|
/**
|
|
|
|
|
* GdkPixbuf:rowstride:
|
|
|
|
|
*
|
|
|
|
|
* The number of bytes between the start of a row and
|
|
|
|
|
* the start of the next row. This number must (obviously)
|
|
|
|
|
* be at least as large as the width of the pixbuf.
|
|
|
|
|
*/
|
2004-01-03 23:45:06 +00:00
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_ROWSTRIDE,
|
|
|
|
|
g_param_spec_int ("rowstride",
|
2004-01-16 23:10:05 +00:00
|
|
|
|
P_("Rowstride"),
|
|
|
|
|
P_("The number of bytes between the start of a row and the start of the next row"),
|
2004-01-03 23:45:06 +00:00
|
|
|
|
1,
|
|
|
|
|
G_MAXINT,
|
|
|
|
|
1,
|
2005-03-21 05:07:20 +00:00
|
|
|
|
PIXBUF_PARAM_FLAGS));
|
2004-01-03 23:45:06 +00:00
|
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_PIXELS,
|
|
|
|
|
g_param_spec_pointer ("pixels",
|
2004-01-16 23:10:05 +00:00
|
|
|
|
P_("Pixels"),
|
|
|
|
|
P_("A pointer to the pixel data of the pixbuf"),
|
2005-03-21 05:07:20 +00:00
|
|
|
|
PIXBUF_PARAM_FLAGS));
|
2000-06-22 15:36:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gdk_pixbuf_finalize (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GdkPixbuf *pixbuf = GDK_PIXBUF (object);
|
|
|
|
|
|
|
|
|
|
if (pixbuf->destroy_fn)
|
|
|
|
|
(* pixbuf->destroy_fn) (pixbuf->pixels, pixbuf->destroy_fn_data);
|
|
|
|
|
|
2006-04-04 13:35:59 +00:00
|
|
|
|
G_OBJECT_CLASS (gdk_pixbuf_parent_class)->finalize (object);
|
2000-06-22 15:36:12 +00:00
|
|
|
|
}
|
Remove assorted G_OBJECT casts where unnecessary.
2001-12-13 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gdk-pixbuf-animation.c, gdk-pixbuf-loader.c, gdk-pixpuf.c,
io-gif-animation.c, io-gif.c, io-tiff.c, test-loaders.c: Remove
assorted G_OBJECT casts where unnecessary.
* gdk-pixbuf-loader.c: Call g_object_ref and g_object_unref
instead of gdk_pixbuf_animation_ref and gdk_pixbuf_animation_unref
resp.
* gdk-pixbuf-csource.c, io-bmp.c, io-gif-animation.c, io-ico.c,
io-jpeg.c, io-png.c, io-pnm.c, io-ras.c, io-tga.c, io-wbmp.c,
io-xbm.c, io-xpm.c, test-gdk-pixbuf.c: Dito for gdk_pixbuf_ref and
gdk_pixbuf_unref.
* Makefile.am, pixops/Makefile.am: Compile everything with
-DG_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED
* gdk-pixdata.c: Use g_ascii_strup() instead of g_strup().
* io-xpm.c: Use g_ascii_strcasecmp() instead of g_strcasecmp().
* demos/testpixbuf-drawable.c, demos/testpixbuf-save.c,
demos/testpixbuf-scale.c, demos/testpixbuf.c: Call g_object_ref
and g_object_unref instead of gdk_pixbuf_ref and gdk_pixbuf_unref
resp.
2001-12-13 21:22:12 +00:00
|
|
|
|
|
1999-09-22 22:30:51 +00:00
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_ref:
|
|
|
|
|
* @pixbuf: A pixbuf.
|
|
|
|
|
*
|
2002-11-29 20:36:26 +00:00
|
|
|
|
* Adds a reference to a pixbuf.
|
2000-01-21 22:54:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Return value: The same as the @pixbuf argument.
|
2002-11-29 20:36:26 +00:00
|
|
|
|
*
|
|
|
|
|
* Deprecated: Use g_object_ref().
|
1999-10-20 21:20:49 +00:00
|
|
|
|
**/
|
2000-01-21 22:54:44 +00:00
|
|
|
|
GdkPixbuf *
|
1999-10-18 19:29:45 +00:00
|
|
|
|
gdk_pixbuf_ref (GdkPixbuf *pixbuf)
|
1999-01-04 23:53:12 +00:00
|
|
|
|
{
|
2002-09-29 21:24:24 +00:00
|
|
|
|
return (GdkPixbuf *) g_object_ref (pixbuf);
|
1999-01-04 23:53:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_unref:
|
|
|
|
|
* @pixbuf: A pixbuf.
|
|
|
|
|
*
|
2002-11-29 20:36:26 +00:00
|
|
|
|
* Removes a reference from a pixbuf.
|
2000-04-13 01:18:41 +00:00
|
|
|
|
*
|
2002-11-29 20:36:26 +00:00
|
|
|
|
* Deprecated: Use g_object_unref().
|
1999-10-20 21:20:49 +00:00
|
|
|
|
**/
|
1999-01-04 23:53:12 +00:00
|
|
|
|
void
|
1999-10-18 19:29:45 +00:00
|
|
|
|
gdk_pixbuf_unref (GdkPixbuf *pixbuf)
|
1999-01-04 23:53:12 +00:00
|
|
|
|
{
|
2002-09-29 21:24:24 +00:00
|
|
|
|
g_object_unref (pixbuf);
|
1999-07-16 20:35:21 +00:00
|
|
|
|
}
|
1999-01-04 23:53:12 +00:00
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
|
1999-07-17 20:03:34 +00:00
|
|
|
|
|
2000-04-11 07:03:25 +00:00
|
|
|
|
/* Used as the destroy notification function for gdk_pixbuf_new() */
|
1999-10-27 23:36:44 +00:00
|
|
|
|
static void
|
2000-04-11 07:03:25 +00:00
|
|
|
|
free_buffer (guchar *pixels, gpointer data)
|
1999-10-27 23:36:44 +00:00
|
|
|
|
{
|
2001-02-19 14:35:25 +00:00
|
|
|
|
g_free (pixels);
|
1999-10-27 23:36:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-10-27 17:28:44 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_new:
|
2006-12-21 20:40:24 +00:00
|
|
|
|
* @colorspace: Color space for image
|
|
|
|
|
* @has_alpha: Whether the image should have transparency information
|
|
|
|
|
* @bits_per_sample: Number of bits per color sample
|
|
|
|
|
* @width: Width of image in pixels, must be > 0
|
|
|
|
|
* @height: Height of image in pixels, must be > 0
|
1999-11-04 08:14:32 +00:00
|
|
|
|
*
|
2002-03-12 20:38:49 +00:00
|
|
|
|
* Creates a new #GdkPixbuf structure and allocates a buffer for it. The
|
|
|
|
|
* buffer has an optimal rowstride. Note that the buffer is not cleared;
|
|
|
|
|
* you will have to fill it completely yourself.
|
1999-11-04 08:14:32 +00:00
|
|
|
|
*
|
2001-12-20 23:44:19 +00:00
|
|
|
|
* Return value: A newly-created #GdkPixbuf with a reference count of 1, or
|
|
|
|
|
* %NULL if not enough memory could be allocated for the image buffer.
|
1999-10-27 17:28:44 +00:00
|
|
|
|
**/
|
|
|
|
|
GdkPixbuf *
|
2002-03-12 20:38:49 +00:00
|
|
|
|
gdk_pixbuf_new (GdkColorspace colorspace,
|
|
|
|
|
gboolean has_alpha,
|
|
|
|
|
int bits_per_sample,
|
|
|
|
|
int width,
|
|
|
|
|
int height)
|
1999-10-27 17:28:44 +00:00
|
|
|
|
{
|
1999-10-27 23:36:44 +00:00
|
|
|
|
guchar *buf;
|
|
|
|
|
int channels;
|
|
|
|
|
int rowstride;
|
2002-03-03 02:35:25 +00:00
|
|
|
|
gsize bytes;
|
1999-10-27 17:28:44 +00:00
|
|
|
|
|
2000-04-11 07:03:25 +00:00
|
|
|
|
g_return_val_if_fail (colorspace == GDK_COLORSPACE_RGB, NULL);
|
1999-10-27 23:36:44 +00:00
|
|
|
|
g_return_val_if_fail (bits_per_sample == 8, NULL);
|
1999-10-27 17:28:44 +00:00
|
|
|
|
g_return_val_if_fail (width > 0, NULL);
|
1999-10-27 23:36:44 +00:00
|
|
|
|
g_return_val_if_fail (height > 0, NULL);
|
1999-10-27 17:28:44 +00:00
|
|
|
|
|
1999-10-27 23:36:44 +00:00
|
|
|
|
channels = has_alpha ? 4 : 3;
|
2002-03-03 02:35:25 +00:00
|
|
|
|
rowstride = width * channels;
|
|
|
|
|
if (rowstride / channels != width || rowstride + 3 < 0) /* overflow */
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
/* Always align rows to 32-bit boundaries */
|
|
|
|
|
rowstride = (rowstride + 3) & ~3;
|
1999-10-27 17:28:44 +00:00
|
|
|
|
|
2002-03-03 02:35:25 +00:00
|
|
|
|
bytes = height * rowstride;
|
|
|
|
|
if (bytes / rowstride != height) /* overflow */
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
buf = g_try_malloc (bytes);
|
1999-10-27 23:36:44 +00:00
|
|
|
|
if (!buf)
|
|
|
|
|
return NULL;
|
1999-10-27 17:28:44 +00:00
|
|
|
|
|
2000-04-11 07:03:25 +00:00
|
|
|
|
return gdk_pixbuf_new_from_data (buf, colorspace, has_alpha, bits_per_sample,
|
|
|
|
|
width, height, rowstride,
|
1999-10-27 23:36:44 +00:00
|
|
|
|
free_buffer, NULL);
|
|
|
|
|
}
|
1999-10-28 19:00:02 +00:00
|
|
|
|
|
2000-04-11 07:03:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_copy:
|
|
|
|
|
* @pixbuf: A pixbuf.
|
|
|
|
|
*
|
|
|
|
|
* Creates a new #GdkPixbuf with a copy of the information in the specified
|
|
|
|
|
* @pixbuf.
|
|
|
|
|
*
|
2001-12-20 23:44:19 +00:00
|
|
|
|
* Return value: A newly-created pixbuf with a reference count of 1, or %NULL if
|
2000-04-11 07:03:25 +00:00
|
|
|
|
* not enough memory could be allocated.
|
|
|
|
|
**/
|
|
|
|
|
GdkPixbuf *
|
|
|
|
|
gdk_pixbuf_copy (const GdkPixbuf *pixbuf)
|
|
|
|
|
{
|
|
|
|
|
guchar *buf;
|
|
|
|
|
int size;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (pixbuf != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
/* Calculate a semi-exact size. Here we copy with full rowstrides;
|
|
|
|
|
* maybe we should copy each row individually with the minimum
|
|
|
|
|
* rowstride?
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
size = ((pixbuf->height - 1) * pixbuf->rowstride +
|
|
|
|
|
pixbuf->width * ((pixbuf->n_channels * pixbuf->bits_per_sample + 7) / 8));
|
|
|
|
|
|
2001-02-19 14:35:25 +00:00
|
|
|
|
buf = g_try_malloc (size * sizeof (guchar));
|
2000-04-11 07:03:25 +00:00
|
|
|
|
if (!buf)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
memcpy (buf, pixbuf->pixels, size);
|
|
|
|
|
|
|
|
|
|
return gdk_pixbuf_new_from_data (buf,
|
|
|
|
|
pixbuf->colorspace, pixbuf->has_alpha,
|
|
|
|
|
pixbuf->bits_per_sample,
|
|
|
|
|
pixbuf->width, pixbuf->height,
|
|
|
|
|
pixbuf->rowstride,
|
|
|
|
|
free_buffer,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-01 07:07:46 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_new_subpixbuf:
|
|
|
|
|
* @src_pixbuf: a #GdkPixbuf
|
|
|
|
|
* @src_x: X coord in @src_pixbuf
|
|
|
|
|
* @src_y: Y coord in @src_pixbuf
|
|
|
|
|
* @width: width of region in @src_pixbuf
|
|
|
|
|
* @height: height of region in @src_pixbuf
|
|
|
|
|
*
|
|
|
|
|
* Creates a new pixbuf which represents a sub-region of
|
|
|
|
|
* @src_pixbuf. The new pixbuf shares its pixels with the
|
|
|
|
|
* original pixbuf, so writing to one affects both.
|
|
|
|
|
* The new pixbuf holds a reference to @src_pixbuf, so
|
|
|
|
|
* @src_pixbuf will not be finalized until the new pixbuf
|
|
|
|
|
* is finalized.
|
|
|
|
|
*
|
|
|
|
|
* Return value: a new pixbuf
|
|
|
|
|
**/
|
|
|
|
|
GdkPixbuf*
|
|
|
|
|
gdk_pixbuf_new_subpixbuf (GdkPixbuf *src_pixbuf,
|
|
|
|
|
int src_x,
|
|
|
|
|
int src_y,
|
|
|
|
|
int width,
|
|
|
|
|
int height)
|
|
|
|
|
{
|
|
|
|
|
guchar *pixels;
|
|
|
|
|
GdkPixbuf *sub;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_PIXBUF (src_pixbuf), NULL);
|
|
|
|
|
g_return_val_if_fail (src_x >= 0 && src_x + width <= src_pixbuf->width, NULL);
|
|
|
|
|
g_return_val_if_fail (src_y >= 0 && src_y + height <= src_pixbuf->height, NULL);
|
|
|
|
|
|
|
|
|
|
pixels = (gdk_pixbuf_get_pixels (src_pixbuf)
|
|
|
|
|
+ src_y * src_pixbuf->rowstride
|
|
|
|
|
+ src_x * src_pixbuf->n_channels);
|
|
|
|
|
|
|
|
|
|
sub = gdk_pixbuf_new_from_data (pixels,
|
|
|
|
|
src_pixbuf->colorspace,
|
|
|
|
|
src_pixbuf->has_alpha,
|
|
|
|
|
src_pixbuf->bits_per_sample,
|
|
|
|
|
width, height,
|
|
|
|
|
src_pixbuf->rowstride,
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
|
|
/* Keep a reference to src_pixbuf */
|
Remove assorted G_OBJECT casts where unnecessary.
2001-12-13 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gdk-pixbuf-animation.c, gdk-pixbuf-loader.c, gdk-pixpuf.c,
io-gif-animation.c, io-gif.c, io-tiff.c, test-loaders.c: Remove
assorted G_OBJECT casts where unnecessary.
* gdk-pixbuf-loader.c: Call g_object_ref and g_object_unref
instead of gdk_pixbuf_animation_ref and gdk_pixbuf_animation_unref
resp.
* gdk-pixbuf-csource.c, io-bmp.c, io-gif-animation.c, io-ico.c,
io-jpeg.c, io-png.c, io-pnm.c, io-ras.c, io-tga.c, io-wbmp.c,
io-xbm.c, io-xpm.c, test-gdk-pixbuf.c: Dito for gdk_pixbuf_ref and
gdk_pixbuf_unref.
* Makefile.am, pixops/Makefile.am: Compile everything with
-DG_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED
* gdk-pixdata.c: Use g_ascii_strup() instead of g_strup().
* io-xpm.c: Use g_ascii_strcasecmp() instead of g_strcasecmp().
* demos/testpixbuf-drawable.c, demos/testpixbuf-save.c,
demos/testpixbuf-scale.c, demos/testpixbuf.c: Call g_object_ref
and g_object_unref instead of gdk_pixbuf_ref and gdk_pixbuf_unref
resp.
2001-12-13 21:22:12 +00:00
|
|
|
|
g_object_ref (src_pixbuf);
|
2000-11-01 07:07:46 +00:00
|
|
|
|
|
|
|
|
|
g_object_set_qdata_full (G_OBJECT (sub),
|
|
|
|
|
g_quark_from_static_string ("gdk-pixbuf-subpixbuf-src"),
|
|
|
|
|
src_pixbuf,
|
|
|
|
|
(GDestroyNotify) g_object_unref);
|
|
|
|
|
|
|
|
|
|
return sub;
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 08:14:32 +00:00
|
|
|
|
|
1999-10-28 19:00:02 +00:00
|
|
|
|
|
2000-04-11 07:03:25 +00:00
|
|
|
|
/* Accessors */
|
1999-11-04 08:14:32 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2000-04-11 07:03:25 +00:00
|
|
|
|
* gdk_pixbuf_get_colorspace:
|
1999-11-04 08:14:32 +00:00
|
|
|
|
* @pixbuf: A pixbuf.
|
|
|
|
|
*
|
2000-04-11 07:03:25 +00:00
|
|
|
|
* Queries the color space of a pixbuf.
|
1999-11-04 08:14:32 +00:00
|
|
|
|
*
|
2000-04-11 07:03:25 +00:00
|
|
|
|
* Return value: Color space.
|
1999-11-04 08:14:32 +00:00
|
|
|
|
**/
|
2000-04-11 07:03:25 +00:00
|
|
|
|
GdkColorspace
|
|
|
|
|
gdk_pixbuf_get_colorspace (const GdkPixbuf *pixbuf)
|
1999-10-28 19:00:02 +00:00
|
|
|
|
{
|
2000-04-11 07:03:25 +00:00
|
|
|
|
g_return_val_if_fail (pixbuf != NULL, GDK_COLORSPACE_RGB);
|
1999-10-28 19:00:02 +00:00
|
|
|
|
|
2000-04-11 07:03:25 +00:00
|
|
|
|
return pixbuf->colorspace;
|
1999-10-28 19:00:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 08:14:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_get_n_channels:
|
|
|
|
|
* @pixbuf: A pixbuf.
|
|
|
|
|
*
|
|
|
|
|
* Queries the number of channels of a pixbuf.
|
|
|
|
|
*
|
|
|
|
|
* Return value: Number of channels.
|
|
|
|
|
**/
|
1999-10-28 19:00:02 +00:00
|
|
|
|
int
|
2000-04-11 07:03:25 +00:00
|
|
|
|
gdk_pixbuf_get_n_channels (const GdkPixbuf *pixbuf)
|
1999-10-28 19:00:02 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (pixbuf != NULL, -1);
|
|
|
|
|
|
2000-04-11 07:03:25 +00:00
|
|
|
|
return pixbuf->n_channels;
|
1999-10-28 19:00:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 08:14:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_get_has_alpha:
|
|
|
|
|
* @pixbuf: A pixbuf.
|
|
|
|
|
*
|
|
|
|
|
* Queries whether a pixbuf has an alpha channel (opacity information).
|
|
|
|
|
*
|
2001-12-20 23:44:19 +00:00
|
|
|
|
* Return value: %TRUE if it has an alpha channel, %FALSE otherwise.
|
1999-11-04 08:14:32 +00:00
|
|
|
|
**/
|
2000-03-29 19:54:29 +00:00
|
|
|
|
gboolean
|
2000-04-11 07:03:25 +00:00
|
|
|
|
gdk_pixbuf_get_has_alpha (const GdkPixbuf *pixbuf)
|
1999-10-28 19:00:02 +00:00
|
|
|
|
{
|
2003-03-08 20:49:00 +00:00
|
|
|
|
g_return_val_if_fail (pixbuf != NULL, FALSE);
|
1999-10-28 19:00:02 +00:00
|
|
|
|
|
2000-04-11 07:03:25 +00:00
|
|
|
|
return pixbuf->has_alpha ? TRUE : FALSE;
|
1999-10-28 19:00:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 08:14:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_get_bits_per_sample:
|
|
|
|
|
* @pixbuf: A pixbuf.
|
|
|
|
|
*
|
|
|
|
|
* Queries the number of bits per color sample in a pixbuf.
|
|
|
|
|
*
|
|
|
|
|
* Return value: Number of bits per color sample.
|
|
|
|
|
**/
|
1999-10-28 19:00:02 +00:00
|
|
|
|
int
|
2000-04-11 07:03:25 +00:00
|
|
|
|
gdk_pixbuf_get_bits_per_sample (const GdkPixbuf *pixbuf)
|
1999-10-28 19:00:02 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (pixbuf != NULL, -1);
|
|
|
|
|
|
2000-04-11 07:03:25 +00:00
|
|
|
|
return pixbuf->bits_per_sample;
|
1999-10-28 19:00:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 08:14:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_get_pixels:
|
|
|
|
|
* @pixbuf: A pixbuf.
|
|
|
|
|
*
|
|
|
|
|
* Queries a pointer to the pixel data of a pixbuf.
|
|
|
|
|
*
|
2004-01-07 03:17:17 +00:00
|
|
|
|
* Return value: A pointer to the pixbuf's pixel data. Please see <xref linkend="image-data"/>
|
|
|
|
|
* for information about how the pixel data is stored in
|
|
|
|
|
* memory.
|
1999-11-04 08:14:32 +00:00
|
|
|
|
**/
|
1999-10-28 19:00:02 +00:00
|
|
|
|
guchar *
|
2000-04-11 07:03:25 +00:00
|
|
|
|
gdk_pixbuf_get_pixels (const GdkPixbuf *pixbuf)
|
1999-10-28 19:00:02 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (pixbuf != NULL, NULL);
|
|
|
|
|
|
2000-04-11 07:03:25 +00:00
|
|
|
|
return pixbuf->pixels;
|
1999-10-28 19:00:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 08:14:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_get_width:
|
|
|
|
|
* @pixbuf: A pixbuf.
|
|
|
|
|
*
|
|
|
|
|
* Queries the width of a pixbuf.
|
|
|
|
|
*
|
|
|
|
|
* Return value: Width in pixels.
|
|
|
|
|
**/
|
1999-10-28 19:00:02 +00:00
|
|
|
|
int
|
2000-04-11 07:03:25 +00:00
|
|
|
|
gdk_pixbuf_get_width (const GdkPixbuf *pixbuf)
|
1999-10-28 19:00:02 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (pixbuf != NULL, -1);
|
|
|
|
|
|
2000-04-11 07:03:25 +00:00
|
|
|
|
return pixbuf->width;
|
1999-10-28 19:00:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 08:14:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_get_height:
|
|
|
|
|
* @pixbuf: A pixbuf.
|
|
|
|
|
*
|
|
|
|
|
* Queries the height of a pixbuf.
|
|
|
|
|
*
|
|
|
|
|
* Return value: Height in pixels.
|
|
|
|
|
**/
|
1999-10-28 19:00:02 +00:00
|
|
|
|
int
|
2000-04-11 07:03:25 +00:00
|
|
|
|
gdk_pixbuf_get_height (const GdkPixbuf *pixbuf)
|
1999-10-28 19:00:02 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (pixbuf != NULL, -1);
|
|
|
|
|
|
2000-04-11 07:03:25 +00:00
|
|
|
|
return pixbuf->height;
|
1999-10-28 19:00:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 08:14:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_get_rowstride:
|
|
|
|
|
* @pixbuf: A pixbuf.
|
|
|
|
|
*
|
2003-08-03 21:51:24 +00:00
|
|
|
|
* Queries the rowstride of a pixbuf, which is the number of bytes between the start of a row
|
|
|
|
|
* and the start of the next row.
|
1999-11-04 08:14:32 +00:00
|
|
|
|
*
|
2003-08-03 21:51:24 +00:00
|
|
|
|
* Return value: Distance between row starts.
|
1999-11-04 08:14:32 +00:00
|
|
|
|
**/
|
1999-10-28 19:00:02 +00:00
|
|
|
|
int
|
2000-04-11 07:03:25 +00:00
|
|
|
|
gdk_pixbuf_get_rowstride (const GdkPixbuf *pixbuf)
|
1999-10-28 19:00:02 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (pixbuf != NULL, -1);
|
|
|
|
|
|
2000-04-11 07:03:25 +00:00
|
|
|
|
return pixbuf->rowstride;
|
1999-10-28 19:00:02 +00:00
|
|
|
|
}
|
2000-01-10 19:17:42 +00:00
|
|
|
|
|
2000-04-02 18:54:17 +00:00
|
|
|
|
|
2000-04-01 03:28:31 +00:00
|
|
|
|
|
2000-01-10 19:17:42 +00:00
|
|
|
|
/* General initialization hooks */
|
2008-05-27 12:05:14 +00:00
|
|
|
|
const guint gdk_pixbuf_major_version = GDK_PIXBUF_MAJOR;
|
|
|
|
|
const guint gdk_pixbuf_minor_version = GDK_PIXBUF_MINOR;
|
|
|
|
|
const guint gdk_pixbuf_micro_version = GDK_PIXBUF_MICRO;
|
2000-01-10 19:17:42 +00:00
|
|
|
|
|
2008-05-27 12:05:14 +00:00
|
|
|
|
const char *gdk_pixbuf_version = GDK_PIXBUF_VERSION;
|
2000-01-10 19:17:42 +00:00
|
|
|
|
|
2000-10-06 18:19:18 +00:00
|
|
|
|
/* Error quark */
|
|
|
|
|
GQuark
|
|
|
|
|
gdk_pixbuf_error_quark (void)
|
|
|
|
|
{
|
2006-04-04 04:14:17 +00:00
|
|
|
|
return g_quark_from_static_string ("gdk-pixbuf-error-quark");
|
2000-10-06 18:19:18 +00:00
|
|
|
|
}
|
Add built marshaller files to support GdkPixbufLoader signals
2001-01-22 Havoc Pennington <hp@redhat.com>
* Makefile.am: Add built marshaller files to support
GdkPixbufLoader signals
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): have
GDK_PIXBUF_MODULEDIR unconditionally replace the compiled-in
module location, rather than acting as a fallback, because we are
using GDK_PIXBUF_MODULEDIR to use gdk-pixbuf before installing it.
* gdk-pixbuf.h: include gdk-pixbuf-loader.h
* gdk-pixbuf-loader.h, gdk-pixbuf-loader.c: Move back over here
from gtk, and add error to close(), because stop_load may do
parsing of the image.
* pixops/have_mmx.S (_pixops_have_mmx): add newline at end of file
* io-*.c: make individual operations static, and add fill_vtable
functions which are exported. Fix the collection of type warnings
that surfaced, including a number of functions that didn't
properly take a GError and some that weren't
const-correct. Involved adding error handling for a few loaders.
* gdk-pixbuf-io.h: Add error reporting to stop_load function
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): change to just look up
a function that fills in the GdkPixbufModule vtable, instead of
looking up all the image functions individually; this means we
can get type safety within modules for the loader functions.
Also it means you don't have to keep the statically compiled and
GModule versions in sync.
* test-gdk-pixbuf.c (main): remove gdk_pixbuf_init()
* make-inline-pixbuf.c (main): remove call to gdk_pixbuf_init()
* gdk-pixbuf.h: nuke gdk_pixbuf_init()
* gdk-pixbuf-animation.c (gdk_pixbuf_frame_get_type): g_type_init
() here
* gdk-pixbuf.c (gdk_pixbuf_get_type): g_type_init () here
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_get_type):
g_type_init() here
2001-01-22 Havoc Pennington <hp@redhat.com>
* demos/testanimation.c: fix to reflect gdk-pixbuf changes
* demos/testpixbuf.c: fix to reflect gdk-pixbuf changes
* gtk/gdk-pixbuf-loader.c, gtk/gdk-pixbuf-loader.h:
Remove, move back to gdk-pixbuf
* gtk/gtktextiter.c, gtk/gtktextiter.h: add sentence equivalents
to all the word functions
* gtk/gtktextview.c (gtk_text_view_start_cursor_blink): return
before doing anything on NULL layout or if we don't have the focus
* gtk/testtext.c (fill_example_buffer): "justification"
* gtk/gtktexttag.h, gtk/gtktexttag.c: change the tag attribute
to be called "justification" not "justify"
* demos/gtk-demo/textview.c (create_tags): "justification"
* gtk/gtktextlayout.c (set_para_values): Handle char-wise wrapping
2001-01-22 23:09:48 +00:00
|
|
|
|
|
2001-04-18 18:09:18 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_fill:
|
|
|
|
|
* @pixbuf: a #GdkPixbuf
|
2002-03-12 20:38:49 +00:00
|
|
|
|
* @pixel: RGBA pixel to clear to
|
|
|
|
|
* (0xffffffff is opaque white, 0x00000000 transparent black)
|
2001-04-18 18:09:18 +00:00
|
|
|
|
*
|
|
|
|
|
* Clears a pixbuf to the given RGBA value, converting the RGBA value into
|
|
|
|
|
* the pixbuf's pixel format. The alpha will be ignored if the pixbuf
|
|
|
|
|
* doesn't have an alpha channel.
|
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
gdk_pixbuf_fill (GdkPixbuf *pixbuf,
|
|
|
|
|
guint32 pixel)
|
|
|
|
|
{
|
|
|
|
|
guchar *pixels;
|
|
|
|
|
guint r, g, b, a;
|
2002-02-01 23:43:07 +00:00
|
|
|
|
guchar *p;
|
2002-03-12 20:38:49 +00:00
|
|
|
|
guint w, h;
|
2002-02-01 23:43:07 +00:00
|
|
|
|
|
2001-04-18 18:09:18 +00:00
|
|
|
|
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
|
|
|
|
|
|
2001-08-07 17:49:09 +00:00
|
|
|
|
if (pixbuf->width == 0 || pixbuf->height == 0)
|
2002-03-12 20:38:49 +00:00
|
|
|
|
return;
|
2001-08-07 17:49:09 +00:00
|
|
|
|
|
2001-04-18 18:09:18 +00:00
|
|
|
|
pixels = pixbuf->pixels;
|
|
|
|
|
|
|
|
|
|
r = (pixel & 0xff000000) >> 24;
|
|
|
|
|
g = (pixel & 0x00ff0000) >> 16;
|
|
|
|
|
b = (pixel & 0x0000ff00) >> 8;
|
|
|
|
|
a = (pixel & 0x000000ff);
|
|
|
|
|
|
2002-03-12 20:38:49 +00:00
|
|
|
|
h = pixbuf->height;
|
2001-04-18 18:09:18 +00:00
|
|
|
|
|
2002-03-12 20:38:49 +00:00
|
|
|
|
while (h--) {
|
|
|
|
|
w = pixbuf->width;
|
2001-04-18 18:09:18 +00:00
|
|
|
|
p = pixels;
|
2002-03-12 20:38:49 +00:00
|
|
|
|
|
|
|
|
|
switch (pixbuf->n_channels) {
|
|
|
|
|
case 3:
|
|
|
|
|
while (w--) {
|
|
|
|
|
p[0] = r;
|
|
|
|
|
p[1] = g;
|
|
|
|
|
p[2] = b;
|
2001-08-07 17:49:09 +00:00
|
|
|
|
p += 3;
|
2002-03-12 20:38:49 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
while (w--) {
|
|
|
|
|
p[0] = r;
|
|
|
|
|
p[1] = g;
|
|
|
|
|
p[2] = b;
|
|
|
|
|
p[3] = a;
|
|
|
|
|
p += 4;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2001-08-07 17:49:09 +00:00
|
|
|
|
}
|
2002-03-12 20:38:49 +00:00
|
|
|
|
|
|
|
|
|
pixels += pixbuf->rowstride;
|
2001-04-18 18:09:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-05 18:51:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_get_option:
|
|
|
|
|
* @pixbuf: a #GdkPixbuf
|
|
|
|
|
* @key: a nul-terminated string.
|
|
|
|
|
*
|
|
|
|
|
* Looks up @key in the list of options that may have been attached to the
|
2007-07-02 14:47:45 +00:00
|
|
|
|
* @pixbuf when it was loaded, or that may have been attached by another
|
|
|
|
|
* function using gdk_pixbuf_set_option().
|
|
|
|
|
*
|
|
|
|
|
* For instance, the ANI loader provides "Title" and "Artist" options.
|
|
|
|
|
* The ICO, XBM, and XPM loaders provide "x_hot" and "y_hot" hot-spot
|
|
|
|
|
* options for cursor definitions. The PNG loader provides the tEXt ancillary
|
|
|
|
|
* chunk key/value pairs as options. Since 2.12, the TIFF and JPEG loaders
|
|
|
|
|
* return an "orientation" option string that corresponds to the embedded
|
|
|
|
|
* TIFF/Exif orientation tag (if present).
|
2001-10-05 18:51:47 +00:00
|
|
|
|
*
|
|
|
|
|
* Return value: the value associated with @key. This is a nul-terminated
|
|
|
|
|
* string that should not be freed or %NULL if @key was not found.
|
|
|
|
|
**/
|
|
|
|
|
G_CONST_RETURN gchar *
|
|
|
|
|
gdk_pixbuf_get_option (GdkPixbuf *pixbuf,
|
|
|
|
|
const gchar *key)
|
|
|
|
|
{
|
|
|
|
|
gchar **options;
|
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
|
|
|
|
|
g_return_val_if_fail (key != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
options = g_object_get_qdata (G_OBJECT (pixbuf),
|
|
|
|
|
g_quark_from_static_string ("gdk_pixbuf_options"));
|
|
|
|
|
if (options) {
|
|
|
|
|
for (i = 0; options[2*i]; i++) {
|
|
|
|
|
if (strcmp (options[2*i], key) == 0)
|
|
|
|
|
return options[2*i+1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2002-09-19 21:00:52 +00:00
|
|
|
|
* gdk_pixbuf_set_option:
|
2001-10-05 18:51:47 +00:00
|
|
|
|
* @pixbuf: a #GdkPixbuf
|
|
|
|
|
* @key: a nul-terminated string.
|
|
|
|
|
* @value: a nul-terminated string.
|
|
|
|
|
*
|
|
|
|
|
* Attaches a key/value pair as an option to a #GdkPixbuf. If %key already
|
|
|
|
|
* exists in the list of options attached to @pixbuf, the new value is
|
|
|
|
|
* ignored and %FALSE is returned.
|
|
|
|
|
*
|
|
|
|
|
* Return value: %TRUE on success.
|
2002-11-28 00:33:17 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.2
|
2001-10-05 18:51:47 +00:00
|
|
|
|
**/
|
|
|
|
|
gboolean
|
2002-09-19 21:00:52 +00:00
|
|
|
|
gdk_pixbuf_set_option (GdkPixbuf *pixbuf,
|
2001-10-05 18:51:47 +00:00
|
|
|
|
const gchar *key,
|
|
|
|
|
const gchar *value)
|
|
|
|
|
{
|
|
|
|
|
GQuark quark;
|
|
|
|
|
gchar **options;
|
|
|
|
|
gint n = 0;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE);
|
|
|
|
|
g_return_val_if_fail (key != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (value != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
quark = g_quark_from_static_string ("gdk_pixbuf_options");
|
|
|
|
|
|
|
|
|
|
options = g_object_get_qdata (G_OBJECT (pixbuf), quark);
|
|
|
|
|
|
|
|
|
|
if (options) {
|
|
|
|
|
for (n = 0; options[2*n]; n++) {
|
|
|
|
|
if (strcmp (options[2*n], key) == 0)
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_steal_qdata (G_OBJECT (pixbuf), quark);
|
|
|
|
|
options = g_renew (gchar *, options, 2*(n+1) + 1);
|
|
|
|
|
} else {
|
|
|
|
|
options = g_new (gchar *, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
options[2*n] = g_strdup (key);
|
|
|
|
|
options[2*n+1] = g_strdup (value);
|
|
|
|
|
options[2*n+2] = NULL;
|
|
|
|
|
|
|
|
|
|
g_object_set_qdata_full (G_OBJECT (pixbuf), quark,
|
|
|
|
|
options, (GDestroyNotify) g_strfreev);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-03 23:45:06 +00:00
|
|
|
|
static void
|
|
|
|
|
gdk_pixbuf_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GdkPixbuf *pixbuf = GDK_PIXBUF (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_COLORSPACE:
|
|
|
|
|
pixbuf->colorspace = g_value_get_enum (value);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_N_CHANNELS:
|
|
|
|
|
pixbuf->n_channels = g_value_get_int (value);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_HAS_ALPHA:
|
|
|
|
|
pixbuf->has_alpha = g_value_get_boolean (value);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_BITS_PER_SAMPLE:
|
|
|
|
|
pixbuf->bits_per_sample = g_value_get_int (value);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_WIDTH:
|
|
|
|
|
pixbuf->width = g_value_get_int (value);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_HEIGHT:
|
|
|
|
|
pixbuf->height = g_value_get_int (value);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_ROWSTRIDE:
|
|
|
|
|
pixbuf->rowstride = g_value_get_int (value);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_PIXELS:
|
|
|
|
|
pixbuf->pixels = (guchar *) g_value_get_pointer (value);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gdk_pixbuf_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GdkPixbuf *pixbuf = GDK_PIXBUF (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_COLORSPACE:
|
|
|
|
|
g_value_set_enum (value, gdk_pixbuf_get_colorspace (pixbuf));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_N_CHANNELS:
|
|
|
|
|
g_value_set_int (value, gdk_pixbuf_get_n_channels (pixbuf));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_HAS_ALPHA:
|
|
|
|
|
g_value_set_boolean (value, gdk_pixbuf_get_has_alpha (pixbuf));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_BITS_PER_SAMPLE:
|
|
|
|
|
g_value_set_int (value, gdk_pixbuf_get_bits_per_sample (pixbuf));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_WIDTH:
|
|
|
|
|
g_value_set_int (value, gdk_pixbuf_get_width (pixbuf));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_HEIGHT:
|
|
|
|
|
g_value_set_int (value, gdk_pixbuf_get_height (pixbuf));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_ROWSTRIDE:
|
|
|
|
|
g_value_set_int (value, gdk_pixbuf_get_rowstride (pixbuf));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_PIXELS:
|
|
|
|
|
g_value_set_pointer (value, gdk_pixbuf_get_pixels (pixbuf));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-14 19:37:00 +00:00
|
|
|
|
#define __GDK_PIXBUF_C__
|
|
|
|
|
#include "gdk-pixbuf-aliasdef.c"
|