Set bits_per_raw_sample when decoding mjpeg / ljpeg.

The ljpeg decoder also supports gray images with
8 - 15 bits per component.
Assume gray8 if 1 < maxval <= 255 in pgm.
Avoid overflows when reading pgm files with maxval != 255 and != 65535.

libjpeg v6b apparently does not initialize the most significant bits
to zero when writing 12bit pgm's with maxval 4095.