Opened 7 years ago

Closed 7 years ago

#5869 closed defect (invalid)

gdal_translate from GeoTIFF to PNG switches to 8 bits and truncates

Reported by: benl Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: 1.11.2
Severity: normal Keywords:


If I download this map:

and translate the tif like so:

gdal_translate -of png srtm_36_02.tif srtm_36_02.png

I get this error:

Warning 6: PNG driver doesn't support data type Int16. Only eight bit (Byte) and sixteen bit (UInt16) bands supported. Defaulting to Byte

Possibly because the tif contains some negative elevation values. In my own code where I offset by the minimum, I can generate a 16 bit PNG just fine.

Change History (5)

comment:1 Changed 7 years ago by Even Rouault

Resolution: invalid
Status: newclosed

You can use the -scale option to do any scaling/offseting you like.

comment:2 Changed 7 years ago by benl

Resolution: invalid
Status: closedreopened

This may be true, but surely the default should be to produce a correct PNG? As well as going down to 8 bits, it truncates all the high ground.

comment:3 Changed 7 years ago by Even Rouault

If you use gdal_translate -strict, the warning is an error and no file is generated. There's no other automated behaviour we can have that will please everybody. Honestly I don't see any further action that could be done on this ticket. A warning is emitted, so you're aware that something might not be OK.

comment:4 Changed 7 years ago by lpinner

@benl - I don't think Int16 is a valid bit depth for single channel greyscale PNGs (, UInt16 is valid though, so if you must output a 16bit PNG, use something like:

gdal_translate -ot UInt16 -of png srtm_36_02.tif srtm_36_02.png

comment:5 Changed 7 years ago by Even Rouault

Resolution: invalid
Status: reopenedclosed
Note: See TracTickets for help on using tickets.