1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use glib::error::ErrorDomain;
use glib::translate::*;
use glib::value::FromValue;
use glib::value::ToValue;
use glib::Quark;
use glib::StaticType;
use glib::Type;
use std::fmt;

/// This enumeration defines the color spaces that are supported by
/// the gdk-pixbuf library.
///
/// Currently only RGB is supported.
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "GdkColorspace")]
pub enum Colorspace {
    /// Indicates a red/green/blue additive color space.
    #[doc(alias = "GDK_COLORSPACE_RGB")]
    Rgb,
    #[doc(hidden)]
    __Unknown(i32),
}

impl fmt::Display for Colorspace {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(
            f,
            "Colorspace::{}",
            match *self {
                Self::Rgb => "Rgb",
                _ => "Unknown",
            }
        )
    }
}

#[doc(hidden)]
impl IntoGlib for Colorspace {
    type GlibType = ffi::GdkColorspace;

    fn into_glib(self) -> ffi::GdkColorspace {
        match self {
            Self::Rgb => ffi::GDK_COLORSPACE_RGB,
            Self::__Unknown(value) => value,
        }
    }
}

#[doc(hidden)]
impl FromGlib<ffi::GdkColorspace> for Colorspace {
    unsafe fn from_glib(value: ffi::GdkColorspace) -> Self {
        match value {
            ffi::GDK_COLORSPACE_RGB => Self::Rgb,
            value => Self::__Unknown(value),
        }
    }
}

impl StaticType for Colorspace {
    fn static_type() -> Type {
        unsafe { from_glib(ffi::gdk_colorspace_get_type()) }
    }
}

impl glib::value::ValueType for Colorspace {
    type Type = Self;
}

unsafe impl<'a> FromValue<'a> for Colorspace {
    type Checker = glib::value::GenericValueTypeChecker<Self>;

    unsafe fn from_value(value: &'a glib::Value) -> Self {
        from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
    }
}

impl ToValue for Colorspace {
    fn to_value(&self) -> glib::Value {
        let mut value = glib::Value::for_value_type::<Self>();
        unsafe {
            glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib());
        }
        value
    }

    fn value_type(&self) -> glib::Type {
        Self::static_type()
    }
}

/// Interpolation modes for scaling functions.
///
/// The `GDK_INTERP_NEAREST` mode is the fastest scaling method, but has
/// horrible quality when scaling down; `GDK_INTERP_BILINEAR` is the best
/// choice if you aren't sure what to choose, it has a good speed/quality
/// balance.
///
/// **Note**: Cubic filtering is missing from the list; hyperbolic
/// interpolation is just as fast and results in higher quality.
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "GdkInterpType")]
pub enum InterpType {
    /// Nearest neighbor sampling; this is the fastest
    ///  and lowest quality mode. Quality is normally unacceptable when scaling
    ///  down, but may be OK when scaling up.
    #[doc(alias = "GDK_INTERP_NEAREST")]
    Nearest,
    /// This is an accurate simulation of the PostScript
    ///  image operator without any interpolation enabled.  Each pixel is
    ///  rendered as a tiny parallelogram of solid color, the edges of which
    ///  are implemented with antialiasing.  It resembles nearest neighbor for
    ///  enlargement, and bilinear for reduction.
    #[doc(alias = "GDK_INTERP_TILES")]
    Tiles,
    /// Best quality/speed balance; use this mode by
    ///  default. Bilinear interpolation.  For enlargement, it is
    ///  equivalent to point-sampling the ideal bilinear-interpolated image.
    ///  For reduction, it is equivalent to laying down small tiles and
    ///  integrating over the coverage area.
    #[doc(alias = "GDK_INTERP_BILINEAR")]
    Bilinear,
    /// This is the slowest and highest quality
    ///  reconstruction function. It is derived from the hyperbolic filters in
    ///  Wolberg's "Digital Image Warping", and is formally defined as the
    ///  hyperbolic-filter sampling the ideal hyperbolic-filter interpolated
    ///  image (the filter is designed to be idempotent for 1:1 pixel mapping).
    ///  **Deprecated**: this interpolation filter is deprecated, as in reality
    ///  it has a lower quality than the @GDK_INTERP_BILINEAR filter
    ///  (Since: 2.38)
    #[doc(alias = "GDK_INTERP_HYPER")]
    Hyper,
    #[doc(hidden)]
    __Unknown(i32),
}

impl fmt::Display for InterpType {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(
            f,
            "InterpType::{}",
            match *self {
                Self::Nearest => "Nearest",
                Self::Tiles => "Tiles",
                Self::Bilinear => "Bilinear",
                Self::Hyper => "Hyper",
                _ => "Unknown",
            }
        )
    }
}

#[doc(hidden)]
impl IntoGlib for InterpType {
    type GlibType = ffi::GdkInterpType;

    fn into_glib(self) -> ffi::GdkInterpType {
        match self {
            Self::Nearest => ffi::GDK_INTERP_NEAREST,
            Self::Tiles => ffi::GDK_INTERP_TILES,
            Self::Bilinear => ffi::GDK_INTERP_BILINEAR,
            Self::Hyper => ffi::GDK_INTERP_HYPER,
            Self::__Unknown(value) => value,
        }
    }
}

#[doc(hidden)]
impl FromGlib<ffi::GdkInterpType> for InterpType {
    unsafe fn from_glib(value: ffi::GdkInterpType) -> Self {
        match value {
            ffi::GDK_INTERP_NEAREST => Self::Nearest,
            ffi::GDK_INTERP_TILES => Self::Tiles,
            ffi::GDK_INTERP_BILINEAR => Self::Bilinear,
            ffi::GDK_INTERP_HYPER => Self::Hyper,
            value => Self::__Unknown(value),
        }
    }
}

impl StaticType for InterpType {
    fn static_type() -> Type {
        unsafe { from_glib(ffi::gdk_interp_type_get_type()) }
    }
}

impl glib::value::ValueType for InterpType {
    type Type = Self;
}

unsafe impl<'a> FromValue<'a> for InterpType {
    type Checker = glib::value::GenericValueTypeChecker<Self>;

    unsafe fn from_value(value: &'a glib::Value) -> Self {
        from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
    }
}

impl ToValue for InterpType {
    fn to_value(&self) -> glib::Value {
        let mut value = glib::Value::for_value_type::<Self>();
        unsafe {
            glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib());
        }
        value
    }

    fn value_type(&self) -> glib::Type {
        Self::static_type()
    }
}

/// Control the alpha channel for drawables.
///
/// These values can be passed to gdk_pixbuf_xlib_render_to_drawable_alpha()
/// in gdk-pixbuf-xlib to control how the alpha channel of an image should
/// be handled.
///
/// This function can create a bilevel clipping mask (black and white) and use
/// it while painting the image.
///
/// In the future, when the X Window System gets an alpha channel extension,
/// it will be possible to do full alpha compositing onto arbitrary drawables.
/// For now both cases fall back to a bilevel clipping mask.
///
/// # Deprecated since 2.42
///
/// There is no user of GdkPixbufAlphaMode in GdkPixbuf,
///   and the Xlib utility functions have been split out to their own
///   library, gdk-pixbuf-xlib
#[cfg_attr(feature = "v2_42", deprecated = "Since 2.42")]
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "GdkPixbufAlphaMode")]
pub enum PixbufAlphaMode {
    /// A bilevel clipping mask (black and white)
    ///  will be created and used to draw the image.  Pixels below 0.5 opacity
    ///  will be considered fully transparent, and all others will be
    ///  considered fully opaque.
    #[doc(alias = "GDK_PIXBUF_ALPHA_BILEVEL")]
    Bilevel,
    /// For now falls back to #GDK_PIXBUF_ALPHA_BILEVEL.
    ///  In the future it will do full alpha compositing.
    #[doc(alias = "GDK_PIXBUF_ALPHA_FULL")]
    Full,
    #[doc(hidden)]
    __Unknown(i32),
}

impl fmt::Display for PixbufAlphaMode {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(
            f,
            "PixbufAlphaMode::{}",
            match *self {
                Self::Bilevel => "Bilevel",
                Self::Full => "Full",
                _ => "Unknown",
            }
        )
    }
}

#[doc(hidden)]
impl IntoGlib for PixbufAlphaMode {
    type GlibType = ffi::GdkPixbufAlphaMode;

    fn into_glib(self) -> ffi::GdkPixbufAlphaMode {
        match self {
            Self::Bilevel => ffi::GDK_PIXBUF_ALPHA_BILEVEL,
            Self::Full => ffi::GDK_PIXBUF_ALPHA_FULL,
            Self::__Unknown(value) => value,
        }
    }
}

#[doc(hidden)]
impl FromGlib<ffi::GdkPixbufAlphaMode> for PixbufAlphaMode {
    unsafe fn from_glib(value: ffi::GdkPixbufAlphaMode) -> Self {
        match value {
            ffi::GDK_PIXBUF_ALPHA_BILEVEL => Self::Bilevel,
            ffi::GDK_PIXBUF_ALPHA_FULL => Self::Full,
            value => Self::__Unknown(value),
        }
    }
}

impl StaticType for PixbufAlphaMode {
    fn static_type() -> Type {
        unsafe { from_glib(ffi::gdk_pixbuf_alpha_mode_get_type()) }
    }
}

impl glib::value::ValueType for PixbufAlphaMode {
    type Type = Self;
}

unsafe impl<'a> FromValue<'a> for PixbufAlphaMode {
    type Checker = glib::value::GenericValueTypeChecker<Self>;

    unsafe fn from_value(value: &'a glib::Value) -> Self {
        from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
    }
}

impl ToValue for PixbufAlphaMode {
    fn to_value(&self) -> glib::Value {
        let mut value = glib::Value::for_value_type::<Self>();
        unsafe {
            glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib());
        }
        value
    }

    fn value_type(&self) -> glib::Type {
        Self::static_type()
    }
}

/// An error code in the `GDK_PIXBUF_ERROR` domain.
///
/// Many gdk-pixbuf operations can cause errors in this domain, or in
/// the `G_FILE_ERROR` domain.
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "GdkPixbufError")]
pub enum PixbufError {
    /// An image file was broken somehow.
    #[doc(alias = "GDK_PIXBUF_ERROR_CORRUPT_IMAGE")]
    CorruptImage,
    /// Not enough memory.
    #[doc(alias = "GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY")]
    InsufficientMemory,
    /// A bad option was passed to a pixbuf save module.
    #[doc(alias = "GDK_PIXBUF_ERROR_BAD_OPTION")]
    BadOption,
    /// Unknown image type.
    #[doc(alias = "GDK_PIXBUF_ERROR_UNKNOWN_TYPE")]
    UnknownType,
    /// Don't know how to perform the
    ///  given operation on the type of image at hand.
    #[doc(alias = "GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION")]
    UnsupportedOperation,
    /// Generic failure code, something went wrong.
    #[doc(alias = "GDK_PIXBUF_ERROR_FAILED")]
    Failed,
    /// Only part of the animation was loaded.
    #[doc(alias = "GDK_PIXBUF_ERROR_INCOMPLETE_ANIMATION")]
    IncompleteAnimation,
    #[doc(hidden)]
    __Unknown(i32),
}

impl fmt::Display for PixbufError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(
            f,
            "PixbufError::{}",
            match *self {
                Self::CorruptImage => "CorruptImage",
                Self::InsufficientMemory => "InsufficientMemory",
                Self::BadOption => "BadOption",
                Self::UnknownType => "UnknownType",
                Self::UnsupportedOperation => "UnsupportedOperation",
                Self::Failed => "Failed",
                Self::IncompleteAnimation => "IncompleteAnimation",
                _ => "Unknown",
            }
        )
    }
}

#[doc(hidden)]
impl IntoGlib for PixbufError {
    type GlibType = ffi::GdkPixbufError;

    fn into_glib(self) -> ffi::GdkPixbufError {
        match self {
            Self::CorruptImage => ffi::GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
            Self::InsufficientMemory => ffi::GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
            Self::BadOption => ffi::GDK_PIXBUF_ERROR_BAD_OPTION,
            Self::UnknownType => ffi::GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
            Self::UnsupportedOperation => ffi::GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION,
            Self::Failed => ffi::GDK_PIXBUF_ERROR_FAILED,
            Self::IncompleteAnimation => ffi::GDK_PIXBUF_ERROR_INCOMPLETE_ANIMATION,
            Self::__Unknown(value) => value,
        }
    }
}

#[doc(hidden)]
impl FromGlib<ffi::GdkPixbufError> for PixbufError {
    unsafe fn from_glib(value: ffi::GdkPixbufError) -> Self {
        match value {
            ffi::GDK_PIXBUF_ERROR_CORRUPT_IMAGE => Self::CorruptImage,
            ffi::GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY => Self::InsufficientMemory,
            ffi::GDK_PIXBUF_ERROR_BAD_OPTION => Self::BadOption,
            ffi::GDK_PIXBUF_ERROR_UNKNOWN_TYPE => Self::UnknownType,
            ffi::GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION => Self::UnsupportedOperation,
            ffi::GDK_PIXBUF_ERROR_FAILED => Self::Failed,
            ffi::GDK_PIXBUF_ERROR_INCOMPLETE_ANIMATION => Self::IncompleteAnimation,
            value => Self::__Unknown(value),
        }
    }
}

impl ErrorDomain for PixbufError {
    fn domain() -> Quark {
        unsafe { from_glib(ffi::gdk_pixbuf_error_quark()) }
    }

    fn code(self) -> i32 {
        self.into_glib()
    }

    fn from(code: i32) -> Option<Self> {
        match code {
            ffi::GDK_PIXBUF_ERROR_CORRUPT_IMAGE => Some(Self::CorruptImage),
            ffi::GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY => Some(Self::InsufficientMemory),
            ffi::GDK_PIXBUF_ERROR_BAD_OPTION => Some(Self::BadOption),
            ffi::GDK_PIXBUF_ERROR_UNKNOWN_TYPE => Some(Self::UnknownType),
            ffi::GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION => Some(Self::UnsupportedOperation),
            ffi::GDK_PIXBUF_ERROR_FAILED => Some(Self::Failed),
            ffi::GDK_PIXBUF_ERROR_INCOMPLETE_ANIMATION => Some(Self::IncompleteAnimation),
            _ => Some(Self::Failed),
        }
    }
}

impl StaticType for PixbufError {
    fn static_type() -> Type {
        unsafe { from_glib(ffi::gdk_pixbuf_error_get_type()) }
    }
}

impl glib::value::ValueType for PixbufError {
    type Type = Self;
}

unsafe impl<'a> FromValue<'a> for PixbufError {
    type Checker = glib::value::GenericValueTypeChecker<Self>;

    unsafe fn from_value(value: &'a glib::Value) -> Self {
        from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
    }
}

impl ToValue for PixbufError {
    fn to_value(&self) -> glib::Value {
        let mut value = glib::Value::for_value_type::<Self>();
        unsafe {
            glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib());
        }
        value
    }

    fn value_type(&self) -> glib::Type {
        Self::static_type()
    }
}

/// The possible rotations which can be passed to gdk_pixbuf_rotate_simple().
///
/// To make them easier to use, their numerical values are the actual degrees.
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "GdkPixbufRotation")]
pub enum PixbufRotation {
    /// No rotation.
    #[doc(alias = "GDK_PIXBUF_ROTATE_NONE")]
    None,
    /// Rotate by 90 degrees.
    #[doc(alias = "GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE")]
    Counterclockwise,
    /// Rotate by 180 degrees.
    #[doc(alias = "GDK_PIXBUF_ROTATE_UPSIDEDOWN")]
    Upsidedown,
    /// Rotate by 270 degrees.
    #[doc(alias = "GDK_PIXBUF_ROTATE_CLOCKWISE")]
    Clockwise,
    #[doc(hidden)]
    __Unknown(i32),
}

impl fmt::Display for PixbufRotation {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(
            f,
            "PixbufRotation::{}",
            match *self {
                Self::None => "None",
                Self::Counterclockwise => "Counterclockwise",
                Self::Upsidedown => "Upsidedown",
                Self::Clockwise => "Clockwise",
                _ => "Unknown",
            }
        )
    }
}

#[doc(hidden)]
impl IntoGlib for PixbufRotation {
    type GlibType = ffi::GdkPixbufRotation;

    fn into_glib(self) -> ffi::GdkPixbufRotation {
        match self {
            Self::None => ffi::GDK_PIXBUF_ROTATE_NONE,
            Self::Counterclockwise => ffi::GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE,
            Self::Upsidedown => ffi::GDK_PIXBUF_ROTATE_UPSIDEDOWN,
            Self::Clockwise => ffi::GDK_PIXBUF_ROTATE_CLOCKWISE,
            Self::__Unknown(value) => value,
        }
    }
}

#[doc(hidden)]
impl FromGlib<ffi::GdkPixbufRotation> for PixbufRotation {
    unsafe fn from_glib(value: ffi::GdkPixbufRotation) -> Self {
        match value {
            ffi::GDK_PIXBUF_ROTATE_NONE => Self::None,
            ffi::GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE => Self::Counterclockwise,
            ffi::GDK_PIXBUF_ROTATE_UPSIDEDOWN => Self::Upsidedown,
            ffi::GDK_PIXBUF_ROTATE_CLOCKWISE => Self::Clockwise,
            value => Self::__Unknown(value),
        }
    }
}

impl StaticType for PixbufRotation {
    fn static_type() -> Type {
        unsafe { from_glib(ffi::gdk_pixbuf_rotation_get_type()) }
    }
}

impl glib::value::ValueType for PixbufRotation {
    type Type = Self;
}

unsafe impl<'a> FromValue<'a> for PixbufRotation {
    type Checker = glib::value::GenericValueTypeChecker<Self>;

    unsafe fn from_value(value: &'a glib::Value) -> Self {
        from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
    }
}

impl ToValue for PixbufRotation {
    fn to_value(&self) -> glib::Value {
        let mut value = glib::Value::for_value_type::<Self>();
        unsafe {
            glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib());
        }
        value
    }

    fn value_type(&self) -> glib::Type {
        Self::static_type()
    }
}