graph_close.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*!
  2. \file lib/pngdriver/graph_close.c
  3. \brief GRASS png display driver - close graphics processing
  4. (C) 2003-2014 by Glynn Clements and the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Per Henrik Johansen (original contributor)
  8. \author Glynn Clements
  9. */
  10. #include <unistd.h>
  11. #include <fcntl.h>
  12. #include <sys/types.h>
  13. #include <sys/stat.h>
  14. #ifdef __MINGW32__
  15. #include <windows.h>
  16. #else
  17. #include <sys/mman.h>
  18. #endif
  19. #include <grass/gis.h>
  20. #include "pngdriver.h"
  21. static void unmap_file(void)
  22. {
  23. size_t size = HEADER_SIZE + png.width * png.height * sizeof(unsigned int);
  24. void *ptr = (char *)png.grid - HEADER_SIZE;
  25. if (!png.mapped)
  26. return;
  27. #ifdef __MINGW32__
  28. UnmapViewOfFile(ptr);
  29. CloseHandle(png.handle);
  30. #else
  31. munmap(ptr, size);
  32. #endif
  33. png.mapped = 0;
  34. }
  35. /*!
  36. \brief Close down the graphics processing. This gets called only at driver
  37. termination time.
  38. */
  39. void PNG_Graph_close(void)
  40. {
  41. write_image();
  42. if (png.mapped)
  43. unmap_file();
  44. else
  45. G_free(png.grid);
  46. }