GRASS 8 Programmer's Manual 8.6.0dev(2026)-c83afef6d3
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 SPDX-FileCopyrightText: 2003-2014 Glynn Clements
7 SPDX-FileCopyrightText: GRASS Development Team
8 SPDX-License-Identifier: GPL-2.0-or-later
9
10 \author Per Henrik Johansen (original contributor)
11 \author Glynn Clements
12 */
13
14#include <unistd.h>
15#include <fcntl.h>
16#include <sys/types.h>
17#include <sys/stat.h>
18#ifdef _WIN32
19#include <windows.h>
20#else
21#include <sys/mman.h>
22#endif
23
24#include <grass/gis.h>
25#include "pngdriver.h"
26
27static void unmap_file(void)
28{
29 size_t size =
30 HEADER_SIZE + (size_t)png.width * png.height * sizeof(unsigned int);
31 void *ptr = (char *)png.grid - HEADER_SIZE;
32
33 if (!png.mapped)
34 return;
35
36#ifdef _WIN32
37 UnmapViewOfFile(ptr);
38 CloseHandle(png.handle);
39#else
40 munmap(ptr, size);
41#endif
42
43 png.mapped = 0;
44}
45
46/*!
47 \brief Close down the graphics processing. This gets called only at driver
48 termination time.
49 */
51{
53
54 if (png.mapped)
55 unmap_file();
56 else
57 G_free(png.grid);
58}
#define HEADER_SIZE
Definition cairodriver.h:45
void G_free(void *)
Free allocated memory.
Definition gis/alloc.c:145
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)