ref' and namely interpolation was causing index out of bounds, also inside was ignoring last right and bottom pixels. Fixed.