/* Histogram equalisation - version 1 */ #include "harp1.h" const dw = 8, aw = 14; const de = (1 << dw), ae = (1 << aw); void main(chan(in) STDIN : dw, chan(out) STDOUT : dw, eram data[ae] = harp1lram : dw, eram hist[de] = harp1hram : aw) { int addr, accu, x, temp; void input_and_histogram() { addr = 0; do { STDIN ? x; data[addr] = x; temp = hist[x]; hist[x] = temp + 1; addr = addr + 1; } while (addr != 0); } void accumulate_histogram() { x = 0; accu = 0; do { temp = hist[x]; hist[x] = accu; accu = accu + temp; x = x + 1; } while (x != 0); } void equalise_and_output() { addr = 0; do { x = data[addr]; temp = hist[x]; STDOUT ! temp \\ (aw - dw); addr = addr + 1; } while (addr != 0); } /* Main program */ input_and_histogram(); accumulate_histogram(); equalise_and_output(); }