[mapserver-commits] r10722 - sandbox/mapserver6

svn at osgeo.org svn at osgeo.org
Sat Nov 13 13:30:19 EST 2010


Author: tamas
Date: 2010-11-13 10:30:19 -0800 (Sat, 13 Nov 2010)
New Revision: 10722

Modified:
   sandbox/mapserver6/mapimageio.c
   sandbox/mapserver6/mapserver.h
Log:
Support for saving the GD image to buffer 

Modified: sandbox/mapserver6/mapimageio.c
===================================================================
--- sandbox/mapserver6/mapimageio.c	2010-11-13 18:27:32 UTC (rev 10721)
+++ sandbox/mapserver6/mapimageio.c	2010-11-13 18:30:19 UTC (rev 10722)
@@ -800,6 +800,58 @@
 	  return MS_SUCCESS;
 }
 
+int saveGdImageBuffer(gdImagePtr ip, bufferObj *buffer, outputFormatObj *format) {
+	gdIOCtx *ctx;
+
+    ctx = gdNewDynamicCtx (2048, NULL);
+
+    if( format->imagemode == MS_IMAGEMODE_RGBA )
+        gdImageSaveAlpha( ip, 1 );
+    else if( format->imagemode == MS_IMAGEMODE_RGB )
+        gdImageSaveAlpha( ip, 0 );
+    
+    if(strcasecmp("ON", msGetOutputFormatOption(format, "INTERLACE", "ON")) == 0)
+	    gdImageInterlace(ip, 1);
+
+	  if(format->transparent)
+	    gdImageColorTransparent(ip, 0);
+
+	  if(msCaseFindSubstring(format->driver, "/gif")) {
+	#ifdef USE_GD_GIF
+	    gdImageGifCtx( ip, ctx );
+	#else
+	    msSetError(MS_MISCERR, "GIF output is not available.", "saveImageGD()");
+        ctx->gd_free(ctx);
+	    return(MS_FAILURE);
+	#endif
+	  } else if(msCaseFindSubstring(format->driver, "/png")) {
+	#ifdef USE_GD_PNG
+	    gdImagePngCtx(ip, ctx);
+	#else
+	    msSetError(MS_MISCERR, "PNG output is not available.", "saveImageGD()");
+        ctx->gd_free(ctx);
+	    return(MS_FAILURE);
+	#endif
+	  } else if(msCaseFindSubstring(format->driver, "/jpeg")) {
+	#ifdef USE_GD_JPEG
+	    gdImageJpegCtx(ip, ctx, atoi(msGetOutputFormatOption( format, "QUALITY", "75")));
+	#else
+	    msSetError(MS_MISCERR, "JPEG output is not available.", "saveImageGD()");
+        ctx->gd_free(ctx);
+	    return(MS_FAILURE);
+	#endif
+	  } else {
+	    msSetError(MS_MISCERR, "Unknown or unsupported format.", "saveImageGD()");
+        ctx->gd_free(ctx);
+	    return(MS_FAILURE);
+	  }
+
+      buffer->data = gdDPExtractData (ctx, &buffer->size);
+
+      ctx->gd_free(ctx);
+	  return MS_SUCCESS;
+}
+
 int msSaveRasterBuffer(rasterBufferObj *rb, FILE *stream,
         outputFormatObj *format) {
 	if(rb->type == MS_BUFFER_GD) {
@@ -824,6 +876,9 @@
 
 int msSaveRasterBufferToBuffer(rasterBufferObj *data, bufferObj *buffer,
         outputFormatObj *format) {
+    if(data->type == MS_BUFFER_GD) {
+		return saveGdImageBuffer(data->data.gd_img, buffer, format);
+	}
     if(msCaseFindSubstring(format->driver,"/png")) {
         streamInfo info;
         info.fp = NULL;

Modified: sandbox/mapserver6/mapserver.h
===================================================================
--- sandbox/mapserver6/mapserver.h	2010-11-13 18:27:32 UTC (rev 10721)
+++ sandbox/mapserver6/mapserver.h	2010-11-13 18:30:19 UTC (rev 10722)
@@ -2487,8 +2487,8 @@
 int msLoadMSRasterBufferFromFile(char *path, rasterBufferObj *rb);
 int msLoadGDRasterBufferFromFile(char *path, rasterBufferObj *rb);
 int saveGdImage(gdImagePtr ip, FILE *fp, outputFormatObj *format);
+int saveGdImageBuffer(gdImagePtr ip, bufferObj *buffer, outputFormatObj *format);
 
-
 void msBufferInit(bufferObj *buffer);
 void msBufferResize(bufferObj *buffer, size_t target_size);
 MS_DLL_EXPORT void msBufferFree(bufferObj *buffer);



More information about the mapserver-commits mailing list