我正在尝试重新进行 Photoshop 调整图层样式过程,其中图像处理功能由堆栈中的图层表示,其中顶部/第一个过程的结果被馈送到下一个过程。这可以表示为处理函数的数组,其中每个函数的输出被馈送到下一个函数。
[Change Brightness(img)->Change Saturation(img)->Change Levels(img)]
我怎样才能从 Rust 中的非静态函数数组中实现这种“传递”值?
fn op_a(mut a: Vec<u8>, p1: i32) -> Vec<u8> {
//process image
println!("Operation A on image with size: {}, and parameter1 val: {}", a.len(), p1);
a[0] = 10;
a
}
fn op_b(mut a: Vec<u8>, p1: i32, p2: i32) -> Vec<u8> {
//process image
println!("Operation B on image with size: {}, parameter 1 val: {}, parameter 2 val: {}", a.len(), p1, p2);
a[0] += 2;
a
}
fn op_c(mut a: Vec<u8>, p1: i32, p2: i32, p3: i32) -> Vec<u8> {
//process image
println!("Operation C on image with size: {}, parameter 1 val: {}, parameter 2 val: {}, parameter 3 val: {}", a.len(), p1, p2, p3);
a[0] *= 2;
a
}
fn pipe_function_array(initial_image: ImageBuffer, Vec<functions>)->ImageBuffer{
//executes an array of functions passing each to the next function in the array, with an initual input value of initial_image
}
fn main() {
let my_starting_value = *some Vec<u8>*;
let my_funcs = *an array of op_a, op_b, and op_c*;
let final_image = pipe_function_array(vec![0], my_funcs);
}
