[mapserver-commits] r10506 - in sandbox/mapserver6/mapscript: python python/pygdioctx swiginc

svn at osgeo.org svn at osgeo.org
Fri Sep 17 11:44:04 EDT 2010


Author: aboudreault
Date: 2010-09-17 15:44:04 +0000 (Fri, 17 Sep 2010)
New Revision: 10506

Modified:
   sandbox/mapserver6/mapscript/python/pyextend.i
   sandbox/mapserver6/mapscript/python/pygdioctx/pygdioctx.c
   sandbox/mapserver6/mapscript/swiginc/image.i
   sandbox/mapserver6/mapscript/swiginc/outputformat.i
   sandbox/mapserver6/mapscript/swiginc/shapefile.i
   sandbox/mapserver6/mapscript/swiginc/symbol.i
Log:
Fixed Mapscript/SWIG to use proper functions of mapserver 6 rendering

Modified: sandbox/mapserver6/mapscript/python/pyextend.i
===================================================================
--- sandbox/mapserver6/mapscript/python/pyextend.i	2010-09-13 19:41:06 UTC (rev 10505)
+++ sandbox/mapserver6/mapscript/python/pyextend.i	2010-09-17 15:44:04 UTC (rev 10506)
@@ -166,23 +166,24 @@
      * omit width and height.  Work done as part of Bugzilla issue 550. */
 
     imageObj(PyObject *arg1=Py_None, PyObject *arg2=Py_None, 
-             PyObject *input_format=Py_None)
+             PyObject *input_format=Py_None, PyObject *input_resolution=Py_None, PyObject *input_defresolution=Py_None)
     {
         imageObj *image=NULL;
         outputFormatObj *format=NULL;
         int width;
         int height;
+        double resolution, defresolution;
         PyObject *pybytes;
+        rendererVTableObj *renderer = NULL;
+        rasterBufferObj *rb = NULL;
       
         unsigned char PNGsig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
         unsigned char JPEGsig[3] = {255, 216, 255};
 
-        if (PyInt_Check(arg1) && PyInt_Check(arg2)) 
+        resolution = defresolution = MS_DEFAULT_RESOLUTION;
+
+        if ((PyInt_Check(arg1) && PyInt_Check(arg2)) || PyString_Check(arg1))
         {
-            /* Create from width, height, format/driver */
-            width = (int) PyInt_AsLong(arg1);
-            height = (int) PyInt_AsLong(arg2);
-            
             if (input_format == Py_None) {
                 format = msCreateDefaultOutputFormat(NULL, "GD/GIF");
                 if (format == NULL)
@@ -191,18 +192,21 @@
                     format = msCreateDefaultOutputFormat(NULL, "GD/JPEG");
                 if (format == NULL)
                     format = msCreateDefaultOutputFormat(NULL, "GD/WBMP");
+
+            if (format)
+                msInitializeRendererVTable(format);
             }
             else if (PyString_Check(input_format)) {
                 format = msCreateDefaultOutputFormat(NULL, 
-                                PyString_AsString(input_format));
+                                                     PyString_AsString(input_format));
             }
             else {
                 if ((SWIG_ConvertPtr(input_format, (void **) &format,
-                     SWIGTYPE_p_outputFormatObj,
-                     SWIG_POINTER_EXCEPTION | 0 )) == -1) 
+                                     SWIGTYPE_p_outputFormatObj,
+                                     SWIG_POINTER_EXCEPTION | 0 )) == -1) 
                 {
                     msSetError(MS_IMGERR, "Can't convert format pointer",
-                                          "imageObj()");
+                               "imageObj()");
                     return NULL;
                 }
             }
@@ -212,15 +216,44 @@
                            "imageObj()");
                 return NULL;
             }
+        }
 
-            image = msImageCreate(width, height, format, NULL, NULL, NULL);
+        if (PyFloat_Check(input_resolution))
+            resolution = PyFloat_AsDouble(input_resolution);
+        if (PyFloat_Check(input_defresolution))
+            defresolution = PyFloat_AsDouble(input_defresolution);
+
+        if (PyInt_Check(arg1) && PyInt_Check(arg2)) 
+        {
+            /* Create from width, height, format/driver */
+            width = (int) PyInt_AsLong(arg1);
+            height = (int) PyInt_AsLong(arg2);
+
+            image = msImageCreate(width, height, format, NULL, NULL, resolution, defresolution, NULL);
             return image;
         }
         
         /* Is arg1 a filename? */
         else if (PyString_Check(arg1)) 
         {
-            return (imageObj *) msImageLoadGD((char *) PyString_AsString(arg1));
+            renderer = format->vtable;
+            rb = (rasterBufferObj*)calloc(1,sizeof(rasterBufferObj));
+
+            if (!rb) {
+                msSetError(MS_MEMERR, NULL, "imageObj()");
+                return NULL;
+            }
+
+            if ( (renderer->loadImageFromFile(PyString_AsString(arg1), rb)) == MS_FAILURE)
+                return NULL;
+
+            image = msImageCreate(rb->width, rb->height, format, NULL, NULL, 
+                                  resolution, defresolution, NULL);
+            renderer->mergeRasterBuffer(image, rb, 1.0, 0, 0, 0, 0, rb->width, rb->height);
+
+            msFreeRasterBuffer(rb);
+
+            return image;
         }
         
         /* Is a file-like object */
@@ -298,47 +331,32 @@
     ====================================================================== */
     int write( PyObject *file=Py_None )
     {
-        FILE *stream;
-        gdIOCtx *ctx;
         unsigned char *imgbuffer=NULL;
         int imgsize;
         PyObject *noerr;
         int retval=MS_FAILURE;
-       
+        rendererVTableObj *renderer = NULL;
+
         /* Return immediately if image driver is not GD */
-        if ( !(MS_DRIVER_GD(self->format) || MS_DRIVER_AGG(self->format)) )
+        if ( !MS_RENDERER_PLUGIN(self->format) )
         {
             msSetError(MS_IMGERR, "Writing of %s format not implemented",
                        "imageObj::write", self->format->driver);
             return MS_FAILURE;
         }
- 
+
         if (file == Py_None) /* write to stdout */
-        {
-            ctx = msNewGDFileCtx(stdout);
-            retval = msSaveImageGDCtx(self, ctx, self->format);
-            ctx->gd_free(ctx);
-        }
+            retval = msSaveImage(NULL, self, NULL);
+
         else if (PyFile_Check(file)) /* a Python (C) file */
         {
-            stream = PyFile_AsFile(file);
-            ctx = msNewGDFileCtx(stream);
-            retval = msSaveImageGDCtx(self, ctx, self->format);
-            ctx->gd_free(ctx);
+            renderer = self->format->vtable;
+            retval = renderer->saveImage(self, PyFile_AsFile(file), self->format);
         }
         else /* presume a Python file-like object */
         {
-            if( MS_DRIVER_GD(self->format) )
-                imgbuffer = msSaveImageBufferGD(self, &imgsize,
-                                                self->format);
-#ifdef USE_AGG
-            else if( MS_DRIVER_AGG(self->format) )
-            {
-                imgbuffer = msSaveImageBuffer(   self, &imgsize,
-                                                    self->format);
-            }
-#endif  
-
+            imgbuffer = msSaveImageBuffer(self, &imgsize,
+                                          self->format);
             if (imgsize == 0)
             {
                 msSetError(MS_IMGERR, "failed to get image buffer", "write()");
@@ -347,7 +365,7 @@
                 
             noerr = PyObject_CallMethod(file, "write", "s#", imgbuffer,
                                         imgsize);
-            gdFree(imgbuffer);
+            free(imgbuffer);
             if (noerr == NULL)
                 return MS_FAILURE;
             else
@@ -364,14 +382,14 @@
         unsigned char *imgbytes;
         PyObject *imgstring; 
 
-        imgbytes = msSaveImageBufferGD(self, &size, self->format);
+        imgbytes = msSaveImageBuffer(self, &size, self->format);
         if (size == 0)
         {
             msSetError(MS_IMGERR, "failed to get image buffer", "saveToString()");
             return NULL;
         }
         imgstring = PyString_FromStringAndSize((const char*) imgbytes, size); 
-        gdFree(imgbytes);
+        free(imgbytes);
         return imgstring;
     }
 

Modified: sandbox/mapserver6/mapscript/python/pygdioctx/pygdioctx.c
===================================================================
--- sandbox/mapserver6/mapscript/python/pygdioctx/pygdioctx.c	2010-09-13 19:41:06 UTC (rev 10505)
+++ sandbox/mapserver6/mapscript/python/pygdioctx/pygdioctx.c	2010-09-17 15:44:04 UTC (rev 10506)
@@ -136,7 +136,7 @@
  * ======================================================================== */
 
 imageObj *createImageObjFromPyFile(PyObject *file, const char *driver)
-    {
+{
     imageObj *image=NULL;
     struct PyFileIfaceObj_gdIOCtx *pctx;
 
@@ -155,7 +155,7 @@
     else
     {
         pctx = alloc_PyFileIfaceObj_IOCtx(file);
-        image = msImageLoadGDCtx((gdIOCtx *) pctx, driver);
+        //image = msImageLoadGDCtx((gdIOCtx *) pctx, driver);
         free_PyFileIfaceObj_IOCtx(pctx);
         return image;
     }

Modified: sandbox/mapserver6/mapscript/swiginc/image.i
===================================================================
--- sandbox/mapserver6/mapscript/swiginc/image.i	2010-09-13 19:41:06 UTC (rev 10505)
+++ sandbox/mapserver6/mapscript/swiginc/image.i	2010-09-17 15:44:04 UTC (rev 10506)
@@ -35,14 +35,14 @@
      * instead use the one in python/pymodule.i. */
 #ifndef SWIGPYTHON
     imageObj(int width, int height, outputFormatObj *input_format=NULL,
-             const char *file=NULL)
+             const char *file=NULL,
+             double resolution=MS_DEFAULT_RESOLUTION, double defresolution=MS_DEFAULT_RESOLUTION)
     {
         imageObj *image=NULL;
         outputFormatObj *format;
+        rendererVTableObj *renderer = NULL;
+        rasterBufferObj *rb = NULL;
 
-        if (file) {
-            return (imageObj *) msImageLoadGD(file);
-        }
         if (input_format) {
             format = input_format;
         }
@@ -54,13 +54,37 @@
                 format = msCreateDefaultOutputFormat(NULL, "GD/JPEG");
             if (format == NULL)
                 format = msCreateDefaultOutputFormat(NULL, "GD/WBMP");
+
+            if (format)
+                msInitializeRendererVTable(format);
         }
         if (format == NULL) {
             msSetError(MS_IMGERR, "Could not create output format",
                        "imageObj()");
             return NULL;
         }
-        image = msImageCreate(width, height, format, NULL, NULL, NULL);
+
+        if (file) {
+            
+            renderer = format->vtable;
+            rb = (rasterBufferObj*) malloc(sizeof(rasterBufferObj));
+            if (!rb) {
+                msSetError(MS_MEMERR, NULL, "imageObj()");
+                return NULL;
+            }
+            if ( (renderer->loadImageFromFile(PyString_AsString(arg1), rb)) == MS_FAILURE)
+                return NULL;
+
+            image = msImageCreate(rb->width, rb->height, format, NULL, NULL, 
+                                  resolution, defresolution, NULL);
+            renderer->mergeRasterBuffer(image, rb, 1.0, 0, 0, 0, 0, rb->width, rb->height);
+
+            msFreeRasterBuffer(rb);
+
+            return image;
+        }
+
+        image = msImageCreate(width, height, format, NULL, NULL, resolution, defresolution, NULL);
         return image;
     }
 #endif
@@ -86,26 +110,20 @@
 #ifndef SWIGPYTHON
     int write( FILE *file=NULL )
     {
-        gdIOCtx *ctx=NULL;
         int retval=MS_FAILURE;
-        
-        if ( MS_DRIVER_GD(self->format) )
+        rendererVTableObj *renderer = NULL;
+
+        if (MS_RENDERER_PLUGIN(self->format))
         {
             if (file)
             {
-                /* gdNewFileCtx is a semi-documented function from 
-                   gd_io_file.c */
-                ctx = msNewGDFileCtx(file);
+                renderer = self->format->vtable;
+                retval = renderer->saveImage(self, file, self->format);
             }
-            else /* create a gdIOCtx interface to stdout */
+            else
             {
-                ctx = msNewGDFileCtx(stdout);
+                retval = msSaveImage(NULL, self, NULL);
             }
-            
-            /* we wrap msSaveImageGDCtx in the same way that 
-               gdImageJpeg() wraps gdImageJpegCtx()  (bug 1047). */
-            retval = msSaveImageGDCtx(self, ctx, self->format);
-            ctx->gd_free(ctx);
         }
         else
         {

Modified: sandbox/mapserver6/mapscript/swiginc/outputformat.i
===================================================================
--- sandbox/mapserver6/mapscript/swiginc/outputformat.i	2010-09-13 19:41:06 UTC (rev 10505)
+++ sandbox/mapserver6/mapscript/swiginc/outputformat.i	2010-09-17 15:44:04 UTC (rev 10506)
@@ -47,6 +47,8 @@
             return NULL;
         }
         
+        msInitializeRendererVTable(format);
+
         /* Else, continue */
         format->refcount++;
 	format->inmapfile = MS_TRUE;

Modified: sandbox/mapserver6/mapscript/swiginc/shapefile.i
===================================================================
--- sandbox/mapserver6/mapscript/swiginc/shapefile.i	2010-09-13 19:41:06 UTC (rev 10505)
+++ sandbox/mapserver6/mapscript/swiginc/shapefile.i	2010-09-17 15:44:04 UTC (rev 10506)
@@ -104,7 +104,7 @@
 
         msFreeShape(shape); /* frees all lines and points before re-filling */
         msSHPReadShape(self->hSHP, i, shape);
-        msTransformShapeToPixel(shape, map->extent, map->cellsize);
+        msTransformShapeToPixel(shape, map->extent, map->cellsize, MS_SIMPLIFY_DEFAULT);
 
         return MS_SUCCESS;
     }

Modified: sandbox/mapserver6/mapscript/swiginc/symbol.i
===================================================================
--- sandbox/mapserver6/mapscript/swiginc/symbol.i	2010-09-13 19:41:06 UTC (rev 10505)
+++ sandbox/mapserver6/mapscript/swiginc/symbol.i	2010-09-17 15:44:04 UTC (rev 10506)
@@ -100,14 +100,76 @@
     }
 
     %newobject getImage;
-    imageObj *getImage(outputFormatObj *format)
+    imageObj *getImage(outputFormatObj *input_format)
     {
-        return msSymbolGetImageGD(self, format);
+        imageObj *image;
+        outputFormatObj *format = NULL;
+        rendererVTableObj *renderer = NULL;
+
+        if (self->type != MS_SYMBOL_PIXMAP)
+        {
+            msSetError(MS_SYMERR, "Can't return image from non-pixmap symbol",
+                       "getImage()");
+            return NULL;
+        }
+    
+        if (input_format)
+        {
+            format = input_format;
+        }
+        else 
+        {
+            format = msCreateDefaultOutputFormat(NULL, "GD/GIF");
+            if (format == NULL)
+                format = msCreateDefaultOutputFormat(NULL, "GD/PNG");
+            if (format == NULL)
+                format = msCreateDefaultOutputFormat(NULL, "GD/JPEG");
+            if (format == NULL)
+                format = msCreateDefaultOutputFormat(NULL, "GD/WBMP");
+
+            if (format)
+                msInitializeRendererVTable(format);
+        }
+        
+        if (format == NULL) 
+        {
+            msSetError(MS_IMGERR, "Could not create output format",
+                       "getImage()");
+            return NULL;
+        }
+
+        renderer = format->vtable;
+        msPreloadImageSymbol(renderer, self);
+        if (self->pixmap_buffer) 
+        {
+            image = msImageCreate(self->pixmap_buffer->width, self->pixmap_buffer->height, format, NULL, NULL,
+                                  MS_DEFAULT_RESOLUTION, MS_DEFAULT_RESOLUTION, NULL);
+            renderer->mergeRasterBuffer(image, self->pixmap_buffer, 1.0, 0, 0, 0, 0, 
+                                        self->pixmap_buffer->width, self->pixmap_buffer->height);
+        }
+
+        return image;
     }
 
     int setImage(imageObj *image)
     {
-        return msSymbolSetImageGD(self, image);
+        rendererVTableObj *renderer = NULL;
+        
+        renderer = image->format->vtable;
+        
+        if (self->pixmap_buffer)
+            msFreeRasterBuffer(self->pixmap_buffer);
+        
+        self->pixmap_buffer = (rasterBufferObj*)malloc(sizeof(rasterBufferObj));
+        if (!self->pixmap_buffer) {
+            msSetError(MS_MEMERR, NULL, "setImage()");
+            return MS_FAILURE;
+        }
+        renderer->initializeRasterBuffer(self->pixmap_buffer, image->width, image->height, image->format->imagemode);
+        self->type = MS_SYMBOL_PIXMAP;
+        renderer->getRasterBufferCopy(image, self->pixmap_buffer);
+
+        return MS_SUCCESS;
     }
 
 }



More information about the mapserver-commits mailing list