color_range.c 2.1 KB

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