color_range.c 1.2 KB

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