Bug Summary

File:_build/../cdk-pixbuf/cdk-pixbuf.c
Warning:line 471, column 38
Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name cdk-pixbuf.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/rootdir/_build -fcoverage-compilation-dir=/rootdir/_build -resource-dir /usr/lib/llvm-21/lib/clang/21 -I cdk-pixbuf/libcdk_pixbuf-2.0.so.0.4500.0.p -I cdk-pixbuf -I ../cdk-pixbuf -I . -I .. -I cdk-pixbuf/pixops -I ../cdk-pixbuf/pixops -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/libmount -I /usr/include/blkid -D _FILE_OFFSET_BITS=64 -D _POSIX_C_SOURCE=200809L -D _DEFAULT_SOURCE -D _XOPEN_SOURCE=700 -D HAVE_CONFIG_H=1 -D G_LOG_STRUCTURED=1 -D G_LOG_DOMAIN="CdkPixbuf" -D CDK_PIXBUF_COMPILATION -D CDK_PIXBUF_PREFIX="/usr/local" -D CDK_PIXBUF_LOCALEDIR="/usr/local/share/locale" -D CDK_PIXBUF_LIBDIR="/usr/local/lib/x86_64-linux-gnu" -D CDK_PIXBUF_BINARY_VERSION="2.10.0" -D CDK_PIXBUF_ENABLE_BACKEND -D PIXBUF_LIBDIR="/usr/local/lib/x86_64-linux-gnu/cdk-pixbuf-2.0/2.10.0/loaders" -D BUILT_MODULES_DIR="/rootdir/_build/cdk-pixbuf" -D INCLUDE_png -D INCLUDE_jpeg -internal-isystem /usr/lib/llvm-21/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/15/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-int-conversion -Wno-uninitialized -Wno-discarded-qualifiers -std=gnu99 -ferror-limit 19 -fvisibility=hidden -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-checker deadcode.DeadStores -analyzer-checker security.ArrayBound -analyzer-checker unix.cstring.NotNullTerminated -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2026-06-03-083413-8532-1 -x c ../cdk-pixbuf/cdk-pixbuf.c
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2/* CdkPixbuf 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, see <http://www.gnu.org/licenses/>.
22 */
23
24/**
25 * CdkPixbuf:
26 *
27 * A pixel buffer.
28 *
29 * `CdkPixbuf` contains information about an image's pixel data,
30 * its color space, bits per sample, width and height, and the
31 * rowstride (the number of bytes between the start of one row
32 * and the start of the next).
33 *
34 * ## Creating new `CdkPixbuf`
35 *
36 * The most basic way to create a pixbuf is to wrap an existing pixel
37 * buffer with a [class@CdkPixbuf.Pixbuf] instance. You can use the
38 * [`ctor@CdkPixbuf.Pixbuf.new_from_data`] function to do this.
39 *
40 * Every time you create a new `CdkPixbuf` instance for some data, you
41 * will need to specify the destroy notification function that will be
42 * called when the data buffer needs to be freed; this will happen when
43 * a `CdkPixbuf` is finalized by the reference counting functions. If
44 * you have a chunk of static data compiled into your application, you
45 * can pass in `NULL` as the destroy notification function so that the
46 * data will not be freed.
47 *
48 * The [`ctor@CdkPixbuf.Pixbuf.new`] constructor function can be used
49 * as a convenience to create a pixbuf with an empty buffer; this is
50 * equivalent to allocating a data buffer using `malloc()` and then
51 * wrapping it with `cdk_pixbuf_new_from_data()`. The `cdk_pixbuf_new()`
52 * function will compute an optimal rowstride so that rendering can be
53 * performed with an efficient algorithm.
54 *
55 * You can also copy an existing pixbuf with the [method@Pixbuf.copy]
56 * function. This is not the same as just acquiring a reference to
57 * the old pixbuf instance: the copy function will actually duplicate
58 * the pixel data in memory and create a new [class@Pixbuf] instance
59 * for it.
60 *
61 * ## Reference counting
62 *
63 * `CdkPixbuf` structures are reference counted. This means that an
64 * application can share a single pixbuf among many parts of the
65 * code. When a piece of the program needs to use a pixbuf, it should
66 * acquire a reference to it by calling `g_object_ref()`; when it no
67 * longer needs the pixbuf, it should release the reference it acquired
68 * by calling `g_object_unref()`. The resources associated with a
69 * `CdkPixbuf` will be freed when its reference count drops to zero.
70 * Newly-created `CdkPixbuf` instances start with a reference count
71 * of one.
72 *
73 * ## Image Data
74 *
75 * Image data in a pixbuf is stored in memory in an uncompressed,
76 * packed format. Rows in the image are stored top to bottom, and
77 * in each row pixels are stored from left to right.
78 *
79 * There may be padding at the end of a row.
80 *
81 * The "rowstride" value of a pixbuf, as returned by [`method@CdkPixbuf.Pixbuf.get_rowstride`],
82 * indicates the number of bytes between rows.
83 *
84 * **NOTE**: If you are copying raw pixbuf data with `memcpy()` note that the
85 * last row in the pixbuf may not be as wide as the full rowstride, but rather
86 * just as wide as the pixel data needs to be; that is: it is unsafe to do
87 * `memcpy (dest, pixels, rowstride * height)` to copy a whole pixbuf. Use
88 * [method@CdkPixbuf.Pixbuf.copy] instead, or compute the width in bytes of the
89 * last row as:
90 *
91 * ```c
92 * last_row = width * ((n_channels * bits_per_sample + 7) / 8);
93 * ```
94 *
95 * The same rule applies when iterating over each row of a `CdkPixbuf` pixels
96 * array.
97 *
98 * The following code illustrates a simple `put_pixel()`
99 * function for RGB pixbufs with 8 bits per channel with an alpha
100 * channel.
101 *
102 * ```c
103 * static void
104 * put_pixel (CdkPixbuf *pixbuf,
105 * int x,
106 * int y,
107 * guchar red,
108 * guchar green,
109 * guchar blue,
110 * guchar alpha)
111 * {
112 * int n_channels = cdk_pixbuf_get_n_channels (pixbuf);
113 *
114 * // Ensure that the pixbuf is valid
115 * g_assert (cdk_pixbuf_get_colorspace (pixbuf) == CDK_COLORSPACE_RGB);
116 * g_assert (cdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
117 * g_assert (cdk_pixbuf_get_has_alpha (pixbuf));
118 * g_assert (n_channels == 4);
119 *
120 * int width = cdk_pixbuf_get_width (pixbuf);
121 * int height = cdk_pixbuf_get_height (pixbuf);
122 *
123 * // Ensure that the coordinates are in a valid range
124 * g_assert (x >= 0 && x < width);
125 * g_assert (y >= 0 && y < height);
126 *
127 * int rowstride = cdk_pixbuf_get_rowstride (pixbuf);
128 *
129 * // The pixel buffer in the CdkPixbuf instance
130 * guchar *pixels = cdk_pixbuf_get_pixels (pixbuf);
131 *
132 * // The pixel we wish to modify
133 * guchar *p = pixels + y * rowstride + x * n_channels;
134 * p[0] = red;
135 * p[1] = green;
136 * p[2] = blue;
137 * p[3] = alpha;
138 * }
139 * ```
140 *
141 * ## Loading images
142 *
143 * The `CdkPixBuf` class provides a simple mechanism for loading
144 * an image from a file in synchronous and asynchronous fashion.
145 *
146 * For GUI applications, it is recommended to use the asynchronous
147 * stream API to avoid blocking the control flow of the application.
148 *
149 * Additionally, `CdkPixbuf` provides the [class@CdkPixbuf.PixbufLoader`]
150 * API for progressive image loading.
151 *
152 * ## Saving images
153 *
154 * The `CdkPixbuf` class provides methods for saving image data in
155 * a number of file formats. The formatted data can be written to a
156 * file or to a memory buffer. `CdkPixbuf` can also call a user-defined
157 * callback on the data, which allows to e.g. write the image
158 * to a socket or store it in a database.
159 */
160
161#include "config.h"
162
163#include <math.h>
164#include <stdlib.h>
165#include <string.h>
166
167#define CDK_PIXBUF_C_COMPILATION
168#include "cdk-pixbuf-private.h"
169#include "cdk-pixbuf-features.h"
170#include "cdk-pixbuf-enum-types.h"
171
172/* Include the marshallers */
173#include <glib-object.h>
174#include <gio/gio.h>
175#include "cdk-pixbuf-marshal.h"
176
177static void cdk_pixbuf_finalize (GObject *object);
178static void cdk_pixbuf_set_property (GObject *object,
179 guint prop_id,
180 const GValue *value,
181 GParamSpec *pspec);
182static void cdk_pixbuf_get_property (GObject *object,
183 guint prop_id,
184 GValue *value,
185 GParamSpec *pspec);
186static void cdk_pixbuf_constructed (GObject *object);
187
188
189enum
190{
191 PROP_0,
192 PROP_COLORSPACE,
193 PROP_N_CHANNELS,
194 PROP_HAS_ALPHA,
195 PROP_BITS_PER_SAMPLE,
196 PROP_WIDTH,
197 PROP_HEIGHT,
198 PROP_ROWSTRIDE,
199 PROP_PIXELS,
200 PROP_PIXEL_BYTES
201};
202
203static void cdk_pixbuf_icon_iface_init (GIconIface *iface);
204static void cdk_pixbuf_loadable_icon_iface_init (GLoadableIconIface *iface);
205
206G_DEFINE_TYPE_WITH_CODE (CdkPixbuf, cdk_pixbuf, G_TYPE_OBJECT,static void cdk_pixbuf_init (CdkPixbuf *self); static void cdk_pixbuf_class_init
(CdkPixbufClass *klass); static GType cdk_pixbuf_get_type_once
(void); static gpointer cdk_pixbuf_parent_class = ((void*)0)
; static gint CdkPixbuf_private_offset; static void cdk_pixbuf_class_intern_init
(gpointer klass) { cdk_pixbuf_parent_class = g_type_class_peek_parent
(klass); if (CdkPixbuf_private_offset != 0) g_type_class_adjust_private_offset
(klass, &CdkPixbuf_private_offset); cdk_pixbuf_class_init
((CdkPixbufClass*) klass); } __attribute__ ((__unused__)) static
inline gpointer cdk_pixbuf_get_instance_private (CdkPixbuf *
self) { return (((gpointer) ((guint8*) (self) + (glong) (CdkPixbuf_private_offset
)))); } GType cdk_pixbuf_get_type (void) { static GType static_g_define_type_id
= 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); (void
) (0 ? (gpointer) * (&static_g_define_type_id) : ((void*)
0)); (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(*(&static_g_define_type_id)) gapg_temp_newval; __typeof__
((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id
); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5)
; gapg_temp_newval; })) && g_once_init_enter_pointer (
&static_g_define_type_id)); })) ) { GType g_define_type_id
= cdk_pixbuf_get_type_once (); (__extension__ ({ _Static_assert
(sizeof *(&static_g_define_type_id) == sizeof (gpointer)
, "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id
) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer
((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id
)); })) ; } return static_g_define_type_id; } __attribute__ (
(__noinline__)) static GType cdk_pixbuf_get_type_once (void) {
GType g_define_type_id = g_type_register_static_simple (((GType
) ((20) << (2))), g_intern_static_string ("CdkPixbuf"),
sizeof (CdkPixbufClass), (GClassInitFunc)(void (*)(void)) cdk_pixbuf_class_intern_init
, sizeof (CdkPixbuf), (GInstanceInitFunc)(void (*)(void)) cdk_pixbuf_init
, (GTypeFlags) 0); { {{ const GInterfaceInfo g_implement_interface_info
= { (GInterfaceInitFunc)(void (*)(void)) cdk_pixbuf_icon_iface_init
, ((void*)0), ((void*)0) }; g_type_add_interface_static (g_define_type_id
, (g_icon_get_type ()), &g_implement_interface_info); } {
const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc
)(void (*)(void)) cdk_pixbuf_loadable_icon_iface_init, ((void
*)0), ((void*)0) }; g_type_add_interface_static (g_define_type_id
, (g_loadable_icon_get_type ()), &g_implement_interface_info
); };} } return g_define_type_id; }
207 G_IMPLEMENT_INTERFACE (G_TYPE_ICON, cdk_pixbuf_icon_iface_init)static void cdk_pixbuf_init (CdkPixbuf *self); static void cdk_pixbuf_class_init
(CdkPixbufClass *klass); static GType cdk_pixbuf_get_type_once
(void); static gpointer cdk_pixbuf_parent_class = ((void*)0)
; static gint CdkPixbuf_private_offset; static void cdk_pixbuf_class_intern_init
(gpointer klass) { cdk_pixbuf_parent_class = g_type_class_peek_parent
(klass); if (CdkPixbuf_private_offset != 0) g_type_class_adjust_private_offset
(klass, &CdkPixbuf_private_offset); cdk_pixbuf_class_init
((CdkPixbufClass*) klass); } __attribute__ ((__unused__)) static
inline gpointer cdk_pixbuf_get_instance_private (CdkPixbuf *
self) { return (((gpointer) ((guint8*) (self) + (glong) (CdkPixbuf_private_offset
)))); } GType cdk_pixbuf_get_type (void) { static GType static_g_define_type_id
= 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); (void
) (0 ? (gpointer) * (&static_g_define_type_id) : ((void*)
0)); (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(*(&static_g_define_type_id)) gapg_temp_newval; __typeof__
((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id
); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5)
; gapg_temp_newval; })) && g_once_init_enter_pointer (
&static_g_define_type_id)); })) ) { GType g_define_type_id
= cdk_pixbuf_get_type_once (); (__extension__ ({ _Static_assert
(sizeof *(&static_g_define_type_id) == sizeof (gpointer)
, "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id
) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer
((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id
)); })) ; } return static_g_define_type_id; } __attribute__ (
(__noinline__)) static GType cdk_pixbuf_get_type_once (void) {
GType g_define_type_id = g_type_register_static_simple (((GType
) ((20) << (2))), g_intern_static_string ("CdkPixbuf"),
sizeof (CdkPixbufClass), (GClassInitFunc)(void (*)(void)) cdk_pixbuf_class_intern_init
, sizeof (CdkPixbuf), (GInstanceInitFunc)(void (*)(void)) cdk_pixbuf_init
, (GTypeFlags) 0); { {{ const GInterfaceInfo g_implement_interface_info
= { (GInterfaceInitFunc)(void (*)(void)) cdk_pixbuf_icon_iface_init
, ((void*)0), ((void*)0) }; g_type_add_interface_static (g_define_type_id
, (g_icon_get_type ()), &g_implement_interface_info); } {
const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc
)(void (*)(void)) cdk_pixbuf_loadable_icon_iface_init, ((void
*)0), ((void*)0) }; g_type_add_interface_static (g_define_type_id
, (g_loadable_icon_get_type ()), &g_implement_interface_info
); };} } return g_define_type_id; }
208 G_IMPLEMENT_INTERFACE (G_TYPE_LOADABLE_ICON, cdk_pixbuf_loadable_icon_iface_init))static void cdk_pixbuf_init (CdkPixbuf *self); static void cdk_pixbuf_class_init
(CdkPixbufClass *klass); static GType cdk_pixbuf_get_type_once
(void); static gpointer cdk_pixbuf_parent_class = ((void*)0)
; static gint CdkPixbuf_private_offset; static void cdk_pixbuf_class_intern_init
(gpointer klass) { cdk_pixbuf_parent_class = g_type_class_peek_parent
(klass); if (CdkPixbuf_private_offset != 0) g_type_class_adjust_private_offset
(klass, &CdkPixbuf_private_offset); cdk_pixbuf_class_init
((CdkPixbufClass*) klass); } __attribute__ ((__unused__)) static
inline gpointer cdk_pixbuf_get_instance_private (CdkPixbuf *
self) { return (((gpointer) ((guint8*) (self) + (glong) (CdkPixbuf_private_offset
)))); } GType cdk_pixbuf_get_type (void) { static GType static_g_define_type_id
= 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); (void
) (0 ? (gpointer) * (&static_g_define_type_id) : ((void*)
0)); (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(*(&static_g_define_type_id)) gapg_temp_newval; __typeof__
((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id
); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5)
; gapg_temp_newval; })) && g_once_init_enter_pointer (
&static_g_define_type_id)); })) ) { GType g_define_type_id
= cdk_pixbuf_get_type_once (); (__extension__ ({ _Static_assert
(sizeof *(&static_g_define_type_id) == sizeof (gpointer)
, "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id
) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer
((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id
)); })) ; } return static_g_define_type_id; } __attribute__ (
(__noinline__)) static GType cdk_pixbuf_get_type_once (void) {
GType g_define_type_id = g_type_register_static_simple (((GType
) ((20) << (2))), g_intern_static_string ("CdkPixbuf"),
sizeof (CdkPixbufClass), (GClassInitFunc)(void (*)(void)) cdk_pixbuf_class_intern_init
, sizeof (CdkPixbuf), (GInstanceInitFunc)(void (*)(void)) cdk_pixbuf_init
, (GTypeFlags) 0); { {{ const GInterfaceInfo g_implement_interface_info
= { (GInterfaceInitFunc)(void (*)(void)) cdk_pixbuf_icon_iface_init
, ((void*)0), ((void*)0) }; g_type_add_interface_static (g_define_type_id
, (g_icon_get_type ()), &g_implement_interface_info); } {
const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc
)(void (*)(void)) cdk_pixbuf_loadable_icon_iface_init, ((void
*)0), ((void*)0) }; g_type_add_interface_static (g_define_type_id
, (g_loadable_icon_get_type ()), &g_implement_interface_info
); };} } return g_define_type_id; }
209
210static void
211cdk_pixbuf_init (CdkPixbuf *pixbuf)
212{
213 pixbuf->colorspace = CDK_COLORSPACE_RGB;
214 pixbuf->n_channels = 3;
215 pixbuf->bits_per_sample = 8;
216 pixbuf->has_alpha = FALSE(0);
217 pixbuf->storage = STORAGE_UNINITIALIZED;
218}
219
220static void
221cdk_pixbuf_class_init (CdkPixbufClass *klass)
222{
223 GObjectClass *object_class = G_OBJECT_CLASS (klass)((((GObjectClass*) (void *) ((klass)))));
224
225 _cdk_pixbuf_init_gettext ();
226
227 object_class->finalize = cdk_pixbuf_finalize;
228 object_class->set_property = cdk_pixbuf_set_property;
229 object_class->get_property = cdk_pixbuf_get_property;
230 object_class->constructed = cdk_pixbuf_constructed;
231
232#define PIXBUF_PARAM_FLAGS(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY
| G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB
)
(G_PARAM_READWRITE | \
233 G_PARAM_CONSTRUCT_ONLY | \
234 G_PARAM_EXPLICIT_NOTIFY | \
235 G_PARAM_STATIC_NAME | \
236 G_PARAM_STATIC_NICK | \
237 G_PARAM_STATIC_BLURB)
238 /**
239 * CdkPixbuf:n-channels:
240 *
241 * The number of samples per pixel.
242 *
243 * Currently, only 3 or 4 samples per pixel are supported.
244 */
245 g_object_class_install_property (object_class,
246 PROP_N_CHANNELS,
247 g_param_spec_int ("n-channels",
248 _("Number of Channels")((char *) g_dgettext ("cdk-pixbuf", "Number of Channels")),
249 _("The number of samples per pixel")((char *) g_dgettext ("cdk-pixbuf", "The number of samples per pixel"
))
,
250 0,
251 G_MAXINT2147483647,
252 3,
253 PIXBUF_PARAM_FLAGS(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY
| G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB
)
));
254 /**
255 * CdkPixbuf:colorspace:
256 *
257 * The color space of the pixbuf.
258 *
259 * Currently, only `CDK_COLORSPACE_RGB` is supported.
260 */
261 g_object_class_install_property (object_class,
262 PROP_COLORSPACE,
263 g_param_spec_enum ("colorspace",
264 _("Colorspace")((char *) g_dgettext ("cdk-pixbuf", "Colorspace")),
265 _("The colorspace in which the samples are interpreted")((char *) g_dgettext ("cdk-pixbuf", "The colorspace in which the samples are interpreted"
))
,
266 CDK_TYPE_COLORSPACE(cdk_colorspace_get_type ()),
267 CDK_COLORSPACE_RGB,
268 PIXBUF_PARAM_FLAGS(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY
| G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB
)
));
269 /**
270 * CdkPixbuf:has-alpha:
271 *
272 * Whether the pixbuf has an alpha channel.
273 */
274 g_object_class_install_property (object_class,
275 PROP_HAS_ALPHA,
276 g_param_spec_boolean ("has-alpha",
277 _("Has Alpha")((char *) g_dgettext ("cdk-pixbuf", "Has Alpha")),
278 _("Whether the pixbuf has an alpha channel")((char *) g_dgettext ("cdk-pixbuf", "Whether the pixbuf has an alpha channel"
))
,
279 FALSE(0),
280 PIXBUF_PARAM_FLAGS(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY
| G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB
)
));
281 /**
282 * CdkPixbuf:bits-per-sample:
283 *
284 * The number of bits per sample.
285 *
286 * Currently only 8 bit per sample are supported.
287 */
288 g_object_class_install_property (object_class,
289 PROP_BITS_PER_SAMPLE,
290 g_param_spec_int ("bits-per-sample",
291 _("Bits per Sample")((char *) g_dgettext ("cdk-pixbuf", "Bits per Sample")),
292 _("The number of bits per sample")((char *) g_dgettext ("cdk-pixbuf", "The number of bits per sample"
))
,
293 1,
294 16,
295 8,
296 PIXBUF_PARAM_FLAGS(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY
| G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB
)
));
297 /**
298 * CdkPixbuf:width:
299 *
300 * The number of columns of the pixbuf.
301 */
302 g_object_class_install_property (object_class,
303 PROP_WIDTH,
304 g_param_spec_int ("width",
305 _("Width")((char *) g_dgettext ("cdk-pixbuf", "Width")),
306 _("The number of columns of the pixbuf")((char *) g_dgettext ("cdk-pixbuf", "The number of columns of the pixbuf"
))
,
307 1,
308 G_MAXINT2147483647,
309 1,
310 PIXBUF_PARAM_FLAGS(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY
| G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB
)
));
311 /**
312 * CdkPixbuf:height:
313 *
314 * The number of rows of the pixbuf.
315 */
316 g_object_class_install_property (object_class,
317 PROP_HEIGHT,
318 g_param_spec_int ("height",
319 _("Height")((char *) g_dgettext ("cdk-pixbuf", "Height")),
320 _("The number of rows of the pixbuf")((char *) g_dgettext ("cdk-pixbuf", "The number of rows of the pixbuf"
))
,
321 1,
322 G_MAXINT2147483647,
323 1,
324 PIXBUF_PARAM_FLAGS(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY
| G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB
)
));
325 /**
326 * CdkPixbuf:rowstride:
327 *
328 * The number of bytes between the start of a row and
329 * the start of the next row.
330 *
331 * This number must (obviously) be at least as large as the
332 * width of the pixbuf.
333 */
334 g_object_class_install_property (object_class,
335 PROP_ROWSTRIDE,
336 g_param_spec_int ("rowstride",
337 _("Rowstride")((char *) g_dgettext ("cdk-pixbuf", "Rowstride")),
338 _("The number of bytes between the start of a row and the start of the next row")((char *) g_dgettext ("cdk-pixbuf", "The number of bytes between the start of a row and the start of the next row"
))
,
339 1,
340 G_MAXINT2147483647,
341 1,
342 PIXBUF_PARAM_FLAGS(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY
| G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB
)
));
343 /**
344 * CdkPixbuf:pixels:
345 *
346 * A pointer to the pixel data of the pixbuf.
347 */
348 g_object_class_install_property (object_class,
349 PROP_PIXELS,
350 g_param_spec_pointer ("pixels",
351 _("Pixels")((char *) g_dgettext ("cdk-pixbuf", "Pixels")),
352 _("A pointer to the pixel data of the pixbuf")((char *) g_dgettext ("cdk-pixbuf", "A pointer to the pixel data of the pixbuf"
))
,
353 PIXBUF_PARAM_FLAGS(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY
| G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB
)
));
354 /**
355 * CdkPixbuf::pixel-bytes:
356 *
357 * If set, this pixbuf was created from read-only #GBytes.
358 *
359 * Replaces CdkPixbuf::pixels.
360 *
361 * Since: 2.32
362 */
363 g_object_class_install_property (object_class,
364 PROP_PIXEL_BYTES,
365 g_param_spec_boxed ("pixel-bytes",
366 _("Pixel Bytes")((char *) g_dgettext ("cdk-pixbuf", "Pixel Bytes")),
367 _("Readonly pixel data")((char *) g_dgettext ("cdk-pixbuf", "Readonly pixel data")),
368 G_TYPE_BYTES(g_bytes_get_type ()),
369 PIXBUF_PARAM_FLAGS(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY
| G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB
)
));
370}
371
372static void
373free_pixels (CdkPixbuf *pixbuf)
374{
375 g_assert (pixbuf->storage == STORAGE_PIXELS)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_49
= 0; if (pixbuf->storage == STORAGE_PIXELS) _g_boolean_var_49
= 1; _g_boolean_var_49; }), 1)) ; else g_assertion_message_expr
("CdkPixbuf", "../cdk-pixbuf/cdk-pixbuf.c", 375, ((const char
*) (__func__)), "pixbuf->storage == STORAGE_PIXELS"); } while
(0)
;
376
377 if (pixbuf->s.pixels.pixels && pixbuf->s.pixels.destroy_fn) {
378 (* pixbuf->s.pixels.destroy_fn) (pixbuf->s.pixels.pixels, pixbuf->s.pixels.destroy_fn_data);
379 }
380
381 pixbuf->s.pixels.pixels = NULL((void*)0);
382}
383
384static void
385free_bytes (CdkPixbuf *pixbuf)
386{
387 g_assert (pixbuf->storage == STORAGE_BYTES)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_50
= 0; if (pixbuf->storage == STORAGE_BYTES) _g_boolean_var_50
= 1; _g_boolean_var_50; }), 1)) ; else g_assertion_message_expr
("CdkPixbuf", "../cdk-pixbuf/cdk-pixbuf.c", 387, ((const char
*) (__func__)), "pixbuf->storage == STORAGE_BYTES"); } while
(0)
;
388
389 g_clear_pointer (&pixbuf->s.bytes.bytes, g_bytes_unref)do { _Static_assert (sizeof *(&pixbuf->s.bytes.bytes) ==
sizeof (gpointer), "Expression evaluates to false"); __typeof__
((&pixbuf->s.bytes.bytes)) _pp = (&pixbuf->s.bytes
.bytes); __typeof__ (*(&pixbuf->s.bytes.bytes)) _ptr =
*_pp; *_pp = ((void*)0); if (_ptr) (g_bytes_unref) (_ptr); }
while (0)
;
390}
391
392static void
393cdk_pixbuf_finalize (GObject *object)
394{
395 CdkPixbuf *pixbuf = CDK_PIXBUF (object)((((CdkPixbuf*) (void *) ((object)))));
396
397 switch (pixbuf->storage) {
398 case STORAGE_PIXELS:
399 free_pixels (pixbuf);
400 break;
401
402 case STORAGE_BYTES:
403 free_bytes (pixbuf);
404 break;
405
406 default:
407 g_assert_not_reached ()do { g_assertion_message_expr ("CdkPixbuf", "../cdk-pixbuf/cdk-pixbuf.c"
, 407, ((const char*) (__func__)), ((void*)0)); } while (0)
;
408 }
409
410 G_OBJECT_CLASS (cdk_pixbuf_parent_class)((((GObjectClass*) (void *) ((cdk_pixbuf_parent_class)))))->finalize (object);
411}
412
413
414/**
415 * cdk_pixbuf_ref: (skip)
416 * @pixbuf: A pixbuf.
417 *
418 * Adds a reference to a pixbuf.
419 *
420 * Return value: The same as the @pixbuf argument.
421 *
422 * Deprecated: 2.0: Use g_object_ref().
423 **/
424CdkPixbuf *
425cdk_pixbuf_ref (CdkPixbuf *pixbuf)
426{
427 return (CdkPixbuf *) g_object_ref (pixbuf)((__typeof__ (pixbuf)) (g_object_ref) (pixbuf));
428}
429
430/**
431 * cdk_pixbuf_unref: (skip)
432 * @pixbuf: A pixbuf.
433 *
434 * Removes a reference from a pixbuf.
435 *
436 * Deprecated: 2.0: Use g_object_unref().
437 **/
438void
439cdk_pixbuf_unref (CdkPixbuf *pixbuf)
440{
441 g_object_unref (pixbuf);
442}
443
444static GBytes *
445cdk_pixbuf_make_bytes (CdkPixbuf *pixbuf,
446 GError **error)
447{
448 gchar *buffer;
449 gsize size;
450
451 if (!cdk_pixbuf_save_to_buffer (pixbuf, &buffer, &size, "png", error, NULL((void*)0)))
452 return NULL((void*)0);
453
454 return g_bytes_new_take (buffer, size);
455}
456
457static GVariant *
458cdk_pixbuf_serialize (GIcon *icon)
459{
460 GError *error = NULL((void*)0);
461 GVariant *result;
462 GBytes *bytes;
463
464 bytes = cdk_pixbuf_make_bytes (CDK_PIXBUF (icon)((((CdkPixbuf*) (void *) ((icon))))), &error);
465 if (!bytes)
466 {
467 g_critical ("Unable to serialise CdkPixbuf to png (via g_icon_serialize()): %s", error->message);
468 g_error_free (error);
469 return NULL((void*)0);
470 }
471 result = g_variant_new_from_bytes (G_VARIANT_TYPE_BYTESTRING((const GVariantType *) "ay"), bytes, TRUE(!(0)));
Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption
472 g_bytes_unref (bytes);
473
474 return g_variant_new ("(sv)", "bytes", result);
475}
476
477static GInputStream *
478cdk_pixbuf_load (GLoadableIcon *icon,
479 int size,
480 char **type,
481 GCancellable *cancellable,
482 GError **error)
483{
484 GInputStream *stream;
485 GBytes *bytes;
486
487 bytes = cdk_pixbuf_make_bytes (CDK_PIXBUF (icon)((((CdkPixbuf*) (void *) ((icon))))), error);
488 if (!bytes)
489 return NULL((void*)0);
490
491 stream = g_memory_input_stream_new_from_bytes (bytes);
492 g_bytes_unref (bytes);
493
494 if (type)
495 *type = g_strdup ("image/png")g_strdup_inline ("image/png");
496
497 return stream;
498}
499
500static void
501cdk_pixbuf_load_async (GLoadableIcon *icon,
502 int size,
503 GCancellable *cancellable,
504 GAsyncReadyCallback callback,
505 gpointer user_data)
506{
507 GTask *task;
508
509 task = g_task_new (icon, cancellable, callback, user_data);
510 g_task_return_pointer (task, icon, NULL((void*)0));
511 g_object_unref (task);
512}
513
514static GInputStream *
515cdk_pixbuf_load_finish (GLoadableIcon *icon,
516 GAsyncResult *res,
517 char **type,
518 GError **error)
519{
520 g_return_val_if_fail (g_task_is_valid (res, icon), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_51
= 0; if (g_task_is_valid (res, icon)) _g_boolean_var_51 = 1;
_g_boolean_var_51; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "g_task_is_valid (res, icon)"
); return (((void*)0)); } } while (0)
;
521
522 if (!g_task_propagate_pointer (G_TASK (res)((((GTask*) (void *) ((res))))), error))
523 return NULL((void*)0);
524
525 return cdk_pixbuf_load (icon, 0, type, NULL((void*)0), error);
526}
527
528static void
529cdk_pixbuf_loadable_icon_iface_init (GLoadableIconIface *iface)
530{
531 iface->load = cdk_pixbuf_load;
532
533 /* In theory encoding a png could be time-consuming but we're talking
534 * about icons here, so assume it's probably going to be OK and handle
535 * the async variant of the call in-thread instead of having the
536 * default implementation dispatch it to a worker.
537 */
538 iface->load_async = cdk_pixbuf_load_async;
539 iface->load_finish = cdk_pixbuf_load_finish;
540}
541
542static void
543cdk_pixbuf_icon_iface_init (GIconIface *iface)
544{
545 iface->hash = (guint (*) (GIcon *)) g_direct_hash;
546 iface->equal = (gboolean (*) (GIcon *, GIcon *)) g_direct_equal;
547 iface->serialize = cdk_pixbuf_serialize;
548}
549
550/* Used as the destroy notification function for cdk_pixbuf_new() */
551static void
552free_buffer (guchar *pixels, gpointer data)
553{
554 g_free (pixels);
555}
556
557/**
558 * cdk_pixbuf_calculate_rowstride:
559 * @colorspace: Color space for image
560 * @has_alpha: Whether the image should have transparency information
561 * @bits_per_sample: Number of bits per color sample
562 * @width: Width of image in pixels, must be > 0
563 * @height: Height of image in pixels, must be > 0
564 *
565 * Calculates the rowstride that an image created with those values would
566 * have.
567 *
568 * This function is useful for front-ends and backends that want to check
569 * image values without needing to create a `CdkPixbuf`.
570 *
571 * Return value: the rowstride for the given values, or -1 in case of error.
572 *
573 * Since: 2.36.8
574 */
575gint
576cdk_pixbuf_calculate_rowstride (CdkColorspace colorspace,
577 gboolean has_alpha,
578 int bits_per_sample,
579 int width,
580 int height)
581{
582 unsigned int channels;
583
584 g_return_val_if_fail (colorspace == CDK_COLORSPACE_RGB, -1)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_52
= 0; if (colorspace == CDK_COLORSPACE_RGB) _g_boolean_var_52
= 1; _g_boolean_var_52; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "colorspace == CDK_COLORSPACE_RGB"
); return (-1); } } while (0)
;
585 g_return_val_if_fail (bits_per_sample == 8, -1)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_53
= 0; if (bits_per_sample == 8) _g_boolean_var_53 = 1; _g_boolean_var_53
; }), 1))) { } else { g_return_if_fail_warning ("CdkPixbuf", (
(const char*) (__func__)), "bits_per_sample == 8"); return (-
1); } } while (0)
;
586 g_return_val_if_fail (width > 0, -1)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_54
= 0; if (width > 0) _g_boolean_var_54 = 1; _g_boolean_var_54
; }), 1))) { } else { g_return_if_fail_warning ("CdkPixbuf", (
(const char*) (__func__)), "width > 0"); return (-1); } } while
(0)
;
587 g_return_val_if_fail (height > 0, -1)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_55
= 0; if (height > 0) _g_boolean_var_55 = 1; _g_boolean_var_55
; }), 1))) { } else { g_return_if_fail_warning ("CdkPixbuf", (
(const char*) (__func__)), "height > 0"); return (-1); } }
while (0)
;
588
589 channels = has_alpha ? 4 : 3;
590
591 /* Overflow? */
592 if (width > (G_MAXINT2147483647 - 3) / channels)
593 return -1;
594
595 /* Always align rows to 32-bit boundaries */
596 return (width * channels + 3) & ~3;
597}
598
599/**
600 * cdk_pixbuf_new:
601 * @colorspace: Color space for image
602 * @has_alpha: Whether the image should have transparency information
603 * @bits_per_sample: Number of bits per color sample
604 * @width: Width of image in pixels, must be > 0
605 * @height: Height of image in pixels, must be > 0
606 *
607 * Creates a new `CdkPixbuf` structure and allocates a buffer for it.
608 *
609 * If the allocation of the buffer failed, this function will return `NULL`.
610 *
611 * The buffer has an optimal rowstride. Note that the buffer is not cleared;
612 * you will have to fill it completely yourself.
613 *
614 * Return value: (transfer full) (nullable): A newly-created pixel buffer
615 **/
616CdkPixbuf *
617cdk_pixbuf_new (CdkColorspace colorspace,
618 gboolean has_alpha,
619 int bits_per_sample,
620 int width,
621 int height)
622{
623 guchar *buf;
624 int rowstride;
625
626 rowstride = cdk_pixbuf_calculate_rowstride (colorspace,
627 has_alpha,
628 bits_per_sample,
629 width,
630 height);
631 if (rowstride <= 0)
632 return NULL((void*)0);
633
634 buf = g_try_malloc0_n (height, rowstride);
635 if (!buf)
636 return NULL((void*)0);
637
638 return cdk_pixbuf_new_from_data (buf, colorspace, has_alpha, bits_per_sample,
639 width, height, rowstride,
640 free_buffer, NULL((void*)0));
641}
642
643/**
644 * cdk_pixbuf_copy:
645 * @pixbuf: A pixbuf.
646 *
647 * Creates a new `CdkPixbuf` with a copy of the information in the specified
648 * `pixbuf`.
649 *
650 * Note that this does not copy the options set on the original `CdkPixbuf`,
651 * use cdk_pixbuf_copy_options() for this.
652 *
653 * Return value: (nullable) (transfer full): A newly-created pixbuf
654 **/
655CdkPixbuf *
656cdk_pixbuf_copy (const CdkPixbuf *pixbuf)
657{
658 guchar *buf;
659 int size;
660
661 g_return_val_if_fail (CDK_IS_PIXBUF (pixbuf), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_56
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_56
= 1; _g_boolean_var_56; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (pixbuf)"
); return (((void*)0)); } } while (0)
;
662
663 /* Calculate a semi-exact size. Here we copy with full rowstrides;
664 * maybe we should copy each row individually with the minimum
665 * rowstride?
666 */
667
668 size = cdk_pixbuf_get_byte_length (pixbuf);
669
670 buf = g_try_malloc (size);
671 if (!buf)
672 return NULL((void*)0);
673
674 memcpy (buf, cdk_pixbuf_read_pixels (pixbuf), size);
675
676 return cdk_pixbuf_new_from_data (buf,
677 pixbuf->colorspace, pixbuf->has_alpha,
678 pixbuf->bits_per_sample,
679 pixbuf->width, pixbuf->height,
680 pixbuf->rowstride,
681 free_buffer,
682 NULL((void*)0));
683}
684
685/**
686 * cdk_pixbuf_new_subpixbuf:
687 * @src_pixbuf: a `CdkPixbuf`
688 * @src_x: X coord in @src_pixbuf
689 * @src_y: Y coord in @src_pixbuf
690 * @width: width of region in @src_pixbuf
691 * @height: height of region in @src_pixbuf
692 *
693 * Creates a new pixbuf which represents a sub-region of `src_pixbuf`.
694 *
695 * The new pixbuf shares its pixels with the original pixbuf, so
696 * writing to one affects both. The new pixbuf holds a reference to
697 * `src_pixbuf`, so `src_pixbuf` will not be finalized until the new
698 * pixbuf is finalized.
699 *
700 * Note that if `src_pixbuf` is read-only, this function will force it
701 * to be mutable.
702 *
703 * Return value: (transfer full): a new pixbuf
704 **/
705CdkPixbuf*
706cdk_pixbuf_new_subpixbuf (CdkPixbuf *src_pixbuf,
707 int src_x,
708 int src_y,
709 int width,
710 int height)
711{
712 guchar *pixels;
713 CdkPixbuf *sub;
714
715 g_return_val_if_fail (CDK_IS_PIXBUF (src_pixbuf), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_57
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((src_pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_57
= 1; _g_boolean_var_57; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (src_pixbuf)"
); return (((void*)0)); } } while (0)
;
716 g_return_val_if_fail (src_x >= 0 && src_x + width <= src_pixbuf->width, NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_58
= 0; if (src_x >= 0 && src_x + width <= src_pixbuf
->width) _g_boolean_var_58 = 1; _g_boolean_var_58; }), 1))
) { } else { g_return_if_fail_warning ("CdkPixbuf", ((const char
*) (__func__)), "src_x >= 0 && src_x + width <= src_pixbuf->width"
); return (((void*)0)); } } while (0)
;
717 g_return_val_if_fail (src_y >= 0 && src_y + height <= src_pixbuf->height, NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_59
= 0; if (src_y >= 0 && src_y + height <= src_pixbuf
->height) _g_boolean_var_59 = 1; _g_boolean_var_59; }), 1)
)) { } else { g_return_if_fail_warning ("CdkPixbuf", ((const char
*) (__func__)), "src_y >= 0 && src_y + height <= src_pixbuf->height"
); return (((void*)0)); } } while (0)
;
718
719 /* Note causes an implicit copy where src_pixbuf owns the data */
720 pixels = (cdk_pixbuf_get_pixels (src_pixbuf)
721 + src_y * src_pixbuf->rowstride
722 + src_x * src_pixbuf->n_channels);
723
724 sub = cdk_pixbuf_new_from_data (pixels,
725 src_pixbuf->colorspace,
726 src_pixbuf->has_alpha,
727 src_pixbuf->bits_per_sample,
728 width, height,
729 src_pixbuf->rowstride,
730 NULL((void*)0), NULL((void*)0));
731
732 /* Keep a reference to src_pixbuf */
733 g_object_ref (src_pixbuf)((__typeof__ (src_pixbuf)) (g_object_ref) (src_pixbuf));
734
735 g_object_set_qdata_full (G_OBJECT (sub)((((GObject*) (void *) ((sub))))),
736 g_quark_from_static_string ("cdk-pixbuf-subpixbuf-src"),
737 src_pixbuf,
738 (GDestroyNotify) g_object_unref);
739
740 return sub;
741}
742
743
744
745/* Accessors */
746
747/**
748 * cdk_pixbuf_get_colorspace:
749 * @pixbuf: A pixbuf.
750 *
751 * Queries the color space of a pixbuf.
752 *
753 * Return value: Color space.
754 **/
755CdkColorspace
756cdk_pixbuf_get_colorspace (const CdkPixbuf *pixbuf)
757{
758 g_return_val_if_fail (CDK_IS_PIXBUF (pixbuf), CDK_COLORSPACE_RGB)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_60
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_60
= 1; _g_boolean_var_60; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (pixbuf)"
); return (CDK_COLORSPACE_RGB); } } while (0)
;
759
760 return pixbuf->colorspace;
761}
762
763/**
764 * cdk_pixbuf_get_n_channels:
765 * @pixbuf: A pixbuf.
766 *
767 * Queries the number of channels of a pixbuf.
768 *
769 * Return value: Number of channels.
770 **/
771int
772cdk_pixbuf_get_n_channels (const CdkPixbuf *pixbuf)
773{
774 g_return_val_if_fail (CDK_IS_PIXBUF (pixbuf), -1)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_61
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_61
= 1; _g_boolean_var_61; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (pixbuf)"
); return (-1); } } while (0)
;
775
776 return pixbuf->n_channels;
777}
778
779/**
780 * cdk_pixbuf_get_has_alpha:
781 * @pixbuf: A pixbuf.
782 *
783 * Queries whether a pixbuf has an alpha channel (opacity information).
784 *
785 * Return value: `TRUE` if it has an alpha channel, `FALSE` otherwise.
786 **/
787gboolean
788cdk_pixbuf_get_has_alpha (const CdkPixbuf *pixbuf)
789{
790 g_return_val_if_fail (CDK_IS_PIXBUF (pixbuf), FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_62
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_62
= 1; _g_boolean_var_62; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (pixbuf)"
); return ((0)); } } while (0)
;
791
792 return pixbuf->has_alpha ? TRUE(!(0)) : FALSE(0);
793}
794
795/**
796 * cdk_pixbuf_get_bits_per_sample:
797 * @pixbuf: A pixbuf.
798 *
799 * Queries the number of bits per color sample in a pixbuf.
800 *
801 * Return value: Number of bits per color sample.
802 **/
803int
804cdk_pixbuf_get_bits_per_sample (const CdkPixbuf *pixbuf)
805{
806 g_return_val_if_fail (CDK_IS_PIXBUF (pixbuf), -1)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_63
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_63
= 1; _g_boolean_var_63; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (pixbuf)"
); return (-1); } } while (0)
;
807
808 return pixbuf->bits_per_sample;
809}
810
811/**
812 * cdk_pixbuf_get_pixels:
813 * @pixbuf: A pixbuf.
814 *
815 * Queries a pointer to the pixel data of a pixbuf.
816 *
817 * This function will cause an implicit copy of the pixbuf data if the
818 * pixbuf was created from read-only data.
819 *
820 * Please see the section on [image data](class.Pixbuf.html#image-data) for information
821 * about how the pixel data is stored in memory.
822 *
823 * Return value: (array): A pointer to the pixbuf's pixel data.
824 **/
825guchar *
826cdk_pixbuf_get_pixels (const CdkPixbuf *pixbuf)
827{
828 return cdk_pixbuf_get_pixels_with_length (pixbuf, NULL((void*)0));
829}
830
831static void
832downgrade_to_pixels (const CdkPixbuf *pixbuf)
833{
834 switch (pixbuf->storage) {
835 case STORAGE_PIXELS:
836 return;
837
838 case STORAGE_BYTES: {
839 CdkPixbuf *mut_pixbuf = (CdkPixbuf *) pixbuf;
840 gsize len;
841 Pixels pixels;
842
843 pixels.pixels = g_bytes_unref_to_data (pixbuf->s.bytes.bytes, &len);
844 pixels.destroy_fn = free_buffer;
845 pixels.destroy_fn_data = NULL((void*)0);
846
847 mut_pixbuf->storage = STORAGE_PIXELS;
848 mut_pixbuf->s.pixels = pixels;
849 break;
850 }
851
852 default:
853 g_assert_not_reached ()do { g_assertion_message_expr ("CdkPixbuf", "../cdk-pixbuf/cdk-pixbuf.c"
, 853, ((const char*) (__func__)), ((void*)0)); } while (0)
;
854 }
855}
856
857/**
858 * cdk_pixbuf_get_pixels_with_length: (rename-to cdk_pixbuf_get_pixels)
859 * @pixbuf: A pixbuf.
860 * @length: (out): The length of the binary data.
861 *
862 * Queries a pointer to the pixel data of a pixbuf.
863 *
864 * This function will cause an implicit copy of the pixbuf data if the
865 * pixbuf was created from read-only data.
866 *
867 * Please see the section on [image data](class.Pixbuf.html#image-data) for information
868 * about how the pixel data is stored in memory.
869 *
870 * Return value: (array length=length): A pointer to the pixbuf's
871 * pixel data.
872 *
873 * Since: 2.26
874 */
875guchar *
876cdk_pixbuf_get_pixels_with_length (const CdkPixbuf *pixbuf,
877 guint *length)
878{
879 g_return_val_if_fail (CDK_IS_PIXBUF (pixbuf), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_64
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_64
= 1; _g_boolean_var_64; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (pixbuf)"
); return (((void*)0)); } } while (0)
;
880
881 downgrade_to_pixels (pixbuf);
882 g_assert (pixbuf->storage == STORAGE_PIXELS)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_65
= 0; if (pixbuf->storage == STORAGE_PIXELS) _g_boolean_var_65
= 1; _g_boolean_var_65; }), 1)) ; else g_assertion_message_expr
("CdkPixbuf", "../cdk-pixbuf/cdk-pixbuf.c", 882, ((const char
*) (__func__)), "pixbuf->storage == STORAGE_PIXELS"); } while
(0)
;
883
884 if (length)
885 *length = cdk_pixbuf_get_byte_length (pixbuf);
886
887 return pixbuf->s.pixels.pixels;
888}
889
890/**
891 * cdk_pixbuf_read_pixels:
892 * @pixbuf: A pixbuf
893 *
894 * Provides a read-only pointer to the raw pixel data.
895 *
896 * This function allows skipping the implicit copy that must be made
897 * if cdk_pixbuf_get_pixels() is called on a read-only pixbuf.
898 *
899 * Returns: a read-only pointer to the raw pixel data
900 *
901 * Since: 2.32
902 */
903const guint8*
904cdk_pixbuf_read_pixels (const CdkPixbuf *pixbuf)
905{
906 g_return_val_if_fail (CDK_IS_PIXBUF (pixbuf), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_66
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_66
= 1; _g_boolean_var_66; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (pixbuf)"
); return (((void*)0)); } } while (0)
;
907
908 switch (pixbuf->storage) {
909 case STORAGE_PIXELS:
910 return pixbuf->s.pixels.pixels;
911
912 case STORAGE_BYTES: {
913 gsize len;
914 /* Ignore len; callers know the size via other variables */
915 return g_bytes_get_data (pixbuf->s.bytes.bytes, &len);
916 }
917
918 default:
919 g_assert_not_reached ()do { g_assertion_message_expr ("CdkPixbuf", "../cdk-pixbuf/cdk-pixbuf.c"
, 919, ((const char*) (__func__)), ((void*)0)); } while (0)
;
920 return NULL((void*)0);
921 }
922}
923
924/**
925 * cdk_pixbuf_read_pixel_bytes:
926 * @pixbuf: A pixbuf
927 *
928 * Provides a #GBytes buffer containing the raw pixel data; the data
929 * must not be modified.
930 *
931 * This function allows skipping the implicit copy that must be made
932 * if cdk_pixbuf_get_pixels() is called on a read-only pixbuf.
933 *
934 * Returns: (transfer full): A new reference to a read-only copy of
935 * the pixel data. Note that for mutable pixbufs, this function will
936 * incur a one-time copy of the pixel data for conversion into the
937 * returned #GBytes.
938 *
939 * Since: 2.32
940 */
941GBytes *
942cdk_pixbuf_read_pixel_bytes (const CdkPixbuf *pixbuf)
943{
944 g_return_val_if_fail (CDK_IS_PIXBUF (pixbuf), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_67
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_67
= 1; _g_boolean_var_67; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (pixbuf)"
); return (((void*)0)); } } while (0)
;
945
946 switch (pixbuf->storage) {
947 case STORAGE_PIXELS:
948 return g_bytes_new (pixbuf->s.pixels.pixels,
949 cdk_pixbuf_get_byte_length (pixbuf));
950
951 case STORAGE_BYTES:
952 return g_bytes_ref (pixbuf->s.bytes.bytes);
953
954 default:
955 g_assert_not_reached ()do { g_assertion_message_expr ("CdkPixbuf", "../cdk-pixbuf/cdk-pixbuf.c"
, 955, ((const char*) (__func__)), ((void*)0)); } while (0)
;
956 }
957}
958
959/**
960 * cdk_pixbuf_get_width:
961 * @pixbuf: A pixbuf.
962 *
963 * Queries the width of a pixbuf.
964 *
965 * Return value: Width in pixels.
966 **/
967int
968cdk_pixbuf_get_width (const CdkPixbuf *pixbuf)
969{
970 g_return_val_if_fail (CDK_IS_PIXBUF (pixbuf), -1)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_68
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_68
= 1; _g_boolean_var_68; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (pixbuf)"
); return (-1); } } while (0)
;
971
972 return pixbuf->width;
973}
974
975/**
976 * cdk_pixbuf_get_height:
977 * @pixbuf: A pixbuf.
978 *
979 * Queries the height of a pixbuf.
980 *
981 * Return value: Height in pixels.
982 **/
983int
984cdk_pixbuf_get_height (const CdkPixbuf *pixbuf)
985{
986 g_return_val_if_fail (CDK_IS_PIXBUF (pixbuf), -1)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_69
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_69
= 1; _g_boolean_var_69; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (pixbuf)"
); return (-1); } } while (0)
;
987
988 return pixbuf->height;
989}
990
991/**
992 * cdk_pixbuf_get_rowstride:
993 * @pixbuf: A pixbuf.
994 *
995 * Queries the rowstride of a pixbuf, which is the number of bytes between
996 * the start of a row and the start of the next row.
997 *
998 * Return value: Distance between row starts.
999 **/
1000int
1001cdk_pixbuf_get_rowstride (const CdkPixbuf *pixbuf)
1002{
1003 g_return_val_if_fail (CDK_IS_PIXBUF (pixbuf), -1)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_70
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_70
= 1; _g_boolean_var_70; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (pixbuf)"
); return (-1); } } while (0)
;
1004
1005 return pixbuf->rowstride;
1006}
1007
1008/**
1009 * cdk_pixbuf_get_byte_length:
1010 * @pixbuf: A pixbuf
1011 *
1012 * Returns the length of the pixel data, in bytes.
1013 *
1014 * Return value: The length of the pixel data.
1015 *
1016 * Since: 2.26
1017 */
1018gsize
1019cdk_pixbuf_get_byte_length (const CdkPixbuf *pixbuf)
1020{
1021 g_return_val_if_fail (CDK_IS_PIXBUF (pixbuf), -1)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_71
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_71
= 1; _g_boolean_var_71; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (pixbuf)"
); return (-1); } } while (0)
;
1022
1023 return ((pixbuf->height - 1) * pixbuf->rowstride +
1024 pixbuf->width * ((pixbuf->n_channels * pixbuf->bits_per_sample + 7) / 8));
1025}
1026
1027
1028
1029/* General initialization hooks */
1030const guint cdk_pixbuf_major_version = CDK_PIXBUF_MAJOR(2);
1031const guint cdk_pixbuf_minor_version = CDK_PIXBUF_MINOR(45);
1032const guint cdk_pixbuf_micro_version = CDK_PIXBUF_MICRO(0);
1033
1034const char *cdk_pixbuf_version = CDK_PIXBUF_VERSION"2.45.0";
1035
1036/* Error quark */
1037GQuark
1038cdk_pixbuf_error_quark (void)
1039{
1040 return g_quark_from_static_string ("cdk-pixbuf-error-quark");
1041}
1042
1043/**
1044 * cdk_pixbuf_fill:
1045 * @pixbuf: a `CdkPixbuf`
1046 * @pixel: RGBA pixel to used to clear (`0xffffffff` is opaque white,
1047 * `0x00000000` transparent black)
1048 *
1049 * Clears a pixbuf to the given RGBA value, converting the RGBA value into
1050 * the pixbuf's pixel format.
1051 *
1052 * The alpha component will be ignored if the pixbuf doesn't have an alpha
1053 * channel.
1054 */
1055void
1056cdk_pixbuf_fill (CdkPixbuf *pixbuf,
1057 guint32 pixel)
1058{
1059 guchar *pixels;
1060 guint r, g, b, a;
1061 guchar *p;
1062 guint w, h;
1063
1064 g_return_if_fail (CDK_IS_PIXBUF (pixbuf))do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_72
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_72
= 1; _g_boolean_var_72; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (pixbuf)"
); return; } } while (0)
;
1065
1066 if (pixbuf->width == 0 || pixbuf->height == 0)
1067 return;
1068
1069 /* Force an implicit copy */
1070 pixels = cdk_pixbuf_get_pixels (pixbuf);
1071
1072 r = (pixel & 0xff000000) >> 24;
1073 g = (pixel & 0x00ff0000) >> 16;
1074 b = (pixel & 0x0000ff00) >> 8;
1075 a = (pixel & 0x000000ff);
1076
1077 h = pixbuf->height;
1078
1079 while (h--) {
1080 w = pixbuf->width;
1081 p = pixels;
1082
1083 switch (pixbuf->n_channels) {
1084 case 3:
1085 while (w--) {
1086 p[0] = r;
1087 p[1] = g;
1088 p[2] = b;
1089 p += 3;
1090 }
1091 break;
1092 case 4:
1093 while (w--) {
1094 p[0] = r;
1095 p[1] = g;
1096 p[2] = b;
1097 p[3] = a;
1098 p += 4;
1099 }
1100 break;
1101 default:
1102 break;
1103 }
1104
1105 pixels += pixbuf->rowstride;
1106 }
1107}
1108
1109
1110
1111/**
1112 * cdk_pixbuf_get_option:
1113 * @pixbuf: a `CdkPixbuf`
1114 * @key: a nul-terminated string.
1115 *
1116 * Looks up @key in the list of options that may have been attached to the
1117 * @pixbuf when it was loaded, or that may have been attached by another
1118 * function using cdk_pixbuf_set_option().
1119 *
1120 * For instance, the ANI loader provides "Title" and "Artist" options.
1121 * The ICO, XBM, and XPM loaders provide "x_hot" and "y_hot" hot-spot
1122 * options for cursor definitions. The PNG loader provides the tEXt ancillary
1123 * chunk key/value pairs as options. Since 2.12, the TIFF and JPEG loaders
1124 * return an "orientation" option string that corresponds to the embedded
1125 * TIFF/Exif orientation tag (if present). Since 2.32, the TIFF loader sets
1126 * the "multipage" option string to "yes" when a multi-page TIFF is loaded.
1127 * Since 2.32 the JPEG and PNG loaders set "x-dpi" and "y-dpi" if the file
1128 * contains image density information in dots per inch.
1129 * Since 2.36.6, the JPEG loader sets the "comment" option with the comment
1130 * EXIF tag.
1131 *
1132 * Return value: (transfer none) (nullable): the value associated with `key`
1133 **/
1134const gchar *
1135cdk_pixbuf_get_option (CdkPixbuf *pixbuf,
1136 const gchar *key)
1137{
1138 gchar **options;
1139 gint i;
1140
1141 g_return_val_if_fail (CDK_IS_PIXBUF (pixbuf), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_73
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_73
= 1; _g_boolean_var_73; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (pixbuf)"
); return (((void*)0)); } } while (0)
;
1142 g_return_val_if_fail (key != NULL, NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_74
= 0; if (key != ((void*)0)) _g_boolean_var_74 = 1; _g_boolean_var_74
; }), 1))) { } else { g_return_if_fail_warning ("CdkPixbuf", (
(const char*) (__func__)), "key != NULL"); return (((void*)0)
); } } while (0)
;
1143
1144 options = g_object_get_qdata (G_OBJECT (pixbuf)((((GObject*) (void *) ((pixbuf))))),
1145 g_quark_from_static_string ("cdk_pixbuf_options"));
1146 if (options) {
1147 for (i = 0; options[2*i]; i++) {
1148 if (strcmp (options[2*i], key) == 0)
1149 return options[2*i+1];
1150 }
1151 }
1152
1153 return NULL((void*)0);
1154}
1155
1156/**
1157 * cdk_pixbuf_get_options:
1158 * @pixbuf: a `CdkPixbuf`
1159 *
1160 * Returns a `GHashTable` with a list of all the options that may have been
1161 * attached to the `pixbuf` when it was loaded, or that may have been
1162 * attached by another function using [method@CdkPixbuf.Pixbuf.set_option].
1163 *
1164 * Return value: (transfer container) (element-type utf8 utf8): a #GHashTable
1165 * of key/values pairs
1166 *
1167 * Since: 2.32
1168 **/
1169GHashTable *
1170cdk_pixbuf_get_options (CdkPixbuf *pixbuf)
1171{
1172 GHashTable *ht;
1173 gchar **options;
1174
1175 g_return_val_if_fail (CDK_IS_PIXBUF (pixbuf), NULL)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_75
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_75
= 1; _g_boolean_var_75; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (pixbuf)"
); return (((void*)0)); } } while (0)
;
1176
1177 ht = g_hash_table_new (g_str_hash, g_str_equal);
1178
1179 options = g_object_get_qdata (G_OBJECT (pixbuf)((((GObject*) (void *) ((pixbuf))))),
1180 g_quark_from_static_string ("cdk_pixbuf_options"));
1181 if (options) {
1182 gint i;
1183
1184 for (i = 0; options[2*i]; i++)
1185 g_hash_table_insert (ht, options[2*i], options[2*i+1]);
1186 }
1187
1188 return ht;
1189}
1190
1191/**
1192 * cdk_pixbuf_remove_option:
1193 * @pixbuf: a `CdkPixbuf`
1194 * @key: a nul-terminated string representing the key to remove.
1195 *
1196 * Removes the key/value pair option attached to a `CdkPixbuf`.
1197 *
1198 * Return value: `TRUE` if an option was removed, `FALSE` if not.
1199 *
1200 * Since: 2.36
1201 **/
1202gboolean
1203cdk_pixbuf_remove_option (CdkPixbuf *pixbuf,
1204 const gchar *key)
1205{
1206 GQuark quark;
1207 gchar **options;
1208 guint n;
1209 GPtrArray *array;
1210 gboolean found;
1211
1212 g_return_val_if_fail (CDK_IS_PIXBUF (pixbuf), FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_76
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_76
= 1; _g_boolean_var_76; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (pixbuf)"
); return ((0)); } } while (0)
;
1213 g_return_val_if_fail (key != NULL, FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_77
= 0; if (key != ((void*)0)) _g_boolean_var_77 = 1; _g_boolean_var_77
; }), 1))) { } else { g_return_if_fail_warning ("CdkPixbuf", (
(const char*) (__func__)), "key != NULL"); return ((0)); } } while
(0)
;
1214
1215 quark = g_quark_from_static_string ("cdk_pixbuf_options");
1216
1217 options = g_object_get_qdata (G_OBJECT (pixbuf)((((GObject*) (void *) ((pixbuf))))), quark);
1218 if (!options)
1219 return FALSE(0);
1220
1221 g_object_steal_qdata (G_OBJECT (pixbuf)((((GObject*) (void *) ((pixbuf))))), quark);
1222
1223 /* There's at least a nul-terminator */
1224 array = g_ptr_array_new_full (1, g_free);
1225
1226 found = FALSE(0);
1227 for (n = 0; options[2*n]; n++) {
1228 if (strcmp (options[2*n], key) != 0) {
1229 g_ptr_array_add (array, g_strdup (options[2*n])g_strdup_inline (options[2*n])); /* key */
1230 g_ptr_array_add (array, g_strdup (options[2*n+1])g_strdup_inline (options[2*n+1])); /* value */
1231 } else {
1232 found = TRUE(!(0));
1233 }
1234 }
1235
1236 if (array->len == 0) {
1237 g_ptr_array_unref (array);
1238 g_strfreev (options);
1239 return found;
1240 }
1241
1242 if (!found) {
1243 g_ptr_array_free (array, TRUE(!(0)));
1244 g_object_set_qdata_full (G_OBJECT (pixbuf)((((GObject*) (void *) ((pixbuf))))), quark,
1245 options, (GDestroyNotify) g_strfreev);
1246 return FALSE(0);
1247 }
1248
1249 g_ptr_array_add (array, NULL((void*)0));
1250 g_object_set_qdata_full (G_OBJECT (pixbuf)((((GObject*) (void *) ((pixbuf))))), quark,
1251 g_ptr_array_free (array, FALSE(0)), (GDestroyNotify) g_strfreev);
1252 g_strfreev (options);
1253
1254 return TRUE(!(0));
1255}
1256
1257/**
1258 * cdk_pixbuf_set_option:
1259 * @pixbuf: a `CdkPixbuf`
1260 * @key: a nul-terminated string.
1261 * @value: a nul-terminated string.
1262 *
1263 * Attaches a key/value pair as an option to a `CdkPixbuf`.
1264 *
1265 * If `key` already exists in the list of options attached to the `pixbuf`,
1266 * the new value is ignored and `FALSE` is returned.
1267 *
1268 * Return value: `TRUE` on success
1269 *
1270 * Since: 2.2
1271 **/
1272gboolean
1273cdk_pixbuf_set_option (CdkPixbuf *pixbuf,
1274 const gchar *key,
1275 const gchar *value)
1276{
1277 GQuark quark;
1278 gchar **options;
1279 gint n = 0;
1280
1281 g_return_val_if_fail (CDK_IS_PIXBUF (pixbuf), FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_78
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_78
= 1; _g_boolean_var_78; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (pixbuf)"
); return ((0)); } } while (0)
;
1282 g_return_val_if_fail (key != NULL, FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_79
= 0; if (key != ((void*)0)) _g_boolean_var_79 = 1; _g_boolean_var_79
; }), 1))) { } else { g_return_if_fail_warning ("CdkPixbuf", (
(const char*) (__func__)), "key != NULL"); return ((0)); } } while
(0)
;
1283 g_return_val_if_fail (value != NULL, FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_80
= 0; if (value != ((void*)0)) _g_boolean_var_80 = 1; _g_boolean_var_80
; }), 1))) { } else { g_return_if_fail_warning ("CdkPixbuf", (
(const char*) (__func__)), "value != NULL"); return ((0)); } }
while (0)
;
1284
1285 quark = g_quark_from_static_string ("cdk_pixbuf_options");
1286
1287 options = g_object_get_qdata (G_OBJECT (pixbuf)((((GObject*) (void *) ((pixbuf))))), quark);
1288
1289 if (options) {
1290 for (n = 0; options[2*n]; n++) {
1291 if (strcmp (options[2*n], key) == 0)
1292 return FALSE(0);
1293 }
1294
1295 g_object_steal_qdata (G_OBJECT (pixbuf)((((GObject*) (void *) ((pixbuf))))), quark);
1296 options = g_renew (gchar *, options, 2*(n+1) + 1)(gchar * *) (__extension__ ({ gsize __n = (gsize) (2*(n+1) + 1
); gsize __s = sizeof (gchar *); gpointer __p = (gpointer) (options
); if (__s == 1) __p = g_realloc (__p, __n); else if (__builtin_constant_p
(__n) && (__s == 0 || __n <= (9223372036854775807L
*2UL+1UL) / __s)) __p = g_realloc (__p, __n * __s); else __p
= g_realloc_n (__p, __n, __s); __p; }))
;
1297 } else {
1298 options = g_new (gchar *, 3)(gchar * *) (__extension__ ({ gsize __n = (gsize) (3); gsize __s
= sizeof (gchar *); gpointer __p; if (__s == 1) __p = g_malloc
(__n); else if (__builtin_constant_p (__n) && (__s ==
0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p =
g_malloc (__n * __s); else __p = g_malloc_n (__n, __s); __p;
}))
;
1299 }
1300
1301 options[2*n] = g_strdup (key)g_strdup_inline (key);
1302 options[2*n+1] = g_strdup (value)g_strdup_inline (value);
1303 options[2*n+2] = NULL((void*)0);
1304
1305 g_object_set_qdata_full (G_OBJECT (pixbuf)((((GObject*) (void *) ((pixbuf))))), quark,
1306 options, (GDestroyNotify) g_strfreev);
1307
1308 return TRUE(!(0));
1309}
1310
1311/**
1312 * cdk_pixbuf_copy_options:
1313 * @src_pixbuf: the source pixbuf
1314 * @dest_pixbuf: the destination pixbuf
1315 *
1316 * Copies the key/value pair options attached to a `CdkPixbuf` to another
1317 * `CdkPixbuf`.
1318 *
1319 * This is useful to keep original metadata after having manipulated
1320 * a file. However be careful to remove metadata which you've already
1321 * applied, such as the "orientation" option after rotating the image.
1322 *
1323 * Return value: `TRUE` on success.
1324 *
1325 * Since: 2.36
1326 **/
1327gboolean
1328cdk_pixbuf_copy_options (CdkPixbuf *src_pixbuf,
1329 CdkPixbuf *dest_pixbuf)
1330{
1331 GQuark quark;
1332 gchar **options;
1333
1334 g_return_val_if_fail (CDK_IS_PIXBUF (src_pixbuf), FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_81
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((src_pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_81
= 1; _g_boolean_var_81; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (src_pixbuf)"
); return ((0)); } } while (0)
;
1335 g_return_val_if_fail (CDK_IS_PIXBUF (dest_pixbuf), FALSE)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_82
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((dest_pixbuf)); GType __t = ((cdk_pixbuf_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_82
= 1; _g_boolean_var_82; }), 1))) { } else { g_return_if_fail_warning
("CdkPixbuf", ((const char*) (__func__)), "CDK_IS_PIXBUF (dest_pixbuf)"
); return ((0)); } } while (0)
;
1336
1337 quark = g_quark_from_static_string ("cdk_pixbuf_options");
1338
1339 options = g_object_dup_qdata (G_OBJECT (src_pixbuf)((((GObject*) (void *) ((src_pixbuf))))),
1340 quark,
1341 (GDuplicateFunc) g_strdupv,
1342 NULL((void*)0));
1343
1344 if (options == NULL((void*)0))
1345 return TRUE(!(0));
1346
1347 g_object_set_qdata_full (G_OBJECT (dest_pixbuf)((((GObject*) (void *) ((dest_pixbuf))))), quark,
1348 options, (GDestroyNotify) g_strfreev);
1349
1350 return TRUE(!(0));
1351}
1352
1353static void
1354cdk_pixbuf_set_property (GObject *object,
1355 guint prop_id,
1356 const GValue *value,
1357 GParamSpec *pspec)
1358{
1359 CdkPixbuf *pixbuf = CDK_PIXBUF (object)((((CdkPixbuf*) (void *) ((object)))));
1360 gboolean notify = TRUE(!(0));
1361
1362 switch (prop_id) {
1363 case PROP_COLORSPACE:
1364 notify = pixbuf->colorspace != g_value_get_enum (value);
1365 pixbuf->colorspace = g_value_get_enum (value);
1366 break;
1367 case PROP_N_CHANNELS:
1368 notify = pixbuf->n_channels != g_value_get_int (value);
1369 pixbuf->n_channels = g_value_get_int (value);
1370 break;
1371 case PROP_HAS_ALPHA:
1372 notify = pixbuf->has_alpha != g_value_get_boolean (value);
1373 pixbuf->has_alpha = g_value_get_boolean (value);
1374 break;
1375 case PROP_BITS_PER_SAMPLE:
1376 notify = pixbuf->bits_per_sample != g_value_get_int (value);
1377 pixbuf->bits_per_sample = g_value_get_int (value);
1378 break;
1379 case PROP_WIDTH:
1380 notify = pixbuf->width != g_value_get_int (value);
1381 pixbuf->width = g_value_get_int (value);
1382 break;
1383 case PROP_HEIGHT:
1384 notify = pixbuf->height != g_value_get_int (value);
1385 pixbuf->height = g_value_get_int (value);
1386 break;
1387 case PROP_ROWSTRIDE:
1388 notify = pixbuf->rowstride != g_value_get_int (value);
1389 pixbuf->rowstride = g_value_get_int (value);
1390 break;
1391
1392 /* The following two are a bit strange. Both PROP_PIXELS and
1393 * PROP_PIXEL_BYTES are G_PARAM_CONSTRUCT_ONLY properties, which means
1394 * that GObject will generate default values for any missing one and
1395 * call us for *both*. So, we need to check whether the passed value is
1396 * not NULL before actually setting pixbuf->storage.
1397 */
1398 case PROP_PIXELS: {
1399 guchar *pixels = g_value_get_pointer (value);
1400
1401 if (pixels) {
1402 g_assert (pixbuf->storage == STORAGE_UNINITIALIZED)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_83
= 0; if (pixbuf->storage == STORAGE_UNINITIALIZED) _g_boolean_var_83
= 1; _g_boolean_var_83; }), 1)) ; else g_assertion_message_expr
("CdkPixbuf", "../cdk-pixbuf/cdk-pixbuf.c", 1402, ((const char
*) (__func__)), "pixbuf->storage == STORAGE_UNINITIALIZED"
); } while (0)
;
1403
1404 pixbuf->storage = STORAGE_PIXELS;
1405 pixbuf->s.pixels.pixels = pixels;
1406 pixbuf->s.pixels.destroy_fn = NULL((void*)0);
1407 pixbuf->s.pixels.destroy_fn_data = NULL((void*)0);
1408 } else {
1409 notify = FALSE(0);
1410 }
1411
1412 break;
1413 }
1414
1415 case PROP_PIXEL_BYTES: {
1416 GBytes *bytes = g_value_get_boxed (value);
1417
1418 if (bytes) {
1419 g_assert (pixbuf->storage == STORAGE_UNINITIALIZED)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_84
= 0; if (pixbuf->storage == STORAGE_UNINITIALIZED) _g_boolean_var_84
= 1; _g_boolean_var_84; }), 1)) ; else g_assertion_message_expr
("CdkPixbuf", "../cdk-pixbuf/cdk-pixbuf.c", 1419, ((const char
*) (__func__)), "pixbuf->storage == STORAGE_UNINITIALIZED"
); } while (0)
;
1420
1421 pixbuf->storage = STORAGE_BYTES;
1422 pixbuf->s.bytes.bytes = g_value_dup_boxed (value);
1423 } else {
1424 notify = FALSE(0);
1425 }
1426
1427 break;
1428 }
1429
1430 default:
1431 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec
*_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id
= ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'"
, "../cdk-pixbuf/cdk-pixbuf.c", 1431, ("property"), _glib__property_id
, _glib__pspec->name, g_type_name ((((((GTypeClass*) (((GTypeInstance
*) (_glib__pspec))->g_class))->g_type)))), (g_type_name
((((((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class
))->g_type)))))); } while (0)
;
1432 break;
1433 }
1434
1435 if (notify)
1436 g_object_notify_by_pspec (G_OBJECT (object)((((GObject*) (void *) ((object))))), pspec);
1437}
1438
1439static void
1440cdk_pixbuf_get_property (GObject *object,
1441 guint prop_id,
1442 GValue *value,
1443 GParamSpec *pspec)
1444{
1445 CdkPixbuf *pixbuf = CDK_PIXBUF (object)((((CdkPixbuf*) (void *) ((object)))));
1446
1447 switch (prop_id) {
1448 case PROP_COLORSPACE:
1449 g_value_set_enum (value, cdk_pixbuf_get_colorspace (pixbuf));
1450 break;
1451 case PROP_N_CHANNELS:
1452 g_value_set_int (value, cdk_pixbuf_get_n_channels (pixbuf));
1453 break;
1454 case PROP_HAS_ALPHA:
1455 g_value_set_boolean (value, cdk_pixbuf_get_has_alpha (pixbuf));
1456 break;
1457 case PROP_BITS_PER_SAMPLE:
1458 g_value_set_int (value, cdk_pixbuf_get_bits_per_sample (pixbuf));
1459 break;
1460 case PROP_WIDTH:
1461 g_value_set_int (value, cdk_pixbuf_get_width (pixbuf));
1462 break;
1463 case PROP_HEIGHT:
1464 g_value_set_int (value, cdk_pixbuf_get_height (pixbuf));
1465 break;
1466 case PROP_ROWSTRIDE:
1467 g_value_set_int (value, cdk_pixbuf_get_rowstride (pixbuf));
1468 break;
1469 case PROP_PIXELS:
1470 g_value_set_pointer (value, cdk_pixbuf_get_pixels (pixbuf));
1471 break;
1472 case PROP_PIXEL_BYTES:
1473 g_value_take_boxed (value, cdk_pixbuf_read_pixel_bytes (pixbuf));
1474 break;
1475 default:
1476 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec
*_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id
= ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'"
, "../cdk-pixbuf/cdk-pixbuf.c", 1476, ("property"), _glib__property_id
, _glib__pspec->name, g_type_name ((((((GTypeClass*) (((GTypeInstance
*) (_glib__pspec))->g_class))->g_type)))), (g_type_name
((((((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class
))->g_type)))))); } while (0)
;
1477 break;
1478 }
1479}
1480
1481static void
1482make_storage_invalid (CdkPixbuf *pixbuf)
1483{
1484 char *buf;
1485 gsize bufsize = 3;
1486
1487 buf = g_new0 (char, bufsize)(char *) (__extension__ ({ gsize __n = (gsize) (bufsize); gsize
__s = sizeof (char); gpointer __p; if (__s == 1) __p = g_malloc0
(__n); else if (__builtin_constant_p (__n) && (__s ==
0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p =
g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p
; }))
;
1488
1489 pixbuf->storage = STORAGE_BYTES;
1490 pixbuf->s.bytes.bytes = g_bytes_new_take (buf, bufsize);
1491
1492 pixbuf->colorspace = CDK_COLORSPACE_RGB;
1493 pixbuf->n_channels = 3;
1494 pixbuf->bits_per_sample = 8;
1495 pixbuf->width = 1;
1496 pixbuf->height = 1;
1497 pixbuf->rowstride = 3;
1498 pixbuf->has_alpha = FALSE(0);
1499}
1500
1501static void
1502cdk_pixbuf_constructed (GObject *object)
1503{
1504 CdkPixbuf *pixbuf = CDK_PIXBUF (object)((((CdkPixbuf*) (void *) ((object)))));
1505
1506 G_OBJECT_CLASS (cdk_pixbuf_parent_class)((((GObjectClass*) (void *) ((cdk_pixbuf_parent_class)))))->constructed (object);
1507
1508 switch (pixbuf->storage) {
1509 case STORAGE_UNINITIALIZED:
1510 /* This means that neither of the construct properties "pixels" nor "pixel-bytes"
1511 * was specified during a call to g_object_new().
1512 *
1513 * To avoid breaking ABI, we don't emit this warning. We'll want
1514 * to emit it once we can have fallible construction.
1515 *
1516 * g_warning ("pixbuf needs to be constructed with the 'pixels' or 'pixel-bytes' properties");
1517 */
1518
1519 make_storage_invalid (pixbuf);
1520 break;
1521
1522 case STORAGE_PIXELS:
1523 g_assert (pixbuf->s.pixels.pixels != NULL)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_85
= 0; if (pixbuf->s.pixels.pixels != ((void*)0)) _g_boolean_var_85
= 1; _g_boolean_var_85; }), 1)) ; else g_assertion_message_expr
("CdkPixbuf", "../cdk-pixbuf/cdk-pixbuf.c", 1523, ((const char
*) (__func__)), "pixbuf->s.pixels.pixels != NULL"); } while
(0)
;
1524 break;
1525
1526 case STORAGE_BYTES: {
1527 gsize bytes_size;
1528 gint width, height;
1529 gboolean has_alpha;
1530
1531 g_assert (pixbuf->s.bytes.bytes != NULL)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_86
= 0; if (pixbuf->s.bytes.bytes != ((void*)0)) _g_boolean_var_86
= 1; _g_boolean_var_86; }), 1)) ; else g_assertion_message_expr
("CdkPixbuf", "../cdk-pixbuf/cdk-pixbuf.c", 1531, ((const char
*) (__func__)), "pixbuf->s.bytes.bytes != NULL"); } while (
0)
;
1532
1533 bytes_size = g_bytes_get_size (pixbuf->s.bytes.bytes);
1534 width = pixbuf->width;
1535 height = pixbuf->height;
1536 has_alpha = pixbuf->has_alpha;
1537
1538 /* This is the same check as in cdk_pixbuf_new_from_bytes() */
1539 if (!(bytes_size >= width * height * (has_alpha ? 4 : 3))) {
1540 g_error ("GBytes is too small to fit the pixbuf's declared width and height");
1541 }
1542 break;
1543 }
1544
1545 default:
1546 g_assert_not_reached ()do { g_assertion_message_expr ("CdkPixbuf", "../cdk-pixbuf/cdk-pixbuf.c"
, 1546, ((const char*) (__func__)), ((void*)0)); } while (0)
;
1547 }
1548
1549 g_assert (pixbuf->storage != STORAGE_UNINITIALIZED)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_87
= 0; if (pixbuf->storage != STORAGE_UNINITIALIZED) _g_boolean_var_87
= 1; _g_boolean_var_87; }), 1)) ; else g_assertion_message_expr
("CdkPixbuf", "../cdk-pixbuf/cdk-pixbuf.c", 1549, ((const char
*) (__func__)), "pixbuf->storage != STORAGE_UNINITIALIZED"
); } while (0)
;
1550}