2000.04.14 18:01 "tiff with jpeg (unknown tag 33918)", by Alex Catchpaugh

2000.04.17 15:04 "Re: libtiff crash with tiled jpeg (was: unknown tag 33918)", by Tom Lane

This jogged my memory a little bit. I think I fixed the problem in my private copy a long time ago,

Try the attached patch and see if it helps.

I still get the crash in the same place with the patch in place.

Yeah, I still see problems too :-(. Darn, I thought this code used to work...

You are right that tiffcp has some severe limitations with subsampled YCbCr input. In fact, I recall complaining on this list several years ago that none of the tiff tools suite offered an option to convert YCbCr data back to RGB; thus, while "tiffcp -c jpeg" by default will convert RGB to YCbCr, there's no way to go the other direction.

Doing it really right would require extending all of the data-copying routines in tiffcp.c to understand about subsampled input data, so that they don't walk off the end of their input or output buffer. I don't have the time to tackle that; any volunteers?

One possible shortcut solution, which would only help for JPEG-coded input files, is to add some more "auto colorspace transformation" code to tiffcp's startup logic. It would check for a YCbCr-colorspace JPEG-compressed input file, and if so select JPEGCOLORMODE_RGB on the *input* file, so as to obtain upsampled RGB data from the JPEG decoder. (Then RGB not YCbCr would be the colorspace propagated to the output file.) I ran out of time last night before testing this, but I think it would solve the problem.

I was also seeing problems last night with JPEG-coded tiled images of width less than the tile width. I am not sure if there's really a bug or if it was an artifact of the subsampling confusion...

regards, tom lane
organizer, Independent JPEG Group