GRASS 8 Programmer's Manual 8.6.0dev(2026)-4f5ca7b89a
Loading...
Searching...
No Matches
pngdriver/graph_close.c
Go to the documentation of this file.
1/*!
2 \file lib/pngdriver/graph_close.c
3
4 \brief GRASS png display driver - close graphics processing
5
6 (C) 2003-2014 by Glynn Clements and the GRASS Development Team
7
8 This program is free software under the GNU General Public License
9 (>=v2). Read the file COPYING that comes with GRASS for details.
10
11 \author Per Henrik Johansen (original contributor)
12 \author Glynn Clements
13 */
14
15#include <unistd.h>
16#include <fcntl.h>
17#include <sys/types.h>
18#include <sys/stat.h>
19#ifdef _WIN32
20#include <windows.h>
21#else
22#include <sys/mman.h>
23#endif
24
25#include <grass/gis.h>
26#include "pngdriver.h"
27
28static void unmap_file(void)
29{
30 size_t size =
31 HEADER_SIZE + (size_t)png.width * png.height * sizeof(unsigned int);
32 void *ptr = (char *)png.grid - HEADER_SIZE;
33
34 if (!png.mapped)
35 return;
36
37#ifdef _WIN32
38 UnmapViewOfFile(ptr);
39 CloseHandle(png.handle);
40#else
41 munmap(ptr, size);
42#endif
43
44 png.mapped = 0;
45}
46
47/*!
48 \brief Close down the graphics processing. This gets called only at driver
49 termination time.
50 */
52{
54
55 if (png.mapped)
56 unmap_file();
57 else
58 G_free(png.grid);
59}
#define HEADER_SIZE
Definition cairodriver.h:46
void G_free(void *)
Free allocated memory.
Definition gis/alloc.c:147
Header file for msvc/fcntl.c.
void PNG_Graph_close(void)
Close down the graphics processing. This gets called only at driver termination time.
struct png_state png
GRASS png display driver - header file.
void write_image(void)