1use num_derive::{FromPrimitive, ToPrimitive};
7pub use num_traits::cast::ToPrimitive;
8pub use num_traits::FromPrimitive;
9use std::fmt;
10use std::ops::Index;
11use std::slice;
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
15#[allow(clippy::upper_case_acronyms)]
16pub enum YUVRange {
17 Limited,
19 Full,
21}
22
23impl fmt::Display for YUVRange {
24 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25 match *self {
26 YUVRange::Limited => write!(f, "Limited range"),
27 YUVRange::Full => write!(f, "Full range"),
28 }
29 }
30}
31
32#[allow(clippy::upper_case_acronyms)]
37#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, FromPrimitive, ToPrimitive)]
38pub enum MatrixCoefficients {
39 Identity = 0,
47 BT709 = 1,
53 Unspecified = 2,
55 Reserved = 3,
57 BT470M = 4,
60 BT470BG = 5,
69 ST170M = 6,
76 ST240M = 7,
78 YCgCo = 8,
83 BT2020NonConstantLuminance = 9,
86 BT2020ConstantLuminance = 10,
88 ST2085 = 11,
90 ChromaticityDerivedNonConstantLuminance = 12,
92 ChromaticityDerivedConstantLuminance = 13,
94 ICtCp = 14,
96}
97
98impl fmt::Display for MatrixCoefficients {
99 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
100 match *self {
101 MatrixCoefficients::Identity => write!(f, "Identity"),
102 MatrixCoefficients::BT709 => write!(f, "ITU BT.709"),
103 MatrixCoefficients::Unspecified => write!(f, "Unspecified"),
104 MatrixCoefficients::Reserved => write!(f, "Reserved"),
105 MatrixCoefficients::BT470M => write!(f, "ITU BT.470M"),
106 MatrixCoefficients::BT470BG => write!(f, "ITU BT.470BG"),
107 MatrixCoefficients::ST170M => write!(f, "SMPTE ST-170M"),
108 MatrixCoefficients::ST240M => write!(f, "SMPTE ST-240M"),
109 MatrixCoefficients::YCgCo => write!(f, "YCgCo"),
110 MatrixCoefficients::BT2020NonConstantLuminance => {
111 write!(f, "ITU BT.2020 (Non Constant Luminance)")
112 }
113 MatrixCoefficients::BT2020ConstantLuminance => {
114 write!(f, "ITU BT.2020 (Constant Luminance)")
115 }
116 MatrixCoefficients::ST2085 => write!(f, "SMPTE ST-2085"),
117 MatrixCoefficients::ChromaticityDerivedNonConstantLuminance => {
118 write!(f, "Chromaticity Derived (Non ConstantLuminance)")
119 }
120 MatrixCoefficients::ChromaticityDerivedConstantLuminance => {
121 write!(f, "Chromaticity Derived (Constant Luminance)")
122 }
123 MatrixCoefficients::ICtCp => write!(f, "ICtCp"),
124 }
125 }
126}
127
128#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, FromPrimitive, ToPrimitive)]
133#[allow(clippy::upper_case_acronyms)]
134pub enum ColorPrimaries {
135 Reserved0 = 0,
137 BT709 = 1,
145 Unspecified = 2,
148 Reserved = 3,
150 BT470M = 4,
157 BT470BG = 5,
162 ST170M = 6,
169 ST240M = 7,
173 Film = 8,
175 BT2020 = 9,
178 ST428 = 10,
181 P3DCI = 11,
183 P3Display = 12,
185 Tech3213 = 22,
187}
188
189impl fmt::Display for ColorPrimaries {
190 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
191 match *self {
192 ColorPrimaries::Reserved0 => write!(f, "Identity"),
193 ColorPrimaries::BT709 => write!(f, "ITU BT.709"),
194 ColorPrimaries::Unspecified => write!(f, "Unspecified"),
195 ColorPrimaries::Reserved => write!(f, "Reserved"),
196 ColorPrimaries::BT470M => write!(f, "ITU BT.470M"),
197 ColorPrimaries::BT470BG => write!(f, "ITU BT.470BG"),
198 ColorPrimaries::ST170M => write!(f, "SMPTE ST-170M"),
199 ColorPrimaries::ST240M => write!(f, "SMPTE ST-240M"),
200 ColorPrimaries::Film => write!(f, "Film"),
201 ColorPrimaries::BT2020 => write!(f, "ITU BT.2020"),
202 ColorPrimaries::ST428 => write!(f, "SMPTE ST-428"),
203 ColorPrimaries::P3DCI => write!(f, "DCI P3"),
204 ColorPrimaries::P3Display => write!(f, "Display P3"),
205 ColorPrimaries::Tech3213 => write!(f, "EBU Tech3213"),
206 }
207 }
208}
209
210#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, FromPrimitive, ToPrimitive)]
218#[allow(clippy::upper_case_acronyms)]
219pub enum TransferCharacteristic {
220 Reserved0 = 0,
222 BT1886 = 1,
228 Unspecified = 2,
231 Reserved = 3,
233 BT470M = 4,
247 BT470BG = 5,
251 ST170M = 6,
259 ST240M = 7,
261 Linear = 8,
263 Logarithmic100 = 9,
266 Logarithmic316 = 10,
269 XVYCC = 11,
271 BT1361E = 12,
274 SRGB = 13,
279 BT2020Ten = 14,
283 BT2020Twelve = 15,
287 PerceptualQuantizer = 16,
292 ST428 = 17,
294 HybridLogGamma = 18,
298}
299
300impl fmt::Display for TransferCharacteristic {
301 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
302 match *self {
303 TransferCharacteristic::Reserved0 => write!(f, "Identity"),
304 TransferCharacteristic::BT1886 => write!(f, "ITU BT.1886"),
305 TransferCharacteristic::Unspecified => write!(f, "Unspecified"),
306 TransferCharacteristic::Reserved => write!(f, "Reserved"),
307 TransferCharacteristic::BT470M => write!(f, "ITU BT.470M"),
308 TransferCharacteristic::BT470BG => write!(f, "ITU BT.470BG"),
309 TransferCharacteristic::ST170M => write!(f, "SMPTE ST-170M"),
310 TransferCharacteristic::ST240M => write!(f, "SMPTE ST-240M"),
311 TransferCharacteristic::Linear => write!(f, "Linear"),
312 TransferCharacteristic::Logarithmic100 => write!(f, "Logarithmic 100:1 range"),
313 TransferCharacteristic::Logarithmic316 => write!(f, "Logarithmic 316:1 range"),
314 TransferCharacteristic::XVYCC => write!(f, "XVYCC"),
315 TransferCharacteristic::BT1361E => write!(f, "ITU BT.1361 Extended Color Gamut"),
316 TransferCharacteristic::SRGB => write!(f, "sRGB"),
317 TransferCharacteristic::BT2020Ten => write!(f, "ITU BT.2020 for 10bit systems"),
318 TransferCharacteristic::BT2020Twelve => write!(f, "ITU BT.2020 for 12bit systems"),
319 TransferCharacteristic::PerceptualQuantizer => write!(f, "Perceptual Quantizer"),
320 TransferCharacteristic::ST428 => write!(f, "SMPTE ST-428"),
321 TransferCharacteristic::HybridLogGamma => write!(f, "Hybrid Log-Gamma"),
322 }
323 }
324}
325
326#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
332#[allow(missing_docs)]
333pub enum ChromaLocation {
334 Unspecified = 0,
335 Left,
336 Center,
337 TopLeft,
338 Top,
339 BottomLeft,
340 Bottom,
341}
342
343impl fmt::Display for ChromaLocation {
344 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
345 use self::ChromaLocation::*;
346 match *self {
347 Unspecified => write!(f, "Unspecified"),
348 Left => write!(f, "Left"),
349 Center => write!(f, "Center"),
350 TopLeft => write!(f, "TopLeft"),
351 Top => write!(f, "Top"),
352 BottomLeft => write!(f, "BottomLeft"),
353 Bottom => write!(f, "Bottom"),
354 }
355 }
356}
357
358#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
360#[allow(clippy::upper_case_acronyms)]
361pub enum YUVSystem {
362 YCbCr(YUVRange),
366 YCoCg,
371 ICtCp,
375}
376
377impl fmt::Display for YUVSystem {
378 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
379 use self::YUVSystem::*;
380 match *self {
381 YCbCr(range) => write!(f, "YCbCr ({})", range),
382 YCoCg => write!(f, "YCbCg"),
383 ICtCp => write!(f, "ICtCp"),
384 }
385 }
386}
387
388#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
390#[allow(clippy::upper_case_acronyms)]
391pub enum TrichromaticEncodingSystem {
392 RGB,
394 YUV(YUVSystem),
396 XYZ,
401}
402
403impl fmt::Display for TrichromaticEncodingSystem {
404 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
405 use self::TrichromaticEncodingSystem::*;
406 match *self {
407 YUV(system) => write!(f, "{}", system),
408 RGB => write!(f, "RGB"),
409 XYZ => write!(f, "XYZ"),
410 }
411 }
412}
413
414#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
416#[allow(clippy::upper_case_acronyms)]
417pub enum ColorModel {
418 Trichromatic(TrichromaticEncodingSystem),
420 CMYK,
424 HSV,
428 LAB,
432}
433
434impl fmt::Display for ColorModel {
435 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
436 match *self {
437 ColorModel::Trichromatic(system) => write!(f, "{}", system),
438 ColorModel::CMYK => write!(f, "CMYK"),
439 ColorModel::HSV => write!(f, "HSV"),
440 ColorModel::LAB => write!(f, "LAB"),
441 }
442 }
443}
444
445impl ColorModel {
446 pub fn get_default_components(self) -> usize {
448 match self {
449 ColorModel::CMYK => 4,
450 _ => 3,
451 }
452 }
453}
454
455#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
460pub struct Chromaton {
461 pub h_ss: u8,
464 pub v_ss: u8,
467 pub packed: bool,
469 pub depth: u8,
471 pub shift: u8,
473 pub comp_offs: u8,
475 pub next_elem: u8,
477}
478
479fn align(v: usize, a: usize) -> usize {
480 (v + a - 1) & !(a - 1)
481}
482
483impl Chromaton {
484 pub const fn new(
486 h_ss: u8,
487 v_ss: u8,
488 packed: bool,
489 depth: u8,
490 shift: u8,
491 comp_offs: u8,
492 next_elem: u8,
493 ) -> Self {
494 Chromaton {
495 h_ss,
496 v_ss,
497 packed,
498 depth,
499 shift,
500 comp_offs,
501 next_elem,
502 }
503 }
504
505 pub const fn yuv8(h_ss: u8, v_ss: u8, comp_offs: u8) -> Chromaton {
507 Chromaton::new(h_ss, v_ss, false, 8, 0, comp_offs, 1)
508 }
509
510 pub const fn yuvhb(h_ss: u8, v_ss: u8, depth: u8, comp_offs: u8) -> Chromaton {
512 Chromaton::new(h_ss, v_ss, false, depth, 0, comp_offs, 1)
513 }
514
515 pub const fn packrgb(depth: u8, shift: u8, comp_offs: u8, next_elem: u8) -> Chromaton {
517 Chromaton::new(0, 0, true, depth, shift, comp_offs, next_elem)
518 }
519
520 pub const fn pal8(comp_offs: u8) -> Chromaton {
522 Chromaton::new(0, 0, true, 8, 0, comp_offs, 3)
523 }
524
525 pub fn get_subsampling(self) -> (u8, u8) {
527 (self.h_ss, self.v_ss)
528 }
529
530 pub fn is_packed(self) -> bool {
532 self.packed
533 }
534
535 pub fn get_depth(self) -> u8 {
537 self.depth
538 }
539
540 pub fn get_shift(self) -> u8 {
542 self.shift
543 }
544
545 pub fn get_offset(self) -> u8 {
547 self.comp_offs
548 }
549
550 pub fn get_step(self) -> u8 {
552 self.next_elem
553 }
554
555 pub fn get_width(self, width: usize) -> usize {
557 (width + ((1 << self.h_ss) - 1)) >> self.h_ss
558 }
559
560 pub fn get_height(self, height: usize) -> usize {
562 (height + ((1 << self.v_ss) - 1)) >> self.v_ss
563 }
564
565 pub fn get_linesize(self, width: usize, alignment: usize) -> usize {
567 let d = self.depth as usize;
568 align((self.get_width(width) * d + d - 1) >> 3, alignment)
569 }
570
571 pub fn get_data_size(self, width: usize, height: usize, align: usize) -> usize {
574 let nh = (height + ((1 << self.v_ss) - 1)) >> self.v_ss;
575 self.get_linesize(width, align) * nh
576 }
577}
578
579impl fmt::Display for Chromaton {
580 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
581 let pfmt = if self.packed {
582 let mask = ((1 << self.depth) - 1) << self.shift;
583 format!(
584 "packed(+{},{:X}, step {})",
585 self.comp_offs, mask, self.next_elem
586 )
587 } else {
588 format!("planar({},{})", self.comp_offs, self.next_elem)
589 };
590 write!(f, "({}x{}, {})", self.h_ss, self.v_ss, pfmt)
591 }
592}
593
594#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
601pub struct Formaton {
602 pub model: ColorModel,
604 pub primaries: ColorPrimaries,
606 pub xfer: TransferCharacteristic,
608 pub matrix: MatrixCoefficients,
610 pub chroma_location: ChromaLocation,
612
613 pub components: u8,
615 pub comp_info: [Option<Chromaton>; 5],
617 pub elem_size: u8,
619 pub be: bool,
621 pub alpha: bool,
623 pub palette: bool,
625}
626
627impl Formaton {
628 pub fn new(
630 model: ColorModel,
631 components: &[Chromaton],
632 elem_size: u8,
633 be: bool,
634 alpha: bool,
635 palette: bool,
636 ) -> Self {
637 let mut c: [Option<Chromaton>; 5] = [None; 5];
638
639 if components.len() > 5 {
640 panic!("too many components");
641 }
642
643 for (i, v) in components.iter().enumerate() {
644 c[i] = Some(*v);
645 }
646
647 Formaton {
648 model,
649
650 primaries: ColorPrimaries::Unspecified,
651 xfer: TransferCharacteristic::Unspecified,
652 matrix: MatrixCoefficients::Unspecified,
653 chroma_location: ChromaLocation::Unspecified,
654
655 components: components.len() as u8,
656 comp_info: c,
657 elem_size,
658 be,
659 alpha,
660 palette,
661 }
662 }
663
664 pub fn get_model(&self) -> ColorModel {
666 self.model
667 }
668
669 pub fn get_primaries(&self) -> ColorPrimaries {
671 self.primaries
672 }
673
674 pub fn get_total_depth(&self) -> u8 {
676 let mut depth = 0;
677 for chromaton in self.comp_info.iter().flatten() {
678 depth += chromaton.depth;
679 }
680 depth
681 }
682
683 pub fn set_primaries(mut self, pc: ColorPrimaries) {
685 self.primaries = pc;
686 }
687
688 pub fn set_primaries_from_u32(mut self, pc: u32) -> Option<ColorPrimaries> {
690 let parsed_pc = ColorPrimaries::from_u32(pc);
691 if let Some(pc) = parsed_pc {
692 self.primaries = pc
693 }
694 parsed_pc
695 }
696
697 pub fn get_xfer(&self) -> TransferCharacteristic {
699 self.xfer
700 }
701
702 pub fn set_xfer(mut self, pc: TransferCharacteristic) {
704 self.xfer = pc;
705 }
706
707 pub fn set_xfer_from_u32(mut self, tc: u32) -> Option<TransferCharacteristic> {
709 let parsed_tc = TransferCharacteristic::from_u32(tc);
710 if let Some(tc) = parsed_tc {
711 self.xfer = tc
712 }
713 parsed_tc
714 }
715
716 pub fn get_matrix(&self) -> MatrixCoefficients {
718 self.matrix
719 }
720
721 pub fn set_matrix(mut self, mc: MatrixCoefficients) {
723 self.matrix = mc;
724 }
725
726 pub fn set_matrix_from_u32(mut self, mc: u32) -> Option<MatrixCoefficients> {
728 let parsed_mc = MatrixCoefficients::from_u32(mc);
729 if let Some(mc) = parsed_mc {
730 self.matrix = mc
731 }
732 parsed_mc
733 }
734
735 pub fn get_num_comp(&self) -> usize {
737 self.components as usize
738 }
739 pub fn get_chromaton(&self, idx: usize) -> Option<Chromaton> {
741 if idx < self.comp_info.len() {
742 return self.comp_info[idx];
743 }
744 None
745 }
746
747 pub fn is_be(&self) -> bool {
749 self.be
750 }
751
752 pub fn has_alpha(&self) -> bool {
754 self.alpha
755 }
756
757 pub fn is_paletted(&self) -> bool {
759 self.palette
760 }
761
762 pub fn get_elem_size(&self) -> u8 {
764 self.elem_size
765 }
766
767 pub fn iter(&self) -> slice::Iter<Option<Chromaton>> {
769 self.comp_info.iter()
770 }
771}
772
773impl<'a> Index<usize> for &'a Formaton {
774 type Output = Option<Chromaton>;
775
776 fn index(&self, index: usize) -> &Self::Output {
777 self.comp_info.index(index)
778 }
779}
780
781impl<'a> IntoIterator for &'a Formaton {
782 type Item = &'a Option<Chromaton>;
783 type IntoIter = slice::Iter<'a, Option<Chromaton>>;
784
785 fn into_iter(self) -> Self::IntoIter {
786 self.comp_info.iter()
787 }
788}
789
790impl fmt::Display for Formaton {
791 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
792 let end = if self.be { "BE" } else { "LE" };
793 let palstr = if self.palette { "palette " } else { "" };
794 let astr = if self.alpha { "alpha " } else { "" };
795 let mut str = format!(
796 "Formaton for {} ({}{}elem {} size {}): ",
797 self.model, palstr, astr, end, self.elem_size
798 );
799 for &i in self.into_iter() {
800 if let Some(chr) = i {
801 str = format!("{} {}", str, chr);
802 }
803 }
804 write!(f, "[{}]", str)
805 }
806}
807
808pub mod formats {
809 use self::ColorModel::*;
814 use self::TrichromaticEncodingSystem::*;
815 use self::YUVRange::*;
816 use self::YUVSystem::*;
817 use crate::pixel::*;
818
819 pub const YUV444: &Formaton = &Formaton {
821 model: Trichromatic(YUV(YCbCr(Limited))),
822 primaries: ColorPrimaries::Unspecified,
823 xfer: TransferCharacteristic::Unspecified,
824 matrix: MatrixCoefficients::Unspecified,
825 chroma_location: ChromaLocation::Unspecified,
826 components: 3,
827 comp_info: [
828 Some(Chromaton::new(0, 0, false, 8, 0, 0, 1)),
829 Some(Chromaton::yuv8(0, 0, 1)),
830 Some(Chromaton::yuv8(0, 0, 2)),
831 None,
832 None,
833 ],
834 elem_size: 0,
835 be: false,
836 alpha: false,
837 palette: false,
838 };
839
840 pub const YUV422: &Formaton = &Formaton {
842 model: Trichromatic(YUV(YCbCr(Limited))),
843 primaries: ColorPrimaries::Unspecified,
844 xfer: TransferCharacteristic::Unspecified,
845 matrix: MatrixCoefficients::Unspecified,
846 chroma_location: ChromaLocation::Unspecified,
847 components: 3,
848 comp_info: [
849 Some(Chromaton::new(0, 0, false, 8, 0, 0, 1)),
850 Some(Chromaton::yuv8(0, 1, 1)),
851 Some(Chromaton::yuv8(0, 1, 2)),
852 None,
853 None,
854 ],
855 elem_size: 0,
856 be: false,
857 alpha: false,
858 palette: false,
859 };
860
861 pub const YUV420: &Formaton = &Formaton {
863 model: Trichromatic(YUV(YCbCr(Limited))),
864 primaries: ColorPrimaries::Unspecified,
865 xfer: TransferCharacteristic::Unspecified,
866 matrix: MatrixCoefficients::Unspecified,
867 chroma_location: ChromaLocation::Unspecified,
868 components: 3,
869 comp_info: [
870 Some(Chromaton::new(0, 0, false, 8, 0, 0, 1)),
871 Some(Chromaton::yuv8(1, 1, 1)),
872 Some(Chromaton::yuv8(1, 1, 2)),
873 None,
874 None,
875 ],
876 elem_size: 0,
877 be: false,
878 alpha: false,
879 palette: false,
880 };
881
882 pub const YUV411: &Formaton = &Formaton {
884 model: Trichromatic(YUV(YCbCr(Limited))),
885 primaries: ColorPrimaries::Unspecified,
886 xfer: TransferCharacteristic::Unspecified,
887 matrix: MatrixCoefficients::Unspecified,
888 chroma_location: ChromaLocation::Unspecified,
889 components: 3,
890 comp_info: [
891 Some(Chromaton::new(0, 0, false, 8, 0, 0, 1)),
892 Some(Chromaton::yuv8(2, 0, 1)),
893 Some(Chromaton::yuv8(2, 0, 2)),
894 None,
895 None,
896 ],
897 elem_size: 0,
898 be: false,
899 alpha: false,
900 palette: false,
901 };
902
903 pub const YUV410: &Formaton = &Formaton {
905 model: Trichromatic(YUV(YCbCr(Limited))),
906 primaries: ColorPrimaries::Unspecified,
907 xfer: TransferCharacteristic::Unspecified,
908 matrix: MatrixCoefficients::Unspecified,
909 chroma_location: ChromaLocation::Unspecified,
910 components: 3,
911 comp_info: [
912 Some(Chromaton::new(0, 0, false, 8, 0, 0, 1)),
913 Some(Chromaton::yuv8(2, 1, 1)),
914 Some(Chromaton::yuv8(2, 1, 2)),
915 None,
916 None,
917 ],
918 elem_size: 0,
919 be: false,
920 alpha: false,
921 palette: false,
922 };
923
924 pub const YUV444_10: &Formaton = &Formaton {
926 model: Trichromatic(YUV(YCbCr(Limited))),
927 primaries: ColorPrimaries::Unspecified,
928 xfer: TransferCharacteristic::Unspecified,
929 matrix: MatrixCoefficients::Unspecified,
930 chroma_location: ChromaLocation::Unspecified,
931 components: 3,
932 comp_info: [
933 Some(Chromaton::new(0, 0, false, 10, 0, 0, 1)),
934 Some(Chromaton::yuvhb(0, 0, 1, 10)),
935 Some(Chromaton::yuvhb(0, 0, 2, 10)),
936 None,
937 None,
938 ],
939 elem_size: 0,
940 be: false,
941 alpha: false,
942 palette: false,
943 };
944
945 pub const YUV422_10: &Formaton = &Formaton {
947 model: Trichromatic(YUV(YCbCr(Limited))),
948 primaries: ColorPrimaries::Unspecified,
949 xfer: TransferCharacteristic::Unspecified,
950 matrix: MatrixCoefficients::Unspecified,
951 chroma_location: ChromaLocation::Unspecified,
952 components: 3,
953 comp_info: [
954 Some(Chromaton::new(0, 0, false, 10, 0, 0, 1)),
955 Some(Chromaton::yuvhb(0, 1, 1, 10)),
956 Some(Chromaton::yuvhb(0, 1, 2, 10)),
957 None,
958 None,
959 ],
960 elem_size: 0,
961 be: false,
962 alpha: false,
963 palette: false,
964 };
965
966 pub const YUV420_10: &Formaton = &Formaton {
968 model: Trichromatic(YUV(YCbCr(Limited))),
969 primaries: ColorPrimaries::Unspecified,
970 xfer: TransferCharacteristic::Unspecified,
971 matrix: MatrixCoefficients::Unspecified,
972 chroma_location: ChromaLocation::Unspecified,
973 components: 3,
974 comp_info: [
975 Some(Chromaton::new(0, 0, false, 10, 0, 0, 1)),
976 Some(Chromaton::yuvhb(1, 1, 1, 10)),
977 Some(Chromaton::yuvhb(1, 1, 2, 10)),
978 None,
979 None,
980 ],
981 elem_size: 0,
982 be: false,
983 alpha: false,
984 palette: false,
985 };
986
987 pub const YUV411_10: &Formaton = &Formaton {
989 model: Trichromatic(YUV(YCbCr(Limited))),
990 primaries: ColorPrimaries::Unspecified,
991 xfer: TransferCharacteristic::Unspecified,
992 matrix: MatrixCoefficients::Unspecified,
993 chroma_location: ChromaLocation::Unspecified,
994 components: 3,
995 comp_info: [
996 Some(Chromaton::new(0, 0, false, 10, 0, 0, 1)),
997 Some(Chromaton::yuvhb(2, 0, 1, 10)),
998 Some(Chromaton::yuvhb(2, 0, 2, 10)),
999 None,
1000 None,
1001 ],
1002 elem_size: 0,
1003 be: false,
1004 alpha: false,
1005 palette: false,
1006 };
1007
1008 pub const YUV410_10: &Formaton = &Formaton {
1010 model: Trichromatic(YUV(YCbCr(Limited))),
1011 primaries: ColorPrimaries::Unspecified,
1012 xfer: TransferCharacteristic::Unspecified,
1013 matrix: MatrixCoefficients::Unspecified,
1014 chroma_location: ChromaLocation::Unspecified,
1015 components: 3,
1016 comp_info: [
1017 Some(Chromaton::new(0, 0, false, 10, 0, 0, 1)),
1018 Some(Chromaton::yuvhb(2, 1, 1, 10)),
1019 Some(Chromaton::yuvhb(2, 1, 2, 10)),
1020 None,
1021 None,
1022 ],
1023 elem_size: 0,
1024 be: false,
1025 alpha: false,
1026 palette: false,
1027 };
1028
1029 pub const PAL8: &Formaton = &Formaton {
1031 model: Trichromatic(RGB),
1032 primaries: ColorPrimaries::Unspecified,
1033 xfer: TransferCharacteristic::Unspecified,
1034 matrix: MatrixCoefficients::Unspecified,
1035 chroma_location: ChromaLocation::Unspecified,
1036 components: 3,
1037 comp_info: [
1038 Some(Chromaton::pal8(0)),
1039 Some(Chromaton::pal8(1)),
1040 Some(Chromaton::pal8(2)),
1041 None,
1042 None,
1043 ],
1044 elem_size: 3,
1045 be: false,
1046 alpha: false,
1047 palette: true,
1048 };
1049
1050 pub const RGB565: &Formaton = &Formaton {
1052 model: Trichromatic(RGB),
1053 primaries: ColorPrimaries::Unspecified,
1054 xfer: TransferCharacteristic::Unspecified,
1055 matrix: MatrixCoefficients::Unspecified,
1056 chroma_location: ChromaLocation::Unspecified,
1057 components: 3,
1058 comp_info: [
1059 Some(Chromaton::packrgb(5, 11, 0, 2)),
1060 Some(Chromaton::packrgb(6, 5, 0, 2)),
1061 Some(Chromaton::packrgb(5, 0, 0, 2)),
1062 None,
1063 None,
1064 ],
1065 elem_size: 2,
1066 be: false,
1067 alpha: false,
1068 palette: false,
1069 };
1070
1071 pub const RGB24: &Formaton = &Formaton {
1073 model: Trichromatic(RGB),
1074 primaries: ColorPrimaries::Unspecified,
1075 xfer: TransferCharacteristic::Unspecified,
1076 matrix: MatrixCoefficients::Unspecified,
1077 chroma_location: ChromaLocation::Unspecified,
1078 components: 3,
1079 comp_info: [
1080 Some(Chromaton::packrgb(8, 0, 2, 3)),
1081 Some(Chromaton::packrgb(8, 0, 1, 3)),
1082 Some(Chromaton::packrgb(8, 0, 0, 3)),
1083 None,
1084 None,
1085 ],
1086 elem_size: 3,
1087 be: false,
1088 alpha: false,
1089 palette: false,
1090 };
1091
1092 pub const RGBA: &Formaton = &Formaton {
1094 model: Trichromatic(RGB),
1095 primaries: ColorPrimaries::Unspecified,
1096 xfer: TransferCharacteristic::Unspecified,
1097 matrix: MatrixCoefficients::Unspecified,
1098 chroma_location: ChromaLocation::Unspecified,
1099 components: 4,
1100 comp_info: [
1101 Some(Chromaton::packrgb(8, 0, 3, 4)),
1102 Some(Chromaton::packrgb(8, 0, 2, 4)),
1103 Some(Chromaton::packrgb(8, 0, 1, 4)),
1104 Some(Chromaton::packrgb(8, 0, 0, 4)),
1105 None,
1106 ],
1107 elem_size: 4,
1108 be: false,
1109 alpha: true,
1110 palette: false,
1111 };
1112
1113 pub const RGB48: &Formaton = &Formaton {
1115 model: Trichromatic(RGB),
1116 primaries: ColorPrimaries::Unspecified,
1117 xfer: TransferCharacteristic::Unspecified,
1118 matrix: MatrixCoefficients::Unspecified,
1119 chroma_location: ChromaLocation::Unspecified,
1120 components: 3,
1121 comp_info: [
1122 Some(Chromaton::packrgb(16, 0, 2, 6)),
1123 Some(Chromaton::packrgb(16, 0, 1, 6)),
1124 Some(Chromaton::packrgb(16, 0, 0, 6)),
1125 None,
1126 None,
1127 ],
1128 elem_size: 6,
1129 be: false,
1130 alpha: false,
1131 palette: false,
1132 };
1133
1134 pub const RGBA64: &Formaton = &Formaton {
1136 model: Trichromatic(RGB),
1137 primaries: ColorPrimaries::Unspecified,
1138 xfer: TransferCharacteristic::Unspecified,
1139 matrix: MatrixCoefficients::Unspecified,
1140 chroma_location: ChromaLocation::Unspecified,
1141 components: 4,
1142 comp_info: [
1143 Some(Chromaton::packrgb(16, 0, 3, 8)),
1144 Some(Chromaton::packrgb(16, 0, 2, 8)),
1145 Some(Chromaton::packrgb(16, 0, 1, 8)),
1146 Some(Chromaton::packrgb(16, 0, 0, 8)),
1147 None,
1148 ],
1149 elem_size: 8,
1150 be: false,
1151 alpha: true,
1152 palette: false,
1153 };
1154}
1155
1156#[cfg(test)]
1157mod test {
1158 mod formats {
1159 use super::super::*;
1160 #[test]
1161 fn fmt() {
1162 println!("formaton yuv- {}", formats::YUV420);
1163 println!("formaton pal- {}", formats::PAL8);
1164 println!("formaton rgb565- {}", formats::RGB565);
1165 println!("formaton rgba- {}", formats::RGBA);
1166 println!("formaton rgb48- {}", formats::RGB48);
1167 println!("formaton rgba64- {}", formats::RGBA64);
1168 }
1169
1170 #[test]
1171 fn comparison() {
1172 use std::sync::Arc;
1173 let rcf = Arc::new(*formats::YUV420);
1174 let cf = &formats::YUV420.clone();
1175
1176 if cf != formats::YUV420 {
1177 panic!("cf");
1178 }
1179
1180 if *rcf != *formats::YUV420 {
1181 panic!("rcf");
1182 }
1183 }
1184 }
1185}