color_set.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*!
  2. * \file raster/color_set.c
  3. *
  4. * \brief Raster Library - Set colors for raster maps.
  5. *
  6. * (C) 2001-2009 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public License
  9. * (>=v2). Read the file COPYING that comes with GRASS for details.
  10. *
  11. * \author Original author CERL
  12. */
  13. #include <grass/gis.h>
  14. #include <grass/raster.h>
  15. /*!
  16. * \brief Set a category color (CELL)
  17. *
  18. * The <i>red, green</i>, and <i>blue</i> intensities for the color
  19. * associated with category <i>cat</i> are set in the <i>colors</i>
  20. * structure. The intensities must be in the range 0 -­ 255. Values
  21. * below zero are set as zero, values above 255 are set as 255.
  22. *
  23. * <b>Warning: Use of this routine is discouraged because it defeats the new
  24. * color logic.</b>
  25. *
  26. * It is provided only for backward compatibility. Overuse can create
  27. * large color tables. Rast_add_c_color_rule() should be used whenever
  28. * possible.
  29. *
  30. * <b>Note:</b> The <i>colors</i> structure must have been
  31. * initialized by G_init_color().
  32. *
  33. * \param cat raster cell value
  34. * \param r red value
  35. * \param g green value
  36. * \param b blue value
  37. * \param colors pointer to Colors structure which holds color info
  38. */
  39. void Rast_set_c_color(CELL cat, int r, int g, int b, struct Colors *colors)
  40. {
  41. if (Rast_is_c_null_value(&cat))
  42. Rast_set_null_value_color(r, g, b, colors);
  43. else
  44. Rast_add_c_color_rule(&cat, r, g, b, &cat, r, g, b, colors);
  45. }
  46. /*!
  47. * \brief Set a category color (DCELL)
  48. *
  49. * See Rast_set_c_color() for detailed information.
  50. *
  51. * \param val raster cell value
  52. * \param r red value
  53. * \param g green value
  54. * \param b blue value
  55. * \param colors pointer to Colors structure which holds color info
  56. */
  57. void Rast_set_d_color(DCELL val, int r, int g, int b, struct Colors *colors)
  58. {
  59. if (Rast_is_d_null_value(&val))
  60. Rast_set_null_value_color(r, g, b, colors);
  61. else
  62. Rast_add_d_color_rule(&val, r, g, b, &val, r, g, b, colors);
  63. }
  64. /*!
  65. * \brief Set color for NULL-value
  66. *
  67. * Sets the color (in <i>colors</i>) for the NULL-value to
  68. * <i>red, green, blue</i>.
  69. *
  70. * \param red red value
  71. * \param grn green value
  72. * \param blu blue value
  73. * \param colors pointer to Colors structure which holds color info
  74. */
  75. void Rast_set_null_value_color(int red, int grn, int blu,
  76. struct Colors *colors)
  77. {
  78. colors->null_red = red;
  79. colors->null_grn = grn;
  80. colors->null_blu = blu;
  81. colors->null_set = 1;
  82. }
  83. /*!
  84. * \brief Set default color value
  85. *
  86. * Sets the default color (in <i>colors</i>) to <i>red, green,
  87. * blue</i>. This is the color for values which do not have an
  88. * explicit rule.
  89. *
  90. * \param red red value
  91. * \param grn green value
  92. * \param blu blue value
  93. * \param colors pointer to Colors structure which holds color info
  94. */
  95. void Rast_set_default_color(int red, int grn, int blu, struct Colors *colors)
  96. {
  97. colors->undef_red = red;
  98. colors->undef_grn = grn;
  99. colors->undef_blu = blu;
  100. colors->undef_set = 1;
  101. }