~canonical-dx-team/ubuntu/maverick/gtk+2.0/menuproxy

« back to all changes in this revision

Viewing changes to gdk-pixbuf/gdk-pixbuf.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-05-04 12:24:25 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20070504122425-0m8midgzrp40y8w2
Tags: 2.10.12-1ubuntu1
* Sync with Debian
* New upstream version:
  Fixed bugs:
  - 379414 file chooser warnings when changing path in the entry
  - 418585 GtkFileChooserDefault sizing code is not DPI independent
  - 419568 Crash in search if start with special letter
  - 435062 build dies with icon cache validation
  - 379399 Segfault to call gtk_print_operation_run twice.
  - 387889 cups backend has problems when there are too many printers
  - 418531 invalid read to gtkicontheme.c gtk_icon_theme_lookup_icon...
  - 423916 crash in color scheme code
  - 424042 Segmentation fault while quickly pressing Alt+arrows
  - 415260 Protect against negative indices when setting values in G...
  - 419171 XGetVisualInfo() may not set nxvisuals
  - 128852 Gdk cursors don't look good on win32
  - 344657 Ctrl-H doesn't toggle "Show Hidden Files" setting
  - 345345 PrintOperation::paginate is not emitted for class handler
  - 347567 GtkPrintOperation::end-print is not emitted if it's cance...
  - 369112 gtk_ui_manager_add_ui should accept unnamed separator
  - 392015 Selected menu item invisible on Windows Vista
  - 399253 MS-Windows Theme Bottom Tab placement rendering glitches
  - 399425 gtk_input_dialog_fill_axes() adds child to gtkscrolledwin...
  - 403251 [patch] little memory leak in GtkPrintJob
  - 403267 [patch] memory leak in GtkPageSetupUnixDialog
  - 403470 MS-Windows Theme tab placement other than on top leaks a ...
  - 404506 Windows system fonts that have multi-byte font names cann...
  - 405089 Incorrect window placement for GtkEventBox private window
  - 405515 Minor leak in gtkfilesystemmodel.c
  - 405539 gdk_pixbuf_save() for PNG saver can return FALSE without ...
  - 415681 gdk_window_clear_area includes an extra line and column o...
  - 418219 GtkRecentChooser should apply filter before sorting and c...
  - 418403 Scroll to printer after selecting it from settings
  - 421985 _gtk_print_operation_platform_backend_launch_preview
  - 421990 gtk_print_job_get_surface
  - 421993 gtk_print_operation_init
  - 423064 Conditional jump or move depends on uninitialised value(s...
  - 423722 Fix printing header in gtk-demo
  - 424168 gtk_print_operation_run on async preview
  - 425655 Don't install gtk+-unix-print-2.0.pc on non-UNIX platforms
  - 425786 GDK segfaults if XineramaQueryScreens fails
  - 428665 Lpr Backend gets stuck in infinite loop during gtk_enumer...
  - 429902 GtkPrintOperation leaks cairo contextes
  - 431997 First delay of GdkPixbufAnimationIter is wrong
  - 433242 Inconsistent scroll arrow position calculations
  - 433972 Placing gtk.Expander inside a gtk.TextView() changes gtk....
  - 434261 _gtk_toolbar_elide_underscores incorrectly handles some s...
  - 383354 ctrl-L should make 'Location' entry disappear
  - 418673 gtk_recent_manager_add_item
  - 429732 gtk_accel_group_finalize accesses invalid memory
  - 435028 WM_CLIENT_LEADER is wrong on the leader_window
  - 431067 Background of the header window is not updated
  - 338843 add recent files support inside the ui manager
  - 148535 add drop shadow to menus, tooltips, etc. under Windows XP
* debian/control.in:
  - Conflicts on ubuntulooks (<= 0.9.11-1)
* debian/patches/15_default-fallback-icon-theme.patch:
  - patch from Debian, fallback on gnome icon theme

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
 
2
/* GdkPixbuf library - Basic memory management
 
3
 *
 
4
 * Copyright (C) 1999 The Free Software Foundation
 
5
 *
 
6
 * Authors: Mark Crichton <crichton@gimp.org>
 
7
 *          Miguel de Icaza <miguel@gnu.org>
 
8
 *          Federico Mena-Quintero <federico@gimp.org>
 
9
 *
 
10
 * This library is free software; you can redistribute it and/or
 
11
 * modify it under the terms of the GNU Lesser General Public
 
12
 * License as published by the Free Software Foundation; either
 
13
 * version 2 of the License, or (at your option) any later version.
 
14
 *
 
15
 * This library is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
18
 * Lesser General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU Lesser General Public
 
21
 * License along with this library; if not, write to the
 
22
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
23
 * Boston, MA 02111-1307, USA.
 
24
 */
 
25
 
 
26
#include <config.h>
 
27
#include <math.h>
 
28
#include <stdlib.h>
 
29
#include <string.h>
 
30
#define GDK_PIXBUF_COMPILATION
 
31
#include "gdk-pixbuf.h"
 
32
#include "gdk-pixbuf-private.h"
 
33
/* Include the marshallers */
 
34
#include <glib-object.h>
 
35
#include "gdk-pixbuf-marshal.c"
 
36
#include "gdk-pixbuf-alias.h"
 
37
 
 
38
static void gdk_pixbuf_finalize     (GObject        *object);
 
39
static void gdk_pixbuf_set_property (GObject        *object,
 
40
                                     guint           prop_id,
 
41
                                     const GValue   *value,
 
42
                                     GParamSpec     *pspec);
 
43
static void gdk_pixbuf_get_property (GObject        *object,
 
44
                                     guint           prop_id,
 
45
                                     GValue         *value,
 
46
                                     GParamSpec     *pspec);
 
47
 
 
48
 
 
49
enum 
 
50
{
 
51
  PROP_0,
 
52
  PROP_COLORSPACE,
 
53
  PROP_N_CHANNELS,
 
54
  PROP_HAS_ALPHA,
 
55
  PROP_BITS_PER_SAMPLE,
 
56
  PROP_WIDTH,
 
57
  PROP_HEIGHT,
 
58
  PROP_ROWSTRIDE,
 
59
  PROP_PIXELS
 
60
};
 
61
 
 
62
G_DEFINE_TYPE (GdkPixbuf, gdk_pixbuf, G_TYPE_OBJECT)
 
63
 
 
64
static void 
 
65
gdk_pixbuf_init (GdkPixbuf *pixbuf)
 
66
{
 
67
}
 
68
 
 
69
static void
 
70
gdk_pixbuf_class_init (GdkPixbufClass *klass)
 
71
{
 
72
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
73
        
 
74
        object_class->finalize = gdk_pixbuf_finalize;
 
75
        object_class->set_property = gdk_pixbuf_set_property;
 
76
        object_class->get_property = gdk_pixbuf_get_property;
 
77
 
 
78
#define PIXBUF_PARAM_FLAGS G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|\
 
79
                           G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
 
80
        /**
 
81
         * GdkPixbuf:n-channels:
 
82
         *
 
83
         * The number of samples per pixel. 
 
84
         * Currently, only 3 or 4 samples per pixel are supported.
 
85
         */
 
86
        g_object_class_install_property (object_class,
 
87
                                         PROP_N_CHANNELS,
 
88
                                         g_param_spec_int ("n-channels",
 
89
                                                           P_("Number of Channels"),
 
90
                                                           P_("The number of samples per pixel"),
 
91
                                                           0,
 
92
                                                           G_MAXINT,
 
93
                                                           3,
 
94
                                                           PIXBUF_PARAM_FLAGS));
 
95
 
 
96
        g_object_class_install_property (object_class,
 
97
                                         PROP_COLORSPACE,
 
98
                                         g_param_spec_enum ("colorspace",
 
99
                                                            P_("Colorspace"),
 
100
                                                            P_("The colorspace in which the samples are interpreted"),
 
101
                                                            GDK_TYPE_COLORSPACE,
 
102
                                                            GDK_COLORSPACE_RGB,
 
103
                                                            PIXBUF_PARAM_FLAGS));
 
104
 
 
105
        g_object_class_install_property (object_class,
 
106
                                         PROP_HAS_ALPHA,
 
107
                                         g_param_spec_boolean ("has-alpha",
 
108
                                                               P_("Has Alpha"),
 
109
                                                               P_("Whether the pixbuf has an alpha channel"),
 
110
                                                               FALSE,
 
111
                                                               PIXBUF_PARAM_FLAGS));
 
112
 
 
113
        /**
 
114
         * GdkPixbuf:bits-per-sample:
 
115
         *
 
116
         * The number of bits per sample. 
 
117
         * Currently only 8 bit per sample are supported.
 
118
         */
 
119
        g_object_class_install_property (object_class,
 
120
                                         PROP_BITS_PER_SAMPLE,
 
121
                                         g_param_spec_int ("bits-per-sample",
 
122
                                                           P_("Bits per Sample"),
 
123
                                                           P_("The number of bits per sample"),
 
124
                                                           1,
 
125
                                                           16,
 
126
                                                           8,
 
127
                                                           PIXBUF_PARAM_FLAGS));
 
128
 
 
129
        g_object_class_install_property (object_class,
 
130
                                         PROP_WIDTH,
 
131
                                         g_param_spec_int ("width",
 
132
                                                           P_("Width"),
 
133
                                                           P_("The number of columns of the pixbuf"),
 
134
                                                           1,
 
135
                                                           G_MAXINT,
 
136
                                                           1,
 
137
                                                           PIXBUF_PARAM_FLAGS));
 
138
 
 
139
        g_object_class_install_property (object_class,
 
140
                                         PROP_HEIGHT,
 
141
                                         g_param_spec_int ("height",
 
142
                                                           P_("Height"),
 
143
                                                           P_("The number of rows of the pixbuf"),
 
144
                                                           1,
 
145
                                                           G_MAXINT,
 
146
                                                           1,
 
147
                                                           PIXBUF_PARAM_FLAGS));
 
148
 
 
149
        /**
 
150
         * GdkPixbuf:rowstride:
 
151
         *
 
152
         * The number of bytes between the start of a row and 
 
153
         * the start of the next row. This number must (obviously)
 
154
         * be at least as large as the width of the pixbuf.
 
155
         */
 
156
        g_object_class_install_property (object_class,
 
157
                                         PROP_ROWSTRIDE,
 
158
                                         g_param_spec_int ("rowstride",
 
159
                                                           P_("Rowstride"),
 
160
                                                           P_("The number of bytes between the start of a row and the start of the next row"),
 
161
                                                           1,
 
162
                                                           G_MAXINT,
 
163
                                                           1,
 
164
                                                           PIXBUF_PARAM_FLAGS));
 
165
 
 
166
        g_object_class_install_property (object_class,
 
167
                                         PROP_PIXELS,
 
168
                                         g_param_spec_pointer ("pixels",
 
169
                                                               P_("Pixels"),
 
170
                                                               P_("A pointer to the pixel data of the pixbuf"),
 
171
                                                               PIXBUF_PARAM_FLAGS));
 
172
}
 
173
 
 
174
static void
 
175
gdk_pixbuf_finalize (GObject *object)
 
176
{
 
177
        GdkPixbuf *pixbuf = GDK_PIXBUF (object);
 
178
        
 
179
        if (pixbuf->destroy_fn)
 
180
                (* pixbuf->destroy_fn) (pixbuf->pixels, pixbuf->destroy_fn_data);
 
181
        
 
182
        G_OBJECT_CLASS (gdk_pixbuf_parent_class)->finalize (object);
 
183
}
 
184
 
 
185
 
 
186
/**
 
187
 * gdk_pixbuf_ref:
 
188
 * @pixbuf: A pixbuf.
 
189
 *
 
190
 * Adds a reference to a pixbuf. 
 
191
 *
 
192
 * Return value: The same as the @pixbuf argument.
 
193
 *
 
194
 * Deprecated: Use g_object_ref().
 
195
 **/
 
196
GdkPixbuf *
 
197
gdk_pixbuf_ref (GdkPixbuf *pixbuf)
 
198
{
 
199
        return (GdkPixbuf *) g_object_ref (pixbuf);
 
200
}
 
201
 
 
202
/**
 
203
 * gdk_pixbuf_unref:
 
204
 * @pixbuf: A pixbuf.
 
205
 *
 
206
 * Removes a reference from a pixbuf. 
 
207
 *
 
208
 * Deprecated: Use g_object_unref().
 
209
 **/
 
210
void
 
211
gdk_pixbuf_unref (GdkPixbuf *pixbuf)
 
212
{
 
213
        g_object_unref (pixbuf);
 
214
}
 
215
 
 
216
 
 
217
 
 
218
/* Used as the destroy notification function for gdk_pixbuf_new() */
 
219
static void
 
220
free_buffer (guchar *pixels, gpointer data)
 
221
{
 
222
        g_free (pixels);
 
223
}
 
224
 
 
225
/**
 
226
 * gdk_pixbuf_new:
 
227
 * @colorspace: Color space for image
 
228
 * @has_alpha: Whether the image should have transparency information
 
229
 * @bits_per_sample: Number of bits per color sample
 
230
 * @width: Width of image in pixels, must be > 0
 
231
 * @height: Height of image in pixels, must be > 0
 
232
 *
 
233
 * Creates a new #GdkPixbuf structure and allocates a buffer for it.  The 
 
234
 * buffer has an optimal rowstride.  Note that the buffer is not cleared;
 
235
 * you will have to fill it completely yourself.
 
236
 *
 
237
 * Return value: A newly-created #GdkPixbuf with a reference count of 1, or 
 
238
 * %NULL if not enough memory could be allocated for the image buffer.
 
239
 **/
 
240
GdkPixbuf *
 
241
gdk_pixbuf_new (GdkColorspace colorspace, 
 
242
                gboolean      has_alpha,
 
243
                int           bits_per_sample,
 
244
                int           width,
 
245
                int           height)
 
246
{
 
247
        guchar *buf;
 
248
        int channels;
 
249
        int rowstride;
 
250
        gsize bytes;
 
251
 
 
252
        g_return_val_if_fail (colorspace == GDK_COLORSPACE_RGB, NULL);
 
253
        g_return_val_if_fail (bits_per_sample == 8, NULL);
 
254
        g_return_val_if_fail (width > 0, NULL);
 
255
        g_return_val_if_fail (height > 0, NULL);
 
256
 
 
257
        channels = has_alpha ? 4 : 3;
 
258
        rowstride = width * channels;
 
259
        if (rowstride / channels != width || rowstride + 3 < 0) /* overflow */
 
260
                return NULL;
 
261
        
 
262
        /* Always align rows to 32-bit boundaries */
 
263
        rowstride = (rowstride + 3) & ~3;
 
264
 
 
265
        bytes = height * rowstride;
 
266
        if (bytes / rowstride !=  height) /* overflow */
 
267
                return NULL;
 
268
            
 
269
        buf = g_try_malloc (bytes);
 
270
        if (!buf)
 
271
                return NULL;
 
272
 
 
273
        return gdk_pixbuf_new_from_data (buf, colorspace, has_alpha, bits_per_sample,
 
274
                                         width, height, rowstride,
 
275
                                         free_buffer, NULL);
 
276
}
 
277
 
 
278
/**
 
279
 * gdk_pixbuf_copy:
 
280
 * @pixbuf: A pixbuf.
 
281
 * 
 
282
 * Creates a new #GdkPixbuf with a copy of the information in the specified
 
283
 * @pixbuf.
 
284
 * 
 
285
 * Return value: A newly-created pixbuf with a reference count of 1, or %NULL if
 
286
 * not enough memory could be allocated.
 
287
 **/
 
288
GdkPixbuf *
 
289
gdk_pixbuf_copy (const GdkPixbuf *pixbuf)
 
290
{
 
291
        guchar *buf;
 
292
        int size;
 
293
 
 
294
        g_return_val_if_fail (pixbuf != NULL, NULL);
 
295
 
 
296
        /* Calculate a semi-exact size.  Here we copy with full rowstrides;
 
297
         * maybe we should copy each row individually with the minimum
 
298
         * rowstride?
 
299
         */
 
300
 
 
301
        size = ((pixbuf->height - 1) * pixbuf->rowstride +
 
302
                pixbuf->width * ((pixbuf->n_channels * pixbuf->bits_per_sample + 7) / 8));
 
303
 
 
304
        buf = g_try_malloc (size * sizeof (guchar));
 
305
        if (!buf)
 
306
                return NULL;
 
307
 
 
308
        memcpy (buf, pixbuf->pixels, size);
 
309
 
 
310
        return gdk_pixbuf_new_from_data (buf,
 
311
                                         pixbuf->colorspace, pixbuf->has_alpha,
 
312
                                         pixbuf->bits_per_sample,
 
313
                                         pixbuf->width, pixbuf->height,
 
314
                                         pixbuf->rowstride,
 
315
                                         free_buffer,
 
316
                                         NULL);
 
317
}
 
318
 
 
319
/**
 
320
 * gdk_pixbuf_new_subpixbuf:
 
321
 * @src_pixbuf: a #GdkPixbuf
 
322
 * @src_x: X coord in @src_pixbuf
 
323
 * @src_y: Y coord in @src_pixbuf
 
324
 * @width: width of region in @src_pixbuf
 
325
 * @height: height of region in @src_pixbuf
 
326
 * 
 
327
 * Creates a new pixbuf which represents a sub-region of
 
328
 * @src_pixbuf. The new pixbuf shares its pixels with the
 
329
 * original pixbuf, so writing to one affects both.
 
330
 * The new pixbuf holds a reference to @src_pixbuf, so
 
331
 * @src_pixbuf will not be finalized until the new pixbuf
 
332
 * is finalized.
 
333
 * 
 
334
 * Return value: a new pixbuf 
 
335
 **/
 
336
GdkPixbuf*
 
337
gdk_pixbuf_new_subpixbuf (GdkPixbuf *src_pixbuf,
 
338
                          int        src_x,
 
339
                          int        src_y,
 
340
                          int        width,
 
341
                          int        height)
 
342
{
 
343
        guchar *pixels;
 
344
        GdkPixbuf *sub;
 
345
 
 
346
        g_return_val_if_fail (GDK_IS_PIXBUF (src_pixbuf), NULL);
 
347
        g_return_val_if_fail (src_x >= 0 && src_x + width <= src_pixbuf->width, NULL);
 
348
        g_return_val_if_fail (src_y >= 0 && src_y + height <= src_pixbuf->height, NULL);
 
349
 
 
350
        pixels = (gdk_pixbuf_get_pixels (src_pixbuf)
 
351
                  + src_y * src_pixbuf->rowstride
 
352
                  + src_x * src_pixbuf->n_channels);
 
353
 
 
354
        sub = gdk_pixbuf_new_from_data (pixels,
 
355
                                        src_pixbuf->colorspace,
 
356
                                        src_pixbuf->has_alpha,
 
357
                                        src_pixbuf->bits_per_sample,
 
358
                                        width, height,
 
359
                                        src_pixbuf->rowstride,
 
360
                                        NULL, NULL);
 
361
 
 
362
        /* Keep a reference to src_pixbuf */
 
363
        g_object_ref (src_pixbuf);
 
364
  
 
365
        g_object_set_qdata_full (G_OBJECT (sub),
 
366
                                 g_quark_from_static_string ("gdk-pixbuf-subpixbuf-src"),
 
367
                                 src_pixbuf,
 
368
                                 (GDestroyNotify) g_object_unref);
 
369
 
 
370
        return sub;
 
371
}
 
372
 
 
373
 
 
374
 
 
375
/* Accessors */
 
376
 
 
377
/**
 
378
 * gdk_pixbuf_get_colorspace:
 
379
 * @pixbuf: A pixbuf.
 
380
 *
 
381
 * Queries the color space of a pixbuf.
 
382
 *
 
383
 * Return value: Color space.
 
384
 **/
 
385
GdkColorspace
 
386
gdk_pixbuf_get_colorspace (const GdkPixbuf *pixbuf)
 
387
{
 
388
        g_return_val_if_fail (pixbuf != NULL, GDK_COLORSPACE_RGB);
 
389
 
 
390
        return pixbuf->colorspace;
 
391
}
 
392
 
 
393
/**
 
394
 * gdk_pixbuf_get_n_channels:
 
395
 * @pixbuf: A pixbuf.
 
396
 *
 
397
 * Queries the number of channels of a pixbuf.
 
398
 *
 
399
 * Return value: Number of channels.
 
400
 **/
 
401
int
 
402
gdk_pixbuf_get_n_channels (const GdkPixbuf *pixbuf)
 
403
{
 
404
        g_return_val_if_fail (pixbuf != NULL, -1);
 
405
 
 
406
        return pixbuf->n_channels;
 
407
}
 
408
 
 
409
/**
 
410
 * gdk_pixbuf_get_has_alpha:
 
411
 * @pixbuf: A pixbuf.
 
412
 *
 
413
 * Queries whether a pixbuf has an alpha channel (opacity information).
 
414
 *
 
415
 * Return value: %TRUE if it has an alpha channel, %FALSE otherwise.
 
416
 **/
 
417
gboolean
 
418
gdk_pixbuf_get_has_alpha (const GdkPixbuf *pixbuf)
 
419
{
 
420
        g_return_val_if_fail (pixbuf != NULL, FALSE);
 
421
 
 
422
        return pixbuf->has_alpha ? TRUE : FALSE;
 
423
}
 
424
 
 
425
/**
 
426
 * gdk_pixbuf_get_bits_per_sample:
 
427
 * @pixbuf: A pixbuf.
 
428
 *
 
429
 * Queries the number of bits per color sample in a pixbuf.
 
430
 *
 
431
 * Return value: Number of bits per color sample.
 
432
 **/
 
433
int
 
434
gdk_pixbuf_get_bits_per_sample (const GdkPixbuf *pixbuf)
 
435
{
 
436
        g_return_val_if_fail (pixbuf != NULL, -1);
 
437
 
 
438
        return pixbuf->bits_per_sample;
 
439
}
 
440
 
 
441
/**
 
442
 * gdk_pixbuf_get_pixels:
 
443
 * @pixbuf: A pixbuf.
 
444
 *
 
445
 * Queries a pointer to the pixel data of a pixbuf.
 
446
 *
 
447
 * Return value: A pointer to the pixbuf's pixel data.  Please see <xref linkend="image-data"/>
 
448
 * for information about how the pixel data is stored in
 
449
 * memory.
 
450
 **/
 
451
guchar *
 
452
gdk_pixbuf_get_pixels (const GdkPixbuf *pixbuf)
 
453
{
 
454
        g_return_val_if_fail (pixbuf != NULL, NULL);
 
455
 
 
456
        return pixbuf->pixels;
 
457
}
 
458
 
 
459
/**
 
460
 * gdk_pixbuf_get_width:
 
461
 * @pixbuf: A pixbuf.
 
462
 *
 
463
 * Queries the width of a pixbuf.
 
464
 *
 
465
 * Return value: Width in pixels.
 
466
 **/
 
467
int
 
468
gdk_pixbuf_get_width (const GdkPixbuf *pixbuf)
 
469
{
 
470
        g_return_val_if_fail (pixbuf != NULL, -1);
 
471
 
 
472
        return pixbuf->width;
 
473
}
 
474
 
 
475
/**
 
476
 * gdk_pixbuf_get_height:
 
477
 * @pixbuf: A pixbuf.
 
478
 *
 
479
 * Queries the height of a pixbuf.
 
480
 *
 
481
 * Return value: Height in pixels.
 
482
 **/
 
483
int
 
484
gdk_pixbuf_get_height (const GdkPixbuf *pixbuf)
 
485
{
 
486
        g_return_val_if_fail (pixbuf != NULL, -1);
 
487
 
 
488
        return pixbuf->height;
 
489
}
 
490
 
 
491
/**
 
492
 * gdk_pixbuf_get_rowstride:
 
493
 * @pixbuf: A pixbuf.
 
494
 *
 
495
 * Queries the rowstride of a pixbuf, which is the number of bytes between the start of a row
 
496
 * and the start of the next row.
 
497
 *
 
498
 * Return value: Distance between row starts.
 
499
 **/
 
500
int
 
501
gdk_pixbuf_get_rowstride (const GdkPixbuf *pixbuf)
 
502
{
 
503
        g_return_val_if_fail (pixbuf != NULL, -1);
 
504
 
 
505
        return pixbuf->rowstride;
 
506
}
 
507
 
 
508
 
 
509
 
 
510
/* General initialization hooks */
 
511
GDK_PIXBUF_VAR const guint gdk_pixbuf_major_version = GDK_PIXBUF_MAJOR;
 
512
GDK_PIXBUF_VAR const guint gdk_pixbuf_minor_version = GDK_PIXBUF_MINOR;
 
513
GDK_PIXBUF_VAR const guint gdk_pixbuf_micro_version = GDK_PIXBUF_MICRO;
 
514
 
 
515
GDK_PIXBUF_VAR const char *gdk_pixbuf_version = GDK_PIXBUF_VERSION;
 
516
 
 
517
/* Error quark */
 
518
GQuark
 
519
gdk_pixbuf_error_quark (void)
 
520
{
 
521
  return g_quark_from_static_string ("gdk-pixbuf-error-quark");
 
522
}
 
523
 
 
524
/**
 
525
 * gdk_pixbuf_fill:
 
526
 * @pixbuf: a #GdkPixbuf
 
527
 * @pixel: RGBA pixel to clear to
 
528
 *         (0xffffffff is opaque white, 0x00000000 transparent black)
 
529
 *
 
530
 * Clears a pixbuf to the given RGBA value, converting the RGBA value into
 
531
 * the pixbuf's pixel format. The alpha will be ignored if the pixbuf
 
532
 * doesn't have an alpha channel.
 
533
 * 
 
534
 **/
 
535
void
 
536
gdk_pixbuf_fill (GdkPixbuf *pixbuf,
 
537
                 guint32    pixel)
 
538
{
 
539
        guchar *pixels;
 
540
        guint r, g, b, a;
 
541
        guchar *p;
 
542
        guint w, h;
 
543
 
 
544
        g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
 
545
 
 
546
        if (pixbuf->width == 0 || pixbuf->height == 0)
 
547
                return;
 
548
 
 
549
        pixels = pixbuf->pixels;
 
550
 
 
551
        r = (pixel & 0xff000000) >> 24;
 
552
        g = (pixel & 0x00ff0000) >> 16;
 
553
        b = (pixel & 0x0000ff00) >> 8;
 
554
        a = (pixel & 0x000000ff);
 
555
 
 
556
        h = pixbuf->height;
 
557
        
 
558
        while (h--) {
 
559
                w = pixbuf->width;
 
560
                p = pixels;
 
561
 
 
562
                switch (pixbuf->n_channels) {
 
563
                case 3:
 
564
                        while (w--) {
 
565
                                p[0] = r;
 
566
                                p[1] = g;
 
567
                                p[2] = b;
 
568
                                p += 3;
 
569
                        }
 
570
                        break;
 
571
                case 4:
 
572
                        while (w--) {
 
573
                                p[0] = r;
 
574
                                p[1] = g;
 
575
                                p[2] = b;
 
576
                                p[3] = a;
 
577
                                p += 4;
 
578
                        }
 
579
                        break;
 
580
                default:
 
581
                        break;
 
582
                }
 
583
                
 
584
                pixels += pixbuf->rowstride;
 
585
        }
 
586
}
 
587
 
 
588
 
 
589
 
 
590
/**
 
591
 * gdk_pixbuf_get_option:
 
592
 * @pixbuf: a #GdkPixbuf
 
593
 * @key: a nul-terminated string.
 
594
 * 
 
595
 * Looks up @key in the list of options that may have been attached to the
 
596
 * @pixbuf when it was loaded. 
 
597
 * 
 
598
 * Return value: the value associated with @key. This is a nul-terminated 
 
599
 * string that should not be freed or %NULL if @key was not found.
 
600
 **/
 
601
G_CONST_RETURN gchar *
 
602
gdk_pixbuf_get_option (GdkPixbuf   *pixbuf,
 
603
                       const gchar *key)
 
604
{
 
605
        gchar **options;
 
606
        gint i;
 
607
 
 
608
        g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
 
609
        g_return_val_if_fail (key != NULL, NULL);
 
610
  
 
611
        options = g_object_get_qdata (G_OBJECT (pixbuf), 
 
612
                                      g_quark_from_static_string ("gdk_pixbuf_options"));
 
613
        if (options) {
 
614
                for (i = 0; options[2*i]; i++) {
 
615
                        if (strcmp (options[2*i], key) == 0)
 
616
                                return options[2*i+1];
 
617
                }
 
618
        }
 
619
        
 
620
        return NULL;
 
621
}
 
622
 
 
623
/**
 
624
 * gdk_pixbuf_set_option:
 
625
 * @pixbuf: a #GdkPixbuf
 
626
 * @key: a nul-terminated string.
 
627
 * @value: a nul-terminated string.
 
628
 * 
 
629
 * Attaches a key/value pair as an option to a #GdkPixbuf. If %key already
 
630
 * exists in the list of options attached to @pixbuf, the new value is 
 
631
 * ignored and %FALSE is returned.
 
632
 *
 
633
 * Return value: %TRUE on success.
 
634
 *
 
635
 * Since: 2.2
 
636
 **/
 
637
gboolean
 
638
gdk_pixbuf_set_option (GdkPixbuf   *pixbuf,
 
639
                       const gchar *key,
 
640
                       const gchar *value)
 
641
{
 
642
        GQuark  quark;
 
643
        gchar **options;
 
644
        gint n = 0;
 
645
 
 
646
        g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE);
 
647
        g_return_val_if_fail (key != NULL, FALSE);
 
648
        g_return_val_if_fail (value != NULL, FALSE);
 
649
 
 
650
        quark = g_quark_from_static_string ("gdk_pixbuf_options");
 
651
 
 
652
        options = g_object_get_qdata (G_OBJECT (pixbuf), quark);
 
653
 
 
654
        if (options) {
 
655
                for (n = 0; options[2*n]; n++) {
 
656
                        if (strcmp (options[2*n], key) == 0)
 
657
                                return FALSE;
 
658
                }
 
659
 
 
660
                g_object_steal_qdata (G_OBJECT (pixbuf), quark);
 
661
                options = g_renew (gchar *, options, 2*(n+1) + 1);
 
662
        } else {
 
663
                options = g_new (gchar *, 3);
 
664
        }
 
665
        
 
666
        options[2*n]   = g_strdup (key);
 
667
        options[2*n+1] = g_strdup (value);
 
668
        options[2*n+2] = NULL;
 
669
 
 
670
        g_object_set_qdata_full (G_OBJECT (pixbuf), quark,
 
671
                                 options, (GDestroyNotify) g_strfreev);
 
672
        
 
673
        return TRUE;
 
674
}
 
675
 
 
676
static void
 
677
gdk_pixbuf_set_property (GObject         *object,
 
678
                         guint            prop_id,
 
679
                         const GValue    *value,
 
680
                         GParamSpec      *pspec)
 
681
{
 
682
  GdkPixbuf *pixbuf = GDK_PIXBUF (object);
 
683
 
 
684
  switch (prop_id)
 
685
          {
 
686
          case PROP_COLORSPACE:
 
687
                  pixbuf->colorspace = g_value_get_enum (value);
 
688
                  break;
 
689
          case PROP_N_CHANNELS:
 
690
                  pixbuf->n_channels = g_value_get_int (value);
 
691
                  break;
 
692
          case PROP_HAS_ALPHA:
 
693
                  pixbuf->has_alpha = g_value_get_boolean (value);
 
694
                  break;
 
695
          case PROP_BITS_PER_SAMPLE:
 
696
                  pixbuf->bits_per_sample = g_value_get_int (value);
 
697
                  break;
 
698
          case PROP_WIDTH:
 
699
                  pixbuf->width = g_value_get_int (value);
 
700
                  break;
 
701
          case PROP_HEIGHT:
 
702
                  pixbuf->height = g_value_get_int (value);
 
703
                  break;
 
704
          case PROP_ROWSTRIDE:
 
705
                  pixbuf->rowstride = g_value_get_int (value);
 
706
                  break;
 
707
          case PROP_PIXELS:
 
708
                  pixbuf->pixels = (guchar *) g_value_get_pointer (value);
 
709
                  break;
 
710
          default:
 
711
                  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
712
                  break;
 
713
          }
 
714
}
 
715
 
 
716
static void
 
717
gdk_pixbuf_get_property (GObject         *object,
 
718
                         guint            prop_id,
 
719
                         GValue          *value,
 
720
                         GParamSpec      *pspec)
 
721
{
 
722
  GdkPixbuf *pixbuf = GDK_PIXBUF (object);
 
723
  
 
724
  switch (prop_id)
 
725
          {
 
726
          case PROP_COLORSPACE:
 
727
                  g_value_set_enum (value, gdk_pixbuf_get_colorspace (pixbuf));
 
728
                  break;
 
729
          case PROP_N_CHANNELS:
 
730
                  g_value_set_int (value, gdk_pixbuf_get_n_channels (pixbuf));
 
731
                  break;
 
732
          case PROP_HAS_ALPHA:
 
733
                  g_value_set_boolean (value, gdk_pixbuf_get_has_alpha (pixbuf));
 
734
                  break;
 
735
          case PROP_BITS_PER_SAMPLE:
 
736
                  g_value_set_int (value, gdk_pixbuf_get_bits_per_sample (pixbuf));
 
737
                  break;
 
738
          case PROP_WIDTH:
 
739
                  g_value_set_int (value, gdk_pixbuf_get_width (pixbuf));
 
740
                  break;
 
741
          case PROP_HEIGHT:
 
742
                  g_value_set_int (value, gdk_pixbuf_get_height (pixbuf));
 
743
                  break;
 
744
          case PROP_ROWSTRIDE:
 
745
                  g_value_set_int (value, gdk_pixbuf_get_rowstride (pixbuf));
 
746
                  break;
 
747
          case PROP_PIXELS:
 
748
                  g_value_set_pointer (value, gdk_pixbuf_get_pixels (pixbuf));
 
749
                  break;
 
750
          default:
 
751
                  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
752
                  break;
 
753
          }
 
754
}
 
755
 
 
756
#define __GDK_PIXBUF_C__
 
757
#include "gdk-pixbuf-aliasdef.c"