[mapserver-commits] r10096 - trunk/mapserver
svn at osgeo.org
svn at osgeo.org
Sat Apr 10 23:40:47 EDT 2010
Author: warmerdam
Date: 2010-04-10 23:40:46 -0400 (Sat, 10 Apr 2010)
New Revision: 10096
Modified:
trunk/mapserver/HISTORY.TXT
trunk/mapserver/mapgd.c
Log:
try to avoid color exhaustion with 24bit keyimg in 8bit map (#1594)
Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT 2010-04-11 02:32:21 UTC (rev 10095)
+++ trunk/mapserver/HISTORY.TXT 2010-04-11 03:40:46 UTC (rev 10096)
@@ -14,6 +14,9 @@
Current Version (SVN trunk):
----------------------------
+- Try to avoid exhausting the color table when rendering 24bit key
+ images into 8bit results (#1594)
+
- Avoid crash, and ensure error report when loading keyimage fails (#1594)
- Improve the handling of simple string comparisons for raster classified
Modified: trunk/mapserver/mapgd.c
===================================================================
--- trunk/mapserver/mapgd.c 2010-04-11 02:32:21 UTC (rev 10095)
+++ trunk/mapserver/mapgd.c 2010-04-11 03:40:46 UTC (rev 10096)
@@ -34,6 +34,7 @@
#include "mapserver.h"
#include "mapthread.h"
#include <time.h>
+#include <assert.h>
#ifdef _WIN32
#include <fcntl.h>
@@ -46,6 +47,34 @@
static unsigned char JPEGsig[3] = {255, 216, 255}; /* FF D8 FF hex */
/*
+ * Create a stratafyied (reduced number of colors) image from a 24bit image.
+ * This is mostly useful when copying into an 8bit image to try and avoid
+ * unnecessary color table exhaustion.
+ */
+
+static gdImagePtr msColorStratefyImageGD( gdImagePtr src_image )
+
+{
+ gdImagePtr dst_image = gdImageCreateTrueColor(src_image->sx,src_image->sy);
+ int ix,iy;
+
+ assert( src_image->trueColor );
+
+ gdImageCopy( dst_image, src_image,
+ 0, 0, 0, 0, src_image->sx, src_image->sy );
+
+ for( iy = 0; iy < dst_image->sy; iy++ )
+ {
+ for( ix = 0; ix < dst_image->sx; ix++ )
+ {
+ dst_image->tpixels[iy][ix] &= 0xfff0f0f0;
+ }
+ }
+
+ return dst_image;
+}
+
+/*
* This function is simlar to msImageTruetypePolyline. It renders pixmap symbols
* along a line. Uses the GAP parameter for distances betewwn symbols.
*/
@@ -1476,6 +1505,7 @@
int j, k;
gdPoint oldpnt,newpnt;
gdPoint mPoints[MS_MAXVECTORPOINTS];
+ gdImagePtr strat_img=NULL;
char *error=NULL;
int fc, bc, oc;
@@ -1569,16 +1599,24 @@
symbol = msRotateSymbol(symbol, style->angle);
}
+ if( !img->img.gd->trueColor && symbol->img->trueColor )
+ strat_img = msColorStratefyImageGD( symbol->img );
+ else
+ strat_img = symbol->img;
+
if(d == 1) { /* don't scale */
offset_x = MS_NINT(p->x - .5*symbol->img->sx + ox);
offset_y = MS_NINT(p->y - .5*symbol->img->sy + oy);
- gdImageCopy(img->img.gd, symbol->img, offset_x, offset_y, 0, 0, symbol->img->sx, symbol->img->sy);
+ gdImageCopy(img->img.gd, strat_img, offset_x, offset_y, 0, 0, symbol->img->sx, symbol->img->sy);
} else {
offset_x = MS_NINT(p->x - .5*symbol->img->sx*d + ox);
offset_y = MS_NINT(p->y - .5*symbol->img->sy*d + oy);
- gdImageCopyResampled(img->img.gd, symbol->img, offset_x, offset_y, 0, 0, (int)(symbol->img->sx*d), (int)(symbol->img->sy*d), symbol->img->sx, symbol->img->sy);
+ gdImageCopyResampled(img->img.gd, strat_img, offset_x, offset_y, 0, 0, (int)(symbol->img->sx*d), (int)(symbol->img->sy*d), symbol->img->sx, symbol->img->sy);
}
+ if( strat_img != symbol->img )
+ gdImageDestroy( strat_img );
+
if(bRotated) {
msFreeSymbol(symbol); /* clean up */
msFree(symbol);
More information about the mapserver-commits
mailing list