gdk_pixbuf/auto/
pixbuf.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, Colorspace, InterpType, PixbufFormat, PixbufRotation};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// A pixel buffer.
10    ///
11    /// [`Pixbuf`][crate::Pixbuf] contains information about an image's pixel data,
12    /// its color space, bits per sample, width and height, and the
13    /// rowstride (the number of bytes between the start of one row
14    /// and the start of the next).
15    ///
16    /// ## Creating new [`Pixbuf`][crate::Pixbuf]
17    ///
18    /// The most basic way to create a pixbuf is to wrap an existing pixel
19    /// buffer with a [`Pixbuf`][crate::Pixbuf] instance. You can use the
20    /// [`ctor@GdkPixbuf.Pixbuf.new_from_data`] function to do this.
21    ///
22    /// Every time you create a new [`Pixbuf`][crate::Pixbuf] instance for some data, you
23    /// will need to specify the destroy notification function that will be
24    /// called when the data buffer needs to be freed; this will happen when
25    /// a [`Pixbuf`][crate::Pixbuf] is finalized by the reference counting functions. If
26    /// you have a chunk of static data compiled into your application, you
27    /// can pass in `NULL` as the destroy notification function so that the
28    /// data will not be freed.
29    ///
30    /// The [`ctor@GdkPixbuf.Pixbuf.new`] constructor function can be used
31    /// as a convenience to create a pixbuf with an empty buffer; this is
32    /// equivalent to allocating a data buffer using `malloc()` and then
33    /// wrapping it with `gdk_pixbuf_new_from_data()`. The `gdk_pixbuf_new()`
34    /// function will compute an optimal rowstride so that rendering can be
35    /// performed with an efficient algorithm.
36    ///
37    /// As a special case, you can use the [`ctor@GdkPixbuf.Pixbuf.new_from_xpm_data`]
38    /// function to create a pixbuf from inline XPM image data.
39    ///
40    /// You can also copy an existing pixbuf with the `Pixbuf::copy()`
41    /// function. This is not the same as just acquiring a reference to
42    /// the old pixbuf instance: the copy function will actually duplicate
43    /// the pixel data in memory and create a new [`Pixbuf`][crate::Pixbuf] instance
44    /// for it.
45    ///
46    /// ## Reference counting
47    ///
48    /// [`Pixbuf`][crate::Pixbuf] structures are reference counted. This means that an
49    /// application can share a single pixbuf among many parts of the
50    /// code. When a piece of the program needs to use a pixbuf, it should
51    /// acquire a reference to it by calling `g_object_ref()`; when it no
52    /// longer needs the pixbuf, it should release the reference it acquired
53    /// by calling `g_object_unref()`. The resources associated with a
54    /// [`Pixbuf`][crate::Pixbuf] will be freed when its reference count drops to zero.
55    /// Newly-created [`Pixbuf`][crate::Pixbuf] instances start with a reference count
56    /// of one.
57    ///
58    /// ## Image Data
59    ///
60    /// Image data in a pixbuf is stored in memory in an uncompressed,
61    /// packed format. Rows in the image are stored top to bottom, and
62    /// in each row pixels are stored from left to right.
63    ///
64    /// There may be padding at the end of a row.
65    ///
66    /// The "rowstride" value of a pixbuf, as returned by [`method@GdkPixbuf.Pixbuf.get_rowstride`],
67    /// indicates the number of bytes between rows.
68    ///
69    /// **NOTE**: If you are copying raw pixbuf data with `memcpy()` note that the
70    /// last row in the pixbuf may not be as wide as the full rowstride, but rather
71    /// just as wide as the pixel data needs to be; that is: it is unsafe to do
72    /// `memcpy (dest, pixels, rowstride * height)` to copy a whole pixbuf. Use
73    /// `GdkPixbuf::Pixbuf::copy()` instead, or compute the width in bytes of the
74    /// last row as:
75    ///
76    /// **⚠️ The following code is in c ⚠️**
77    ///
78    /// ```c
79    /// last_row = width * ((n_channels * bits_per_sample + 7) / 8);
80    /// ```
81    ///
82    /// The same rule applies when iterating over each row of a [`Pixbuf`][crate::Pixbuf] pixels
83    /// array.
84    ///
85    /// The following code illustrates a simple `put_pixel()`
86    /// function for RGB pixbufs with 8 bits per channel with an alpha
87    /// channel.
88    ///
89    /// **⚠️ The following code is in c ⚠️**
90    ///
91    /// ```c
92    /// static void
93    /// put_pixel (GdkPixbuf *pixbuf,
94    ///            int x,
95    ///        int y,
96    ///        guchar red,
97    ///        guchar green,
98    ///        guchar blue,
99    ///        guchar alpha)
100    /// {
101    ///   int n_channels = gdk_pixbuf_get_n_channels (pixbuf);
102    ///
103    ///   // Ensure that the pixbuf is valid
104    ///   g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
105    ///   g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
106    ///   g_assert (gdk_pixbuf_get_has_alpha (pixbuf));
107    ///   g_assert (n_channels == 4);
108    ///
109    ///   int width = gdk_pixbuf_get_width (pixbuf);
110    ///   int height = gdk_pixbuf_get_height (pixbuf);
111    ///
112    ///   // Ensure that the coordinates are in a valid range
113    ///   g_assert (x >= 0 && x < width);
114    ///   g_assert (y >= 0 && y < height);
115    ///
116    ///   int rowstride = gdk_pixbuf_get_rowstride (pixbuf);
117    ///
118    ///   // The pixel buffer in the GdkPixbuf instance
119    ///   guchar *pixels = gdk_pixbuf_get_pixels (pixbuf);
120    ///
121    ///   // The pixel we wish to modify
122    ///   guchar *p = pixels + y * rowstride + x * n_channels;
123    ///   p[0] = red;
124    ///   p[1] = green;
125    ///   p[2] = blue;
126    ///   p[3] = alpha;
127    /// }
128    /// ```
129    ///
130    /// ## Loading images
131    ///
132    /// The `GdkPixBuf` class provides a simple mechanism for loading
133    /// an image from a file in synchronous and asynchronous fashion.
134    ///
135    /// For GUI applications, it is recommended to use the asynchronous
136    /// stream API to avoid blocking the control flow of the application.
137    ///
138    /// Additionally, [`Pixbuf`][crate::Pixbuf] provides the [`PixbufLoader`][crate::PixbufLoader]`]
139    /// API for progressive image loading.
140    ///
141    /// ## Saving images
142    ///
143    /// The [`Pixbuf`][crate::Pixbuf] class provides methods for saving image data in
144    /// a number of file formats. The formatted data can be written to a
145    /// file or to a memory buffer. [`Pixbuf`][crate::Pixbuf] can also call a user-defined
146    /// callback on the data, which allows to e.g. write the image
147    /// to a socket or store it in a database.
148    ///
149    /// ## Properties
150    ///
151    ///
152    /// #### `bits-per-sample`
153    ///  The number of bits per sample.
154    ///
155    /// Currently only 8 bit per sample are supported.
156    ///
157    /// Readable | Writeable | Construct Only
158    ///
159    ///
160    /// #### `colorspace`
161    ///  The color space of the pixbuf.
162    ///
163    /// Currently, only `GDK_COLORSPACE_RGB` is supported.
164    ///
165    /// Readable | Writeable | Construct Only
166    ///
167    ///
168    /// #### `has-alpha`
169    ///  Whether the pixbuf has an alpha channel.
170    ///
171    /// Readable | Writeable | Construct Only
172    ///
173    ///
174    /// #### `height`
175    ///  The number of rows of the pixbuf.
176    ///
177    /// Readable | Writeable | Construct Only
178    ///
179    ///
180    /// #### `n-channels`
181    ///  The number of samples per pixel.
182    ///
183    /// Currently, only 3 or 4 samples per pixel are supported.
184    ///
185    /// Readable | Writeable | Construct Only
186    ///
187    ///
188    /// #### `pixel-bytes`
189    ///  Readable | Writeable | Construct Only
190    ///
191    ///
192    /// #### `pixels`
193    ///  A pointer to the pixel data of the pixbuf.
194    ///
195    /// Readable | Writeable | Construct Only
196    ///
197    ///
198    /// #### `rowstride`
199    ///  The number of bytes between the start of a row and
200    /// the start of the next row.
201    ///
202    /// This number must (obviously) be at least as large as the
203    /// width of the pixbuf.
204    ///
205    /// Readable | Writeable | Construct Only
206    ///
207    ///
208    /// #### `width`
209    ///  The number of columns of the pixbuf.
210    ///
211    /// Readable | Writeable | Construct Only
212    ///
213    /// # Implements
214    ///
215    /// [`trait@gio::prelude::IconExt`], [`trait@gio::prelude::LoadableIconExt`]
216    #[doc(alias = "GdkPixbuf")]
217    pub struct Pixbuf(Object<ffi::GdkPixbuf>) @implements gio::Icon, gio::LoadableIcon;
218
219    match fn {
220        type_ => || ffi::gdk_pixbuf_get_type(),
221    }
222}
223
224impl Pixbuf {
225    /// Creates a new [`Pixbuf`][crate::Pixbuf] structure and allocates a buffer for it.
226    ///
227    /// If the allocation of the buffer failed, this function will return `NULL`.
228    ///
229    /// The buffer has an optimal rowstride. Note that the buffer is not cleared;
230    /// you will have to fill it completely yourself.
231    /// ## `colorspace`
232    /// Color space for image
233    /// ## `has_alpha`
234    /// Whether the image should have transparency information
235    /// ## `bits_per_sample`
236    /// Number of bits per color sample
237    /// ## `width`
238    /// Width of image in pixels, must be > 0
239    /// ## `height`
240    /// Height of image in pixels, must be > 0
241    ///
242    /// # Returns
243    ///
244    /// A newly-created pixel buffer
245    #[doc(alias = "gdk_pixbuf_new")]
246    pub fn new(
247        colorspace: Colorspace,
248        has_alpha: bool,
249        bits_per_sample: i32,
250        width: i32,
251        height: i32,
252    ) -> Option<Pixbuf> {
253        unsafe {
254            from_glib_full(ffi::gdk_pixbuf_new(
255                colorspace.into_glib(),
256                has_alpha.into_glib(),
257                bits_per_sample,
258                width,
259                height,
260            ))
261        }
262    }
263
264    /// Creates a new #GdkPixbuf out of in-memory readonly image data.
265    ///
266    /// Currently only RGB images with 8 bits per sample are supported.
267    ///
268    /// This is the `GBytes` variant of gdk_pixbuf_new_from_data(), useful
269    /// for language bindings.
270    /// ## `data`
271    /// Image data in 8-bit/sample packed format inside a #GBytes
272    /// ## `colorspace`
273    /// Colorspace for the image data
274    /// ## `has_alpha`
275    /// Whether the data has an opacity channel
276    /// ## `bits_per_sample`
277    /// Number of bits per sample
278    /// ## `width`
279    /// Width of the image in pixels, must be > 0
280    /// ## `height`
281    /// Height of the image in pixels, must be > 0
282    /// ## `rowstride`
283    /// Distance in bytes between row starts
284    ///
285    /// # Returns
286    ///
287    /// A newly-created pixbuf
288    #[doc(alias = "gdk_pixbuf_new_from_bytes")]
289    #[doc(alias = "new_from_bytes")]
290    pub fn from_bytes(
291        data: &glib::Bytes,
292        colorspace: Colorspace,
293        has_alpha: bool,
294        bits_per_sample: i32,
295        width: i32,
296        height: i32,
297        rowstride: i32,
298    ) -> Pixbuf {
299        unsafe {
300            from_glib_full(ffi::gdk_pixbuf_new_from_bytes(
301                data.to_glib_none().0,
302                colorspace.into_glib(),
303                has_alpha.into_glib(),
304                bits_per_sample,
305                width,
306                height,
307                rowstride,
308            ))
309        }
310    }
311
312    //#[doc(alias = "gdk_pixbuf_new_from_data")]
313    //#[doc(alias = "new_from_data")]
314    //pub fn from_data(data: &[u8], colorspace: Colorspace, has_alpha: bool, bits_per_sample: i32, width: i32, height: i32, rowstride: i32, destroy_fn: Option<Box_<dyn FnOnce(&Vec<u8>) + 'static>>) -> Pixbuf {
315    //    unsafe { TODO: call ffi:gdk_pixbuf_new_from_data() }
316    //}
317
318    /// Creates a new pixbuf by loading an image from a file.
319    ///
320    /// The file format is detected automatically.
321    ///
322    /// If `NULL` is returned, then @error will be set. Possible errors are:
323    ///
324    ///  - the file could not be opened
325    ///  - there is no loader for the file's format
326    ///  - there is not enough memory to allocate the image buffer
327    ///  - the image buffer contains invalid data
328    ///
329    /// The error domains are `GDK_PIXBUF_ERROR` and `G_FILE_ERROR`.
330    /// ## `filename`
331    /// Name of file to load, in the GLib file
332    ///   name encoding
333    ///
334    /// # Returns
335    ///
336    /// A newly-created pixbuf
337    #[doc(alias = "gdk_pixbuf_new_from_file")]
338    #[doc(alias = "new_from_file")]
339    pub fn from_file(filename: impl AsRef<std::path::Path>) -> Result<Pixbuf, glib::Error> {
340        unsafe {
341            let mut error = std::ptr::null_mut();
342            let ret = ffi::gdk_pixbuf_new_from_file(filename.as_ref().to_glib_none().0, &mut error);
343            if error.is_null() {
344                Ok(from_glib_full(ret))
345            } else {
346                Err(from_glib_full(error))
347            }
348        }
349    }
350
351    /// Creates a new pixbuf by loading an image from a file.
352    ///
353    /// The file format is detected automatically.
354    ///
355    /// If `NULL` is returned, then @error will be set. Possible errors are:
356    ///
357    ///  - the file could not be opened
358    ///  - there is no loader for the file's format
359    ///  - there is not enough memory to allocate the image buffer
360    ///  - the image buffer contains invalid data
361    ///
362    /// The error domains are `GDK_PIXBUF_ERROR` and `G_FILE_ERROR`.
363    ///
364    /// The image will be scaled to fit in the requested size, optionally preserving
365    /// the image's aspect ratio.
366    ///
367    /// When preserving the aspect ratio, a `width` of -1 will cause the image
368    /// to be scaled to the exact given height, and a `height` of -1 will cause
369    /// the image to be scaled to the exact given width. When not preserving
370    /// aspect ratio, a `width` or `height` of -1 means to not scale the image
371    /// at all in that dimension. Negative values for `width` and `height` are
372    /// allowed since 2.8.
373    /// ## `filename`
374    /// Name of file to load, in the GLib file
375    ///     name encoding
376    /// ## `width`
377    /// The width the image should have or -1 to not constrain the width
378    /// ## `height`
379    /// The height the image should have or -1 to not constrain the height
380    /// ## `preserve_aspect_ratio`
381    /// `TRUE` to preserve the image's aspect ratio
382    ///
383    /// # Returns
384    ///
385    /// A newly-created pixbuf
386    #[doc(alias = "gdk_pixbuf_new_from_file_at_scale")]
387    #[doc(alias = "new_from_file_at_scale")]
388    pub fn from_file_at_scale(
389        filename: impl AsRef<std::path::Path>,
390        width: i32,
391        height: i32,
392        preserve_aspect_ratio: bool,
393    ) -> Result<Pixbuf, glib::Error> {
394        unsafe {
395            let mut error = std::ptr::null_mut();
396            let ret = ffi::gdk_pixbuf_new_from_file_at_scale(
397                filename.as_ref().to_glib_none().0,
398                width,
399                height,
400                preserve_aspect_ratio.into_glib(),
401                &mut error,
402            );
403            if error.is_null() {
404                Ok(from_glib_full(ret))
405            } else {
406                Err(from_glib_full(error))
407            }
408        }
409    }
410
411    /// Creates a new pixbuf by loading an image from a file.
412    ///
413    /// The file format is detected automatically.
414    ///
415    /// If `NULL` is returned, then @error will be set. Possible errors are:
416    ///
417    ///  - the file could not be opened
418    ///  - there is no loader for the file's format
419    ///  - there is not enough memory to allocate the image buffer
420    ///  - the image buffer contains invalid data
421    ///
422    /// The error domains are `GDK_PIXBUF_ERROR` and `G_FILE_ERROR`.
423    ///
424    /// The image will be scaled to fit in the requested size, preserving
425    /// the image's aspect ratio. Note that the returned pixbuf may be smaller
426    /// than `width` x `height`, if the aspect ratio requires it. To load
427    /// and image at the requested size, regardless of aspect ratio, use
428    /// [`from_file_at_scale()`][Self::from_file_at_scale()].
429    /// ## `filename`
430    /// Name of file to load, in the GLib file
431    ///     name encoding
432    /// ## `width`
433    /// The width the image should have or -1 to not constrain the width
434    /// ## `height`
435    /// The height the image should have or -1 to not constrain the height
436    ///
437    /// # Returns
438    ///
439    /// A newly-created pixbuf
440    #[doc(alias = "gdk_pixbuf_new_from_file_at_size")]
441    #[doc(alias = "new_from_file_at_size")]
442    pub fn from_file_at_size(
443        filename: impl AsRef<std::path::Path>,
444        width: i32,
445        height: i32,
446    ) -> Result<Pixbuf, glib::Error> {
447        unsafe {
448            let mut error = std::ptr::null_mut();
449            let ret = ffi::gdk_pixbuf_new_from_file_at_size(
450                filename.as_ref().to_glib_none().0,
451                width,
452                height,
453                &mut error,
454            );
455            if error.is_null() {
456                Ok(from_glib_full(ret))
457            } else {
458                Err(from_glib_full(error))
459            }
460        }
461    }
462
463    /// Creates a new pixbuf by loading an image from an resource.
464    ///
465    /// The file format is detected automatically. If `NULL` is returned, then
466    /// @error will be set.
467    /// ## `resource_path`
468    /// the path of the resource file
469    ///
470    /// # Returns
471    ///
472    /// A newly-created pixbuf
473    #[doc(alias = "gdk_pixbuf_new_from_resource")]
474    #[doc(alias = "new_from_resource")]
475    pub fn from_resource(resource_path: &str) -> Result<Pixbuf, glib::Error> {
476        unsafe {
477            let mut error = std::ptr::null_mut();
478            let ret = ffi::gdk_pixbuf_new_from_resource(resource_path.to_glib_none().0, &mut error);
479            if error.is_null() {
480                Ok(from_glib_full(ret))
481            } else {
482                Err(from_glib_full(error))
483            }
484        }
485    }
486
487    /// Creates a new pixbuf by loading an image from an resource.
488    ///
489    /// The file format is detected automatically. If `NULL` is returned, then
490    /// @error will be set.
491    ///
492    /// The image will be scaled to fit in the requested size, optionally
493    /// preserving the image's aspect ratio. When preserving the aspect ratio,
494    /// a @width of -1 will cause the image to be scaled to the exact given
495    /// height, and a @height of -1 will cause the image to be scaled to the
496    /// exact given width. When not preserving aspect ratio, a @width or
497    /// @height of -1 means to not scale the image at all in that dimension.
498    ///
499    /// The stream is not closed.
500    /// ## `resource_path`
501    /// the path of the resource file
502    /// ## `width`
503    /// The width the image should have or -1 to not constrain the width
504    /// ## `height`
505    /// The height the image should have or -1 to not constrain the height
506    /// ## `preserve_aspect_ratio`
507    /// `TRUE` to preserve the image's aspect ratio
508    ///
509    /// # Returns
510    ///
511    /// A newly-created pixbuf
512    #[doc(alias = "gdk_pixbuf_new_from_resource_at_scale")]
513    #[doc(alias = "new_from_resource_at_scale")]
514    pub fn from_resource_at_scale(
515        resource_path: &str,
516        width: i32,
517        height: i32,
518        preserve_aspect_ratio: bool,
519    ) -> Result<Pixbuf, glib::Error> {
520        unsafe {
521            let mut error = std::ptr::null_mut();
522            let ret = ffi::gdk_pixbuf_new_from_resource_at_scale(
523                resource_path.to_glib_none().0,
524                width,
525                height,
526                preserve_aspect_ratio.into_glib(),
527                &mut error,
528            );
529            if error.is_null() {
530                Ok(from_glib_full(ret))
531            } else {
532                Err(from_glib_full(error))
533            }
534        }
535    }
536
537    /// Creates a new pixbuf by loading an image from an input stream.
538    ///
539    /// The file format is detected automatically.
540    ///
541    /// If `NULL` is returned, then `error` will be set.
542    ///
543    /// The `cancellable` can be used to abort the operation from another thread.
544    /// If the operation was cancelled, the error `G_IO_ERROR_CANCELLED` will be
545    /// returned. Other possible errors are in the `GDK_PIXBUF_ERROR` and
546    /// `G_IO_ERROR` domains.
547    ///
548    /// The stream is not closed.
549    /// ## `stream`
550    /// a `GInputStream` to load the pixbuf from
551    /// ## `cancellable`
552    /// optional `GCancellable` object, `NULL` to ignore
553    ///
554    /// # Returns
555    ///
556    /// A newly-created pixbuf
557    #[doc(alias = "gdk_pixbuf_new_from_stream")]
558    #[doc(alias = "new_from_stream")]
559    pub fn from_stream(
560        stream: &impl IsA<gio::InputStream>,
561        cancellable: Option<&impl IsA<gio::Cancellable>>,
562    ) -> Result<Pixbuf, glib::Error> {
563        unsafe {
564            let mut error = std::ptr::null_mut();
565            let ret = ffi::gdk_pixbuf_new_from_stream(
566                stream.as_ref().to_glib_none().0,
567                cancellable.map(|p| p.as_ref()).to_glib_none().0,
568                &mut error,
569            );
570            if error.is_null() {
571                Ok(from_glib_full(ret))
572            } else {
573                Err(from_glib_full(error))
574            }
575        }
576    }
577
578    /// Creates a new pixbuf by loading an image from an input stream.
579    ///
580    /// The file format is detected automatically. If `NULL` is returned, then
581    /// @error will be set. The @cancellable can be used to abort the operation
582    /// from another thread. If the operation was cancelled, the error
583    /// `G_IO_ERROR_CANCELLED` will be returned. Other possible errors are in
584    /// the `GDK_PIXBUF_ERROR` and `G_IO_ERROR` domains.
585    ///
586    /// The image will be scaled to fit in the requested size, optionally
587    /// preserving the image's aspect ratio.
588    ///
589    /// When preserving the aspect ratio, a `width` of -1 will cause the image to be
590    /// scaled to the exact given height, and a `height` of -1 will cause the image
591    /// to be scaled to the exact given width. If both `width` and `height` are
592    /// given, this function will behave as if the smaller of the two values
593    /// is passed as -1.
594    ///
595    /// When not preserving aspect ratio, a `width` or `height` of -1 means to not
596    /// scale the image at all in that dimension.
597    ///
598    /// The stream is not closed.
599    /// ## `stream`
600    /// a `GInputStream` to load the pixbuf from
601    /// ## `width`
602    /// The width the image should have or -1 to not constrain the width
603    /// ## `height`
604    /// The height the image should have or -1 to not constrain the height
605    /// ## `preserve_aspect_ratio`
606    /// `TRUE` to preserve the image's aspect ratio
607    /// ## `cancellable`
608    /// optional `GCancellable` object, `NULL` to ignore
609    ///
610    /// # Returns
611    ///
612    /// A newly-created pixbuf
613    #[doc(alias = "gdk_pixbuf_new_from_stream_at_scale")]
614    #[doc(alias = "new_from_stream_at_scale")]
615    pub fn from_stream_at_scale(
616        stream: &impl IsA<gio::InputStream>,
617        width: i32,
618        height: i32,
619        preserve_aspect_ratio: bool,
620        cancellable: Option<&impl IsA<gio::Cancellable>>,
621    ) -> Result<Pixbuf, glib::Error> {
622        unsafe {
623            let mut error = std::ptr::null_mut();
624            let ret = ffi::gdk_pixbuf_new_from_stream_at_scale(
625                stream.as_ref().to_glib_none().0,
626                width,
627                height,
628                preserve_aspect_ratio.into_glib(),
629                cancellable.map(|p| p.as_ref()).to_glib_none().0,
630                &mut error,
631            );
632            if error.is_null() {
633                Ok(from_glib_full(ret))
634            } else {
635                Err(from_glib_full(error))
636            }
637        }
638    }
639
640    /// Creates a new pixbuf by parsing XPM data in memory.
641    ///
642    /// This data is commonly the result of including an XPM file into a
643    /// program's C source.
644    /// ## `data`
645    /// Pointer to inline XPM data.
646    ///
647    /// # Returns
648    ///
649    /// A newly-created pixbuf
650    #[doc(alias = "gdk_pixbuf_new_from_xpm_data")]
651    #[doc(alias = "new_from_xpm_data")]
652    pub fn from_xpm_data(data: &[&str]) -> Result<Pixbuf, glib::BoolError> {
653        unsafe {
654            Option::<_>::from_glib_full(ffi::gdk_pixbuf_new_from_xpm_data(data.to_glib_none().0))
655                .ok_or_else(|| glib::bool_error!("Invalid XPM data"))
656        }
657    }
658
659    /// Takes an existing pixbuf and adds an alpha channel to it.
660    ///
661    /// If the existing pixbuf already had an alpha channel, the channel
662    /// values are copied from the original; otherwise, the alpha channel
663    /// is initialized to 255 (full opacity).
664    ///
665    /// If `substitute_color` is `TRUE`, then the color specified by the
666    /// (`r`, `g`, `b`) arguments will be assigned zero opacity. That is,
667    /// if you pass `(255, 255, 255)` for the substitute color, all white
668    /// pixels will become fully transparent.
669    ///
670    /// If `substitute_color` is `FALSE`, then the (`r`, `g`, `b`) arguments
671    /// will be ignored.
672    /// ## `substitute_color`
673    /// Whether to set a color to zero opacity.
674    /// ## `r`
675    /// Red value to substitute.
676    /// ## `g`
677    /// Green value to substitute.
678    /// ## `b`
679    /// Blue value to substitute.
680    ///
681    /// # Returns
682    ///
683    /// A newly-created pixbuf
684    #[doc(alias = "gdk_pixbuf_add_alpha")]
685    pub fn add_alpha(
686        &self,
687        substitute_color: bool,
688        r: u8,
689        g: u8,
690        b: u8,
691    ) -> Result<Pixbuf, glib::BoolError> {
692        unsafe {
693            Option::<_>::from_glib_full(ffi::gdk_pixbuf_add_alpha(
694                self.to_glib_none().0,
695                substitute_color.into_glib(),
696                r,
697                g,
698                b,
699            ))
700            .ok_or_else(|| glib::bool_error!("Failed to add alpha channel"))
701        }
702    }
703
704    /// Takes an existing pixbuf and checks for the presence of an
705    /// associated "orientation" option.
706    ///
707    /// The orientation option may be provided by the JPEG loader (which
708    /// reads the exif orientation tag) or the TIFF loader (which reads
709    /// the TIFF orientation tag, and compensates it for the partial
710    /// transforms performed by libtiff).
711    ///
712    /// If an orientation option/tag is present, the appropriate transform
713    /// will be performed so that the pixbuf is oriented correctly.
714    ///
715    /// # Returns
716    ///
717    /// A newly-created pixbuf
718    #[doc(alias = "gdk_pixbuf_apply_embedded_orientation")]
719    #[must_use]
720    pub fn apply_embedded_orientation(&self) -> Option<Pixbuf> {
721        unsafe {
722            from_glib_full(ffi::gdk_pixbuf_apply_embedded_orientation(
723                self.to_glib_none().0,
724            ))
725        }
726    }
727
728    /// Creates a transformation of the source image @self by scaling by
729    /// @scale_x and @scale_y then translating by @offset_x and @offset_y.
730    ///
731    /// This gives an image in the coordinates of the destination pixbuf.
732    /// The rectangle (@dest_x, @dest_y, @dest_width, @dest_height)
733    /// is then alpha blended onto the corresponding rectangle of the
734    /// original destination image.
735    ///
736    /// When the destination rectangle contains parts not in the source
737    /// image, the data at the edges of the source image is replicated
738    /// to infinity.
739    ///
740    /// ![](composite.png)
741    /// ## `dest`
742    /// the #GdkPixbuf into which to render the results
743    /// ## `dest_x`
744    /// the left coordinate for region to render
745    /// ## `dest_y`
746    /// the top coordinate for region to render
747    /// ## `dest_width`
748    /// the width of the region to render
749    /// ## `dest_height`
750    /// the height of the region to render
751    /// ## `offset_x`
752    /// the offset in the X direction (currently rounded to an integer)
753    /// ## `offset_y`
754    /// the offset in the Y direction (currently rounded to an integer)
755    /// ## `scale_x`
756    /// the scale factor in the X direction
757    /// ## `scale_y`
758    /// the scale factor in the Y direction
759    /// ## `interp_type`
760    /// the interpolation type for the transformation.
761    /// ## `overall_alpha`
762    /// overall alpha for source image (0..255)
763    #[doc(alias = "gdk_pixbuf_composite")]
764    pub fn composite(
765        &self,
766        dest: &Pixbuf,
767        dest_x: i32,
768        dest_y: i32,
769        dest_width: i32,
770        dest_height: i32,
771        offset_x: f64,
772        offset_y: f64,
773        scale_x: f64,
774        scale_y: f64,
775        interp_type: InterpType,
776        overall_alpha: i32,
777    ) {
778        unsafe {
779            ffi::gdk_pixbuf_composite(
780                self.to_glib_none().0,
781                dest.to_glib_none().0,
782                dest_x,
783                dest_y,
784                dest_width,
785                dest_height,
786                offset_x,
787                offset_y,
788                scale_x,
789                scale_y,
790                interp_type.into_glib(),
791                overall_alpha,
792            );
793        }
794    }
795
796    /// Creates a transformation of the source image @self by scaling by
797    /// @scale_x and @scale_y then translating by @offset_x and @offset_y,
798    /// then alpha blends the rectangle (@dest_x ,@dest_y, @dest_width,
799    /// @dest_height) of the resulting image with a checkboard of the
800    /// colors @color1 and @color2 and renders it onto the destination
801    /// image.
802    ///
803    /// If the source image has no alpha channel, and @overall_alpha is 255, a fast
804    /// path is used which omits the alpha blending and just performs the scaling.
805    ///
806    /// See gdk_pixbuf_composite_color_simple() for a simpler variant of this
807    /// function suitable for many tasks.
808    /// ## `dest`
809    /// the #GdkPixbuf into which to render the results
810    /// ## `dest_x`
811    /// the left coordinate for region to render
812    /// ## `dest_y`
813    /// the top coordinate for region to render
814    /// ## `dest_width`
815    /// the width of the region to render
816    /// ## `dest_height`
817    /// the height of the region to render
818    /// ## `offset_x`
819    /// the offset in the X direction (currently rounded to an integer)
820    /// ## `offset_y`
821    /// the offset in the Y direction (currently rounded to an integer)
822    /// ## `scale_x`
823    /// the scale factor in the X direction
824    /// ## `scale_y`
825    /// the scale factor in the Y direction
826    /// ## `interp_type`
827    /// the interpolation type for the transformation.
828    /// ## `overall_alpha`
829    /// overall alpha for source image (0..255)
830    /// ## `check_x`
831    /// the X offset for the checkboard (origin of checkboard is at -@check_x, -@check_y)
832    /// ## `check_y`
833    /// the Y offset for the checkboard
834    /// ## `check_size`
835    /// the size of checks in the checkboard (must be a power of two)
836    /// ## `color1`
837    /// the color of check at upper left
838    /// ## `color2`
839    /// the color of the other check
840    #[doc(alias = "gdk_pixbuf_composite_color")]
841    pub fn composite_color(
842        &self,
843        dest: &Pixbuf,
844        dest_x: i32,
845        dest_y: i32,
846        dest_width: i32,
847        dest_height: i32,
848        offset_x: f64,
849        offset_y: f64,
850        scale_x: f64,
851        scale_y: f64,
852        interp_type: InterpType,
853        overall_alpha: i32,
854        check_x: i32,
855        check_y: i32,
856        check_size: i32,
857        color1: u32,
858        color2: u32,
859    ) {
860        unsafe {
861            ffi::gdk_pixbuf_composite_color(
862                self.to_glib_none().0,
863                dest.to_glib_none().0,
864                dest_x,
865                dest_y,
866                dest_width,
867                dest_height,
868                offset_x,
869                offset_y,
870                scale_x,
871                scale_y,
872                interp_type.into_glib(),
873                overall_alpha,
874                check_x,
875                check_y,
876                check_size,
877                color1,
878                color2,
879            );
880        }
881    }
882
883    /// Creates a new pixbuf by scaling `src` to `dest_width` x `dest_height`
884    /// and alpha blending the result with a checkboard of colors `color1`
885    /// and `color2`.
886    /// ## `dest_width`
887    /// the width of destination image
888    /// ## `dest_height`
889    /// the height of destination image
890    /// ## `interp_type`
891    /// the interpolation type for the transformation.
892    /// ## `overall_alpha`
893    /// overall alpha for source image (0..255)
894    /// ## `check_size`
895    /// the size of checks in the checkboard (must be a power of two)
896    /// ## `color1`
897    /// the color of check at upper left
898    /// ## `color2`
899    /// the color of the other check
900    ///
901    /// # Returns
902    ///
903    /// the new pixbuf
904    #[doc(alias = "gdk_pixbuf_composite_color_simple")]
905    #[must_use]
906    pub fn composite_color_simple(
907        &self,
908        dest_width: i32,
909        dest_height: i32,
910        interp_type: InterpType,
911        overall_alpha: i32,
912        check_size: i32,
913        color1: u32,
914        color2: u32,
915    ) -> Option<Pixbuf> {
916        unsafe {
917            from_glib_full(ffi::gdk_pixbuf_composite_color_simple(
918                self.to_glib_none().0,
919                dest_width,
920                dest_height,
921                interp_type.into_glib(),
922                overall_alpha,
923                check_size,
924                color1,
925                color2,
926            ))
927        }
928    }
929
930    #[doc(alias = "gdk_pixbuf_copy")]
931    #[must_use]
932    pub fn copy(&self) -> Option<Pixbuf> {
933        unsafe { from_glib_full(ffi::gdk_pixbuf_copy(self.to_glib_none().0)) }
934    }
935
936    /// Copies a rectangular area from `src_pixbuf` to `dest_pixbuf`.
937    ///
938    /// Conversion of pixbuf formats is done automatically.
939    ///
940    /// If the source rectangle overlaps the destination rectangle on the
941    /// same pixbuf, it will be overwritten during the copy operation.
942    /// Therefore, you can not use this function to scroll a pixbuf.
943    /// ## `src_x`
944    /// Source X coordinate within @self.
945    /// ## `src_y`
946    /// Source Y coordinate within @self.
947    /// ## `width`
948    /// Width of the area to copy.
949    /// ## `height`
950    /// Height of the area to copy.
951    /// ## `dest_pixbuf`
952    /// Destination pixbuf.
953    /// ## `dest_x`
954    /// X coordinate within @dest_pixbuf.
955    /// ## `dest_y`
956    /// Y coordinate within @dest_pixbuf.
957    #[doc(alias = "gdk_pixbuf_copy_area")]
958    pub fn copy_area(
959        &self,
960        src_x: i32,
961        src_y: i32,
962        width: i32,
963        height: i32,
964        dest_pixbuf: &Pixbuf,
965        dest_x: i32,
966        dest_y: i32,
967    ) {
968        unsafe {
969            ffi::gdk_pixbuf_copy_area(
970                self.to_glib_none().0,
971                src_x,
972                src_y,
973                width,
974                height,
975                dest_pixbuf.to_glib_none().0,
976                dest_x,
977                dest_y,
978            );
979        }
980    }
981
982    /// Copies the key/value pair options attached to a [`Pixbuf`][crate::Pixbuf] to another
983    /// [`Pixbuf`][crate::Pixbuf].
984    ///
985    /// This is useful to keep original metadata after having manipulated
986    /// a file. However be careful to remove metadata which you've already
987    /// applied, such as the "orientation" option after rotating the image.
988    /// ## `dest_pixbuf`
989    /// the destination pixbuf
990    ///
991    /// # Returns
992    ///
993    /// `TRUE` on success.
994    #[doc(alias = "gdk_pixbuf_copy_options")]
995    pub fn copy_options(&self, dest_pixbuf: &Pixbuf) -> bool {
996        unsafe {
997            from_glib(ffi::gdk_pixbuf_copy_options(
998                self.to_glib_none().0,
999                dest_pixbuf.to_glib_none().0,
1000            ))
1001        }
1002    }
1003
1004    /// Clears a pixbuf to the given RGBA value, converting the RGBA value into
1005    /// the pixbuf's pixel format.
1006    ///
1007    /// The alpha component will be ignored if the pixbuf doesn't have an alpha
1008    /// channel.
1009    /// ## `pixel`
1010    /// RGBA pixel to used to clear (`0xffffffff` is opaque white,
1011    ///   `0x00000000` transparent black)
1012    #[doc(alias = "gdk_pixbuf_fill")]
1013    pub fn fill(&self, pixel: u32) {
1014        unsafe {
1015            ffi::gdk_pixbuf_fill(self.to_glib_none().0, pixel);
1016        }
1017    }
1018
1019    /// Flips a pixbuf horizontally or vertically and returns the
1020    /// result in a new pixbuf.
1021    /// ## `horizontal`
1022    /// `TRUE` to flip horizontally, `FALSE` to flip vertically
1023    ///
1024    /// # Returns
1025    ///
1026    /// the new pixbuf
1027    #[doc(alias = "gdk_pixbuf_flip")]
1028    #[must_use]
1029    pub fn flip(&self, horizontal: bool) -> Option<Pixbuf> {
1030        unsafe {
1031            from_glib_full(ffi::gdk_pixbuf_flip(
1032                self.to_glib_none().0,
1033                horizontal.into_glib(),
1034            ))
1035        }
1036    }
1037
1038    /// Queries the number of bits per color sample in a pixbuf.
1039    ///
1040    /// # Returns
1041    ///
1042    /// Number of bits per color sample.
1043    #[doc(alias = "gdk_pixbuf_get_bits_per_sample")]
1044    #[doc(alias = "get_bits_per_sample")]
1045    #[doc(alias = "bits-per-sample")]
1046    pub fn bits_per_sample(&self) -> i32 {
1047        unsafe { ffi::gdk_pixbuf_get_bits_per_sample(self.to_glib_none().0) }
1048    }
1049
1050    /// Returns the length of the pixel data, in bytes.
1051    ///
1052    /// # Returns
1053    ///
1054    /// The length of the pixel data.
1055    #[doc(alias = "gdk_pixbuf_get_byte_length")]
1056    #[doc(alias = "get_byte_length")]
1057    pub fn byte_length(&self) -> usize {
1058        unsafe { ffi::gdk_pixbuf_get_byte_length(self.to_glib_none().0) }
1059    }
1060
1061    /// Queries the color space of a pixbuf.
1062    ///
1063    /// # Returns
1064    ///
1065    /// Color space.
1066    #[doc(alias = "gdk_pixbuf_get_colorspace")]
1067    #[doc(alias = "get_colorspace")]
1068    pub fn colorspace(&self) -> Colorspace {
1069        unsafe { from_glib(ffi::gdk_pixbuf_get_colorspace(self.to_glib_none().0)) }
1070    }
1071
1072    /// Queries whether a pixbuf has an alpha channel (opacity information).
1073    ///
1074    /// # Returns
1075    ///
1076    /// `TRUE` if it has an alpha channel, `FALSE` otherwise.
1077    #[doc(alias = "gdk_pixbuf_get_has_alpha")]
1078    #[doc(alias = "get_has_alpha")]
1079    #[doc(alias = "has-alpha")]
1080    pub fn has_alpha(&self) -> bool {
1081        unsafe { from_glib(ffi::gdk_pixbuf_get_has_alpha(self.to_glib_none().0)) }
1082    }
1083
1084    /// Queries the height of a pixbuf.
1085    ///
1086    /// # Returns
1087    ///
1088    /// Height in pixels.
1089    #[doc(alias = "gdk_pixbuf_get_height")]
1090    #[doc(alias = "get_height")]
1091    pub fn height(&self) -> i32 {
1092        unsafe { ffi::gdk_pixbuf_get_height(self.to_glib_none().0) }
1093    }
1094
1095    /// Queries the number of channels of a pixbuf.
1096    ///
1097    /// # Returns
1098    ///
1099    /// Number of channels.
1100    #[doc(alias = "gdk_pixbuf_get_n_channels")]
1101    #[doc(alias = "get_n_channels")]
1102    #[doc(alias = "n-channels")]
1103    pub fn n_channels(&self) -> i32 {
1104        unsafe { ffi::gdk_pixbuf_get_n_channels(self.to_glib_none().0) }
1105    }
1106
1107    /// Looks up @key in the list of options that may have been attached to the
1108    /// @self when it was loaded, or that may have been attached by another
1109    /// function using gdk_pixbuf_set_option().
1110    ///
1111    /// For instance, the ANI loader provides "Title" and "Artist" options.
1112    /// The ICO, XBM, and XPM loaders provide "x_hot" and "y_hot" hot-spot
1113    /// options for cursor definitions. The PNG loader provides the tEXt ancillary
1114    /// chunk key/value pairs as options. Since 2.12, the TIFF and JPEG loaders
1115    /// return an "orientation" option string that corresponds to the embedded
1116    /// TIFF/Exif orientation tag (if present). Since 2.32, the TIFF loader sets
1117    /// the "multipage" option string to "yes" when a multi-page TIFF is loaded.
1118    /// Since 2.32 the JPEG and PNG loaders set "x-dpi" and "y-dpi" if the file
1119    /// contains image density information in dots per inch.
1120    /// Since 2.36.6, the JPEG loader sets the "comment" option with the comment
1121    /// EXIF tag.
1122    /// ## `key`
1123    /// a nul-terminated string.
1124    ///
1125    /// # Returns
1126    ///
1127    /// the value associated with `key`
1128    #[doc(alias = "gdk_pixbuf_get_option")]
1129    #[doc(alias = "get_option")]
1130    pub fn option(&self, key: &str) -> Option<glib::GString> {
1131        unsafe {
1132            from_glib_none(ffi::gdk_pixbuf_get_option(
1133                self.to_glib_none().0,
1134                key.to_glib_none().0,
1135            ))
1136        }
1137    }
1138
1139    //#[doc(alias = "gdk_pixbuf_get_options")]
1140    //#[doc(alias = "get_options")]
1141    //pub fn options(&self) -> /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 } {
1142    //    unsafe { TODO: call ffi:gdk_pixbuf_get_options() }
1143    //}
1144
1145    /// Queries the rowstride of a pixbuf, which is the number of bytes between
1146    /// the start of a row and the start of the next row.
1147    ///
1148    /// # Returns
1149    ///
1150    /// Distance between row starts.
1151    #[doc(alias = "gdk_pixbuf_get_rowstride")]
1152    #[doc(alias = "get_rowstride")]
1153    pub fn rowstride(&self) -> i32 {
1154        unsafe { ffi::gdk_pixbuf_get_rowstride(self.to_glib_none().0) }
1155    }
1156
1157    /// Queries the width of a pixbuf.
1158    ///
1159    /// # Returns
1160    ///
1161    /// Width in pixels.
1162    #[doc(alias = "gdk_pixbuf_get_width")]
1163    #[doc(alias = "get_width")]
1164    pub fn width(&self) -> i32 {
1165        unsafe { ffi::gdk_pixbuf_get_width(self.to_glib_none().0) }
1166    }
1167
1168    /// Creates a new pixbuf which represents a sub-region of `src_pixbuf`.
1169    ///
1170    /// The new pixbuf shares its pixels with the original pixbuf, so
1171    /// writing to one affects both.  The new pixbuf holds a reference to
1172    /// `src_pixbuf`, so `src_pixbuf` will not be finalized until the new
1173    /// pixbuf is finalized.
1174    ///
1175    /// Note that if `src_pixbuf` is read-only, this function will force it
1176    /// to be mutable.
1177    /// ## `src_x`
1178    /// X coord in @self
1179    /// ## `src_y`
1180    /// Y coord in @self
1181    /// ## `width`
1182    /// width of region in @self
1183    /// ## `height`
1184    /// height of region in @self
1185    ///
1186    /// # Returns
1187    ///
1188    /// a new pixbuf
1189    #[doc(alias = "gdk_pixbuf_new_subpixbuf")]
1190    #[must_use]
1191    pub fn new_subpixbuf(&self, src_x: i32, src_y: i32, width: i32, height: i32) -> Pixbuf {
1192        unsafe {
1193            from_glib_full(ffi::gdk_pixbuf_new_subpixbuf(
1194                self.to_glib_none().0,
1195                src_x,
1196                src_y,
1197                width,
1198                height,
1199            ))
1200        }
1201    }
1202
1203    /// Provides a #GBytes buffer containing the raw pixel data; the data
1204    /// must not be modified.
1205    ///
1206    /// This function allows skipping the implicit copy that must be made
1207    /// if gdk_pixbuf_get_pixels() is called on a read-only pixbuf.
1208    ///
1209    /// # Returns
1210    ///
1211    /// A new reference to a read-only copy of
1212    ///   the pixel data.  Note that for mutable pixbufs, this function will
1213    ///   incur a one-time copy of the pixel data for conversion into the
1214    ///   returned #GBytes.
1215    #[doc(alias = "gdk_pixbuf_read_pixel_bytes")]
1216    pub fn read_pixel_bytes(&self) -> glib::Bytes {
1217        unsafe { from_glib_full(ffi::gdk_pixbuf_read_pixel_bytes(self.to_glib_none().0)) }
1218    }
1219
1220    /// Removes the key/value pair option attached to a [`Pixbuf`][crate::Pixbuf].
1221    /// ## `key`
1222    /// a nul-terminated string representing the key to remove.
1223    ///
1224    /// # Returns
1225    ///
1226    /// `TRUE` if an option was removed, `FALSE` if not.
1227    #[doc(alias = "gdk_pixbuf_remove_option")]
1228    pub fn remove_option(&self, key: &str) -> bool {
1229        unsafe {
1230            from_glib(ffi::gdk_pixbuf_remove_option(
1231                self.to_glib_none().0,
1232                key.to_glib_none().0,
1233            ))
1234        }
1235    }
1236
1237    /// Rotates a pixbuf by a multiple of 90 degrees, and returns the
1238    /// result in a new pixbuf.
1239    ///
1240    /// If `angle` is 0, this function will return a copy of `src`.
1241    /// ## `angle`
1242    /// the angle to rotate by
1243    ///
1244    /// # Returns
1245    ///
1246    /// the new pixbuf
1247    #[doc(alias = "gdk_pixbuf_rotate_simple")]
1248    #[must_use]
1249    pub fn rotate_simple(&self, angle: PixbufRotation) -> Option<Pixbuf> {
1250        unsafe {
1251            from_glib_full(ffi::gdk_pixbuf_rotate_simple(
1252                self.to_glib_none().0,
1253                angle.into_glib(),
1254            ))
1255        }
1256    }
1257
1258    /// Modifies saturation and optionally pixelates `src`, placing the result in
1259    /// `dest`.
1260    ///
1261    /// The `src` and `dest` pixbufs must have the same image format, size, and
1262    /// rowstride.
1263    ///
1264    /// The `src` and `dest` arguments may be the same pixbuf with no ill effects.
1265    ///
1266    /// If `saturation` is 1.0 then saturation is not changed. If it's less than 1.0,
1267    /// saturation is reduced (the image turns toward grayscale); if greater than
1268    /// 1.0, saturation is increased (the image gets more vivid colors).
1269    ///
1270    /// If `pixelate` is `TRUE`, then pixels are faded in a checkerboard pattern to
1271    /// create a pixelated image.
1272    /// ## `dest`
1273    /// place to write modified version of @self
1274    /// ## `saturation`
1275    /// saturation factor
1276    /// ## `pixelate`
1277    /// whether to pixelate
1278    #[doc(alias = "gdk_pixbuf_saturate_and_pixelate")]
1279    pub fn saturate_and_pixelate(&self, dest: &Pixbuf, saturation: f32, pixelate: bool) {
1280        unsafe {
1281            ffi::gdk_pixbuf_saturate_and_pixelate(
1282                self.to_glib_none().0,
1283                dest.to_glib_none().0,
1284                saturation,
1285                pixelate.into_glib(),
1286            );
1287        }
1288    }
1289
1290    //#[doc(alias = "gdk_pixbuf_save")]
1291    //pub fn save(&self, filename: impl AsRef<std::path::Path>, type_: &str, error: Option<&mut glib::Error>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> bool {
1292    //    unsafe { TODO: call ffi:gdk_pixbuf_save() }
1293    //}
1294
1295    //#[doc(alias = "gdk_pixbuf_save_to_buffer")]
1296    //pub fn save_to_buffer(&self, type_: &str, error: Option<&mut glib::Error>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> Option<Vec<u8>> {
1297    //    unsafe { TODO: call ffi:gdk_pixbuf_save_to_buffer() }
1298    //}
1299
1300    //#[doc(alias = "gdk_pixbuf_save_to_callback")]
1301    //pub fn save_to_callback<P: FnMut(&Vec<u8>, usize, &glib::Error) -> bool>(&self, save_func: P, type_: &str, error: Option<&mut glib::Error>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> bool {
1302    //    unsafe { TODO: call ffi:gdk_pixbuf_save_to_callback() }
1303    //}
1304
1305    //#[doc(alias = "gdk_pixbuf_save_to_callbackv")]
1306    //pub fn save_to_callbackv<P: FnMut(&Vec<u8>, usize, &glib::Error) -> bool>(&self, save_func: P, type_: &str, option_keys: &[&str], option_values: &[&str]) -> Result<(), glib::Error> {
1307    //    unsafe { TODO: call ffi:gdk_pixbuf_save_to_callbackv() }
1308    //}
1309
1310    //#[doc(alias = "gdk_pixbuf_save_to_stream")]
1311    //pub fn save_to_stream(&self, stream: &impl IsA<gio::OutputStream>, type_: &str, cancellable: Option<&impl IsA<gio::Cancellable>>, error: Option<&mut glib::Error>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> bool {
1312    //    unsafe { TODO: call ffi:gdk_pixbuf_save_to_stream() }
1313    //}
1314
1315    //#[doc(alias = "gdk_pixbuf_save_to_stream_async")]
1316    //pub fn save_to_stream_async<P: FnOnce(Result<(), glib::Error>) + 'static>(&self, stream: &impl IsA<gio::OutputStream>, type_: &str, cancellable: Option<&impl IsA<gio::Cancellable>>, callback: P, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
1317    //    unsafe { TODO: call ffi:gdk_pixbuf_save_to_stream_async() }
1318    //}
1319
1320    //
1321    //pub fn save_to_stream_future(&self, stream: &(impl IsA<gio::OutputStream> + Clone + 'static), type_: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
1322
1323    //let stream = stream.clone();
1324    //let type_ = String::from(type_);
1325    //Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
1326    //    obj.save_to_stream_async(
1327    //        &stream,
1328    //        &type_,
1329    //        Some(cancellable),
1330    //        ,
1331    //        move |res| {
1332    //            send.resolve(res);
1333    //        },
1334    //    );
1335    //}))
1336    //}
1337
1338    /// Creates a transformation of the source image @self by scaling by
1339    /// @scale_x and @scale_y then translating by @offset_x and @offset_y,
1340    /// then renders the rectangle (@dest_x, @dest_y, @dest_width,
1341    /// @dest_height) of the resulting image onto the destination image
1342    /// replacing the previous contents.
1343    ///
1344    /// Try to use gdk_pixbuf_scale_simple() first; this function is
1345    /// the industrial-strength power tool you can fall back to, if
1346    /// gdk_pixbuf_scale_simple() isn't powerful enough.
1347    ///
1348    /// If the source rectangle overlaps the destination rectangle on the
1349    /// same pixbuf, it will be overwritten during the scaling which
1350    /// results in rendering artifacts.
1351    /// ## `dest`
1352    /// the #GdkPixbuf into which to render the results
1353    /// ## `dest_x`
1354    /// the left coordinate for region to render
1355    /// ## `dest_y`
1356    /// the top coordinate for region to render
1357    /// ## `dest_width`
1358    /// the width of the region to render
1359    /// ## `dest_height`
1360    /// the height of the region to render
1361    /// ## `offset_x`
1362    /// the offset in the X direction (currently rounded to an integer)
1363    /// ## `offset_y`
1364    /// the offset in the Y direction (currently rounded to an integer)
1365    /// ## `scale_x`
1366    /// the scale factor in the X direction
1367    /// ## `scale_y`
1368    /// the scale factor in the Y direction
1369    /// ## `interp_type`
1370    /// the interpolation type for the transformation.
1371    #[doc(alias = "gdk_pixbuf_scale")]
1372    pub fn scale(
1373        &self,
1374        dest: &Pixbuf,
1375        dest_x: i32,
1376        dest_y: i32,
1377        dest_width: i32,
1378        dest_height: i32,
1379        offset_x: f64,
1380        offset_y: f64,
1381        scale_x: f64,
1382        scale_y: f64,
1383        interp_type: InterpType,
1384    ) {
1385        unsafe {
1386            ffi::gdk_pixbuf_scale(
1387                self.to_glib_none().0,
1388                dest.to_glib_none().0,
1389                dest_x,
1390                dest_y,
1391                dest_width,
1392                dest_height,
1393                offset_x,
1394                offset_y,
1395                scale_x,
1396                scale_y,
1397                interp_type.into_glib(),
1398            );
1399        }
1400    }
1401
1402    /// Create a new pixbuf containing a copy of `src` scaled to
1403    /// `dest_width` x `dest_height`.
1404    ///
1405    /// This function leaves `src` unaffected.
1406    ///
1407    /// The `interp_type` should be `GDK_INTERP_NEAREST` if you want maximum
1408    /// speed (but when scaling down `GDK_INTERP_NEAREST` is usually unusably
1409    /// ugly). The default `interp_type` should be `GDK_INTERP_BILINEAR` which
1410    /// offers reasonable quality and speed.
1411    ///
1412    /// You can scale a sub-portion of `src` by creating a sub-pixbuf
1413    /// pointing into `src`; see [`new_subpixbuf()`][Self::new_subpixbuf()].
1414    ///
1415    /// If `dest_width` and `dest_height` are equal to the width and height of
1416    /// `src`, this function will return an unscaled copy of `src`.
1417    ///
1418    /// For more complicated scaling/alpha blending see [`scale()`][Self::scale()]
1419    /// and [`composite()`][Self::composite()].
1420    /// ## `dest_width`
1421    /// the width of destination image
1422    /// ## `dest_height`
1423    /// the height of destination image
1424    /// ## `interp_type`
1425    /// the interpolation type for the transformation.
1426    ///
1427    /// # Returns
1428    ///
1429    /// the new pixbuf
1430    #[doc(alias = "gdk_pixbuf_scale_simple")]
1431    #[must_use]
1432    pub fn scale_simple(
1433        &self,
1434        dest_width: i32,
1435        dest_height: i32,
1436        interp_type: InterpType,
1437    ) -> Option<Pixbuf> {
1438        unsafe {
1439            from_glib_full(ffi::gdk_pixbuf_scale_simple(
1440                self.to_glib_none().0,
1441                dest_width,
1442                dest_height,
1443                interp_type.into_glib(),
1444            ))
1445        }
1446    }
1447
1448    /// Attaches a key/value pair as an option to a [`Pixbuf`][crate::Pixbuf].
1449    ///
1450    /// If `key` already exists in the list of options attached to the `pixbuf`,
1451    /// the new value is ignored and `FALSE` is returned.
1452    /// ## `key`
1453    /// a nul-terminated string.
1454    /// ## `value`
1455    /// a nul-terminated string.
1456    ///
1457    /// # Returns
1458    ///
1459    /// `TRUE` on success
1460    #[doc(alias = "gdk_pixbuf_set_option")]
1461    pub fn set_option(&self, key: &str, value: &str) -> bool {
1462        unsafe {
1463            from_glib(ffi::gdk_pixbuf_set_option(
1464                self.to_glib_none().0,
1465                key.to_glib_none().0,
1466                value.to_glib_none().0,
1467            ))
1468        }
1469    }
1470
1471    #[doc(alias = "pixel-bytes")]
1472    pub fn pixel_bytes(&self) -> Option<glib::Bytes> {
1473        ObjectExt::property(self, "pixel-bytes")
1474    }
1475
1476    /// Calculates the rowstride that an image created with those values would
1477    /// have.
1478    ///
1479    /// This function is useful for front-ends and backends that want to check
1480    /// image values without needing to create a [`Pixbuf`][crate::Pixbuf].
1481    /// ## `colorspace`
1482    /// Color space for image
1483    /// ## `has_alpha`
1484    /// Whether the image should have transparency information
1485    /// ## `bits_per_sample`
1486    /// Number of bits per color sample
1487    /// ## `width`
1488    /// Width of image in pixels, must be > 0
1489    /// ## `height`
1490    /// Height of image in pixels, must be > 0
1491    ///
1492    /// # Returns
1493    ///
1494    /// the rowstride for the given values, or -1 in case of error.
1495    #[doc(alias = "gdk_pixbuf_calculate_rowstride")]
1496    pub fn calculate_rowstride(
1497        colorspace: Colorspace,
1498        has_alpha: bool,
1499        bits_per_sample: i32,
1500        width: i32,
1501        height: i32,
1502    ) -> i32 {
1503        unsafe {
1504            ffi::gdk_pixbuf_calculate_rowstride(
1505                colorspace.into_glib(),
1506                has_alpha.into_glib(),
1507                bits_per_sample,
1508                width,
1509                height,
1510            )
1511        }
1512    }
1513
1514    /// Obtains the available information about the image formats supported
1515    /// by GdkPixbuf.
1516    ///
1517    /// # Returns
1518    ///
1519    /// A list of
1520    ///   support image formats.
1521    #[doc(alias = "gdk_pixbuf_get_formats")]
1522    #[doc(alias = "get_formats")]
1523    pub fn formats() -> Vec<PixbufFormat> {
1524        unsafe { FromGlibPtrContainer::from_glib_container(ffi::gdk_pixbuf_get_formats()) }
1525    }
1526
1527    /// Initalizes the gdk-pixbuf loader modules referenced by the `loaders.cache`
1528    /// file present inside that directory.
1529    ///
1530    /// This is to be used by applications that want to ship certain loaders
1531    /// in a different location from the system ones.
1532    ///
1533    /// This is needed when the OS or runtime ships a minimal number of loaders
1534    /// so as to reduce the potential attack surface of carefully crafted image
1535    /// files, especially for uncommon file types. Applications that require
1536    /// broader image file types coverage, such as image viewers, would be
1537    /// expected to ship the gdk-pixbuf modules in a separate location, bundled
1538    /// with the application in a separate directory from the OS or runtime-
1539    /// provided modules.
1540    /// ## `path`
1541    /// Path to directory where the `loaders.cache` is installed
1542    #[cfg(feature = "v2_40")]
1543    #[cfg_attr(docsrs, doc(cfg(feature = "v2_40")))]
1544    #[doc(alias = "gdk_pixbuf_init_modules")]
1545    pub fn init_modules(path: &str) -> Result<(), glib::Error> {
1546        unsafe {
1547            let mut error = std::ptr::null_mut();
1548            let is_ok = ffi::gdk_pixbuf_init_modules(path.to_glib_none().0, &mut error);
1549            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1550            if error.is_null() {
1551                Ok(())
1552            } else {
1553                Err(from_glib_full(error))
1554            }
1555        }
1556    }
1557}