his.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include <grass/gis.h>
  2. #include <grass/raster.h>
  3. #include "his.h"
  4. /****************************************************************************
  5. * HIS_to_RGB() returns the R/G/B values for the proper HIS color associated
  6. * with the following values:
  7. * HUE:
  8. * R: red percent. value 0 - 255
  9. * G: grn percent. value 0 - 255
  10. * B: blu percent. value 0 - 255
  11. * INTENSITY:
  12. * I intensity value: 0 (black) to 255 (full color)
  13. * SATURATION:
  14. * S saturation val: 0 (gray) to 255 (full color)
  15. *
  16. * make_gray_scale() generates a gray-scale color lookup table
  17. ****************************************************************************/
  18. void HIS_to_RGB(int R, /* red percent. for hue: value 0 - 255 */
  19. int G, /* grn percent. for hue: value 0 - 255 */
  20. int B, /* blu percent. for hue: value 0 - 255 */
  21. int I, /* intensity value: 0 (black) to 255 (white) */
  22. int S, /* saturation val: 0 (gray) to 255 (full color) */
  23. CELL * red, /* resulting red value */
  24. CELL * grn, /* resulting green value */
  25. CELL * blu /* resulting blue value */
  26. )
  27. {
  28. /* modify according to intensity */
  29. if (I != 255) {
  30. R = R * I / 255;
  31. G = G * I / 255;
  32. B = B * I / 255;
  33. }
  34. /* modify according to saturation (actually "haze factor") */
  35. if (S != 255) {
  36. R = 127 + (R - 127) * S / 255;
  37. G = 127 + (G - 127) * S / 255;
  38. B = 127 + (B - 127) * S / 255;
  39. }
  40. /* make sure final values are within range */
  41. if (R < 0)
  42. R = 0;
  43. if (G < 0)
  44. G = 0;
  45. if (B < 0)
  46. B = 0;
  47. if (R > 255)
  48. R = 255;
  49. if (G > 255)
  50. G = 255;
  51. if (B > 255)
  52. B = 255;
  53. *red = R;
  54. *grn = G;
  55. *blu = B;
  56. }
  57. int make_gray_scale(struct Colors *gray)
  58. {
  59. int i;
  60. Rast_init_colors(gray);
  61. for (i = 0; i < 256; i++)
  62. Rast_set_c_color((CELL) i, i, i, i, gray);
  63. return 0;
  64. }