123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- /**
- * \file color_get.c
- *
- * \brief GIS Library - Functions to get colors from a raster map.
- *
- * (C) 2001-2008 by the GRASS Development Team
- *
- * This program is free software under the GNU General Public License
- * (>=v2). Read the file COPYING that comes with GRASS for details.
- *
- * \author GRASS GIS Development Team
- *
- * \date 1999-2008
- */
- #include <grass/gis.h>
- /**
- * \brief Get a category color.
- *
- * The <b>red, green</b>, and
- * <b>blue</b> intensities for the color associated with category <b>n</b>
- * are extracted from the <b>colors</b> structure. The intensities will be in
- * the range 0 - 255. Also works for null cells.
- *
- * \param[in] n CELL to get color from
- * \param[out] red red value
- * \param[out] grn green value
- * \param[out] blu blue value
- * \param[in] colors Colors struct
- * \return int
- */
- int G_get_color(CELL n, int *red, int *grn, int *blu, struct Colors *colors)
- {
- CELL cat;
- unsigned char r, g, b, set;
- cat = n;
- G_lookup_colors(&cat, &r, &g, &b, &set, 1, colors);
- *red = (int)r;
- *grn = (int)g;
- *blu = (int)b;
- return (int)set;
- }
- /**
- * \brief Gets color from raster.
- *
- * Looks up the rgb colors for
- * <em>rast</em> in the color table <em>colors</em>
- *
- * \param[in] rast input raster map
- * \param[out] red red value
- * \param[out] grn green value
- * \param[out] blu blue value
- * \param[in] colors Colors struct
- * \param[in] map_type type of map (CELL_TYPE,FCELL_TYPE,DCELL_TYPE)
- * \return int
- */
- int G_get_raster_color(const void *rast,
- int *red, int *grn, int *blu,
- struct Colors *colors, RASTER_MAP_TYPE map_type)
- {
- unsigned char r, g, b, set;
- G_lookup_raster_colors(rast, &r, &g, &b, &set, 1, colors, map_type);
- *red = (int)r;
- *grn = (int)g;
- *blu = (int)b;
- return (int)set;
- }
- /**
- * \brief Gets color for a CELL raster.
- *
- * Looks up the rgb colors for CELL
- * <em>rast</em> in the color table <em>colors</em>
- *
- * \param[in] rast input CELL raster
- * \param[out] red red value
- * \param[out] grn green value
- * \param[out] blu blue value
- * \param[in] colors Colors struct
- * \return int
- */
- int G_get_c_raster_color(const CELL * rast,
- int *red, int *grn, int *blu, struct Colors *colors)
- {
- return G_get_raster_color(rast, red, grn, blu, colors, CELL_TYPE);
- }
- /**
- * \brief Gets color for a FCELL raster.
- *
- * Looks up the rgb colors for FCELL <em>rast</em> in the color table
- * <em>colors</em>
- *
- * \param[in] rast input FCELL raster
- * \param[out] red red value
- * \param[out] grn green value
- * \param[out] blu blue value
- * \param[in] colors Colors struct
- * \return int
- */
- int G_get_f_raster_color(const FCELL * rast,
- int *red, int *grn, int *blu, struct Colors *colors)
- {
- return G_get_raster_color(rast, red, grn, blu, colors, FCELL_TYPE);
- }
- /**
- * \brief Gets color for a DCELL raster.
- *
- * Looks up the rgb colors for DCELL <em>rast</em> in the color table
- * <em>colors</em>
- *
- * \param[in] rast input DCELL raster
- * \param[out] red red value
- * \param[out] grn green value
- * \param[out] blu blue value
- * \param[in] colors Colors struct
- * \return int
- */
- int G_get_d_raster_color(const DCELL * rast,
- int *red, int *grn, int *blu, struct Colors *colors)
- {
- return G_get_raster_color(rast, red, grn, blu, colors, DCELL_TYPE);
- }
- /**
- * \brief Gets color for null value.
- *
- * Puts the red, green, and blue components of <b>colors</b> for the
- * NULL-value into <b>red, grn, and blu</b>.
- *
- * \param[out] red red value
- * \param[out] grn green value
- * \param[out] blu blue value
- * \param[in] colors Colors struct
- * \return
- */
- void G_get_null_value_color(int *red, int *grn, int *blu,
- const struct Colors *colors)
- {
- if (colors->null_set) {
- *red = (int)colors->null_red;
- *grn = (int)colors->null_grn;
- *blu = (int)colors->null_blu;
- }
- else if (colors->undef_set) {
- *red = (int)colors->undef_red;
- *grn = (int)colors->undef_grn;
- *blu = (int)colors->undef_blu;
- }
- else
- *red = *blu = *grn = 255; /* white */
- }
- /**
- * \brief Gets default color.
- *
- * Puts the red, green, and blue components of the
- * <tt>"default"</tt> color into <b>red, grn, and blu</b>.
- *
- * \param[out] red red value
- * \param[out] grn green value
- * \param[out] blu blue value
- * \param[in] colors Colors struct
- * \return
- */
- void G_get_default_color(int *red, int *grn, int *blu,
- const struct Colors *colors)
- {
- if (colors->undef_set) {
- *red = (int)colors->undef_red;
- *grn = (int)colors->undef_grn;
- *blu = (int)colors->undef_blu;
- }
- else
- *red = *blu = *grn = 255; /* white */
- }
|