For JPX decoding only read next packet after checking for byte aligning.

This patch makes the image from #5349 appear correctly, however artefacts
for the last packet seem to still be there.
This patch also optimizes some "in-checks" and adds a few header parsings.
Anyway, ignoring the return value of `readBits(1)` seems wrong. I don't think that `if (!packet)` will work correctly, because `nextPacket()` will either create a valid packet or throw an exception.