mapsymbol.h 5.87 KB
Newer Older
1
/******************************************************************************
2
 * $Id$
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * Project:  MapServer
 * Purpose:  symbolObj related declarations.
 * Author:   Steve Lime and the MapServer team.
 *
 ******************************************************************************
 * Copyright (c) 1996-2005 Regents of the University of Minnesota.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
18
 * The above copyright notice and this permission notice shall be included in
19 20 21 22 23 24 25 26 27 28 29 30 31 32
 * all copies of this Software or works derived from this Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 ****************************************************************************/

#ifndef MAPSYMBOL_H
#define MAPSYMBOL_H

33
#ifdef USE_GD
34
#include <gd.h>
35 36
#endif

37
#include "mapserver-api.h"
38
#include <assert.h>
39

40
enum MS_SYMBOL_TYPE {MS_SYMBOL_SIMPLE=1000, MS_SYMBOL_VECTOR, MS_SYMBOL_ELLIPSE, MS_SYMBOL_PIXMAP, MS_SYMBOL_TRUETYPE, MS_SYMBOL_HATCH, MS_SYMBOL_SVG};
41 42 43 44 45 46 47 48 49

#define MS_SYMBOL_ALLOCSIZE 64      /* number of symbolObj ptrs to allocate for a symbolset at once */
#define MS_MAXVECTORPOINTS 100      /* shade, marker and line symbol parameters */
#define MS_MAXPATTERNLENGTH 10

#define MS_IMAGECACHESIZE 6

/* COLOR OBJECT */
typedef struct {
50
#ifdef USE_GD
51
  int pen;
52
#endif
53 54 55 56 57 58 59
  int red;
  int green;
  int blue;
  int alpha;
} colorObj;

#ifndef SWIG
60 61 62
enum MS_RASTER_BUFFER_TYPE { MS_BUFFER_NONE=2000, MS_BUFFER_BYTE_RGBA, MS_BUFFER_BYTE_PALETTE, MS_BUFFER_GD };

typedef struct {
63 64 65
  unsigned char *pixels;
  unsigned int pixel_step, row_step;
  unsigned char *a,*r,*g,*b;
66 67 68
} rgbaArrayObj;

typedef struct {
69
  unsigned char b,g,r,a;
70 71 72
} rgbaPixel;

typedef struct {
73
  unsigned char r,g,b;
74 75 76 77
} rgbPixel;


typedef struct {
78 79 80 81
  unsigned char *pixels; /*stores the actual pixel indexes*/
  rgbaPixel *palette; /*rgba palette entries*/
  unsigned int num_entries; /*number of palette entries*/
  unsigned int scaling_maxval;
82 83 84
} paletteArrayObj;

typedef struct {
85 86 87 88 89 90 91 92 93
  int type;
  unsigned int width,height;
  union {
    rgbaArrayObj rgba;
    paletteArrayObj palette;
#ifdef USE_GD
    gdImagePtr gd_img;
#endif
  } data;
94 95
} rasterBufferObj;

96
/* NOTE: RB_SET_PIXEL() will premultiply by alpha, inputs should not be
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
         premultiplied */

#define RB_SET_PIXEL(rb,x,y,red,green,blue,alpha) \
    {  \
        int _rb_off = (x) * (rb)->data.rgba.pixel_step + (y) * (rb)->data.rgba.row_step;   \
        if( !(rb)->data.rgba.a ) { \
           (rb)->data.rgba.r[_rb_off] = red; \
           (rb)->data.rgba.g[_rb_off] = green; \
           (rb)->data.rgba.b[_rb_off] = blue; \
        } else { \
           double a = alpha/255.0; \
           (rb)->data.rgba.r[_rb_off] = red * a; \
           (rb)->data.rgba.g[_rb_off] = green * a; \
           (rb)->data.rgba.b[_rb_off] = blue * a; \
           (rb)->data.rgba.a[_rb_off] = alpha; \
        } \
    }

/* This versions receives an input red/green/blue that is already
   premultiplied with alpha */
#define RB_SET_PIXEL_PM(rb,x,y,red,green,blue,alpha) \
    {  \
        int _rb_off = (x) * (rb)->data.rgba.pixel_step + (y) * (rb)->data.rgba.row_step;   \
        (rb)->data.rgba.r[_rb_off] = red; \
        (rb)->data.rgba.g[_rb_off] = green; \
        (rb)->data.rgba.b[_rb_off] = blue; \
        if( rb->data.rgba.a ) { \
           (rb)->data.rgba.a[_rb_off] = alpha; \
        } \
    }

128
/* NOTE: RB_MIX_PIXEL() will premultiply by alpha, inputs should not be
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
         premultiplied */

#define RB_MIX_PIXEL(rb,x,y,red,green,blue,alpha) \
    {  \
        int _rb_off = (x) * (rb)->data.rgba.pixel_step + (y) * (rb)->data.rgba.row_step;   \
        \
        msAlphaBlend(  red, green, blue, alpha, \
                       (rb)->data.rgba.r + _rb_off, \
                       (rb)->data.rgba.g + _rb_off, \
                       (rb)->data.rgba.b + _rb_off, \
                       ((rb)->data.rgba.a == NULL ) ? NULL : (rb)->data.rgba.a + _rb_off );  \
    }



144 145 146 147 148 149
struct imageCacheObj {
  int symbol;
  int size;
  colorObj color;
  colorObj outlinecolor;
  colorObj backgroundcolor;
150
  rasterBufferObj img;
151 152 153 154 155 156 157
  struct imageCacheObj *next;
};


#endif /* SWIG */


158
struct symbolObj{
159 160 161 162 163 164 165 166
  char *name;
  int type;
  int inmapfile; /* boolean value for writing */

#ifndef SWIG
  /*
  ** Pointer to his map
  */
167
  struct mapObj *map;
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
#endif /* SWIG */
  /*
  ** MS_SYMBOL_VECTOR and MS_SYMBOL_ELLIPSE options
  */
  double sizex, sizey;
  double minx,miny,maxx,maxy;

#ifndef SWIG
  pointObj points[MS_MAXVECTORPOINTS];
#endif

#ifdef SWIG
  %immutable;
#endif /* SWIG */
  int refcount;
  int numpoints;
#ifdef SWIG
  %mutable;
#endif /* SWIG */
  int filled;
188 189 190

  double anchorpoint_x, anchorpoint_y;

191 192 193 194 195
  /*
  ** MS_SYMBOL_PIXMAP options
  */
#ifndef SWIG
  rendererVTableObj *renderer;
196
  void (*renderer_free_func)(symbolObj *self);
197
  rasterBufferObj *pixmap_buffer;
198
  void *renderer_cache;
199
  char *full_font_path;
200
  char *full_pixmap_path;
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
#endif /* SWIG */

#ifdef SWIG
  %immutable;
#endif /* SWIG */
  char *imagepath;
#ifdef SWIG
  %mutable;
#endif /* SWIG */

  int transparent;
  int transparentcolor;

  /*
  ** MS_SYMBOL_TRUETYPE options
  */
  char *character;
  int antialias;
  char *font;
220
} ;
221 222

#endif /* MAPSYMBOL_H */