raster.c 896 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <stdlib.h>
  2. #include <grass/gis.h>
  3. #include <grass/raster.h>
  4. #include <grass/glocale.h>
  5. void *read_raster(void *buf, const int fd, const RASTER_MAP_TYPE rtype)
  6. {
  7. void *tmpbuf = buf;
  8. int rows = Rast_window_rows();
  9. int i;
  10. G_message(_("Reading raster map..."));
  11. for (i = 0; i < rows; i++) {
  12. G_percent(i + 1, rows, 10);
  13. Rast_get_row(fd, tmpbuf, i, rtype);
  14. tmpbuf =
  15. G_incr_void_ptr(tmpbuf, Rast_cell_size(rtype) * Rast_window_cols());
  16. }
  17. return tmpbuf;
  18. }
  19. void *write_raster(void *buf, const int fd, const RASTER_MAP_TYPE rtype)
  20. {
  21. void *tmpbuf = buf;
  22. int rows = Rast_window_rows();
  23. int i;
  24. G_message(_("Writing raster map..."));
  25. for (i = 0; i < rows; i++) {
  26. G_percent(i, rows, 10);
  27. Rast_put_row(fd, tmpbuf, rtype);
  28. tmpbuf =
  29. G_incr_void_ptr(tmpbuf, Rast_cell_size(rtype) * Rast_window_cols());
  30. }
  31. return tmpbuf;
  32. }