AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2010.12.14 17:55 "[Tiff] patch to tif_jpeg.c", by Dwight Kelly
2010.12.15 00:00 "Re: [Tiff] patch to tif_jpeg.c", by Lee Howard
2011.01.01 13:41 "[Tiff] Regression in libtiff 4.0 CVS when creating a JPEG RGB contig", by Even Rouault
2011.01.01 13:53 "Re: [Tiff] Regression in libtiff 4.0 CVS when creating a JPEG RGB contig", by Even Rouault
2011.01.04 02:44 "Re: [Tiff] Regression in libtiff 4.0 CVS when creating a JPEG RGB contig", by Lee Howard
2011.01.21 00:51 "[Tiff] Cannot read YCbCr JPEG-compressed images", by Craig Bruce
[...]

2011.01.01 13:41 "[Tiff] Regression in libtiff 4.0 CVS when creating a JPEG RGB contig", by Even Rouault

Hi Lee,

Happy New Year to begin with. Now, less funny things ;-) I've seen a regression in GDAL (http://trac.osgeo.org/gdal/ticket/3887) that I tracked down to be caused by the following change in libtiff:

2010-12-14 Lee Howard <faxguy@howardsilvan.com>

        * libtiff/tif_jpeg.c: reduce usage of JCS_UNKNOWN in order
        to improve compatibility with various viewers
        submitted by e-mail from Dwight Kelly <dkelly@apago.com>

--- frmts/gtiff/libtiff/tif_jpeg.c.ok   2011-01-01 14:10:57.226381933 +0100
+++ frmts/gtiff/libtiff/tif_jpeg.c      2011-01-01 14:11:06.736240426 +0100

@@ -1701,8 +1701,15 @@
                        sp->cinfo.c.comp_info[0].h_samp_factor = sp->h_sampling;
                        sp->cinfo.c.comp_info[0].v_samp_factor = sp->v_sampling;
                } else {
- sp->cinfo.c.in_color_space = JCS_UNKNOWN;
- if (!TIFFjpeg_set_colorspace(sp, JCS_UNKNOWN))
+ if (td->td_photometric == PHOTOMETRIC_MINISWHITE || td-
>td_photometric == PHOTOMETRIC_MINISBLACK)

                   sp->cinfo.c.in_color_space = JCS_GRAYSCALE;
 if (td->td_photometric == PHOTOMETRIC_RGB) else
 = JCS_RGB;sp->cinfo.c.in_color_space

+ else if (td->td_photometric == PHOTOMETRIC_SEPARATED && td-
>td_samplesperpixel == 4)

sp->cinfo.c.in_color_space = JCS_CMYK;

else
= JCS_UNKNOWN; sp->cinfo.c.in_color_space
(!TIFFjpeg_set_colorspace(sp, if

(sp->cinfo.c.in_color_space == JCS_RGB)? JCS_YCbCr: sp->cinfo.c.in_color_space))

                                return (0);
                        /* jpeg_set_colorspace set all sampling factors to 1 */
                }

This can be also reproduced with tifcp:

$ ./tools/tiffcp in.tif out.tif -c jpeg:r -p contig

where in.tif is a 3 band image (uncompressed, since for some reason tiffcp doesn't like compressed images as source)

and then:

$ ./tools/tiffinfo out.tif -D
TIFF Directory at offset 0x1274 (4724)
  Image Width: 128 Image Length: 128
  Tile Width: 256 Tile Length: 16
  Bits/Sample: 8
  Sample Format: unsigned integer
  Compression Scheme: JPEG
  Photometric Interpretation: RGB color
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 3
  Planar Configuration: single image plane
  JPEG Tables: (289 bytes)

JPEGPreDecode: Warning, Improper JPEG sampling factors 2,2 Apparently should be 1,1..

JPEGPreDecode: Cannot honour JPEG sampling factors that exceed those specified..

JPEGPreDecode: Warning, Improper JPEG sampling factors 2,2 Apparently should be 1,1..

JPEGPreDecode: Cannot honour JPEG sampling factors that exceed those specified..

JPEGPreDecode: Warning, Improper JPEG sampling factors 2,2 Apparently should be 1,1..

JPEGPreDecode: Cannot honour JPEG sampling factors that exceed those specified..

JPEGPreDecode: Warning, Improper JPEG sampling factors 2,2 Apparently should be 1,1..

JPEGPreDecode: Cannot honour JPEG sampling factors that exceed those specified..

JPEGPreDecode: Warning, Improper JPEG sampling factors 2,2 Apparently should be 1,1..

JPEGPreDecode: Cannot honour JPEG sampling factors that exceed those specified..

JPEGPreDecode: Warning, Improper JPEG sampling factors 2,2 Apparently should be 1,1..

JPEGPreDecode: Cannot honour JPEG sampling factors that exceed those specified..

JPEGPreDecode: Warning, Improper JPEG sampling factors 2,2 Apparently should be 1,1..

JPEGPreDecode: Cannot honour JPEG sampling factors that exceed those specified..

JPEGPreDecode: Warning, Improper JPEG sampling factors 2,2 Apparently should be 1,1..

JPEGPreDecode: Cannot honour JPEG sampling factors that exceed those specified..

The line

if (!TIFFjpeg_set_colorspace(sp, (sp->cinfo.c.in_color_space == JCS_RGB)? JCS_YCbCr: sp->cinfo.c.in_color_space))

looks suspicious to me. Why shouldn't it be just:

 if (!TIFFjpeg_set_colorspace(sp, sp->cinfo.c.in_color_space))

I've tried this and it works fine.

Best regards,

Even