mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-02 19:15:29 -04:00
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:
parent
c2245a503d
commit
73a880a358
@ -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);
|
||||
}
|
||||
|
||||
|
@ -276,6 +276,22 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTestCase<JPEGImageRe
|
||||
// TODO: Need to test colors!
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEOFSOSSegment() throws IOException {
|
||||
// Regression...
|
||||
JPEGImageReader reader = createReader();
|
||||
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/eof-sos-segment-bug.jpg")));
|
||||
|
||||
assertEquals(266, reader.getWidth(0));
|
||||
assertEquals(400, reader.getHeight(0));
|
||||
|
||||
BufferedImage image = reader.read(0);
|
||||
|
||||
assertNotNull(image);
|
||||
assertEquals(266, image.getWidth());
|
||||
assertEquals(400, image.getHeight());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidICCSingleChunkBadSequence() throws IOException {
|
||||
// Regression
|
||||
|
@ -123,4 +123,16 @@ public class JPEGSegmentImageInputStreamTest {
|
||||
|
||||
// And thus, no XMP, no ICC_PROFILE or other segments
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEOFSOSSegmentBug() throws IOException {
|
||||
ImageInputStream stream = new JPEGSegmentImageInputStream(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/eof-sos-segment-bug.jpg")));
|
||||
|
||||
long length = 0;
|
||||
while (stream.read() != -1) {
|
||||
length++;
|
||||
}
|
||||
|
||||
assertEquals(9299l, length); // Sanity check: same as file size
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 9.1 KiB |
Loading…
x
Reference in New Issue
Block a user