Opened 11 years ago

Closed 11 years ago

#2642 closed defect (fixed)

JPEG quality for GeoTiff is always set to 75, and zip quality is always the default value

Reported by: smyth Owned by: warmerdam
Priority: normal Milestone: 1.5.4
Component: GDAL_Raster Version: unspecified
Severity: normal Keywords: gtiff
Cc:

Description

I have a program that creates a raster file using the the gtiff driver. I have set the jpeg quality using the option string "JPEQ_QUALITY=<value>". When I run the program first with a quality of 10, and then with a quality of 90 I get identical output - the quality has no effect. My guess was that the JPEQ quality gets set to the default 75 each time.

I ran my program in a debugger using a debug version of GDAL version 1.5.3 (using the --enable-debug option).

Going through the debugger, it looks like the quality is initially set correctly. However, before the first write a call is made to GTiffDataset::Crystalize. In the GTiffDataset::Crystalize() function, the routine TIFFSetDirectory is called. A side effect of calling this function is that the compression is reinitialized, setting the quality back to the the default of 75. This reset value is then what is used when the writing occurs.

I have a patch to fix this, which I've attached. This patch is similar to what is already done in GTiffCreateCopy, where the tags for the zip and JPEG quality get reset after closing and opening the file. The patch just grabs the zip and jpeg quality tags at the beginning of Cystalize routine and then reset them at the end of the routine.

Attachments (1)

gdal.patch (943 bytes) - added by smyth 11 years ago.
Patch to 1.5.3 version of GDAL to fix JPEQ and ZIP quality setting

Download all attachments as: .zip

Change History (3)

Changed 11 years ago by smyth

Attachment: gdal.patch added

Patch to 1.5.3 version of GDAL to fix JPEQ and ZIP quality setting

comment:1 Changed 11 years ago by warmerdam

Component: defaultGDAL_Raster
Keywords: gtiff added
Milestone: 1.5.4
Status: newassigned

I'll review and apply this.

comment:2 Changed 11 years ago by warmerdam

Resolution: fixed
Status: assignedclosed

I confirmed the problem using gdalwarp.

 gdalwarp utm.tif out.tif -co COMPRESS=JPEG -co JPEG_QUALITY=10

I have applied the fix in trunk (r15657) and 1.5 branch (r15658).

The problem only impacted Create() related files, not CreateCopy?() created files.

Note: See TracTickets for help on using tickets.