Skip to content

Commit

Permalink
Test jpeg overlays over pngs
Browse files Browse the repository at this point in the history
  • Loading branch information
lilith committed Mar 17, 2021
1 parent f091d14 commit ab902fb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion imageflow_core/src/flow/nodes/watermark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl NodeDefOneInputExpand for WatermarkDef {

let opacity = f32::max(0f32, f32::min(1f32, watermark.opacity.unwrap_or(1f32)));
if opacity < 1f32 {
//TODO: push EnableTransparency node
//ColorFilterSrgb pushes the EnableTransparency node if Alpha is used, so we don't need to do that here
b.push(Node::from(imageflow_types::Node::ColorFilterSrgb(imageflow_types::ColorFilterSrgb::Alpha(opacity))));
}

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

#[test]
fn test_watermark_jpeg_over_pnga() {
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://imageflow-resources.s3-us-west-2.amazonaws.com/test_inputs/gamma_test.jpg".to_owned())
]), 500,
"watermark_jpeg_over_pnga", 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: Some(0.3f32),
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 @@ -55,6 +55,7 @@
"transparent_png_to_jpeg": "0DC709F50C5148224.jpg",
"transparent_png_to_jpeg_constrained": "0D6B7D34193494A6C.jpg",
"transparent_trim_whitespace": "0FBC6A5C3930ADEF7.png",
"watermark_jpeg_over_pnga": "04C0143A72CB4EBAA_073B7BE0C1ABF189F",
"webp_lossless_alpha_decode_and_scale": "057FA4CBAC9D0E267_0172196390B512E97",
"webp_lossy_alpha_decode_and_scale": "09F54D063249F69C8_0172196390B512E97",
"webp_lossy_opaque_decode_and_scale": "041A5FD590623EB11_0172196390B512E97",
Expand Down

0 comments on commit ab902fb

Please sign in to comment.