display.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include <stdlib.h>
  2. #include <grass/gis.h>
  3. #include <grass/colors.h>
  4. #include <grass/raster.h>
  5. #include <grass/display.h>
  6. #include <grass/glocale.h>
  7. #include "mask.h"
  8. #include "local_proto.h"
  9. static int cell_draw(const char *, struct Colors *, int, int, RASTER_MAP_TYPE);
  10. int display(const char *name,
  11. int overlay,
  12. char *bg, RASTER_MAP_TYPE data_type, int invert)
  13. {
  14. struct Colors colors;
  15. int r, g, b;
  16. if (Rast_read_colors(name, "", &colors) == -1)
  17. G_fatal_error(_("Color file for <%s> not available"), name);
  18. if (bg) {
  19. if (G_str_to_color(bg, &r, &g, &b) != 1) {
  20. G_warning(_("[%s]: No such color"), bg);
  21. r = g = b = 255;
  22. }
  23. Rast_set_null_value_color(r, g, b, &colors);
  24. }
  25. D_setup(0);
  26. /* Go draw the raster map */
  27. cell_draw(name, &colors, overlay, invert, data_type);
  28. /* release the colors now */
  29. Rast_free_colors(&colors);
  30. return 0;
  31. }
  32. static int cell_draw(const char *name,
  33. struct Colors *colors,
  34. int overlay, int invert, RASTER_MAP_TYPE data_type)
  35. {
  36. int cellfile;
  37. void *xarray;
  38. int cur_A_row;
  39. int ncols, nrows;
  40. ncols = Rast_window_cols();
  41. nrows = Rast_window_rows();
  42. /* Set up the screen, conversions, and graphics */
  43. D_setup(0);
  44. D_set_overlay_mode(overlay);
  45. /* Make sure map is available */
  46. cellfile = Rast_open_old(name, "");
  47. /* Allocate space for cell buffer */
  48. xarray = Rast_allocate_buf(data_type);
  49. D_cell_draw_begin();
  50. /* loop for array rows */
  51. for (cur_A_row = 0; cur_A_row != -1;) {
  52. G_percent(cur_A_row, nrows, 2);
  53. /* Get window (array) row currently required */
  54. Rast_get_row(cellfile, xarray, cur_A_row, data_type);
  55. mask_raster_array(xarray, ncols, invert, data_type);
  56. /* Draw the cell row, and get the next row number */
  57. cur_A_row = D_draw_raster(cur_A_row, xarray, colors, data_type);
  58. }
  59. D_cell_draw_end();
  60. G_percent(nrows, nrows, 2);
  61. /* Wrap up and return */
  62. Rast_close(cellfile);
  63. G_free(xarray);
  64. return (0);
  65. }
  66. int mask_raster_array(void *xarray,
  67. int ncols, int invert, RASTER_MAP_TYPE data_type)
  68. {
  69. if (data_type == CELL_TYPE)
  70. mask_cell_array((CELL *) xarray, ncols, &mask, invert);
  71. else if (data_type == DCELL_TYPE)
  72. mask_d_cell_array((DCELL *) xarray, ncols, &d_mask, invert);
  73. return 0;
  74. }