Good stream downscaler v1.
This commit is contained in:
parent
a08da94edc
commit
551b19546d
1 changed files with 44 additions and 28 deletions
|
@ -1,3 +1,4 @@
|
|||
open Iostream
|
||||
|
||||
type pixel = float^3
|
||||
|
||||
|
@ -17,7 +18,7 @@ let
|
|||
tel
|
||||
|
||||
const pix_zero :pixel = 0.0^3
|
||||
const pix_o :pixel = [1.0,2.0,3.0]
|
||||
const pix_o :pixel = [1.0,1.0,1.0]
|
||||
|
||||
node counter() returns (cpt :int)
|
||||
let
|
||||
|
@ -48,36 +49,40 @@ tel
|
|||
|
||||
node current(x :int; ck :bool) returns (c :int)
|
||||
let
|
||||
c = merge ck x (0 fby (c whenot ck))
|
||||
c = merge ck x ((0 fby c) whenot ck)
|
||||
tel
|
||||
node current_bool(x :bool; ck :bool) returns (c :bool)
|
||||
let
|
||||
c = merge ck x (false fby (c whenot ck))
|
||||
c = merge ck x ((false fby c) whenot ck)
|
||||
tel
|
||||
|
||||
fun flatten_clock(ck :bool :: .; ck2 :bool :: . on ck) returns (ck2_flat :bool :: .)
|
||||
fun flatten_clock(x :pixel ::.on ck on ck2; ck :bool ::.; ck2 :bool ::.on ck) returns (y :pixel; ck2_flat :bool :: .)
|
||||
var x_ck, x_base : pixel;
|
||||
let
|
||||
ck2_flat = merge ck ck2 false
|
||||
x_ck = merge ck2 x pix_o;
|
||||
x_base = merge ck x_ck pix_o;
|
||||
ck2_flat = merge ck ck2 false;
|
||||
y = x_base when ck2_flat;
|
||||
tel
|
||||
|
||||
|
||||
node transpose<<x, y : int>>(i :pixel) returns (o :pixel)
|
||||
var store :pixel^x^y^2; (*This is the double buffer*)
|
||||
i_x, i_y, o_x, o_y :int; (*These are current buffer indexes*)
|
||||
i_line, i_img, o_line :bool; (*These define line and img beginning*)
|
||||
i_line, o_line, i_img :bool; (*These define line and img beginning*)
|
||||
i_buff, o_buff :int; (*These are used to control the double buffering*)
|
||||
let
|
||||
i_x = mod_counter<<x>>() - 1;
|
||||
i_line = i_x = 0;
|
||||
i_y = current (mod_counter<<y>>() - 1, i_line);
|
||||
i_img = i_y = 0;
|
||||
i_img = (i_x = 0) & (i_y = 0);
|
||||
i_buff = current(mod_counter<<2>>() - 1, i_img);
|
||||
o_buff = (i_buff + 1) % 2;
|
||||
o_x = mod_counter<<y>>() -1;
|
||||
o_line = o_x = 0;
|
||||
o_y = current (mod_counter<<x>>() -1, o_line);
|
||||
store = (pix_zero^x^y^2) fby [store with [i_x][i_y][i_buff] = i];
|
||||
o = store[>o_x<][>o_y<][>o_buff<];
|
||||
o_y = mod_counter<<y>>() -1;
|
||||
o_line = o_y = 0;
|
||||
o_x = current (mod_counter<<x>>()-1, o_line);
|
||||
store = (pix_zero^x^y^2) fby [store with [i_buff][i_y][i_x] = i];
|
||||
o = store[>o_buff<][>o_y<][>o_x<];
|
||||
tel
|
||||
|
||||
|
||||
|
@ -98,15 +103,15 @@ let
|
|||
tel
|
||||
|
||||
|
||||
node down_img
|
||||
<<size_x, size_y, ratio_x, ratio_y :int>>
|
||||
(x :pixel :: .)
|
||||
returns (y :pixel; ck_y_dh, ck_y_dhv :bool)
|
||||
var x_img, x_line, y_dh_t_line :bool;
|
||||
y_dh, y_dh_t, y_dhv_t :pixel;
|
||||
node down_img <<size_x, size_y, ratio_x, ratio_y :int>> (x :pixel :: .)
|
||||
returns (y_flat :pixel; y_clock :bool;
|
||||
y, y_dh, y_dh_t, y_dhv_t :pixel;
|
||||
ck_y_dh, ck_y_dhv :bool
|
||||
)
|
||||
var
|
||||
x_line, y_dh_t_line :bool;
|
||||
|
||||
let
|
||||
x_img = mod_counter<<size_x*size_y>>() = 1;
|
||||
reset
|
||||
x_line = mod_counter<<size_x>>() = 1;
|
||||
reset
|
||||
(y_dh, ck_y_dh) = down_line<<ratio_x>>(x)
|
||||
|
@ -117,16 +122,27 @@ let
|
|||
(y_dhv_t, ck_y_dhv) = down_line<<ratio_y>>(y_dh_t)
|
||||
every y_dh_t_line;
|
||||
y = transpose<<size_x/ratio_x, size_y/ratio_y>>(y_dhv_t);
|
||||
(* y_clock = flatten_clock(ck_y_dh, ck_y_dhv); (*flatten clock of y, in order to return only one, instead of ck_y_dh on ck_y_dhv*)
|
||||
y = y_dhv when y_clock;
|
||||
*)
|
||||
every x_img
|
||||
(*flatten clock of y, in order to return only one, instead of ck_y_dh on ck_y_dhv*)
|
||||
(y_flat, y_clock) = flatten_clock(y, ck_y_dh, ck_y_dhv);
|
||||
tel
|
||||
|
||||
|
||||
node main () returns (out : pixel; ck_out, ck_out_2 :bool)
|
||||
var img : pixel;
|
||||
(*node main () returns (img, out : pixel; ck_out, ck_out_2 :bool)
|
||||
(*var img : pixel;*)
|
||||
let
|
||||
img = pix_zero fby (pix_sum(img, pix_o));
|
||||
(out, ck_out, ck_out_2) = down_img<<10,10,2,2>>(img);
|
||||
img = pix_o;
|
||||
(out, ck_out, ck_out_2) = down_img<<2,2,2,2>>(img);
|
||||
tel*)
|
||||
|
||||
node main<<size_x, size_y:int>> () returns (img, out : pixel; ck_out :bool;
|
||||
y, y_dh, y_dh_t, y_dhv_t :pixel;
|
||||
ck_y_dh, ck_y_dhv :bool)
|
||||
(*var img : pixel;*)
|
||||
let
|
||||
(*ck_out = true fby false fby not ck_out;*)
|
||||
img = pix_o fby pix_sum(img, pix_o);
|
||||
() = out_bool(ck_y_dhv);
|
||||
(out, ck_out, y, y_dh, y_dh_t, y_dhv_t, ck_y_dh, ck_y_dhv) = down_img<<size_x,size_y,3,3>>(img);
|
||||
tel
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue