From d240c612f18cb4c8b2eb7487d675cbed5346adb6 Mon Sep 17 00:00:00 2001 From: Felix Hanau Date: Mon, 22 Jul 2019 13:30:27 +0100 Subject: [PATCH] Also sort when reducing to palette --- src/reduction/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/reduction/mod.rs b/src/reduction/mod.rs index c8fd94d9..0fa1476f 100644 --- a/src/reduction/mod.rs +++ b/src/reduction/mod.rs @@ -226,6 +226,14 @@ pub fn reduce_color_type(png: &PngImage) -> Option { } } + //Make sure that palette gets sorted. Ideally, this should be done within reduced_color_to_palette. + if should_reduce_bit_depth && reduced.ihdr.color_type == ColorType::Indexed { + if let Some(r) = reduced_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