[gdal-dev] Is Internal JPEG compression allowed on RGBA GeoTIFF?

Even Rouault even.rouault at spatialys.com
Tue Jul 25 10:53:58 PDT 2017


Daniele,

> Dear all,
> I was always thinking that JPEG doesn't support transparency so that it
> would not be possible to convert a 4 bands GeoTIFF using JPEG compression
> (without using internal binary mask).
> 
> However, I just did a gdal_translate -ot byte -scale -CO COMPRESS=JPEG
> 4bands.tif rgba_jpeg.tif and it "worked".
> 
> The gdalinfo output on the new file reports 4 bands dataset with
> Gray,Green,Blue,Alpha colors.

I guess you have a .aux.xml file with color interpreation in them. To get a proper RGBA file, 
add -co PHOTOMETRIC=RGB

> 
> Does the TIFF specification allows that?

I didn't find anything in the TechNote 2, which defines JPEG in TIFF compression, that would 
restrict using RGBA
ftp://ftp.sgi.com/graphics/tiff/TTN2.draft.txt

Using imagemagick or gimp seems to show they can decode JPEG-compressed RGBA files 
correctly, but I've no idea how interaporable it is outside of libtiff-based decoders (which 
they are)

> I still have to read it again to check if/how alpha and JPEG compression
> are related, but I'm wondering if you have any feedback on this topic in
> order to understand if a "standard" GeoTIFF reader should be able to deal
> with that or not and how to deal with the Alpha band (which at this point
> would be a Lossy band, containing artifacts).

Yes, the alpha band will be lossily compressed. I guess it would be possible to tweak the 
encoder to use a very conservative quantization table for the alpha component so as to limit 
the loss on this channel (not implemented right now in GDAL)

Basically, you are limited by the combined limitations of TIFF and JPEG spec

So for a pixel-interleaved TIFF (the default with GDAL), up to 4 components (since the JPEG 
spec limits to 4 components per JPEG "scan", and libtiff only knows to drive libjpeg to 
generate a single scan), which could be RGBA or CMYK depending on the 
PhotometricInterpreation and ExtraSamples tag values.

For a band-interleave TIFF ( -co INTERLEAVE=BAND), you can have an arbitrary number of 
bands.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170725/15c8a720/attachment.html>


More information about the gdal-dev mailing list