From 3aab436e6116c84994da70274348bdd723bde185 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 21 Mar 2021 14:43:28 +0100 Subject: [PATCH] mapagg: add missing initializeation of member variables and a few C++11 ification --- mapagg.cpp | 58 +++++++++++++++++++++--------------------------------- mapagg.h | 7 ++++--- 2 files changed, 26 insertions(+), 39 deletions(-) diff --git a/mapagg.cpp b/mapagg.cpp index 91863dcdc9..b38865d8a3 100755 --- a/mapagg.cpp +++ b/mapagg.cpp @@ -67,6 +67,10 @@ #include #endif +#include +#include +#include + typedef mapserver::order_bgra band_order; #define AGG_LINESPACE 1.33 @@ -106,27 +110,7 @@ class aggRendererCache class AGG2Renderer { public: - - AGG2Renderer() - { - stroke = NULL; - dash = NULL; - stroke_dash = NULL; - } - - ~AGG2Renderer() { - if(stroke) { - delete stroke; - } - if(dash) { - delete dash; - } - if(stroke_dash) { - delete stroke_dash; - } - } - - band_type* buffer; + std::vector buffer{}; rendering_buffer m_rendering_buffer; pixel_format m_pixel_format; compop_pixel_format m_compop_pixel_format; @@ -140,11 +124,11 @@ class AGG2Renderer than the perimeter, in number of pixels*/ mapserver::scanline_u8 sl_line; /*unpacked scanlines, works faster if the area is roughly equal to the perimeter, in number of pixels*/ - bool use_alpha; - mapserver::conv_stroke *stroke; - mapserver::conv_dash *dash; - mapserver::conv_stroke > *stroke_dash; - double default_gamma; + bool use_alpha = false; + std::unique_ptr> stroke{}; + std::unique_ptr> dash{}; + std::unique_ptr >> stroke_dash{}; + double default_gamma = 0.0; mapserver::gamma_linear gamma_function; }; @@ -198,7 +182,7 @@ int agg2RenderLine(imageObj *img, shapeObj *p, strokeStyleObj *style) if (style->patternlength <= 0) { if(!r->stroke) { - r->stroke = new mapserver::conv_stroke(lines); + r->stroke.reset(new mapserver::conv_stroke(lines)); } else { r->stroke->attach(lines); } @@ -212,14 +196,14 @@ int agg2RenderLine(imageObj *img, shapeObj *p, strokeStyleObj *style) r->m_rasterizer_aa.add_path(*r->stroke); } else { if(!r->dash) { - r->dash = new mapserver::conv_dash(lines); + r->dash.reset(new mapserver::conv_dash(lines)); } else { r->dash->remove_all_dashes(); r->dash->dash_start(0.0); r->dash->attach(lines); } if(!r->stroke_dash) { - r->stroke_dash = new mapserver::conv_stroke > (*r->dash); + r->stroke_dash.reset(new mapserver::conv_stroke > (*r->dash)); } else { r->stroke_dash->attach(*r->dash); } @@ -752,7 +736,7 @@ int aggGetRasterBufferHandle(imageObj *img, rasterBufferObj * rb) { AGG2Renderer *r = AGG_RENDERER(img); rb->type =MS_BUFFER_BYTE_RGBA; - rb->data.rgba.pixels = r->buffer; + rb->data.rgba.pixels = r->buffer.data(); rb->data.rgba.row_step = r->m_rendering_buffer.stride(); rb->data.rgba.pixel_step = 4; rb->width = r->m_rendering_buffer.width(); @@ -772,7 +756,7 @@ int aggGetRasterBufferCopy(imageObj *img, rasterBufferObj *rb) AGG2Renderer *r = AGG_RENDERER(img); aggInitializeRasterBuffer(rb, img->width, img->height, MS_IMAGEMODE_RGBA); int nBytes = r->m_rendering_buffer.stride()*r->m_rendering_buffer.height(); - memcpy(rb->data.rgba.pixels,r->buffer, nBytes); + memcpy(rb->data.rgba.pixels,r->buffer.data(), nBytes); return MS_SUCCESS; } @@ -814,15 +798,18 @@ imageObj *agg2CreateImage(int width, int height, outputFormatObj *format, colorO return NULL; } - r->buffer = (band_type*)malloc(bufSize); - if (r->buffer == NULL) { + try + { + r->buffer.resize(bufSize / sizeof(band_type)); + } + catch( const std::bad_alloc& ) { msSetError(MS_MEMERR, "%s: %d: Out of memory allocating " AGG_INT64U_FRMT " bytes.\n", "agg2CreateImage()", __FILE__, __LINE__, bufSize64); free(image); delete r; return NULL; } - r->m_rendering_buffer.attach(r->buffer, width, height, width * 4); + r->m_rendering_buffer.attach(r->buffer.data(), width, height, width * 4); r->m_pixel_format.attach(r->m_rendering_buffer); r->m_compop_pixel_format.attach(r->m_rendering_buffer); r->m_renderer_base.attach(r->m_pixel_format); @@ -883,7 +870,6 @@ int agg2CloseNewLayer(imageObj *img, mapObj *map, layerObj *layer) int agg2FreeImage(imageObj * image) { AGG2Renderer *r = AGG_RENDERER(image); - free(r->buffer); delete r; image->img.plugin = NULL; return MS_SUCCESS; @@ -1278,7 +1264,7 @@ int aggCompositeRasterBuffer(imageObj *dest, rasterBufferObj *overlay, Compositi pixman_image_t *si = pixman_image_create_bits(PIXMAN_a8r8g8b8,overlay->width,overlay->height, (uint32_t*)overlay->data.rgba.pixels,overlay->data.rgba.row_step); pixman_image_t *bi = pixman_image_create_bits(PIXMAN_a8r8g8b8,dest->width,dest->height, - (uint32_t*)r->buffer,dest->width*4); + reinterpret_cast(&(r->buffer[0])),dest->width*4); pixman_image_t *alpha_mask_i=NULL, *alpha_mask_i_ptr; pixman_image_set_filter(si,PIXMAN_FILTER_NEAREST, NULL, 0); unsigned char *alpha_mask = NULL; diff --git a/mapagg.h b/mapagg.h index 41248b7fd7..0d5f9ee320 100644 --- a/mapagg.h +++ b/mapagg.h @@ -88,7 +88,7 @@ class line_adaptor class polygon_adaptor { public: - polygon_adaptor(shapeObj *shape):s(shape),m_stop(false) { + polygon_adaptor(shapeObj *shape):s(shape) { m_line=s->line; /*first lines*/ m_point=m_line->point; /*first vertex of first line*/ m_lend=&(s->line[s->numlines]); /*pointer to after last line*/ @@ -140,12 +140,13 @@ class polygon_adaptor } protected: shapeObj *s; - double ox,oy; + double ox = 0.0; + double oy = 0.0; lineObj *m_line, /*pointer to current line*/ *m_lend; /*pointer to after last line of the shape*/ pointObj *m_point, /*pointer to current vertex*/ *m_pend; /*pointer to after last vertex of current line*/ - bool m_stop; /*should next call return stop command*/ + bool m_stop = false; /*should next call return stop command*/ }; mapserver::path_storage imageVectorSymbol(symbolObj *);