1#![cfg_attr(docsrs, feature(doc_cfg))]
2use core::fmt;
15
16pub mod convert;
17
18macro_rules! pixel_formats {
21 ($(
22 $(#[$meta:meta])*
23 $variant:ident = $code:literal, $name:literal $(| $alias:literal)*;
24 )*) => {
25 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
30 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
31 #[non_exhaustive]
32 #[repr(u32)]
33 #[allow(non_camel_case_types)]
36 pub enum PixelFormat {
37 $(
38 $(#[$meta])*
39 #[doc = concat!("PFNC `", stringify!($variant), "`, code `", stringify!($code), "`.")]
40 $variant = $code,
41 )*
42 Unknown(u32),
44 }
45
46 impl PixelFormat {
47 pub const fn from_code(code: u32) -> PixelFormat {
49 match code {
50 $($code => PixelFormat::$variant,)*
51 other => PixelFormat::Unknown(other),
52 }
53 }
54
55 pub const fn code(self) -> u32 {
57 match self {
58 $(PixelFormat::$variant => $code,)*
59 PixelFormat::Unknown(code) => code,
60 }
61 }
62
63 pub fn from_name(name: &str) -> PixelFormat {
70 match name {
71 $($name $(| $alias)* => PixelFormat::$variant,)*
72 _ => PixelFormat::Unknown(0),
73 }
74 }
75
76 pub const fn name(self) -> Option<&'static str> {
79 match self {
80 $(PixelFormat::$variant => Some($name),)*
81 PixelFormat::Unknown(_) => None,
82 }
83 }
84
85 #[cfg(test)]
87 const ALL: &'static [PixelFormat] = &[$(PixelFormat::$variant,)*];
88 }
89 };
90}
91
92pixel_formats! {
93 Mono8 = 0x0108_0001, "Mono8";
94 Mono10 = 0x0110_0003, "Mono10";
95 Mono12 = 0x0110_0005, "Mono12";
96 Mono14 = 0x0110_0025, "Mono14";
97 Mono16 = 0x0110_0007, "Mono16";
98 Mono10p = 0x010A_0046, "Mono10p";
101 Mono12p = 0x010C_0047, "Mono12p";
104 Mono10Packed = 0x010C_0004, "Mono10Packed";
108 Mono12Packed = 0x010C_0006, "Mono12Packed";
118 Confidence8 = 0x0108_00C6, "Confidence8";
119 Coord3DC16 = 0x0110_00B8, "Coord3D_C16";
120 Coord3DC32f = 0x0120_00BF, "Coord3D_C32f";
121 Coord3DAC16 = 0x0220_00BB, "Coord3D_AC16";
122 Coord3DAC32f = 0x0240_00C2, "Coord3D_AC32f";
123 Coord3DABC32f = 0x0260_00C0, "Coord3D_ABC32f";
124 BayerGR8 = 0x0108_0008, "BayerGR8";
125 BayerRG8 = 0x0108_0009, "BayerRG8";
126 BayerGB8 = 0x0108_000A, "BayerGB8";
127 BayerBG8 = 0x0108_000B, "BayerBG8";
128 BayerGR10 = 0x0110_000C, "BayerGR10";
129 BayerRG10 = 0x0110_000D, "BayerRG10";
130 BayerGB10 = 0x0110_000E, "BayerGB10";
131 BayerBG10 = 0x0110_000F, "BayerBG10";
132 BayerGR12 = 0x0110_0010, "BayerGR12";
133 BayerRG12 = 0x0110_0011, "BayerRG12";
134 BayerGB12 = 0x0110_0012, "BayerGB12";
135 BayerBG12 = 0x0110_0013, "BayerBG12";
136 BayerGR16 = 0x0110_002E, "BayerGR16";
137 BayerRG16 = 0x0110_002F, "BayerRG16";
138 BayerGB16 = 0x0110_0030, "BayerGB16";
139 BayerBG16 = 0x0110_0031, "BayerBG16";
140 BayerGR10p = 0x010A_0056, "BayerGR10p";
142 BayerRG10p = 0x010A_0058, "BayerRG10p";
144 BayerGB10p = 0x010A_0054, "BayerGB10p";
146 BayerBG10p = 0x010A_0052, "BayerBG10p";
148 BayerGR12p = 0x010C_0057, "BayerGR12p";
150 BayerRG12p = 0x010C_0059, "BayerRG12p";
152 BayerGB12p = 0x010C_0055, "BayerGB12p";
154 BayerBG12p = 0x010C_0053, "BayerBG12p";
156 BayerGR10Packed = 0x010C_0026, "BayerGR10Packed";
158 BayerRG10Packed = 0x010C_0027, "BayerRG10Packed";
160 BayerGB10Packed = 0x010C_0028, "BayerGB10Packed";
162 BayerBG10Packed = 0x010C_0029, "BayerBG10Packed";
164 BayerGR12Packed = 0x010C_002A, "BayerGR12Packed";
166 BayerRG12Packed = 0x010C_002B, "BayerRG12Packed";
168 BayerGB12Packed = 0x010C_002C, "BayerGB12Packed";
170 BayerBG12Packed = 0x010C_002D, "BayerBG12Packed";
172 RGB8Packed = 0x0218_0014, "RGB8Packed" | "RGB8";
173 BGR8Packed = 0x0218_0015, "BGR8Packed" | "BGR8";
174 RGBa8 = 0x0220_0016, "RGBa8" | "RGBA8Packed";
176 BGRa8 = 0x0220_0017, "BGRa8" | "BGRA8Packed";
178 YUV411_8_UYYVYY = 0x020C_001E, "YUV411_8_UYYVYY" | "YUV411Packed";
180 YUV422_8_UYVY = 0x0210_001F, "YUV422_8_UYVY" | "YUV422Packed";
182 YUV422_8 = 0x0210_0032, "YUV422_8" | "YUV422_YUYV_Packed";
185 YCbCr422_8 = 0x0210_003B, "YCbCr422_8";
187 YCbCr422_8_CbYCrY = 0x0210_0043, "YCbCr422_8_CbYCrY";
189 YUV8_UYV = 0x0218_0020, "YUV8_UYV" | "YUV444Packed";
191 YCbCr8_CbYCr = 0x0218_003A, "YCbCr8_CbYCr";
193 YCbCr8 = 0x0218_005B, "YCbCr8";
195 VendorLucidEvsEvt30 = 0x8110_0E30, "EVT3_0";
207 VendorLucidEvsEvt21 = 0x8140_0E21, "EVT2_1";
210}
211
212impl PixelFormat {
213 pub const fn bytes_per_pixel(self) -> Option<usize> {
221 PixelFormat::bytes_from_code(self.code())
222 }
223
224 const fn bytes_from_code(code: u32) -> Option<usize> {
242 let bits = (code >> 16) & 0xFF;
243 if bits == 0 || !bits.is_multiple_of(8) {
244 return None;
245 }
246 Some((bits / 8) as usize)
247 }
248
249 pub const fn bits_per_pixel(self) -> Option<u32> {
255 match (self.code() >> 16) & 0xFF {
256 0 => None,
257 bits => Some(bits),
258 }
259 }
260
261 pub const fn line_bytes(self, width: u32) -> Option<usize> {
269 self.bytes_for(width as usize)
270 }
271
272 pub const fn image_bytes(self, width: u32, height: u32) -> Option<usize> {
285 let Some(pixels) = (width as usize).checked_mul(height as usize) else {
286 return None;
287 };
288 self.bytes_for(pixels)
289 }
290
291 const fn group(self) -> Option<(usize, usize)> {
299 match self {
300 PixelFormat::YUV422_8
301 | PixelFormat::YUV422_8_UYVY
302 | PixelFormat::YCbCr422_8
303 | PixelFormat::YCbCr422_8_CbYCrY => return Some((2, 4)),
304 PixelFormat::YUV411_8_UYYVYY => return Some((4, 6)),
305 PixelFormat::VendorLucidEvsEvt30 | PixelFormat::VendorLucidEvsEvt21 => return None,
306 _ => {}
307 }
308 let Some(bits) = self.bits_per_pixel() else {
309 return None;
310 };
311 let common = 1u32 << bits.trailing_zeros();
313 let common = if common > 8 { 8 } else { common };
314 Some(((8 / common) as usize, (bits / common) as usize))
315 }
316
317 const fn bytes_for(self, pixels: usize) -> Option<usize> {
320 let Some((group_pixels, group_bytes)) = self.group() else {
321 return None;
322 };
323 pixels.div_ceil(group_pixels).checked_mul(group_bytes)
324 }
325
326 pub const fn is_bayer(self) -> bool {
328 self.cfa_pattern().is_some()
329 }
330
331 pub const fn is_mono(self) -> bool {
333 matches!(
334 self,
335 PixelFormat::Mono8
336 | PixelFormat::Mono10
337 | PixelFormat::Mono12
338 | PixelFormat::Mono14
339 | PixelFormat::Mono16
340 | PixelFormat::Mono10p
341 | PixelFormat::Mono12p
342 | PixelFormat::Mono10Packed
343 | PixelFormat::Mono12Packed
344 )
345 }
346
347 pub const fn cfa_pattern(self) -> Option<(&'static str, u8, u8)> {
355 use PixelFormat as P;
356 match self {
357 P::BayerRG8
358 | P::BayerRG10
359 | P::BayerRG12
360 | P::BayerRG16
361 | P::BayerRG10p
362 | P::BayerRG12p
363 | P::BayerRG10Packed
364 | P::BayerRG12Packed => Some(("RGGB", 0, 0)),
365 P::BayerGR8
366 | P::BayerGR10
367 | P::BayerGR12
368 | P::BayerGR16
369 | P::BayerGR10p
370 | P::BayerGR12p
371 | P::BayerGR10Packed
372 | P::BayerGR12Packed => Some(("RGGB", 1, 0)),
373 P::BayerGB8
374 | P::BayerGB10
375 | P::BayerGB12
376 | P::BayerGB16
377 | P::BayerGB10p
378 | P::BayerGB12p
379 | P::BayerGB10Packed
380 | P::BayerGB12Packed => Some(("RGGB", 0, 1)),
381 P::BayerBG8
382 | P::BayerBG10
383 | P::BayerBG12
384 | P::BayerBG16
385 | P::BayerBG10p
386 | P::BayerBG12p
387 | P::BayerBG10Packed
388 | P::BayerBG12Packed => Some(("RGGB", 1, 1)),
389 _ => None,
390 }
391 }
392}
393
394impl fmt::Display for PixelFormat {
395 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
396 match self.name() {
397 Some(name) => f.write_str(name),
398 None => write!(f, "Unknown(0x{:08X})", self.code()),
399 }
400 }
401}
402
403#[cfg(test)]
404mod tests {
405 use super::PixelFormat;
406
407 #[test]
408 fn roundtrip_known_codes() {
409 for &fmt in PixelFormat::ALL {
410 assert_eq!(PixelFormat::from_code(fmt.code()), fmt);
411 assert_eq!(PixelFormat::from_name(&fmt.to_string()), fmt);
412 }
413 }
414
415 #[test]
416 fn unknown_code_roundtrip() {
417 let code = 0xDEAD_BEEF;
418 let fmt = PixelFormat::from_code(code);
419 assert!(matches!(fmt, PixelFormat::Unknown(value) if value == code));
420 assert_eq!(fmt.code(), code);
421 }
422
423 #[test]
424 fn bytes_per_pixel_matches_expectations() {
425 assert_eq!(PixelFormat::Mono8.bytes_per_pixel(), Some(1));
426 assert_eq!(PixelFormat::Mono10.bytes_per_pixel(), Some(2));
427 assert_eq!(PixelFormat::Mono16.bytes_per_pixel(), Some(2));
428 assert_eq!(PixelFormat::Confidence8.bytes_per_pixel(), Some(1));
429 assert_eq!(PixelFormat::Coord3DC32f.bytes_per_pixel(), Some(4));
430 assert_eq!(PixelFormat::Coord3DAC16.bytes_per_pixel(), Some(4));
431 assert_eq!(PixelFormat::Coord3DAC32f.bytes_per_pixel(), Some(8));
432 assert_eq!(PixelFormat::Coord3DABC32f.bytes_per_pixel(), Some(12));
433 assert_eq!(PixelFormat::RGB8Packed.bytes_per_pixel(), Some(3));
434 assert_eq!(PixelFormat::BayerRG8.bytes_per_pixel(), Some(1));
435 assert_eq!(PixelFormat::BayerRG16.bytes_per_pixel(), Some(2));
436 assert_eq!(PixelFormat::BayerGR16.bytes_per_pixel(), Some(2));
437 assert_eq!(PixelFormat::VendorLucidEvsEvt30.bytes_per_pixel(), Some(2));
438 assert_eq!(PixelFormat::VendorLucidEvsEvt21.bytes_per_pixel(), Some(8));
439 assert_eq!(PixelFormat::Unknown(0).bytes_per_pixel(), None);
440 }
441
442 #[test]
443 fn event_format_names_roundtrip() {
444 for (name, format) in [
445 ("EVT3_0", PixelFormat::VendorLucidEvsEvt30),
446 ("EVT2_1", PixelFormat::VendorLucidEvsEvt21),
447 ] {
448 assert_eq!(PixelFormat::from_name(name), format);
449 assert_eq!(format.to_string(), name);
450 }
451 }
452
453 #[test]
456 fn named_formats_agree_with_their_own_pfnc_code() {
457 for &fmt in PixelFormat::ALL {
458 let disguised = PixelFormat::from_code((fmt.code() & 0xFFFF_0000) | 0xFFFF);
462 assert!(
463 matches!(disguised, PixelFormat::Unknown(_)),
464 "{fmt}: the disguise resolved to a named format"
465 );
466 assert_eq!(
467 fmt.bytes_per_pixel(),
468 disguised.bytes_per_pixel(),
469 "{fmt}: the hardcoded size disagrees with bits 23-16 of its own code"
470 );
471 }
472 }
473
474 #[test]
477 fn unknown_formats_are_sized_from_their_code() {
478 assert_eq!(
481 PixelFormat::from_code(0x0218_0021).bytes_per_pixel(),
482 Some(3)
483 );
484 assert_eq!(
485 PixelFormat::from_code(0x0230_0033).bytes_per_pixel(),
486 Some(6)
487 );
488 assert_eq!(
489 PixelFormat::from_code(0x0260_00C1).bytes_per_pixel(),
490 Some(12)
491 );
492 }
493
494 #[test]
501 fn packed_formats_report_no_whole_byte_size() {
502 for (name, code) in [
503 ("Mono10Packed", 0x010C_0004_u32),
504 ("Mono12Packed", 0x010C_0006),
505 ("YUV411Packed", 0x020C_001E),
506 ("BayerGB12Packed", 0x010C_002C),
507 ("BayerBG12Packed", 0x010C_002D),
508 ] {
509 assert_eq!(
510 PixelFormat::from_code(code).bytes_per_pixel(),
511 None,
512 "{name} declares 12 bits per pixel and must not be rounded"
513 );
514 }
515 }
516
517 #[test]
518 fn scancontrol_names_resolve_to_known_formats() {
519 let formats = [
520 ("Mono10", PixelFormat::Mono10),
521 ("Confidence8", PixelFormat::Confidence8),
522 ("Coord3D_C32f", PixelFormat::Coord3DC32f),
523 ("Coord3D_AC16", PixelFormat::Coord3DAC16),
524 ("Coord3D_AC32f", PixelFormat::Coord3DAC32f),
525 ("Coord3D_ABC32f", PixelFormat::Coord3DABC32f),
526 ];
527
528 for (name, format) in formats {
529 assert_eq!(PixelFormat::from_name(name), format);
530 assert_eq!(format.to_string(), name);
531 }
532 }
533
534 #[test]
538 fn names_and_codes_match_the_emva_values_table() {
539 for (name, code) in [
540 ("Mono10p", 0x010A_0046_u32),
541 ("Mono12p", 0x010C_0047),
542 ("Mono10Packed", 0x010C_0004),
543 ("Mono12Packed", 0x010C_0006),
544 ("BayerGR10", 0x0110_000C),
545 ("BayerRG10", 0x0110_000D),
546 ("BayerGB10", 0x0110_000E),
547 ("BayerBG10", 0x0110_000F),
548 ("BayerGR12", 0x0110_0010),
549 ("BayerRG12", 0x0110_0011),
550 ("BayerGB12", 0x0110_0012),
551 ("BayerBG12", 0x0110_0013),
552 ("BayerGR16", 0x0110_002E),
553 ("BayerRG16", 0x0110_002F),
554 ("BayerGB16", 0x0110_0030),
555 ("BayerBG16", 0x0110_0031),
556 ("BayerGR10Packed", 0x010C_0026),
557 ("BayerRG10Packed", 0x010C_0027),
558 ("BayerGB10Packed", 0x010C_0028),
559 ("BayerBG10Packed", 0x010C_0029),
560 ("BayerGR12Packed", 0x010C_002A),
561 ("BayerRG12Packed", 0x010C_002B),
562 ("BayerGB12Packed", 0x010C_002C),
563 ("BayerBG12Packed", 0x010C_002D),
564 ("BayerBG10p", 0x010A_0052),
565 ("BayerBG12p", 0x010C_0053),
566 ("BayerGB10p", 0x010A_0054),
567 ("BayerGB12p", 0x010C_0055),
568 ("BayerGR10p", 0x010A_0056),
569 ("BayerGR12p", 0x010C_0057),
570 ("BayerRG10p", 0x010A_0058),
571 ("BayerRG12p", 0x010C_0059),
572 ("RGBa8", 0x0220_0016),
573 ("BGRa8", 0x0220_0017),
574 ("YUV411_8_UYYVYY", 0x020C_001E),
575 ("YUV422_8_UYVY", 0x0210_001F),
576 ("YUV422_8", 0x0210_0032),
577 ("YCbCr422_8", 0x0210_003B),
578 ("YCbCr422_8_CbYCrY", 0x0210_0043),
579 ("YUV8_UYV", 0x0218_0020),
580 ("YCbCr8_CbYCr", 0x0218_003A),
581 ("YCbCr8", 0x0218_005B),
582 ("Coord3D_C16", 0x0110_00B8),
583 ] {
584 assert_eq!(PixelFormat::from_name(name).code(), code, "{name}");
585 assert_eq!(
586 PixelFormat::from_code(code).to_string(),
587 name,
588 "{code:#010X}"
589 );
590 }
591 }
592
593 #[test]
597 fn bayer16_codes_are_not_the_bayer10_and_12_codes() {
598 assert_eq!(PixelFormat::BayerGR16.code(), 0x0110_002E);
599 assert_eq!(PixelFormat::BayerRG16.code(), 0x0110_002F);
600 assert_eq!(PixelFormat::BayerGB16.code(), 0x0110_0030);
601 assert_eq!(PixelFormat::BayerBG16.code(), 0x0110_0031);
602 assert_eq!(PixelFormat::from_code(0x0110_000E).to_string(), "BayerGB10");
603 assert_eq!(PixelFormat::from_code(0x0110_0011).to_string(), "BayerRG12");
604 }
605
606 #[test]
610 fn legacy_names_resolve_to_the_pfnc_codes() {
611 for (name, code) in [
612 ("YUV422Packed", 0x0210_001F_u32),
613 ("YUV422_YUYV_Packed", 0x0210_0032),
614 ("YUV411Packed", 0x020C_001E),
615 ("YUV444Packed", 0x0218_0020),
616 ("RGBA8Packed", 0x0220_0016),
617 ("BGRA8Packed", 0x0220_0017),
618 ("RGB8Packed", 0x0218_0014),
619 ("BGR8Packed", 0x0218_0015),
620 ] {
621 assert_eq!(PixelFormat::from_name(name).code(), code, "{name}");
622 }
623 }
624
625 #[test]
628 fn cfa_offsets_align_to_rggb() {
629 use PixelFormat as P;
630 for (formats, offsets) in [
631 (
632 [P::BayerRG8, P::BayerRG10, P::BayerRG12, P::BayerRG16],
633 ("RGGB", 0, 0),
634 ),
635 (
636 [P::BayerGR8, P::BayerGR10, P::BayerGR12, P::BayerGR16],
637 ("RGGB", 1, 0),
638 ),
639 (
640 [P::BayerGB8, P::BayerGB10, P::BayerGB12, P::BayerGB16],
641 ("RGGB", 0, 1),
642 ),
643 (
644 [P::BayerBG8, P::BayerBG10, P::BayerBG12, P::BayerBG16],
645 ("RGGB", 1, 1),
646 ),
647 (
648 [
649 P::BayerRG10p,
650 P::BayerRG12p,
651 P::BayerRG10Packed,
652 P::BayerRG12Packed,
653 ],
654 ("RGGB", 0, 0),
655 ),
656 (
657 [
658 P::BayerGR10p,
659 P::BayerGR12p,
660 P::BayerGR10Packed,
661 P::BayerGR12Packed,
662 ],
663 ("RGGB", 1, 0),
664 ),
665 (
666 [
667 P::BayerGB10p,
668 P::BayerGB12p,
669 P::BayerGB10Packed,
670 P::BayerGB12Packed,
671 ],
672 ("RGGB", 0, 1),
673 ),
674 (
675 [
676 P::BayerBG10p,
677 P::BayerBG12p,
678 P::BayerBG10Packed,
679 P::BayerBG12Packed,
680 ],
681 ("RGGB", 1, 1),
682 ),
683 ] {
684 for format in formats {
685 assert_eq!(format.cfa_pattern(), Some(offsets), "{format}");
686 assert!(format.is_bayer() && !format.is_mono(), "{format}");
687 }
688 }
689 assert_eq!(P::Mono8.cfa_pattern(), None);
690 assert_eq!(P::Mono12Packed.cfa_pattern(), None);
691 for &format in P::ALL {
693 assert_eq!(
694 format.is_bayer(),
695 format.to_string().starts_with("Bayer"),
696 "{format}"
697 );
698 }
699 }
700
701 #[test]
704 fn bits_per_pixel_is_the_size_field_of_the_code() {
705 use PixelFormat as P;
706 for (format, bits) in [
707 (P::Mono8, 8),
708 (P::Mono10p, 10),
709 (P::Mono12p, 12),
710 (P::Mono10Packed, 12),
711 (P::Mono12Packed, 12),
712 (P::Mono12, 16),
713 (P::BayerRG12Packed, 12),
714 (P::YUV411_8_UYYVYY, 12),
715 (P::YUV422_8, 16),
716 (P::RGB8Packed, 24),
717 (P::RGBa8, 32),
718 ] {
719 assert_eq!(format.bits_per_pixel(), Some(bits), "{format}");
720 }
721 assert_eq!(P::Unknown(0).bits_per_pixel(), None);
722 assert_eq!(P::from_code(0x0110_FFFF).bits_per_pixel(), Some(16));
723 }
724
725 #[test]
731 fn line_bytes_complete_the_last_packing_group() {
732 use PixelFormat as P;
733 for (format, width, bytes) in [
734 (P::Mono8, 7, 7),
735 (P::Mono12, 3, 6),
736 (P::RGB8Packed, 2, 6),
737 (P::Mono10p, 4, 5),
738 (P::Mono10p, 8, 10),
739 (P::Mono10p, 1, 5),
740 (P::Mono10p, 5, 10),
741 (P::Mono12p, 2, 3),
742 (P::Mono12p, 3, 6),
743 (P::Mono12Packed, 640, 960),
744 (P::Mono12Packed, 1, 3),
745 (P::Mono10Packed, 2, 3),
746 (P::BayerGR10p, 4, 5),
747 (P::YUV422_8_UYVY, 2, 4),
748 (P::YUV422_8, 3, 8),
749 (P::YUV411_8_UYYVYY, 4, 6),
750 (P::YUV411_8_UYYVYY, 5, 12),
751 (P::YUV8_UYV, 3, 9),
752 ] {
753 assert_eq!(format.line_bytes(width), Some(bytes), "{format} × {width}");
754 }
755 }
756
757 #[test]
760 fn image_bytes_complete_only_the_last_group() {
761 use PixelFormat as P;
762 for (format, width, height, bytes) in [
763 (P::Mono8, 640, 480, 307_200),
764 (P::Mono16, 640, 480, 614_400),
765 (P::Mono12Packed, 640, 480, 460_800),
766 (P::Mono12p, 640, 480, 460_800),
767 (P::Mono10p, 640, 480, 384_000),
768 (P::Mono10p, 2, 2, 5),
769 (P::Mono10p, 3, 3, 15),
770 (P::Mono12p, 3, 1, 6),
771 (P::YUV422_8, 640, 480, 614_400),
772 (P::YUV422_8, 3, 1, 8),
773 (P::Coord3DABC32f, 1280, 1, 15_360),
774 ] {
775 assert_eq!(
776 format.image_bytes(width, height),
777 Some(bytes),
778 "{format} {width}×{height}"
779 );
780 }
781 assert_eq!(P::VendorLucidEvsEvt30.image_bytes(1, 64_000), None);
783 assert_eq!(P::VendorLucidEvsEvt21.image_bytes(1, 64_000), None);
784 assert_eq!(P::Unknown(0).image_bytes(4, 4), None);
785 assert_eq!(P::from_code(0x010C_FFFF).image_bytes(2, 1), Some(3));
787 }
788
789 #[test]
790 fn image_bytes_refuse_to_overflow() {
791 assert_eq!(
792 PixelFormat::Coord3DABC32f.image_bytes(u32::MAX, u32::MAX),
793 None
794 );
795 }
796}