There are two errors in the For-loops:
It should be
"For GS_y = GS_vy To GS_vy+GS_h - 1" and
"For GS_x = GS_vx To GS_vx+GS_w - 1".
Otherwise this function will attempt to read and write outside the specified rectangle.
For example if you want to grayscale the whole buffer in 800 x 600 graphics mode with
grayscale GraphicsBuffer(), 0, 0, 800, 600
GS_y will go from 0 to 600 and GS_x from 0 to 800, but it should go to 599 and 799 respectively.
It should be
"For GS_y = GS_vy To GS_vy+GS_h - 1" and
"For GS_x = GS_vx To GS_vx+GS_w - 1".
Otherwise this function will attempt to read and write outside the specified rectangle.
For example if you want to grayscale the whole buffer in 800 x 600 graphics mode with
grayscale GraphicsBuffer(), 0, 0, 800, 600
GS_y will go from 0 to 600 and GS_x from 0 to 800, but it should go to 599 and 799 respectively.