From 9f2b65888a1fffa4876f02e12371002fa931e563 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Thu, 31 Dec 2009 10:13:59 +0000 Subject: Worked around what appears to be a bad JPEG image in the Masterpiece edition of Myst. If I dump the image to file, I'm able to read it into other programs, such as The GIMP, just fine. It seems that the only thing that's missing is the End Of Image marker, and what everyone else does is to just fake one. svn-id: r46795 --- graphics/jpeg.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/graphics/jpeg.cpp b/graphics/jpeg.cpp index fc3d99ca4a..8ff253fda7 100644 --- a/graphics/jpeg.cpp +++ b/graphics/jpeg.cpp @@ -114,16 +114,41 @@ bool JPEG::read(Common::SeekableReadStream *str) { bool done = false; while (!_str->eos() && ok && !done) { // Read the marker + + // WORKAROUND: While each and every JPEG file should end with + // an EOI (end of image) tag, in reality this may not be the + // case. For instance, at least one image in the Masterpiece + // edition of Myst doesn't, yet other programs are able to read + // the image without complaining. + // + // Apparently, the customary workaround is to insert a fake + // EOI tag. + uint16 marker = _str->readByte(); + bool fakeEOI = false; + + if (_str->eos()) { + fakeEOI = true; + marker = 0xFF; + } + if (marker != 0xFF) { error("JPEG: Invalid marker[0]: 0x%02X", marker); ok = false; break; } - while (marker == 0xFF) + while (marker == 0xFF && !_str->eos()) marker = _str->readByte(); + if (_str->eos()) { + fakeEOI = true; + marker = 0xD9; + } + + if (fakeEOI) + warning("JPEG: Inserted fake EOI"); + // Process the marker data switch (marker) { case 0xC0: // Start Of Frame -- cgit v1.2.3