diff --git a/src/reduction/alpha.rs b/src/reduction/alpha.rs index 658b8c28..be82bd8e 100644 --- a/src/reduction/alpha.rs +++ b/src/reduction/alpha.rs @@ -29,8 +29,11 @@ pub fn reduce_alpha_channel(png: &mut PngData, channels: u8) -> Option> // sBIT contains information about alpha channel's original depth, // and alpha has just been removed if let Some(sbit_header) = png.aux_headers.get_mut(b"sBIT") { - assert_eq!(sbit_header.len(), channels as usize); - sbit_header.pop(); + // Some programs save the sBIT header as RGB even if the image is RGBA. + // Only remove the alpha channel if it's actually there. + if sbit_header.len() == channels as usize { + sbit_header.pop(); + } } Some(reduced) diff --git a/tests/files/issue-141.png b/tests/files/issue-141.png new file mode 100644 index 00000000..586f7155 Binary files /dev/null and b/tests/files/issue-141.png differ diff --git a/tests/regression.rs b/tests/regression.rs index ea3ecf24..3a344963 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -548,3 +548,15 @@ fn issue_140() { BitDepth::Two, ); } + +#[test] +fn issue_141() { + test_it_converts( + "tests/files/issue-141.png", + None, + ColorType::RGBA, + BitDepth::Eight, + ColorType::RGB, + BitDepth::Eight, + ); +}