make_colr.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**********************************************************************
  2. *
  3. * G_make_color (name, mapset, colors)
  4. * char *name name of map
  5. * char *mapset mapset containing name
  6. * struct Colors *colors struct to hold colors
  7. *
  8. * Interactively prompts user for deciding which type of color
  9. * lookup table is desired.
  10. * Red, green, and blue color ramps
  11. * Gray scale
  12. * Rainbow colors
  13. * Random colors
  14. * Color wave
  15. * Aspect colors
  16. * Red through yellow to green
  17. *
  18. * Returns -1 user canceled the request
  19. * 1 color table is ok
  20. **********************************************************************/
  21. #include <grass/gis.h>
  22. #include <grass/glocale.h>
  23. int G_ask_colors(const char *name, const char *mapset, struct Colors *pcolr)
  24. {
  25. char buff[128];
  26. int answ;
  27. struct FPRange range;
  28. DCELL min, max;
  29. G_init_colors(pcolr);
  30. /* determine range cell values */
  31. if (G_read_fp_range(name, mapset, &range) < 0)
  32. return -1;
  33. G_get_fp_range_min_max(&range, &min, &max);
  34. if (G_is_d_null_value(&min) || G_is_d_null_value(&max)) {
  35. sprintf(buff, _(" The raster map %s@%s is empty"), name, mapset);
  36. G_warning(buff);
  37. return -1;
  38. }
  39. /* Prompting */
  40. ASK:
  41. G_clear_screen();
  42. fprintf(stderr,
  43. _("\n\nColor table needed for file [%s] in mapset [%s].\n"), name,
  44. mapset);
  45. fprintf(stderr, _("\nPlease identify the type desired:\n"));
  46. fprintf(stderr, _(" 1: Random colors\n"));
  47. fprintf(stderr, _(" 2: Red, green, and blue color ramps\n"));
  48. fprintf(stderr, _(" 3: Color wave\n"));
  49. fprintf(stderr, _(" 4: Gray scale\n"));
  50. fprintf(stderr, _(" 5: Aspect\n"));
  51. fprintf(stderr, _(" 6: Rainbow colors\n"));
  52. fprintf(stderr, _(" 7: Red through yellow to green\n"));
  53. fprintf(stderr, _(" 8: Green through yellow to red\n"));
  54. fprintf(stderr, _("RETURN quit\n"));
  55. fprintf(stderr, "\n> ");
  56. for (;;) {
  57. if (!G_gets(buff))
  58. goto ASK;
  59. G_strip(buff);
  60. if (*buff == 0)
  61. return -1;
  62. if (sscanf(buff, "%d", &answ) != 1)
  63. answ = -1;
  64. switch (answ) {
  65. case 1:
  66. return G_make_random_colors(pcolr, (CELL) min, (CELL) max);
  67. case 2:
  68. return G_make_ramp_fp_colors(pcolr, min, max);
  69. case 3:
  70. return G_make_wave_fp_colors(pcolr, min, max);
  71. case 4:
  72. return G_make_grey_scale_fp_colors(pcolr, min, max);
  73. case 5:
  74. return G_make_aspect_fp_colors(pcolr, min, max);
  75. case 6:
  76. return G_make_rainbow_fp_colors(pcolr, min, max);
  77. case 7:
  78. return G_make_ryg_fp_colors(pcolr, min, max);
  79. case 8:
  80. return G_make_gyr_fp_colors(pcolr, min, max);
  81. default:
  82. fprintf(stderr, _("\n%s invalid; Try again > "), buff);
  83. break;
  84. }
  85. }
  86. }