2010.02.11 21:56 "[Tiff] TIFF and IJG JPEG 8", by Bob Friesenhahn

2010.03.16 19:45 "[Tiff] TIFFVStripSize overflow, JPEG decoding", by Lee Cooper

I am trying to develop software to support a new tiff file source of large medical images. Using libtiff I am encountering problems with TIFFOpen, I suspect because the dimensions are causing overflow of 32-bit variables (image dimensions in the tens-of-thousands).

I am aware of the bigtiff project but that is not an option in this case since I don't have control over how the files are generated. Since I only have to support a very limited format (file organization is always the same), I am hoping to generate some simple specific code that uses header information to read the image contents. The files contain multiple "pages", each encoded with JPEG. I have listed a sample tiffdump output below.

If I have the offset from the header, is there a way to decode the output without using TIFFOpen directly? I don't mind writing some software but would prefer not to decode the JPEG from scratch :)

Regards,
Lee

-----------------------------------------------------------------------------------

Magic: 0x4949 <little-endian> Version: 0x2a
Directory 0: offset 184062235 (0xaf8911b) next 197055203 (0xbbed2e3)
ImageWidth (256) LONG (4) 1<51200>
ImageLength (257) LONG (4) 1<38144>
BitsPerSample (258) SHORT (3) 3<8 8 8>
SamplesPerPixel (277) SHORT (3) 1<3>
RowsPerStrip (278) LONG (4) 1<38144>

Compression (259) SHORT (3) 1<7>
Photometric (262) SHORT (3) 1<6>
Make (271) ASCII (2) 10<Hamamatsu\0>

Model (272) ASCII (2) 11<NanoZoomer\0>
XResolution (282) RATIONAL (5) 1<21910>
YResolution (283) RATIONAL (5) 1<21975>
ResolutionUnit (296) SHORT (3) 1<3>

Software (305) ASCII (2) 9<NDP.scan\0>

DateTime (306) ASCII (2) 20<2009:12:31 09:11:46\0>
YCbCrSubsampling (530) SHORT (3) 2<1 1>
ReferenceBlackWhite (532) LONG (4) 6<0 255 128 255 128 255>
65420 (0xff8c) SHORT (3) 1<1>

65421 (0xff8d) FLOAT (11) 1<20>
65422 (0xff8e) SLONG (9) 1<4876667>
65423 (0xff8f) SLONG (9) 1<4292627296>

65424 (0xff90) SLONG (9) 1<0>

65425 (0xff91) LONG (4) 1<0>

StripOffsets (273) LONG (4) 1<108>
StripByteCounts (279) LONG (4) 1<183585327>
65426 (0xff92) LONG (4) 119200<660 1344 2086 2840 3471 4158 4868 5518 6152 6802 7432 8106 8760 9417 10060 10703 11347 11979 12616 13258 13882 14519 15170 15798 ...>
65428 (0xff94) LONG (4) 1<3916405674>

Directory 1: offset 197055203 (0xbbed2e3) next 197918647 (0xbcbffb7)
ImageWidth (256) LONG (4) 1<12800>
ImageLength (257) LONG (4) 1<9536>
BitsPerSample (258) SHORT (3) 3<8 8 8>
SamplesPerPixel (277) SHORT (3) 1<3>
RowsPerStrip (278) LONG (4) 1<9536>
Compression (259) SHORT (3) 1<7>
Photometric (262) SHORT (3) 1<6>
Make (271) ASCII (2) 10<Hamamatsu\0>
Model (272) ASCII (2) 11<NanoZoomer\0>
XResolution (282) RATIONAL (5) 1<5477>
YResolution (283) RATIONAL (5) 1<5493>
ResolutionUnit (296) SHORT (3) 1<3>

Software (305) ASCII (2) 9<NDP.scan\0>

DateTime (306) ASCII (2) 20<2009:12:31 09:11:46\0>
YCbCrSubsampling (530) SHORT (3) 2<1 1>
ReferenceBlackWhite (532) LONG (4) 6<0 255 128 255 128 255>
65420 (0xff8c) SHORT (3) 1<1>

65421 (0xff8d) FLOAT (11) 1<5>
65422 (0xff8e) SLONG (9) 1<4876667>
65423 (0xff8f) SLONG (9) 1<4292627296>

65424 (0xff90) SLONG (9) 1<0>

65425 (0xff91) LONG (4) 1<0>

StripOffsets (273) LONG (4) 1<184062757>
StripByteCounts (279) LONG (4) 1<12873246>
65426 (0xff92) LONG (4) 29800<660 825 997 1171 1306 1493 1669 1813 1951 2083 2215 2367 2529 2666 2800 2935 3073 3207 3347 3481 3619 3763 3910 4040 ...>
65428 (0xff94) LONG (4) 1<4063277570>

Directory 2: offset 197918647 (0xbcbffb7) next 197972969 (0xbccd3e9)
ImageWidth (256) LONG (4) 1<3200>
ImageLength (257) LONG (4) 1<2384>
BitsPerSample (258) SHORT (3) 3<8 8 8>
SamplesPerPixel (277) SHORT (3) 1<3>
RowsPerStrip (278) LONG (4) 1<2384>
Compression (259) SHORT (3) 1<7>
Photometric (262) SHORT (3) 1<6>
Make (271) ASCII (2) 10<Hamamatsu\0>
Model (272) ASCII (2) 11<NanoZoomer\0>
XResolution (282) RATIONAL (5) 1<1369>
YResolution (283) RATIONAL (5) 1<1373>
ResolutionUnit (296) SHORT (3) 1<3>

Software (305) ASCII (2) 9<NDP.scan\0>

DateTime (306) ASCII (2) 20<2009:12:31 09:11:46\0>
YCbCrSubsampling (530) SHORT (3) 2<1 1>
ReferenceBlackWhite (532) LONG (4) 6<0 255 128 255 128 255>
65420 (0xff8c) SHORT (3) 1<1>

65421 (0xff8d) FLOAT (11) 1<1.25>
65422 (0xff8e) SLONG (9) 1<4876667>
65423 (0xff8f) SLONG (9) 1<4292627296>

65424 (0xff90) SLONG (9) 1<0>

65425 (0xff91) LONG (4) 1<0>

StripOffsets (273) LONG (4) 1<197055725>
StripByteCounts (279) LONG (4) 1<833122>
65426 (0xff92) LONG (4) 7450<660 717 772 829 870 933 984 1028 1068 1107 1145 1191 1280 1320 1358 1397 1438 1476 1515 1556 1595 1637 1687 1725 ...>
65428 (0xff94) LONG (4) 1<451833854>

Directory 3: offset 197972969 (0xbccd3e9) next 198030603 (0xbcdb50b)
ImageWidth (256) LONG (4) 1<800>
ImageLength (257) LONG (4) 1<596>
BitsPerSample (258) SHORT (3) 3<8 8 8>
SamplesPerPixel (277) SHORT (3) 1<3>
RowsPerStrip (278) LONG (4) 1<596>
Compression (259) SHORT (3) 1<7>
Photometric (262) SHORT (3) 1<6>
Make (271) ASCII (2) 10<Hamamatsu\0>
Model (272) ASCII (2) 11<NanoZoomer\0>
XResolution (282) RATIONAL (5) 1<342>
YResolution (283) RATIONAL (5) 1<343>
ResolutionUnit (296) SHORT (3) 1<3>

Software (305) ASCII (2) 9<NDP.scan\0>

DateTime (306) ASCII (2) 20<2009:12:31 09:11:46\0>
YCbCrSubsampling (530) SHORT (3) 2<1 1>
ReferenceBlackWhite (532) LONG (4) 6<0 255 128 255 128 255>
65420 (0xff8c) SHORT (3) 1<1>

65421 (0xff8d) FLOAT (11) 1<0.3125>
65422 (0xff8e) SLONG (9) 1<4876667>
65423 (0xff8f) SLONG (9) 1<4292627296>

65424 (0xff90) SLONG (9) 1<0>

65425 (0xff91) LONG (4) 1<0>

StripOffsets (273) LONG (4) 1<197919169>
StripByteCounts (279) LONG (4) 1<53800>

Directory 4: offset 198030603 (0xbcdb50b) next 0 (0)
ImageWidth (256) LONG (4) 1<1191>
ImageLength (257) LONG (4) 1<408>
BitsPerSample (258) SHORT (3) 3<8 8 8>
SamplesPerPixel (277) SHORT (3) 1<3>
RowsPerStrip (278) LONG (4) 1<408>
Compression (259) SHORT (3) 1<7>
Photometric (262) SHORT (3) 1<6>
Make (271) ASCII (2) 10<Hamamatsu\0>
Model (272) ASCII (2) 11<NanoZoomer\0>
XResolution (282) RATIONAL (5) 1<156>
YResolution (283) RATIONAL (5) 1<156>
ResolutionUnit (296) SHORT (3) 1<3>

Software (305) ASCII (2) 9<NDP.scan\0>

DateTime (306) ASCII (2) 20<2009:12:31 09:11:46\0>
YCbCrSubsampling (530) SHORT (3) 2<1 1>
ReferenceBlackWhite (532) LONG (4) 6<0 255 128 255 128 255>
65420 (0xff8c) SHORT (3) 1<1>

65421 (0xff8d) FLOAT (11) 1<-1>
65422 (0xff8e) SLONG (9) 1<0>
65423 (0xff8f) SLONG (9) 1<0>

StripOffsets (273) LONG (4) 1<197973459>
StripByteCounts (279) LONG (4) 1<57144>