color_set.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include <grass/gis.h>
  2. /* for convenience, but to be avoided if possible */
  3. /*!
  4. * \brief set a category color
  5. *
  6. * The <b>red, green</b>, and
  7. * <b>blue</b> intensities for the color associated with category <b>cat</b>
  8. * are set in the <b>colors</b> structure. The intensities must be in the
  9. * range 0 -­ 255. Values below zero are set as zero, values above 255 are set as
  10. * 255.
  11. * <b>Use of this routine is discouraged because it defeats the new color
  12. * logic.</b> It is provided only for backward compatibility. Overuse can create
  13. * large color tables. <i>G_add_color_rule</i> should be used whenever
  14. * possible.
  15. * <b>Note.</b> The <b>colors</b> structure must have been initialized by
  16. * <i>G_init_color.</i>
  17. *
  18. * \param cat
  19. * \param red
  20. * \param green
  21. * \param blue
  22. * \param colors
  23. * \return int
  24. */
  25. int G_set_color(CELL cat, int r, int g, int b, struct Colors *colors)
  26. {
  27. CELL tmp = cat;
  28. if (G_is_c_null_value(&tmp))
  29. return G_set_null_value_color(r, g, b, colors);
  30. return G_add_color_rule(cat, r, g, b, cat, r, g, b, colors);
  31. }
  32. int G_set_d_color(DCELL val, int r, int g, int b, struct Colors *colors)
  33. {
  34. DCELL tmp = val;
  35. if (G_is_d_null_value(&tmp))
  36. return G_set_null_value_color(r, g, b, colors);
  37. return G_add_d_raster_color_rule(&val, r, g, b, &val, r, g, b, colors);
  38. }
  39. /*!
  40. * \brief
  41. *
  42. * Sets the color (in <em>colors</em>) for the NULL-value to <em>r,g,b</em>.
  43. *
  44. * \param r
  45. * \param g
  46. * \param b
  47. * \param colors
  48. * \return int
  49. */
  50. int G_set_null_value_color(int red, int grn, int blu, struct Colors *colors)
  51. {
  52. colors->null_red = red;
  53. colors->null_grn = grn;
  54. colors->null_blu = blu;
  55. colors->null_set = 1;
  56. return 1;
  57. }
  58. /*!
  59. * \brief
  60. *
  61. * Sets the default color (in <em>colors</em>) to <em>r,g,b</em>. This is
  62. * the color for values which do not have an explicit rule.
  63. *
  64. * \param r
  65. * \param g
  66. * \param b
  67. * \param colors
  68. * \return int
  69. */
  70. int G_set_default_color(int red, int grn, int blu, struct Colors *colors)
  71. {
  72. colors->undef_red = red;
  73. colors->undef_grn = grn;
  74. colors->undef_blu = blu;
  75. colors->undef_set = 1;
  76. return 1;
  77. }