color_range.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. \todo Rename to G_set_c_color_range() ?
  18. \param min,max minimum and maximum value
  19. \param colors pointer to Colors structure which holds color info
  20. */
  21. void Rast_set_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. \todo Rename to G_get_c_color_range() ?
  51. Returns min and max category in the range or huge numbers if the
  52. color table is defined on floating cell values and not on
  53. categories.
  54. \param[out] min,max minimum and maximum value
  55. \param colors pointer to Colors structure which holds color info
  56. */
  57. void Rast_get_color_range(CELL * min, CELL * max, 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 (DELL)
  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, const struct Colors *colors)
  77. {
  78. *min = colors->cmin;
  79. *max = colors->cmax;
  80. }