Turn the pixbuf attributes into (construct-only, but always readable)

Sun Jan  4 00:44:57 2004  Matthias Clasen  <maclas@gmx.de>

	* gdk-pixbuf.c (gdk_pixbuf_class_init): Turn the pixbuf
	attributes into (construct-only, but always readable)
	properties.  (#130196)

	* gdk-pixbuf-data.c (gdk_pixbuf_new_from_data): Set properties
	in g_object_new().
This commit is contained in:
Matthias Clasen 2004-01-03 23:45:06 +00:00 committed by Matthias Clasen
parent 19c17861c6
commit ab74970131
3 changed files with 206 additions and 11 deletions

View File

@ -1,3 +1,12 @@
Sun Jan 4 00:44:57 2004 Matthias Clasen <maclas@gmx.de>
* gdk-pixbuf.c (gdk_pixbuf_class_init): Turn the pixbuf
attributes into (construct-only, but always readable)
properties. (#130196)
* gdk-pixbuf-data.c (gdk_pixbuf_new_from_data): Set properties
in g_object_new().
Mon Dec 22 01:35:36 2003 Matthias Clasen <maclas@gmx.de>
* Makefile.am (gdk-pixbuf.loaders): Fix building with

View File

@ -61,16 +61,17 @@ gdk_pixbuf_new_from_data (const guchar *data, GdkColorspace colorspace, gboolean
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
pixbuf = g_object_new (GDK_TYPE_PIXBUF, NULL);
pixbuf = g_object_new (GDK_TYPE_PIXBUF,
"colorspace", colorspace,
"n_channels", has_alpha ? 4 : 3,
"bits_per_sample", bits_per_sample,
"has_alpha", has_alpha ? TRUE : FALSE,
"width", width,
"height", height,
"rowstride", rowstride,
"pixels", data,
NULL);
pixbuf->colorspace = colorspace;
pixbuf->n_channels = has_alpha ? 4 : 3;
pixbuf->bits_per_sample = bits_per_sample;
pixbuf->has_alpha = has_alpha ? TRUE : FALSE;
pixbuf->width = width;
pixbuf->height = height;
pixbuf->rowstride = rowstride;
pixbuf->pixels = (guchar *) data;
pixbuf->destroy_fn = destroy_fn;
pixbuf->destroy_fn_data = destroy_fn_data;

View File

@ -30,10 +30,30 @@
#include "gdk-pixbuf.h"
#include "gdk-pixbuf-private.h"
static void gdk_pixbuf_class_init (GdkPixbufClass *klass);
static void gdk_pixbuf_finalize (GObject *object);
static void gdk_pixbuf_class_init (GdkPixbufClass *klass);
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);
enum
{
PROP_0,
PROP_COLORSPACE,
PROP_N_CHANNELS,
PROP_HAS_ALPHA,
PROP_BITS_PER_SAMPLE,
PROP_WIDTH,
PROP_HEIGHT,
PROP_ROWSTRIDE,
PROP_PIXELS
};
static gpointer parent_class;
@ -71,6 +91,91 @@ gdk_pixbuf_class_init (GdkPixbufClass *klass)
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gdk_pixbuf_finalize;
object_class->set_property = gdk_pixbuf_set_property;
object_class->get_property = gdk_pixbuf_get_property;
g_object_class_install_property (object_class,
PROP_N_CHANNELS,
g_param_spec_int ("n_channels",
_("Number of Channels"),
_("The number of samples per pixel"),
0,
G_MAXINT,
3,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_COLORSPACE,
g_param_spec_enum ("colorspace",
_("Colorspace"),
_("The colorspace in which the samples are interpreted"),
GDK_TYPE_COLORSPACE,
GDK_COLORSPACE_RGB,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_HAS_ALPHA,
g_param_spec_boolean ("has_alpha",
_("Has Alpha"),
_("Whether the pixbuf has an alpha channel"),
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_BITS_PER_SAMPLE,
g_param_spec_int ("bits_per_sample",
_("Bits per Sample"),
_("The number of bits per sample"),
1,
16,
8,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_WIDTH,
g_param_spec_int ("width",
_("Width"),
_("The number of columns of the pixbuf"),
1,
G_MAXINT,
1,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_HEIGHT,
g_param_spec_int ("height",
_("Height"),
_("The number of rows of the pixbuf"),
1,
G_MAXINT,
1,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_ROWSTRIDE,
g_param_spec_int ("rowstride",
_("Rowstride"),
_("The number of bytes between the start of a row and the start of the next row"),
1,
G_MAXINT,
1,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_PIXELS,
g_param_spec_pointer ("pixels",
_("Pixels"),
_("A pointer to the pixel data of the pixbuf"),
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
}
static void
@ -580,6 +685,86 @@ gdk_pixbuf_set_option (GdkPixbuf *pixbuf,
return TRUE;
}
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;
}
}
/* Include the marshallers */