Opened 13 years ago

Closed 13 years ago

#3887 closed defect (fixed)

trunk 1.8.0 regression with internal libtiff and JPEG compression

Reported by: Even Rouault Owned by: warmerdam
Priority: normal Milestone: 1.8.0
Component: default Version: unspecified
Severity: major Keywords:
Cc:

Description (last modified by Even Rouault)

gdal_translate ../autotest/gcore/data/rgbsmall.tif  tif_jpeg.tif -co COMPRESS=JPEG

produces a dataset that cannot be read :

$ gdalinfo -checksum tif_jpeg.tif
Driver: GTiff/GeoTIFF
Files: tif_jpeg.tif
Size is 50, 50
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433],
    AUTHORITY["EPSG","4326"]]
Origin = (-44.840319999999998,-22.932583999999999)
Pixel Size = (0.003432000000000,-0.003432000000000)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  COMPRESSION=JPEG
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  ( -44.8403200, -22.9325840) ( 44d50'25.15"W, 22d55'57.30"S)
Lower Left  ( -44.8403200, -23.1041840) ( 44d50'25.15"W, 23d 6'15.06"S)
Upper Right ( -44.6687200, -22.9325840) ( 44d40' 7.39"W, 22d55'57.30"S)
Lower Right ( -44.6687200, -23.1041840) ( 44d40' 7.39"W, 23d 6'15.06"S)
Center      ( -44.7545200, -23.0183840) ( 44d45'16.27"W, 23d 1' 6.18"S)
Band 1 Block=50x50 Type=Byte, ColorInterp=Red
Warning 1: JPEGPreDecode:Improper JPEG sampling factors 2,2
Apparently should be 1,1.
ERROR 1: JPEGPreDecode:Cannot honour JPEG sampling factors that exceed those specified.
ERROR 1: TIFFReadEncodedStrip() failed.
ERROR 1: IReadBlock failed at X offset 0, Y offset 0
ERROR 1: GetBlockRef failed at X block offset 0, Y block offset 0
ERROR 3: Checksum value couldn't be computed due to I/O read error.

  Checksum=0
Band 2 Block=50x50 Type=Byte, ColorInterp=Green
  Checksum=0
Band 3 Block=50x50 Type=Byte, ColorInterp=Blue
  Checksum=0

Works fine with 1.7 branch and its internal libtiff.

The issue occurs when writing the dataset (a dataset produced with 1.7 can be read by trunk, but not the reverse)

Change History (3)

comment:1 by Even Rouault, 13 years ago

Description: modified (diff)

comment:2 by Even Rouault, 13 years ago

I've identified the regression to be caused by a very recent 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;
+			else if (td->td_photometric == PHOTOMETRIC_RGB)
+				sp->cinfo.c.in_color_space = JCS_RGB;
+			else if (td->td_photometric == PHOTOMETRIC_SEPARATED && td->td_samplesperpixel == 4)
+				sp->cinfo.c.in_color_space = JCS_CMYK;
+			else
+				sp->cinfo.c.in_color_space = JCS_UNKNOWN;
+			if (!TIFFjpeg_set_colorspace(sp, (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 */
 		}

Emailing Lee and libtiff list about this...

comment:3 by Even Rouault, 13 years ago

Resolution: fixed
Status: newclosed

r21395 /trunk/gdal/frmts/gtiff/libtiff/tif_jpeg.c: Update tif_jpeg.c from libtiff CVS to solve #3887

Tests were added in r21360 and r21361

Note: See TracTickets for help on using tickets.