color_range.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*!
  2. * \file raster/color_range.c
  3. *
  4. * \brief Raster Library - Color range functions.
  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 <math.h>
  14. #include <grass/gis.h>
  15. /*!
  16. \brief Set color range (CELL version)
  17. \param min,max minimum and maximum value
  18. \param colors pointer to Colors structure which holds color info
  19. */
  20. void Rast_set_c_color_range(CELL min, CELL max, struct Colors *colors)
  21. {
  22. if (min < max) {
  23. colors->cmin = (DCELL) min;
  24. colors->cmax = (DCELL) max;
  25. }
  26. else {
  27. colors->cmin = (DCELL) max;
  28. colors->cmax = (DCELL) min;
  29. }
  30. }
  31. /*!
  32. \brief Set color range (DCELL version)
  33. \param min,max minimum and maximum value
  34. \param colors pointer to Colors structure which holds color info
  35. */
  36. void Rast_set_d_color_range(DCELL min, DCELL max, struct Colors *colors)
  37. {
  38. if (min < max) {
  39. colors->cmin = min;
  40. colors->cmax = max;
  41. }
  42. else {
  43. colors->cmin = max;
  44. colors->cmax = min;
  45. }
  46. }
  47. /*!
  48. \brief Get color range values (CELL)
  49. Returns min and max category in the range or huge numbers if the
  50. color table is defined on floating cell values and not on
  51. categories.
  52. \param[out] min,max minimum and maximum value
  53. \param colors pointer to Colors structure which holds color info
  54. */
  55. void Rast_get_c_color_range(CELL * min, CELL * max, const struct Colors *colors)
  56. {
  57. if (!colors->is_float) {
  58. *min = (CELL) floor(colors->cmin);
  59. *max = (CELL) ceil(colors->cmax);
  60. }
  61. else {
  62. *min = -255 * 255 * 255;
  63. *max = 255 * 255 * 255;
  64. }
  65. }
  66. /*!
  67. \brief Get color range values (DELL)
  68. Returns min and max category in the range or huge numbers if the
  69. color table is defined on floating cell values and not on
  70. categories.
  71. \param[out] min,max minimum and maximum value
  72. \param colors pointer to Colors structure which holds color info
  73. */
  74. void Rast_get_d_color_range(DCELL * min, DCELL * max, const struct Colors *colors)
  75. {
  76. *min = colors->cmin;
  77. *max = colors->cmax;
  78. }