Skip to content

Commit

Permalink
Fix compositing when the canvas is a decoded PNG
Browse files Browse the repository at this point in the history
  • Loading branch information
lilith committed Mar 17, 2021
1 parent 395e3c9 commit f091d14
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion imageflow_core/src/codecs/libpng_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Decoder for LibPngDecoder {
w,h,fmt.pixel_layout(),
false, fmt.alpha_meaningful(),
ColorSpace::StandardRGB,
BitmapCompositing::BlendWithMatte(s::Color::Transparent))
BitmapCompositing::ReplaceSelf)
.map_err(|e| e.at(here!()))?;


Expand Down
33 changes: 33 additions & 0 deletions imageflow_core/tests/visuals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,39 @@ fn test_watermark_image_small() {
);
assert!(matched);
}


#[test]
fn test_watermark_image_on_png() {
let matched = compare_multiple(Some(vec![
IoTestEnum::Url("https://imageflow-resources.s3-us-west-2.amazonaws.com/test_inputs/shirt_transparent.png".to_owned()),
IoTestEnum::Url("https://s3-us-west-2.amazonaws.com/imageflow-resources/test_inputs/1_webp_a.sm.png".to_owned())
]), 500,
"WatermarkSmallOnPnga", POPULATE_CHECKSUMS, DEBUG_GRAPH, vec![
Node::Decode {io_id: 0, commands: None},
Node::Watermark(imageflow_types::Watermark{
io_id: 1,
gravity: Some(imageflow_types::ConstraintGravity::Percentage {x: 100f32, y: 100f32}),
fit_box: Some(imageflow_types::WatermarkConstraintBox::ImagePercentage {x1: 0f32, y1: 0f32, x2: 90f32, y2: 90f32}),
fit_mode: Some(imageflow_types::WatermarkConstraintMode::Within),
min_canvas_width: None,
min_canvas_height: None,
opacity: None,
hints: Some(imageflow_types::ResampleHints{
sharpen_percent: None,
down_filter: None,
up_filter: None,
scaling_colorspace: None,
background_color: None,
resample_when: None,
sharpen_when: None
}),

})
]
);
assert!(matched);
}
// Does not reproduce across different compiler optimizations
// #[test]
// fn test_image_rs_jpeg_decode(){
Expand Down
1 change: 1 addition & 0 deletions imageflow_core/tests/visuals/checksums.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Test_Jpeg_Simple.jpg": "018BC932FB29F2C53_0AF9F040B874D83F7",
"Watermark1": "008A242F2FBED3C1D_0DE3336C466C67DD9",
"WatermarkSmall": "09BF9877BE2CB36AC_0DE3336C466C67DD9",
"WatermarkSmallOnPnga": "0D6EA2688E7F01BD5_073B7BE0C1ABF189F",
"WhiteBalanceNight": "0D84206BD2DD308DA_05C9231C6124D62A8",
"cmyk_decode": "00C5CD1E1ADF2628A_0D58EB335590501F3",
"crop_with_preshrink": "04FF87FFA9A645517_09D5B46DC8E13B7B4",
Expand Down

0 comments on commit f091d14

Please sign in to comment.