#include "harp1.h" const dw = 8; /* Data width */ const iw = dw << 1; /* Internal data width */ const xw = 7; /* Log horizontal size */ const yw = 7; /* Log vertical size */ const aw = xw + yw; /* Address width */ const ae = 1 << aw; /* Number of elements in ram */ const null = 0 : dw; /* Null element */ const threshold = 48; const white = (1 << dw) - 1; const black = 0; #define LO(x) ((x) <- dw) /* Lo word */ #define HI(x) ((x) \\ dw) /* Hi word */ void main (chan (in) STDIN : dw, chan (out) STDOUT : dw, eram img1[ae] = harp1lram : iw, eram img2[ae] = harp1lram : 1) { int x : xw; int y : yw; int p_0, p_1, p_2 : iw; int abs_diff() = abs(LO(p_2) - LO(p_0)); int sum_abs() = (false @ abs_diff() ) + (false @ HI(p_1)); /* Differentiate in x direction */ do { do par { STDIN ? any; p_0, p_1, p_2 = p_1, p_2, null @ STDIN; img1[y @ x] = abs_diff() @ LO(p_1); x = x + 1; } while (x != 0); y = y + 1; } while (y != 0); /* Differentiate and threshold in y direction */ do { do par { p_0, p_1, p_2 = p_1, p_2, img1[y @ x]; img2[y @ x] = (sum_abs() >= threshold ? 1 : 0); y = y + 1; } while (y != 0); x = x + 1; } while (x != 0); /* Output */ y = 2; do { x = 2; do par { STDOUT ! (img2[y @ x] ? white : black); x = x + 1; } while (x != 2); y = y + 1; } while (y != 2); }