Graph_close.c 746 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Close down the graphics processing. This gets called only at driver
  3. * termination time.
  4. */
  5. #include <unistd.h>
  6. #include <fcntl.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #ifdef __MINGW32__
  10. #include <windows.h>
  11. #else
  12. #include <sys/mman.h>
  13. #endif
  14. #include <grass/gis.h>
  15. #include "pngdriver.h"
  16. static void unmap_file(void)
  17. {
  18. size_t size = HEADER_SIZE + png.width * png.height * sizeof(unsigned int);
  19. void *ptr = (char *)png.grid - HEADER_SIZE;
  20. if (!png.mapped)
  21. return;
  22. #ifdef __MINGW32__
  23. UnmapViewOfFile(ptr);
  24. CloseHandle(png.handle);
  25. #else
  26. munmap(ptr, size);
  27. #endif
  28. png.mapped = 0;
  29. }
  30. void PNG_Graph_close(void)
  31. {
  32. write_image();
  33. if (png.mapped)
  34. unmap_file();
  35. else
  36. G_free(png.grid);
  37. }