[GRASS-dev] Re: [GRASS GIS] #73: r.out.gdal tiff output does not
work
Glynn Clements
glynn at gclements.plus.com
Fri Feb 29 04:01:34 EST 2008
GRASS GIS wrote:
> #73: r.out.gdal tiff output does not work
> ----------------------+-----------------------------------------------------
> Reporter: helena | Owner: grass-dev at lists.osgeo.org
> Type: defect | Status: new
> Priority: major | Milestone: 6.4.0
> Component: default | Version: svn-trunk
> Resolution: | Keywords: r.out.gdal, tiff
> ----------------------+-----------------------------------------------------
> Comment (by hamish):
>
> (I see the same with 6.2.1's old script version of r.out.gdal)
>
> it works if the values are in the range of 0-255:
> {{{
> #spearfish
> r.out.gdal in=fields out=fields.tif type=Byte
> qiv fields.tif # qiv is a quick image viewer
> }}}
>
> but not if all values are out of range:
> {{{
> r.info -r elevation.dem
> min=1066
> max=1840
> r.info -t elevation.dem
> datatype=CELL
> r.out.gdal in=elevation.dem out=elv.tif type=Byte
>
> gdalinfo -stats elv.tif | grep STATISTIC
> STATISTICS_MINIMUM=255
> STATISTICS_MAXIMUM=255
> STATISTICS_MEAN=255
> STATISTICS_STDDEV=0
>
> r.in.gdal in=elv.tif out=elv2
> r.info -r elv2
> min=255
> max=255
> }}}
>
>
> we can try with half the raster in range:
> {{{
> r.mapcalc "elev_0 = elevation.dem - 1066"
> r.info -r elev_0
> min=0
> max=774
> r.out.gdal in=elev_0 out=elv0.tif type=Byte
> gdalinfo -stats elv0.tif | grep STATISTIC
> STATISTICS_MINIMUM=0
> STATISTICS_MAXIMUM=254
> STATISTICS_MEAN=138.68943338231
> STATISTICS_STDDEV=56.526296226099
> }}}
>
> If I load elv0.tif into an image viewer it comes out as all black. But in
> Gimp if you use the eyedropper you can see the index number changes, but
> the palette is black for all 256 index entries.
>
> gdalinfo confirms palette info was not written to file:
I have noticed that r.out.gdal only generates the palette if
G_read_colors() returns 1, i.e. if the map has its own colour table.
If G_read_colors() falls back to a default rainbow colour table, you
don't get a palette.
I suggest:
--- raster/r.out.gdal/main.c (revision 30389)
+++ raster/r.out.gdal/main.c (working copy)
@@ -125,7 +125,7 @@
GDALSetRasterColorInterpretation(hBand, GPI_RGB);
CPLPopErrorHandler();
- if( G_read_colors(name, mapset, &sGrassColors ) == 1 )
+ if( G_read_colors(name, mapset, &sGrassColors ) >= 0 )
{
int maxcolor, i;
CELL min, max;
G_read_colors() returns -1 on error (e.g. the map doesn't exist), 0 if
a default rainbow colour table was generated, and 1 if the map has its
own colour table.
AFAICT, the UInt16 case actually works, insofar as the debug output
with DEBUG=3 and the output from gdalinfo look just like they do for
an 8-bit TIFF which works fine in various viewers.
I wouldn't rule out the possibility that popular image viewers can't
handle 16-bit indexed-colour images.
TIFF's strong-point is that it supports so many different formats.
It's weak point is also that it supports so many different formats. I
doubt that there is a program in existence which can correctly handle
every possible valid TIFF file.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list