pioneerspacesim/pioneer — pull request #1818 by johnbartholomew (2012-12-15 17:35:24+00:00)
Title: Interpret galaxy density bitmap as unsigned values

Fixes #1813.

The C `char` type can be signed or unsigned. If it's signed, then values
"greater" than 127 are actually interpreted as negative values. When
converting to (signed) int, sign extension leads to all the high bits
being set. When that value is later shifted right (aka, divided by a
power of two), those high bits get shifted into the value, making it
much larger than it should be. This leads to a sudden jump in sector
density.

By interpreting the density bitmap pixels as unsigned values, all these
problems are avoided (when converting unsigned char to signed int, the
result is always non-negative).

This patch also changes right-shifts to divisions, because division is
the intended operation; the compiler can turn it back into a right-shift
if that's useful.