[mapserver-commits] r10233 - sandbox/mapserver6

svn at osgeo.org svn at osgeo.org
Fri Jun 18 03:01:12 EDT 2010


Author: tbonfort
Date: 2010-06-18 07:01:11 +0000 (Fri, 18 Jun 2010)
New Revision: 10233

Modified:
   sandbox/mapserver6/mapgd2.c
   sandbox/mapserver6/mapimageio.c
   sandbox/mapserver6/mapserver.h
Log:
gd pixmap symbols


Modified: sandbox/mapserver6/mapgd2.c
===================================================================
--- sandbox/mapserver6/mapgd2.c	2010-06-17 15:12:05 UTC (rev 10232)
+++ sandbox/mapserver6/mapgd2.c	2010-06-18 07:01:11 UTC (rev 10233)
@@ -481,8 +481,77 @@
   return MS_SUCCESS;
 }
 
+gdImagePtr rotatePixmapGD(gdImagePtr img, double angle_rad) {
+   gdImagePtr rimg = NULL;
+   double cos_a, sin_a;
+   double x1 = 0.0, y1 = 0.0; /* destination rectangle */
+   double x2 = 0.0, y2 = 0.0;
+   double x3 = 0.0, y3 = 0.0;
+   double x4 = 0.0, y4 = 0.0;
+
+   long minx, miny, maxx, maxy;
+
+   int width=0, height=0;
+   /* int color; */
+
+   sin_a = sin(angle_rad);
+   cos_a = cos(angle_rad);
+
+   /* compute distination rectangle (x1,y1 is known) */
+   x1 = 0 ; y1 = 0 ;
+   x2 = img->sy * sin_a;
+   y2 = -img->sy * cos_a;
+   x3 = (img->sx * cos_a) + (img->sy * sin_a);
+   y3 = (img->sx * sin_a) - (img->sy * cos_a);
+   x4 = (img->sx * cos_a);
+   y4 = (img->sx * sin_a);
+
+   minx = (long) MS_MIN(x1,MS_MIN(x2,MS_MIN(x3,x4)));
+   miny = (long) MS_MIN(y1,MS_MIN(y2,MS_MIN(y3,y4)));
+   maxx = (long) MS_MAX(x1,MS_MAX(x2,MS_MAX(x3,x4)));
+   maxy = (long) MS_MAX(y1,MS_MAX(y2,MS_MAX(y3,y4)));
+
+   width = (int)ceil(maxx-minx);
+   height = (int)ceil(maxy-miny);
+
+   /* create the new image based on the computed width/height */
+   
+   if (gdImageTrueColor(img)) {
+      rimg = gdImageCreateTrueColor(width, height);
+      gdImageAlphaBlending(rimg, 0);
+      gdImageFilledRectangle(rimg, 0, 0, width, height, gdImageColorAllocateAlpha(rimg, 0, 0, 0, gdAlphaTransparent)); 
+   } else {
+      int tc = gdImageGetTransparent(img);
+      rimg = gdImageCreate(width, height);  
+      if(tc != -1)
+         gdImageColorTransparent(rimg, gdImageColorAllocate(rimg, gdImageRed(img, tc), gdImageGreen(img, tc), gdImageBlue(img, tc)));
+   }
+   if(!rimg) {
+      msSetError(MS_GDERR,"failed to create rotated pixmap","rotatePixmapGD()");
+      return NULL;
+   }
+
+   gdImageCopyRotated (rimg, img, width*0.5, height*0.5, 0, 0, gdImageSX(img), gdImageSY(img), angle_rad*MS_RAD_TO_DEG);
+   return rimg;
+}
+
 int renderPixmapSymbolGD(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style) {
-  return MS_SUCCESS;
+   gdImagePtr ip;
+   if(!(ip = MS_IMAGE_GET_GDIMAGEPTR(img))) return MS_FAILURE;
+   assert(symbol->pixmap_buffer && symbol->pixmap_buffer->type == MS_BUFFER_GD);
+   if(style->scale == 1.0) { /* don't scale */
+      x -= .5*symbol->pixmap_buffer->width;
+      y -= .5*symbol->pixmap_buffer->height;
+      gdImageCopy(ip, symbol->pixmap_buffer->data.gd_img, x, y, 0, 0, symbol->pixmap_buffer->width,symbol->pixmap_buffer->height);
+    } else {
+      x -=  .5*symbol->pixmap_buffer->width*style->scale;
+      y -=  .5*symbol->pixmap_buffer->height*style->scale;
+      gdImageCopyResampled(ip, symbol->pixmap_buffer->data.gd_img, x, y, 0, 0,
+            (int)(symbol->pixmap_buffer->width * style->scale),
+            (int)(symbol->pixmap_buffer->height * style->scale),
+            symbol->pixmap_buffer->width,symbol->pixmap_buffer->height);
+    }
+   return MS_SUCCESS;
 }
 
 int renderTileGD(imageObj *img, imageObj *tile, double x, double y) {
@@ -525,9 +594,8 @@
 
 }
 
-rasterBufferObj* getRasterBufferCopyGD(imageObj *img) {
+int getRasterBufferCopyGD(imageObj *img, rasterBufferObj *rb) {
 	gdImagePtr gdImg = MS_IMAGE_GET_GDIMAGEPTR(img);
-	rasterBufferObj *rb = (rasterBufferObj*)calloc(1,sizeof(rasterBufferObj));
 	rb->type = MS_BUFFER_GD;
 	rb->width = gdImg->sx;
 	rb->height = gdImg->sy;
@@ -537,7 +605,7 @@
 		rb->data.gd_img = gdImageCreate(gdImg->sx,gdImg->sy);
 	}
 	gdImageCopy(gdImg,rb->data.gd_img,0,0,0,0,gdImg->sx,gdImg->sy);
-	return rb;
+	return MS_SUCCESS;
 }
 
 int mergeRasterBufferGD(imageObj *dest, rasterBufferObj *overlay, double opacity, int srcX, int srcY, int dstX, int dstY, int width, int height) {
@@ -628,6 +696,7 @@
   renderer->getRasterBufferHandle = &getRasterBufferHandleGD;
   renderer->getRasterBufferCopy = &getRasterBufferCopyGD;
   renderer->initializeRasterBuffer = initializeRasterBufferGD;
+  renderer->loadImageFromFile = msLoadGDRasterBufferFromFile;
     
   renderer->transformShape = &msTransformShapeToPixel;
   renderer->renderPolygon = &renderPolygonGD;

Modified: sandbox/mapserver6/mapimageio.c
===================================================================
--- sandbox/mapserver6/mapimageio.c	2010-06-17 15:12:05 UTC (rev 10232)
+++ sandbox/mapserver6/mapimageio.c	2010-06-18 07:01:11 UTC (rev 10233)
@@ -387,14 +387,14 @@
 
 static const unsigned char PNGsig[8] = {137, 80, 78, 71, 13, 10, 26, 10}; /* 89 50 4E 47 0D 0A 1A 0A hex */ 
 
-gdImagePtr loadGDImg(char *path) {
+int msLoadGDRasterBufferFromFile(char *path, rasterBufferObj *rb) {
     FILE *stream;
     char bytes[8];
     gdImagePtr img = NULL; 
     stream = fopen(path,"rb");
     if(!stream) {
         msSetError(MS_MISCERR, "unable to open file %s for reading", "loadGDImg()", path);
-        return NULL;
+        return MS_FAILURE;
     }
     fread(bytes,8,1,stream); /* read some bytes to try and identify the file */
     rewind(stream); /* reset the image for the readers */
@@ -406,7 +406,7 @@
         ctx->gd_free(ctx);
 #else
         msSetError(MS_MISCERR, "Unable to load GIF symbol.", "msGetSymbolGdPixmap()");
-        return(-1);
+        return MS_FAILURE;
 #endif
     } else if (memcmp(bytes,PNGsig,8)==0) {
 #ifdef USE_GD_PNG
@@ -416,17 +416,22 @@
         ctx->gd_free(ctx);
 #else
         msSetError(MS_MISCERR, "Unable to load PNG symbol.", "msGetSymbolGdPixmap()");
-        return(-1);
+        return MS_FAILURE;
 #endif
     }
     
     fclose(stream);
 
     if(!img) {
-        msSetError(MS_GDERR, NULL, "msGetSymbolGdPixmap()");
-        return(NULL);
+        msSetError(MS_GDERR, NULL, "loadGDImg()");
+        rb->type = MS_BUFFER_NONE;
+        return MS_FAILURE;
     }
-    return img;
+    rb->type = MS_BUFFER_GD;
+    rb->width = gdImageSX(img);
+    rb->height = gdImageSY(img);
+    rb->data.gd_img = img;
+    return MS_SUCCESS;
 }
 
 int readPNG(FILE *stream, rasterBufferObj *rb) {

Modified: sandbox/mapserver6/mapserver.h
===================================================================
--- sandbox/mapserver6/mapserver.h	2010-06-17 15:12:05 UTC (rev 10232)
+++ sandbox/mapserver6/mapserver.h	2010-06-18 07:01:11 UTC (rev 10233)
@@ -2701,6 +2701,7 @@
 int msSaveRasterBuffer(rasterBufferObj *data, FILE *stream, outputFormatObj *format);
 int msSaveRasterBufferToBuffer(rasterBufferObj *data, bufferObj *buffer, outputFormatObj *format);
 int msLoadMSRasterBufferFromFile(char *path, rasterBufferObj *rb);
+int msLoadGDRasterBufferFromFile(char *path, rasterBufferObj *rb);
 int saveGdImage(gdImagePtr ip, FILE *fp, outputFormatObj *format);
 
 



More information about the mapserver-commits mailing list