-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
GdkPixbuf-2.0.gir
4832 lines (4539 loc) · 233 KB
/
GdkPixbuf-2.0.gir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0"?>
<!-- This file was automatically generated from C sources - DO NOT EDIT!
To affect the contents of this file, edit the original C definitions,
and/or use gtk-doc annotations. -->
<repository xmlns="http://www.gtk.org/introspection/core/1.0" xmlns:c="http://www.gtk.org/introspection/c/1.0" xmlns:glib="http://www.gtk.org/introspection/glib/1.0" version="1.2">
<include name="GModule" version="2.0"/>
<include name="Gio" version="2.0"/>
<package name="gdk-pixbuf-2.0"/>
<c:include name="gdk-pixbuf/gdk-pixbuf.h"/>
<namespace name="GdkPixbuf" version="2.0" shared-library="libgdk_pixbuf-2.0.so.0" c:identifier-prefixes="Gdk" c:symbol-prefixes="gdk">
<enumeration name="Colorspace" glib:type-name="GdkColorspace" glib:get-type="gdk_colorspace_get_type" c:type="GdkColorspace">
<doc xml:space="preserve">This enumeration defines the color spaces that are supported by
the gdk-pixbuf library.
Currently only RGB is supported.</doc>
<member name="rgb" value="0" c:identifier="GDK_COLORSPACE_RGB" glib:nick="rgb" glib:name="GDK_COLORSPACE_RGB">
<doc xml:space="preserve">Indicates a red/green/blue additive color space.</doc>
</member>
</enumeration>
<function-macro name="IS_PIXBUF" c:identifier="GDK_IS_PIXBUF" introspectable="0">
<parameters>
<parameter name="object">
</parameter>
</parameters>
</function-macro>
<function-macro name="IS_PIXBUF_ANIMATION" c:identifier="GDK_IS_PIXBUF_ANIMATION" introspectable="0">
<parameters>
<parameter name="object">
</parameter>
</parameters>
</function-macro>
<function-macro name="IS_PIXBUF_ANIMATION_CLASS" c:identifier="GDK_IS_PIXBUF_ANIMATION_CLASS" introspectable="0">
<parameters>
<parameter name="klass">
</parameter>
</parameters>
</function-macro>
<function-macro name="IS_PIXBUF_ANIMATION_ITER" c:identifier="GDK_IS_PIXBUF_ANIMATION_ITER" introspectable="0">
<parameters>
<parameter name="object">
</parameter>
</parameters>
</function-macro>
<function-macro name="IS_PIXBUF_ANIMATION_ITER_CLASS" c:identifier="GDK_IS_PIXBUF_ANIMATION_ITER_CLASS" introspectable="0">
<parameters>
<parameter name="klass">
</parameter>
</parameters>
</function-macro>
<function-macro name="IS_PIXBUF_LOADER" c:identifier="GDK_IS_PIXBUF_LOADER" introspectable="0">
<parameters>
<parameter name="obj">
</parameter>
</parameters>
</function-macro>
<function-macro name="IS_PIXBUF_LOADER_CLASS" c:identifier="GDK_IS_PIXBUF_LOADER_CLASS" introspectable="0">
<parameters>
<parameter name="klass">
</parameter>
</parameters>
</function-macro>
<function-macro name="IS_PIXBUF_SIMPLE_ANIM" c:identifier="GDK_IS_PIXBUF_SIMPLE_ANIM" introspectable="0">
<parameters>
<parameter name="object">
</parameter>
</parameters>
</function-macro>
<function-macro name="IS_PIXBUF_SIMPLE_ANIM_CLASS" c:identifier="GDK_IS_PIXBUF_SIMPLE_ANIM_CLASS" introspectable="0">
<parameters>
<parameter name="klass">
</parameter>
</parameters>
</function-macro>
<enumeration name="InterpType" glib:type-name="GdkInterpType" glib:get-type="gdk_interp_type_get_type" c:type="GdkInterpType">
<doc xml:space="preserve">Interpolation modes for scaling functions.
The `GDK_INTERP_NEAREST` mode is the fastest scaling method, but has
horrible quality when scaling down; `GDK_INTERP_BILINEAR` is the best
choice if you aren't sure what to choose, it has a good speed/quality
balance.
**Note**: Cubic filtering is missing from the list; hyperbolic
interpolation is just as fast and results in higher quality.</doc>
<member name="nearest" value="0" c:identifier="GDK_INTERP_NEAREST" glib:nick="nearest" glib:name="GDK_INTERP_NEAREST">
<doc xml:space="preserve">Nearest neighbor sampling; this is the fastest
and lowest quality mode. Quality is normally unacceptable when scaling
down, but may be OK when scaling up.</doc>
</member>
<member name="tiles" value="1" c:identifier="GDK_INTERP_TILES" glib:nick="tiles" glib:name="GDK_INTERP_TILES">
<doc xml:space="preserve">This is an accurate simulation of the PostScript
image operator without any interpolation enabled. Each pixel is
rendered as a tiny parallelogram of solid color, the edges of which
are implemented with antialiasing. It resembles nearest neighbor for
enlargement, and bilinear for reduction.</doc>
</member>
<member name="bilinear" value="2" c:identifier="GDK_INTERP_BILINEAR" glib:nick="bilinear" glib:name="GDK_INTERP_BILINEAR">
<doc xml:space="preserve">Best quality/speed balance; use this mode by
default. Bilinear interpolation. For enlargement, it is
equivalent to point-sampling the ideal bilinear-interpolated image.
For reduction, it is equivalent to laying down small tiles and
integrating over the coverage area.</doc>
</member>
<member name="hyper" value="3" c:identifier="GDK_INTERP_HYPER" glib:nick="hyper" glib:name="GDK_INTERP_HYPER">
<doc xml:space="preserve">This is the slowest and highest quality
reconstruction function. It is derived from the hyperbolic filters in
Wolberg's "Digital Image Warping", and is formally defined as the
hyperbolic-filter sampling the ideal hyperbolic-filter interpolated
image (the filter is designed to be idempotent for 1:1 pixel mapping).
**Deprecated**: this interpolation filter is deprecated, as in reality
it has a lower quality than the @GDK_INTERP_BILINEAR filter
(Since: 2.38)</doc>
</member>
</enumeration>
<function-macro name="PIXBUF" c:identifier="GDK_PIXBUF" introspectable="0">
<parameters>
<parameter name="object">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_ANIMATION" c:identifier="GDK_PIXBUF_ANIMATION" introspectable="0">
<parameters>
<parameter name="object">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_ANIMATION_CLASS" c:identifier="GDK_PIXBUF_ANIMATION_CLASS" introspectable="0">
<parameters>
<parameter name="klass">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_ANIMATION_GET_CLASS" c:identifier="GDK_PIXBUF_ANIMATION_GET_CLASS" introspectable="0">
<parameters>
<parameter name="obj">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_ANIMATION_ITER" c:identifier="GDK_PIXBUF_ANIMATION_ITER" introspectable="0">
<parameters>
<parameter name="object">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_ANIMATION_ITER_CLASS" c:identifier="GDK_PIXBUF_ANIMATION_ITER_CLASS" introspectable="0">
<parameters>
<parameter name="klass">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_ANIMATION_ITER_GET_CLASS" c:identifier="GDK_PIXBUF_ANIMATION_ITER_GET_CLASS" introspectable="0">
<parameters>
<parameter name="obj">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_CHECK_VERSION" c:identifier="GDK_PIXBUF_CHECK_VERSION" version="2.36" introspectable="0">
<doc xml:space="preserve">Macro to test the version of GdkPixbuf being compiled against.</doc>
<parameters>
<parameter name="major">
<doc xml:space="preserve">major version (e.g. 2 for version 2.34.0)</doc>
</parameter>
<parameter name="minor">
<doc xml:space="preserve">minor version (e.g. 34 for version 2.34.0)</doc>
</parameter>
<parameter name="micro">
<doc xml:space="preserve">micro version (e.g. 0 for version 2.34.0)</doc>
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_0_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_0_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_10_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_10_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_12_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_12_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_14_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_14_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_16_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_16_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_18_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_18_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_20_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_20_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_22_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_22_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_24_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_24_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_26_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_26_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_28_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_28_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_2_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_2_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_30_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_30_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_32_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_32_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_34_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_34_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_36_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_36_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_38_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_38_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_40_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_40_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_4_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_4_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_6_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_6_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_DEPRECATED_IN_2_8_FOR" c:identifier="GDK_PIXBUF_DEPRECATED_IN_2_8_FOR" introspectable="0">
<parameters>
<parameter name="f">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_LOADER" c:identifier="GDK_PIXBUF_LOADER" introspectable="0">
<parameters>
<parameter name="obj">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_LOADER_CLASS" c:identifier="GDK_PIXBUF_LOADER_CLASS" introspectable="0">
<parameters>
<parameter name="klass">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_LOADER_GET_CLASS" c:identifier="GDK_PIXBUF_LOADER_GET_CLASS" introspectable="0">
<parameters>
<parameter name="obj">
</parameter>
</parameters>
</function-macro>
<constant name="PIXBUF_MAJOR" value="2" c:type="GDK_PIXBUF_MAJOR">
<doc xml:space="preserve">Major version of gdk-pixbuf library, that is the "0" in
"0.8.2" for example.</doc>
<type name="gint" c:type="gint"/>
</constant>
<constant name="PIXBUF_MICRO" value="13" c:type="GDK_PIXBUF_MICRO">
<doc xml:space="preserve">Micro version of gdk-pixbuf library, that is the "2" in
"0.8.2" for example.</doc>
<type name="gint" c:type="gint"/>
</constant>
<constant name="PIXBUF_MINOR" value="42" c:type="GDK_PIXBUF_MINOR">
<doc xml:space="preserve">Minor version of gdk-pixbuf library, that is the "8" in
"0.8.2" for example.</doc>
<type name="gint" c:type="gint"/>
</constant>
<function-macro name="PIXBUF_SIMPLE_ANIM" c:identifier="GDK_PIXBUF_SIMPLE_ANIM" introspectable="0">
<parameters>
<parameter name="object">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_SIMPLE_ANIM_CLASS" c:identifier="GDK_PIXBUF_SIMPLE_ANIM_CLASS" introspectable="0">
<parameters>
<parameter name="klass">
</parameter>
</parameters>
</function-macro>
<function-macro name="PIXBUF_SIMPLE_ANIM_GET_CLASS" c:identifier="GDK_PIXBUF_SIMPLE_ANIM_GET_CLASS" introspectable="0">
<parameters>
<parameter name="obj">
</parameter>
</parameters>
</function-macro>
<constant name="PIXBUF_VERSION" value="2.42.13" c:type="GDK_PIXBUF_VERSION">
<doc xml:space="preserve">Contains the full version of GdkPixbuf as a string.
This is the version being compiled against; contrast with
`gdk_pixbuf_version`.</doc>
<type name="utf8" c:type="gchar*"/>
</constant>
<class name="Pixbuf" c:symbol-prefix="pixbuf" c:type="GdkPixbuf" parent="GObject.Object" glib:type-name="GdkPixbuf" glib:get-type="gdk_pixbuf_get_type">
<doc xml:space="preserve">A pixel buffer.
`GdkPixbuf` contains information about an image's pixel data,
its color space, bits per sample, width and height, and the
rowstride (the number of bytes between the start of one row
and the start of the next).
## Creating new `GdkPixbuf`
The most basic way to create a pixbuf is to wrap an existing pixel
buffer with a [[email protected]] instance. You can use the
[`[email protected]_from_data`] function to do this.
Every time you create a new `GdkPixbuf` instance for some data, you
will need to specify the destroy notification function that will be
called when the data buffer needs to be freed; this will happen when
a `GdkPixbuf` is finalized by the reference counting functions. If
you have a chunk of static data compiled into your application, you
can pass in `NULL` as the destroy notification function so that the
data will not be freed.
The [`[email protected]`] constructor function can be used
as a convenience to create a pixbuf with an empty buffer; this is
equivalent to allocating a data buffer using `malloc()` and then
wrapping it with `gdk_pixbuf_new_from_data()`. The `gdk_pixbuf_new()`
function will compute an optimal rowstride so that rendering can be
performed with an efficient algorithm.
As a special case, you can use the [`[email protected]_from_xpm_data`]
function to create a pixbuf from inline XPM image data.
You can also copy an existing pixbuf with the [[email protected]]
function. This is not the same as just acquiring a reference to
the old pixbuf instance: the copy function will actually duplicate
the pixel data in memory and create a new [class@Pixbuf] instance
for it.
## Reference counting
`GdkPixbuf` structures are reference counted. This means that an
application can share a single pixbuf among many parts of the
code. When a piece of the program needs to use a pixbuf, it should
acquire a reference to it by calling `g_object_ref()`; when it no
longer needs the pixbuf, it should release the reference it acquired
by calling `g_object_unref()`. The resources associated with a
`GdkPixbuf` will be freed when its reference count drops to zero.
Newly-created `GdkPixbuf` instances start with a reference count
of one.
## Image Data
Image data in a pixbuf is stored in memory in an uncompressed,
packed format. Rows in the image are stored top to bottom, and
in each row pixels are stored from left to right.
There may be padding at the end of a row.
The "rowstride" value of a pixbuf, as returned by [`[email protected]_rowstride`],
indicates the number of bytes between rows.
**NOTE**: If you are copying raw pixbuf data with `memcpy()` note that the
last row in the pixbuf may not be as wide as the full rowstride, but rather
just as wide as the pixel data needs to be; that is: it is unsafe to do
`memcpy (dest, pixels, rowstride * height)` to copy a whole pixbuf. Use
[[email protected]] instead, or compute the width in bytes of the
last row as:
```c
last_row = width * ((n_channels * bits_per_sample + 7) / 8);
```
The same rule applies when iterating over each row of a `GdkPixbuf` pixels
array.
The following code illustrates a simple `put_pixel()`
function for RGB pixbufs with 8 bits per channel with an alpha
channel.
```c
static void
put_pixel (GdkPixbuf *pixbuf,
int x,
int y,
guchar red,
guchar green,
guchar blue,
guchar alpha)
{
int n_channels = gdk_pixbuf_get_n_channels (pixbuf);
// Ensure that the pixbuf is valid
g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
g_assert (gdk_pixbuf_get_has_alpha (pixbuf));
g_assert (n_channels == 4);
int width = gdk_pixbuf_get_width (pixbuf);
int height = gdk_pixbuf_get_height (pixbuf);
// Ensure that the coordinates are in a valid range
g_assert (x >= 0 && x < width);
g_assert (y >= 0 && y < height);
int rowstride = gdk_pixbuf_get_rowstride (pixbuf);
// The pixel buffer in the GdkPixbuf instance
guchar *pixels = gdk_pixbuf_get_pixels (pixbuf);
// The pixel we wish to modify
guchar *p = pixels + y * rowstride + x * n_channels;
p[0] = red;
p[1] = green;
p[2] = blue;
p[3] = alpha;
}
```
## Loading images
The `GdkPixBuf` class provides a simple mechanism for loading
an image from a file in synchronous and asynchronous fashion.
For GUI applications, it is recommended to use the asynchronous
stream API to avoid blocking the control flow of the application.
Additionally, `GdkPixbuf` provides the [[email protected]`]
API for progressive image loading.
## Saving images
The `GdkPixbuf` class provides methods for saving image data in
a number of file formats. The formatted data can be written to a
file or to a memory buffer. `GdkPixbuf` can also call a user-defined
callback on the data, which allows to e.g. write the image
to a socket or store it in a database.</doc>
<implements name="Gio.Icon"/>
<implements name="Gio.LoadableIcon"/>
<constructor name="new" c:identifier="gdk_pixbuf_new">
<doc xml:space="preserve">Creates a new `GdkPixbuf` structure and allocates a buffer for it.
If the allocation of the buffer failed, this function will return `NULL`.
The buffer has an optimal rowstride. Note that the buffer is not cleared;
you will have to fill it completely yourself.</doc>
<return-value transfer-ownership="full" nullable="1">
<doc xml:space="preserve">A newly-created pixel buffer</doc>
<type name="Pixbuf" c:type="GdkPixbuf*"/>
</return-value>
<parameters>
<parameter name="colorspace" transfer-ownership="none">
<doc xml:space="preserve">Color space for image</doc>
<type name="Colorspace" c:type="GdkColorspace"/>
</parameter>
<parameter name="has_alpha" transfer-ownership="none">
<doc xml:space="preserve">Whether the image should have transparency information</doc>
<type name="gboolean" c:type="gboolean"/>
</parameter>
<parameter name="bits_per_sample" transfer-ownership="none">
<doc xml:space="preserve">Number of bits per color sample</doc>
<type name="gint" c:type="int"/>
</parameter>
<parameter name="width" transfer-ownership="none">
<doc xml:space="preserve">Width of image in pixels, must be > 0</doc>
<type name="gint" c:type="int"/>
</parameter>
<parameter name="height" transfer-ownership="none">
<doc xml:space="preserve">Height of image in pixels, must be > 0</doc>
<type name="gint" c:type="int"/>
</parameter>
</parameters>
</constructor>
<constructor name="new_from_bytes" c:identifier="gdk_pixbuf_new_from_bytes" version="2.32">
<doc xml:space="preserve">Creates a new #GdkPixbuf out of in-memory readonly image data.
Currently only RGB images with 8 bits per sample are supported.
This is the `GBytes` variant of gdk_pixbuf_new_from_data(), useful
for language bindings.</doc>
<return-value transfer-ownership="full">
<doc xml:space="preserve">A newly-created pixbuf</doc>
<type name="Pixbuf" c:type="GdkPixbuf*"/>
</return-value>
<parameters>
<parameter name="data" transfer-ownership="none">
<doc xml:space="preserve">Image data in 8-bit/sample packed format inside a #GBytes</doc>
<type name="GLib.Bytes" c:type="GBytes*"/>
</parameter>
<parameter name="colorspace" transfer-ownership="none">
<doc xml:space="preserve">Colorspace for the image data</doc>
<type name="Colorspace" c:type="GdkColorspace"/>
</parameter>
<parameter name="has_alpha" transfer-ownership="none">
<doc xml:space="preserve">Whether the data has an opacity channel</doc>
<type name="gboolean" c:type="gboolean"/>
</parameter>
<parameter name="bits_per_sample" transfer-ownership="none">
<doc xml:space="preserve">Number of bits per sample</doc>
<type name="gint" c:type="int"/>
</parameter>
<parameter name="width" transfer-ownership="none">
<doc xml:space="preserve">Width of the image in pixels, must be > 0</doc>
<type name="gint" c:type="int"/>
</parameter>
<parameter name="height" transfer-ownership="none">
<doc xml:space="preserve">Height of the image in pixels, must be > 0</doc>
<type name="gint" c:type="int"/>
</parameter>
<parameter name="rowstride" transfer-ownership="none">
<doc xml:space="preserve">Distance in bytes between row starts</doc>
<type name="gint" c:type="int"/>
</parameter>
</parameters>
</constructor>
<constructor name="new_from_data" c:identifier="gdk_pixbuf_new_from_data">
<doc xml:space="preserve">Creates a new #GdkPixbuf out of in-memory image data.
Currently only RGB images with 8 bits per sample are supported.
Since you are providing a pre-allocated pixel buffer, you must also
specify a way to free that data. This is done with a function of
type `GdkPixbufDestroyNotify`. When a pixbuf created with is
finalized, your destroy notification function will be called, and
it is its responsibility to free the pixel array.
See also: [[email protected]_from_bytes]</doc>
<return-value transfer-ownership="full">
<doc xml:space="preserve">A newly-created pixbuf</doc>
<type name="Pixbuf" c:type="GdkPixbuf*"/>
</return-value>
<parameters>
<parameter name="data" transfer-ownership="none">
<doc xml:space="preserve">Image data in 8-bit/sample packed format</doc>
<array zero-terminated="0" c:type="const guchar*">
<type name="guint8" c:type="guchar"/>
</array>
</parameter>
<parameter name="colorspace" transfer-ownership="none">
<doc xml:space="preserve">Colorspace for the image data</doc>
<type name="Colorspace" c:type="GdkColorspace"/>
</parameter>
<parameter name="has_alpha" transfer-ownership="none">
<doc xml:space="preserve">Whether the data has an opacity channel</doc>
<type name="gboolean" c:type="gboolean"/>
</parameter>
<parameter name="bits_per_sample" transfer-ownership="none">
<doc xml:space="preserve">Number of bits per sample</doc>
<type name="gint" c:type="int"/>
</parameter>
<parameter name="width" transfer-ownership="none">
<doc xml:space="preserve">Width of the image in pixels, must be > 0</doc>
<type name="gint" c:type="int"/>
</parameter>
<parameter name="height" transfer-ownership="none">
<doc xml:space="preserve">Height of the image in pixels, must be > 0</doc>
<type name="gint" c:type="int"/>
</parameter>
<parameter name="rowstride" transfer-ownership="none">
<doc xml:space="preserve">Distance in bytes between row starts</doc>
<type name="gint" c:type="int"/>
</parameter>
<parameter name="destroy_fn" transfer-ownership="none" nullable="1" allow-none="1" scope="async" closure="8">
<doc xml:space="preserve">Function used to free the data when the pixbuf's reference count
drops to zero, or %NULL if the data should not be freed</doc>
<type name="PixbufDestroyNotify" c:type="GdkPixbufDestroyNotify"/>
</parameter>
<parameter name="destroy_fn_data" transfer-ownership="none" nullable="1" allow-none="1">
<doc xml:space="preserve">Closure data to pass to the destroy notification function</doc>
<type name="gpointer" c:type="gpointer"/>
</parameter>
</parameters>
</constructor>
<constructor name="new_from_file" c:identifier="gdk_pixbuf_new_from_file" throws="1">
<doc xml:space="preserve">Creates a new pixbuf by loading an image from a file.
The file format is detected automatically.
If `NULL` is returned, then @error will be set. Possible errors are:
- the file could not be opened
- there is no loader for the file's format
- there is not enough memory to allocate the image buffer
- the image buffer contains invalid data
The error domains are `GDK_PIXBUF_ERROR` and `G_FILE_ERROR`.</doc>
<return-value transfer-ownership="full" nullable="1">
<doc xml:space="preserve">A newly-created pixbuf</doc>
<type name="Pixbuf" c:type="GdkPixbuf*"/>
</return-value>
<parameters>
<parameter name="filename" transfer-ownership="none">
<doc xml:space="preserve">Name of file to load, in the GLib file
name encoding</doc>
<type name="filename" c:type="const char*"/>
</parameter>
</parameters>
</constructor>
<constructor name="new_from_file_at_scale" c:identifier="gdk_pixbuf_new_from_file_at_scale" version="2.6" throws="1">
<doc xml:space="preserve">Creates a new pixbuf by loading an image from a file.
The file format is detected automatically.
If `NULL` is returned, then @error will be set. Possible errors are:
- the file could not be opened
- there is no loader for the file's format
- there is not enough memory to allocate the image buffer
- the image buffer contains invalid data
The error domains are `GDK_PIXBUF_ERROR` and `G_FILE_ERROR`.
The image will be scaled to fit in the requested size, optionally preserving
the image's aspect ratio.
When preserving the aspect ratio, a `width` of -1 will cause the image
to be scaled to the exact given height, and a `height` of -1 will cause
the image to be scaled to the exact given width. When not preserving
aspect ratio, a `width` or `height` of -1 means to not scale the image
at all in that dimension. Negative values for `width` and `height` are
allowed since 2.8.</doc>
<return-value transfer-ownership="full" nullable="1">
<doc xml:space="preserve">A newly-created pixbuf</doc>
<type name="Pixbuf" c:type="GdkPixbuf*"/>
</return-value>
<parameters>
<parameter name="filename" transfer-ownership="none">
<doc xml:space="preserve">Name of file to load, in the GLib file
name encoding</doc>
<type name="filename" c:type="const char*"/>
</parameter>
<parameter name="width" transfer-ownership="none">
<doc xml:space="preserve">The width the image should have or -1 to not constrain the width</doc>
<type name="gint" c:type="int"/>
</parameter>
<parameter name="height" transfer-ownership="none">
<doc xml:space="preserve">The height the image should have or -1 to not constrain the height</doc>
<type name="gint" c:type="int"/>
</parameter>
<parameter name="preserve_aspect_ratio" transfer-ownership="none">
<doc xml:space="preserve">`TRUE` to preserve the image's aspect ratio</doc>
<type name="gboolean" c:type="gboolean"/>
</parameter>
</parameters>
</constructor>
<constructor name="new_from_file_at_size" c:identifier="gdk_pixbuf_new_from_file_at_size" version="2.4" throws="1">
<doc xml:space="preserve">Creates a new pixbuf by loading an image from a file.
The file format is detected automatically.
If `NULL` is returned, then @error will be set. Possible errors are:
- the file could not be opened
- there is no loader for the file's format
- there is not enough memory to allocate the image buffer
- the image buffer contains invalid data
The error domains are `GDK_PIXBUF_ERROR` and `G_FILE_ERROR`.
The image will be scaled to fit in the requested size, preserving
the image's aspect ratio. Note that the returned pixbuf may be smaller
than `width` x `height`, if the aspect ratio requires it. To load
and image at the requested size, regardless of aspect ratio, use
[[email protected]_from_file_at_scale].</doc>
<return-value transfer-ownership="full" nullable="1">
<doc xml:space="preserve">A newly-created pixbuf</doc>
<type name="Pixbuf" c:type="GdkPixbuf*"/>
</return-value>
<parameters>
<parameter name="filename" transfer-ownership="none">
<doc xml:space="preserve">Name of file to load, in the GLib file
name encoding</doc>
<type name="filename" c:type="const char*"/>
</parameter>
<parameter name="width" transfer-ownership="none">
<doc xml:space="preserve">The width the image should have or -1 to not constrain the width</doc>
<type name="gint" c:type="int"/>
</parameter>
<parameter name="height" transfer-ownership="none">
<doc xml:space="preserve">The height the image should have or -1 to not constrain the height</doc>
<type name="gint" c:type="int"/>
</parameter>
</parameters>
</constructor>
<constructor name="new_from_inline" c:identifier="gdk_pixbuf_new_from_inline" deprecated="1" deprecated-version="2.32" throws="1">
<doc xml:space="preserve">Creates a `GdkPixbuf` from a flat representation that is suitable for
storing as inline data in a program.
This is useful if you want to ship a program with images, but don't want
to depend on any external files.
GdkPixbuf ships with a program called `gdk-pixbuf-csource`, which allows
for conversion of `GdkPixbuf`s into such a inline representation.
In almost all cases, you should pass the `--raw` option to
`gdk-pixbuf-csource`. A sample invocation would be:
```
gdk-pixbuf-csource --raw --name=myimage_inline myimage.png
```
For the typical case where the inline pixbuf is read-only static data,
you don't need to copy the pixel data unless you intend to write to
it, so you can pass `FALSE` for `copy_pixels`. If you pass `--rle` to
`gdk-pixbuf-csource`, a copy will be made even if `copy_pixels` is `FALSE`,
so using this option is generally a bad idea.
If you create a pixbuf from const inline data compiled into your
program, it's probably safe to ignore errors and disable length checks,
since things will always succeed:
```c
pixbuf = gdk_pixbuf_new_from_inline (-1, myimage_inline, FALSE, NULL);
```
For non-const inline data, you could get out of memory. For untrusted
inline data located at runtime, you could have corrupt inline data in
addition.</doc>
<doc-deprecated xml:space="preserve">Use `GResource` instead.</doc-deprecated>
<return-value transfer-ownership="full">
<doc xml:space="preserve">A newly-created pixbuf</doc>
<type name="Pixbuf" c:type="GdkPixbuf*"/>
</return-value>
<parameters>
<parameter name="data_length" transfer-ownership="none">
<doc xml:space="preserve">Length in bytes of the `data` argument or -1 to
disable length checks</doc>
<type name="gint" c:type="gint"/>
</parameter>
<parameter name="data" transfer-ownership="none">
<doc xml:space="preserve">Byte data containing a
serialized `GdkPixdata` structure</doc>
<array length="0" zero-terminated="0" c:type="const guint8*">
<type name="guint8" c:type="guint8"/>
</array>
</parameter>
<parameter name="copy_pixels" transfer-ownership="none">
<doc xml:space="preserve">Whether to copy the pixel data, or use direct pointers
`data` for the resulting pixbuf</doc>
<type name="gboolean" c:type="gboolean"/>
</parameter>
</parameters>
</constructor>
<constructor name="new_from_resource" c:identifier="gdk_pixbuf_new_from_resource" version="2.26" throws="1">
<doc xml:space="preserve">Creates a new pixbuf by loading an image from an resource.
The file format is detected automatically. If `NULL` is returned, then
@error will be set.</doc>
<return-value transfer-ownership="full" nullable="1">
<doc xml:space="preserve">A newly-created pixbuf</doc>
<type name="Pixbuf" c:type="GdkPixbuf*"/>
</return-value>
<parameters>
<parameter name="resource_path" transfer-ownership="none">
<doc xml:space="preserve">the path of the resource file</doc>
<type name="utf8" c:type="const char*"/>
</parameter>
</parameters>
</constructor>
<constructor name="new_from_resource_at_scale" c:identifier="gdk_pixbuf_new_from_resource_at_scale" version="2.26" throws="1">
<doc xml:space="preserve">Creates a new pixbuf by loading an image from an resource.
The file format is detected automatically. If `NULL` is returned, then
@error will be set.
The image will be scaled to fit in the requested size, optionally
preserving the image's aspect ratio. When preserving the aspect ratio,
a @width of -1 will cause the image to be scaled to the exact given
height, and a @height of -1 will cause the image to be scaled to the
exact given width. When not preserving aspect ratio, a @width or
@height of -1 means to not scale the image at all in that dimension.
The stream is not closed.</doc>
<return-value transfer-ownership="full" nullable="1">
<doc xml:space="preserve">A newly-created pixbuf</doc>
<type name="Pixbuf" c:type="GdkPixbuf*"/>
</return-value>
<parameters>
<parameter name="resource_path" transfer-ownership="none">
<doc xml:space="preserve">the path of the resource file</doc>
<type name="utf8" c:type="const char*"/>
</parameter>
<parameter name="width" transfer-ownership="none">
<doc xml:space="preserve">The width the image should have or -1 to not constrain the width</doc>
<type name="gint" c:type="int"/>
</parameter>
<parameter name="height" transfer-ownership="none">
<doc xml:space="preserve">The height the image should have or -1 to not constrain the height</doc>
<type name="gint" c:type="int"/>
</parameter>
<parameter name="preserve_aspect_ratio" transfer-ownership="none">
<doc xml:space="preserve">`TRUE` to preserve the image's aspect ratio</doc>
<type name="gboolean" c:type="gboolean"/>
</parameter>
</parameters>
</constructor>
<constructor name="new_from_stream" c:identifier="gdk_pixbuf_new_from_stream" version="2.14" throws="1">
<doc xml:space="preserve">Creates a new pixbuf by loading an image from an input stream.
The file format is detected automatically.
If `NULL` is returned, then `error` will be set.
The `cancellable` can be used to abort the operation from another thread.
If the operation was cancelled, the error `G_IO_ERROR_CANCELLED` will be
returned. Other possible errors are in the `GDK_PIXBUF_ERROR` and
`G_IO_ERROR` domains.
The stream is not closed.</doc>
<return-value transfer-ownership="full" nullable="1">
<doc xml:space="preserve">A newly-created pixbuf</doc>
<type name="Pixbuf" c:type="GdkPixbuf*"/>
</return-value>
<parameters>
<parameter name="stream" transfer-ownership="none">
<doc xml:space="preserve">a `GInputStream` to load the pixbuf from</doc>
<type name="Gio.InputStream" c:type="GInputStream*"/>
</parameter>
<parameter name="cancellable" transfer-ownership="none" nullable="1" allow-none="1">
<doc xml:space="preserve">optional `GCancellable` object, `NULL` to ignore</doc>
<type name="Gio.Cancellable" c:type="GCancellable*"/>
</parameter>
</parameters>
</constructor>
<constructor name="new_from_stream_at_scale" c:identifier="gdk_pixbuf_new_from_stream_at_scale" version="2.14" throws="1">
<doc xml:space="preserve">Creates a new pixbuf by loading an image from an input stream.
The file format is detected automatically. If `NULL` is returned, then
@error will be set. The @cancellable can be used to abort the operation
from another thread. If the operation was cancelled, the error
`G_IO_ERROR_CANCELLED` will be returned. Other possible errors are in
the `GDK_PIXBUF_ERROR` and `G_IO_ERROR` domains.
The image will be scaled to fit in the requested size, optionally
preserving the image's aspect ratio.
When preserving the aspect ratio, a `width` of -1 will cause the image to be
scaled to the exact given height, and a `height` of -1 will cause the image
to be scaled to the exact given width. If both `width` and `height` are
given, this function will behave as if the smaller of the two values
is passed as -1.
When not preserving aspect ratio, a `width` or `height` of -1 means to not
scale the image at all in that dimension.
The stream is not closed.</doc>
<return-value transfer-ownership="full" nullable="1">
<doc xml:space="preserve">A newly-created pixbuf</doc>
<type name="Pixbuf" c:type="GdkPixbuf*"/>
</return-value>
<parameters>
<parameter name="stream" transfer-ownership="none">
<doc xml:space="preserve">a `GInputStream` to load the pixbuf from</doc>
<type name="Gio.InputStream" c:type="GInputStream*"/>
</parameter>
<parameter name="width" transfer-ownership="none">
<doc xml:space="preserve">The width the image should have or -1 to not constrain the width</doc>
<type name="gint" c:type="gint"/>
</parameter>
<parameter name="height" transfer-ownership="none">
<doc xml:space="preserve">The height the image should have or -1 to not constrain the height</doc>
<type name="gint" c:type="gint"/>
</parameter>
<parameter name="preserve_aspect_ratio" transfer-ownership="none">
<doc xml:space="preserve">`TRUE` to preserve the image's aspect ratio</doc>
<type name="gboolean" c:type="gboolean"/>
</parameter>
<parameter name="cancellable" transfer-ownership="none" nullable="1" allow-none="1">
<doc xml:space="preserve">optional `GCancellable` object, `NULL` to ignore</doc>
<type name="Gio.Cancellable" c:type="GCancellable*"/>
</parameter>
</parameters>
</constructor>
<constructor name="new_from_stream_finish" c:identifier="gdk_pixbuf_new_from_stream_finish" version="2.24" throws="1">
<doc xml:space="preserve">Finishes an asynchronous pixbuf creation operation started with
gdk_pixbuf_new_from_stream_async().</doc>
<return-value transfer-ownership="full" nullable="1">
<doc xml:space="preserve">the newly created pixbuf</doc>
<type name="Pixbuf" c:type="GdkPixbuf*"/>
</return-value>
<parameters>
<parameter name="async_result" transfer-ownership="none">
<doc xml:space="preserve">a `GAsyncResult`</doc>
<type name="Gio.AsyncResult" c:type="GAsyncResult*"/>
</parameter>
</parameters>
</constructor>
<constructor name="new_from_xpm_data" c:identifier="gdk_pixbuf_new_from_xpm_data">
<doc xml:space="preserve">Creates a new pixbuf by parsing XPM data in memory.
This data is commonly the result of including an XPM file into a
program's C source.</doc>
<return-value transfer-ownership="full" nullable="1">
<doc xml:space="preserve">A newly-created pixbuf</doc>
<type name="Pixbuf" c:type="GdkPixbuf*"/>
</return-value>
<parameters>
<parameter name="data" transfer-ownership="none">
<doc xml:space="preserve">Pointer to inline XPM data.</doc>
<array c:type="const char**">
<type name="utf8" c:type="char*"/>
</array>
</parameter>
</parameters>
</constructor>
<function name="calculate_rowstride" c:identifier="gdk_pixbuf_calculate_rowstride" version="2.36.8">
<doc xml:space="preserve">Calculates the rowstride that an image created with those values would
have.
This function is useful for front-ends and backends that want to check
image values without needing to create a `GdkPixbuf`.</doc>
<return-value transfer-ownership="none">
<doc xml:space="preserve">the rowstride for the given values, or -1 in case of error.</doc>
<type name="gint" c:type="gint"/>
</return-value>
<parameters>
<parameter name="colorspace" transfer-ownership="none">
<doc xml:space="preserve">Color space for image</doc>
<type name="Colorspace" c:type="GdkColorspace"/>
</parameter>
<parameter name="has_alpha" transfer-ownership="none">
<doc xml:space="preserve">Whether the image should have transparency information</doc>
<type name="gboolean" c:type="gboolean"/>
</parameter>
<parameter name="bits_per_sample" transfer-ownership="none">
<doc xml:space="preserve">Number of bits per color sample</doc>
<type name="gint" c:type="int"/>
</parameter>
<parameter name="width" transfer-ownership="none">
<doc xml:space="preserve">Width of image in pixels, must be > 0</doc>
<type name="gint" c:type="int"/>
</parameter>
<parameter name="height" transfer-ownership="none">
<doc xml:space="preserve">Height of image in pixels, must be > 0</doc>
<type name="gint" c:type="int"/>
</parameter>
</parameters>
</function>
<function name="get_file_info" c:identifier="gdk_pixbuf_get_file_info" version="2.4" glib:async-func="get_file_info_async">
<doc xml:space="preserve">Parses an image file far enough to determine its format and size.</doc>
<return-value transfer-ownership="none" nullable="1">
<doc xml:space="preserve">A `GdkPixbufFormat` describing
the image format of the file</doc>
<type name="PixbufFormat" c:type="GdkPixbufFormat*"/>
</return-value>
<parameters>
<parameter name="filename" transfer-ownership="none">
<doc xml:space="preserve">The name of the file to identify.</doc>