[GRASS-dev] write out indexed array?

Glynn Clements glynn at gclements.plus.com
Mon Feb 8 02:11:51 EST 2010


Hamish wrote:

> r.out.tiff's palette flag seems like a good model, but is there a way
> to set the max color levels to 127 automatically instead of just exiting
> with an error telling the user to adjust the input map?

No.

Note that the cmin and cmax fields in "struct Colors" are just the
minimum and maximum cell values covered by the colour table. 
r.out.tiff doesn't "choose" a palette; it just insists that the data
(after conversion to integer) doesn't span more than 256 categories,
and outputs the result of looking up those categories in the colour
table.

> there is R_get_num_colors(), is there any R_set_num_colors() possible?

No.

And R_get_num_colors() isn't particularly relevant. Support for
indexed colour was largely removed sometime between 5.3 and 6.2.3 (I
don't have the early 6.x versions for comparios), and removed entirely
between 6.2.3 and 6.3.0. In 6.4+, R_get_num_colors() is essentially
meaningless; the only module which uses it is d.info, which just
displays the result. In 7.0, it doesn't exist at all.

Even when indexed colour was fully supported ("d.colormode float"
etc), rasters were drawn using either a grey scale or a quantised
colour cube; there was never any palette optimisation code as would be
found in e.g. ppmtogif.

If you're outputting 16-colour images, either output 24-bpp RGB and
use a suitable image conversion tool, or take the palette optimisation
code from such a tool (one with a GPL-compatible licence, obviously).

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list