2003.11.17 20:04 "[Tiff] TIFF JPEG and Upsampling", by Antonio Scuri

2003.11.18 00:19 "[Tiff] TIFF JPEG and Upsampling", by Ross Finlayson

I�m using LibTIFF 3.6.0 - tif_jpeg.c,v 1.15, in Visual C++ 7.0 (.NET). If I set JPEGCOLORMODE_RGB it works fine.

Since I do not want to auto convert to RGB, and I want an upsampled YCbCr data, I look at the function JPEGPreDecode in line 745 of "tif_jpeg.c" and noticed that what I want is not possible if the original data is downsampled with "sp->xxx_sampling != 1", it will assume that I want a downsampled output.

So I just comment lines 743-745 to avoid the "downsampled_output = TRUE;", and the decoding works fine because it changed the initialization of the decoder functions and libJPEG is upsampling the data for JPEGDecode.

In the today logic it seems that I can not have upsampled output for a downsampled data if not using JPEGCOLORMODE_RGB. Is that true? Did I miss something?

I noticed some "XXX" comments about upsampling in the code. Can a pseudo tag control upsampling? It could make the upsampling/downsampling logic easier.

I think it would require changes in several places. For example, the TIFFStripSize function would have to ignore YCbCrCoefficients. After the JPEG codec converts the data from compressed entropy coded data to YCbCr samples (eg Y Y Y Y Cb Cr or Y Y Cb Cr ) then there would have to be a function to upsample the data. I think you might be better off getting the downsampled data and then upsampling it in a separate function.

The YCbCr photometric interpretation is the only one of those supported by libtiff that allows up- and down-sampling, where for each component of the image various amounts of samples represent each pixel. I have read that early TIFF versions allowed different bits per sample for each component, that is no longer the case, each component has the same precision.

It might be a good idea to add the up and down sampling logic to the encoder/decoder, execept that other compressions besides JPEG can use YCbCr. TIFFReadRGBAImage will do upsampling of YCbCr image data. It does this separately from the compressor/codec.

What I want to do is know how to pass downsampled data to the JPEG compressor. I try to pass data that is already downsampled to the JPEG compressor, for example from the file ycbcrcat-tif of the sample images, and don't yet understand how to have the JPEG compressor handle that. I think I might have to read the data from YCbCr image, upsample it to constant sampling factors, and then pass the requested sampling factors back to the output with setting the coefficients tag in the output.

Ross F.