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