I have an RGBA foo.tif with NoData Value=0
on all 4 bands.
Unfortunately values that are transparent black (0 0 0 0), when converting to jpg, become black instead of no data becoming white like I would expect.
I am trying to work around it with a basic color = if R+G+B==0 then white else color
for each band:
gdal_calc.py -R foo.tif --R_band=1 -G foo.tif --G_band=2 -B foo.tif --B_band=3 --outfile=result.tif \
--calc="where(R+G+B,R,255)" --calc="G*where(R+G+B,G,255)" --calc="where(R+G+B,B,255)" --overwrite
Or this "arithmetic-only" variant
gdal_calc.py -R foo.tif --R_band=1 -G foo.tif --G_band=2 -B foo.tif --B_band=3 --outfile=result.tif \
--calc='R*((R+G+B)!=0) + 255*((R+G+B)==0)' --calc='G*((R+G+B)!=0) + 255*((R+G+B)==0)' --calc='B*((R+G+B)!=0) + 255*((R+G+B)==0)' --overwrite
But the result is not as I expect: Input / Output
Al lot of colors (orange...) have turned white, which is the output's nodata value. And if I add --NoDataValue=0
I get this:
Which makes me think the Blue
Band 3
is somehow the only one impacted by the input "nodata" value of 0. How can I fix this? I have GDAL 3.2 without the new -hideNoData
flag :-(
Or better, can I make a jpg with a white "bottom" with pure GDAL (like this answer, but without rasterio because I actually want mbtiles jpg in the end)
gdalinfo foo.tif
...
Band 1 Block=390x5 Type=Byte, ColorInterp=Red
NoData Value=0
Band 2 Block=390x5 Type=Byte, ColorInterp=Green
NoData Value=0
Band 3 Block=390x5 Type=Byte, ColorInterp=Blue
NoData Value=0
Band 4 Block=390x5 Type=Byte, ColorInterp=Alpha
NoData Value=0