Minor improvement, use real length when known.

This commit is contained in:
Harald Kuhr 2024-11-19 10:36:41 +01:00
parent 9610256ddb
commit d78e6373a8

View File

@ -195,7 +195,8 @@ final class JPEGSegmentImageInputStream extends ImageInputStreamImpl {
if (marker == JPEG.SOS) {
// Treat rest of stream as a single segment (scanning for EOI is too much work)
// TODO: For progressive, there will be more than one SOS...
segments.add(new Segment(-1, segment.realEnd(), segment.end(), Long.MAX_VALUE - segment.realEnd()));
long end = stream.length() > 0 ? stream.length() : Long.MAX_VALUE;
segments.add(new Segment(-1, segment.realEnd(), segment.end(), end - segment.realEnd()));
}
if (streamPos >= segment.start && streamPos < segment.end()) {