use crate::{ColorSpace, Decoder, Info, SofKind};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[doc(hidden)]
pub enum JpegFastPacketFamily {
Fast420,
Fast422,
Fast444,
}
#[doc(hidden)]
#[must_use]
pub fn classify_color_fast_packet_family(decoder: &Decoder<'_>) -> Option<JpegFastPacketFamily> {
classify_color_fast_packet_info(decoder.info())
}
pub(super) fn classify_color_fast_packet_info(info: &Info) -> Option<JpegFastPacketFamily> {
if info.bit_depth != 8 || !matches!(info.sof_kind, SofKind::Baseline8 | SofKind::Extended8) {
return None;
}
match (info.color_space, info.sampling.components()) {
(ColorSpace::YCbCr, [(2, 2), (1, 1), (1, 1)]) => Some(JpegFastPacketFamily::Fast420),
(ColorSpace::YCbCr, [(2, 1), (1, 1), (1, 1)]) => Some(JpegFastPacketFamily::Fast422),
(ColorSpace::YCbCr | ColorSpace::Rgb, [(1, 1), (1, 1), (1, 1)]) => {
Some(JpegFastPacketFamily::Fast444)
}
_ => None,
}
}