[mapserver-commits] r9882 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Tue Feb 23 12:17:40 EST 2010


Author: tbonfort
Date: 2010-02-23 12:17:39 -0500 (Tue, 23 Feb 2010)
New Revision: 9882

Modified:
   trunk/mapserver/mapimageio.c
Log:
function headers for PNG image loading


Modified: trunk/mapserver/mapimageio.c
===================================================================
--- trunk/mapserver/mapimageio.c	2010-02-23 16:36:12 UTC (rev 9881)
+++ trunk/mapserver/mapimageio.c	2010-02-23 17:17:39 UTC (rev 9882)
@@ -2,7 +2,7 @@
  * $Id$
  *
  * Project:  MapServer
- * Purpose:  Low level PNG/JPEG image io functions independent of GD.
+ * Purpose:  Low level PNG/JPEG/GIF image io native functions
  * Author:   Thomas Bonfort (tbonfort)
  *
  ******************************************************************************
@@ -271,6 +271,57 @@
     return MS_SUCCESS;
 }
 
+rasterBufferObj* readPNG(FILE *stream) {
+    rasterBufferObj *rb = (rasterBufferObj*)malloc(sizeof(rasterBufferObj));
+    png_uint_32 width,height;
+    int bit_depth,color_type;
+    png_structp png_ptr = NULL;
+    png_infop info_ptr = NULL;
+    
+    /* could pass pointers to user-defined error handlers instead of NULLs: */
+    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+    if (!png_ptr)
+        return NULL;   /* out of memory */
+
+    info_ptr = png_create_info_struct(png_ptr);
+    if (!info_ptr) {
+        png_destroy_read_struct(&png_ptr, NULL, NULL);
+        return NULL;   /* out of memory */
+    }
+
+    if(setjmp(png_jmpbuf(png_ptr))) {
+        png_destroy_read_struct(&png_ptr,&info_ptr,NULL);
+        return NULL;
+    }
+
+    png_init_io(png_ptr,stream);
+    png_read_info(png_ptr,info_ptr);
+    png_get_IHDR(png_ptr, info_ptr, &width, &height,
+            &bit_depth, &color_type,
+            NULL,NULL,NULL);
+    
+    rb->width = width;
+    rb->height = height;
+    
+    return rb; 
+
+}
+
+rasterBufferObj *readImage(FILE *stream) {
+    unsigned char signature[8];
+    fread(signature,1,8,stream);
+    rewind(stream);
+    if(png_check_sig(signature,8)) {
+        return readPNG(stream);
+#if 0
+    } else if () {//GIF loading
+#endif
+    } else {
+        msSetError(MS_MISCERR,"unsupported pixmap format","readImage()");
+        return NULL;
+    }
+}
+
 int msSaveRasterBuffer(rasterBufferObj *data, FILE *stream,
         outputFormatObj *format) {
     if(msCaseFindSubstring(format->driver,"/png")) {



More information about the mapserver-commits mailing list