[GRASS-SVN] r43338 - in grass/trunk: lib/pngdriver
visualization/wximgview
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Aug 29 11:28:18 EDT 2010
Author: glynn
Date: 2010-08-29 15:28:18 +0000 (Sun, 29 Aug 2010)
New Revision: 43338
Modified:
grass/trunk/lib/pngdriver/Graph_close.c
grass/trunk/lib/pngdriver/Graph_set.c
grass/trunk/lib/pngdriver/pngdriver.h
grass/trunk/visualization/wximgview/main.cc
Log:
Add/fix mmap'd BMP support for Windows
Modified: grass/trunk/lib/pngdriver/Graph_close.c
===================================================================
--- grass/trunk/lib/pngdriver/Graph_close.c 2010-08-29 10:56:46 UTC (rev 43337)
+++ grass/trunk/lib/pngdriver/Graph_close.c 2010-08-29 15:28:18 UTC (rev 43338)
@@ -3,11 +3,13 @@
* termination time.
*/
-#ifndef __MINGW32__
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
+#ifdef __MINGW32__
+#include <windows.h>
+#else
#include <sys/mman.h>
#endif
@@ -16,17 +18,20 @@
static void unmap_file(void)
{
-#ifndef __MINGW32__
size_t size = HEADER_SIZE + png.width * png.height * sizeof(unsigned int);
void *ptr = (char *)png.grid - HEADER_SIZE;
if (!png.mapped)
return;
+#ifdef __MINGW32__
+ UnmapViewOfFile(ptr);
+ CloseHandle(png.handle);
+#else
munmap(ptr, size);
+#endif
png.mapped = 0;
-#endif
}
void PNG_Graph_close(void)
Modified: grass/trunk/lib/pngdriver/Graph_set.c
===================================================================
--- grass/trunk/lib/pngdriver/Graph_set.c 2010-08-29 10:56:46 UTC (rev 43337)
+++ grass/trunk/lib/pngdriver/Graph_set.c 2010-08-29 15:28:18 UTC (rev 43338)
@@ -13,10 +13,12 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
-#ifndef __MINGW32__
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
+#ifdef __MINGW32__
+#include <windows.h>
+#else
#include <sys/mman.h>
#endif
@@ -28,7 +30,6 @@
static void map_file(void)
{
-#ifndef __MINGW32__
size_t size = HEADER_SIZE + png.width * png.height * sizeof(unsigned int);
void *ptr;
int fd;
@@ -37,9 +38,20 @@
if (fd < 0)
return;
+#ifdef __MINGW32__
+ png.handle = CreateFileMapping((HANDLE) _get_osfhandle(fd),
+ NULL, PAGE_READWRITE,
+ 0, size, NULL);
+ if (!png.handle)
+ return;
+ ptr = MapViewOfFile(png.handle, FILE_MAP_WRITE, 0, 0, size);
+ if (!ptr)
+ return;
+#else
ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t) 0);
if (ptr == MAP_FAILED)
return;
+#endif
if (png.grid)
G_free(png.grid);
@@ -48,7 +60,6 @@
close(fd);
png.mapped = 1;
-#endif
}
int PNG_Graph_set(void)
Modified: grass/trunk/lib/pngdriver/pngdriver.h
===================================================================
--- grass/trunk/lib/pngdriver/pngdriver.h 2010-08-29 10:56:46 UTC (rev 43337)
+++ grass/trunk/lib/pngdriver/pngdriver.h 2010-08-29 15:28:18 UTC (rev 43338)
@@ -3,6 +3,10 @@
#include <stdio.h>
+#ifdef __MINGW32__
+#include <windows.h>
+#endif
+
#include <grass/config.h>
#include "driver.h"
#include "path.h"
@@ -18,6 +22,9 @@
int true_color;
int has_alpha;
int mapped;
+#ifdef __MINGW32__
+ HANDLE handle;
+#endif
double clip_top, clip_bot, clip_left, clip_rite;
int width, height;
Modified: grass/trunk/visualization/wximgview/main.cc
===================================================================
--- grass/trunk/visualization/wximgview/main.cc 2010-08-29 10:56:46 UTC (rev 43337)
+++ grass/trunk/visualization/wximgview/main.cc 2010-08-29 15:28:18 UTC (rev 43338)
@@ -187,8 +187,12 @@
size = HEADER_SIZE + i_width * i_height * 4;
#ifdef __MINGW32__
- ptr = MapViewOfFile((HANDLE) _get_osfhandle(fd),
- FILE_MAP_READ, 0, 0, size);
+ HANDLE handle = CreateFileMapping((HANDLE) _get_osfhandle(fd),
+ NULL, PAGE_READONLY,
+ 0, size, NULL);
+ if (!handle)
+ return;
+ ptr = MapViewOfFile(handle, FILE_MAP_READ, 0, 0, size);
if (!ptr)
G_fatal_error(_("Unable to map image file"));
#else
More information about the grass-commit
mailing list