[mapserver-commits] r10698 - trunk/mapserver
svn at osgeo.org
svn at osgeo.org
Mon Nov 1 18:08:23 EDT 2010
Author: tamas
Date: 2010-11-01 15:08:23 -0700 (Mon, 01 Nov 2010)
New Revision: 10698
Modified:
trunk/mapserver/mapgd2.c
trunk/mapserver/mapserver.h
trunk/mapserver/maputil.c
Log:
Add saveImageBuffer to the renderer vtable in order to support the renderer specific native buffer output. Implemented saveImageBuffer for the gd2 renderer.
Modified: trunk/mapserver/mapgd2.c
===================================================================
--- trunk/mapserver/mapgd2.c 2010-11-01 19:26:33 UTC (rev 10697)
+++ trunk/mapserver/mapgd2.c 2010-11-01 22:08:23 UTC (rev 10698)
@@ -61,6 +61,65 @@
return img;
}
+unsigned char* saveImageBufferGD(imageObj *img, int *size_ptr, outputFormatObj *format)
+{
+ gdImagePtr ip;
+ unsigned char *imgbytes;
+ gdIOCtx *ctx;
+
+ if(!img || !size_ptr) return NULL;
+ if(!(ip = MS_IMAGE_GET_GDIMAGEPTR(img))) return NULL;
+
+ 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(strcasecmp(format->driver, "gd2/gif") == 0) {
+#ifdef USE_GD_GIF
+ gdImageGifCtx( ip, ctx );
+#else
+ msSetError(MS_MISCERR, "GIF output is not available.", "saveImageBufferGD()");
+ ctx->gd_free(ctx);
+ return NULL;
+#endif
+ } else if(strcasecmp(format->driver, "gd2/png") == 0) {
+#ifdef USE_GD_PNG
+ gdImagePngCtx(ip, ctx);
+#else
+ msSetError(MS_MISCERR, "PNG output is not available.", "saveImageBufferGD()");
+ ctx->gd_free(ctx);
+ return NULL;
+#endif
+ } else if(strcasecmp(format->driver, "gd2/jpeg") == 0) {
+#ifdef USE_GD_JPEG
+ gdImageJpegCtx(ip, ctx, atoi(msGetOutputFormatOption( format, "QUALITY", "75")));
+#else
+ msSetError(MS_MISCERR, "JPEG output is not available.", "saveImageBufferGD()");
+ ctx->gd_free(ctx);
+ return NULL;
+#endif
+ } else {
+ msSetError(MS_MISCERR, "Unknown or unsupported format.", "saveImageBufferGD()");
+ ctx->gd_free(ctx);
+ return NULL;
+ }
+
+ imgbytes = gdDPExtractData (ctx, size_ptr);
+
+ ctx->gd_free(ctx);
+
+ return imgbytes;
+}
+
int saveImageGD(imageObj *img, FILE *fp, outputFormatObj *format)
{
gdImagePtr ip;
@@ -426,6 +485,7 @@
renderer->renderLine = &renderLineGD;
renderer->createImage = &createImageGD;
renderer->saveImage = &saveImageGD;
+ renderer->saveImageBuffer = &saveImageBufferGD;
renderer->getRasterBuffer = &getRasterBufferGD;
renderer->transformShape = &msTransformShapeToPixel;
renderer->renderPolygon = &renderPolygonGD;
Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h 2010-11-01 19:26:33 UTC (rev 10697)
+++ trunk/mapserver/mapserver.h 2010-11-01 22:08:23 UTC (rev 10698)
@@ -2753,6 +2753,7 @@
/* image i/o */
imageObj* (*createImage)(int width, int height, outputFormatObj *format, colorObj* bg);
int (*saveImage)(imageObj *img, FILE *fp, outputFormatObj *format);
+ unsigned char* (*saveImageBuffer)(imageObj *img, int *size_ptr, outputFormatObj *format);
/*...*/
/* helper functions */
Modified: trunk/mapserver/maputil.c
===================================================================
--- trunk/mapserver/maputil.c 2010-11-01 19:26:33 UTC (rev 10697)
+++ trunk/mapserver/maputil.c 2010-11-01 22:08:23 UTC (rev 10698)
@@ -795,6 +795,10 @@
return buffer.data;
//don't free the bufferObj as we don't own the bytes anymore
} else {
+ /* check if the renderer supports native buffer output */
+ if (renderer->saveImageBuffer)
+ return renderer->saveImageBuffer(image, size_ptr, format);
+
msSetError(MS_MISCERR, "Unsupported image type", "msSaveImageBuffer()");
return NULL;
}
More information about the mapserver-commits
mailing list