TMI-23: Better handling of SOS segment (variable length). Now treats the rest of the stream after SOS as single segment. Not really ideal, but gives better performance than scanning for EOI...

This commit is contained in:
Harald Kuhr
2012-06-21 16:08:03 +02:00
parent c2245a503d
commit 73a880a358
4 changed files with 40 additions and 2 deletions

View File

@@ -101,8 +101,18 @@ final class JPEGSegmentImageInputStream extends ImageInputStreamImpl {
segments.add(segment);
}
else {
int length = stream.readUnsignedShort(); // Length including length field itself
segment = new Segment(marker, realPosition, segment.end(), 2 + length);
long length;
if (marker == JPEG.SOS) {
// Treat rest of stream as a single segment (scanning for EOI is too much work)
length = Long.MAX_VALUE - realPosition;
}
else {
// Length including length field itself
length = stream.readUnsignedShort() + 2;
}
segment = new Segment(marker, realPosition, segment.end(), length);
segments.add(segment);
}