Insert check for range min and max value (on conversion)

The range could also be inverse (255..0 instead of 0..255), so we have to improve the check and set the correct min and max values.