1#[cfg(feature = "f16-pixel-type")]
4use half::f16;
5
6use crate::format::{Format, SampleType};
7
8pub unsafe trait Component {
14 fn is_valid(format: Format) -> bool;
16}
17
18unsafe impl Component for u8 {
19 #[inline]
20 fn is_valid(format: Format) -> bool {
21 format.sample_type() == SampleType::Integer && format.bytes_per_sample() == 1
22 }
23}
24
25unsafe impl Component for u16 {
26 #[inline]
27 fn is_valid(format: Format) -> bool {
28 format.sample_type() == SampleType::Integer && format.bytes_per_sample() == 2
29 }
30}
31
32unsafe impl Component for u32 {
33 #[inline]
34 fn is_valid(format: Format) -> bool {
35 format.sample_type() == SampleType::Integer && format.bytes_per_sample() == 4
36 }
37}
38
39#[cfg(feature = "f16-pixel-type")]
40unsafe impl Component for f16 {
41 #[inline]
42 fn is_valid(format: Format) -> bool {
43 format.sample_type() == SampleType::Float && format.bytes_per_sample() == 2
44 }
45}
46
47unsafe impl Component for f32 {
48 #[inline]
49 fn is_valid(format: Format) -> bool {
50 format.sample_type() == SampleType::Float && format.bytes_per_sample() == 4
51 }
52}