Skip to content

Commit

Permalink
Collection of backports from the 8.0 development work. (#6818)
Browse files Browse the repository at this point in the history
Co-authored-by: Landry Breuil <landryb@users.noreply.github.com>
  • Loading branch information
sdlime and landryb authored Feb 5, 2023
1 parent d1c4fa6 commit 3891125
Show file tree
Hide file tree
Showing 8 changed files with 399 additions and 258 deletions.
87 changes: 46 additions & 41 deletions mapagg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,52 +812,57 @@ imageObj *agg2CreateImage(int width, int height, outputFormatObj *format, colorO
"AGG2 driver only supports RGB or RGBA pixel models.", "agg2CreateImage()");
return image;
}
image = (imageObj *) calloc(1, sizeof (imageObj));
MS_CHECK_ALLOC(image, sizeof (imageObj), NULL);
AGG2Renderer *r = new AGG2Renderer();
if (width > 0 && height > 0) {
image = (imageObj *) calloc(1, sizeof (imageObj));
MS_CHECK_ALLOC(image, sizeof (imageObj), NULL);
AGG2Renderer *r = new AGG2Renderer();

/* Compute size on 64bit and check that it is compatible of the platform size_t */
AGG_INT64U bufSize64 = (AGG_INT64U)width * height * 4 * sizeof(band_type);
size_t bufSize = (size_t)bufSize64;
if( (AGG_INT64U)bufSize != bufSize64 ) {
msSetError(MS_MEMERR, "%s: %d: Out of memory allocating " AGG_INT64U_FRMT " bytes.\n", "agg2CreateImage()",
__FILE__, __LINE__, bufSize64);
free(image);
delete r;
return NULL;
}
/* Compute size on 64bit and check that it is compatible of the platform size_t */
AGG_INT64U bufSize64 = (AGG_INT64U)width * height * 4 * sizeof(band_type);
size_t bufSize = (size_t)bufSize64;
if( (AGG_INT64U)bufSize != bufSize64 ) {
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->buffer = (band_type*)malloc(bufSize);
if (r->buffer == NULL) {
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_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);
r->m_compop_renderer_base.attach(r->m_compop_pixel_format);
r->m_renderer_scanline.attach(r->m_renderer_base);
r->default_gamma = atof(msGetOutputFormatOption( format, "GAMMA", "0.75" ));
if(r->default_gamma <= 0.0 || r->default_gamma >= 1.0) {
r->default_gamma = 0.75;
}
r->gamma_function.set(0,r->default_gamma);
r->m_rasterizer_aa_gamma.gamma(r->gamma_function);
if( bg && !format->transparent )
r->m_renderer_base.clear(aggColor(bg));
else
r->m_renderer_base.clear(AGG_NO_COLOR);
r->buffer = (band_type*)malloc(bufSize);
if (r->buffer == NULL) {
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_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);
r->m_compop_renderer_base.attach(r->m_compop_pixel_format);
r->m_renderer_scanline.attach(r->m_renderer_base);
r->default_gamma = atof(msGetOutputFormatOption( format, "GAMMA", "0.75" ));
if(r->default_gamma <= 0.0 || r->default_gamma >= 1.0) {
r->default_gamma = 0.75;
}
r->gamma_function.set(0,r->default_gamma);
r->m_rasterizer_aa_gamma.gamma(r->gamma_function);
if( bg && !format->transparent )
r->m_renderer_base.clear(aggColor(bg));
else
r->m_renderer_base.clear(AGG_NO_COLOR);

if (!bg || format->transparent || format->imagemode == MS_IMAGEMODE_RGBA ) {
r->use_alpha = true;
if (!bg || format->transparent || format->imagemode == MS_IMAGEMODE_RGBA ) {
r->use_alpha = true;
} else {
r->use_alpha = false;
}
image->img.plugin = (void*) r;
} else {
r->use_alpha = false;
msSetError(MS_RENDERERERR, "Cannot create AGG2 image of size %dx%d.",
"agg2CreateImage()", width, height);
}
image->img.plugin = (void*) r;

return image;
}
Expand Down
4 changes: 2 additions & 2 deletions mapdraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ imageObj *msDrawMap(mapObj *map, int querymap)
if(map->debug >= MS_DEBUGLEVEL_TUNING) msGettimeofday(&mapstarttime, NULL);

if(querymap) { /* use queryMapObj image dimensions */
if(map->querymap.width != -1) map->width = map->querymap.width;
if(map->querymap.height != -1) map->height = map->querymap.height;
if(map->querymap.width > 0 && map->querymap.width <= map->maxsize) map->width = map->querymap.width;
if(map->querymap.height > 0 && map->querymap.height <= map->maxsize) map->height = map->querymap.height;
}

msApplyMapConfigOptions(map);
Expand Down
1 change: 1 addition & 0 deletions maperror.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ void msResetErrorList()

ms_error->next = NULL;
ms_error->code = MS_NOERR;
ms_error->isreported = MS_FALSE;
ms_error->routine[0] = '\0';
ms_error->message[0] = '\0';
ms_error->errorcount = 0;
Expand Down
Loading

0 comments on commit 3891125

Please sign in to comment.