Skip to content

Commit

Permalink
Add watermark_red_dot JSON node and querystring command
Browse files Browse the repository at this point in the history
  • Loading branch information
lilith committed Nov 9, 2020
1 parent fde10b9 commit 4a570be
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 3 deletions.
1 change: 1 addition & 0 deletions imageflow_core/src/flow/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ impl From<s::Node> for Node {
Node::n(&nodes::COLOR_FILTER_SRGB, NodeParams::Json(node))
},
s::Node::Watermark (_) => Node::n(&nodes::WATERMARK, NodeParams::Json(node)),
s::Node::WatermarkRedDot => Node::n(&nodes::WATERMARK_RED_DOT, NodeParams::Json(node)),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions imageflow_core/src/flow/nodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod constrain;
mod white_balance;
mod color;
mod watermark;
mod watermark_red_dot;
mod enable_transparency;
//mod detection;

Expand Down Expand Up @@ -67,6 +68,7 @@ pub use self::color::COLOR_MATRIX_SRGB_MUTATE;
pub use self::color::COLOR_MATRIX_SRGB;
pub use self::color::COLOR_FILTER_SRGB;
pub use self::watermark::WATERMARK;
pub use self::watermark_red_dot::WATERMARK_RED_DOT;
pub use self::enable_transparency::ENABLE_TRANSPARENCY;

//pub use self::detection::CROP_FACES;
Expand Down
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 @@ -141,7 +141,7 @@ impl NodeDefOneInputExpand for WatermarkDef {
ctx.delete_node_and_snap_together(ix);
Ok(())
} else {
Err(nerror!(crate::ErrorKind::NodeParamsMismatch, "Need Constrain, got {:?}", params))
Err(nerror!(crate::ErrorKind::NodeParamsMismatch, "Need Watermark, got {:?}", params))
}
}
}
41 changes: 41 additions & 0 deletions imageflow_core/src/flow/nodes/watermark_red_dot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use super::internal_prelude::*;

pub static WATERMARK_RED_DOT: WatermarkRedDotDef = WatermarkRedDotDef{};

#[derive(Debug,Clone)]
pub struct WatermarkRedDotDef;
impl WatermarkRedDotDef{
}

impl NodeDef for WatermarkRedDotDef{
fn as_one_input_expand(&self) -> Option<&dyn NodeDefOneInputExpand>{
Some(self)
}
}
impl NodeDefOneInputExpand for WatermarkRedDotDef {
fn fqn(&self) -> &'static str {
"imazen.watermark"
}
fn expand(&self, ctx: &mut OpCtxMut, ix: NodeIndex, params: NodeParams, input: FrameInfo) -> Result<()> {
if let NodeParams::Json(imageflow_types::Node::WatermarkRedDot) = params {
let canvas_sufficient = input.w > 3 &&
input.h > 3;
if canvas_sufficient {

ctx.replace_node(ix, vec![
Node::from(imageflow_types::Node::FillRect {
x1: input.w as u32 - 3,
y1: input.h as u32 - 3,
x2: input.w as u32,
y2: input.h as u32,
color: imageflow_types::Color::Srgb(imageflow_types::ColorSrgb::Hex("FF0000".to_owned()))
})
]);

}
Ok(())
} else {
Err(nerror!(crate::ErrorKind::NodeParamsMismatch, "Need WatermarkRedDot, got {:?}", params))
}
}
}
27 changes: 27 additions & 0 deletions imageflow_core/tests/visuals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,33 @@ fn test_jpeg_simple_rot_90() {
assert!(matched);
}

#[test]
fn test_rot_90_and_red_dot() {
let url = "https://s3-us-west-2.amazonaws.com/imageflow-resources/test_inputs/orientation/Landscape_1.jpg".to_owned();
let title = "test_rot_90_and_red_dot".to_owned();
let matched = compare(Some(IoTestEnum::Url(url)), 500, &title, POPULATE_CHECKSUMS, DEBUG_GRAPH,
vec![Node::Decode { io_id: 0, commands: None },
Node::Constrain(Constraint { mode: ConstraintMode::Within, w: Some(70), h: Some(70), hints: None, gravity: None, canvas_color: None })
, Node::Rotate90,
Node::WatermarkRedDot]);
assert!(matched);
}
#[test]
fn test_rot_90_and_red_dot_command_string() {
let url = "https://s3-us-west-2.amazonaws.com/imageflow-resources/test_inputs/orientation/Landscape_1.jpg".to_owned();
let title = "test_rot_90_and_red_dot_command_string".to_owned();
let matched = compare(Some(IoTestEnum::Url(url)), 500, &title, POPULATE_CHECKSUMS, DEBUG_GRAPH,
vec![Node::CommandString {
kind: CommandStringKind::ImageResizer4,
value: "w=70&h=70&mode=max&rotate=90&watermark_red_dot=true".to_string(),
decode: Some(0),
encode: None,
watermarks: None
}]);
assert!(matched);
}


#[test]
fn test_jpeg_rotation() {
let orientations = vec!["Landscape", "Portrait"];
Expand Down
2 changes: 2 additions & 0 deletions imageflow_core/tests/visuals/checksums.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
"mountain_gif_scaled400": "03FB3160ED6A86E15_05C9232CFE2672D1C",
"test rotate 90 degrees": "0B843EE7B6518278E_0AE4839D1D9B04C57",
"test rotate jpeg 90 degrees": "0285B89DDE072042D_0AE4839D1D9B04C57",
"test_rot_90_and_red_dot": "0176FBE641002F3ED_0AE4839D1D9B04C57",
"test_rot_90_and_red_dot_command_string": "0C790C6600AFBBADA_0AE4839D1D9B04C57",
"transparent_png_to_jpeg": "0DC709F50C5148224.jpg",
"webp_lossless_alpha_decode_and_scale": "057FA4CBAC9D0E267_0172196390B512E97",
"webp_lossy_alpha_decode_and_scale": "09F54D063249F69C8_0172196390B512E97",
Expand Down
5 changes: 5 additions & 0 deletions imageflow_riapi/src/ir4/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@ impl Ir4Layout{
b.add_rotate(self.i.rotate);
b.add_flip(self.i.flip);

//We apply red dot watermarking after rotate/flip unlike imageresizer
if self.i.watermark_red_dot == Some(true){
b.add(s::Node::WatermarkRedDot);
}

Ok(Ir4LayoutInfo {
canvas
})
Expand Down
12 changes: 10 additions & 2 deletions imageflow_riapi/src/ir4/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ pub enum ScalingColorspace {

}

pub static IR4_KEYS: [&'static str;79] = ["mode", "anchor", "flip", "sflip", "scale", "cache", "process",
pub static IR4_KEYS: [&'static str;80] = ["mode", "anchor", "flip", "sflip", "scale", "cache", "process",
"quality", "jpeg.quality", "zoom", "crop", "cropxunits", "cropyunits",
"w", "h", "width", "height", "maxwidth", "maxheight", "format", "thumbnail",
"autorotate", "srotate", "rotate", "ignoreicc", "ignore_icc_errors", //really? : "precise_scaling_ratio",
"stretch", "webp.lossless", "webp.quality",
"stretch", "webp.lossless", "webp.quality", "watermark_red_dot",
"frame", "page", "subsampling", "colors", "f.sharpen", "f.sharpen_when", "down.colorspace",
"404", "bgcolor", "paddingcolor", "bordercolor", "preset", "floatspace",
"jpeg_idct_downscale_linear", "watermark", "s.invert", "s.sepia", "s.grayscale", "s.alpha",
Expand Down Expand Up @@ -360,6 +360,9 @@ impl Instructions{
add(&mut m, "down.filter", self.down_filter.map(|v| format!("{:?}", v).to_lowercase()));
add(&mut m, "up.filter", self.up_filter.map(|v| format!("{:?}", v).to_lowercase()));
add(&mut m, "decoder.min_precise_scaling_ratio", self.min_precise_scaling_ratio);

add(&mut m, "watermark_red_dot", self.watermark_red_dot);

m
}

Expand Down Expand Up @@ -447,6 +450,7 @@ impl Instructions{
i.jpeg_progressive = p.parse_bool("jpeg.progressive");
i.jpeg_turbo = p.parse_bool("jpeg.turbo");

i.watermark_red_dot = p.parse_bool("watermark_red_dot");
i
}

Expand Down Expand Up @@ -890,6 +894,7 @@ pub struct Instructions{
pub png_lossless: Option<bool>,
pub up_filter: Option<FilterStrings>,
pub down_filter: Option<FilterStrings>,
pub watermark_red_dot: Option<bool>
}
#[derive(Debug,Copy, Clone,PartialEq)]
pub enum Anchor1D{
Expand Down Expand Up @@ -1060,6 +1065,8 @@ fn test_url_parsing() {
t("down.filter=lanczos", Instructions{down_filter: Some(FilterStrings::Lanczos), ..Default::default()}, vec![]);

t("anchor=bottomleft", Instructions{anchor: Some((Anchor1D::Near, Anchor1D::Far)), ..Default::default()}, vec![]);
t("watermark_red_dot=true", Instructions{watermark_red_dot: Some(true), ..Default::default()}, vec![]);


expect_warning("a.balancewhite","gimp", Instructions{a_balance_white: Some(HistogramThresholdAlgorithm::Gimp), ..Default::default()});
expect_warning("a.balancewhite","simple", Instructions{a_balance_white: Some(HistogramThresholdAlgorithm::Simple), ..Default::default()});
Expand Down Expand Up @@ -1126,5 +1133,6 @@ fn test_tostr(){
t("anchor=bottomleft", Instructions{anchor: Some((Anchor1D::Near, Anchor1D::Far)), ..Default::default()});
t("ignoreicc=true", Instructions { ignoreicc: Some(true), ..Default::default() });
t("ignore_icc_errors=true", Instructions { ignore_icc_errors: Some(true), ..Default::default() });
t("watermark_red_dot=true", Instructions{watermark_red_dot: Some(true), ..Default::default()});

}
2 changes: 2 additions & 0 deletions imageflow_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,8 @@ pub enum Node {
// },
#[serde(rename="watermark")]
Watermark (Watermark),
#[serde(rename="watermark_red_dot")]
WatermarkRedDot,
#[serde(rename="white_balance_histogram_area_threshold_srgb")]
WhiteBalanceHistogramAreaThresholdSrgb{
threshold: Option<f32>
Expand Down

0 comments on commit 4a570be

Please sign in to comment.