[gdal-dev] Creating jpeg compressed tiff with alpha

Even Rouault even.rouault at mines-paris.org
Mon Jul 2 04:44:39 PDT 2012

Selon Livneh Yehiyam <yehil at rafael.co.il>:

I've always thought that JPEG compression couldn't deal with RGBA, but it turns
out that I was wrong. I've managed to produce such files (or similar ones) with
2 different approaches :

gdal_translate some_rgba.png out.tif -co COMPRESS=JPEG -co

--> produces a PIXEL-interleaved JPEG-compressed, but reports grey, undefined,
undefined, undefined color interpretation

gdal_translate some_rgba.png out2.tif -co COMPRESS=JPEG -co PHOTOMETRIC=RGB -co

--> produces a BAND-interleaved JPEG-compressed with R,G,B,A color

But no way to produce a PIXEL-interleaved JPEG-compressed with R,G,B,A like the
one you quote below. So I'm not sure what trick GlobalMapper used to produce
such an image. Could you share it for closer analysis of its content ? Does
gdal_translate from this image to an uncompressed one give a result that is
visually OK ?

One drawback that I can see to use JPEG compression for the alpha band is that
at the border between transparent and opaque zones, you might have artifacts due
to the JPEG compression, which is annoying for an alpha channel. Mask bands have
the advantage to be compressed with a non-lossy compression scheme, regardless
of the compression scheme used for the other bands. And when using mask band to
transport transparency alpha, you could still use YCbCr color space for the JPEG
compression of the RGB band, which, thanks to its 2:1:1 resampling, will lead to
smaller file size. (YCbCr cannot be used if you provide the 4 RGBA bands to the
JPEG compressor : you need to separate the RGB content from the A content).

> Even
> Thanks for your quick reply.
> Converting the same image with global mapper gives me different results:
> Driver: GTiff/GeoTIFF
> Files: C:\Users\Atlas\Pictures\2.tif
> Size is 480, 360
> Coordinate System is:
> GEOGCS["WGS 84",
>     DATUM["WGS_1984",
>         SPHEROID["WGS 84",6378137,298.257223560493,
>             AUTHORITY["EPSG","7030"]],
>         AUTHORITY["EPSG","6326"]],
>     PRIMEM["Greenwich",0],
>     UNIT["arc-second",4.848136811095361e-006],
>     AUTHORITY["EPSG","4326"]]
> Origin = (0.000000000000000,360.000000000000000)
> Pixel Size = (1.000000000000000,-1.000000000000000)
> Metadata:
> Image Structure Metadata:
> Corner Coordinates:
> Upper Left  (       0.000,     360.000) (  0d 0' 0.01"E,360d 0' 0.00"N)
> Lower Left  (   0.0000000,   0.0000000) (  0d 0' 0.01"E,  0d 0' 0.01"N)
> Upper Right (     480.000,     360.000) (Invalid angle,360d 0' 0.00"N)
> Lower Right (     480.000,       0.000) (Invalid angle,  0d 0' 0.01"N)
> Center      (     240.000,     180.000) (240d 0' 0.00"E,180d 0' 0.00"N)
> Band 1 Block=128x128 Type=Byte, ColorInterp=Red
> Band 2 Block=128x128 Type=Byte, ColorInterp=Green
> Band 3 Block=128x128 Type=Byte, ColorInterp=Blue
> Band 4 Block=128x128 Type=Byte, ColorInterp=Alpha
> Press any key to continue . . .
> Is there a way to get the same result with gdal? I see that the mask flag is
> different (PER_DATASET ALPHA)

More information about the gdal-dev mailing list