image-rs/image-tiff

Erroneous JPEG decoding

to-mas-kral opened this issue · 3 comments

Some JPEG-in-TIFF images aren't correctly decoded.

For example: (tested with Emulsion 8.0.0)
jpegdecoding

Output from tiffdump:

stripped-jpeg.tif:
Magic: 0x4949 <little-endian> Version: 0x2a <ClassicTIFF>
Directory 0: offset 94702 (0x171ee) next 0 (0)
ImageWidth (256) SHORT (3) 1<365>
ImageLength (257) SHORT (3) 1<547>
BitsPerSample (258) SHORT (3) 3<8 8 8>
Compression (259) SHORT (3) 1<7>
Photometric (262) SHORT (3) 1<2>
FillOrder (266) SHORT (3) 1<1>
StripOffsets (273) LONG (4) 1<8>
Orientation (274) SHORT (3) 1<1>
SamplesPerPixel (277) SHORT (3) 1<3>
RowsPerStrip (278) SHORT (3) 1<547>
StripByteCounts (279) LONG (4) 1<94694>
XResolution (282) RATIONAL (5) 1<72>
YResolution (283) RATIONAL (5) 1<72>
PlanarConfig (284) SHORT (3) 1<1>
ResolutionUnit (296) SHORT (3) 1<2>
PageNumber (297) SHORT (3) 2<0 1>
Whitepoint (318) RATIONAL (5) 2<0.3127 0.329>
PrimaryChromaticities (319) RATIONAL (5) 6<0.64 0.33 0.3 0.6 0.15 0.06>
JPEGTables (347) UNDEFINED (7) 289<0xff 0xd8 0xff 0xdb 00 0x43 00 0x8 0x6 0x6 0x7 0x6 0x5 0x8 0x7 0x7 0x7 0x9 0x9 0x8 0xa 0xc 0x14 0xd ...>
ICC Profile (34675) UNDEFINED (7) 3144<00 00 0xc 0x48 0x4c 0x69 0x6e 0x6f 0x2 0x10 00 00 0x6d 0x6e 0x74 0x72 0x52 0x47 0x42 0x20 0x58 0x59 0x5a 0x20 ...>

Same error appeared while I was trying to decode tiled-based images.

stripped-jpeg.zip

Here's a sample file that uses jpeg compression and is meant to be a blue gradient when decoded correctly but decodes as a red gradient with this library.
jpeg_compression.tif.zip

This is what it should look like.
view_buffer-2

This is what it decodes like.
view_buffer

@McSpidey which version of the library are you using? I don't get this issue using the latest in master, which I believe is now 0.7.3 on crates.io.

Oh wonderful, I was using image crate ver "0.24.2", but just updated to "0.24.3" which includes Tiff 0.7.3 and it's now working fine!