Loading...
Searching...
No Matches
pngdriver/graph_close.c
Go to the documentation of this file.
/*!
\file lib/pngdriver/graph_close.c
\brief GRASS png display driver - close graphics processing
(C) 2003-2014 by Glynn Clements and the GRASS Development Team
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
\author Per Henrik Johansen (original contributor)
\author Glynn Clements
*/
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/mman.h>
#endif
#include <grass/gis.h>
#include "pngdriver.h"
static void unmap_file(void)
{
size_t size = HEADER_SIZE + png.width * png.height * sizeof(unsigned int);
void *ptr = (char *)png.grid - HEADER_SIZE;
if (!png.mapped)
return;
#ifdef _WIN32
UnmapViewOfFile(ptr);
CloseHandle(png.handle);
#else
munmap(ptr, size);
#endif
png.mapped = 0;
}
/*!
\brief Close down the graphics processing. This gets called only at driver
termination time.
*/
void PNG_Graph_close(void)
{
write_image();
if (png.mapped)
unmap_file();
else
G_free(png.grid);
}
G_free
void G_free(void *buf)
Free allocated memory.
Definition alloc.c:147
HEADER_SIZE
#define HEADER_SIZE
Definition cairodriver.h:46
PNG_Graph_close
void PNG_Graph_close(void)
Close down the graphics processing. This gets called only at driver termination time.
Definition pngdriver/graph_close.c:50
png
struct png_state png
Definition pngdriver/graph_set.c:32
pngdriver.h
GRASS png display driver - header file.
write_image
void write_image(void)
Definition pngdriver/write.c:22