[mapserver-commits] r10270 - sandbox/mapserver6
svn at osgeo.org
svn at osgeo.org
Thu Jul 1 06:16:17 EDT 2010
Author: tbonfort
Date: 2010-07-01 10:16:17 +0000 (Thu, 01 Jul 2010)
New Revision: 10270
Modified:
sandbox/mapserver6/mapagg.h
sandbox/mapserver6/mapagg2.cpp
sandbox/mapserver6/mapimageio.c
sandbox/mapserver6/mapoutput.c
sandbox/mapserver6/maprendering.c
sandbox/mapserver6/maputil.c
Log:
memory allocation cleanups
Modified: sandbox/mapserver6/mapagg.h
===================================================================
--- sandbox/mapserver6/mapagg.h 2010-07-01 03:49:04 UTC (rev 10269)
+++ sandbox/mapserver6/mapagg.h 2010-07-01 10:16:17 UTC (rev 10270)
@@ -27,126 +27,8 @@
* DEALINGS IN THE SOFTWARE.
******************************************************************************/
-#include "renderers/agg/include/agg_array.h"
#include "renderers/agg/include/agg_rendering_buffer.h"
-
-template<class T> class mapserv_row_ptr_cache
-{
-public:
- typedef mapserver::const_row_info<T> row_data;
-
- mapserv_row_ptr_cache() :
- m_buf(0),
- m_rows(),
- m_width(0),
- m_height(0),
- m_stride(0)
- {
- }
-
- mapserv_row_ptr_cache( const gdImagePtr pImg ) :
- m_buf(0),
- m_rows(),
- m_width(0),
- m_height(0),
- m_stride(0)
- {
- attach( pImg->tpixels, pImg->sx, pImg->sy, pImg->sx * sizeof( T ) );
- }
-
- void attach( T **ppRows, unsigned width, unsigned height, int stride )
- {
- m_width = width;
- m_height = height;
- m_stride = stride;
-
- if( height > m_rows.size() )
- m_rows.resize( height );
-
- T** rows = &m_rows[0];
- int iRowIndex = 0;
-
- while( height--)
- {
- *rows = ppRows[iRowIndex];
- rows++;
- iRowIndex++;
- }
- }
-
- /*-------------------------------------------------------------------*/
- AGG_INLINE T* buf() { return m_buf; }
- AGG_INLINE const T* buf() const { return m_buf; }
- AGG_INLINE unsigned width() const { return m_width; }
- AGG_INLINE unsigned height() const { return m_height; }
- AGG_INLINE int stride() const { return m_stride; }
- AGG_INLINE unsigned stride_abs() const
- {
- return (m_stride < 0) ? unsigned(-m_stride) : unsigned(m_stride);
- }
-
- /*-------------------------------------------------------------------*/
- AGG_INLINE T* row_ptr(int, int y, unsigned)
- {
- return m_rows[y];
- }
- AGG_INLINE T* row_ptr(int y) { return m_rows[y]; }
- AGG_INLINE const T* row_ptr(int y) const { return m_rows[y]; }
- AGG_INLINE row_data row (int y) const
- {
- return row_data(0, m_width-1, m_rows[y]);
- }
-
- /*-------------------------------------------------------------------*/
- T const* const* rows() const { return &m_rows[0]; }
-
- /*-------------------------------------------------------------------*/
- template<class RenBuf>
- void copy_from(const RenBuf& src)
- {
- unsigned h = height();
- if(src.height() < h) h = src.height();
-
- unsigned l = stride_abs();
- if(src.stride_abs() < l) l = src.stride_abs();
-
- l *= sizeof(T);
-
- unsigned y;
- unsigned w = width();
- for (y = 0; y < h; y++)
- {
- memcpy(row_ptr(0, y, w), src.row_ptr(y), l);
- }
- }
-
- /*-------------------------------------------------------------------*/
- void clear(T value)
- {
- unsigned y;
- unsigned w = width();
- unsigned stride = stride_abs();
- for(y = 0; y < height(); y++)
- {
- T* p = row_ptr(0, y, w);
- unsigned x;
- for(x = 0; x < stride; x++)
- {
- *p++ = value;
- }
- }
- }
-
- private:
- /*-------------------------------------------------------------------*/
- T* m_buf; /* Pointer to rendering buffer */
- mapserver::pod_array<T*> m_rows; /* Pointers to each row of the buffer */
- unsigned m_width; /* Width in pixels */
- unsigned m_height; /* Height in pixels */
- int m_stride; /* Number of bytes per row. Can be < 0 */
-};
-
/*
* interface to a shapeObj representing lines, providing the functions
* needed by the agg rasterizer. treats shapeObjs with multiple linestrings.
Modified: sandbox/mapserver6/mapagg2.cpp
===================================================================
--- sandbox/mapserver6/mapagg2.cpp 2010-07-01 03:49:04 UTC (rev 10269)
+++ sandbox/mapserver6/mapagg2.cpp 2010-07-01 10:16:17 UTC (rev 10270)
@@ -438,7 +438,7 @@
rasterBufferObj *pixmap = symbol->pixmap_buffer;
assert(pixmap->type == MS_BUFFER_BYTE_RGBA);
if(!symbol->renderer_cache) {
- band_type *data = new band_type[pixmap->width*pixmap->height*4];
+ band_type *data = (band_type*)malloc(pixmap->width*pixmap->height*4*sizeof(band_type));
memcpy(data,pixmap->data.rgba.pixels,pixmap->width*pixmap->height*4);
rendering_buffer *b = new rendering_buffer(data, pixmap->width, pixmap->height, (int)pixmap->width*4);
symbol->renderer_cache = (void*)b;
@@ -658,7 +658,7 @@
image = (imageObj *) calloc(1, sizeof (imageObj));
AGG2Renderer *r = new AGG2Renderer();
- r->buffer = new band_type[width * height * 4];
+ r->buffer = (band_type*)malloc(width * height * 4 * sizeof(band_type));
r->m_rendering_buffer.attach(r->buffer, width, height, width * 4);
r->m_pixel_format.attach(r->m_rendering_buffer);
r->m_renderer_base.attach(r->m_pixel_format);
@@ -759,7 +759,7 @@
int agg2FreeImage(imageObj * image) {
AGG2Renderer *r = agg2GetRenderer(image);
- delete[] r->buffer;
+ free(r->buffer);
delete r;
image->img.plugin = NULL;
return MS_SUCCESS;
@@ -770,6 +770,16 @@
}
int agg2FreeSymbol(symbolObj * symbol) {
+ switch(symbol->type) {
+ case MS_SYMBOL_PIXMAP:
+ if(symbol->renderer_cache) {
+ rendering_buffer *rb = (rendering_buffer*)symbol->renderer_cache;
+ free(rb->buf());
+ delete (rendering_buffer*)symbol->renderer_cache;
+ }
+ symbol->renderer_cache = NULL;
+ break;
+ }
return MS_SUCCESS;
}
Modified: sandbox/mapserver6/mapimageio.c
===================================================================
--- sandbox/mapserver6/mapimageio.c 2010-07-01 03:49:04 UTC (rev 10269)
+++ sandbox/mapserver6/mapimageio.c 2010-07-01 10:16:17 UTC (rev 10270)
@@ -737,6 +737,7 @@
int msLoadMSRasterBufferFromFile(char *path, rasterBufferObj *rb) {
FILE *stream;
unsigned char signature[8];
+ int ret = MS_FAILURE;
stream = fopen(path,"rb");
if(!stream) {
msSetError(MS_MISCERR, "unable to open file %s for reading", "msLoadRasterBuffer()", path);
@@ -745,7 +746,7 @@
fread(signature,1,8,stream);
rewind(stream);
if(png_check_sig(signature,8)) {
- return readPNG(stream,rb);
+ ret = readPNG(stream,rb);
#if 0
} else if () {//GIF loading
#endif
@@ -753,7 +754,8 @@
msSetError(MS_MISCERR,"unsupported pixmap format","readImage()");
return MS_FAILURE;
}
- return MS_FAILURE;
+ fclose(stream);
+ return ret;
}
int saveGdImage(gdImagePtr ip, FILE *fp, outputFormatObj *format) {
Modified: sandbox/mapserver6/mapoutput.c
===================================================================
--- sandbox/mapserver6/mapoutput.c 2010-07-01 03:49:04 UTC (rev 10269)
+++ sandbox/mapserver6/mapoutput.c 2010-07-01 10:16:17 UTC (rev 10270)
@@ -1019,9 +1019,7 @@
int msInitializeRendererVTable(outputFormatObj *format) {
assert(format);
if(format->vtable) {
- /* TODO?: clean up caches before switch
- msFreeRendererVTable(format->vtable); */
- msFree(format->vtable);
+ return MS_SUCCESS;
}
format->vtable = (rendererVTableObj*)malloc(sizeof(rendererVTableObj));
Modified: sandbox/mapserver6/maprendering.c
===================================================================
--- sandbox/mapserver6/maprendering.c 2010-07-01 03:49:04 UTC (rev 10269)
+++ sandbox/mapserver6/maprendering.c 2010-07-01 10:16:17 UTC (rev 10270)
@@ -156,10 +156,6 @@
MS_COPYCOLOR(&dst->backgroundcolor,&src->backgroundcolor);
}
-void freeTileCache(tileCacheObj *cache) {
-
-}
-
/* add a cached tile to the current image's cache */
tileCacheObj *addTileCache(imageObj *img,
imageObj *tile, symbolObj *symbol, symbolStyleObj *style, int width, int height) {
Modified: sandbox/mapserver6/maputil.c
===================================================================
--- sandbox/mapserver6/maputil.c 2010-07-01 03:49:04 UTC (rev 10269)
+++ sandbox/mapserver6/maputil.c 2010-07-01 10:16:17 UTC (rev 10270)
@@ -770,19 +770,17 @@
{
if (image)
{
- if(MS_RENDERER_PLUGIN(image->format)) {
- rendererVTableObj *renderer = image->format->vtable;
- if(renderer->supports_imagecache) {
- tileCacheObj *next,*cur = image->tilecache;
- while(cur) {
- renderer->freeImage(cur->image);
- next = cur->next;
- free(cur);
- cur = next;
- }
- image->ntiles = 0;
- }
- renderer->freeImage(image);
+ if(MS_RENDERER_PLUGIN(image->format)) {
+ rendererVTableObj *renderer = image->format->vtable;
+ tileCacheObj *next,*cur = image->tilecache;
+ while(cur) {
+ msFreeImage(cur->image);
+ next = cur->next;
+ free(cur);
+ cur = next;
+ }
+ image->ntiles = 0;
+ renderer->freeImage(image);
} else if( MS_RENDERER_IMAGEMAP(image->format) )
msFreeImageIM(image);
else if( MS_RENDERER_RAWDATA(image->format) )
More information about the mapserver-commits
mailing list