jiao 0.4.1

Cross platform 2D graphics library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
// Copyright (c) 2023 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
// Use of this source is governed by Lesser General Public License that can be found
// in the LICENSE file.

use crate::base::math::MAX_S32;
use crate::core::alpha_type::AlphaType;
use crate::core::color_space::ColorSpace;
use crate::core::color_type::{self, ColorType};
use crate::core::irect::IRect;
use crate::core::size::ISize;

/// `YuvColorSpace` describes color range of YUV pixels.
///
/// The color mapping from YUV to RGB varies depending on the source.
/// YUV pixels may be generated by JPEG images, standard video streams,
/// or high definition video streams. Each has its own mapping from YUV to RGB.
///
/// JPEG YUV values encode the full range of 0 to 255 for all three components.
/// Video YUV values often range from 16 to 235 for Y and from 16 to 240 for U and V (limited).
/// Details of encoding and conversion to RGB are described in `YCbCr` color space.
///
/// The identity colorspace exists to provide a utility mapping from Y to R, U to G and V to B.
/// It can be used to visualize the YUV planes or to explicitly post process the YUV channels.

//#[repr(u32)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum YuvColorSpace {
    /// describes full range
    JpegFull,

    /// describes SDTV range
    Rec601Limited,

    /// describes HDTV range
    Rec709Full,

    Rec709Limited,

    /// describes UHDTV range, non-constant-luminance
    Bt2020_8bitFull,

    Bt2020_8bitLimited,

    Bt2020_10bitFull,

    Bt2020_10bitLimited,

    Bt2020_12bitFull,

    Bt2020_12bitLimited,

    /// maps Y->R, U->G, V->B
    Identity,
}

/// `ColorInfo` describes pixel and encoding.
///
/// `ImageInfo` can be created from `ColorInfo` by providing dimensions.
///
/// It encodes how pixel bits describe alpha, transparency; color components red, blue,
/// and green; and `ColorSpace`, the range and linearity of colors.
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ColorInfo {
    color_space: Option<ColorSpace>,
    color_type: ColorType,
    alpha_type: AlphaType,
}

impl Default for ColorInfo {
    fn default() -> Self {
        Self::new()
    }
}

impl ColorInfo {
    #[must_use]
    pub const fn new() -> Self {
        Self {
            color_space: None,
            color_type: ColorType::Unknown,
            alpha_type: AlphaType::Unknown,
        }
    }

    /// Creates `ColorInfo` from `ColorType`, `AlphaType` and `ColorSpace`.
    /// `ColorSpace` defaults to `sRGB`.
    #[must_use]
    pub const fn from(
        color_type: ColorType,
        alpha_type: AlphaType,
        color_space: Option<ColorSpace>,
    ) -> Self {
        Self {
            color_space,
            color_type,
            alpha_type,
        }
    }

    /// Creates `ColorInfo` with same `ColorType`, `ColorSpace` as self, with `AlphaType` changed.
    ///
    /// Created `ColorInfo` contains `new_alpha_type` even if it is incompatible with
    /// `ColorType`, in which case `AlphaType` in `ColorInfo` is ignored.
    #[must_use]
    pub fn from_alpha_type(&self, new_alpha_type: AlphaType) -> Self {
        Self {
            color_space: self.color_space.clone(),
            color_type: self.color_type,
            alpha_type: new_alpha_type,
        }
    }

    /// Creates new `ColorInfo` with same `AlphaType`, `ColorSpace` as self, with `ColorType`
    /// changed.
    #[must_use]
    pub fn from_color_type(&self, new_color_type: ColorType) -> Self {
        Self {
            color_space: self.color_space.clone(),
            color_type: new_color_type,
            alpha_type: self.alpha_type,
        }
    }

    /// Creates `ColorInfo` with same `AlphaType`, `ColorType` as self, with `ColorSpace` changed.
    #[must_use]
    pub const fn from_color_space(&self, new_color_space: Option<ColorSpace>) -> Self {
        Self {
            color_space: new_color_space,
            color_type: self.color_type,
            alpha_type: self.alpha_type,
        }
    }

    #[must_use]
    pub const fn color_space(&self) -> &Option<ColorSpace> {
        &self.color_space
    }

    #[must_use]
    pub const fn color_type(&self) -> ColorType {
        self.color_type
    }

    #[must_use]
    pub const fn alpha_type(&self) -> AlphaType {
        self.alpha_type
    }

    #[must_use]
    pub fn is_opaque(&self) -> bool {
        self.alpha_type.is_opaque() || self.color_type.is_always_opaque()
    }

    #[must_use]
    pub const fn gamma_close_to_srgb(&self) -> bool {
        if let Some(color_space) = &self.color_space {
            color_space.gamma_close_to_srgb()
        } else {
            false
        }
    }

    /// Returns number of bytes per pixel required by `ColorType`.
    ///
    /// Returns zero if `color_type()` is `ColorType::Unknown`.
    #[must_use]
    pub const fn bytes_per_pixel(&self) -> i32 {
        self.color_type.bytes_per_pixel()
    }

    /// Returns bit shift converting row bytes to row pixels.
    ///
    /// Returns zero for `ColorType::Unknown`.
    ///
    /// One of: 0, 1, 2, 3, 4; left shift to convert pixels to bytes
    #[must_use]
    pub const fn shift_per_pixel(&self) -> i32 {
        self.color_type.shift_per_pixel()
    }

    /// Returns true if contains a valid `color_type` and `alpha_type`.
    pub(crate) fn is_valid(&self) -> bool {
        self.color_type != ColorType::Unknown && self.alpha_type != AlphaType::Unknown
    }
}

/// `ImageInfo` describes pixel dimensions and encoding.
///
/// `Bitmap`, `Image`, `PixMap`, and `Surface` can be created from `ImageInfo`.
///
/// `ImageInfo` can be retrieved from `Bitmap` and `Pixmap`, but not from `Image` and
/// `Surface`.
/// For example, `Image` and `Surface` implementations may defer pixel depth,
/// so may not completely specify `ImageInfo`.
///
/// `ImageInfo` contains dimensions, the pixel integral width and height.
/// It encodes how pixel bits describe alpha, transparency; color components red, blue,
/// and green; and `ColorSpace`, the range and linearity of colors.
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ImageInfo {
    color_info: ColorInfo,
    dimensions: ISize,
}

impl Default for ImageInfo {
    fn default() -> Self {
        Self::new()
    }
}

impl ImageInfo {
    /// Creates an empty `ImageInfo` with `ColorType::Unknown`, `AlphaType::Unknown`,
    /// a width and height of zero, and no `ColorSpace`.
    #[must_use]
    pub const fn new() -> Self {
        Self {
            color_info: ColorInfo::new(),
            dimensions: ISize::new(),
        }
    }

    /// Creates `ImageInfo` from integral dimensions width and height, `ColorType`,
    /// `AlphaType`, and optionally `ColorSpace`.
    ///
    /// If `ColorSpace` is None and `ImageInfo` is part of drawing source: `ColorSpace`
    /// defaults to `sRGB`, mapping into `Surface` `ColorSpace`.
    ///
    /// # Parameters
    /// Parameters are not validated to see if their values are legal, or that the
    /// combination is supported.
    ///
    /// - `width` - pixel column count; must be zero or greater
    /// - `height` - pixel row count; must be zero or greater
    /// - `cs` - range of colors; may be None
    #[must_use]
    pub const fn from(
        width: i32,
        height: i32,
        ct: ColorType,
        at: AlphaType,
        cs: Option<ColorSpace>,
    ) -> Self {
        Self {
            color_info: ColorInfo::from(ct, at, cs),
            dimensions: ISize::from_wh(width, height),
        }
    }

    #[must_use]
    pub const fn new_dimensions(
        dimensions: ISize,
        ct: ColorType,
        at: AlphaType,
        cs: Option<ColorSpace>,
    ) -> Self {
        Self {
            color_info: ColorInfo::from(ct, at, cs),
            dimensions,
        }
    }

    /// Creates `ImageInfo` from integral dimensions and `ColorInfo`.
    ///
    /// # Parameters
    /// Parameters are not validated to see if their values are legal, or that the
    /// combination is supported.
    ///
    /// - `dimensions` - pixel column and row count; must be zeros or greater
    /// - `color_info` - the pixel encoding consisting of `ColorType`, `AlphaType`, and
    ///                  `ColorSpace` (which may be nullptr)
    #[must_use]
    pub const fn from_color_info(dimensions: ISize, color_info: ColorInfo) -> Self {
        Self {
            color_info,
            dimensions,
        }
    }

    /// Creates `ImageInfo` from integral dimensions width and height, `ColorType` N32,
    /// `AlphaType`, and optionally `ColorSpace`.
    ///
    /// `ColorType` N32 will equal either `ColorType::Bgra8888` or `ColorType::Rgba8888`,
    /// whichever is optimal.
    ///
    /// If `ColorSpace` is None and `ImageInfo` is part of drawing source: `ColorSpace`
    /// defaults to `sRGB`, mapping into `Surface` `ColorSpace`.
    ///
    /// # Parameters
    /// Parameters are not validated to see if their values are legal, or that the
    /// combination is supported.
    ///
    /// - `width` - pixel column count; must be zero or greater
    /// - `height` -  pixel row count; must be zero or greater
    /// - `cs` - range of colors; may be None
    #[must_use]
    pub const fn new_n32(width: i32, height: i32, at: AlphaType, cs: Option<ColorSpace>) -> Self {
        Self {
            color_info: ColorInfo::from(color_type::N32, at, cs),
            dimensions: ISize::from_wh(width, height),
        }
    }

    /// Creates `ImageInfo` from integral dimensions width and height, `ColorType` N32,
    /// `AlphaType`, with `sRGB` `ColorSpace`.
    ///
    /// # Parameters
    /// Parameters are not validated to see if their values are legal, or that the
    /// combination is supported.
    ///
    /// - `width` - pixel column count; must be zero or greater
    /// - `height` - pixel column count; must be zero or greater
    #[must_use]
    pub const fn new_s32(width: i32, height: i32, at: AlphaType) -> Self {
        Self {
            // TODO(Shaohua): Set color space.
            color_info: ColorInfo::from(color_type::N32, at, None),
            dimensions: ISize::from_wh(width, height),
        }
    }

    /// Creates `ImageInfo` from integral dimensions width and height, `ColorType` N32,
    /// `AlphaType::Premul`, with optional `ColorSpace`.
    ///
    /// If `ColorSpace` is None and `ImageInfo` is part of drawing source: `ColorSpace`
    /// defaults to `sRGB`, mapping into `Surface` `ColorSpace`.
    ///
    /// # Parameters
    /// Parameters are not validated to see if their values are legal, or that the
    /// combination is supported.
    ///
    /// - `width` - pixel column count; must be zero or greater
    /// - `height` -  pixel row count; must be zero or greater
    /// - `cs` - range of colors; may be None
    #[must_use]
    pub const fn new_n32_premul(width: i32, height: i32, cs: Option<ColorSpace>) -> Self {
        Self {
            color_info: ColorInfo::from(ColorType::Alpha8, AlphaType::Premul, cs),
            dimensions: ISize::from_wh(width, height),
        }
    }

    /// Creates `ImageInfo` from integral dimensions width and height, `ColorType::Alpha8`,
    /// `AlphaType::Premul`, with `ColorSpace` set to None.
    ///
    /// # Parameters
    /// - `width` - pixel column count; must be zero or greater
    /// - `height` - pixel row count; must be zero or greater
    #[must_use]
    pub const fn new_a8(width: i32, height: i32) -> Self {
        Self {
            color_info: ColorInfo::from(ColorType::Alpha8, AlphaType::Premul, None),
            dimensions: ISize::from_wh(width, height),
        }
    }

    /// Creates `ImageInfo` from integral dimensions width and height, `ColorType::Unknown`,
    /// `AlphaType::Unknown`, with `ColorSpace` set to None.
    ///
    /// Returned `ImageInfo` as part of source does not draw, and as part of destination
    /// can not be drawn to.
    ///
    /// # Parameters
    /// - `width` - pixel column count; must be zero or greater
    /// - `height` - pixel row count; must be zero or greater
    #[must_use]
    pub const fn new_unknown(width: i32, height: i32) -> Self {
        Self {
            color_info: ColorInfo::from(ColorType::Unknown, AlphaType::Unknown, None),
            dimensions: ISize::from_wh(width, height),
        }
    }

    /// Creates `ImageInfo` from integral dimensions width and height set to zero,
    /// `ColorType::Unknown`, `AlphaType::Unknown`, with `ColorSpace` set to None.
    #[must_use]
    pub const fn new_unknown_empty() -> Self {
        Self::new_unknown(0, 0)
    }

    /// Creates `ImageInfo` with the same `ColorType`, `ColorSpace`, and `AlphaType`,
    /// with dimensions set to width and height.
    ///
    /// # Parameters
    /// - `new_width` - pixel column count; must be zero or greater
    /// - `new_height` - pixel row count; must be zero or greater
    #[must_use]
    pub fn from_wh(&self, new_width: i32, new_height: i32) -> Self {
        Self::from_color_info(
            ISize::from_wh(new_width, new_height),
            self.color_info.clone(),
        )
    }

    /// Creates `ImageInfo` with the same `ColorType`, `ColorSpace`, and `AlphaType`,
    /// with dimensions set to `new_dimensions`.
    #[must_use]
    pub fn from_dimensions(&self, new_size: ISize) -> Self {
        Self::from_color_info(new_size, self.color_info.clone())
    }

    /// Creates `ImageInfo` with same `ColorType`, `ColorSpace`, width, and height,
    /// with `AlphaType` set to `new_alpha_type`.
    ///
    /// Created `ImageInfo` contains `new_alpha_type` even if it is incompatible with
    /// `ColorType`, in which case `AlphaType` in `ImageInfo` is ignored.
    #[must_use]
    pub fn from_alpha_type(&self, new_alpha_type: AlphaType) -> Self {
        Self::from_color_info(
            self.dimensions,
            self.color_info.from_alpha_type(new_alpha_type),
        )
    }

    /// Creates `ImageInfo` with same `AlphaType`, `ColorSpace`, width, and height,
    /// with `ColorType` set to `new_color_type`.
    #[must_use]
    pub fn from_color_type(&self, new_color_type: ColorType) -> Self {
        Self::from_color_info(
            self.dimensions,
            self.color_info.from_color_type(new_color_type),
        )
    }

    /// Creates `ImageInfo` with same `AlphaType`, `ColorType`, width, and height,
    /// with `ColorSpace` set to `new_color_space`.
    #[must_use]
    pub const fn from_color_space(&self, new_color_space: Option<ColorSpace>) -> Self {
        Self::from_color_info(
            self.dimensions,
            self.color_info.from_color_space(new_color_space),
        )
    }

    /// Returns pixel count in each row.
    #[must_use]
    pub const fn width(&self) -> i32 {
        self.dimensions.width()
    }

    /// Returns pixel row count.
    #[must_use]
    pub const fn height(&self) -> i32 {
        self.dimensions.height()
    }

    #[must_use]
    pub const fn color_type(&self) -> ColorType {
        self.color_info.color_type()
    }

    #[must_use]
    pub const fn alpha_type(&self) -> AlphaType {
        self.color_info.alpha_type()
    }

    /// Returns `ColorSpace`, the range of colors.
    #[must_use]
    pub const fn color_space(&self) -> &Option<ColorSpace> {
        self.color_info.color_space()
    }

    /// Returns if `ImageInfo` describes an empty area of pixels by checking if either
    /// width or height is zero or smaller.
    #[must_use]
    pub const fn is_empty(&self) -> bool {
        self.dimensions.is_empty()
    }

    /// Returns the dimensionless `ColorInfo` that represents the same color type,
    /// alpha type, and color space as this `ImageInfo`.
    #[must_use]
    pub const fn color_info(&self) -> &ColorInfo {
        &self.color_info
    }

    /// Returns true if `AlphaType` is set to hint that all pixels are opaque; their
    /// alpha value is implicitly or explicitly 1.0.
    ///
    /// Return true if `AlphaType` is `AlphaType::Opaque`.
    /// If true, and all pixels are not opaque, may draw incorrectly.
    ///
    /// Does not check if `ColorType` allows alpha, or if any pixel value has
    /// transparency.
    #[must_use]
    pub fn is_opaque(&self) -> bool {
        self.color_info.is_opaque()
    }

    /// Returns `ISize { width(), height() }`.
    #[must_use]
    pub const fn dimensions(&self) -> ISize {
        self.dimensions
    }

    /// Returns true if contains a valid combination of width, height and `color_info`.
    #[must_use]
    pub(crate) fn is_valid(&self) -> bool {
        const MAX_DIMENSION: i32 = MAX_S32 >> 2;

        if self.width() <= 0 || self.height() <= 0 {
            return false;
        }

        if self.width() > MAX_DIMENSION || self.height() > MAX_DIMENSION {
            return false;
        }

        self.color_info.is_valid()
    }

    /// Returns true if it has defined a pixel conversion from the `src` to the `self`.
    /// Returns false otherwise.
    #[must_use]
    pub fn valid_conversion(&self, src: &Self) -> bool {
        self.is_valid() && src.is_valid()
    }

    /// Returns bounding rect.
    ///
    /// Returns integral rectangle from origin to `width()` and `height()`
    #[must_use]
    pub const fn bounds(&self) -> IRect {
        IRect::from_size(self.dimensions)
    }

    /// Returns true if associated `ColorSpace` is not None, and `ColorSpace` gamma
    /// is approximately the same as `sRGB`.
    #[must_use]
    pub const fn gamma_close_to_srgb(&self) -> bool {
        self.color_info.gamma_close_to_srgb()
    }

    /// Returns number of bytes per pixel required by `ColorType`.
    ///
    /// Returns zero if `color_type` is `ColorType::Unknown`.
    #[must_use]
    pub const fn bytes_per_pixel(&self) -> i32 {
        self.color_info.bytes_per_pixel()
    }

    /// Returns bit shift converting row bytes to row pixels.
    ///
    /// Returns zero for `ColorType::Unknown`.
    /// Returns one of: 0, 1, 2, 3; left shift to convert pixels to bytes
    #[must_use]
    pub const fn shift_per_pixel(&self) -> i32 {
        self.color_info.shift_per_pixel()
    }

    /// Returns minimum bytes per row, computed from pixel `width()` and `ColorType`,
    /// which specifies `bytes_per_pixel()`.
    ///
    /// `Bitmap` maximum value for row bytes must fit in 31 bits.
    ///
    /// Return `width()` times `bytes_per_pixel()` as unsigned 64-bit integer
    #[must_use]
    #[allow(clippy::cast_sign_loss)]
    pub const fn min_row_bytes64(&self) -> u64 {
        (self.width() as u64) * (self.bytes_per_pixel() as u64)
    }

    /// Returns minimum bytes per row, computed from pixel `width()` and `ColorType`,
    /// which specifies `bytes_per_pixel()`.
    ///
    /// `Bitmap` maximum value for row bytes must fit in 31 bits.
    #[must_use]
    #[allow(clippy::cast_possible_truncation)]
    pub const fn min_row_bytes(&self) -> usize {
        let min_row_bytes = self.min_row_bytes64();
        // TODO(Shaohua): Check range
        //if (!TFitsIn<int32_t>(minRowBytes)) {
        //    return 0;
        //}
        min_row_bytes as usize
    }

    /// Returns byte offset of pixel from pixel base address.
    ///
    /// Asserts in debug build if x or y is outside of bounds.
    /// Does not assert if `row_bytes` is smaller than `min_row_bytes()`,
    /// even though result may be incorrect.
    ///
    /// # Parameters
    /// - `x` - column index, zero or greater, and less than `width()`
    /// - `y` - row index, zero or greater, and less than `height()`
    /// - `row_bytes` - size of pixel row or larger
    #[must_use]
    pub const fn compute_offset(&self, _x: i32, _y: i32, _row_bytes: usize) -> usize {
        unimplemented!()
    }

    /// Returns storage required by pixel array, given `ImageInfo` dimensions,
    /// `ColorType`, and `row_bytes`.
    ///
    /// `row_bytes` is assumed to be at least as large as `min_row_bytes()`.
    ///
    /// Returns zero if height is zero.
    /// Returns `usize::MAX` if answer exceeds the range of usize.
    #[must_use]
    pub const fn compute_byte_size(&self, _row_bytes: usize) -> usize {
        unimplemented!()
    }

    /// Returns storage required by pixel array, given `ImageInfo` dimensions,
    /// and `ColorType`.
    ///
    /// Uses `min_row_bytes()` to compute bytes for pixel row.
    ///
    /// Returns zero if height is zero.
    ///
    /// Returns `usize::MAX` if answer exceeds the range of usize.
    ///
    /// Returns least memory required by pixel buffer
    #[must_use]
    pub const fn compute_min_byte_size(&self) -> usize {
        self.compute_byte_size(self.min_row_bytes())
    }

    /// Returns true if `byte_size` equals `usize::MAX`.
    ///
    /// `compute_byte_size()` and `compute_min_byte_size()` return `usize::MAX`
    /// if usize can not hold buffer size.
    ///
    /// # Parameters
    /// `byte_size` - result of `compute_byte_size()` or `compute_min_byte_size()`
    #[must_use]
    pub(crate) const fn byte_size_overflowed(byte_size: usize) -> bool {
        byte_size == usize::MAX
    }

    /// Returns true if `row_bytes` is valid for this `ImageInfo`.
    ///
    /// Returns true if `row_bytes` is large enough to contain pixel row
    /// and is properly aligned.
    ///
    /// # Parameters
    /// - `row_bytes` - size of pixel row including padding
    #[must_use]
    pub const fn valid_row_bytes(&self, row_bytes: usize) -> bool {
        if (row_bytes as u64) < self.min_row_bytes64() {
            return false;
        }

        let shift = self.shift_per_pixel();
        let aligned_row_bytes = row_bytes >> shift << shift;
        aligned_row_bytes == row_bytes
    }

    /// Creates an empty `ImageInfo` with `ColorType::Unknown`, `AlphaType::Unknown`,
    /// a width and height of zero, and no `ColorSpace`.
    pub fn reset(&mut self) {
        *self = Self::new();
    }

    // Asserts if internal values are illegal or inconsistent. Only available in debug mode at compile time.
    //validate() const;
}