Skip to content

Commit 999744c

Browse files
committed
Invalidate estimates when reconfiguring decoder during command string expansion
1 parent d45a18f commit 999744c

File tree

6 files changed

+72
-33
lines changed

6 files changed

+72
-33
lines changed

imageflow_core/src/flow/nodes/constrain.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,26 @@ fn command_string_partially_expanded_def() -> NodeDefinition {
171171
description: "expanding command string",
172172
fn_estimate: Some({
173173
fn f(ctx: &mut OpCtxMut, ix: NodeIndex<u32>) {
174-
let e = get_expand(ctx, ix);
175174

175+
let old_estimate = ctx.weight(ix).frame_est;
176+
177+
178+
if old_estimate == FrameEstimate::Invalidated{
179+
ctx.weight_mut(ix).frame_est = FrameEstimate::Impossible;
180+
} else {
181+
let e = get_expand(ctx, ix);
176182

177-
if let Some(command) = e.get_decode_commands().unwrap() {
178-
//Send command to codec
179-
for io_id in ctx.get_decoder_io_ids(ix) {
180-
ctx.job.tell_decoder(io_id, command.clone()).unwrap();
183+
if let Some(command) = e.get_decode_commands().unwrap() {
184+
//Send command to codec
185+
for (io_id, decoder_ix) in ctx.get_decoder_io_ids_and_indexes(ix) {
186+
ctx.job.tell_decoder(io_id, command.clone()).unwrap();
187+
ctx.weight_mut(decoder_ix).frame_est = FrameEstimate::Invalidated;
188+
}
181189
}
182-
}
183190

184-
let weight = &mut ctx.weight_mut(ix);
185-
// let canvas = e.get_canvas_size().unwrap();
186-
weight.frame_est = FrameEstimate::Impossible;
191+
// let canvas = e.get_canvas_size().unwrap();
192+
ctx.weight_mut(ix).frame_est = FrameEstimate::Invalidated;
193+
}
187194

188195

189196
// FrameEstimate::UpperBound(FrameInfo {

imageflow_core/src/flow/nodes/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,18 @@ impl<'c> OpCtxMut<'c> {
308308
self.graph.remove_node(index).unwrap();
309309
}
310310

311-
pub fn get_decoder_io_ids(&self,
311+
pub fn get_decoder_io_ids_and_indexes(&self,
312312
ancestors_of_node: NodeIndex<u32>)
313-
-> Vec<i32> {
313+
-> Vec<(i32,NodeIndex<u32>)> {
314314
self.graph.parents(ancestors_of_node).iter(self.graph).map(|(_, ix)| match self.weight(ix).params{
315-
NodeParams::Json(s::Node::Decode { io_id, ..}) => Some(io_id), _ => None
315+
NodeParams::Json(s::Node::Decode { io_id, ..}) => Some((io_id,ix)), _ => None
316316
} ).filter(|v| v.is_some()).map(|v| v.unwrap()).collect::<>()
317317
}
318-
318+
pub fn get_decoder_io_ids(&self,
319+
ancestors_of_node: NodeIndex<u32>)
320+
-> Vec<i32> {
321+
self.get_decoder_io_ids_and_indexes(ancestors_of_node).into_iter().map(|(a,b)| a).collect::<>()
322+
}
319323
pub fn get_image_info_list(&mut self,
320324
ancestors_of_node: NodeIndex<u32>) -> Vec<::std::result::Result<s::ImageInfo, ::FlowError>>{
321325
self.get_decoder_io_ids(ancestors_of_node).into_iter().map(|io_id| self.job.get_image_info(io_id)).collect::<>()

imageflow_core/tests/visuals.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,23 @@ fn test_jpeg_rotation() {
278278
}
279279

280280
}
281+
282+
283+
#[test]
284+
fn test_jpeg_crop() {
285+
let matched = compare(Some(s::IoEnum::Url("https://s3-us-west-2.amazonaws.com/imageflow-resources/test_inputs/waterhouse.jpg".to_owned())), 500,
286+
"jpeg_crop".to_owned(), false, false, vec![
287+
s::Node::CommandString{
288+
kind: s::CommandStringKind::ImageResizer4,
289+
value: "width=100&height=200&mode=crop".to_owned(),
290+
decode: Some(0),
291+
encode: None
292+
}
293+
]
294+
);
295+
assert!(matched);
296+
}
297+
281298
//
282299
//#[test]
283300
//fn test_gif_ir4(){
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
{
2+
"MarsRGB_ICCv4_Scaled400300": "0CEA7717E76E828C0_0E6130049ADFEB2D0",
3+
"WhiteBalanceNight": "0D84206BD2DD308DA_0219F93FDDB57B45C",
4+
"ScaleTheHouse": "0568E6941605D8031_0E6130049ADFEB2D0",
5+
"Test_Apply_Orientation_Landscape_6.jpg": "022F25890464CEF5E_0737E89DC5F717498",
26
"Test_Apply_Orientation_Landscape_4.jpg": "0983D7771C9D027F3_0737E89DC5F717498",
3-
"FillRectEECCFFExpand2233AAFF": "0BEE361EED2335E51_0B0FCB3BE40D894D1",
4-
"MarsRGB_ICC_Scaled400300": "051EA508DFA6C0FDA_0E6130049ADFEB2D0",
5-
"DetectWhitespace": "0549704430DA253E1_0B144C3EB1ECD0F26",
6-
"Test_Apply_Orientation_Portrait_5.jpg": "0D76AD5A6519860A1_0C7861091F69310F8",
7-
"FillRectAndCrop": "023A1A32B1D12004D_0116F4507255DDCBF",
7+
"Test_Apply_Orientation_Portrait_4.jpg": "0DF5904E42A836E8E_0C7861091F69310F8",
8+
"FillRectEECCFF": "0D2D3A96EC962A552_0B0FCB3BE40D894D1",
89
"FillRect": "0E528C65475538702_0E6130049ADFEB2D0",
9-
"RingsDownscaling": "041EAE7364EE7D48F_0B0FCB3BE40D894D1",
10-
"WhiteBalanceNight": "0D84206BD2DD308DA_0219F93FDDB57B45C",
11-
"Test_Apply_Orientation_Landscape_8.jpg": "03797221195AC1AF6_0737E89DC5F717498",
12-
"Test_Apply_Orientation_Portrait_3.jpg": "0F4B6AFFAAF67A89E_0C7861091F69310F8",
1310
"Test_Apply_Orientation_Landscape_3.jpg": "0BE692134537D68C9_0737E89DC5F717498",
14-
"FillRectEECCFF": "0D2D3A96EC962A552_0B0FCB3BE40D894D1",
1511
"Test_Apply_Orientation_Portrait_2.jpg": "0821FC43B168957D2_0C7861091F69310F8",
16-
"MarsRGB_ICCv4_Scaled400300": "0CEA7717E76E828C0_0E6130049ADFEB2D0",
17-
"ScaleIDCT_approx_gamma": "01DD6D368FDF435EF_0BA63E6C61FFC4738",
18-
"ScaleTheHouse": "0568E6941605D8031_0E6130049ADFEB2D0",
19-
"ScaleIDCTFastvsSlow": "04549C40B272C69E8_0E6130049ADFEB2D0",
2012
"Test_Apply_Orientation_Portrait_1.jpg": "0130B45451220FE91_0C7861091F69310F8",
21-
"Test_Apply_Orientation_Portrait_6.jpg": "00D24FDAA62F061A5_0C7861091F69310F8",
13+
"DetectWhitespace": "0549704430DA253E1_0B144C3EB1ECD0F26",
14+
"Test_Apply_Orientation_Portrait_5.jpg": "0D76AD5A6519860A1_0C7861091F69310F8",
15+
"MarsRGB_ICC_Scaled400300": "051EA508DFA6C0FDA_0E6130049ADFEB2D0",
16+
"Test_Apply_Orientation_Portrait_3.jpg": "0F4B6AFFAAF67A89E_0C7861091F69310F8",
17+
"jpeg_crop": "0AC75CD46C66EA068_0C6CF405827FDE14C",
2218
"Test_Apply_Orientation_Landscape_1.jpg": "0D893C1AB988C1626_0737E89DC5F717498",
19+
"Test_Apply_Orientation_Portrait_6.jpg": "00D24FDAA62F061A5_0C7861091F69310F8",
20+
"ScaleIDCT_approx_gamma": "01DD6D368FDF435EF_0BA63E6C61FFC4738",
21+
"FillRectEECCFFExpand2233AAFF": "0BEE361EED2335E51_0B0FCB3BE40D894D1",
2322
"Test_Apply_Orientation_Landscape_2.jpg": "0F26C3C320ED5A074_0737E89DC5F717498",
24-
"Test_Apply_Orientation_Landscape_6.jpg": "022F25890464CEF5E_0737E89DC5F717498",
2523
"Test_Apply_Orientation_Portrait_8.jpg": "0AC9F547ADDDEF923_0C7861091F69310F8",
26-
"mountain_gif_scaled400": "0E9E7863A738C1054_0E6130049ADFEB2D0",
27-
"Test_Apply_Orientation_Portrait_4.jpg": "0DF5904E42A836E8E_0C7861091F69310F8",
28-
"Test_Apply_Orientation_Portrait_7.jpg": "0002098ACFD00B380_0C7861091F69310F8",
24+
"Test_Apply_Orientation_Landscape_7.jpg": "052524D529AA08236_0737E89DC5F717498",
2925
"Test_Apply_Orientation_Landscape_5.jpg": "0C80D19F51A28A93B_0737E89DC5F717498",
30-
"Test_Apply_Orientation_Landscape_7.jpg": "052524D529AA08236_0737E89DC5F717498"
26+
"FillRectAndCrop": "023A1A32B1D12004D_0116F4507255DDCBF",
27+
"mountain_gif_scaled400": "0E9E7863A738C1054_0E6130049ADFEB2D0",
28+
"Test_Apply_Orientation_Landscape_8.jpg": "03797221195AC1AF6_0737E89DC5F717498",
29+
"ScaleIDCTFastvsSlow": "04549C40B272C69E8_0E6130049ADFEB2D0",
30+
"RingsDownscaling": "041EAE7364EE7D48F_0B0FCB3BE40D894D1",
31+
"Test_Apply_Orientation_Portrait_7.jpg": "0002098ACFD00B380_0C7861091F69310F8"
3132
}

imageflow_riapi/src/ir4/layout.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,12 @@ impl FramewiseBuilder {
447447
}
448448
}
449449

450+
#[test]
451+
fn test_crop_and_scale(){
452+
let mut b = FramewiseBuilder::new();
453+
454+
let l = Ir4Layout::new(Instructions{w: Some(100), h: Some(200), mode: Some(FitMode::Crop), .. Default::default() }, 768, 433);
455+
l.add_steps(&mut b);
456+
457+
assert_eq!(b.steps, vec![s::Node::Crop { x1: 275, y1: 0, x2: 492, y2: 433 }, s::Node::Resample2D { w: 100, h: 200, down_filter: None, up_filter: None, scaling_colorspace: None, hints: Some(s::ResampleHints { sharpen_percent: None, prefer_1d_twice: None }) }]);
458+
}

imageflow_riapi/src/sizing_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ impl Kit{
580580
}
581581

582582

583+
583584
#[test]
584585
fn test_scale_to_outer(){
585586
let cropper = sizing::IdentityCropProvider::new();

0 commit comments

Comments
 (0)