Skip to content

Commit

Permalink
Fixes #538, adds regression test, fixes test harness
Browse files Browse the repository at this point in the history
  • Loading branch information
lilith committed Oct 21, 2020
1 parent a8b6e01 commit 1967ca4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
6 changes: 5 additions & 1 deletion imageflow_core/src/flow/nodes/scale_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ impl NodeDefOneInputExpand for ScaleDef {
let size_differs = w != parent.w as u32 || h != parent.h as u32;
let downscaling = w < parent.w as u32 || h < parent.h as u32;
let upscaling = w > parent.w as u32 || h > parent.h as u32;
let matte_color = hints.as_ref().and_then(|h| h.background_color.as_ref());
let apply_matte = parent.fmt == PixelFormat::Bgra32 &&
matte_color != Some(&s::Color::Transparent) && matte_color != None;

let sharpen_percent_raw = hints.as_ref().and_then(|h| h.sharpen_percent).unwrap_or(0f32);

Expand All @@ -60,7 +63,8 @@ impl NodeDefOneInputExpand for ScaleDef {
_ => false
};

if resample {
// TODO: apply matte in a more efficient way than resampling.
if resample || apply_matte {
let scale2d_params = imageflow_types::Node::Resample2D {
w,
h,
Expand Down
2 changes: 1 addition & 1 deletion imageflow_core/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ pub fn compare_encoded(input: Option<IoTestEnum>, checksum_name: &str, store_if_
let mut context = Context::create().unwrap();


let _ = build_steps(&mut context, &steps, io_vec, None, debug);
let _ = build_steps(&mut context, &steps, io_vec, None, debug).unwrap();

let bytes = context.get_output_buffer_slice(1).unwrap();

Expand Down
24 changes: 24 additions & 0 deletions imageflow_core/tests/visuals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ fn test_encode_gradients() {



#[test]
fn test_transparent_png_to_jpeg() {
compare_encoded(
Some(IoTestEnum::Url("https://s3-us-west-2.amazonaws.com/imageflow-resources/test_inputs/shirt_transparent.png".to_owned())),
"transparent_png_to_jpeg",
POPULATE_CHECKSUMS,
DEBUG_GRAPH,
Constraints {
similarity: Similarity::AllowDssimMatch(0.0, 0.00001),
max_file_size: None
},
vec![
Node::CommandString{
kind: CommandStringKind::ImageResizer4,
value: "format=jpg".to_owned(),
decode: Some(0),
encode: Some(1),
watermarks: None
}
]
);
}


#[test]
fn test_fill_rect(){
let matched = compare(None, 500,
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 @@ -42,6 +42,7 @@
"encode_pngquant": "0BD7DEBB451A58B0A.png",
"jpeg_crop": "0227EE691E56BA13A_0FB5487907981932B",
"mountain_gif_scaled400": "036AA4DCCE19C8DB7_05C9232CFE2672D1C",
"transparent_png_to_jpeg": "0DC709F50C5148224.jpg",
"webp_lossless_alpha_decode_and_scale": "057FA4CBAC9D0E267_0172196390B512E97",
"webp_lossy_alpha_decode_and_scale": "09F54D063249F69C8_0172196390B512E97",
"wrenches_decode": "0E680C080BE9CD3A9_01397E6B9AECAB9F4"
Expand Down

0 comments on commit 1967ca4

Please sign in to comment.