color_range.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <math.h>
  2. #include <grass/gis.h>
  3. void G_set_color_range(CELL min, CELL max, struct Colors *colors)
  4. {
  5. if (min < max) {
  6. colors->cmin = (DCELL) min;
  7. colors->cmax = (DCELL) max;
  8. }
  9. else {
  10. colors->cmin = (DCELL) max;
  11. colors->cmax = (DCELL) min;
  12. }
  13. }
  14. void G_set_d_color_range(DCELL min, DCELL max, struct Colors *colors)
  15. {
  16. if (min < max) {
  17. colors->cmin = min;
  18. colors->cmax = max;
  19. }
  20. else {
  21. colors->cmin = max;
  22. colors->cmax = min;
  23. }
  24. }
  25. /* returns min and max category in the range or huge numbers
  26. if the co,lor table is defined on floating cell values and
  27. not on categories */
  28. /*!
  29. * \brief
  30. *
  31. * \param G_get_color_range
  32. * \return int
  33. */
  34. void G_get_color_range(CELL * min, CELL * max, const struct Colors *colors)
  35. {
  36. if (!colors->is_float) {
  37. *min = (CELL) floor(colors->cmin);
  38. *max = (CELL) ceil(colors->cmax);
  39. }
  40. else {
  41. *min = -255 * 255 * 255;
  42. *max = 255 * 255 * 255;
  43. }
  44. }
  45. /* returns min and max values in the range */
  46. void G_get_d_color_range(DCELL * min, DCELL * max, const struct Colors *colors)
  47. {
  48. *min = colors->cmin;
  49. *max = colors->cmax;
  50. }