Speedup maximum distance mask generation