pub fn reduce_color_type(png: &PngImage) -> Option<PngImage> {
    let mut should_reduce_bit_depth = false;
    let mut reduced = Cow::Borrowed(png);

    // Go down one step at a time
    // Maybe not the most efficient, but it's safe
    if reduced.ihdr.color_type == ColorType::RGBA {
        if let Some(r) = reduce_rgba_to_grayscale_alpha(&reduced).or_else(|| reduced_alpha_channel(&reduced)) {
            reduced = Cow::Owned(r);
        } else if let Some(r) = reduced_color_to_palette(&reduced) {
            reduced = Cow::Owned(r);
            should_reduce_bit_depth = true;
        }
    }

    if reduced.ihdr.color_type == ColorType::GrayscaleAlpha {
        if let Some(r) = reduced_alpha_channel(&reduced) {
            reduced = Cow::Owned(r);
            should_reduce_bit_depth = true;
        }
    }

    if reduced.ihdr.color_type == ColorType::RGB {
        if let Some(r) = reduce_rgb_to_grayscale(&reduced).or_else(|| reduced_color_to_palette(&reduced)) {
            reduced = Cow::Owned(r);
            should_reduce_bit_depth = true;
        }
    }

    if should_reduce_bit_depth {
        // Some conversions will allow us to perform bit depth reduction that
        // wasn't possible before
        if let Some(r) = reduce_bit_depth_8_or_less(&reduced, 1) {
            reduced = Cow::Owned(r);
        }
    }

    match reduced {
        Cow::Owned(r) => Some(r),
        _ => None,
    }
}
/// Attempt to reduce the color type of the image
/// Returns true if the color type was reduced, false otherwise
Attempt to reduce the color type of the image
Returns true if the color type was reduced, false otherwise
Attempt to reduce the color type of the image Returns true if the color type was reduced false otherwise
pub fn reduce_color_type(png: &PngImage) -> Option<PngImage> {
    let mut should_reduce_bit_depth = false;
    let mut reduced = Cow::Borrowed(png);
    // Go down one step at a time
    // Maybe not the most efficient, but it's safe
    if reduced.ihdr.color_type == ColorType::RGBA {
        if let Some(r) = reduce_rgba_to_grayscale_alpha(&reduced).or_else(|| reduced_alpha_channel(&reduced)) {
            reduced = Cow::Owned(r);
        } else if let Some(r) = reduced_color_to_palette(&reduced) {
            reduced = Cow::Owned(r);
            should_reduce_bit_depth = true;
        }
    }
    if reduced.ihdr.color_type == ColorType::GrayscaleAlpha {
        if let Some(r) = reduced_alpha_channel(&reduced) {
            reduced = Cow::Owned(r);
            should_reduce_bit_depth = true;
        }
    }
    if reduced.ihdr.color_type == ColorType::RGB {
        if let Some(r) = reduce_rgb_to_grayscale(&reduced).or_else(|| reduced_color_to_palette(&reduced)) {
            reduced = Cow::Owned(r);
            should_reduce_bit_depth = true;
        }
    }
    if should_reduce_bit_depth {
        // Some conversions will allow us to perform bit depth reduction that
        // wasn't possible before
        if let Some(r) = reduce_bit_depth_8_or_less(&reduced, 1) {
            reduced = Cow::Owned(r);
        }
    }
    match reduced {
        Cow::Owned(r) => Some(r),
        _ => None,
    }
}
pub fn reduce_color_type ( png : & PngImage ) -> Option < PngImage > { let mut should_reduce_bit_depth = false ; let mut reduced = Cow :: Borrowed ( png ) ; // Go down one step at a time // Maybe not the most efficient, but it's safe if reduced . ihdr . color_type == ColorType :: RGBA { if let Some ( r ) = reduce_rgba_to_grayscale_alpha ( & reduced ) . or_else ( | | reduced_alpha_channel ( & reduced ) ) { reduced = Cow :: Owned ( r ) ; } else if let Some ( r ) = reduced_color_to_palette ( & reduced ) { reduced = Cow :: Owned ( r ) ; should_reduce_bit_depth = true ; } } if reduced . ihdr . color_type == ColorType :: GrayscaleAlpha { if let Some ( r ) = reduced_alpha_channel ( & reduced ) { reduced = Cow :: Owned ( r ) ; should_reduce_bit_depth = true ; } } if reduced . ihdr . color_type == ColorType :: RGB { if let Some ( r ) = reduce_rgb_to_grayscale ( & reduced ) . or_else ( | | reduced_color_to_palette ( & reduced ) ) { reduced = Cow :: Owned ( r ) ; should_reduce_bit_depth = true ; } } if should_reduce_bit_depth { // Some conversions will allow us to perform bit depth reduction that // wasn't possible before if let Some ( r ) = reduce_bit_depth_8_or_less ( & reduced , 1 ) { reduced = Cow :: Owned ( r ) ; } } match reduced { Cow :: Owned ( r ) => Some ( r ) , _ => None , } }
Attempt to reduce the color type of the image
Returns true if the color type was reduced, false otherwise
Attempt to reduce the color type of the image Returns true if the color type was reduced false otherwise
png
&PngImage
png
&PngImage