OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.82k stars 2.52k forks source link

gdal2tiles ignores alpha channel of the input #3953

Open zdila opened 3 years ago

zdila commented 3 years ago

Expected behavior and actual behavior.

I expect gdal2tiles to copy alpha-channel from the input tif (or vrt) to the output png files. It actually generates pngs where output alpha channel is always 100% for non-nodata pixels and 0% for nodata pixels. I would expect it to have alpha=0% for notada and alpha=value_from_alpha_channel for non-nodata pixels.

Steps to reproduce the problem.

My input file bands:

Band 1 Block=256x256 Type=Byte, ColorInterp=Red
  NoData Value=255
Band 2 Block=256x256 Type=Byte, ColorInterp=Green
  NoData Value=255
Band 3 Block=256x256 Type=Byte, ColorInterp=Blue
  NoData Value=255
Band 4 Block=256x256 Type=Byte, ColorInterp=Alpha
  NoData Value=255

Command for generating tiles:

gdal2tiles.py -r near -z 18 --xyz --processes=$(getconf _NPROCESSORS_ONLN) -n -w none input.tif tiles

Operating system

Linux 5.10.0-6-amd64 #1 SMP Debian 5.10.28-1 (2021-04-09) x86_64 GNU/Linux

GDAL version and provenance

3.2.1

jratike80 commented 3 years ago

May be unrelated, but why do you have both NoData value and alpha?

zdila commented 3 years ago

May be unrelated, but why do you have both NoData value and alpha?

jratike80 commented 3 years ago

Ok. Developers will give you better answer, but as far as I know alpha for GDAL is often acting like a binary mask "zeros vs anything else than zero". For some other use case I would have a test by changing the interpretation of band 4 into undefined before processing and then back to alpha, but with thousands of tiles that is unpractical.

zdila commented 3 years ago

BTW I can generate png tiles with correct alpha using mapnik-based server (it is just more work to set it up). Also QGIS has no problem interpreting alpha channel correctly.

rouault commented 3 years ago

Please attach a small input file demonstrating the issue

zdila commented 3 years ago

Attached a sample.

sample.tif.gz

fphilippe commented 1 year ago

Hello everybody, i encounter the same issue. Any news ?

TrimVis commented 5 months ago

I also experience the same issue. I assume there has been no progress on this?