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.
After looking at the code of poppler and jj2000 I think, our code should be 
```
alignToByte();
if (!readBits(1)) {
  continue; // empty packet
}
var packet = packetsIterator.nextPacket();
```
In both [jj2000](https://github.com/aurora-sim/Aurora-LibOMV/blob/master/CSJ2K/j2k/codestream/reader/PktDecoder.cs#L988-991) and [poppler](http://code.metager.de/source/xref/freedesktop/poppler/poppler/JPXStream.cc#2133), the byte is aligned before reading the "empty packet" bit