Raster Graphics Integer Errors

A common problem with plotting lines in raster graphics is visualization errors as we display the graphics. Most times we can just ignore these, but as I am drawing scrolling real-time plots I also receive the side effect of an integer error.

This show a line that due to integer rounding is a straight line in the left plot, cover two pixel rows in the second before it is straight again in the third. As you move this over the screen it don’t look good or smooth at all.

The solution is quite simple – the error comes because you calculate x/y from double or float. Depending on position the conversion to pixel xy end up different as a line moves – so you can pre-compute a x and scroll this by adding/subtracting offset. The concept is that integer errors stay constant and your line looks like is moves more smoothly – no jumping between positions.

Leave a Reply