Skip to content

Commit

Permalink
Fix #613, 24-bit PNG files with a zero alpha channel are now properly…
Browse files Browse the repository at this point in the history
… encoded when using lossy PNG and when no transparency-inducing operations are performed.
  • Loading branch information
lilith committed Nov 21, 2022
1 parent c6039b4 commit d5f439c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions imageflow_core/src/codecs/pngquant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ impl Encoder for PngquantEncoder {
let mut bitmap = bitmaps.try_borrow_mut(bitmap_key)
.map_err(|e| e.at(here!()))?;

{
let mut bitmap_bgra = unsafe { bitmap.get_window_u8().unwrap().to_bitmap_bgra()? };
bitmap_bgra.normalize_alpha().map_err(|e| e.at(here!()))?;
}

unsafe {
let (vec,w,h) = bitmap.get_window_u8()
.ok_or_else(|| nerror!(ErrorKind::InvalidBitmapType))?
Expand Down
4 changes: 2 additions & 2 deletions imageflow_core/tests/visuals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ fn test_transparent_png_to_png() {
#[test]
fn test_problematic_png_lossy() {
compare_encoded(
Some(IoTestEnum::Url("https://imageflow-resources.s3.us-west-2.amazonaws.com/test_inputs/png_turns_empty.png".to_owned())),
Some(IoTestEnum::Url("https://imageflow-resources.s3.us-west-2.amazonaws.com/test_inputs/png_turns_empty_2.png".to_owned())),
"test_problematic_png_lossy",
POPULATE_CHECKSUMS,
DEBUG_GRAPH,
Constraints {
similarity: Similarity::AllowOffByOneBytesCount(100),
similarity: Similarity::AllowDssimMatch(0.0, 0.002),
max_file_size: None
},
vec![
Expand Down
2 changes: 1 addition & 1 deletion imageflow_core/tests/visuals/checksums.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"test_branching_crop_whitespace_gradient_output_1": "01864661ED8AB31EF.png",
"test_branching_crop_whitespace_gradient_output_2": "0B3D16EB972FE0DBB.png",
"test_negatives_in_command_string": "0BA85F7DC751DD69E_0726847C75419A20C",
"test_problematic_png_lossy": "0E5E63543D35A149D.png",
"test_problematic_png_lossy": "03B9493B2F3806A45.png",
"test_rot_90_and_red_dot": "0176FBE641002F3ED_0AE4839D1D9B04C57",
"test_rot_90_and_red_dot_command_string": "0C790C6600AFBBADA_0AE4839D1D9B04C57",
"test_round_corners_command_string": "05218274046A5989B_0BF80F0AE71CD9A63",
Expand Down

0 comments on commit d5f439c

Please sign in to comment.