| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* | 
 | 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 3 | %                                                                             % | 
 | 4 | %                                                                             % | 
 | 5 | %                                                                             % | 
 | 6 | %                        DDDD   RRRR    AAA   W   W                           % | 
 | 7 | %                        D   D  R   R  A   A  W   W                           % | 
 | 8 | %                        D   D  RRRR   AAAAA  W W W                           % | 
 | 9 | %                        D   D  R RN   A   A  WW WW                           % | 
 | 10 | %                        DDDD   R  R   A   A  W   W                           % | 
 | 11 | %                                                                             % | 
 | 12 | %                                                                             % | 
 | 13 | %                     MagickCore Image Drawing Methods                        % | 
 | 14 | %                                                                             % | 
 | 15 | %                                                                             % | 
 | 16 | %                              Software Design                                % | 
 | 17 | %                                John Cristy                                  % | 
 | 18 | %                                 July 1998                                   % | 
 | 19 | %                                                                             % | 
 | 20 | %                                                                             % | 
| cristy | 16af1cb | 2009-12-11 21:38:29 +0000 | [diff] [blame] | 21 | %  Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization      % | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 22 | %  dedicated to making software imaging solutions freely available.           % | 
 | 23 | %                                                                             % | 
 | 24 | %  You may not use this file except in compliance with the License.  You may  % | 
 | 25 | %  obtain a copy of the License at                                            % | 
 | 26 | %                                                                             % | 
 | 27 | %    http://www.imagemagick.org/script/license.php                            % | 
 | 28 | %                                                                             % | 
 | 29 | %  Unless required by applicable law or agreed to in writing, software        % | 
 | 30 | %  distributed under the License is distributed on an "AS IS" BASIS,          % | 
 | 31 | %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   % | 
 | 32 | %  See the License for the specific language governing permissions and        % | 
 | 33 | %  limitations under the License.                                             % | 
 | 34 | %                                                                             % | 
 | 35 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 36 | % | 
 | 37 | % Bill Radcliffe of Corbis (www.corbis.com) contributed the polygon | 
 | 38 | % rendering code based on Paul Heckbert's "Concave Polygon Scan Conversion", | 
 | 39 | % Graphics Gems, 1990.  Leonard Rosenthal and David Harr of Appligent | 
 | 40 | % (www.appligent.com) contributed the dash pattern, linecap stroking | 
 | 41 | % algorithm, and minor rendering improvements. | 
 | 42 | % | 
 | 43 | */ | 
 | 44 |  | 
 | 45 | /* | 
 | 46 |   Include declarations. | 
 | 47 | */ | 
 | 48 | #include "magick/studio.h" | 
 | 49 | #include "magick/annotate.h" | 
 | 50 | #include "magick/artifact.h" | 
 | 51 | #include "magick/blob.h" | 
 | 52 | #include "magick/cache.h" | 
 | 53 | #include "magick/cache-view.h" | 
 | 54 | #include "magick/color.h" | 
 | 55 | #include "magick/composite.h" | 
 | 56 | #include "magick/composite-private.h" | 
 | 57 | #include "magick/constitute.h" | 
 | 58 | #include "magick/draw.h" | 
 | 59 | #include "magick/draw-private.h" | 
 | 60 | #include "magick/enhance.h" | 
 | 61 | #include "magick/exception.h" | 
 | 62 | #include "magick/exception-private.h" | 
 | 63 | #include "magick/gem.h" | 
 | 64 | #include "magick/geometry.h" | 
 | 65 | #include "magick/image-private.h" | 
 | 66 | #include "magick/list.h" | 
 | 67 | #include "magick/log.h" | 
 | 68 | #include "magick/monitor.h" | 
 | 69 | #include "magick/monitor-private.h" | 
 | 70 | #include "magick/option.h" | 
 | 71 | #include "magick/paint.h" | 
 | 72 | #include "magick/pixel-private.h" | 
 | 73 | #include "magick/property.h" | 
 | 74 | #include "magick/resample.h" | 
 | 75 | #include "magick/resample-private.h" | 
 | 76 | #include "magick/string_.h" | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 77 | #include "magick/string-private.h" | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 78 | #include "magick/thread-private.h" | 
 | 79 | #include "magick/token.h" | 
 | 80 | #include "magick/transform.h" | 
 | 81 | #include "magick/utility.h" | 
 | 82 |  | 
 | 83 | /* | 
 | 84 |   Define declarations. | 
 | 85 | */ | 
 | 86 | #define BezierQuantum  200 | 
 | 87 |  | 
 | 88 | /* | 
 | 89 |   Typedef declarations. | 
 | 90 | */ | 
 | 91 | typedef struct _EdgeInfo | 
 | 92 | { | 
 | 93 |   SegmentInfo | 
 | 94 |     bounds; | 
 | 95 |  | 
 | 96 |   MagickRealType | 
 | 97 |     scanline; | 
 | 98 |  | 
 | 99 |   PointInfo | 
 | 100 |     *points; | 
 | 101 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 102 |   size_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 103 |     number_points; | 
 | 104 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 105 |   ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 106 |     direction; | 
 | 107 |  | 
 | 108 |   MagickBooleanType | 
 | 109 |     ghostline; | 
 | 110 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 111 |   size_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 112 |     highwater; | 
 | 113 | } EdgeInfo; | 
 | 114 |  | 
 | 115 | typedef struct _ElementInfo | 
 | 116 | { | 
 | 117 |   MagickRealType | 
 | 118 |     cx, | 
 | 119 |     cy, | 
 | 120 |     major, | 
 | 121 |     minor, | 
 | 122 |     angle; | 
 | 123 | } ElementInfo; | 
 | 124 |  | 
 | 125 | typedef struct _PolygonInfo | 
 | 126 | { | 
 | 127 |   EdgeInfo | 
 | 128 |     *edges; | 
 | 129 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 130 |   size_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 131 |     number_edges; | 
 | 132 | } PolygonInfo; | 
 | 133 |  | 
 | 134 | typedef enum | 
 | 135 | { | 
 | 136 |   MoveToCode, | 
 | 137 |   OpenCode, | 
 | 138 |   GhostlineCode, | 
 | 139 |   LineToCode, | 
 | 140 |   EndCode | 
 | 141 | } PathInfoCode; | 
 | 142 |  | 
 | 143 | typedef struct _PathInfo | 
 | 144 | { | 
 | 145 |   PointInfo | 
 | 146 |     point; | 
 | 147 |  | 
 | 148 |   PathInfoCode | 
 | 149 |     code; | 
 | 150 | } PathInfo; | 
 | 151 |  | 
 | 152 | /* | 
 | 153 |   Forward declarations. | 
 | 154 | */ | 
 | 155 | static MagickBooleanType | 
 | 156 |   DrawStrokePolygon(Image *,const DrawInfo *,const PrimitiveInfo *); | 
 | 157 |  | 
 | 158 | static PrimitiveInfo | 
 | 159 |   *TraceStrokePolygon(const DrawInfo *,const PrimitiveInfo *); | 
 | 160 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 161 | static size_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 162 |   TracePath(PrimitiveInfo *,const char *); | 
 | 163 |  | 
 | 164 | static void | 
 | 165 |   TraceArc(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo), | 
 | 166 |   TraceArcPath(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo, | 
 | 167 |     const MagickRealType,const MagickBooleanType,const MagickBooleanType), | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 168 |   TraceBezier(PrimitiveInfo *,const size_t), | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 169 |   TraceCircle(PrimitiveInfo *,const PointInfo,const PointInfo), | 
 | 170 |   TraceEllipse(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo), | 
 | 171 |   TraceLine(PrimitiveInfo *,const PointInfo,const PointInfo), | 
 | 172 |   TraceRectangle(PrimitiveInfo *,const PointInfo,const PointInfo), | 
 | 173 |   TraceRoundRectangle(PrimitiveInfo *,const PointInfo,const PointInfo, | 
 | 174 |     PointInfo), | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 175 |   TraceSquareLinecap(PrimitiveInfo *,const size_t,const MagickRealType); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 176 |  | 
 | 177 | /* | 
 | 178 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 179 | %                                                                             % | 
 | 180 | %                                                                             % | 
 | 181 | %                                                                             % | 
 | 182 | %   A c q u i r e D r a w I n f o                                             % | 
 | 183 | %                                                                             % | 
 | 184 | %                                                                             % | 
 | 185 | %                                                                             % | 
 | 186 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 187 | % | 
 | 188 | %  AcquireDrawInfo() returns a DrawInfo structure properly initialized. | 
 | 189 | % | 
 | 190 | %  The format of the AcquireDrawInfo method is: | 
 | 191 | % | 
 | 192 | %      DrawInfo *AcquireDrawInfo(void) | 
 | 193 | % | 
 | 194 | */ | 
 | 195 | MagickExport DrawInfo *AcquireDrawInfo(void) | 
 | 196 | { | 
 | 197 |   DrawInfo | 
 | 198 |     *draw_info; | 
 | 199 |  | 
| cristy | 9082321 | 2009-12-12 20:48:33 +0000 | [diff] [blame] | 200 |   draw_info=(DrawInfo *) AcquireAlignedMemory(1,sizeof(*draw_info)); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 201 |   if (draw_info == (DrawInfo *) NULL) | 
 | 202 |     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); | 
 | 203 |   GetDrawInfo((ImageInfo *) NULL,draw_info); | 
 | 204 |   return(draw_info); | 
 | 205 | } | 
 | 206 |  | 
 | 207 | /* | 
 | 208 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 209 | %                                                                             % | 
 | 210 | %                                                                             % | 
 | 211 | %                                                                             % | 
 | 212 | %   C l o n e D r a w I n f o                                                 % | 
 | 213 | %                                                                             % | 
 | 214 | %                                                                             % | 
 | 215 | %                                                                             % | 
 | 216 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 217 | % | 
 | 218 | %  CloneDrawInfo() makes a copy of the given draw info structure.  If NULL | 
 | 219 | %  is specified, a new image info structure is created initialized to | 
 | 220 | %  default values. | 
 | 221 | % | 
 | 222 | %  The format of the CloneDrawInfo method is: | 
 | 223 | % | 
 | 224 | %      DrawInfo *CloneDrawInfo(const ImageInfo *image_info, | 
 | 225 | %        const DrawInfo *draw_info) | 
 | 226 | % | 
 | 227 | %  A description of each parameter follows: | 
 | 228 | % | 
 | 229 | %    o image_info: the image info. | 
 | 230 | % | 
 | 231 | %    o draw_info: the draw info. | 
 | 232 | % | 
 | 233 | */ | 
 | 234 | MagickExport DrawInfo *CloneDrawInfo(const ImageInfo *image_info, | 
 | 235 |   const DrawInfo *draw_info) | 
 | 236 | { | 
 | 237 |   DrawInfo | 
 | 238 |     *clone_info; | 
 | 239 |  | 
| cristy | 9082321 | 2009-12-12 20:48:33 +0000 | [diff] [blame] | 240 |   clone_info=(DrawInfo *) AcquireAlignedMemory(1,sizeof(*clone_info)); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 241 |   if (clone_info == (DrawInfo *) NULL) | 
 | 242 |     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); | 
 | 243 |   GetDrawInfo(image_info,clone_info); | 
 | 244 |   if (draw_info == (DrawInfo *) NULL) | 
 | 245 |     return(clone_info); | 
 | 246 |   if (clone_info->primitive != (char *) NULL) | 
 | 247 |     (void) CloneString(&clone_info->primitive,draw_info->primitive); | 
 | 248 |   if (draw_info->geometry != (char *) NULL) | 
 | 249 |     (void) CloneString(&clone_info->geometry,draw_info->geometry); | 
 | 250 |   clone_info->viewbox=draw_info->viewbox; | 
 | 251 |   clone_info->affine=draw_info->affine; | 
 | 252 |   clone_info->gravity=draw_info->gravity; | 
 | 253 |   clone_info->fill=draw_info->fill; | 
 | 254 |   clone_info->stroke=draw_info->stroke; | 
 | 255 |   clone_info->stroke_width=draw_info->stroke_width; | 
 | 256 |   if (draw_info->fill_pattern != (Image *) NULL) | 
 | 257 |     clone_info->fill_pattern=CloneImage(draw_info->fill_pattern,0,0,MagickTrue, | 
 | 258 |       &draw_info->fill_pattern->exception); | 
 | 259 |   else | 
 | 260 |     if (draw_info->tile != (Image *) NULL) | 
 | 261 |       clone_info->fill_pattern=CloneImage(draw_info->tile,0,0,MagickTrue, | 
 | 262 |         &draw_info->tile->exception); | 
 | 263 |   clone_info->tile=NewImageList();  /* tile is deprecated */ | 
 | 264 |   if (draw_info->stroke_pattern != (Image *) NULL) | 
 | 265 |     clone_info->stroke_pattern=CloneImage(draw_info->stroke_pattern,0,0, | 
 | 266 |       MagickTrue,&draw_info->stroke_pattern->exception); | 
 | 267 |   clone_info->stroke_antialias=draw_info->stroke_antialias; | 
 | 268 |   clone_info->text_antialias=draw_info->text_antialias; | 
 | 269 |   clone_info->fill_rule=draw_info->fill_rule; | 
 | 270 |   clone_info->linecap=draw_info->linecap; | 
 | 271 |   clone_info->linejoin=draw_info->linejoin; | 
 | 272 |   clone_info->miterlimit=draw_info->miterlimit; | 
 | 273 |   clone_info->dash_offset=draw_info->dash_offset; | 
 | 274 |   clone_info->decorate=draw_info->decorate; | 
 | 275 |   clone_info->compose=draw_info->compose; | 
 | 276 |   if (draw_info->text != (char *) NULL) | 
 | 277 |     (void) CloneString(&clone_info->text,draw_info->text); | 
 | 278 |   if (draw_info->font != (char *) NULL) | 
 | 279 |     (void) CloneString(&clone_info->font,draw_info->font); | 
 | 280 |   if (draw_info->metrics != (char *) NULL) | 
 | 281 |     (void) CloneString(&clone_info->metrics,draw_info->metrics); | 
 | 282 |   if (draw_info->family != (char *) NULL) | 
 | 283 |     (void) CloneString(&clone_info->family,draw_info->family); | 
 | 284 |   clone_info->style=draw_info->style; | 
 | 285 |   clone_info->stretch=draw_info->stretch; | 
 | 286 |   clone_info->weight=draw_info->weight; | 
 | 287 |   if (draw_info->encoding != (char *) NULL) | 
 | 288 |     (void) CloneString(&clone_info->encoding,draw_info->encoding); | 
 | 289 |   clone_info->pointsize=draw_info->pointsize; | 
 | 290 |   clone_info->kerning=draw_info->kerning; | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 291 |   clone_info->interline_spacing=draw_info->interline_spacing; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 292 |   clone_info->interword_spacing=draw_info->interword_spacing; | 
| cristy | c9b1295 | 2010-03-28 01:12:28 +0000 | [diff] [blame] | 293 |   clone_info->direction=draw_info->direction; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 294 |   if (draw_info->density != (char *) NULL) | 
 | 295 |     (void) CloneString(&clone_info->density,draw_info->density); | 
 | 296 |   clone_info->align=draw_info->align; | 
 | 297 |   clone_info->undercolor=draw_info->undercolor; | 
 | 298 |   clone_info->border_color=draw_info->border_color; | 
 | 299 |   if (draw_info->server_name != (char *) NULL) | 
 | 300 |     (void) CloneString(&clone_info->server_name,draw_info->server_name); | 
 | 301 |   if (draw_info->dash_pattern != (double *) NULL) | 
 | 302 |     { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 303 |       register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 304 |         x; | 
 | 305 |  | 
 | 306 |       for (x=0; draw_info->dash_pattern[x] != 0.0; x++) ; | 
 | 307 |       clone_info->dash_pattern=(double *) AcquireQuantumMemory((size_t) x+1UL, | 
 | 308 |         sizeof(*clone_info->dash_pattern)); | 
 | 309 |       if (clone_info->dash_pattern == (double *) NULL) | 
 | 310 |         ThrowFatalException(ResourceLimitFatalError, | 
 | 311 |           "UnableToAllocateDashPattern"); | 
 | 312 |       (void) CopyMagickMemory(clone_info->dash_pattern,draw_info->dash_pattern, | 
 | 313 |         (size_t) (x+1)*sizeof(*clone_info->dash_pattern)); | 
 | 314 |     } | 
 | 315 |   clone_info->gradient=draw_info->gradient; | 
 | 316 |   if (draw_info->gradient.stops != (StopInfo *) NULL) | 
 | 317 |     { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 318 |       size_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 319 |         number_stops; | 
 | 320 |  | 
 | 321 |       number_stops=clone_info->gradient.number_stops; | 
 | 322 |       clone_info->gradient.stops=(StopInfo *) AcquireQuantumMemory((size_t) | 
 | 323 |         number_stops,sizeof(*clone_info->gradient.stops)); | 
 | 324 |       if (clone_info->gradient.stops == (StopInfo *) NULL) | 
 | 325 |         ThrowFatalException(ResourceLimitFatalError, | 
 | 326 |           "UnableToAllocateDashPattern"); | 
 | 327 |       (void) CopyMagickMemory(clone_info->gradient.stops, | 
 | 328 |         draw_info->gradient.stops,(size_t) number_stops* | 
 | 329 |         sizeof(*clone_info->gradient.stops)); | 
 | 330 |     } | 
 | 331 |   if (draw_info->clip_mask != (char *) NULL) | 
 | 332 |     (void) CloneString(&clone_info->clip_mask,draw_info->clip_mask); | 
 | 333 |   clone_info->bounds=draw_info->bounds; | 
 | 334 |   clone_info->clip_units=draw_info->clip_units; | 
 | 335 |   clone_info->render=draw_info->render; | 
 | 336 |   clone_info->opacity=draw_info->opacity; | 
 | 337 |   clone_info->element_reference=draw_info->element_reference; | 
 | 338 |   clone_info->debug=IsEventLogging(); | 
 | 339 |   return(clone_info); | 
 | 340 | } | 
 | 341 |  | 
 | 342 | /* | 
 | 343 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 344 | %                                                                             % | 
 | 345 | %                                                                             % | 
 | 346 | %                                                                             % | 
 | 347 | +   C o n v e r t P a t h T o P o l y g o n                                   % | 
 | 348 | %                                                                             % | 
 | 349 | %                                                                             % | 
 | 350 | %                                                                             % | 
 | 351 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 352 | % | 
 | 353 | %  ConvertPathToPolygon() converts a path to the more efficient sorted | 
 | 354 | %  rendering form. | 
 | 355 | % | 
 | 356 | %  The format of the ConvertPathToPolygon method is: | 
 | 357 | % | 
 | 358 | %      PolygonInfo *ConvertPathToPolygon(const DrawInfo *draw_info, | 
 | 359 | %        const PathInfo *path_info) | 
 | 360 | % | 
 | 361 | %  A description of each parameter follows: | 
 | 362 | % | 
 | 363 | %    o Method ConvertPathToPolygon returns the path in a more efficient sorted | 
 | 364 | %      rendering form of type PolygonInfo. | 
 | 365 | % | 
 | 366 | %    o draw_info: Specifies a pointer to an DrawInfo structure. | 
 | 367 | % | 
 | 368 | %    o path_info: Specifies a pointer to an PathInfo structure. | 
 | 369 | % | 
 | 370 | % | 
 | 371 | */ | 
 | 372 |  | 
 | 373 | #if defined(__cplusplus) || defined(c_plusplus) | 
 | 374 | extern "C" { | 
 | 375 | #endif | 
 | 376 |  | 
 | 377 | static int CompareEdges(const void *x,const void *y) | 
 | 378 | { | 
 | 379 |   register const EdgeInfo | 
 | 380 |     *p, | 
 | 381 |     *q; | 
 | 382 |  | 
 | 383 |   /* | 
 | 384 |     Compare two edges. | 
 | 385 |   */ | 
 | 386 |   p=(const EdgeInfo *) x; | 
 | 387 |   q=(const EdgeInfo *) y; | 
 | 388 |   if ((p->points[0].y-MagickEpsilon) > q->points[0].y) | 
 | 389 |     return(1); | 
 | 390 |   if ((p->points[0].y+MagickEpsilon) < q->points[0].y) | 
 | 391 |     return(-1); | 
 | 392 |   if ((p->points[0].x-MagickEpsilon) > q->points[0].x) | 
 | 393 |     return(1); | 
 | 394 |   if ((p->points[0].x+MagickEpsilon) < q->points[0].x) | 
 | 395 |     return(-1); | 
 | 396 |   if (((p->points[1].x-p->points[0].x)*(q->points[1].y-q->points[0].y)- | 
 | 397 |        (p->points[1].y-p->points[0].y)*(q->points[1].x-q->points[0].x)) > 0.0) | 
 | 398 |     return(1); | 
 | 399 |   return(-1); | 
 | 400 | } | 
 | 401 |  | 
 | 402 | #if defined(__cplusplus) || defined(c_plusplus) | 
 | 403 | } | 
 | 404 | #endif | 
 | 405 |  | 
 | 406 | static void LogPolygonInfo(const PolygonInfo *polygon_info) | 
 | 407 | { | 
 | 408 |   register EdgeInfo | 
 | 409 |     *p; | 
 | 410 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 411 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 412 |     i, | 
 | 413 |     j; | 
 | 414 |  | 
 | 415 |   (void) LogMagickEvent(DrawEvent,GetMagickModule(),"    begin active-edge"); | 
 | 416 |   p=polygon_info->edges; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 417 |   for (i=0; i < (ssize_t) polygon_info->number_edges; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 418 |   { | 
| cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 419 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(),"      edge %lu:", | 
 | 420 |      (unsigned long) i); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 421 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(),"      direction: %s", | 
 | 422 |       p->direction != MagickFalse ? "down" : "up"); | 
 | 423 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(),"      ghostline: %s", | 
 | 424 |       p->ghostline != MagickFalse ? "transparent" : "opaque"); | 
 | 425 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(), | 
| cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 426 |       "      bounds: %g,%g - %g,%g",p->bounds.x1,p->bounds.y1, | 
| cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 427 |       p->bounds.x2,p->bounds.y2); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 428 |     for (j=0; j < (ssize_t) p->number_points; j++) | 
| cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 429 |       (void) LogMagickEvent(DrawEvent,GetMagickModule(),"        %g,%g", | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 430 |         p->points[j].x,p->points[j].y); | 
 | 431 |     p++; | 
 | 432 |   } | 
 | 433 |   (void) LogMagickEvent(DrawEvent,GetMagickModule(),"    end active-edge"); | 
 | 434 | } | 
 | 435 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 436 | static void ReversePoints(PointInfo *points,const size_t number_points) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 437 | { | 
 | 438 |   PointInfo | 
 | 439 |     point; | 
 | 440 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 441 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 442 |     i; | 
 | 443 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 444 |   for (i=0; i < (ssize_t) (number_points >> 1); i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 445 |   { | 
 | 446 |     point=points[i]; | 
 | 447 |     points[i]=points[number_points-(i+1)]; | 
 | 448 |     points[number_points-(i+1)]=point; | 
 | 449 |   } | 
 | 450 | } | 
 | 451 |  | 
 | 452 | static PolygonInfo *ConvertPathToPolygon( | 
 | 453 |   const DrawInfo *magick_unused(draw_info),const PathInfo *path_info) | 
 | 454 | { | 
| cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 455 |   long | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 456 |     direction, | 
 | 457 |     next_direction; | 
 | 458 |  | 
 | 459 |   PointInfo | 
 | 460 |     point, | 
 | 461 |     *points; | 
 | 462 |  | 
 | 463 |   PolygonInfo | 
 | 464 |     *polygon_info; | 
 | 465 |  | 
 | 466 |   SegmentInfo | 
 | 467 |     bounds; | 
 | 468 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 469 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 470 |     i, | 
 | 471 |     n; | 
 | 472 |  | 
 | 473 |   MagickBooleanType | 
 | 474 |     ghostline; | 
 | 475 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 476 |   size_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 477 |     edge, | 
 | 478 |     number_edges, | 
 | 479 |     number_points; | 
 | 480 |  | 
 | 481 |   /* | 
 | 482 |     Convert a path to the more efficient sorted rendering form. | 
 | 483 |   */ | 
| cristy | 9082321 | 2009-12-12 20:48:33 +0000 | [diff] [blame] | 484 |   polygon_info=(PolygonInfo *) AcquireAlignedMemory(1,sizeof(*polygon_info)); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 485 |   if (polygon_info == (PolygonInfo *) NULL) | 
 | 486 |     return((PolygonInfo *) NULL); | 
 | 487 |   number_edges=16; | 
 | 488 |   polygon_info->edges=(EdgeInfo *) AcquireQuantumMemory((size_t) number_edges, | 
 | 489 |     sizeof(*polygon_info->edges)); | 
 | 490 |   if (polygon_info->edges == (EdgeInfo *) NULL) | 
 | 491 |     return((PolygonInfo *) NULL); | 
 | 492 |   direction=0; | 
 | 493 |   edge=0; | 
 | 494 |   ghostline=MagickFalse; | 
 | 495 |   n=0; | 
 | 496 |   number_points=0; | 
 | 497 |   points=(PointInfo *) NULL; | 
 | 498 |   (void) ResetMagickMemory(&point,0,sizeof(point)); | 
 | 499 |   (void) ResetMagickMemory(&bounds,0,sizeof(bounds)); | 
 | 500 |   for (i=0; path_info[i].code != EndCode; i++) | 
 | 501 |   { | 
 | 502 |     if ((path_info[i].code == MoveToCode) || (path_info[i].code == OpenCode) || | 
 | 503 |         (path_info[i].code == GhostlineCode)) | 
 | 504 |       { | 
 | 505 |         /* | 
 | 506 |           Move to. | 
 | 507 |         */ | 
 | 508 |         if ((points != (PointInfo *) NULL) && (n >= 2)) | 
 | 509 |           { | 
 | 510 |             if (edge == number_edges) | 
 | 511 |               { | 
 | 512 |                 number_edges<<=1; | 
 | 513 |                 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory( | 
 | 514 |                   polygon_info->edges,(size_t) number_edges, | 
 | 515 |                   sizeof(*polygon_info->edges)); | 
 | 516 |                 if (polygon_info->edges == (EdgeInfo *) NULL) | 
 | 517 |                   return((PolygonInfo *) NULL); | 
 | 518 |               } | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 519 |             polygon_info->edges[edge].number_points=(size_t) n; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 520 |             polygon_info->edges[edge].scanline=(-1.0); | 
 | 521 |             polygon_info->edges[edge].highwater=0; | 
 | 522 |             polygon_info->edges[edge].ghostline=ghostline; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 523 |             polygon_info->edges[edge].direction=(ssize_t) (direction > 0); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 524 |             if (direction < 0) | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 525 |               ReversePoints(points,(size_t) n); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 526 |             polygon_info->edges[edge].points=points; | 
 | 527 |             polygon_info->edges[edge].bounds=bounds; | 
 | 528 |             polygon_info->edges[edge].bounds.y1=points[0].y; | 
 | 529 |             polygon_info->edges[edge].bounds.y2=points[n-1].y; | 
 | 530 |             points=(PointInfo *) NULL; | 
 | 531 |             ghostline=MagickFalse; | 
 | 532 |             edge++; | 
 | 533 |           } | 
 | 534 |         if (points == (PointInfo *) NULL) | 
 | 535 |           { | 
 | 536 |             number_points=16; | 
 | 537 |             points=(PointInfo *) AcquireQuantumMemory((size_t) number_points, | 
 | 538 |               sizeof(*points)); | 
 | 539 |             if (points == (PointInfo *) NULL) | 
 | 540 |               return((PolygonInfo *) NULL); | 
 | 541 |           } | 
 | 542 |         ghostline=path_info[i].code == GhostlineCode ? MagickTrue : MagickFalse; | 
 | 543 |         point=path_info[i].point; | 
 | 544 |         points[0]=point; | 
 | 545 |         bounds.x1=point.x; | 
 | 546 |         bounds.x2=point.x; | 
 | 547 |         direction=0; | 
 | 548 |         n=1; | 
 | 549 |         continue; | 
 | 550 |       } | 
 | 551 |     /* | 
 | 552 |       Line to. | 
 | 553 |     */ | 
 | 554 |     next_direction=((path_info[i].point.y > point.y) || | 
 | 555 |       ((path_info[i].point.y == point.y) && | 
 | 556 |        (path_info[i].point.x > point.x))) ? 1 : -1; | 
 | 557 |     if ((direction != 0) && (direction != next_direction)) | 
 | 558 |       { | 
 | 559 |         /* | 
 | 560 |           New edge. | 
 | 561 |         */ | 
 | 562 |         point=points[n-1]; | 
 | 563 |         if (edge == number_edges) | 
 | 564 |           { | 
 | 565 |             number_edges<<=1; | 
 | 566 |             polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory( | 
 | 567 |               polygon_info->edges,(size_t) number_edges, | 
 | 568 |               sizeof(*polygon_info->edges)); | 
 | 569 |             if (polygon_info->edges == (EdgeInfo *) NULL) | 
 | 570 |               return((PolygonInfo *) NULL); | 
 | 571 |           } | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 572 |         polygon_info->edges[edge].number_points=(size_t) n; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 573 |         polygon_info->edges[edge].scanline=(-1.0); | 
 | 574 |         polygon_info->edges[edge].highwater=0; | 
 | 575 |         polygon_info->edges[edge].ghostline=ghostline; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 576 |         polygon_info->edges[edge].direction=(ssize_t) (direction > 0); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 577 |         if (direction < 0) | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 578 |           ReversePoints(points,(size_t) n); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 579 |         polygon_info->edges[edge].points=points; | 
 | 580 |         polygon_info->edges[edge].bounds=bounds; | 
 | 581 |         polygon_info->edges[edge].bounds.y1=points[0].y; | 
 | 582 |         polygon_info->edges[edge].bounds.y2=points[n-1].y; | 
 | 583 |         number_points=16; | 
 | 584 |         points=(PointInfo *) AcquireQuantumMemory((size_t) number_points, | 
 | 585 |           sizeof(*points)); | 
 | 586 |         if (points == (PointInfo *) NULL) | 
 | 587 |           return((PolygonInfo *) NULL); | 
 | 588 |         n=1; | 
 | 589 |         ghostline=MagickFalse; | 
 | 590 |         points[0]=point; | 
 | 591 |         bounds.x1=point.x; | 
 | 592 |         bounds.x2=point.x; | 
 | 593 |         edge++; | 
 | 594 |       } | 
 | 595 |     direction=next_direction; | 
 | 596 |     if (points == (PointInfo *) NULL) | 
 | 597 |       continue; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 598 |     if (n == (ssize_t) number_points) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 599 |       { | 
 | 600 |         number_points<<=1; | 
 | 601 |         points=(PointInfo *) ResizeQuantumMemory(points,(size_t) number_points, | 
 | 602 |           sizeof(*points)); | 
 | 603 |         if (points == (PointInfo *) NULL) | 
 | 604 |           return((PolygonInfo *) NULL); | 
 | 605 |       } | 
 | 606 |     point=path_info[i].point; | 
 | 607 |     points[n]=point; | 
 | 608 |     if (point.x < bounds.x1) | 
 | 609 |       bounds.x1=point.x; | 
 | 610 |     if (point.x > bounds.x2) | 
 | 611 |       bounds.x2=point.x; | 
 | 612 |     n++; | 
 | 613 |   } | 
 | 614 |   if (points != (PointInfo *) NULL) | 
 | 615 |     { | 
 | 616 |       if (n < 2) | 
 | 617 |         points=(PointInfo *) RelinquishMagickMemory(points); | 
 | 618 |       else | 
 | 619 |         { | 
 | 620 |           if (edge == number_edges) | 
 | 621 |             { | 
 | 622 |               number_edges<<=1; | 
 | 623 |               polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory( | 
 | 624 |                 polygon_info->edges,(size_t) number_edges, | 
 | 625 |                 sizeof(*polygon_info->edges)); | 
 | 626 |               if (polygon_info->edges == (EdgeInfo *) NULL) | 
 | 627 |                 return((PolygonInfo *) NULL); | 
 | 628 |             } | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 629 |           polygon_info->edges[edge].number_points=(size_t) n; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 630 |           polygon_info->edges[edge].scanline=(-1.0); | 
 | 631 |           polygon_info->edges[edge].highwater=0; | 
 | 632 |           polygon_info->edges[edge].ghostline=ghostline; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 633 |           polygon_info->edges[edge].direction=(ssize_t) (direction > 0); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 634 |           if (direction < 0) | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 635 |             ReversePoints(points,(size_t) n); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 636 |           polygon_info->edges[edge].points=points; | 
 | 637 |           polygon_info->edges[edge].bounds=bounds; | 
 | 638 |           polygon_info->edges[edge].bounds.y1=points[0].y; | 
 | 639 |           polygon_info->edges[edge].bounds.y2=points[n-1].y; | 
 | 640 |           ghostline=MagickFalse; | 
 | 641 |           edge++; | 
 | 642 |         } | 
 | 643 |     } | 
 | 644 |   polygon_info->number_edges=edge; | 
 | 645 |   qsort(polygon_info->edges,(size_t) polygon_info->number_edges, | 
 | 646 |     sizeof(*polygon_info->edges),CompareEdges); | 
 | 647 |   if (IsEventLogging() != MagickFalse) | 
 | 648 |     LogPolygonInfo(polygon_info); | 
 | 649 |   return(polygon_info); | 
 | 650 | } | 
 | 651 |  | 
 | 652 | /* | 
 | 653 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 654 | %                                                                             % | 
 | 655 | %                                                                             % | 
 | 656 | %                                                                             % | 
 | 657 | +   C o n v e r t P r i m i t i v e T o P a t h                               % | 
 | 658 | %                                                                             % | 
 | 659 | %                                                                             % | 
 | 660 | %                                                                             % | 
 | 661 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 662 | % | 
 | 663 | %  ConvertPrimitiveToPath() converts a PrimitiveInfo structure into a vector | 
 | 664 | %  path structure. | 
 | 665 | % | 
 | 666 | %  The format of the ConvertPrimitiveToPath method is: | 
 | 667 | % | 
 | 668 | %      PathInfo *ConvertPrimitiveToPath(const DrawInfo *draw_info, | 
 | 669 | %        const PrimitiveInfo *primitive_info) | 
 | 670 | % | 
 | 671 | %  A description of each parameter follows: | 
 | 672 | % | 
 | 673 | %    o Method ConvertPrimitiveToPath returns a vector path structure of type | 
 | 674 | %      PathInfo. | 
 | 675 | % | 
 | 676 | %    o draw_info: a structure of type DrawInfo. | 
 | 677 | % | 
 | 678 | %    o primitive_info: Specifies a pointer to an PrimitiveInfo structure. | 
 | 679 | % | 
 | 680 | % | 
 | 681 | */ | 
 | 682 |  | 
 | 683 | static void LogPathInfo(const PathInfo *path_info) | 
 | 684 | { | 
 | 685 |   register const PathInfo | 
 | 686 |     *p; | 
 | 687 |  | 
 | 688 |   (void) LogMagickEvent(DrawEvent,GetMagickModule(),"    begin vector-path"); | 
 | 689 |   for (p=path_info; p->code != EndCode; p++) | 
 | 690 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(), | 
| cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 691 |       "      %g,%g %s",p->point.x,p->point.y,p->code == GhostlineCode ? | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 692 |       "moveto ghostline" : p->code == OpenCode ? "moveto open" : | 
 | 693 |       p->code == MoveToCode ? "moveto" : p->code == LineToCode ? "lineto" : | 
 | 694 |       "?"); | 
 | 695 |   (void) LogMagickEvent(DrawEvent,GetMagickModule(),"    end vector-path"); | 
 | 696 | } | 
 | 697 |  | 
 | 698 | static PathInfo *ConvertPrimitiveToPath( | 
 | 699 |   const DrawInfo *magick_unused(draw_info),const PrimitiveInfo *primitive_info) | 
 | 700 | { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 701 |   ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 702 |     coordinates, | 
 | 703 |     start; | 
 | 704 |  | 
 | 705 |   PathInfo | 
 | 706 |     *path_info; | 
 | 707 |  | 
 | 708 |   PathInfoCode | 
 | 709 |     code; | 
 | 710 |  | 
 | 711 |   PointInfo | 
 | 712 |     p, | 
 | 713 |     q; | 
 | 714 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 715 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 716 |     i, | 
 | 717 |     n; | 
 | 718 |  | 
 | 719 |   /* | 
 | 720 |     Converts a PrimitiveInfo structure into a vector path structure. | 
 | 721 |   */ | 
 | 722 |   switch (primitive_info->primitive) | 
 | 723 |   { | 
 | 724 |     case PointPrimitive: | 
 | 725 |     case ColorPrimitive: | 
 | 726 |     case MattePrimitive: | 
 | 727 |     case TextPrimitive: | 
 | 728 |     case ImagePrimitive: | 
 | 729 |       return((PathInfo *) NULL); | 
 | 730 |     default: | 
 | 731 |       break; | 
 | 732 |   } | 
 | 733 |   for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ; | 
 | 734 |   path_info=(PathInfo *) AcquireQuantumMemory((size_t) (2UL*i+3UL), | 
 | 735 |     sizeof(*path_info)); | 
 | 736 |   if (path_info == (PathInfo *) NULL) | 
 | 737 |     return((PathInfo *) NULL); | 
 | 738 |   coordinates=0; | 
 | 739 |   n=0; | 
 | 740 |   p.x=(-1.0); | 
 | 741 |   p.y=(-1.0); | 
 | 742 |   q.x=(-1.0); | 
 | 743 |   q.y=(-1.0); | 
 | 744 |   start=0; | 
 | 745 |   for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) | 
 | 746 |   { | 
 | 747 |     code=LineToCode; | 
 | 748 |     if (coordinates <= 0) | 
 | 749 |       { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 750 |         coordinates=(ssize_t) primitive_info[i].coordinates; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 751 |         p=primitive_info[i].point; | 
 | 752 |         start=n; | 
 | 753 |         code=MoveToCode; | 
 | 754 |       } | 
 | 755 |     coordinates--; | 
 | 756 |     /* | 
 | 757 |       Eliminate duplicate points. | 
 | 758 |     */ | 
 | 759 |     if ((i == 0) || (fabs(q.x-primitive_info[i].point.x) > MagickEpsilon) || | 
 | 760 |         (fabs(q.y-primitive_info[i].point.y) > MagickEpsilon)) | 
 | 761 |       { | 
 | 762 |         path_info[n].code=code; | 
 | 763 |         path_info[n].point=primitive_info[i].point; | 
 | 764 |         q=primitive_info[i].point; | 
 | 765 |         n++; | 
 | 766 |       } | 
 | 767 |     if (coordinates > 0) | 
 | 768 |       continue; | 
 | 769 |     if ((fabs(p.x-primitive_info[i].point.x) <= MagickEpsilon) && | 
 | 770 |         (fabs(p.y-primitive_info[i].point.y) <= MagickEpsilon)) | 
 | 771 |       continue; | 
 | 772 |     /* | 
 | 773 |       Mark the p point as open if it does not match the q. | 
 | 774 |     */ | 
 | 775 |     path_info[start].code=OpenCode; | 
 | 776 |     path_info[n].code=GhostlineCode; | 
 | 777 |     path_info[n].point=primitive_info[i].point; | 
 | 778 |     n++; | 
 | 779 |     path_info[n].code=LineToCode; | 
 | 780 |     path_info[n].point=p; | 
 | 781 |     n++; | 
 | 782 |   } | 
 | 783 |   path_info[n].code=EndCode; | 
 | 784 |   path_info[n].point.x=0.0; | 
 | 785 |   path_info[n].point.y=0.0; | 
 | 786 |   if (IsEventLogging() != MagickFalse) | 
 | 787 |     LogPathInfo(path_info); | 
 | 788 |   return(path_info); | 
 | 789 | } | 
 | 790 |  | 
 | 791 | /* | 
 | 792 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 793 | %                                                                             % | 
 | 794 | %                                                                             % | 
 | 795 | %                                                                             % | 
 | 796 | %   D e s t r o y D r a w I n f o                                             % | 
 | 797 | %                                                                             % | 
 | 798 | %                                                                             % | 
 | 799 | %                                                                             % | 
 | 800 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 801 | % | 
 | 802 | %  DestroyDrawInfo() deallocates memory associated with an DrawInfo | 
 | 803 | %  structure. | 
 | 804 | % | 
 | 805 | %  The format of the DestroyDrawInfo method is: | 
 | 806 | % | 
 | 807 | %      DrawInfo *DestroyDrawInfo(DrawInfo *draw_info) | 
 | 808 | % | 
 | 809 | %  A description of each parameter follows: | 
 | 810 | % | 
 | 811 | %    o draw_info: the draw info. | 
 | 812 | % | 
 | 813 | */ | 
 | 814 | MagickExport DrawInfo *DestroyDrawInfo(DrawInfo *draw_info) | 
 | 815 | { | 
 | 816 |   if (draw_info->debug != MagickFalse) | 
 | 817 |     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); | 
 | 818 |   assert(draw_info != (DrawInfo *) NULL); | 
 | 819 |   assert(draw_info->signature == MagickSignature); | 
 | 820 |   if (draw_info->primitive != (char *) NULL) | 
 | 821 |     draw_info->primitive=DestroyString(draw_info->primitive); | 
 | 822 |   if (draw_info->text != (char *) NULL) | 
 | 823 |     draw_info->text=DestroyString(draw_info->text); | 
 | 824 |   if (draw_info->geometry != (char *) NULL) | 
 | 825 |     draw_info->geometry=DestroyString(draw_info->geometry); | 
 | 826 |   if (draw_info->tile != (Image *) NULL) | 
 | 827 |     draw_info->tile=DestroyImage(draw_info->tile); | 
 | 828 |   if (draw_info->fill_pattern != (Image *) NULL) | 
 | 829 |     draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern); | 
 | 830 |   if (draw_info->stroke_pattern != (Image *) NULL) | 
 | 831 |     draw_info->stroke_pattern=DestroyImage(draw_info->stroke_pattern); | 
 | 832 |   if (draw_info->font != (char *) NULL) | 
 | 833 |     draw_info->font=DestroyString(draw_info->font); | 
 | 834 |   if (draw_info->metrics != (char *) NULL) | 
 | 835 |     draw_info->metrics=DestroyString(draw_info->metrics); | 
 | 836 |   if (draw_info->family != (char *) NULL) | 
 | 837 |     draw_info->family=DestroyString(draw_info->family); | 
 | 838 |   if (draw_info->encoding != (char *) NULL) | 
 | 839 |     draw_info->encoding=DestroyString(draw_info->encoding); | 
 | 840 |   if (draw_info->density != (char *) NULL) | 
 | 841 |     draw_info->density=DestroyString(draw_info->density); | 
 | 842 |   if (draw_info->server_name != (char *) NULL) | 
 | 843 |     draw_info->server_name=(char *) | 
 | 844 |      RelinquishMagickMemory(draw_info->server_name); | 
 | 845 |   if (draw_info->dash_pattern != (double *) NULL) | 
 | 846 |     draw_info->dash_pattern=(double *) RelinquishMagickMemory( | 
 | 847 |       draw_info->dash_pattern); | 
 | 848 |   if (draw_info->gradient.stops != (StopInfo *) NULL) | 
 | 849 |     draw_info->gradient.stops=(StopInfo *) RelinquishMagickMemory( | 
 | 850 |       draw_info->gradient.stops); | 
 | 851 |   if (draw_info->clip_mask != (char *) NULL) | 
 | 852 |     draw_info->clip_mask=DestroyString(draw_info->clip_mask); | 
 | 853 |   draw_info->signature=(~MagickSignature); | 
 | 854 |   draw_info=(DrawInfo *) RelinquishMagickMemory(draw_info); | 
 | 855 |   return(draw_info); | 
 | 856 | } | 
 | 857 |  | 
 | 858 | /* | 
 | 859 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 860 | %                                                                             % | 
 | 861 | %                                                                             % | 
 | 862 | %                                                                             % | 
 | 863 | +   D e s t r o y E d g e                                                     % | 
 | 864 | %                                                                             % | 
 | 865 | %                                                                             % | 
 | 866 | %                                                                             % | 
 | 867 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 868 | % | 
 | 869 | %  DestroyEdge() destroys the specified polygon edge. | 
 | 870 | % | 
 | 871 | %  The format of the DestroyEdge method is: | 
 | 872 | % | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 873 | %      ssize_t DestroyEdge(PolygonInfo *polygon_info,const int edge) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 874 | % | 
 | 875 | %  A description of each parameter follows: | 
 | 876 | % | 
 | 877 | %    o polygon_info: Specifies a pointer to an PolygonInfo structure. | 
 | 878 | % | 
 | 879 | %    o edge: the polygon edge number to destroy. | 
 | 880 | % | 
 | 881 | */ | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 882 | static size_t DestroyEdge(PolygonInfo *polygon_info, | 
 | 883 |   const size_t edge) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 884 | { | 
 | 885 |   assert(edge < polygon_info->number_edges); | 
 | 886 |   polygon_info->edges[edge].points=(PointInfo *) RelinquishMagickMemory( | 
 | 887 |     polygon_info->edges[edge].points); | 
 | 888 |   polygon_info->number_edges--; | 
 | 889 |   if (edge < polygon_info->number_edges) | 
 | 890 |     (void) CopyMagickMemory(polygon_info->edges+edge,polygon_info->edges+edge+1, | 
 | 891 |       (size_t) (polygon_info->number_edges-edge)*sizeof(*polygon_info->edges)); | 
 | 892 |   return(polygon_info->number_edges); | 
 | 893 | } | 
 | 894 |  | 
 | 895 | /* | 
 | 896 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 897 | %                                                                             % | 
 | 898 | %                                                                             % | 
 | 899 | %                                                                             % | 
 | 900 | +   D e s t r o y P o l y g o n I n f o                                       % | 
 | 901 | %                                                                             % | 
 | 902 | %                                                                             % | 
 | 903 | %                                                                             % | 
 | 904 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 905 | % | 
 | 906 | %  DestroyPolygonInfo() destroys the PolygonInfo data structure. | 
 | 907 | % | 
 | 908 | %  The format of the DestroyPolygonInfo method is: | 
 | 909 | % | 
 | 910 | %      PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info) | 
 | 911 | % | 
 | 912 | %  A description of each parameter follows: | 
 | 913 | % | 
 | 914 | %    o polygon_info: Specifies a pointer to an PolygonInfo structure. | 
 | 915 | % | 
 | 916 | */ | 
 | 917 | static PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info) | 
 | 918 | { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 919 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 920 |     i; | 
 | 921 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 922 |   for (i=0; i < (ssize_t) polygon_info->number_edges; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 923 |     polygon_info->edges[i].points=(PointInfo *) | 
 | 924 |       RelinquishMagickMemory(polygon_info->edges[i].points); | 
 | 925 |   polygon_info->edges=(EdgeInfo *) RelinquishMagickMemory(polygon_info->edges); | 
 | 926 |   return((PolygonInfo *) RelinquishMagickMemory(polygon_info)); | 
 | 927 | } | 
 | 928 |  | 
 | 929 | /* | 
 | 930 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 931 | %                                                                             % | 
 | 932 | %                                                                             % | 
 | 933 | %                                                                             % | 
 | 934 | %     D r a w A f f i n e I m a g e                                           % | 
 | 935 | %                                                                             % | 
 | 936 | %                                                                             % | 
 | 937 | %                                                                             % | 
 | 938 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 939 | % | 
 | 940 | %  DrawAffineImage() composites the source over the destination image as | 
 | 941 | %  dictated by the affine transform. | 
 | 942 | % | 
 | 943 | %  The format of the DrawAffineImage method is: | 
 | 944 | % | 
 | 945 | %      MagickBooleanType DrawAffineImage(Image *image,const Image *source, | 
 | 946 | %        const AffineMatrix *affine) | 
 | 947 | % | 
 | 948 | %  A description of each parameter follows: | 
 | 949 | % | 
 | 950 | %    o image: the image. | 
 | 951 | % | 
 | 952 | %    o source: the source image. | 
 | 953 | % | 
 | 954 | %    o affine: the affine transform. | 
 | 955 | % | 
 | 956 | */ | 
 | 957 | static SegmentInfo AffineEdge(const Image *image,const AffineMatrix *affine, | 
 | 958 |   const double y,const SegmentInfo *edge) | 
 | 959 | { | 
 | 960 |   double | 
 | 961 |     intercept, | 
 | 962 |     z; | 
 | 963 |  | 
 | 964 |   register double | 
 | 965 |     x; | 
 | 966 |  | 
 | 967 |   SegmentInfo | 
 | 968 |     inverse_edge; | 
 | 969 |  | 
 | 970 |   /* | 
 | 971 |     Determine left and right edges. | 
 | 972 |   */ | 
 | 973 |   inverse_edge.x1=edge->x1; | 
 | 974 |   inverse_edge.y1=edge->y1; | 
 | 975 |   inverse_edge.x2=edge->x2; | 
 | 976 |   inverse_edge.y2=edge->y2; | 
 | 977 |   z=affine->ry*y+affine->tx; | 
 | 978 |   if (affine->sx > MagickEpsilon) | 
 | 979 |     { | 
 | 980 |       intercept=(-z/affine->sx); | 
 | 981 |       x=intercept+MagickEpsilon; | 
 | 982 |       if (x > inverse_edge.x1) | 
 | 983 |         inverse_edge.x1=x; | 
 | 984 |       intercept=(-z+(double) image->columns)/affine->sx; | 
 | 985 |       x=intercept-MagickEpsilon; | 
 | 986 |       if (x < inverse_edge.x2) | 
 | 987 |         inverse_edge.x2=x; | 
 | 988 |     } | 
 | 989 |   else | 
 | 990 |     if (affine->sx < -MagickEpsilon) | 
 | 991 |       { | 
 | 992 |         intercept=(-z+(double) image->columns)/affine->sx; | 
 | 993 |         x=intercept+MagickEpsilon; | 
 | 994 |         if (x > inverse_edge.x1) | 
 | 995 |           inverse_edge.x1=x; | 
 | 996 |         intercept=(-z/affine->sx); | 
 | 997 |         x=intercept-MagickEpsilon; | 
 | 998 |         if (x < inverse_edge.x2) | 
 | 999 |           inverse_edge.x2=x; | 
 | 1000 |       } | 
 | 1001 |     else | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1002 |       if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->columns)) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1003 |         { | 
 | 1004 |           inverse_edge.x2=edge->x1; | 
 | 1005 |           return(inverse_edge); | 
 | 1006 |         } | 
 | 1007 |   /* | 
 | 1008 |     Determine top and bottom edges. | 
 | 1009 |   */ | 
 | 1010 |   z=affine->sy*y+affine->ty; | 
 | 1011 |   if (affine->rx > MagickEpsilon) | 
 | 1012 |     { | 
 | 1013 |       intercept=(-z/affine->rx); | 
 | 1014 |       x=intercept+MagickEpsilon; | 
 | 1015 |       if (x > inverse_edge.x1) | 
 | 1016 |         inverse_edge.x1=x; | 
 | 1017 |       intercept=(-z+(double) image->rows)/affine->rx; | 
 | 1018 |       x=intercept-MagickEpsilon; | 
 | 1019 |       if (x < inverse_edge.x2) | 
 | 1020 |         inverse_edge.x2=x; | 
 | 1021 |     } | 
 | 1022 |   else | 
 | 1023 |     if (affine->rx < -MagickEpsilon) | 
 | 1024 |       { | 
 | 1025 |         intercept=(-z+(double) image->rows)/affine->rx; | 
 | 1026 |         x=intercept+MagickEpsilon; | 
 | 1027 |         if (x > inverse_edge.x1) | 
 | 1028 |           inverse_edge.x1=x; | 
 | 1029 |         intercept=(-z/affine->rx); | 
 | 1030 |         x=intercept-MagickEpsilon; | 
 | 1031 |         if (x < inverse_edge.x2) | 
 | 1032 |           inverse_edge.x2=x; | 
 | 1033 |       } | 
 | 1034 |     else | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1035 |       if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->rows)) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1036 |         { | 
 | 1037 |           inverse_edge.x2=edge->x2; | 
 | 1038 |           return(inverse_edge); | 
 | 1039 |         } | 
 | 1040 |   return(inverse_edge); | 
 | 1041 | } | 
 | 1042 |  | 
 | 1043 | static AffineMatrix InverseAffineMatrix(const AffineMatrix *affine) | 
 | 1044 | { | 
 | 1045 |   AffineMatrix | 
 | 1046 |     inverse_affine; | 
 | 1047 |  | 
 | 1048 |   double | 
 | 1049 |     determinant; | 
 | 1050 |  | 
 | 1051 |   determinant=1.0/(affine->sx*affine->sy-affine->rx*affine->ry); | 
 | 1052 |   inverse_affine.sx=determinant*affine->sy; | 
 | 1053 |   inverse_affine.rx=determinant*(-affine->rx); | 
 | 1054 |   inverse_affine.ry=determinant*(-affine->ry); | 
 | 1055 |   inverse_affine.sy=determinant*affine->sx; | 
 | 1056 |   inverse_affine.tx=(-affine->tx)*inverse_affine.sx-affine->ty* | 
 | 1057 |     inverse_affine.ry; | 
 | 1058 |   inverse_affine.ty=(-affine->tx)*inverse_affine.rx-affine->ty* | 
 | 1059 |     inverse_affine.sy; | 
 | 1060 |   return(inverse_affine); | 
 | 1061 | } | 
 | 1062 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1063 | static inline ssize_t MagickAbsoluteValue(const ssize_t x) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1064 | { | 
 | 1065 |   if (x < 0) | 
 | 1066 |     return(-x); | 
 | 1067 |   return(x); | 
 | 1068 | } | 
 | 1069 |  | 
 | 1070 | static inline double MagickMax(const double x,const double y) | 
 | 1071 | { | 
 | 1072 |   if (x > y) | 
 | 1073 |     return(x); | 
 | 1074 |   return(y); | 
 | 1075 | } | 
 | 1076 |  | 
 | 1077 | static inline double MagickMin(const double x,const double y) | 
 | 1078 | { | 
 | 1079 |   if (x < y) | 
 | 1080 |     return(x); | 
 | 1081 |   return(y); | 
 | 1082 | } | 
 | 1083 |  | 
 | 1084 | MagickExport MagickBooleanType DrawAffineImage(Image *image, | 
 | 1085 |   const Image *source,const AffineMatrix *affine) | 
 | 1086 | { | 
 | 1087 |   AffineMatrix | 
 | 1088 |     inverse_affine; | 
 | 1089 |  | 
| cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 1090 |   CacheView | 
 | 1091 |     *image_view, | 
 | 1092 |     *source_view; | 
 | 1093 |  | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1094 |   ExceptionInfo | 
 | 1095 |     *exception; | 
 | 1096 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1097 |   ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1098 |     y; | 
 | 1099 |  | 
 | 1100 |   MagickBooleanType | 
 | 1101 |     status; | 
 | 1102 |  | 
 | 1103 |   MagickPixelPacket | 
 | 1104 |     zero; | 
 | 1105 |  | 
 | 1106 |   PointInfo | 
 | 1107 |     extent[4], | 
 | 1108 |     min, | 
 | 1109 |     max, | 
 | 1110 |     point; | 
 | 1111 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1112 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1113 |     i; | 
 | 1114 |  | 
 | 1115 |   ResampleFilter | 
| cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 1116 |     **restrict resample_filter; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1117 |  | 
 | 1118 |   SegmentInfo | 
 | 1119 |     edge; | 
 | 1120 |  | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1121 |   /* | 
 | 1122 |     Determine bounding box. | 
 | 1123 |   */ | 
 | 1124 |   assert(image != (Image *) NULL); | 
 | 1125 |   assert(image->signature == MagickSignature); | 
 | 1126 |   if (image->debug != MagickFalse) | 
 | 1127 |     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); | 
 | 1128 |   assert(source != (const Image *) NULL); | 
 | 1129 |   assert(source->signature == MagickSignature); | 
 | 1130 |   assert(affine != (AffineMatrix *) NULL); | 
 | 1131 |   extent[0].x=0.0; | 
 | 1132 |   extent[0].y=0.0; | 
 | 1133 |   extent[1].x=(double) source->columns-1.0; | 
 | 1134 |   extent[1].y=0.0; | 
 | 1135 |   extent[2].x=(double) source->columns-1.0; | 
 | 1136 |   extent[2].y=(double) source->rows-1.0; | 
 | 1137 |   extent[3].x=0.0; | 
 | 1138 |   extent[3].y=(double) source->rows-1.0; | 
 | 1139 |   for (i=0; i < 4; i++) | 
 | 1140 |   { | 
 | 1141 |     point=extent[i]; | 
 | 1142 |     extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx; | 
 | 1143 |     extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty; | 
 | 1144 |   } | 
 | 1145 |   min=extent[0]; | 
 | 1146 |   max=extent[0]; | 
 | 1147 |   for (i=1; i < 4; i++) | 
 | 1148 |   { | 
 | 1149 |     if (min.x > extent[i].x) | 
 | 1150 |       min.x=extent[i].x; | 
 | 1151 |     if (min.y > extent[i].y) | 
 | 1152 |       min.y=extent[i].y; | 
 | 1153 |     if (max.x < extent[i].x) | 
 | 1154 |       max.x=extent[i].x; | 
 | 1155 |     if (max.y < extent[i].y) | 
 | 1156 |       max.y=extent[i].y; | 
 | 1157 |   } | 
 | 1158 |   /* | 
 | 1159 |     Affine transform image. | 
 | 1160 |   */ | 
 | 1161 |   if (SetImageStorageClass(image,DirectClass) == MagickFalse) | 
 | 1162 |     return(MagickFalse); | 
 | 1163 |   status=MagickTrue; | 
 | 1164 |   edge.x1=MagickMax(min.x,0.0); | 
 | 1165 |   edge.y1=MagickMax(min.y,0.0); | 
 | 1166 |   edge.x2=MagickMin(max.x,(double) image->columns-1.0); | 
 | 1167 |   edge.y2=MagickMin(max.y,(double) image->rows-1.0); | 
 | 1168 |   inverse_affine=InverseAffineMatrix(affine); | 
 | 1169 |   GetMagickPixelPacket(image,&zero); | 
 | 1170 |   exception=(&image->exception); | 
| cristy | b2a11ae | 2010-02-22 00:53:36 +0000 | [diff] [blame] | 1171 |   resample_filter=AcquireResampleFilterThreadSet(source, | 
 | 1172 |     UndefinedVirtualPixelMethod,MagickTrue,exception); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1173 |   image_view=AcquireCacheView(image); | 
 | 1174 |   source_view=AcquireCacheView(source); | 
| cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 1175 | #if defined(MAGICKCORE_OPENMP_SUPPORT) | 
 | 1176 |   #pragma omp parallel for schedule(dynamic,4) shared(status) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1177 | #endif | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1178 |   for (y=(ssize_t) ceil(edge.y1-0.5); y <= (ssize_t) floor(edge.y2+0.5); y++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1179 |   { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1180 |     ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1181 |       x_offset; | 
 | 1182 |  | 
 | 1183 |     MagickPixelPacket | 
 | 1184 |       composite, | 
 | 1185 |       pixel; | 
 | 1186 |  | 
 | 1187 |     PointInfo | 
 | 1188 |       point; | 
 | 1189 |  | 
 | 1190 |     register IndexPacket | 
| cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1191 |       *restrict indexes; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1192 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1193 |     register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1194 |       id, | 
 | 1195 |       x; | 
 | 1196 |  | 
 | 1197 |     register PixelPacket | 
| cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1198 |       *restrict q; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1199 |  | 
 | 1200 |     SegmentInfo | 
 | 1201 |       inverse_edge; | 
 | 1202 |  | 
 | 1203 |     inverse_edge=AffineEdge(source,&inverse_affine,(double) y,&edge); | 
 | 1204 |     if (inverse_edge.x2 < inverse_edge.x1) | 
 | 1205 |       continue; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1206 |     q=GetCacheViewAuthenticPixels(image_view,(ssize_t) ceil(inverse_edge.x1-0.5),y, | 
 | 1207 |       (size_t) ((ssize_t) floor(inverse_edge.x2+0.5)-(ssize_t) floor( | 
| cristy | 06609ee | 2010-03-17 20:21:27 +0000 | [diff] [blame] | 1208 |       inverse_edge.x1+0.5)+1),1,exception); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1209 |     if (q == (PixelPacket *) NULL) | 
 | 1210 |       continue; | 
 | 1211 |     id=GetOpenMPThreadId(); | 
 | 1212 |     indexes=GetCacheViewAuthenticIndexQueue(image_view); | 
 | 1213 |     pixel=zero; | 
 | 1214 |     composite=zero; | 
 | 1215 |     x_offset=0; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1216 |     for (x=(ssize_t) ceil(inverse_edge.x1-0.5); x <= (ssize_t) floor(inverse_edge.x2+0.5); x++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1217 |     { | 
 | 1218 |       point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+ | 
 | 1219 |         inverse_affine.tx; | 
 | 1220 |       point.y=(double) x*inverse_affine.rx+y*inverse_affine.sy+ | 
 | 1221 |         inverse_affine.ty; | 
 | 1222 |       (void) ResamplePixelColor(resample_filter[id],point.x,point.y,&pixel); | 
 | 1223 |       SetMagickPixelPacket(image,q,indexes+x_offset,&composite); | 
 | 1224 |       MagickPixelCompositeOver(&pixel,pixel.opacity,&composite, | 
 | 1225 |         composite.opacity,&composite); | 
 | 1226 |       SetPixelPacket(image,&composite,q,indexes+x_offset); | 
 | 1227 |       x_offset++; | 
 | 1228 |       q++; | 
 | 1229 |     } | 
 | 1230 |     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) | 
 | 1231 |       status=MagickFalse; | 
 | 1232 |   } | 
 | 1233 |   resample_filter=DestroyResampleFilterThreadSet(resample_filter); | 
 | 1234 |   source_view=DestroyCacheView(source_view); | 
 | 1235 |   image_view=DestroyCacheView(image_view); | 
 | 1236 |   return(status); | 
 | 1237 | } | 
 | 1238 |  | 
 | 1239 | /* | 
 | 1240 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 1241 | %                                                                             % | 
 | 1242 | %                                                                             % | 
 | 1243 | %                                                                             % | 
 | 1244 | +   D r a w B o u n d i n g R e c t a n g l e s                               % | 
 | 1245 | %                                                                             % | 
 | 1246 | %                                                                             % | 
 | 1247 | %                                                                             % | 
 | 1248 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 1249 | % | 
 | 1250 | %  DrawBoundingRectangles() draws the bounding rectangles on the image.  This | 
 | 1251 | %  is only useful for developers debugging the rendering algorithm. | 
 | 1252 | % | 
 | 1253 | %  The format of the DrawBoundingRectangles method is: | 
 | 1254 | % | 
 | 1255 | %      void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info, | 
 | 1256 | %        PolygonInfo *polygon_info) | 
 | 1257 | % | 
 | 1258 | %  A description of each parameter follows: | 
 | 1259 | % | 
 | 1260 | %    o image: the image. | 
 | 1261 | % | 
 | 1262 | %    o draw_info: the draw info. | 
 | 1263 | % | 
 | 1264 | %    o polygon_info: Specifies a pointer to a PolygonInfo structure. | 
 | 1265 | % | 
 | 1266 | */ | 
 | 1267 | static void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info, | 
 | 1268 |   const PolygonInfo *polygon_info) | 
 | 1269 | { | 
 | 1270 |   DrawInfo | 
 | 1271 |     *clone_info; | 
 | 1272 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1273 |   ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1274 |     coordinates; | 
 | 1275 |  | 
 | 1276 |   MagickRealType | 
 | 1277 |     mid; | 
 | 1278 |  | 
 | 1279 |   PointInfo | 
 | 1280 |     end, | 
 | 1281 |     resolution, | 
 | 1282 |     start; | 
 | 1283 |  | 
 | 1284 |   PrimitiveInfo | 
 | 1285 |     primitive_info[6]; | 
 | 1286 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1287 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1288 |     i; | 
 | 1289 |  | 
 | 1290 |   SegmentInfo | 
 | 1291 |     bounds; | 
 | 1292 |  | 
 | 1293 |   clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); | 
 | 1294 |   (void) QueryColorDatabase("#0000",&clone_info->fill,&image->exception); | 
 | 1295 |   resolution.x=DefaultResolution; | 
 | 1296 |   resolution.y=DefaultResolution; | 
 | 1297 |   if (clone_info->density != (char *) NULL) | 
 | 1298 |     { | 
 | 1299 |       GeometryInfo | 
 | 1300 |         geometry_info; | 
 | 1301 |  | 
 | 1302 |       MagickStatusType | 
 | 1303 |         flags; | 
 | 1304 |  | 
 | 1305 |       flags=ParseGeometry(clone_info->density,&geometry_info); | 
 | 1306 |       resolution.x=geometry_info.rho; | 
 | 1307 |       resolution.y=geometry_info.sigma; | 
 | 1308 |       if ((flags & SigmaValue) == MagickFalse) | 
 | 1309 |         resolution.y=resolution.x; | 
 | 1310 |     } | 
 | 1311 |   mid=(resolution.x/72.0)*ExpandAffine(&clone_info->affine)* | 
 | 1312 |     clone_info->stroke_width/2.0; | 
 | 1313 |   bounds.x1=0.0; | 
 | 1314 |   bounds.y1=0.0; | 
 | 1315 |   bounds.x2=0.0; | 
 | 1316 |   bounds.y2=0.0; | 
 | 1317 |   if (polygon_info != (PolygonInfo *) NULL) | 
 | 1318 |     { | 
 | 1319 |       bounds=polygon_info->edges[0].bounds; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1320 |       for (i=1; i < (ssize_t) polygon_info->number_edges; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1321 |       { | 
 | 1322 |         if (polygon_info->edges[i].bounds.x1 < (double) bounds.x1) | 
 | 1323 |           bounds.x1=polygon_info->edges[i].bounds.x1; | 
 | 1324 |         if (polygon_info->edges[i].bounds.y1 < (double) bounds.y1) | 
 | 1325 |           bounds.y1=polygon_info->edges[i].bounds.y1; | 
 | 1326 |         if (polygon_info->edges[i].bounds.x2 > (double) bounds.x2) | 
 | 1327 |           bounds.x2=polygon_info->edges[i].bounds.x2; | 
 | 1328 |         if (polygon_info->edges[i].bounds.y2 > (double) bounds.y2) | 
 | 1329 |           bounds.y2=polygon_info->edges[i].bounds.y2; | 
 | 1330 |       } | 
 | 1331 |       bounds.x1-=mid; | 
 | 1332 |       bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double) | 
 | 1333 |         image->columns ? (double) image->columns-1 : bounds.x1; | 
 | 1334 |       bounds.y1-=mid; | 
 | 1335 |       bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double) | 
 | 1336 |         image->rows ? (double) image->rows-1 : bounds.y1; | 
 | 1337 |       bounds.x2+=mid; | 
 | 1338 |       bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double) | 
 | 1339 |         image->columns ? (double) image->columns-1 : bounds.x2; | 
 | 1340 |       bounds.y2+=mid; | 
 | 1341 |       bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double) | 
 | 1342 |         image->rows ? (double) image->rows-1 : bounds.y2; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1343 |       for (i=0; i < (ssize_t) polygon_info->number_edges; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1344 |       { | 
 | 1345 |         if (polygon_info->edges[i].direction != 0) | 
 | 1346 |           (void) QueryColorDatabase("red",&clone_info->stroke, | 
 | 1347 |             &image->exception); | 
 | 1348 |         else | 
 | 1349 |           (void) QueryColorDatabase("green",&clone_info->stroke, | 
 | 1350 |             &image->exception); | 
 | 1351 |         start.x=(double) (polygon_info->edges[i].bounds.x1-mid); | 
 | 1352 |         start.y=(double) (polygon_info->edges[i].bounds.y1-mid); | 
 | 1353 |         end.x=(double) (polygon_info->edges[i].bounds.x2+mid); | 
 | 1354 |         end.y=(double) (polygon_info->edges[i].bounds.y2+mid); | 
 | 1355 |         primitive_info[0].primitive=RectanglePrimitive; | 
 | 1356 |         TraceRectangle(primitive_info,start,end); | 
 | 1357 |         primitive_info[0].method=ReplaceMethod; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1358 |         coordinates=(ssize_t) primitive_info[0].coordinates; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1359 |         primitive_info[coordinates].primitive=UndefinedPrimitive; | 
 | 1360 |         (void) DrawPrimitive(image,clone_info,primitive_info); | 
 | 1361 |       } | 
 | 1362 |     } | 
 | 1363 |   (void) QueryColorDatabase("blue",&clone_info->stroke,&image->exception); | 
 | 1364 |   start.x=(double) (bounds.x1-mid); | 
 | 1365 |   start.y=(double) (bounds.y1-mid); | 
 | 1366 |   end.x=(double) (bounds.x2+mid); | 
 | 1367 |   end.y=(double) (bounds.y2+mid); | 
 | 1368 |   primitive_info[0].primitive=RectanglePrimitive; | 
 | 1369 |   TraceRectangle(primitive_info,start,end); | 
 | 1370 |   primitive_info[0].method=ReplaceMethod; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1371 |   coordinates=(ssize_t) primitive_info[0].coordinates; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1372 |   primitive_info[coordinates].primitive=UndefinedPrimitive; | 
 | 1373 |   (void) DrawPrimitive(image,clone_info,primitive_info); | 
 | 1374 |   clone_info=DestroyDrawInfo(clone_info); | 
 | 1375 | } | 
 | 1376 |  | 
 | 1377 | /* | 
 | 1378 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 1379 | %                                                                             % | 
 | 1380 | %                                                                             % | 
 | 1381 | %                                                                             % | 
 | 1382 | %   D r a w C l i p P a t h                                                   % | 
 | 1383 | %                                                                             % | 
 | 1384 | %                                                                             % | 
 | 1385 | %                                                                             % | 
 | 1386 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 1387 | % | 
 | 1388 | %  DrawClipPath() draws the clip path on the image mask. | 
 | 1389 | % | 
 | 1390 | %  The format of the DrawClipPath method is: | 
 | 1391 | % | 
 | 1392 | %      MagickBooleanType DrawClipPath(Image *image,const DrawInfo *draw_info, | 
 | 1393 | %        const char *name) | 
 | 1394 | % | 
 | 1395 | %  A description of each parameter follows: | 
 | 1396 | % | 
 | 1397 | %    o image: the image. | 
 | 1398 | % | 
 | 1399 | %    o draw_info: the draw info. | 
 | 1400 | % | 
 | 1401 | %    o name: the name of the clip path. | 
 | 1402 | % | 
 | 1403 | */ | 
 | 1404 | MagickExport MagickBooleanType DrawClipPath(Image *image, | 
 | 1405 |   const DrawInfo *draw_info,const char *name) | 
 | 1406 | { | 
 | 1407 |   char | 
 | 1408 |     clip_mask[MaxTextExtent]; | 
 | 1409 |  | 
 | 1410 |   const char | 
 | 1411 |     *value; | 
 | 1412 |  | 
 | 1413 |   DrawInfo | 
 | 1414 |     *clone_info; | 
 | 1415 |  | 
 | 1416 |   MagickStatusType | 
 | 1417 |     status; | 
 | 1418 |  | 
 | 1419 |   assert(image != (Image *) NULL); | 
 | 1420 |   assert(image->signature == MagickSignature); | 
 | 1421 |   if (image->debug != MagickFalse) | 
 | 1422 |     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); | 
 | 1423 |   assert(draw_info != (const DrawInfo *) NULL); | 
 | 1424 |   (void) FormatMagickString(clip_mask,MaxTextExtent,"%s",name); | 
 | 1425 |   value=GetImageArtifact(image,clip_mask); | 
 | 1426 |   if (value == (const char *) NULL) | 
 | 1427 |     return(MagickFalse); | 
 | 1428 |   if (image->clip_mask == (Image *) NULL) | 
 | 1429 |     { | 
 | 1430 |       Image | 
 | 1431 |         *clip_mask; | 
 | 1432 |  | 
 | 1433 |       clip_mask=CloneImage(image,image->columns,image->rows,MagickTrue, | 
 | 1434 |         &image->exception); | 
 | 1435 |       if (clip_mask == (Image *) NULL) | 
 | 1436 |         return(MagickFalse); | 
 | 1437 |       (void) SetImageClipMask(image,clip_mask); | 
 | 1438 |       clip_mask=DestroyImage(clip_mask); | 
 | 1439 |     } | 
 | 1440 |   (void) QueryColorDatabase("#00000000",&image->clip_mask->background_color, | 
 | 1441 |     &image->exception); | 
 | 1442 |   image->clip_mask->background_color.opacity=(Quantum) TransparentOpacity; | 
 | 1443 |   (void) SetImageBackgroundColor(image->clip_mask); | 
 | 1444 |   if (image->debug != MagickFalse) | 
 | 1445 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(),"\nbegin clip-path %s", | 
 | 1446 |       draw_info->clip_mask); | 
 | 1447 |   clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); | 
 | 1448 |   (void) CloneString(&clone_info->primitive,value); | 
 | 1449 |   (void) QueryColorDatabase("#ffffff",&clone_info->fill,&image->exception); | 
 | 1450 |   clone_info->clip_mask=(char *) NULL; | 
 | 1451 |   status=DrawImage(image->clip_mask,clone_info); | 
 | 1452 |   status|=NegateImage(image->clip_mask,MagickFalse); | 
 | 1453 |   clone_info=DestroyDrawInfo(clone_info); | 
 | 1454 |   if (image->debug != MagickFalse) | 
 | 1455 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end clip-path"); | 
 | 1456 |   return(status != 0 ? MagickTrue : MagickFalse); | 
 | 1457 | } | 
 | 1458 |  | 
 | 1459 | /* | 
 | 1460 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 1461 | %                                                                             % | 
 | 1462 | %                                                                             % | 
 | 1463 | %                                                                             % | 
 | 1464 | +   D r a w D a s h P o l y g o n                                             % | 
 | 1465 | %                                                                             % | 
 | 1466 | %                                                                             % | 
 | 1467 | %                                                                             % | 
 | 1468 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 1469 | % | 
 | 1470 | %  DrawDashPolygon() draws a dashed polygon (line, rectangle, ellipse) on the | 
 | 1471 | %  image while respecting the dash offset and dash pattern attributes. | 
 | 1472 | % | 
 | 1473 | %  The format of the DrawDashPolygon method is: | 
 | 1474 | % | 
 | 1475 | %      MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info, | 
 | 1476 | %        const PrimitiveInfo *primitive_info,Image *image) | 
 | 1477 | % | 
 | 1478 | %  A description of each parameter follows: | 
 | 1479 | % | 
 | 1480 | %    o draw_info: the draw info. | 
 | 1481 | % | 
 | 1482 | %    o primitive_info: Specifies a pointer to a PrimitiveInfo structure. | 
 | 1483 | % | 
 | 1484 | %    o image: the image. | 
 | 1485 | % | 
 | 1486 | % | 
 | 1487 | */ | 
 | 1488 | static MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info, | 
 | 1489 |   const PrimitiveInfo *primitive_info,Image *image) | 
 | 1490 | { | 
 | 1491 |   DrawInfo | 
 | 1492 |     *clone_info; | 
 | 1493 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1494 |   ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1495 |     j, | 
 | 1496 |     n; | 
 | 1497 |  | 
 | 1498 |   MagickRealType | 
 | 1499 |     length, | 
 | 1500 |     maximum_length, | 
 | 1501 |     offset, | 
 | 1502 |     scale, | 
 | 1503 |     total_length; | 
 | 1504 |  | 
 | 1505 |   MagickStatusType | 
 | 1506 |     status; | 
 | 1507 |  | 
 | 1508 |   PrimitiveInfo | 
 | 1509 |     *dash_polygon; | 
 | 1510 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1511 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1512 |     i; | 
 | 1513 |  | 
 | 1514 |   register MagickRealType | 
 | 1515 |     dx, | 
 | 1516 |     dy; | 
 | 1517 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1518 |   size_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1519 |     number_vertices; | 
 | 1520 |  | 
 | 1521 |   assert(draw_info != (const DrawInfo *) NULL); | 
 | 1522 |   if (image->debug != MagickFalse) | 
 | 1523 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(),"    begin draw-dash"); | 
 | 1524 |   clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); | 
 | 1525 |   clone_info->miterlimit=0; | 
 | 1526 |   for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1527 |   number_vertices=(size_t) i; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1528 |   dash_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t) | 
 | 1529 |     (2UL*number_vertices+1UL),sizeof(*dash_polygon)); | 
 | 1530 |   if (dash_polygon == (PrimitiveInfo *) NULL) | 
 | 1531 |     return(MagickFalse); | 
 | 1532 |   dash_polygon[0]=primitive_info[0]; | 
 | 1533 |   scale=ExpandAffine(&draw_info->affine); | 
 | 1534 |   length=scale*(draw_info->dash_pattern[0]-0.5); | 
 | 1535 |   offset=draw_info->dash_offset != 0.0 ? scale*draw_info->dash_offset : 0.0; | 
 | 1536 |   j=1; | 
 | 1537 |   for (n=0; offset > 0.0; j=0) | 
 | 1538 |   { | 
 | 1539 |     if (draw_info->dash_pattern[n] <= 0.0) | 
 | 1540 |       break; | 
 | 1541 |     length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5)); | 
 | 1542 |     if (offset > length) | 
 | 1543 |       { | 
 | 1544 |         offset-=length; | 
 | 1545 |         n++; | 
 | 1546 |         length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5)); | 
 | 1547 |         continue; | 
 | 1548 |       } | 
 | 1549 |     if (offset < length) | 
 | 1550 |       { | 
 | 1551 |         length-=offset; | 
 | 1552 |         offset=0.0; | 
 | 1553 |         break; | 
 | 1554 |       } | 
 | 1555 |     offset=0.0; | 
 | 1556 |     n++; | 
 | 1557 |   } | 
 | 1558 |   status=MagickTrue; | 
 | 1559 |   maximum_length=0.0; | 
 | 1560 |   total_length=0.0; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1561 |   for (i=1; i < (ssize_t) number_vertices; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1562 |   { | 
 | 1563 |     dx=primitive_info[i].point.x-primitive_info[i-1].point.x; | 
 | 1564 |     dy=primitive_info[i].point.y-primitive_info[i-1].point.y; | 
 | 1565 |     maximum_length=hypot((double) dx,dy); | 
 | 1566 |     if (length == 0.0) | 
 | 1567 |       { | 
 | 1568 |         n++; | 
 | 1569 |         if (draw_info->dash_pattern[n] == 0.0) | 
 | 1570 |           n=0; | 
 | 1571 |         length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5)); | 
 | 1572 |       } | 
 | 1573 |     for (total_length=0.0; (total_length+length) < maximum_length; ) | 
 | 1574 |     { | 
 | 1575 |       total_length+=length; | 
 | 1576 |       if ((n & 0x01) != 0) | 
 | 1577 |         { | 
 | 1578 |           dash_polygon[0]=primitive_info[0]; | 
 | 1579 |           dash_polygon[0].point.x=(double) (primitive_info[i-1].point.x+dx* | 
 | 1580 |             total_length/maximum_length); | 
 | 1581 |           dash_polygon[0].point.y=(double) (primitive_info[i-1].point.y+dy* | 
 | 1582 |             total_length/maximum_length); | 
 | 1583 |           j=1; | 
 | 1584 |         } | 
 | 1585 |       else | 
 | 1586 |         { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1587 |           if ((j+1) > (ssize_t) (2*number_vertices)) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1588 |             break; | 
 | 1589 |           dash_polygon[j]=primitive_info[i-1]; | 
 | 1590 |           dash_polygon[j].point.x=(double) (primitive_info[i-1].point.x+dx* | 
 | 1591 |             total_length/maximum_length); | 
 | 1592 |           dash_polygon[j].point.y=(double) (primitive_info[i-1].point.y+dy* | 
 | 1593 |             total_length/maximum_length); | 
 | 1594 |           dash_polygon[j].coordinates=1; | 
 | 1595 |           j++; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1596 |           dash_polygon[0].coordinates=(size_t) j; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1597 |           dash_polygon[j].primitive=UndefinedPrimitive; | 
 | 1598 |           status|=DrawStrokePolygon(image,clone_info,dash_polygon); | 
 | 1599 |         } | 
 | 1600 |       n++; | 
 | 1601 |       if (draw_info->dash_pattern[n] == 0.0) | 
 | 1602 |         n=0; | 
 | 1603 |       length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5)); | 
 | 1604 |     } | 
 | 1605 |     length-=(maximum_length-total_length); | 
 | 1606 |     if ((n & 0x01) != 0) | 
 | 1607 |       continue; | 
 | 1608 |     dash_polygon[j]=primitive_info[i]; | 
 | 1609 |     dash_polygon[j].coordinates=1; | 
 | 1610 |     j++; | 
 | 1611 |   } | 
 | 1612 |   if ((total_length < maximum_length) && ((n & 0x01) == 0) && (j > 1)) | 
 | 1613 |     { | 
 | 1614 |       dash_polygon[j]=primitive_info[i-1]; | 
 | 1615 |       dash_polygon[j].point.x+=MagickEpsilon; | 
 | 1616 |       dash_polygon[j].point.y+=MagickEpsilon; | 
 | 1617 |       dash_polygon[j].coordinates=1; | 
 | 1618 |       j++; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1619 |       dash_polygon[0].coordinates=(size_t) j; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1620 |       dash_polygon[j].primitive=UndefinedPrimitive; | 
 | 1621 |       status|=DrawStrokePolygon(image,clone_info,dash_polygon); | 
 | 1622 |     } | 
 | 1623 |   dash_polygon=(PrimitiveInfo *) RelinquishMagickMemory(dash_polygon); | 
 | 1624 |   clone_info=DestroyDrawInfo(clone_info); | 
 | 1625 |   if (image->debug != MagickFalse) | 
 | 1626 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(),"    end draw-dash"); | 
 | 1627 |   return(status != 0 ? MagickTrue : MagickFalse); | 
 | 1628 | } | 
 | 1629 |  | 
 | 1630 | /* | 
 | 1631 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 1632 | %                                                                             % | 
 | 1633 | %                                                                             % | 
 | 1634 | %                                                                             % | 
 | 1635 | %   D r a w I m a g e                                                         % | 
 | 1636 | %                                                                             % | 
 | 1637 | %                                                                             % | 
 | 1638 | %                                                                             % | 
 | 1639 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 1640 | % | 
 | 1641 | %  DrawImage() draws a graphic primitive on your image.  The primitive | 
 | 1642 | %  may be represented as a string or filename.  Precede the filename with an | 
 | 1643 | %  "at" sign (@) and the contents of the file are drawn on the image.  You | 
 | 1644 | %  can affect how text is drawn by setting one or more members of the draw | 
 | 1645 | %  info structure. | 
 | 1646 | % | 
 | 1647 | %  The format of the DrawImage method is: | 
 | 1648 | % | 
 | 1649 | %      MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info) | 
 | 1650 | % | 
 | 1651 | %  A description of each parameter follows: | 
 | 1652 | % | 
 | 1653 | %    o image: the image. | 
 | 1654 | % | 
 | 1655 | %    o draw_info: the draw info. | 
 | 1656 | % | 
 | 1657 | */ | 
 | 1658 |  | 
 | 1659 | static inline MagickBooleanType IsPoint(const char *point) | 
 | 1660 | { | 
 | 1661 |   char | 
 | 1662 |     *p; | 
 | 1663 |  | 
 | 1664 |   double | 
 | 1665 |     value; | 
 | 1666 |  | 
 | 1667 |   value=strtod(point,&p); | 
 | 1668 |   return((value == 0.0) && (p == point) ? MagickFalse : MagickTrue); | 
 | 1669 | } | 
 | 1670 |  | 
 | 1671 | static inline void TracePoint(PrimitiveInfo *primitive_info, | 
 | 1672 |   const PointInfo point) | 
 | 1673 | { | 
 | 1674 |   primitive_info->coordinates=1; | 
 | 1675 |   primitive_info->point=point; | 
 | 1676 | } | 
 | 1677 |  | 
 | 1678 | MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info) | 
 | 1679 | { | 
 | 1680 | #define RenderImageTag  "Render/Image" | 
 | 1681 |  | 
 | 1682 |   AffineMatrix | 
 | 1683 |     affine, | 
 | 1684 |     current; | 
 | 1685 |  | 
 | 1686 |   char | 
 | 1687 |     key[2*MaxTextExtent], | 
 | 1688 |     keyword[MaxTextExtent], | 
 | 1689 |     geometry[MaxTextExtent], | 
 | 1690 |     name[MaxTextExtent], | 
 | 1691 |     pattern[MaxTextExtent], | 
 | 1692 |     *primitive, | 
 | 1693 |     *token; | 
 | 1694 |  | 
 | 1695 |   const char | 
 | 1696 |     *q; | 
 | 1697 |  | 
 | 1698 |   DrawInfo | 
 | 1699 |     **graphic_context; | 
 | 1700 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1701 |   ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1702 |     j, | 
 | 1703 |     k, | 
 | 1704 |     n; | 
 | 1705 |  | 
 | 1706 |   MagickBooleanType | 
 | 1707 |     proceed, | 
 | 1708 |     status; | 
 | 1709 |  | 
 | 1710 |   MagickRealType | 
 | 1711 |     angle, | 
 | 1712 |     factor, | 
 | 1713 |     primitive_extent; | 
 | 1714 |  | 
 | 1715 |   PointInfo | 
 | 1716 |     point; | 
 | 1717 |  | 
 | 1718 |   PixelPacket | 
 | 1719 |     start_color; | 
 | 1720 |  | 
 | 1721 |   PrimitiveInfo | 
 | 1722 |     *primitive_info; | 
 | 1723 |  | 
 | 1724 |   PrimitiveType | 
 | 1725 |     primitive_type; | 
 | 1726 |  | 
 | 1727 |   register const char | 
 | 1728 |     *p; | 
 | 1729 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1730 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1731 |     i, | 
 | 1732 |     x; | 
 | 1733 |  | 
 | 1734 |   SegmentInfo | 
 | 1735 |     bounds; | 
 | 1736 |  | 
 | 1737 |   size_t | 
 | 1738 |     length; | 
 | 1739 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1740 |   size_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1741 |     number_points; | 
 | 1742 |  | 
 | 1743 |   /* | 
 | 1744 |     Ensure the annotation info is valid. | 
 | 1745 |   */ | 
 | 1746 |   assert(image != (Image *) NULL); | 
 | 1747 |   assert(image->signature == MagickSignature); | 
 | 1748 |   if (image->debug != MagickFalse) | 
 | 1749 |     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); | 
 | 1750 |   assert(draw_info != (DrawInfo *) NULL); | 
 | 1751 |   assert(draw_info->signature == MagickSignature); | 
 | 1752 |   if (image->debug != MagickFalse) | 
 | 1753 |     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); | 
 | 1754 |   if ((draw_info->primitive == (char *) NULL) || | 
 | 1755 |       (*draw_info->primitive == '\0')) | 
 | 1756 |     return(MagickFalse); | 
 | 1757 |   if (image->debug != MagickFalse) | 
 | 1758 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(),"begin draw-image"); | 
 | 1759 |   if (*draw_info->primitive != '@') | 
 | 1760 |     primitive=AcquireString(draw_info->primitive); | 
 | 1761 |   else | 
 | 1762 |     primitive=FileToString(draw_info->primitive+1,~0,&image->exception); | 
 | 1763 |   if (primitive == (char *) NULL) | 
 | 1764 |     return(MagickFalse); | 
 | 1765 |   primitive_extent=(MagickRealType) strlen(primitive); | 
 | 1766 |   (void) SetImageArtifact(image,"MVG",primitive); | 
 | 1767 |   n=0; | 
 | 1768 |   /* | 
 | 1769 |     Allocate primitive info memory. | 
 | 1770 |   */ | 
| cristy | ed11071 | 2010-03-23 01:16:38 +0000 | [diff] [blame] | 1771 |   graphic_context=(DrawInfo **) AcquireAlignedMemory(1, | 
 | 1772 |     sizeof(*graphic_context)); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1773 |   if (graphic_context == (DrawInfo **) NULL) | 
 | 1774 |     { | 
 | 1775 |       primitive=DestroyString(primitive); | 
 | 1776 |       ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", | 
 | 1777 |         image->filename); | 
 | 1778 |     } | 
 | 1779 |   number_points=2047; | 
 | 1780 |   primitive_info=(PrimitiveInfo *) AcquireQuantumMemory((size_t) number_points, | 
 | 1781 |     sizeof(*primitive_info)); | 
 | 1782 |   if (primitive_info == (PrimitiveInfo *) NULL) | 
 | 1783 |     { | 
 | 1784 |       primitive=DestroyString(primitive); | 
 | 1785 |       for ( ; n >= 0; n--) | 
 | 1786 |         graphic_context[n]=DestroyDrawInfo(graphic_context[n]); | 
 | 1787 |       graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context); | 
 | 1788 |       ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", | 
 | 1789 |         image->filename); | 
 | 1790 |     } | 
 | 1791 |   graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,draw_info); | 
 | 1792 |   graphic_context[n]->viewbox=image->page; | 
 | 1793 |   if ((image->page.width == 0) || (image->page.height == 0)) | 
 | 1794 |     { | 
 | 1795 |       graphic_context[n]->viewbox.width=image->columns; | 
 | 1796 |       graphic_context[n]->viewbox.height=image->rows; | 
 | 1797 |     } | 
 | 1798 |   token=AcquireString(primitive); | 
 | 1799 |   (void) QueryColorDatabase("#000000",&start_color,&image->exception); | 
 | 1800 |   if (SetImageStorageClass(image,DirectClass) == MagickFalse) | 
 | 1801 |     return(MagickFalse); | 
 | 1802 |   status=MagickTrue; | 
 | 1803 |   for (q=primitive; *q != '\0'; ) | 
 | 1804 |   { | 
 | 1805 |     /* | 
 | 1806 |       Interpret graphic primitive. | 
 | 1807 |     */ | 
 | 1808 |     GetMagickToken(q,&q,keyword); | 
 | 1809 |     if (*keyword == '\0') | 
 | 1810 |       break; | 
 | 1811 |     if (*keyword == '#') | 
 | 1812 |       { | 
 | 1813 |         /* | 
 | 1814 |           Comment. | 
 | 1815 |         */ | 
 | 1816 |         while ((*q != '\n') && (*q != '\0')) | 
 | 1817 |           q++; | 
 | 1818 |         continue; | 
 | 1819 |       } | 
 | 1820 |     p=q-strlen(keyword)-1; | 
 | 1821 |     primitive_type=UndefinedPrimitive; | 
 | 1822 |     current=graphic_context[n]->affine; | 
 | 1823 |     GetAffineMatrix(&affine); | 
 | 1824 |     switch (*keyword) | 
 | 1825 |     { | 
 | 1826 |       case ';': | 
 | 1827 |         break; | 
 | 1828 |       case 'a': | 
 | 1829 |       case 'A': | 
 | 1830 |       { | 
 | 1831 |         if (LocaleCompare("affine",keyword) == 0) | 
 | 1832 |           { | 
 | 1833 |             GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 1834 |             affine.sx=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1835 |             GetMagickToken(q,&q,token); | 
 | 1836 |             if (*token == ',') | 
 | 1837 |               GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 1838 |             affine.rx=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1839 |             GetMagickToken(q,&q,token); | 
 | 1840 |             if (*token == ',') | 
 | 1841 |               GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 1842 |             affine.ry=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1843 |             GetMagickToken(q,&q,token); | 
 | 1844 |             if (*token == ',') | 
 | 1845 |               GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 1846 |             affine.sy=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1847 |             GetMagickToken(q,&q,token); | 
 | 1848 |             if (*token == ',') | 
 | 1849 |               GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 1850 |             affine.tx=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1851 |             GetMagickToken(q,&q,token); | 
 | 1852 |             if (*token == ',') | 
 | 1853 |               GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 1854 |             affine.ty=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1855 |             break; | 
 | 1856 |           } | 
 | 1857 |         if (LocaleCompare("arc",keyword) == 0) | 
 | 1858 |           { | 
 | 1859 |             primitive_type=ArcPrimitive; | 
 | 1860 |             break; | 
 | 1861 |           } | 
 | 1862 |         status=MagickFalse; | 
 | 1863 |         break; | 
 | 1864 |       } | 
 | 1865 |       case 'b': | 
 | 1866 |       case 'B': | 
 | 1867 |       { | 
 | 1868 |         if (LocaleCompare("bezier",keyword) == 0) | 
 | 1869 |           { | 
 | 1870 |             primitive_type=BezierPrimitive; | 
 | 1871 |             break; | 
 | 1872 |           } | 
 | 1873 |         if (LocaleCompare("border-color",keyword) == 0) | 
 | 1874 |           { | 
 | 1875 |             GetMagickToken(q,&q,token); | 
 | 1876 |             (void) QueryColorDatabase(token,&graphic_context[n]->border_color, | 
 | 1877 |               &image->exception); | 
 | 1878 |             break; | 
 | 1879 |           } | 
 | 1880 |         status=MagickFalse; | 
 | 1881 |         break; | 
 | 1882 |       } | 
 | 1883 |       case 'c': | 
 | 1884 |       case 'C': | 
 | 1885 |       { | 
 | 1886 |         if (LocaleCompare("clip-path",keyword) == 0) | 
 | 1887 |           { | 
 | 1888 |             /* | 
 | 1889 |               Create clip mask. | 
 | 1890 |             */ | 
 | 1891 |             GetMagickToken(q,&q,token); | 
 | 1892 |             (void) CloneString(&graphic_context[n]->clip_mask,token); | 
 | 1893 |             (void) DrawClipPath(image,graphic_context[n], | 
 | 1894 |               graphic_context[n]->clip_mask); | 
 | 1895 |             break; | 
 | 1896 |           } | 
 | 1897 |         if (LocaleCompare("clip-rule",keyword) == 0) | 
 | 1898 |           { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1899 |             ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1900 |               fill_rule; | 
 | 1901 |  | 
 | 1902 |             GetMagickToken(q,&q,token); | 
 | 1903 |             fill_rule=ParseMagickOption(MagickFillRuleOptions,MagickFalse, | 
 | 1904 |               token); | 
 | 1905 |             if (fill_rule == -1) | 
 | 1906 |               { | 
 | 1907 |                 status=MagickFalse; | 
 | 1908 |                 break; | 
 | 1909 |               } | 
 | 1910 |             graphic_context[n]->fill_rule=(FillRule) fill_rule; | 
 | 1911 |             break; | 
 | 1912 |           } | 
 | 1913 |         if (LocaleCompare("clip-units",keyword) == 0) | 
 | 1914 |           { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1915 |             ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1916 |               clip_units; | 
 | 1917 |  | 
 | 1918 |             GetMagickToken(q,&q,token); | 
 | 1919 |             clip_units=ParseMagickOption(MagickClipPathOptions,MagickFalse, | 
 | 1920 |               token); | 
 | 1921 |             if (clip_units == -1) | 
 | 1922 |               { | 
 | 1923 |                 status=MagickFalse; | 
 | 1924 |                 break; | 
 | 1925 |               } | 
 | 1926 |             graphic_context[n]->clip_units=(ClipPathUnits) clip_units; | 
 | 1927 |             if (clip_units == ObjectBoundingBox) | 
 | 1928 |               { | 
 | 1929 |                 GetAffineMatrix(¤t); | 
 | 1930 |                 affine.sx=draw_info->bounds.x2; | 
 | 1931 |                 affine.sy=draw_info->bounds.y2; | 
 | 1932 |                 affine.tx=draw_info->bounds.x1; | 
 | 1933 |                 affine.ty=draw_info->bounds.y1; | 
 | 1934 |                 break; | 
 | 1935 |               } | 
 | 1936 |             break; | 
 | 1937 |           } | 
 | 1938 |         if (LocaleCompare("circle",keyword) == 0) | 
 | 1939 |           { | 
 | 1940 |             primitive_type=CirclePrimitive; | 
 | 1941 |             break; | 
 | 1942 |           } | 
 | 1943 |         if (LocaleCompare("color",keyword) == 0) | 
 | 1944 |           { | 
 | 1945 |             primitive_type=ColorPrimitive; | 
 | 1946 |             break; | 
 | 1947 |           } | 
 | 1948 |         status=MagickFalse; | 
 | 1949 |         break; | 
 | 1950 |       } | 
 | 1951 |       case 'd': | 
 | 1952 |       case 'D': | 
 | 1953 |       { | 
 | 1954 |         if (LocaleCompare("decorate",keyword) == 0) | 
 | 1955 |           { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1956 |             ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1957 |               decorate; | 
 | 1958 |  | 
 | 1959 |             GetMagickToken(q,&q,token); | 
 | 1960 |             decorate=ParseMagickOption(MagickDecorateOptions,MagickFalse, | 
 | 1961 |               token); | 
 | 1962 |             if (decorate == -1) | 
 | 1963 |               { | 
 | 1964 |                 status=MagickFalse; | 
 | 1965 |                 break; | 
 | 1966 |               } | 
 | 1967 |             graphic_context[n]->decorate=(DecorationType) decorate; | 
 | 1968 |             break; | 
 | 1969 |           } | 
 | 1970 |         status=MagickFalse; | 
 | 1971 |         break; | 
 | 1972 |       } | 
 | 1973 |       case 'e': | 
 | 1974 |       case 'E': | 
 | 1975 |       { | 
 | 1976 |         if (LocaleCompare("ellipse",keyword) == 0) | 
 | 1977 |           { | 
 | 1978 |             primitive_type=EllipsePrimitive; | 
 | 1979 |             break; | 
 | 1980 |           } | 
 | 1981 |         if (LocaleCompare("encoding",keyword) == 0) | 
 | 1982 |           { | 
 | 1983 |             GetMagickToken(q,&q,token); | 
 | 1984 |             (void) CloneString(&graphic_context[n]->encoding,token); | 
 | 1985 |             break; | 
 | 1986 |           } | 
 | 1987 |         status=MagickFalse; | 
 | 1988 |         break; | 
 | 1989 |       } | 
 | 1990 |       case 'f': | 
 | 1991 |       case 'F': | 
 | 1992 |       { | 
 | 1993 |         if (LocaleCompare("fill",keyword) == 0) | 
 | 1994 |           { | 
 | 1995 |             GetMagickToken(q,&q,token); | 
 | 1996 |             (void) FormatMagickString(pattern,MaxTextExtent,"%s",token); | 
 | 1997 |             if (GetImageArtifact(image,pattern) != (const char *) NULL) | 
 | 1998 |               (void) DrawPatternPath(image,draw_info,token, | 
 | 1999 |                 &graphic_context[n]->fill_pattern); | 
 | 2000 |             else | 
 | 2001 |               { | 
 | 2002 |                 status=QueryColorDatabase(token,&graphic_context[n]->fill, | 
 | 2003 |                   &image->exception); | 
 | 2004 |                 if (status == MagickFalse) | 
 | 2005 |                   { | 
 | 2006 |                     ImageInfo | 
 | 2007 |                       *pattern_info; | 
 | 2008 |  | 
 | 2009 |                     pattern_info=AcquireImageInfo(); | 
 | 2010 |                     (void) CopyMagickString(pattern_info->filename,token, | 
 | 2011 |                       MaxTextExtent); | 
 | 2012 |                     graphic_context[n]->fill_pattern= | 
 | 2013 |                       ReadImage(pattern_info,&image->exception); | 
 | 2014 |                     CatchException(&image->exception); | 
 | 2015 |                     pattern_info=DestroyImageInfo(pattern_info); | 
 | 2016 |                   } | 
 | 2017 |               } | 
 | 2018 |             break; | 
 | 2019 |           } | 
 | 2020 |         if (LocaleCompare("fill-opacity",keyword) == 0) | 
 | 2021 |           { | 
 | 2022 |             GetMagickToken(q,&q,token); | 
 | 2023 |             factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0; | 
| cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 2024 |             graphic_context[n]->fill.opacity=ClampToQuantum((MagickRealType) | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2025 |               QuantumRange*(1.0-factor*StringToDouble(token))); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2026 |             break; | 
 | 2027 |           } | 
 | 2028 |         if (LocaleCompare("fill-rule",keyword) == 0) | 
 | 2029 |           { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2030 |             ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2031 |               fill_rule; | 
 | 2032 |  | 
 | 2033 |             GetMagickToken(q,&q,token); | 
 | 2034 |             fill_rule=ParseMagickOption(MagickFillRuleOptions,MagickFalse, | 
 | 2035 |               token); | 
 | 2036 |             if (fill_rule == -1) | 
 | 2037 |               { | 
 | 2038 |                 status=MagickFalse; | 
 | 2039 |                 break; | 
 | 2040 |               } | 
 | 2041 |             graphic_context[n]->fill_rule=(FillRule) fill_rule; | 
 | 2042 |             break; | 
 | 2043 |           } | 
 | 2044 |         if (LocaleCompare("font",keyword) == 0) | 
 | 2045 |           { | 
 | 2046 |             GetMagickToken(q,&q,token); | 
 | 2047 |             (void) CloneString(&graphic_context[n]->font,token); | 
 | 2048 |             if (LocaleCompare("none",token) == 0) | 
 | 2049 |               graphic_context[n]->font=(char *) | 
 | 2050 |                 RelinquishMagickMemory(graphic_context[n]->font); | 
 | 2051 |             break; | 
 | 2052 |           } | 
 | 2053 |         if (LocaleCompare("font-family",keyword) == 0) | 
 | 2054 |           { | 
 | 2055 |             GetMagickToken(q,&q,token); | 
 | 2056 |             (void) CloneString(&graphic_context[n]->family,token); | 
 | 2057 |             break; | 
 | 2058 |           } | 
 | 2059 |         if (LocaleCompare("font-size",keyword) == 0) | 
 | 2060 |           { | 
 | 2061 |             GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2062 |             graphic_context[n]->pointsize=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2063 |             break; | 
 | 2064 |           } | 
 | 2065 |         if (LocaleCompare("font-stretch",keyword) == 0) | 
 | 2066 |           { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2067 |             ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2068 |               stretch; | 
 | 2069 |  | 
 | 2070 |             GetMagickToken(q,&q,token); | 
 | 2071 |             stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,token); | 
 | 2072 |             if (stretch == -1) | 
 | 2073 |               { | 
 | 2074 |                 status=MagickFalse; | 
 | 2075 |                 break; | 
 | 2076 |               } | 
 | 2077 |             graphic_context[n]->stretch=(StretchType) stretch; | 
 | 2078 |             break; | 
 | 2079 |           } | 
 | 2080 |         if (LocaleCompare("font-style",keyword) == 0) | 
 | 2081 |           { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2082 |             ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2083 |               style; | 
 | 2084 |  | 
 | 2085 |             GetMagickToken(q,&q,token); | 
 | 2086 |             style=ParseMagickOption(MagickStyleOptions,MagickFalse,token); | 
 | 2087 |             if (style == -1) | 
 | 2088 |               { | 
 | 2089 |                 status=MagickFalse; | 
 | 2090 |                 break; | 
 | 2091 |               } | 
 | 2092 |             graphic_context[n]->style=(StyleType) style; | 
 | 2093 |             break; | 
 | 2094 |           } | 
 | 2095 |         if (LocaleCompare("font-weight",keyword) == 0) | 
 | 2096 |           { | 
 | 2097 |             GetMagickToken(q,&q,token); | 
| cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 2098 |             graphic_context[n]->weight=StringToUnsignedLong(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2099 |             if (LocaleCompare(token,"all") == 0) | 
 | 2100 |               graphic_context[n]->weight=0; | 
 | 2101 |             if (LocaleCompare(token,"bold") == 0) | 
 | 2102 |               graphic_context[n]->weight=700; | 
 | 2103 |             if (LocaleCompare(token,"bolder") == 0) | 
 | 2104 |               if (graphic_context[n]->weight <= 800) | 
 | 2105 |                 graphic_context[n]->weight+=100; | 
 | 2106 |             if (LocaleCompare(token,"lighter") == 0) | 
 | 2107 |               if (graphic_context[n]->weight >= 100) | 
 | 2108 |                 graphic_context[n]->weight-=100; | 
 | 2109 |             if (LocaleCompare(token,"normal") == 0) | 
 | 2110 |               graphic_context[n]->weight=400; | 
 | 2111 |             break; | 
 | 2112 |           } | 
 | 2113 |         status=MagickFalse; | 
 | 2114 |         break; | 
 | 2115 |       } | 
 | 2116 |       case 'g': | 
 | 2117 |       case 'G': | 
 | 2118 |       { | 
 | 2119 |         if (LocaleCompare("gradient-units",keyword) == 0) | 
 | 2120 |           { | 
 | 2121 |             GetMagickToken(q,&q,token); | 
 | 2122 |             break; | 
 | 2123 |           } | 
 | 2124 |         if (LocaleCompare("gravity",keyword) == 0) | 
 | 2125 |           { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2126 |             ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2127 |               gravity; | 
 | 2128 |  | 
 | 2129 |             GetMagickToken(q,&q,token); | 
 | 2130 |             gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,token); | 
 | 2131 |             if (gravity == -1) | 
 | 2132 |               { | 
 | 2133 |                 status=MagickFalse; | 
 | 2134 |                 break; | 
 | 2135 |               } | 
 | 2136 |             graphic_context[n]->gravity=(GravityType) gravity; | 
 | 2137 |             break; | 
 | 2138 |           } | 
 | 2139 |         status=MagickFalse; | 
 | 2140 |         break; | 
 | 2141 |       } | 
 | 2142 |       case 'i': | 
 | 2143 |       case 'I': | 
 | 2144 |       { | 
 | 2145 |         if (LocaleCompare("image",keyword) == 0) | 
 | 2146 |           { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2147 |             ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2148 |               compose; | 
 | 2149 |  | 
 | 2150 |             primitive_type=ImagePrimitive; | 
 | 2151 |             GetMagickToken(q,&q,token); | 
 | 2152 |             compose=ParseMagickOption(MagickComposeOptions,MagickFalse,token); | 
 | 2153 |             if (compose == -1) | 
 | 2154 |               { | 
 | 2155 |                 status=MagickFalse; | 
 | 2156 |                 break; | 
 | 2157 |               } | 
 | 2158 |             graphic_context[n]->compose=(CompositeOperator) compose; | 
 | 2159 |             break; | 
 | 2160 |           } | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2161 |         if (LocaleCompare("interline-spacing",keyword) == 0) | 
 | 2162 |           { | 
 | 2163 |             GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2164 |             graphic_context[n]->interline_spacing=StringToDouble(token); | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2165 |             break; | 
 | 2166 |           } | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2167 |         if (LocaleCompare("interword-spacing",keyword) == 0) | 
 | 2168 |           { | 
 | 2169 |             GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2170 |             graphic_context[n]->interword_spacing=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2171 |             break; | 
 | 2172 |           } | 
 | 2173 |         status=MagickFalse; | 
 | 2174 |         break; | 
 | 2175 |       } | 
 | 2176 |       case 'k': | 
 | 2177 |       case 'K': | 
 | 2178 |       { | 
 | 2179 |         if (LocaleCompare("kerning",keyword) == 0) | 
 | 2180 |           { | 
 | 2181 |             GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2182 |             graphic_context[n]->kerning=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2183 |             break; | 
 | 2184 |           } | 
 | 2185 |         status=MagickFalse; | 
 | 2186 |         break; | 
 | 2187 |       } | 
 | 2188 |       case 'l': | 
 | 2189 |       case 'L': | 
 | 2190 |       { | 
 | 2191 |         if (LocaleCompare("line",keyword) == 0) | 
 | 2192 |           { | 
 | 2193 |             primitive_type=LinePrimitive; | 
 | 2194 |             break; | 
 | 2195 |           } | 
 | 2196 |         status=MagickFalse; | 
 | 2197 |         break; | 
 | 2198 |       } | 
 | 2199 |       case 'm': | 
 | 2200 |       case 'M': | 
 | 2201 |       { | 
 | 2202 |         if (LocaleCompare("matte",keyword) == 0) | 
 | 2203 |           { | 
 | 2204 |             primitive_type=MattePrimitive; | 
 | 2205 |             break; | 
 | 2206 |           } | 
 | 2207 |         status=MagickFalse; | 
 | 2208 |         break; | 
 | 2209 |       } | 
 | 2210 |       case 'o': | 
 | 2211 |       case 'O': | 
 | 2212 |       { | 
 | 2213 |         if (LocaleCompare("offset",keyword) == 0) | 
 | 2214 |           { | 
 | 2215 |             GetMagickToken(q,&q,token); | 
 | 2216 |             break; | 
 | 2217 |           } | 
 | 2218 |         if (LocaleCompare("opacity",keyword) == 0) | 
 | 2219 |           { | 
 | 2220 |             GetMagickToken(q,&q,token); | 
 | 2221 |             factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0; | 
| cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 2222 |             graphic_context[n]->opacity=ClampToQuantum((MagickRealType) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2223 |               QuantumRange*(1.0-((1.0-QuantumScale*graphic_context[n]->opacity)* | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2224 |               factor*StringToDouble(token)))); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2225 |             graphic_context[n]->fill.opacity=graphic_context[n]->opacity; | 
 | 2226 |             graphic_context[n]->stroke.opacity=graphic_context[n]->opacity; | 
 | 2227 |             break; | 
 | 2228 |           } | 
 | 2229 |         status=MagickFalse; | 
 | 2230 |         break; | 
 | 2231 |       } | 
 | 2232 |       case 'p': | 
 | 2233 |       case 'P': | 
 | 2234 |       { | 
 | 2235 |         if (LocaleCompare("path",keyword) == 0) | 
 | 2236 |           { | 
 | 2237 |             primitive_type=PathPrimitive; | 
 | 2238 |             break; | 
 | 2239 |           } | 
 | 2240 |         if (LocaleCompare("point",keyword) == 0) | 
 | 2241 |           { | 
 | 2242 |             primitive_type=PointPrimitive; | 
 | 2243 |             break; | 
 | 2244 |           } | 
 | 2245 |         if (LocaleCompare("polyline",keyword) == 0) | 
 | 2246 |           { | 
 | 2247 |             primitive_type=PolylinePrimitive; | 
 | 2248 |             break; | 
 | 2249 |           } | 
 | 2250 |         if (LocaleCompare("polygon",keyword) == 0) | 
 | 2251 |           { | 
 | 2252 |             primitive_type=PolygonPrimitive; | 
 | 2253 |             break; | 
 | 2254 |           } | 
 | 2255 |         if (LocaleCompare("pop",keyword) == 0) | 
 | 2256 |           { | 
 | 2257 |             GetMagickToken(q,&q,token); | 
 | 2258 |             if (LocaleCompare("clip-path",token) == 0) | 
 | 2259 |               break; | 
 | 2260 |             if (LocaleCompare("defs",token) == 0) | 
 | 2261 |               break; | 
 | 2262 |             if (LocaleCompare("gradient",token) == 0) | 
 | 2263 |               break; | 
 | 2264 |             if (LocaleCompare("graphic-context",token) == 0) | 
 | 2265 |               { | 
 | 2266 |                 if (n <= 0) | 
 | 2267 |                   { | 
 | 2268 |                     (void) ThrowMagickException(&image->exception, | 
 | 2269 |                       GetMagickModule(),DrawError, | 
 | 2270 |                       "UnbalancedGraphicContextPushPop","`%s'",token); | 
 | 2271 |                     n=0; | 
 | 2272 |                     break; | 
 | 2273 |                   } | 
 | 2274 |                 if (graphic_context[n]->clip_mask != (char *) NULL) | 
 | 2275 |                   if (LocaleCompare(graphic_context[n]->clip_mask, | 
 | 2276 |                       graphic_context[n-1]->clip_mask) != 0) | 
 | 2277 |                     (void) SetImageClipMask(image,(Image *) NULL); | 
 | 2278 |                 graphic_context[n]=DestroyDrawInfo(graphic_context[n]); | 
 | 2279 |                 n--; | 
 | 2280 |                 break; | 
 | 2281 |               } | 
 | 2282 |             if (LocaleCompare("pattern",token) == 0) | 
 | 2283 |               break; | 
 | 2284 |             status=MagickFalse; | 
 | 2285 |             break; | 
 | 2286 |           } | 
 | 2287 |         if (LocaleCompare("push",keyword) == 0) | 
 | 2288 |           { | 
 | 2289 |             GetMagickToken(q,&q,token); | 
 | 2290 |             if (LocaleCompare("clip-path",token) == 0) | 
 | 2291 |               { | 
 | 2292 |                 char | 
 | 2293 |                   name[MaxTextExtent]; | 
 | 2294 |  | 
 | 2295 |                 GetMagickToken(q,&q,token); | 
 | 2296 |                 (void) FormatMagickString(name,MaxTextExtent,"%s",token); | 
 | 2297 |                 for (p=q; *q != '\0'; ) | 
 | 2298 |                 { | 
 | 2299 |                   GetMagickToken(q,&q,token); | 
 | 2300 |                   if (LocaleCompare(token,"pop") != 0) | 
 | 2301 |                     continue; | 
 | 2302 |                   GetMagickToken(q,(const char **) NULL,token); | 
 | 2303 |                   if (LocaleCompare(token,"clip-path") != 0) | 
 | 2304 |                     continue; | 
 | 2305 |                   break; | 
 | 2306 |                 } | 
 | 2307 |                 (void) CopyMagickString(token,p,(size_t) (q-p-4+1)); | 
 | 2308 |                 (void) SetImageArtifact(image,name,token); | 
 | 2309 |                 GetMagickToken(q,&q,token); | 
 | 2310 |                 break; | 
 | 2311 |               } | 
 | 2312 |             if (LocaleCompare("gradient",token) == 0) | 
 | 2313 |               { | 
 | 2314 |                 char | 
 | 2315 |                   key[2*MaxTextExtent], | 
 | 2316 |                   name[MaxTextExtent], | 
 | 2317 |                   type[MaxTextExtent]; | 
 | 2318 |  | 
 | 2319 |                 ElementInfo | 
 | 2320 |                   element; | 
 | 2321 |  | 
 | 2322 |                 SegmentInfo | 
 | 2323 |                   segment; | 
 | 2324 |  | 
 | 2325 |                 GetMagickToken(q,&q,token); | 
 | 2326 |                 (void) CopyMagickString(name,token,MaxTextExtent); | 
 | 2327 |                 GetMagickToken(q,&q,token); | 
 | 2328 |                 (void) CopyMagickString(type,token,MaxTextExtent); | 
 | 2329 |                 GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2330 |                 segment.x1=StringToDouble(token); | 
 | 2331 |                 element.cx=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2332 |                 GetMagickToken(q,&q,token); | 
 | 2333 |                 if (*token == ',') | 
 | 2334 |                   GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2335 |                 segment.y1=StringToDouble(token); | 
 | 2336 |                 element.cy=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2337 |                 GetMagickToken(q,&q,token); | 
 | 2338 |                 if (*token == ',') | 
 | 2339 |                   GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2340 |                 segment.x2=StringToDouble(token); | 
 | 2341 |                 element.major=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2342 |                 GetMagickToken(q,&q,token); | 
 | 2343 |                 if (*token == ',') | 
 | 2344 |                   GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2345 |                 segment.y2=StringToDouble(token); | 
 | 2346 |                 element.minor=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2347 |                 if (LocaleCompare(type,"radial") == 0) | 
 | 2348 |                   { | 
 | 2349 |                     GetMagickToken(q,&q,token); | 
 | 2350 |                     if (*token == ',') | 
 | 2351 |                       GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2352 |                     element.angle=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2353 |                   } | 
 | 2354 |                 for (p=q; *q != '\0'; ) | 
 | 2355 |                 { | 
 | 2356 |                   GetMagickToken(q,&q,token); | 
 | 2357 |                   if (LocaleCompare(token,"pop") != 0) | 
 | 2358 |                     continue; | 
 | 2359 |                   GetMagickToken(q,(const char **) NULL,token); | 
 | 2360 |                   if (LocaleCompare(token,"gradient") != 0) | 
 | 2361 |                     continue; | 
 | 2362 |                   break; | 
 | 2363 |                 } | 
 | 2364 |                 (void) CopyMagickString(token,p,(size_t) (q-p-4+1)); | 
 | 2365 |                 bounds.x1=graphic_context[n]->affine.sx*segment.x1+ | 
 | 2366 |                   graphic_context[n]->affine.ry*segment.y1+ | 
 | 2367 |                   graphic_context[n]->affine.tx; | 
 | 2368 |                 bounds.y1=graphic_context[n]->affine.rx*segment.x1+ | 
 | 2369 |                   graphic_context[n]->affine.sy*segment.y1+ | 
 | 2370 |                   graphic_context[n]->affine.ty; | 
 | 2371 |                 bounds.x2=graphic_context[n]->affine.sx*segment.x2+ | 
 | 2372 |                   graphic_context[n]->affine.ry*segment.y2+ | 
 | 2373 |                   graphic_context[n]->affine.tx; | 
 | 2374 |                 bounds.y2=graphic_context[n]->affine.rx*segment.x2+ | 
 | 2375 |                   graphic_context[n]->affine.sy*segment.y2+ | 
 | 2376 |                   graphic_context[n]->affine.ty; | 
 | 2377 |                 (void) FormatMagickString(key,MaxTextExtent,"%s",name); | 
 | 2378 |                 (void) SetImageArtifact(image,key,token); | 
 | 2379 |                 (void) FormatMagickString(key,MaxTextExtent,"%s-geometry",name); | 
| cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 2380 |                 (void) FormatMagickString(geometry,MaxTextExtent, | 
| cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 2381 |                   "%gx%g%+.15g%+.15g", | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2382 |                   MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0), | 
 | 2383 |                   MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0), | 
 | 2384 |                   bounds.x1,bounds.y1); | 
 | 2385 |                 (void) SetImageArtifact(image,key,geometry); | 
 | 2386 |                 GetMagickToken(q,&q,token); | 
 | 2387 |                 break; | 
 | 2388 |               } | 
 | 2389 |             if (LocaleCompare("pattern",token) == 0) | 
 | 2390 |               { | 
 | 2391 |                 RectangleInfo | 
 | 2392 |                   bounds; | 
 | 2393 |  | 
 | 2394 |                 GetMagickToken(q,&q,token); | 
 | 2395 |                 (void) CopyMagickString(name,token,MaxTextExtent); | 
 | 2396 |                 GetMagickToken(q,&q,token); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2397 |                 bounds.x=(ssize_t) ceil(StringToDouble(token)-0.5); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2398 |                 GetMagickToken(q,&q,token); | 
 | 2399 |                 if (*token == ',') | 
 | 2400 |                   GetMagickToken(q,&q,token); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2401 |                 bounds.y=(ssize_t) ceil(StringToDouble(token)-0.5); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2402 |                 GetMagickToken(q,&q,token); | 
 | 2403 |                 if (*token == ',') | 
 | 2404 |                   GetMagickToken(q,&q,token); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2405 |                 bounds.width=(size_t) floor(StringToDouble(token)+0.5); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2406 |                 GetMagickToken(q,&q,token); | 
 | 2407 |                 if (*token == ',') | 
 | 2408 |                   GetMagickToken(q,&q,token); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2409 |                 bounds.height=(size_t) floor(StringToDouble(token)+0.5); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2410 |                 for (p=q; *q != '\0'; ) | 
 | 2411 |                 { | 
 | 2412 |                   GetMagickToken(q,&q,token); | 
 | 2413 |                   if (LocaleCompare(token,"pop") != 0) | 
 | 2414 |                     continue; | 
 | 2415 |                   GetMagickToken(q,(const char **) NULL,token); | 
 | 2416 |                   if (LocaleCompare(token,"pattern") != 0) | 
 | 2417 |                     continue; | 
 | 2418 |                   break; | 
 | 2419 |                 } | 
 | 2420 |                 (void) CopyMagickString(token,p,(size_t) (q-p-4+1)); | 
 | 2421 |                 (void) FormatMagickString(key,MaxTextExtent,"%s",name); | 
 | 2422 |                 (void) SetImageArtifact(image,key,token); | 
 | 2423 |                 (void) FormatMagickString(key,MaxTextExtent,"%s-geometry",name); | 
 | 2424 |                 (void) FormatMagickString(geometry,MaxTextExtent, | 
| cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 2425 |                   "%lux%lu%+ld%+ld",(unsigned long) bounds.width, | 
 | 2426 |                   (unsigned long) bounds.height,(long) bounds.x, | 
 | 2427 |                   (long) bounds.y); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2428 |                 (void) SetImageArtifact(image,key,geometry); | 
 | 2429 |                 GetMagickToken(q,&q,token); | 
 | 2430 |                 break; | 
 | 2431 |               } | 
 | 2432 |             if (LocaleCompare("graphic-context",token) == 0) | 
 | 2433 |               { | 
 | 2434 |                 n++; | 
 | 2435 |                 graphic_context=(DrawInfo **) ResizeQuantumMemory( | 
 | 2436 |                   graphic_context,(size_t) (n+1),sizeof(*graphic_context)); | 
 | 2437 |                 if (graphic_context == (DrawInfo **) NULL) | 
 | 2438 |                   { | 
 | 2439 |                     (void) ThrowMagickException(&image->exception, | 
 | 2440 |                       GetMagickModule(),ResourceLimitError, | 
 | 2441 |                       "MemoryAllocationFailed","`%s'",image->filename); | 
 | 2442 |                     break; | 
 | 2443 |                   } | 
 | 2444 |                 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL, | 
 | 2445 |                   graphic_context[n-1]); | 
 | 2446 |                 break; | 
 | 2447 |               } | 
 | 2448 |             if (LocaleCompare("defs",token) == 0) | 
 | 2449 |               break; | 
 | 2450 |             status=MagickFalse; | 
 | 2451 |             break; | 
 | 2452 |           } | 
 | 2453 |         status=MagickFalse; | 
 | 2454 |         break; | 
 | 2455 |       } | 
 | 2456 |       case 'r': | 
 | 2457 |       case 'R': | 
 | 2458 |       { | 
 | 2459 |         if (LocaleCompare("rectangle",keyword) == 0) | 
 | 2460 |           { | 
 | 2461 |             primitive_type=RectanglePrimitive; | 
 | 2462 |             break; | 
 | 2463 |           } | 
 | 2464 |         if (LocaleCompare("rotate",keyword) == 0) | 
 | 2465 |           { | 
 | 2466 |             GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2467 |             angle=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2468 |             affine.sx=cos(DegreesToRadians(fmod((double) angle,360.0))); | 
 | 2469 |             affine.rx=sin(DegreesToRadians(fmod((double) angle,360.0))); | 
 | 2470 |             affine.ry=(-sin(DegreesToRadians(fmod((double) angle,360.0)))); | 
 | 2471 |             affine.sy=cos(DegreesToRadians(fmod((double) angle,360.0))); | 
 | 2472 |             break; | 
 | 2473 |           } | 
 | 2474 |         if (LocaleCompare("roundRectangle",keyword) == 0) | 
 | 2475 |           { | 
 | 2476 |             primitive_type=RoundRectanglePrimitive; | 
 | 2477 |             break; | 
 | 2478 |           } | 
 | 2479 |         status=MagickFalse; | 
 | 2480 |         break; | 
 | 2481 |       } | 
 | 2482 |       case 's': | 
 | 2483 |       case 'S': | 
 | 2484 |       { | 
 | 2485 |         if (LocaleCompare("scale",keyword) == 0) | 
 | 2486 |           { | 
 | 2487 |             GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2488 |             affine.sx=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2489 |             GetMagickToken(q,&q,token); | 
 | 2490 |             if (*token == ',') | 
 | 2491 |               GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2492 |             affine.sy=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2493 |             break; | 
 | 2494 |           } | 
 | 2495 |         if (LocaleCompare("skewX",keyword) == 0) | 
 | 2496 |           { | 
 | 2497 |             GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2498 |             angle=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2499 |             affine.ry=sin(DegreesToRadians(angle)); | 
 | 2500 |             break; | 
 | 2501 |           } | 
 | 2502 |         if (LocaleCompare("skewY",keyword) == 0) | 
 | 2503 |           { | 
 | 2504 |             GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2505 |             angle=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2506 |             affine.rx=(-tan(DegreesToRadians(angle)/2.0)); | 
 | 2507 |             break; | 
 | 2508 |           } | 
 | 2509 |         if (LocaleCompare("stop-color",keyword) == 0) | 
 | 2510 |           { | 
 | 2511 |             PixelPacket | 
 | 2512 |               stop_color; | 
 | 2513 |  | 
 | 2514 |             GetMagickToken(q,&q,token); | 
 | 2515 |             (void) QueryColorDatabase(token,&stop_color,&image->exception); | 
 | 2516 |             (void) GradientImage(image,LinearGradient,ReflectSpread, | 
 | 2517 |               &start_color,&stop_color); | 
 | 2518 |             start_color=stop_color; | 
 | 2519 |             GetMagickToken(q,&q,token); | 
 | 2520 |             break; | 
 | 2521 |           } | 
 | 2522 |         if (LocaleCompare("stroke",keyword) == 0) | 
 | 2523 |           { | 
 | 2524 |             GetMagickToken(q,&q,token); | 
 | 2525 |             (void) FormatMagickString(pattern,MaxTextExtent,"%s",token); | 
 | 2526 |             if (GetImageArtifact(image,pattern) != (const char *) NULL) | 
 | 2527 |               (void) DrawPatternPath(image,draw_info,token, | 
 | 2528 |                 &graphic_context[n]->stroke_pattern); | 
 | 2529 |             else | 
 | 2530 |               { | 
 | 2531 |                 status=QueryColorDatabase(token,&graphic_context[n]->stroke, | 
 | 2532 |                   &image->exception); | 
 | 2533 |                 if (status == MagickFalse) | 
 | 2534 |                   { | 
 | 2535 |                     ImageInfo | 
 | 2536 |                       *pattern_info; | 
 | 2537 |  | 
 | 2538 |                     pattern_info=AcquireImageInfo(); | 
 | 2539 |                     (void) CopyMagickString(pattern_info->filename,token, | 
 | 2540 |                       MaxTextExtent); | 
 | 2541 |                     graphic_context[n]->stroke_pattern= | 
 | 2542 |                       ReadImage(pattern_info,&image->exception); | 
 | 2543 |                     CatchException(&image->exception); | 
 | 2544 |                     pattern_info=DestroyImageInfo(pattern_info); | 
 | 2545 |                   } | 
 | 2546 |               } | 
 | 2547 |             break; | 
 | 2548 |           } | 
 | 2549 |         if (LocaleCompare("stroke-antialias",keyword) == 0) | 
 | 2550 |           { | 
 | 2551 |             GetMagickToken(q,&q,token); | 
 | 2552 |             graphic_context[n]->stroke_antialias= | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2553 |               StringToLong(token) != 0 ? MagickTrue : MagickFalse; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2554 |             break; | 
 | 2555 |           } | 
 | 2556 |         if (LocaleCompare("stroke-dasharray",keyword) == 0) | 
 | 2557 |           { | 
 | 2558 |             if (graphic_context[n]->dash_pattern != (double *) NULL) | 
 | 2559 |               graphic_context[n]->dash_pattern=(double *) | 
 | 2560 |                 RelinquishMagickMemory(graphic_context[n]->dash_pattern); | 
 | 2561 |             if (IsPoint(q) != MagickFalse) | 
 | 2562 |               { | 
 | 2563 |                 const char | 
 | 2564 |                   *p; | 
 | 2565 |  | 
 | 2566 |                 p=q; | 
 | 2567 |                 GetMagickToken(p,&p,token); | 
 | 2568 |                 if (*token == ',') | 
 | 2569 |                   GetMagickToken(p,&p,token); | 
 | 2570 |                 for (x=0; IsPoint(token) != MagickFalse; x++) | 
 | 2571 |                 { | 
 | 2572 |                   GetMagickToken(p,&p,token); | 
 | 2573 |                   if (*token == ',') | 
 | 2574 |                     GetMagickToken(p,&p,token); | 
 | 2575 |                 } | 
 | 2576 |                 graphic_context[n]->dash_pattern=(double *) | 
 | 2577 |                   AcquireQuantumMemory((size_t) (2UL*x+1UL), | 
 | 2578 |                   sizeof(*graphic_context[n]->dash_pattern)); | 
 | 2579 |                 if (graphic_context[n]->dash_pattern == (double *) NULL) | 
 | 2580 |                   { | 
 | 2581 |                     (void) ThrowMagickException(&image->exception, | 
 | 2582 |                       GetMagickModule(),ResourceLimitError, | 
 | 2583 |                       "MemoryAllocationFailed","`%s'",image->filename); | 
 | 2584 |                     break; | 
 | 2585 |                   } | 
 | 2586 |                 for (j=0; j < x; j++) | 
 | 2587 |                 { | 
 | 2588 |                   GetMagickToken(q,&q,token); | 
 | 2589 |                   if (*token == ',') | 
 | 2590 |                     GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2591 |                   graphic_context[n]->dash_pattern[j]=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2592 |                 } | 
 | 2593 |                 if ((x & 0x01) != 0) | 
 | 2594 |                   for ( ; j < (2*x); j++) | 
 | 2595 |                     graphic_context[n]->dash_pattern[j]= | 
 | 2596 |                       graphic_context[n]->dash_pattern[j-x]; | 
 | 2597 |                 graphic_context[n]->dash_pattern[j]=0.0; | 
 | 2598 |                 break; | 
 | 2599 |               } | 
 | 2600 |             GetMagickToken(q,&q,token); | 
 | 2601 |             break; | 
 | 2602 |           } | 
 | 2603 |         if (LocaleCompare("stroke-dashoffset",keyword) == 0) | 
 | 2604 |           { | 
 | 2605 |             GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2606 |             graphic_context[n]->dash_offset=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2607 |             break; | 
 | 2608 |           } | 
 | 2609 |         if (LocaleCompare("stroke-linecap",keyword) == 0) | 
 | 2610 |           { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2611 |             ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2612 |               linecap; | 
 | 2613 |  | 
 | 2614 |             GetMagickToken(q,&q,token); | 
 | 2615 |             linecap=ParseMagickOption(MagickLineCapOptions,MagickFalse,token); | 
 | 2616 |             if (linecap == -1) | 
 | 2617 |               { | 
 | 2618 |                 status=MagickFalse; | 
 | 2619 |                 break; | 
 | 2620 |               } | 
 | 2621 |             graphic_context[n]->linecap=(LineCap) linecap; | 
 | 2622 |             break; | 
 | 2623 |           } | 
 | 2624 |         if (LocaleCompare("stroke-linejoin",keyword) == 0) | 
 | 2625 |           { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2626 |             ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2627 |               linejoin; | 
 | 2628 |  | 
 | 2629 |             GetMagickToken(q,&q,token); | 
 | 2630 |             linejoin=ParseMagickOption(MagickLineJoinOptions,MagickFalse,token); | 
 | 2631 |             if (linejoin == -1) | 
 | 2632 |               { | 
 | 2633 |                 status=MagickFalse; | 
 | 2634 |                 break; | 
 | 2635 |               } | 
 | 2636 |             graphic_context[n]->linejoin=(LineJoin) linejoin; | 
 | 2637 |             break; | 
 | 2638 |           } | 
 | 2639 |         if (LocaleCompare("stroke-miterlimit",keyword) == 0) | 
 | 2640 |           { | 
 | 2641 |             GetMagickToken(q,&q,token); | 
| cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 2642 |             graphic_context[n]->miterlimit=StringToUnsignedLong(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2643 |             break; | 
 | 2644 |           } | 
 | 2645 |         if (LocaleCompare("stroke-opacity",keyword) == 0) | 
 | 2646 |           { | 
 | 2647 |             GetMagickToken(q,&q,token); | 
 | 2648 |             factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0; | 
| cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 2649 |             graphic_context[n]->stroke.opacity=ClampToQuantum((MagickRealType) | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2650 |               QuantumRange*(1.0-factor*StringToDouble(token))); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2651 |             break; | 
 | 2652 |           } | 
 | 2653 |         if (LocaleCompare("stroke-width",keyword) == 0) | 
 | 2654 |           { | 
 | 2655 |             GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2656 |             graphic_context[n]->stroke_width=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2657 |             break; | 
 | 2658 |           } | 
 | 2659 |         status=MagickFalse; | 
 | 2660 |         break; | 
 | 2661 |       } | 
 | 2662 |       case 't': | 
 | 2663 |       case 'T': | 
 | 2664 |       { | 
 | 2665 |         if (LocaleCompare("text",keyword) == 0) | 
 | 2666 |           { | 
 | 2667 |             primitive_type=TextPrimitive; | 
 | 2668 |             break; | 
 | 2669 |           } | 
 | 2670 |         if (LocaleCompare("text-align",keyword) == 0) | 
 | 2671 |           { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2672 |             ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2673 |               align; | 
 | 2674 |  | 
 | 2675 |             GetMagickToken(q,&q,token); | 
 | 2676 |             align=ParseMagickOption(MagickAlignOptions,MagickFalse,token); | 
 | 2677 |             if (align == -1) | 
 | 2678 |               { | 
 | 2679 |                 status=MagickFalse; | 
 | 2680 |                 break; | 
 | 2681 |               } | 
 | 2682 |             graphic_context[n]->align=(AlignType) align; | 
 | 2683 |             break; | 
 | 2684 |           } | 
 | 2685 |         if (LocaleCompare("text-anchor",keyword) == 0) | 
 | 2686 |           { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2687 |             ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2688 |               align; | 
 | 2689 |  | 
 | 2690 |             GetMagickToken(q,&q,token); | 
 | 2691 |             align=ParseMagickOption(MagickAlignOptions,MagickFalse,token); | 
 | 2692 |             if (align == -1) | 
 | 2693 |               { | 
 | 2694 |                 status=MagickFalse; | 
 | 2695 |                 break; | 
 | 2696 |               } | 
 | 2697 |             graphic_context[n]->align=(AlignType) align; | 
 | 2698 |             break; | 
 | 2699 |           } | 
 | 2700 |         if (LocaleCompare("text-antialias",keyword) == 0) | 
 | 2701 |           { | 
 | 2702 |             GetMagickToken(q,&q,token); | 
 | 2703 |             graphic_context[n]->text_antialias= | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2704 |               StringToLong(token) != 0 ? MagickTrue : MagickFalse; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2705 |             break; | 
 | 2706 |           } | 
 | 2707 |         if (LocaleCompare("text-undercolor",keyword) == 0) | 
 | 2708 |           { | 
 | 2709 |             GetMagickToken(q,&q,token); | 
 | 2710 |             (void) QueryColorDatabase(token,&graphic_context[n]->undercolor, | 
 | 2711 |               &image->exception); | 
 | 2712 |             break; | 
 | 2713 |           } | 
 | 2714 |         if (LocaleCompare("translate",keyword) == 0) | 
 | 2715 |           { | 
 | 2716 |             GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2717 |             affine.tx=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2718 |             GetMagickToken(q,&q,token); | 
 | 2719 |             if (*token == ',') | 
 | 2720 |               GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2721 |             affine.ty=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2722 |             break; | 
 | 2723 |           } | 
 | 2724 |         status=MagickFalse; | 
 | 2725 |         break; | 
 | 2726 |       } | 
 | 2727 |       case 'v': | 
 | 2728 |       case 'V': | 
 | 2729 |       { | 
 | 2730 |         if (LocaleCompare("viewbox",keyword) == 0) | 
 | 2731 |           { | 
 | 2732 |             GetMagickToken(q,&q,token); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2733 |             graphic_context[n]->viewbox.x=(ssize_t) ceil(StringToDouble(token)- | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2734 |               0.5); | 
| cristy | 06609ee | 2010-03-17 20:21:27 +0000 | [diff] [blame] | 2735 |             GetMagickToken(q,&q,token); | 
 | 2736 |             if (*token == ',') | 
 | 2737 |               GetMagickToken(q,&q,token); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2738 |             graphic_context[n]->viewbox.y=(ssize_t) ceil(StringToDouble(token)- | 
| cristy | 06609ee | 2010-03-17 20:21:27 +0000 | [diff] [blame] | 2739 |               0.5); | 
 | 2740 |             GetMagickToken(q,&q,token); | 
 | 2741 |             if (*token == ',') | 
 | 2742 |               GetMagickToken(q,&q,token); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2743 |             graphic_context[n]->viewbox.width=(size_t) floor( | 
| cristy | 06609ee | 2010-03-17 20:21:27 +0000 | [diff] [blame] | 2744 |               StringToDouble(token)+0.5); | 
 | 2745 |             GetMagickToken(q,&q,token); | 
 | 2746 |             if (*token == ',') | 
 | 2747 |               GetMagickToken(q,&q,token); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2748 |             graphic_context[n]->viewbox.height=(size_t) floor( | 
| cristy | 06609ee | 2010-03-17 20:21:27 +0000 | [diff] [blame] | 2749 |               StringToDouble(token)+0.5); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2750 |             break; | 
 | 2751 |           } | 
 | 2752 |         status=MagickFalse; | 
 | 2753 |         break; | 
 | 2754 |       } | 
 | 2755 |       default: | 
 | 2756 |       { | 
 | 2757 |         status=MagickFalse; | 
 | 2758 |         break; | 
 | 2759 |       } | 
 | 2760 |     } | 
 | 2761 |     if (status == MagickFalse) | 
 | 2762 |       break; | 
 | 2763 |     if ((affine.sx != 1.0) || (affine.rx != 0.0) || (affine.ry != 0.0) || | 
 | 2764 |         (affine.sy != 1.0) || (affine.tx != 0.0) || (affine.ty != 0.0)) | 
 | 2765 |       { | 
 | 2766 |         graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx; | 
 | 2767 |         graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx; | 
 | 2768 |         graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy; | 
 | 2769 |         graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy; | 
 | 2770 |         graphic_context[n]->affine.tx= | 
 | 2771 |           current.sx*affine.tx+current.ry*affine.ty+current.tx; | 
 | 2772 |         graphic_context[n]->affine.ty= | 
 | 2773 |           current.rx*affine.tx+current.sy*affine.ty+current.ty; | 
 | 2774 |       } | 
 | 2775 |     if (primitive_type == UndefinedPrimitive) | 
 | 2776 |       { | 
 | 2777 |         if (image->debug != MagickFalse) | 
 | 2778 |           (void) LogMagickEvent(DrawEvent,GetMagickModule(),"  %.*s", | 
 | 2779 |             (int) (q-p),p); | 
 | 2780 |         continue; | 
 | 2781 |       } | 
 | 2782 |     /* | 
 | 2783 |       Parse the primitive attributes. | 
 | 2784 |     */ | 
 | 2785 |     i=0; | 
 | 2786 |     j=0; | 
 | 2787 |     primitive_info[0].point.x=0.0; | 
 | 2788 |     primitive_info[0].point.y=0.0; | 
 | 2789 |     for (x=0; *q != '\0'; x++) | 
 | 2790 |     { | 
 | 2791 |       /* | 
 | 2792 |         Define points. | 
 | 2793 |       */ | 
 | 2794 |       if (IsPoint(q) == MagickFalse) | 
 | 2795 |         break; | 
 | 2796 |       GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2797 |       point.x=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2798 |       GetMagickToken(q,&q,token); | 
 | 2799 |       if (*token == ',') | 
 | 2800 |         GetMagickToken(q,&q,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2801 |       point.y=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2802 |       GetMagickToken(q,(const char **) NULL,token); | 
 | 2803 |       if (*token == ',') | 
 | 2804 |         GetMagickToken(q,&q,token); | 
 | 2805 |       primitive_info[i].primitive=primitive_type; | 
 | 2806 |       primitive_info[i].point=point; | 
 | 2807 |       primitive_info[i].coordinates=0; | 
 | 2808 |       primitive_info[i].method=FloodfillMethod; | 
 | 2809 |       i++; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2810 |       if (i < (ssize_t) number_points) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2811 |         continue; | 
 | 2812 |       number_points<<=1; | 
 | 2813 |       primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info, | 
 | 2814 |         (size_t) number_points,sizeof(*primitive_info)); | 
 | 2815 |       if (primitive_info == (PrimitiveInfo *) NULL) | 
 | 2816 |         { | 
 | 2817 |           (void) ThrowMagickException(&image->exception,GetMagickModule(), | 
 | 2818 |             ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); | 
 | 2819 |           break; | 
 | 2820 |         } | 
 | 2821 |     } | 
 | 2822 |     primitive_info[j].primitive=primitive_type; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2823 |     primitive_info[j].coordinates=(size_t) x; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2824 |     primitive_info[j].method=FloodfillMethod; | 
 | 2825 |     primitive_info[j].text=(char *) NULL; | 
 | 2826 |     /* | 
 | 2827 |       Circumscribe primitive within a circle. | 
 | 2828 |     */ | 
 | 2829 |     bounds.x1=primitive_info[j].point.x; | 
 | 2830 |     bounds.y1=primitive_info[j].point.y; | 
 | 2831 |     bounds.x2=primitive_info[j].point.x; | 
 | 2832 |     bounds.y2=primitive_info[j].point.y; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2833 |     for (k=1; k < (ssize_t) primitive_info[j].coordinates; k++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2834 |     { | 
 | 2835 |       point=primitive_info[j+k].point; | 
 | 2836 |       if (point.x < bounds.x1) | 
 | 2837 |         bounds.x1=point.x; | 
 | 2838 |       if (point.y < bounds.y1) | 
 | 2839 |         bounds.y1=point.y; | 
 | 2840 |       if (point.x > bounds.x2) | 
 | 2841 |         bounds.x2=point.x; | 
 | 2842 |       if (point.y > bounds.y2) | 
 | 2843 |         bounds.y2=point.y; | 
 | 2844 |     } | 
 | 2845 |     /* | 
 | 2846 |       Speculate how many points our primitive might consume. | 
 | 2847 |     */ | 
 | 2848 |     length=primitive_info[j].coordinates; | 
 | 2849 |     switch (primitive_type) | 
 | 2850 |     { | 
 | 2851 |       case RectanglePrimitive: | 
 | 2852 |       { | 
 | 2853 |         length*=5; | 
 | 2854 |         break; | 
 | 2855 |       } | 
 | 2856 |       case RoundRectanglePrimitive: | 
 | 2857 |       { | 
| cristy | 78817ad | 2010-05-07 12:25:34 +0000 | [diff] [blame] | 2858 |         length*=5+8*BezierQuantum; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2859 |         break; | 
 | 2860 |       } | 
 | 2861 |       case BezierPrimitive: | 
 | 2862 |       { | 
 | 2863 |         if (primitive_info[j].coordinates > 107) | 
 | 2864 |           (void) ThrowMagickException(&image->exception,GetMagickModule(), | 
 | 2865 |             DrawError,"TooManyBezierCoordinates","`%s'",token); | 
 | 2866 |         length=BezierQuantum*primitive_info[j].coordinates; | 
 | 2867 |         break; | 
 | 2868 |       } | 
 | 2869 |       case PathPrimitive: | 
 | 2870 |       { | 
 | 2871 |         char | 
 | 2872 |           *s, | 
 | 2873 |           *t; | 
 | 2874 |  | 
 | 2875 |         GetMagickToken(q,&q,token); | 
| cristy | 40a08ad | 2010-02-09 02:27:44 +0000 | [diff] [blame] | 2876 |         length=1; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2877 |         t=token; | 
 | 2878 |         for (s=token; *s != '\0'; s=t) | 
 | 2879 |         { | 
 | 2880 |           double | 
 | 2881 |             value; | 
 | 2882 |  | 
 | 2883 |           value=strtod(s,&t); | 
 | 2884 |           if (s == t) | 
 | 2885 |             { | 
 | 2886 |               t++; | 
 | 2887 |               continue; | 
 | 2888 |             } | 
| cristy | a0bf468 | 2010-05-14 12:15:55 +0000 | [diff] [blame] | 2889 |           length+=BezierQuantum; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2890 |         } | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2891 |         break; | 
 | 2892 |       } | 
 | 2893 |       case CirclePrimitive: | 
 | 2894 |       case ArcPrimitive: | 
 | 2895 |       case EllipsePrimitive: | 
 | 2896 |       { | 
 | 2897 |         MagickRealType | 
 | 2898 |           alpha, | 
 | 2899 |           beta, | 
 | 2900 |           radius; | 
 | 2901 |  | 
 | 2902 |         alpha=bounds.x2-bounds.x1; | 
 | 2903 |         beta=bounds.y2-bounds.y1; | 
 | 2904 |         radius=hypot((double) alpha,(double) beta); | 
 | 2905 |         length=2*((size_t) (MagickPI*radius))+6*BezierQuantum+360+1; | 
 | 2906 |         break; | 
 | 2907 |       } | 
 | 2908 |       default: | 
 | 2909 |         break; | 
 | 2910 |     } | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2911 |     if ((size_t) (i+length) >= number_points) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2912 |       { | 
 | 2913 |         /* | 
 | 2914 |           Resize based on speculative points required by primitive. | 
 | 2915 |         */ | 
| cristy | 9ce61b9 | 2010-05-12 16:30:26 +0000 | [diff] [blame] | 2916 |         number_points+=length+1; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2917 |         primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info, | 
 | 2918 |           (size_t) number_points,sizeof(*primitive_info)); | 
 | 2919 |         if (primitive_info == (PrimitiveInfo *) NULL) | 
 | 2920 |           { | 
 | 2921 |             (void) ThrowMagickException(&image->exception,GetMagickModule(), | 
 | 2922 |               ResourceLimitError,"MemoryAllocationFailed","`%s'", | 
 | 2923 |               image->filename); | 
 | 2924 |             break; | 
 | 2925 |           } | 
 | 2926 |       } | 
 | 2927 |     switch (primitive_type) | 
 | 2928 |     { | 
 | 2929 |       case PointPrimitive: | 
 | 2930 |       default: | 
 | 2931 |       { | 
 | 2932 |         if (primitive_info[j].coordinates != 1) | 
 | 2933 |           { | 
 | 2934 |             status=MagickFalse; | 
 | 2935 |             break; | 
 | 2936 |           } | 
 | 2937 |         TracePoint(primitive_info+j,primitive_info[j].point); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2938 |         i=(ssize_t) (j+primitive_info[j].coordinates); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2939 |         break; | 
 | 2940 |       } | 
 | 2941 |       case LinePrimitive: | 
 | 2942 |       { | 
 | 2943 |         if (primitive_info[j].coordinates != 2) | 
 | 2944 |           { | 
 | 2945 |             status=MagickFalse; | 
 | 2946 |             break; | 
 | 2947 |           } | 
 | 2948 |         TraceLine(primitive_info+j,primitive_info[j].point, | 
 | 2949 |           primitive_info[j+1].point); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2950 |         i=(ssize_t) (j+primitive_info[j].coordinates); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2951 |         break; | 
 | 2952 |       } | 
 | 2953 |       case RectanglePrimitive: | 
 | 2954 |       { | 
 | 2955 |         if (primitive_info[j].coordinates != 2) | 
 | 2956 |           { | 
 | 2957 |             status=MagickFalse; | 
 | 2958 |             break; | 
 | 2959 |           } | 
 | 2960 |         TraceRectangle(primitive_info+j,primitive_info[j].point, | 
 | 2961 |           primitive_info[j+1].point); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2962 |         i=(ssize_t) (j+primitive_info[j].coordinates); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2963 |         break; | 
 | 2964 |       } | 
 | 2965 |       case RoundRectanglePrimitive: | 
 | 2966 |       { | 
 | 2967 |         if (primitive_info[j].coordinates != 3) | 
 | 2968 |           { | 
 | 2969 |             status=MagickFalse; | 
 | 2970 |             break; | 
 | 2971 |           } | 
 | 2972 |         TraceRoundRectangle(primitive_info+j,primitive_info[j].point, | 
 | 2973 |           primitive_info[j+1].point,primitive_info[j+2].point); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2974 |         i=(ssize_t) (j+primitive_info[j].coordinates); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2975 |         break; | 
 | 2976 |       } | 
 | 2977 |       case ArcPrimitive: | 
 | 2978 |       { | 
 | 2979 |         if (primitive_info[j].coordinates != 3) | 
 | 2980 |           { | 
 | 2981 |             primitive_type=UndefinedPrimitive; | 
 | 2982 |             break; | 
 | 2983 |           } | 
 | 2984 |         TraceArc(primitive_info+j,primitive_info[j].point, | 
 | 2985 |           primitive_info[j+1].point,primitive_info[j+2].point); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2986 |         i=(ssize_t) (j+primitive_info[j].coordinates); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2987 |         break; | 
 | 2988 |       } | 
 | 2989 |       case EllipsePrimitive: | 
 | 2990 |       { | 
 | 2991 |         if (primitive_info[j].coordinates != 3) | 
 | 2992 |           { | 
 | 2993 |             status=MagickFalse; | 
 | 2994 |             break; | 
 | 2995 |           } | 
 | 2996 |         TraceEllipse(primitive_info+j,primitive_info[j].point, | 
 | 2997 |           primitive_info[j+1].point,primitive_info[j+2].point); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2998 |         i=(ssize_t) (j+primitive_info[j].coordinates); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2999 |         break; | 
 | 3000 |       } | 
 | 3001 |       case CirclePrimitive: | 
 | 3002 |       { | 
 | 3003 |         if (primitive_info[j].coordinates != 2) | 
 | 3004 |           { | 
 | 3005 |             status=MagickFalse; | 
 | 3006 |             break; | 
 | 3007 |           } | 
 | 3008 |         TraceCircle(primitive_info+j,primitive_info[j].point, | 
 | 3009 |           primitive_info[j+1].point); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3010 |         i=(ssize_t) (j+primitive_info[j].coordinates); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3011 |         break; | 
 | 3012 |       } | 
 | 3013 |       case PolylinePrimitive: | 
 | 3014 |         break; | 
 | 3015 |       case PolygonPrimitive: | 
 | 3016 |       { | 
 | 3017 |         primitive_info[i]=primitive_info[j]; | 
 | 3018 |         primitive_info[i].coordinates=0; | 
 | 3019 |         primitive_info[j].coordinates++; | 
 | 3020 |         i++; | 
 | 3021 |         break; | 
 | 3022 |       } | 
 | 3023 |       case BezierPrimitive: | 
 | 3024 |       { | 
 | 3025 |         if (primitive_info[j].coordinates < 3) | 
 | 3026 |           { | 
 | 3027 |             status=MagickFalse; | 
 | 3028 |             break; | 
 | 3029 |           } | 
 | 3030 |         TraceBezier(primitive_info+j,primitive_info[j].coordinates); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3031 |         i=(ssize_t) (j+primitive_info[j].coordinates); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3032 |         break; | 
 | 3033 |       } | 
 | 3034 |       case PathPrimitive: | 
 | 3035 |       { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3036 |         i=(ssize_t) (j+TracePath(primitive_info+j,token)); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3037 |         break; | 
 | 3038 |       } | 
 | 3039 |       case ColorPrimitive: | 
 | 3040 |       case MattePrimitive: | 
 | 3041 |       { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3042 |         ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3043 |           method; | 
 | 3044 |  | 
 | 3045 |         if (primitive_info[j].coordinates != 1) | 
 | 3046 |           { | 
 | 3047 |             status=MagickFalse; | 
 | 3048 |             break; | 
 | 3049 |           } | 
 | 3050 |         GetMagickToken(q,&q,token); | 
 | 3051 |         method=ParseMagickOption(MagickMethodOptions,MagickFalse,token); | 
 | 3052 |         if (method == -1) | 
 | 3053 |           { | 
 | 3054 |             status=MagickFalse; | 
 | 3055 |             break; | 
 | 3056 |           } | 
 | 3057 |         primitive_info[j].method=(PaintMethod) method; | 
 | 3058 |         break; | 
 | 3059 |       } | 
 | 3060 |       case TextPrimitive: | 
 | 3061 |       { | 
 | 3062 |         if (primitive_info[j].coordinates != 1) | 
 | 3063 |           { | 
 | 3064 |             status=MagickFalse; | 
 | 3065 |             break; | 
 | 3066 |           } | 
 | 3067 |         if (*token != ',') | 
 | 3068 |           GetMagickToken(q,&q,token); | 
 | 3069 |         primitive_info[j].text=AcquireString(token); | 
 | 3070 |         break; | 
 | 3071 |       } | 
 | 3072 |       case ImagePrimitive: | 
 | 3073 |       { | 
 | 3074 |         if (primitive_info[j].coordinates != 2) | 
 | 3075 |           { | 
 | 3076 |             status=MagickFalse; | 
 | 3077 |             break; | 
 | 3078 |           } | 
 | 3079 |         GetMagickToken(q,&q,token); | 
 | 3080 |         primitive_info[j].text=AcquireString(token); | 
 | 3081 |         break; | 
 | 3082 |       } | 
 | 3083 |     } | 
 | 3084 |     if (primitive_info == (PrimitiveInfo *) NULL) | 
 | 3085 |       break; | 
 | 3086 |     if (image->debug != MagickFalse) | 
 | 3087 |       (void) LogMagickEvent(DrawEvent,GetMagickModule(),"  %.*s",(int) (q-p),p); | 
 | 3088 |     if (status == MagickFalse) | 
 | 3089 |       break; | 
 | 3090 |     primitive_info[i].primitive=UndefinedPrimitive; | 
 | 3091 |     if (i == 0) | 
 | 3092 |       continue; | 
 | 3093 |     /* | 
 | 3094 |       Transform points. | 
 | 3095 |     */ | 
 | 3096 |     for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) | 
 | 3097 |     { | 
 | 3098 |       point=primitive_info[i].point; | 
 | 3099 |       primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+ | 
 | 3100 |         graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx; | 
 | 3101 |       primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+ | 
 | 3102 |         graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty; | 
 | 3103 |       point=primitive_info[i].point; | 
 | 3104 |       if (point.x < graphic_context[n]->bounds.x1) | 
 | 3105 |         graphic_context[n]->bounds.x1=point.x; | 
 | 3106 |       if (point.y < graphic_context[n]->bounds.y1) | 
 | 3107 |         graphic_context[n]->bounds.y1=point.y; | 
 | 3108 |       if (point.x > graphic_context[n]->bounds.x2) | 
 | 3109 |         graphic_context[n]->bounds.x2=point.x; | 
 | 3110 |       if (point.y > graphic_context[n]->bounds.y2) | 
 | 3111 |         graphic_context[n]->bounds.y2=point.y; | 
 | 3112 |       if (primitive_info[i].primitive == ImagePrimitive) | 
 | 3113 |         break; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3114 |       if (i >= (ssize_t) number_points) | 
| cristy | 9ce61b9 | 2010-05-12 16:30:26 +0000 | [diff] [blame] | 3115 |         ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3116 |     } | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3117 |     if (graphic_context[n]->render != MagickFalse) | 
 | 3118 |       { | 
 | 3119 |         if ((n != 0) && (graphic_context[n]->clip_mask != (char *) NULL) && | 
 | 3120 |             (LocaleCompare(graphic_context[n]->clip_mask, | 
 | 3121 |              graphic_context[n-1]->clip_mask) != 0)) | 
 | 3122 |           (void) DrawClipPath(image,graphic_context[n], | 
 | 3123 |             graphic_context[n]->clip_mask); | 
 | 3124 |         (void) DrawPrimitive(image,graphic_context[n],primitive_info); | 
 | 3125 |       } | 
 | 3126 |     if (primitive_info->text != (char *) NULL) | 
 | 3127 |       primitive_info->text=(char *) RelinquishMagickMemory( | 
 | 3128 |         primitive_info->text); | 
 | 3129 |     proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType) | 
 | 3130 |       primitive_extent); | 
 | 3131 |     if (proceed == MagickFalse) | 
 | 3132 |       break; | 
 | 3133 |   } | 
 | 3134 |   if (image->debug != MagickFalse) | 
 | 3135 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end draw-image"); | 
 | 3136 |   /* | 
 | 3137 |     Relinquish resources. | 
 | 3138 |   */ | 
 | 3139 |   token=DestroyString(token); | 
 | 3140 |   if (primitive_info != (PrimitiveInfo *) NULL) | 
 | 3141 |     primitive_info=(PrimitiveInfo *) RelinquishMagickMemory(primitive_info); | 
 | 3142 |   primitive=DestroyString(primitive); | 
 | 3143 |   for ( ; n >= 0; n--) | 
 | 3144 |     graphic_context[n]=DestroyDrawInfo(graphic_context[n]); | 
 | 3145 |   graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context); | 
 | 3146 |   if (status == MagickFalse) | 
 | 3147 |     ThrowBinaryException(DrawError,"NonconformingDrawingPrimitiveDefinition", | 
 | 3148 |       keyword); | 
 | 3149 |   return(status); | 
 | 3150 | } | 
 | 3151 |  | 
 | 3152 | /* | 
 | 3153 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 3154 | %                                                                             % | 
 | 3155 | %                                                                             % | 
 | 3156 | %                                                                             % | 
 | 3157 | %     D r a w G r a d i e n t I m a g e                                       % | 
 | 3158 | %                                                                             % | 
 | 3159 | %                                                                             % | 
 | 3160 | %                                                                             % | 
 | 3161 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 3162 | % | 
 | 3163 | %  DrawGradientImage() draws a linear gradient on the image. | 
 | 3164 | % | 
 | 3165 | %  The format of the DrawGradientImage method is: | 
 | 3166 | % | 
 | 3167 | %      MagickBooleanType DrawGradientImage(Image *image, | 
 | 3168 | %        const DrawInfo *draw_info) | 
 | 3169 | % | 
 | 3170 | %  A description of each parameter follows: | 
 | 3171 | % | 
 | 3172 | %    o image: the image. | 
 | 3173 | % | 
 | 3174 | %    o _info: the draw info. | 
 | 3175 | % | 
 | 3176 | */ | 
 | 3177 |  | 
 | 3178 | static inline MagickRealType GetStopColorOffset(const GradientInfo *gradient, | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3179 |   const ssize_t x,const ssize_t y) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3180 | { | 
 | 3181 |   switch (gradient->type) | 
 | 3182 |   { | 
 | 3183 |     case UndefinedGradient: | 
 | 3184 |     case LinearGradient: | 
 | 3185 |     { | 
 | 3186 |       MagickRealType | 
 | 3187 |         gamma, | 
 | 3188 |         length, | 
 | 3189 |         offset, | 
 | 3190 |         scale; | 
 | 3191 |  | 
 | 3192 |       PointInfo | 
 | 3193 |         p, | 
 | 3194 |         q; | 
 | 3195 |  | 
 | 3196 |       const SegmentInfo | 
 | 3197 |         *gradient_vector; | 
 | 3198 |  | 
 | 3199 |       gradient_vector=(&gradient->gradient_vector); | 
 | 3200 |       p.x=gradient_vector->x2-gradient_vector->x1; | 
 | 3201 |       p.y=gradient_vector->y2-gradient_vector->y1; | 
 | 3202 |       q.x=(double) x-gradient_vector->x1; | 
 | 3203 |       q.y=(double) y-gradient_vector->y1; | 
 | 3204 |       length=sqrt(q.x*q.x+q.y*q.y); | 
 | 3205 |       gamma=sqrt(p.x*p.x+p.y*p.y)*length; | 
 | 3206 |       gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma); | 
 | 3207 |       scale=p.x*q.x+p.y*q.y; | 
 | 3208 |       offset=gamma*scale*length; | 
 | 3209 |       return(offset); | 
 | 3210 |     } | 
 | 3211 |     case RadialGradient: | 
 | 3212 |     { | 
 | 3213 |       MagickRealType | 
 | 3214 |         length, | 
 | 3215 |         offset; | 
 | 3216 |  | 
 | 3217 |       PointInfo | 
 | 3218 |         v; | 
 | 3219 |  | 
 | 3220 |       v.x=(double) x-gradient->center.x; | 
 | 3221 |       v.y=(double) y-gradient->center.y; | 
 | 3222 |       length=sqrt(v.x*v.x+v.y*v.y); | 
 | 3223 |       if (gradient->spread == RepeatSpread) | 
 | 3224 |         return(length); | 
 | 3225 |       offset=length/gradient->radius; | 
 | 3226 |       return(offset); | 
 | 3227 |     } | 
 | 3228 |   } | 
 | 3229 |   return(0.0); | 
 | 3230 | } | 
 | 3231 |  | 
 | 3232 | MagickExport MagickBooleanType DrawGradientImage(Image *image, | 
 | 3233 |   const DrawInfo *draw_info) | 
 | 3234 | { | 
| cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 3235 |   CacheView | 
 | 3236 |     *image_view; | 
 | 3237 |  | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3238 |   const GradientInfo | 
 | 3239 |     *gradient; | 
 | 3240 |  | 
 | 3241 |   const SegmentInfo | 
 | 3242 |     *gradient_vector; | 
 | 3243 |  | 
 | 3244 |   ExceptionInfo | 
 | 3245 |     *exception; | 
 | 3246 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3247 |   ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3248 |     y; | 
 | 3249 |  | 
 | 3250 |   MagickBooleanType | 
 | 3251 |     status; | 
 | 3252 |  | 
 | 3253 |   MagickPixelPacket | 
 | 3254 |     zero; | 
 | 3255 |  | 
 | 3256 |   MagickRealType | 
 | 3257 |     length; | 
 | 3258 |  | 
 | 3259 |   PointInfo | 
 | 3260 |     point; | 
 | 3261 |  | 
 | 3262 |   RectangleInfo | 
 | 3263 |     bounding_box; | 
 | 3264 |  | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3265 |   /* | 
 | 3266 |     Draw linear or radial gradient on image. | 
 | 3267 |   */ | 
 | 3268 |   assert(image != (Image *) NULL); | 
 | 3269 |   assert(image->signature == MagickSignature); | 
 | 3270 |   if (image->debug != MagickFalse) | 
 | 3271 |     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); | 
 | 3272 |   assert(draw_info != (const DrawInfo *) NULL); | 
 | 3273 |   gradient=(&draw_info->gradient); | 
 | 3274 |   gradient_vector=(&gradient->gradient_vector); | 
 | 3275 |   point.x=gradient_vector->x2-gradient_vector->x1; | 
 | 3276 |   point.y=gradient_vector->y2-gradient_vector->y1; | 
 | 3277 |   length=sqrt(point.x*point.x+point.y*point.y); | 
 | 3278 |   bounding_box=gradient->bounding_box; | 
 | 3279 |   status=MagickTrue; | 
 | 3280 |   exception=(&image->exception); | 
 | 3281 |   GetMagickPixelPacket(image,&zero); | 
 | 3282 |   image_view=AcquireCacheView(image); | 
| cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3283 | #if defined(MAGICKCORE_OPENMP_SUPPORT) | 
 | 3284 |   #pragma omp parallel for schedule(dynamic,4) shared(status) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3285 | #endif | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3286 |   for (y=bounding_box.y; y < (ssize_t) bounding_box.height; y++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3287 |   { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3288 |     ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3289 |       j; | 
 | 3290 |  | 
 | 3291 |     MagickPixelPacket | 
 | 3292 |       composite, | 
 | 3293 |       pixel; | 
 | 3294 |  | 
 | 3295 |     MagickRealType | 
 | 3296 |       alpha, | 
 | 3297 |       offset; | 
 | 3298 |  | 
 | 3299 |     register IndexPacket | 
| cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3300 |       *restrict indexes; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3301 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3302 |     register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3303 |       i, | 
 | 3304 |       x; | 
 | 3305 |  | 
 | 3306 |     register PixelPacket | 
| cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3307 |       *restrict q; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3308 |  | 
 | 3309 |     if (status == MagickFalse) | 
 | 3310 |       continue; | 
 | 3311 |     q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); | 
 | 3312 |     if (q == (PixelPacket *) NULL) | 
 | 3313 |       { | 
 | 3314 |         status=MagickFalse; | 
 | 3315 |         continue; | 
 | 3316 |       } | 
 | 3317 |     indexes=GetCacheViewAuthenticIndexQueue(image_view); | 
 | 3318 |     pixel=zero; | 
 | 3319 |     composite=zero; | 
 | 3320 |     offset=GetStopColorOffset(gradient,0,y); | 
 | 3321 |     if (gradient->type != RadialGradient) | 
 | 3322 |       offset/=length; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3323 |     for (x=bounding_box.x; x < (ssize_t) bounding_box.width; x++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3324 |     { | 
 | 3325 |       SetMagickPixelPacket(image,q,indexes+x,&pixel); | 
 | 3326 |       switch (gradient->spread) | 
 | 3327 |       { | 
 | 3328 |         case UndefinedSpread: | 
 | 3329 |         case PadSpread: | 
 | 3330 |         { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3331 |           if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) || | 
 | 3332 |               (y != (ssize_t) ceil(gradient_vector->y1-0.5))) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3333 |             { | 
 | 3334 |               offset=GetStopColorOffset(gradient,x,y); | 
 | 3335 |               if (gradient->type != RadialGradient) | 
 | 3336 |                 offset/=length; | 
 | 3337 |             } | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3338 |           for (i=0; i < (ssize_t) gradient->number_stops; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3339 |             if (offset < gradient->stops[i].offset) | 
 | 3340 |               break; | 
 | 3341 |           if ((offset < 0.0) || (i == 0)) | 
 | 3342 |             composite=gradient->stops[0].color; | 
 | 3343 |           else | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3344 |             if ((offset > 1.0) || (i == (ssize_t) gradient->number_stops)) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3345 |               composite=gradient->stops[gradient->number_stops-1].color; | 
 | 3346 |             else | 
 | 3347 |               { | 
 | 3348 |                 j=i; | 
 | 3349 |                 i--; | 
 | 3350 |                 alpha=(offset-gradient->stops[i].offset)/ | 
 | 3351 |                   (gradient->stops[j].offset-gradient->stops[i].offset); | 
 | 3352 |                 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha, | 
 | 3353 |                   &gradient->stops[j].color,alpha,&composite); | 
 | 3354 |               } | 
 | 3355 |           break; | 
 | 3356 |         } | 
 | 3357 |         case ReflectSpread: | 
 | 3358 |         { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3359 |           if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) || | 
 | 3360 |               (y != (ssize_t) ceil(gradient_vector->y1-0.5))) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3361 |             { | 
 | 3362 |               offset=GetStopColorOffset(gradient,x,y); | 
 | 3363 |               if (gradient->type != RadialGradient) | 
 | 3364 |                 offset/=length; | 
 | 3365 |             } | 
 | 3366 |           if (offset < 0.0) | 
 | 3367 |             offset=(-offset); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3368 |           if ((ssize_t) fmod(offset,2.0) == 0) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3369 |             offset=fmod(offset,1.0); | 
 | 3370 |           else | 
 | 3371 |             offset=1.0-fmod(offset,1.0); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3372 |           for (i=0; i < (ssize_t) gradient->number_stops; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3373 |             if (offset < gradient->stops[i].offset) | 
 | 3374 |               break; | 
 | 3375 |           if (i == 0) | 
 | 3376 |             composite=gradient->stops[0].color; | 
 | 3377 |           else | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3378 |             if (i == (ssize_t) gradient->number_stops) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3379 |               composite=gradient->stops[gradient->number_stops-1].color; | 
 | 3380 |             else | 
 | 3381 |               { | 
 | 3382 |                 j=i; | 
 | 3383 |                 i--; | 
 | 3384 |                 alpha=(offset-gradient->stops[i].offset)/ | 
 | 3385 |                   (gradient->stops[j].offset-gradient->stops[i].offset); | 
 | 3386 |                 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha, | 
 | 3387 |                   &gradient->stops[j].color,alpha,&composite); | 
 | 3388 |               } | 
 | 3389 |           break; | 
 | 3390 |         } | 
 | 3391 |         case RepeatSpread: | 
 | 3392 |         { | 
 | 3393 |           MagickBooleanType | 
 | 3394 |             antialias; | 
 | 3395 |  | 
 | 3396 |           MagickRealType | 
 | 3397 |             repeat; | 
 | 3398 |  | 
 | 3399 |           antialias=MagickFalse; | 
 | 3400 |           repeat=0.0; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3401 |           if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) || | 
 | 3402 |               (y != (ssize_t) ceil(gradient_vector->y1-0.5))) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3403 |             { | 
 | 3404 |               offset=GetStopColorOffset(gradient,x,y); | 
 | 3405 |               if (gradient->type == LinearGradient) | 
 | 3406 |                 { | 
 | 3407 |                   repeat=fmod(offset,length); | 
 | 3408 |                   if (repeat < 0.0) | 
 | 3409 |                     repeat=length-fmod(-repeat,length); | 
 | 3410 |                   else | 
 | 3411 |                     repeat=fmod(offset,length); | 
 | 3412 |                   antialias=(repeat < length) && ((repeat+1.0) > length) ? | 
 | 3413 |                     MagickTrue : MagickFalse; | 
 | 3414 |                   offset=repeat/length; | 
 | 3415 |                 } | 
 | 3416 |               else | 
 | 3417 |                 { | 
 | 3418 |                   repeat=fmod(offset,gradient->radius); | 
 | 3419 |                   if (repeat < 0.0) | 
 | 3420 |                     repeat=gradient->radius-fmod(-repeat,gradient->radius); | 
 | 3421 |                   else | 
 | 3422 |                     repeat=fmod(offset,gradient->radius); | 
 | 3423 |                   antialias=repeat+1.0 > gradient->radius ? | 
 | 3424 |                     MagickTrue : MagickFalse; | 
 | 3425 |                   offset=repeat/gradient->radius; | 
 | 3426 |                 } | 
 | 3427 |             } | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3428 |           for (i=0; i < (ssize_t) gradient->number_stops; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3429 |             if (offset < gradient->stops[i].offset) | 
 | 3430 |               break; | 
 | 3431 |           if (i == 0) | 
 | 3432 |             composite=gradient->stops[0].color; | 
 | 3433 |           else | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3434 |             if (i == (ssize_t) gradient->number_stops) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3435 |               composite=gradient->stops[gradient->number_stops-1].color; | 
 | 3436 |             else | 
 | 3437 |               { | 
 | 3438 |                 j=i; | 
 | 3439 |                 i--; | 
 | 3440 |                 alpha=(offset-gradient->stops[i].offset)/ | 
 | 3441 |                   (gradient->stops[j].offset-gradient->stops[i].offset); | 
 | 3442 |                 if (antialias != MagickFalse) | 
 | 3443 |                   { | 
 | 3444 |                     if (gradient->type == LinearGradient) | 
 | 3445 |                       alpha=length-repeat; | 
 | 3446 |                     else | 
 | 3447 |                       alpha=gradient->radius-repeat; | 
 | 3448 |                     i=0; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3449 |                     j=(ssize_t) gradient->number_stops-1L; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3450 |                   } | 
 | 3451 |                 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha, | 
 | 3452 |                   &gradient->stops[j].color,alpha,&composite); | 
 | 3453 |               } | 
 | 3454 |           break; | 
 | 3455 |         } | 
 | 3456 |       } | 
 | 3457 |       MagickPixelCompositeOver(&composite,composite.opacity,&pixel, | 
 | 3458 |         pixel.opacity,&pixel); | 
 | 3459 |       SetPixelPacket(image,&pixel,q,indexes+x); | 
 | 3460 |       q++; | 
 | 3461 |     } | 
 | 3462 |     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) | 
 | 3463 |       status=MagickFalse; | 
 | 3464 |   } | 
 | 3465 |   image_view=DestroyCacheView(image_view); | 
 | 3466 |   return(status); | 
 | 3467 | } | 
 | 3468 |  | 
 | 3469 | /* | 
 | 3470 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 3471 | %                                                                             % | 
 | 3472 | %                                                                             % | 
 | 3473 | %                                                                             % | 
 | 3474 | %   D r a w P a t t e r n P a t h                                             % | 
 | 3475 | %                                                                             % | 
 | 3476 | %                                                                             % | 
 | 3477 | %                                                                             % | 
 | 3478 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 3479 | % | 
 | 3480 | %  DrawPatternPath() draws a pattern. | 
 | 3481 | % | 
 | 3482 | %  The format of the DrawPatternPath method is: | 
 | 3483 | % | 
 | 3484 | %      MagickBooleanType DrawPatternPath(Image *image,const DrawInfo *draw_info, | 
 | 3485 | %        const char *name,Image **pattern) | 
 | 3486 | % | 
 | 3487 | %  A description of each parameter follows: | 
 | 3488 | % | 
 | 3489 | %    o image: the image. | 
 | 3490 | % | 
 | 3491 | %    o draw_info: the draw info. | 
 | 3492 | % | 
 | 3493 | %    o name: the pattern name. | 
 | 3494 | % | 
 | 3495 | %    o image: the image. | 
 | 3496 | % | 
 | 3497 | */ | 
 | 3498 | MagickExport MagickBooleanType DrawPatternPath(Image *image, | 
 | 3499 |   const DrawInfo *draw_info,const char *name,Image **pattern) | 
 | 3500 | { | 
 | 3501 |   char | 
 | 3502 |     property[MaxTextExtent]; | 
 | 3503 |  | 
 | 3504 |   const char | 
 | 3505 |     *geometry, | 
 | 3506 |     *path; | 
 | 3507 |  | 
 | 3508 |   DrawInfo | 
 | 3509 |     *clone_info; | 
 | 3510 |  | 
 | 3511 |   ImageInfo | 
 | 3512 |     *image_info; | 
 | 3513 |  | 
 | 3514 |   MagickBooleanType | 
 | 3515 |     status; | 
 | 3516 |  | 
 | 3517 |   assert(image != (Image *) NULL); | 
 | 3518 |   assert(image->signature == MagickSignature); | 
 | 3519 |   if (image->debug != MagickFalse) | 
 | 3520 |     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); | 
 | 3521 |   assert(draw_info != (const DrawInfo *) NULL); | 
 | 3522 |   assert(name != (const char *) NULL); | 
 | 3523 |   (void) FormatMagickString(property,MaxTextExtent,"%s",name); | 
 | 3524 |   path=GetImageArtifact(image,property); | 
 | 3525 |   if (path == (const char *) NULL) | 
 | 3526 |     return(MagickFalse); | 
 | 3527 |   (void) FormatMagickString(property,MaxTextExtent,"%s-geometry",name); | 
 | 3528 |   geometry=GetImageArtifact(image,property); | 
 | 3529 |   if (geometry == (const char *) NULL) | 
 | 3530 |     return(MagickFalse); | 
 | 3531 |   if ((*pattern) != (Image *) NULL) | 
 | 3532 |     *pattern=DestroyImage(*pattern); | 
 | 3533 |   image_info=AcquireImageInfo(); | 
 | 3534 |   image_info->size=AcquireString(geometry); | 
 | 3535 |   *pattern=AcquireImage(image_info); | 
 | 3536 |   image_info=DestroyImageInfo(image_info); | 
 | 3537 |   (void) QueryColorDatabase("#00000000",&(*pattern)->background_color, | 
 | 3538 |     &image->exception); | 
 | 3539 |   (void) SetImageBackgroundColor(*pattern); | 
 | 3540 |   if (image->debug != MagickFalse) | 
 | 3541 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(), | 
 | 3542 |       "begin pattern-path %s %s",name,geometry); | 
 | 3543 |   clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); | 
 | 3544 |   clone_info->fill_pattern=NewImageList(); | 
 | 3545 |   clone_info->stroke_pattern=NewImageList(); | 
 | 3546 |   (void) CloneString(&clone_info->primitive,path); | 
 | 3547 |   status=DrawImage(*pattern,clone_info); | 
 | 3548 |   clone_info=DestroyDrawInfo(clone_info); | 
 | 3549 |   if (image->debug != MagickFalse) | 
 | 3550 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end pattern-path"); | 
 | 3551 |   return(status); | 
 | 3552 | } | 
 | 3553 |  | 
 | 3554 | /* | 
 | 3555 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 3556 | %                                                                             % | 
 | 3557 | %                                                                             % | 
 | 3558 | %                                                                             % | 
 | 3559 | +   D r a w P o l y g o n P r i m i t i v e                                   % | 
 | 3560 | %                                                                             % | 
 | 3561 | %                                                                             % | 
 | 3562 | %                                                                             % | 
 | 3563 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 3564 | % | 
 | 3565 | %  DrawPolygonPrimitive() draws a polygon on the image. | 
 | 3566 | % | 
 | 3567 | %  The format of the DrawPolygonPrimitive method is: | 
 | 3568 | % | 
 | 3569 | %      MagickBooleanType DrawPolygonPrimitive(Image *image, | 
 | 3570 | %        const DrawInfo *draw_info,const PrimitiveInfo *primitive_info) | 
 | 3571 | % | 
 | 3572 | %  A description of each parameter follows: | 
 | 3573 | % | 
 | 3574 | %    o image: the image. | 
 | 3575 | % | 
 | 3576 | %    o draw_info: the draw info. | 
 | 3577 | % | 
 | 3578 | %    o primitive_info: Specifies a pointer to a PrimitiveInfo structure. | 
 | 3579 | % | 
 | 3580 | */ | 
 | 3581 |  | 
 | 3582 | static PolygonInfo **DestroyPolygonThreadSet(PolygonInfo **polygon_info) | 
 | 3583 | { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3584 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3585 |     i; | 
 | 3586 |  | 
 | 3587 |   assert(polygon_info != (PolygonInfo **) NULL); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3588 |   for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3589 |     if (polygon_info[i] != (PolygonInfo *) NULL) | 
 | 3590 |       polygon_info[i]=DestroyPolygonInfo(polygon_info[i]); | 
 | 3591 |   polygon_info=(PolygonInfo **) RelinquishAlignedMemory(polygon_info); | 
 | 3592 |   return(polygon_info); | 
 | 3593 | } | 
 | 3594 |  | 
 | 3595 | static PolygonInfo **AcquirePolygonThreadSet(const DrawInfo *draw_info, | 
 | 3596 |   const PrimitiveInfo *primitive_info) | 
 | 3597 | { | 
 | 3598 |   PathInfo | 
| cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3599 |     *restrict path_info; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3600 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3601 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3602 |     i; | 
 | 3603 |  | 
 | 3604 |   PolygonInfo | 
 | 3605 |     **polygon_info; | 
 | 3606 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3607 |   size_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3608 |     number_threads; | 
 | 3609 |  | 
 | 3610 |   number_threads=GetOpenMPMaximumThreads(); | 
 | 3611 |   polygon_info=(PolygonInfo **) AcquireAlignedMemory(number_threads, | 
 | 3612 |     sizeof(*polygon_info)); | 
 | 3613 |   if (polygon_info == (PolygonInfo **) NULL) | 
 | 3614 |     return((PolygonInfo **) NULL); | 
 | 3615 |   (void) ResetMagickMemory(polygon_info,0,GetOpenMPMaximumThreads()* | 
 | 3616 |     sizeof(*polygon_info)); | 
 | 3617 |   path_info=ConvertPrimitiveToPath(draw_info,primitive_info); | 
 | 3618 |   if (path_info == (PathInfo *) NULL) | 
 | 3619 |     return(DestroyPolygonThreadSet(polygon_info)); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3620 |   for (i=0; i < (ssize_t) number_threads; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3621 |   { | 
 | 3622 |     polygon_info[i]=ConvertPathToPolygon(draw_info,path_info); | 
 | 3623 |     if (polygon_info[i] == (PolygonInfo *) NULL) | 
 | 3624 |       return(DestroyPolygonThreadSet(polygon_info)); | 
 | 3625 |   } | 
 | 3626 |   path_info=(PathInfo *) RelinquishMagickMemory(path_info); | 
 | 3627 |   return(polygon_info); | 
 | 3628 | } | 
 | 3629 |  | 
 | 3630 | static MagickRealType GetPixelOpacity(PolygonInfo *polygon_info, | 
 | 3631 |   const MagickRealType mid,const MagickBooleanType fill, | 
| cristy | 77f38fb | 2010-04-22 15:51:47 +0000 | [diff] [blame] | 3632 |   const FillRule fill_rule,const double x,const double y, | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3633 |   MagickRealType *stroke_opacity) | 
 | 3634 | { | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3635 |   MagickRealType | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3636 |     alpha, | 
 | 3637 |     beta, | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3638 |     distance, | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3639 |     subpath_opacity; | 
 | 3640 |  | 
 | 3641 |   PointInfo | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3642 |     delta; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3643 |  | 
 | 3644 |   register EdgeInfo | 
 | 3645 |     *p; | 
 | 3646 |  | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3647 |   register const PointInfo | 
 | 3648 |     *q; | 
 | 3649 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3650 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3651 |     i; | 
 | 3652 |  | 
| cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 3653 |   ssize_t | 
 | 3654 |     j, | 
 | 3655 |     winding_number; | 
 | 3656 |  | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3657 |   /* | 
 | 3658 |     Compute fill & stroke opacity for this (x,y) point. | 
 | 3659 |   */ | 
 | 3660 |   *stroke_opacity=0.0; | 
 | 3661 |   subpath_opacity=0.0; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3662 |   p=polygon_info->edges; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3663 |   for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3664 |   { | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3665 |     if (y <= (p->bounds.y1-mid-0.5)) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3666 |       break; | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3667 |     if (y > (p->bounds.y2+mid+0.5)) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3668 |       { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3669 |         (void) DestroyEdge(polygon_info,(size_t) j); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3670 |         continue; | 
 | 3671 |       } | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3672 |     if ((x <= (p->bounds.x1-mid-0.5)) || (x > (p->bounds.x2+mid+0.5))) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3673 |       continue; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3674 |     i=(ssize_t) MagickMax((double) p->highwater,1.0); | 
 | 3675 |     for ( ; i < (ssize_t) p->number_points; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3676 |     { | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3677 |       if (y <= (p->points[i-1].y-mid-0.5)) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3678 |         break; | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3679 |       if (y > (p->points[i].y+mid+0.5)) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3680 |         continue; | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3681 |       if (p->scanline != y) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3682 |         { | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3683 |           p->scanline=y; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3684 |           p->highwater=(size_t) i; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3685 |         } | 
 | 3686 |       /* | 
 | 3687 |         Compute distance between a point and an edge. | 
 | 3688 |       */ | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3689 |       q=p->points+i-1; | 
 | 3690 |       delta.x=(q+1)->x-q->x; | 
 | 3691 |       delta.y=(q+1)->y-q->y; | 
 | 3692 |       beta=delta.x*(x-q->x)+delta.y*(y-q->y); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3693 |       if (beta < 0.0) | 
 | 3694 |         { | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3695 |           delta.x=x-q->x; | 
 | 3696 |           delta.y=y-q->y; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3697 |           distance=delta.x*delta.x+delta.y*delta.y; | 
 | 3698 |         } | 
 | 3699 |       else | 
 | 3700 |         { | 
 | 3701 |           alpha=delta.x*delta.x+delta.y*delta.y; | 
 | 3702 |           if (beta > alpha) | 
 | 3703 |             { | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3704 |               delta.x=x-(q+1)->x; | 
 | 3705 |               delta.y=y-(q+1)->y; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3706 |               distance=delta.x*delta.x+delta.y*delta.y; | 
 | 3707 |             } | 
 | 3708 |           else | 
 | 3709 |             { | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3710 |               alpha=1.0/alpha; | 
 | 3711 |               beta=delta.x*(y-q->y)-delta.y*(x-q->x); | 
 | 3712 |               distance=alpha*beta*beta; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3713 |             } | 
 | 3714 |         } | 
 | 3715 |       /* | 
 | 3716 |         Compute stroke & subpath opacity. | 
 | 3717 |       */ | 
 | 3718 |       beta=0.0; | 
 | 3719 |       if (p->ghostline == MagickFalse) | 
 | 3720 |         { | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3721 |           alpha=mid+0.5; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3722 |           if ((*stroke_opacity < 1.0) && | 
 | 3723 |               (distance <= ((alpha+0.25)*(alpha+0.25)))) | 
 | 3724 |             { | 
 | 3725 |               alpha=mid-0.5; | 
 | 3726 |               if (distance <= ((alpha+0.25)*(alpha+0.25))) | 
 | 3727 |                 *stroke_opacity=1.0; | 
 | 3728 |               else | 
 | 3729 |                 { | 
 | 3730 |                   beta=1.0; | 
 | 3731 |                   if (distance != 1.0) | 
 | 3732 |                     beta=sqrt((double) distance); | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3733 |                   alpha=beta-mid-0.5; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3734 |                   if (*stroke_opacity < ((alpha-0.25)*(alpha-0.25))) | 
 | 3735 |                     *stroke_opacity=(alpha-0.25)*(alpha-0.25); | 
 | 3736 |                 } | 
 | 3737 |             } | 
 | 3738 |         } | 
 | 3739 |       if ((fill == MagickFalse) || (distance > 1.0) || (subpath_opacity >= 1.0)) | 
 | 3740 |         continue; | 
 | 3741 |       if (distance <= 0.0) | 
 | 3742 |         { | 
 | 3743 |           subpath_opacity=1.0; | 
 | 3744 |           continue; | 
 | 3745 |         } | 
 | 3746 |       if (distance > 1.0) | 
 | 3747 |         continue; | 
 | 3748 |       if (beta == 0.0) | 
 | 3749 |         { | 
 | 3750 |           beta=1.0; | 
 | 3751 |           if (distance != 1.0) | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3752 |             beta=sqrt(distance); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3753 |         } | 
 | 3754 |       alpha=beta-1.0; | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3755 |       if (subpath_opacity < (alpha*alpha)) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3756 |         subpath_opacity=alpha*alpha; | 
 | 3757 |     } | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3758 |   } | 
 | 3759 |   /* | 
 | 3760 |     Compute fill opacity. | 
 | 3761 |   */ | 
 | 3762 |   if (fill == MagickFalse) | 
 | 3763 |     return(0.0); | 
 | 3764 |   if (subpath_opacity >= 1.0) | 
 | 3765 |     return(1.0); | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3766 |   /* | 
 | 3767 |     Determine winding number. | 
 | 3768 |   */ | 
 | 3769 |   winding_number=0; | 
 | 3770 |   p=polygon_info->edges; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3771 |   for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++) | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3772 |   { | 
 | 3773 |     if (y <= p->bounds.y1) | 
 | 3774 |       break; | 
 | 3775 |     if ((y > p->bounds.y2) || (x <= p->bounds.x1)) | 
 | 3776 |       continue; | 
 | 3777 |     if (x > p->bounds.x2) | 
 | 3778 |       { | 
 | 3779 |         winding_number+=p->direction ? 1 : -1; | 
 | 3780 |         continue; | 
 | 3781 |       } | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3782 |     i=(ssize_t) MagickMax((double) p->highwater,1.0); | 
 | 3783 |     for ( ; i < (ssize_t) p->number_points; i++) | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3784 |       if (y <= p->points[i].y) | 
 | 3785 |         break; | 
 | 3786 |     q=p->points+i-1; | 
 | 3787 |     if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x))) | 
 | 3788 |       winding_number+=p->direction ? 1 : -1; | 
 | 3789 |   } | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3790 |   if (fill_rule != NonZeroRule) | 
 | 3791 |     { | 
 | 3792 |       if ((MagickAbsoluteValue(winding_number) & 0x01) != 0) | 
 | 3793 |         return(1.0); | 
 | 3794 |     } | 
 | 3795 |   else | 
 | 3796 |     if (MagickAbsoluteValue(winding_number) != 0) | 
 | 3797 |       return(1.0); | 
 | 3798 |   return(subpath_opacity); | 
 | 3799 | } | 
 | 3800 |  | 
 | 3801 | static MagickBooleanType DrawPolygonPrimitive(Image *image, | 
 | 3802 |   const DrawInfo *draw_info,const PrimitiveInfo *primitive_info) | 
 | 3803 | { | 
| cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3804 |   CacheView | 
 | 3805 |     *image_view; | 
 | 3806 |  | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3807 |   ExceptionInfo | 
 | 3808 |     *exception; | 
 | 3809 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3810 |   ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3811 |     start, | 
 | 3812 |     stop, | 
 | 3813 |     y; | 
 | 3814 |  | 
 | 3815 |   MagickBooleanType | 
 | 3816 |     fill, | 
 | 3817 |     status; | 
 | 3818 |  | 
 | 3819 |   MagickRealType | 
 | 3820 |     mid; | 
 | 3821 |  | 
 | 3822 |   PolygonInfo | 
| cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3823 |     **restrict polygon_info; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3824 |  | 
 | 3825 |   register EdgeInfo | 
 | 3826 |     *p; | 
 | 3827 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3828 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3829 |     i; | 
 | 3830 |  | 
 | 3831 |   SegmentInfo | 
 | 3832 |     bounds; | 
 | 3833 |  | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3834 |   /* | 
 | 3835 |     Compute bounding box. | 
 | 3836 |   */ | 
 | 3837 |   assert(image != (Image *) NULL); | 
 | 3838 |   assert(image->signature == MagickSignature); | 
 | 3839 |   if (image->debug != MagickFalse) | 
 | 3840 |     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); | 
 | 3841 |   assert(draw_info != (DrawInfo *) NULL); | 
 | 3842 |   assert(draw_info->signature == MagickSignature); | 
 | 3843 |   assert(primitive_info != (PrimitiveInfo *) NULL); | 
 | 3844 |   if (primitive_info->coordinates == 0) | 
 | 3845 |     return(MagickTrue); | 
 | 3846 |   polygon_info=AcquirePolygonThreadSet(draw_info,primitive_info); | 
 | 3847 |   if (polygon_info == (PolygonInfo **) NULL) | 
 | 3848 |     return(MagickFalse); | 
 | 3849 |   if (0) | 
 | 3850 |     DrawBoundingRectangles(image,draw_info,polygon_info[0]); | 
 | 3851 |   if (image->debug != MagickFalse) | 
 | 3852 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(),"    begin draw-polygon"); | 
 | 3853 |   fill=(primitive_info->method == FillToBorderMethod) || | 
 | 3854 |     (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse; | 
 | 3855 |   mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0; | 
 | 3856 |   bounds=polygon_info[0]->edges[0].bounds; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3857 |   for (i=1; i < (ssize_t) polygon_info[0]->number_edges; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3858 |   { | 
 | 3859 |     p=polygon_info[0]->edges+i; | 
 | 3860 |     if (p->bounds.x1 < bounds.x1) | 
 | 3861 |       bounds.x1=p->bounds.x1; | 
 | 3862 |     if (p->bounds.y1 < bounds.y1) | 
 | 3863 |       bounds.y1=p->bounds.y1; | 
 | 3864 |     if (p->bounds.x2 > bounds.x2) | 
 | 3865 |       bounds.x2=p->bounds.x2; | 
 | 3866 |     if (p->bounds.y2 > bounds.y2) | 
 | 3867 |       bounds.y2=p->bounds.y2; | 
 | 3868 |   } | 
 | 3869 |   bounds.x1-=(mid+1.0); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3870 |   bounds.x1=bounds.x1 < 0.0 ? 0.0 : (size_t) ceil(bounds.x1-0.5) >= | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3871 |     image->columns ? (double) image->columns-1.0 : bounds.x1; | 
 | 3872 |   bounds.y1-=(mid+1.0); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3873 |   bounds.y1=bounds.y1 < 0.0 ? 0.0 : (size_t) ceil(bounds.y1-0.5) >= | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3874 |     image->rows ? (double) image->rows-1.0 : bounds.y1; | 
 | 3875 |   bounds.x2+=(mid+1.0); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3876 |   bounds.x2=bounds.x2 < 0.0 ? 0.0 : (size_t) floor(bounds.x2+0.5) >= | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3877 |     image->columns ? (double) image->columns-1.0 : bounds.x2; | 
 | 3878 |   bounds.y2+=(mid+1.0); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3879 |   bounds.y2=bounds.y2 < 0.0 ? 0.0 : (size_t) floor(bounds.y2+0.5) >= | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3880 |     image->rows ? (double) image->rows-1.0 : bounds.y2; | 
 | 3881 |   status=MagickTrue; | 
 | 3882 |   exception=(&image->exception); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3883 |   start=(ssize_t) ceil(bounds.x1-0.5); | 
 | 3884 |   stop=(ssize_t) floor(bounds.x2+0.5); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3885 |   image_view=AcquireCacheView(image); | 
 | 3886 |   if (primitive_info->coordinates == 1) | 
 | 3887 |     { | 
 | 3888 |       /* | 
 | 3889 |         Draw point. | 
 | 3890 |       */ | 
| cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3891 | #if defined(MAGICKCORE_OPENMP_SUPPORT) | 
 | 3892 |   #pragma omp parallel for schedule(dynamic,4) shared(status) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3893 | #endif | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3894 |       for (y=(ssize_t) ceil(bounds.y1-0.5); y <= (ssize_t) floor(bounds.y2+0.5); y++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3895 |       { | 
 | 3896 |         MagickBooleanType | 
 | 3897 |           sync; | 
 | 3898 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3899 |         register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3900 |           x; | 
 | 3901 |  | 
 | 3902 |         register PixelPacket | 
| cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3903 |           *restrict q; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3904 |  | 
 | 3905 |         if (status == MagickFalse) | 
 | 3906 |           continue; | 
 | 3907 |         x=start; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3908 |         q=GetCacheViewAuthenticPixels(image_view,x,y,(size_t) (stop-x+1), | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3909 |           1,exception); | 
 | 3910 |         if (q == (PixelPacket *) NULL) | 
 | 3911 |           { | 
 | 3912 |             status=MagickFalse; | 
 | 3913 |             continue; | 
 | 3914 |           } | 
 | 3915 |         for ( ; x <= stop; x++) | 
 | 3916 |         { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3917 |           if ((x == (ssize_t) ceil(primitive_info->point.x-0.5)) && | 
 | 3918 |               (y == (ssize_t) ceil(primitive_info->point.y-0.5))) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3919 |             (void) GetStrokeColor(draw_info,x,y,q); | 
 | 3920 |           q++; | 
 | 3921 |         } | 
 | 3922 |         sync=SyncCacheViewAuthenticPixels(image_view,exception); | 
 | 3923 |         if (sync == MagickFalse) | 
 | 3924 |           status=MagickFalse; | 
 | 3925 |       } | 
 | 3926 |       image_view=DestroyCacheView(image_view); | 
 | 3927 |       polygon_info=DestroyPolygonThreadSet(polygon_info); | 
 | 3928 |       if (image->debug != MagickFalse) | 
 | 3929 |         (void) LogMagickEvent(DrawEvent,GetMagickModule(), | 
 | 3930 |           "    end draw-polygon"); | 
 | 3931 |       return(status); | 
 | 3932 |     } | 
 | 3933 |   /* | 
 | 3934 |     Draw polygon or line. | 
 | 3935 |   */ | 
 | 3936 |   if (image->matte == MagickFalse) | 
 | 3937 |     (void) SetImageAlphaChannel(image,OpaqueAlphaChannel); | 
| cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3938 | #if defined(MAGICKCORE_OPENMP_SUPPORT) | 
 | 3939 |   #pragma omp parallel for schedule(dynamic,4) shared(status) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3940 | #endif | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3941 |   for (y=(ssize_t) ceil(bounds.y1-0.5); y <= (ssize_t) floor(bounds.y2+0.5); y++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3942 |   { | 
 | 3943 |     MagickRealType | 
 | 3944 |       fill_opacity, | 
 | 3945 |       stroke_opacity; | 
 | 3946 |  | 
 | 3947 |     PixelPacket | 
 | 3948 |       fill_color, | 
 | 3949 |       stroke_color; | 
 | 3950 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3951 |     register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3952 |       id, | 
 | 3953 |       x; | 
 | 3954 |  | 
 | 3955 |     register PixelPacket | 
| cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3956 |       *restrict q; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3957 |  | 
 | 3958 |     if (status == MagickFalse) | 
 | 3959 |       continue; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3960 |     q=GetCacheViewAuthenticPixels(image_view,start,y,(size_t) (stop- | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3961 |       start+1),1,exception); | 
 | 3962 |     if (q == (PixelPacket *) NULL) | 
 | 3963 |       { | 
 | 3964 |         status=MagickFalse; | 
 | 3965 |         continue; | 
 | 3966 |       } | 
 | 3967 |     id=GetOpenMPThreadId(); | 
 | 3968 |     for (x=start; x <= stop; x++) | 
 | 3969 |     { | 
 | 3970 |       /* | 
 | 3971 |         Fill and/or stroke. | 
 | 3972 |       */ | 
 | 3973 |       fill_opacity=GetPixelOpacity(polygon_info[id],mid,fill, | 
| cristy | 77f38fb | 2010-04-22 15:51:47 +0000 | [diff] [blame] | 3974 |         draw_info->fill_rule,(double) x,(double) y,&stroke_opacity); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3975 |       if (draw_info->stroke_antialias == MagickFalse) | 
 | 3976 |         { | 
 | 3977 |           fill_opacity=fill_opacity > 0.25 ? 1.0 : 0.0; | 
 | 3978 |           stroke_opacity=stroke_opacity > 0.25 ? 1.0 : 0.0; | 
 | 3979 |         } | 
 | 3980 |       (void) GetFillColor(draw_info,x,y,&fill_color); | 
 | 3981 |       fill_opacity=(MagickRealType) (QuantumRange-fill_opacity*(QuantumRange- | 
 | 3982 |         fill_color.opacity)); | 
 | 3983 |       MagickCompositeOver(&fill_color,fill_opacity,q,(MagickRealType) | 
 | 3984 |         q->opacity,q); | 
 | 3985 |       (void) GetStrokeColor(draw_info,x,y,&stroke_color); | 
 | 3986 |       stroke_opacity=(MagickRealType) (QuantumRange-stroke_opacity* | 
 | 3987 |         (QuantumRange-stroke_color.opacity)); | 
 | 3988 |       MagickCompositeOver(&stroke_color,stroke_opacity,q,(MagickRealType) | 
 | 3989 |         q->opacity,q); | 
 | 3990 |       q++; | 
 | 3991 |     } | 
 | 3992 |     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) | 
 | 3993 |       status=MagickFalse; | 
 | 3994 |   } | 
 | 3995 |   image_view=DestroyCacheView(image_view); | 
 | 3996 |   polygon_info=DestroyPolygonThreadSet(polygon_info); | 
 | 3997 |   if (image->debug != MagickFalse) | 
 | 3998 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(),"    end draw-polygon"); | 
 | 3999 |   return(status); | 
 | 4000 | } | 
 | 4001 |  | 
 | 4002 | /* | 
 | 4003 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 4004 | %                                                                             % | 
 | 4005 | %                                                                             % | 
 | 4006 | %                                                                             % | 
 | 4007 | %   D r a w P r i m i t i v e                                                 % | 
 | 4008 | %                                                                             % | 
 | 4009 | %                                                                             % | 
 | 4010 | %                                                                             % | 
 | 4011 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 4012 | % | 
 | 4013 | %  DrawPrimitive() draws a primitive (line, rectangle, ellipse) on the image. | 
 | 4014 | % | 
 | 4015 | %  The format of the DrawPrimitive method is: | 
 | 4016 | % | 
 | 4017 | %      MagickBooleanType DrawPrimitive(Image *image,const DrawInfo *draw_info, | 
 | 4018 | %        PrimitiveInfo *primitive_info) | 
 | 4019 | % | 
 | 4020 | %  A description of each parameter follows: | 
 | 4021 | % | 
 | 4022 | %    o image: the image. | 
 | 4023 | % | 
 | 4024 | %    o draw_info: the draw info. | 
 | 4025 | % | 
 | 4026 | %    o primitive_info: Specifies a pointer to a PrimitiveInfo structure. | 
 | 4027 | % | 
 | 4028 | */ | 
 | 4029 |  | 
 | 4030 | static void LogPrimitiveInfo(const PrimitiveInfo *primitive_info) | 
 | 4031 | { | 
 | 4032 |   const char | 
 | 4033 |     *methods[] = | 
 | 4034 |     { | 
 | 4035 |       "point", | 
 | 4036 |       "replace", | 
 | 4037 |       "floodfill", | 
 | 4038 |       "filltoborder", | 
 | 4039 |       "reset", | 
 | 4040 |       "?" | 
 | 4041 |     }; | 
 | 4042 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4043 |   ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4044 |     coordinates, | 
 | 4045 |     y; | 
 | 4046 |  | 
 | 4047 |   PointInfo | 
 | 4048 |     p, | 
 | 4049 |     q, | 
 | 4050 |     point; | 
 | 4051 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4052 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4053 |     i, | 
 | 4054 |     x; | 
 | 4055 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4056 |   x=(ssize_t) ceil(primitive_info->point.x-0.5); | 
 | 4057 |   y=(ssize_t) ceil(primitive_info->point.y-0.5); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4058 |   switch (primitive_info->primitive) | 
 | 4059 |   { | 
 | 4060 |     case PointPrimitive: | 
 | 4061 |     { | 
 | 4062 |       (void) LogMagickEvent(DrawEvent,GetMagickModule(), | 
| cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4063 |         "PointPrimitive %ld,%ld %s",(long) x,(long) y, | 
 | 4064 |         methods[primitive_info->method]); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4065 |       return; | 
 | 4066 |     } | 
 | 4067 |     case ColorPrimitive: | 
 | 4068 |     { | 
 | 4069 |       (void) LogMagickEvent(DrawEvent,GetMagickModule(), | 
| cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4070 |         "ColorPrimitive %ld,%ld %s",(long) x,(long) y, | 
 | 4071 |         methods[primitive_info->method]); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4072 |       return; | 
 | 4073 |     } | 
 | 4074 |     case MattePrimitive: | 
 | 4075 |     { | 
 | 4076 |       (void) LogMagickEvent(DrawEvent,GetMagickModule(), | 
| cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4077 |         "MattePrimitive %ld,%ld %s",(long) x,(long) y, | 
 | 4078 |         methods[primitive_info->method]); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4079 |       return; | 
 | 4080 |     } | 
 | 4081 |     case TextPrimitive: | 
 | 4082 |     { | 
 | 4083 |       (void) LogMagickEvent(DrawEvent,GetMagickModule(), | 
| cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4084 |         "TextPrimitive %ld,%ld",(long) x,(long) y); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4085 |       return; | 
 | 4086 |     } | 
 | 4087 |     case ImagePrimitive: | 
 | 4088 |     { | 
 | 4089 |       (void) LogMagickEvent(DrawEvent,GetMagickModule(), | 
| cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4090 |         "ImagePrimitive %ld,%ld",(long) x,(long) y); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4091 |       return; | 
 | 4092 |     } | 
 | 4093 |     default: | 
 | 4094 |       break; | 
 | 4095 |   } | 
 | 4096 |   coordinates=0; | 
 | 4097 |   p=primitive_info[0].point; | 
 | 4098 |   q.x=(-1.0); | 
 | 4099 |   q.y=(-1.0); | 
 | 4100 |   for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) | 
 | 4101 |   { | 
 | 4102 |     point=primitive_info[i].point; | 
 | 4103 |     if (coordinates <= 0) | 
 | 4104 |       { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4105 |         coordinates=(ssize_t) primitive_info[i].coordinates; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4106 |         (void) LogMagickEvent(DrawEvent,GetMagickModule(), | 
| cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4107 |           "    begin open (%ld)",(long) coordinates); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4108 |         p=point; | 
 | 4109 |       } | 
 | 4110 |     point=primitive_info[i].point; | 
 | 4111 |     if ((fabs(q.x-point.x) > MagickEpsilon) || | 
 | 4112 |         (fabs(q.y-point.y) > MagickEpsilon)) | 
| cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 4113 |       (void) LogMagickEvent(DrawEvent,GetMagickModule(), | 
| cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4114 |         "      %ld: %.18g,%.18g",(long) coordinates,point.x,point.y); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4115 |     else | 
 | 4116 |       (void) LogMagickEvent(DrawEvent,GetMagickModule(), | 
| cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4117 |         "      %ld: %g,%g (duplicate)",(long) coordinates,point.x,point.y); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4118 |     q=point; | 
 | 4119 |     coordinates--; | 
 | 4120 |     if (coordinates > 0) | 
 | 4121 |       continue; | 
 | 4122 |     if ((fabs(p.x-point.x) > MagickEpsilon) || | 
 | 4123 |         (fabs(p.y-point.y) > MagickEpsilon)) | 
 | 4124 |       (void) LogMagickEvent(DrawEvent,GetMagickModule(),"    end last (%ld)", | 
| cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4125 |         (long) coordinates); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4126 |     else | 
 | 4127 |       (void) LogMagickEvent(DrawEvent,GetMagickModule(),"    end open (%ld)", | 
| cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4128 |         (long) coordinates); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4129 |   } | 
 | 4130 | } | 
 | 4131 |  | 
 | 4132 | MagickExport MagickBooleanType DrawPrimitive(Image *image, | 
 | 4133 |   const DrawInfo *draw_info,const PrimitiveInfo *primitive_info) | 
 | 4134 | { | 
| cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 4135 |   CacheView | 
 | 4136 |     *image_view; | 
 | 4137 |  | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4138 |   ExceptionInfo | 
 | 4139 |     *exception; | 
 | 4140 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4141 |   ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4142 |     y; | 
 | 4143 |  | 
 | 4144 |   MagickStatusType | 
 | 4145 |     status; | 
 | 4146 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4147 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4148 |     i, | 
 | 4149 |     x; | 
 | 4150 |  | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4151 |   if (image->debug != MagickFalse) | 
 | 4152 |     { | 
 | 4153 |       (void) LogMagickEvent(DrawEvent,GetMagickModule(), | 
 | 4154 |         "  begin draw-primitive"); | 
 | 4155 |       (void) LogMagickEvent(DrawEvent,GetMagickModule(), | 
| cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 4156 |         "    affine: %g,%g,%g,%g,%g,%g",draw_info->affine.sx, | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4157 |         draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy, | 
 | 4158 |         draw_info->affine.tx,draw_info->affine.ty); | 
 | 4159 |     } | 
 | 4160 |   status=MagickTrue; | 
 | 4161 |   exception=(&image->exception); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4162 |   x=(ssize_t) ceil(primitive_info->point.x-0.5); | 
 | 4163 |   y=(ssize_t) ceil(primitive_info->point.y-0.5); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4164 |   image_view=AcquireCacheView(image); | 
 | 4165 |   switch (primitive_info->primitive) | 
 | 4166 |   { | 
 | 4167 |     case PointPrimitive: | 
 | 4168 |     { | 
 | 4169 |       PixelPacket | 
 | 4170 |         fill_color; | 
 | 4171 |  | 
 | 4172 |       PixelPacket | 
 | 4173 |         *q; | 
 | 4174 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4175 |       if ((y < 0) || (y >= (ssize_t) image->rows)) | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 4176 |         break; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4177 |       if ((x < 0) || (x >= (ssize_t) image->columns)) | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 4178 |         break; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4179 |       q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception); | 
 | 4180 |       if (q == (PixelPacket *) NULL) | 
 | 4181 |         break; | 
 | 4182 |       (void) GetFillColor(draw_info,x,y,&fill_color); | 
 | 4183 |       MagickCompositeOver(&fill_color,(MagickRealType) fill_color.opacity,q, | 
 | 4184 |         (MagickRealType) q->opacity,q); | 
 | 4185 |       (void) SyncCacheViewAuthenticPixels(image_view,exception); | 
 | 4186 |       break; | 
 | 4187 |     } | 
 | 4188 |     case ColorPrimitive: | 
 | 4189 |     { | 
 | 4190 |       switch (primitive_info->method) | 
 | 4191 |       { | 
 | 4192 |         case PointMethod: | 
 | 4193 |         default: | 
 | 4194 |         { | 
 | 4195 |           PixelPacket | 
 | 4196 |             *q; | 
 | 4197 |  | 
 | 4198 |           q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception); | 
 | 4199 |           if (q == (PixelPacket *) NULL) | 
 | 4200 |             break; | 
 | 4201 |           (void) GetFillColor(draw_info,x,y,q); | 
 | 4202 |           (void) SyncCacheViewAuthenticPixels(image_view,exception); | 
 | 4203 |           break; | 
 | 4204 |         } | 
 | 4205 |         case ReplaceMethod: | 
 | 4206 |         { | 
 | 4207 |           MagickBooleanType | 
 | 4208 |             sync; | 
 | 4209 |  | 
 | 4210 |           PixelPacket | 
 | 4211 |             target; | 
 | 4212 |  | 
 | 4213 |           (void) GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4214 |           for (y=0; y < (ssize_t) image->rows; y++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4215 |           { | 
 | 4216 |             register PixelPacket | 
| cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4217 |               *restrict q; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4218 |  | 
 | 4219 |             q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, | 
 | 4220 |               exception); | 
 | 4221 |             if (q == (PixelPacket *) NULL) | 
 | 4222 |               break; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4223 |             for (x=0; x < (ssize_t) image->columns; x++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4224 |             { | 
 | 4225 |               if (IsColorSimilar(image,q,&target) == MagickFalse) | 
 | 4226 |                 { | 
 | 4227 |                   q++; | 
 | 4228 |                   continue; | 
 | 4229 |                 } | 
 | 4230 |               (void) GetFillColor(draw_info,x,y,q); | 
 | 4231 |               q++; | 
 | 4232 |             } | 
 | 4233 |             sync=SyncCacheViewAuthenticPixels(image_view,exception); | 
 | 4234 |             if (sync == MagickFalse) | 
 | 4235 |               break; | 
 | 4236 |           } | 
 | 4237 |           break; | 
 | 4238 |         } | 
 | 4239 |         case FloodfillMethod: | 
 | 4240 |         case FillToBorderMethod: | 
 | 4241 |         { | 
 | 4242 |           MagickPixelPacket | 
 | 4243 |             target; | 
 | 4244 |  | 
 | 4245 |           (void) GetOneVirtualMagickPixel(image,x,y,&target,exception); | 
 | 4246 |           if (primitive_info->method == FillToBorderMethod) | 
 | 4247 |             { | 
 | 4248 |               target.red=(MagickRealType) draw_info->border_color.red; | 
 | 4249 |               target.green=(MagickRealType) draw_info->border_color.green; | 
 | 4250 |               target.blue=(MagickRealType) draw_info->border_color.blue; | 
 | 4251 |             } | 
 | 4252 |           (void) FloodfillPaintImage(image,DefaultChannels,draw_info,&target,x, | 
 | 4253 |             y,primitive_info->method == FloodfillMethod ? MagickFalse : | 
 | 4254 |             MagickTrue); | 
 | 4255 |           break; | 
 | 4256 |         } | 
 | 4257 |         case ResetMethod: | 
 | 4258 |         { | 
 | 4259 |           MagickBooleanType | 
 | 4260 |             sync; | 
 | 4261 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4262 |           for (y=0; y < (ssize_t) image->rows; y++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4263 |           { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4264 |             register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4265 |               x; | 
 | 4266 |  | 
 | 4267 |             register PixelPacket | 
| cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4268 |               *restrict q; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4269 |  | 
 | 4270 |             q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, | 
 | 4271 |               exception); | 
 | 4272 |             if (q == (PixelPacket *) NULL) | 
 | 4273 |               break; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4274 |             for (x=0; x < (ssize_t) image->columns; x++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4275 |             { | 
 | 4276 |               (void) GetFillColor(draw_info,x,y,q); | 
 | 4277 |               q++; | 
 | 4278 |             } | 
 | 4279 |             sync=SyncCacheViewAuthenticPixels(image_view,exception); | 
 | 4280 |             if (sync == MagickFalse) | 
 | 4281 |               break; | 
 | 4282 |           } | 
 | 4283 |           break; | 
 | 4284 |         } | 
 | 4285 |       } | 
 | 4286 |       break; | 
 | 4287 |     } | 
 | 4288 |     case MattePrimitive: | 
 | 4289 |     { | 
 | 4290 |       if (image->matte == MagickFalse) | 
 | 4291 |         (void) SetImageAlphaChannel(image,OpaqueAlphaChannel); | 
 | 4292 |       switch (primitive_info->method) | 
 | 4293 |       { | 
 | 4294 |         case PointMethod: | 
 | 4295 |         default: | 
 | 4296 |         { | 
 | 4297 |           PixelPacket | 
 | 4298 |             pixel; | 
 | 4299 |  | 
 | 4300 |           PixelPacket | 
 | 4301 |             *q; | 
 | 4302 |  | 
 | 4303 |           q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception); | 
 | 4304 |           if (q == (PixelPacket *) NULL) | 
 | 4305 |             break; | 
 | 4306 |           (void) GetFillColor(draw_info,x,y,&pixel); | 
 | 4307 |           q->opacity=pixel.opacity; | 
 | 4308 |           (void) SyncCacheViewAuthenticPixels(image_view,exception); | 
 | 4309 |           break; | 
 | 4310 |         } | 
 | 4311 |         case ReplaceMethod: | 
 | 4312 |         { | 
 | 4313 |           MagickBooleanType | 
 | 4314 |             sync; | 
 | 4315 |  | 
 | 4316 |           PixelPacket | 
 | 4317 |             pixel, | 
 | 4318 |             target; | 
 | 4319 |  | 
 | 4320 |           (void) GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4321 |           for (y=0; y < (ssize_t) image->rows; y++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4322 |           { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4323 |             register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4324 |               x; | 
 | 4325 |  | 
 | 4326 |             register PixelPacket | 
| cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4327 |               *restrict q; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4328 |  | 
 | 4329 |             q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, | 
 | 4330 |               exception); | 
 | 4331 |             if (q == (PixelPacket *) NULL) | 
 | 4332 |               break; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4333 |             for (x=0; x < (ssize_t) image->columns; x++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4334 |             { | 
 | 4335 |               if (IsColorSimilar(image,q,&target) == MagickFalse) | 
 | 4336 |                 { | 
 | 4337 |                   q++; | 
 | 4338 |                   continue; | 
 | 4339 |                 } | 
 | 4340 |               (void) GetFillColor(draw_info,x,y,&pixel); | 
 | 4341 |               q->opacity=pixel.opacity; | 
 | 4342 |               q++; | 
 | 4343 |             } | 
 | 4344 |             sync=SyncCacheViewAuthenticPixels(image_view,exception); | 
 | 4345 |             if (sync == MagickFalse) | 
 | 4346 |               break; | 
 | 4347 |           } | 
 | 4348 |           break; | 
 | 4349 |         } | 
 | 4350 |         case FloodfillMethod: | 
 | 4351 |         case FillToBorderMethod: | 
 | 4352 |         { | 
 | 4353 |           MagickPixelPacket | 
 | 4354 |             target; | 
 | 4355 |  | 
 | 4356 |           (void) GetOneVirtualMagickPixel(image,x,y,&target,exception); | 
 | 4357 |           if (primitive_info->method == FillToBorderMethod) | 
 | 4358 |             { | 
 | 4359 |               target.red=(MagickRealType) draw_info->border_color.red; | 
 | 4360 |               target.green=(MagickRealType) draw_info->border_color.green; | 
 | 4361 |               target.blue=(MagickRealType) draw_info->border_color.blue; | 
 | 4362 |             } | 
 | 4363 |           (void) FloodfillPaintImage(image,OpacityChannel,draw_info,&target,x,y, | 
 | 4364 |             primitive_info->method == FloodfillMethod ? MagickFalse : | 
 | 4365 |             MagickTrue); | 
 | 4366 |           break; | 
 | 4367 |         } | 
 | 4368 |         case ResetMethod: | 
 | 4369 |         { | 
 | 4370 |           MagickBooleanType | 
 | 4371 |             sync; | 
 | 4372 |  | 
 | 4373 |           PixelPacket | 
 | 4374 |             pixel; | 
 | 4375 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4376 |           for (y=0; y < (ssize_t) image->rows; y++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4377 |           { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4378 |             register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4379 |               x; | 
 | 4380 |  | 
 | 4381 |             register PixelPacket | 
| cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4382 |               *restrict q; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4383 |  | 
 | 4384 |             q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, | 
 | 4385 |               exception); | 
 | 4386 |             if (q == (PixelPacket *) NULL) | 
 | 4387 |               break; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4388 |             for (x=0; x < (ssize_t) image->columns; x++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4389 |             { | 
 | 4390 |               (void) GetFillColor(draw_info,x,y,&pixel); | 
 | 4391 |               q->opacity=pixel.opacity; | 
 | 4392 |               q++; | 
 | 4393 |             } | 
 | 4394 |             sync=SyncCacheViewAuthenticPixels(image_view,exception); | 
 | 4395 |             if (sync == MagickFalse) | 
 | 4396 |               break; | 
 | 4397 |           } | 
 | 4398 |           break; | 
 | 4399 |         } | 
 | 4400 |       } | 
 | 4401 |       break; | 
 | 4402 |     } | 
 | 4403 |     case TextPrimitive: | 
 | 4404 |     { | 
 | 4405 |       char | 
 | 4406 |         geometry[MaxTextExtent]; | 
 | 4407 |  | 
 | 4408 |       DrawInfo | 
 | 4409 |         *clone_info; | 
 | 4410 |  | 
 | 4411 |       if (primitive_info->text == (char *) NULL) | 
 | 4412 |         break; | 
 | 4413 |       clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); | 
 | 4414 |       (void) CloneString(&clone_info->text,primitive_info->text); | 
 | 4415 |       (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f", | 
 | 4416 |         primitive_info->point.x,primitive_info->point.y); | 
 | 4417 |       (void) CloneString(&clone_info->geometry,geometry); | 
 | 4418 |       status=AnnotateImage(image,clone_info); | 
 | 4419 |       clone_info=DestroyDrawInfo(clone_info); | 
 | 4420 |       break; | 
 | 4421 |     } | 
 | 4422 |     case ImagePrimitive: | 
 | 4423 |     { | 
 | 4424 |       AffineMatrix | 
 | 4425 |         affine; | 
 | 4426 |  | 
 | 4427 |       char | 
 | 4428 |         composite_geometry[MaxTextExtent]; | 
 | 4429 |  | 
 | 4430 |       Image | 
 | 4431 |         *composite_image; | 
 | 4432 |  | 
 | 4433 |       ImageInfo | 
 | 4434 |         *clone_info; | 
 | 4435 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4436 |       ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4437 |         x1, | 
 | 4438 |         y1; | 
 | 4439 |  | 
 | 4440 |       RectangleInfo | 
 | 4441 |         geometry; | 
 | 4442 |  | 
 | 4443 |       if (primitive_info->text == (char *) NULL) | 
 | 4444 |         break; | 
 | 4445 |       clone_info=AcquireImageInfo(); | 
 | 4446 |       if (LocaleNCompare(primitive_info->text,"data:",5) == 0) | 
 | 4447 |         composite_image=ReadInlineImage(clone_info,primitive_info->text, | 
 | 4448 |           &image->exception); | 
 | 4449 |       else | 
 | 4450 |         { | 
 | 4451 |           (void) CopyMagickString(clone_info->filename,primitive_info->text, | 
 | 4452 |             MaxTextExtent); | 
 | 4453 |           composite_image=ReadImage(clone_info,&image->exception); | 
 | 4454 |         } | 
 | 4455 |       clone_info=DestroyImageInfo(clone_info); | 
 | 4456 |       if (composite_image == (Image *) NULL) | 
 | 4457 |         break; | 
 | 4458 |       (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor) | 
 | 4459 |         NULL,(void *) NULL); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4460 |       x1=(ssize_t) ceil(primitive_info[1].point.x-0.5); | 
 | 4461 |       y1=(ssize_t) ceil(primitive_info[1].point.y-0.5); | 
 | 4462 |       if (((x1 != 0L) && (x1 != (ssize_t) composite_image->columns)) || | 
 | 4463 |           ((y1 != 0L) && (y1 != (ssize_t) composite_image->rows))) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4464 |         { | 
 | 4465 |           char | 
 | 4466 |             geometry[MaxTextExtent]; | 
 | 4467 |  | 
 | 4468 |           /* | 
 | 4469 |             Resize image. | 
 | 4470 |           */ | 
| cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 4471 |           (void) FormatMagickString(geometry,MaxTextExtent,"%gx%g!", | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4472 |             primitive_info[1].point.x,primitive_info[1].point.y); | 
 | 4473 |           composite_image->filter=image->filter; | 
 | 4474 |           (void) TransformImage(&composite_image,(char *) NULL,geometry); | 
 | 4475 |         } | 
 | 4476 |       if (composite_image->matte == MagickFalse) | 
 | 4477 |         (void) SetImageAlphaChannel(composite_image,OpaqueAlphaChannel); | 
 | 4478 |       if (draw_info->opacity != OpaqueOpacity) | 
 | 4479 |         (void) SetImageOpacity(composite_image,draw_info->opacity); | 
 | 4480 |       SetGeometry(image,&geometry); | 
 | 4481 |       image->gravity=draw_info->gravity; | 
 | 4482 |       geometry.x=x; | 
 | 4483 |       geometry.y=y; | 
 | 4484 |       (void) FormatMagickString(composite_geometry,MaxTextExtent, | 
| cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4485 |         "%lux%lu%+ld%+ld",(unsigned long) composite_image->columns, | 
 | 4486 |         (unsigned long) composite_image->rows,(long) geometry.x,(long) | 
 | 4487 |         geometry.y); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4488 |       (void) ParseGravityGeometry(image,composite_geometry,&geometry, | 
 | 4489 |         &image->exception); | 
 | 4490 |       affine=draw_info->affine; | 
 | 4491 |       affine.tx=(double) geometry.x; | 
 | 4492 |       affine.ty=(double) geometry.y; | 
 | 4493 |       composite_image->interpolate=image->interpolate; | 
 | 4494 |       if (draw_info->compose == OverCompositeOp) | 
 | 4495 |         (void) DrawAffineImage(image,composite_image,&affine); | 
 | 4496 |       else | 
 | 4497 |         (void) CompositeImage(image,draw_info->compose,composite_image, | 
 | 4498 |           geometry.x,geometry.y); | 
 | 4499 |       composite_image=DestroyImage(composite_image); | 
 | 4500 |       break; | 
 | 4501 |     } | 
 | 4502 |     default: | 
 | 4503 |     { | 
 | 4504 |       MagickRealType | 
 | 4505 |         mid, | 
 | 4506 |         scale; | 
 | 4507 |  | 
 | 4508 |       DrawInfo | 
 | 4509 |         *clone_info; | 
 | 4510 |  | 
 | 4511 |       if (IsEventLogging() != MagickFalse) | 
 | 4512 |         LogPrimitiveInfo(primitive_info); | 
 | 4513 |       scale=ExpandAffine(&draw_info->affine); | 
 | 4514 |       if ((draw_info->dash_pattern != (double *) NULL) && | 
 | 4515 |           (draw_info->dash_pattern[0] != 0.0) && | 
 | 4516 |           ((scale*draw_info->stroke_width) > MagickEpsilon) && | 
 | 4517 |           (draw_info->stroke.opacity != (Quantum) TransparentOpacity)) | 
 | 4518 |         { | 
 | 4519 |           /* | 
 | 4520 |             Draw dash polygon. | 
 | 4521 |           */ | 
 | 4522 |           clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); | 
 | 4523 |           clone_info->stroke_width=0.0; | 
 | 4524 |           clone_info->stroke.opacity=(Quantum) TransparentOpacity; | 
 | 4525 |           status=DrawPolygonPrimitive(image,clone_info,primitive_info); | 
 | 4526 |           clone_info=DestroyDrawInfo(clone_info); | 
 | 4527 |           (void) DrawDashPolygon(draw_info,primitive_info,image); | 
 | 4528 |           break; | 
 | 4529 |         } | 
 | 4530 |       mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0; | 
 | 4531 |       if ((mid > 1.0) && | 
 | 4532 |           (draw_info->stroke.opacity != (Quantum) TransparentOpacity)) | 
 | 4533 |         { | 
 | 4534 |           MagickBooleanType | 
 | 4535 |             closed_path; | 
 | 4536 |  | 
 | 4537 |           /* | 
 | 4538 |             Draw strokes while respecting line cap/join attributes. | 
 | 4539 |           */ | 
 | 4540 |           for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ; | 
 | 4541 |           closed_path= | 
 | 4542 |             (primitive_info[i-1].point.x == primitive_info[0].point.x) && | 
 | 4543 |             (primitive_info[i-1].point.y == primitive_info[0].point.y) ? | 
 | 4544 |             MagickTrue : MagickFalse; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4545 |           i=(ssize_t) primitive_info[0].coordinates; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4546 |           if ((((draw_info->linecap == RoundCap) || | 
 | 4547 |                 (closed_path != MagickFalse)) && | 
 | 4548 |                (draw_info->linejoin == RoundJoin)) || | 
 | 4549 |                (primitive_info[i].primitive != UndefinedPrimitive)) | 
 | 4550 |             { | 
 | 4551 |               (void) DrawPolygonPrimitive(image,draw_info,primitive_info); | 
 | 4552 |               break; | 
 | 4553 |             } | 
 | 4554 |           clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); | 
 | 4555 |           clone_info->stroke_width=0.0; | 
 | 4556 |           clone_info->stroke.opacity=(Quantum) TransparentOpacity; | 
 | 4557 |           status=DrawPolygonPrimitive(image,clone_info,primitive_info); | 
 | 4558 |           clone_info=DestroyDrawInfo(clone_info); | 
 | 4559 |           status|=DrawStrokePolygon(image,draw_info,primitive_info); | 
 | 4560 |           break; | 
 | 4561 |         } | 
 | 4562 |       status=DrawPolygonPrimitive(image,draw_info,primitive_info); | 
 | 4563 |       break; | 
 | 4564 |     } | 
 | 4565 |   } | 
 | 4566 |   image_view=DestroyCacheView(image_view); | 
 | 4567 |   if (image->debug != MagickFalse) | 
 | 4568 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(),"  end draw-primitive"); | 
 | 4569 |   return(status != 0 ? MagickTrue : MagickFalse); | 
 | 4570 | } | 
 | 4571 |  | 
 | 4572 | /* | 
 | 4573 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 4574 | %                                                                             % | 
 | 4575 | %                                                                             % | 
 | 4576 | %                                                                             % | 
 | 4577 | +   D r a w S t r o k e P o l y g o n                                         % | 
 | 4578 | %                                                                             % | 
 | 4579 | %                                                                             % | 
 | 4580 | %                                                                             % | 
 | 4581 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 4582 | % | 
 | 4583 | %  DrawStrokePolygon() draws a stroked polygon (line, rectangle, ellipse) on | 
 | 4584 | %  the image while respecting the line cap and join attributes. | 
 | 4585 | % | 
 | 4586 | %  The format of the DrawStrokePolygon method is: | 
 | 4587 | % | 
 | 4588 | %      MagickBooleanType DrawStrokePolygon(Image *image, | 
 | 4589 | %        const DrawInfo *draw_info,const PrimitiveInfo *primitive_info) | 
 | 4590 | % | 
 | 4591 | %  A description of each parameter follows: | 
 | 4592 | % | 
 | 4593 | %    o image: the image. | 
 | 4594 | % | 
 | 4595 | %    o draw_info: the draw info. | 
 | 4596 | % | 
 | 4597 | %    o primitive_info: Specifies a pointer to a PrimitiveInfo structure. | 
 | 4598 | % | 
 | 4599 | % | 
 | 4600 | */ | 
 | 4601 |  | 
 | 4602 | static void DrawRoundLinecap(Image *image,const DrawInfo *draw_info, | 
 | 4603 |   const PrimitiveInfo *primitive_info) | 
 | 4604 | { | 
 | 4605 |   PrimitiveInfo | 
 | 4606 |     linecap[5]; | 
 | 4607 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4608 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4609 |     i; | 
 | 4610 |  | 
 | 4611 |   for (i=0; i < 4; i++) | 
 | 4612 |     linecap[i]=(*primitive_info); | 
 | 4613 |   linecap[0].coordinates=4; | 
 | 4614 |   linecap[1].point.x+=(double) (10.0*MagickEpsilon); | 
 | 4615 |   linecap[2].point.x+=(double) (10.0*MagickEpsilon); | 
 | 4616 |   linecap[2].point.y+=(double) (10.0*MagickEpsilon); | 
 | 4617 |   linecap[3].point.y+=(double) (10.0*MagickEpsilon); | 
 | 4618 |   linecap[4].primitive=UndefinedPrimitive; | 
 | 4619 |   (void) DrawPolygonPrimitive(image,draw_info,linecap); | 
 | 4620 | } | 
 | 4621 |  | 
 | 4622 | static MagickBooleanType DrawStrokePolygon(Image *image, | 
 | 4623 |   const DrawInfo *draw_info,const PrimitiveInfo *primitive_info) | 
 | 4624 | { | 
 | 4625 |   DrawInfo | 
 | 4626 |     *clone_info; | 
 | 4627 |  | 
 | 4628 |   MagickBooleanType | 
 | 4629 |     closed_path, | 
 | 4630 |     status; | 
 | 4631 |  | 
 | 4632 |   PrimitiveInfo | 
 | 4633 |     *stroke_polygon; | 
 | 4634 |  | 
 | 4635 |   register const PrimitiveInfo | 
 | 4636 |     *p, | 
 | 4637 |     *q; | 
 | 4638 |  | 
 | 4639 |   /* | 
 | 4640 |     Draw stroked polygon. | 
 | 4641 |   */ | 
 | 4642 |   if (image->debug != MagickFalse) | 
 | 4643 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(), | 
 | 4644 |       "    begin draw-stroke-polygon"); | 
 | 4645 |   clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); | 
 | 4646 |   clone_info->fill=draw_info->stroke; | 
 | 4647 |   clone_info->stroke.opacity=(Quantum) TransparentOpacity; | 
 | 4648 |   clone_info->stroke_width=0.0; | 
 | 4649 |   clone_info->fill_rule=NonZeroRule; | 
 | 4650 |   status=MagickTrue; | 
 | 4651 |   for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=p->coordinates) | 
 | 4652 |   { | 
 | 4653 |     stroke_polygon=TraceStrokePolygon(draw_info,p); | 
 | 4654 |     status=DrawPolygonPrimitive(image,clone_info,stroke_polygon); | 
 | 4655 |     stroke_polygon=(PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon); | 
 | 4656 |     q=p+p->coordinates-1; | 
 | 4657 |     closed_path=(q->point.x == p->point.x) && (q->point.y == p->point.y) ? | 
 | 4658 |       MagickTrue : MagickFalse; | 
 | 4659 |     if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse)) | 
 | 4660 |       { | 
 | 4661 |         DrawRoundLinecap(image,draw_info,p); | 
 | 4662 |         DrawRoundLinecap(image,draw_info,q); | 
 | 4663 |       } | 
 | 4664 |   } | 
 | 4665 |   clone_info=DestroyDrawInfo(clone_info); | 
 | 4666 |   if (image->debug != MagickFalse) | 
 | 4667 |     (void) LogMagickEvent(DrawEvent,GetMagickModule(), | 
 | 4668 |       "    end draw-stroke-polygon"); | 
 | 4669 |   return(status); | 
 | 4670 | } | 
 | 4671 |  | 
 | 4672 | /* | 
 | 4673 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 4674 | %                                                                             % | 
 | 4675 | %                                                                             % | 
 | 4676 | %                                                                             % | 
 | 4677 | %   G e t A f f i n e M a t r i x                                             % | 
 | 4678 | %                                                                             % | 
 | 4679 | %                                                                             % | 
 | 4680 | %                                                                             % | 
 | 4681 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 4682 | % | 
 | 4683 | %  GetAffineMatrix() returns an AffineMatrix initialized to the identity | 
 | 4684 | %  matrix. | 
 | 4685 | % | 
 | 4686 | %  The format of the GetAffineMatrix method is: | 
 | 4687 | % | 
 | 4688 | %      void GetAffineMatrix(AffineMatrix *affine_matrix) | 
 | 4689 | % | 
 | 4690 | %  A description of each parameter follows: | 
 | 4691 | % | 
 | 4692 | %    o affine_matrix: the affine matrix. | 
 | 4693 | % | 
 | 4694 | */ | 
 | 4695 | MagickExport void GetAffineMatrix(AffineMatrix *affine_matrix) | 
 | 4696 | { | 
 | 4697 |   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); | 
 | 4698 |   assert(affine_matrix != (AffineMatrix *) NULL); | 
 | 4699 |   (void) ResetMagickMemory(affine_matrix,0,sizeof(*affine_matrix)); | 
 | 4700 |   affine_matrix->sx=1.0; | 
 | 4701 |   affine_matrix->sy=1.0; | 
 | 4702 | } | 
 | 4703 |  | 
 | 4704 | /* | 
 | 4705 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 4706 | %                                                                             % | 
 | 4707 | %                                                                             % | 
 | 4708 | %                                                                             % | 
 | 4709 | +   G e t D r a w I n f o                                                     % | 
 | 4710 | %                                                                             % | 
 | 4711 | %                                                                             % | 
 | 4712 | %                                                                             % | 
 | 4713 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 4714 | % | 
 | 4715 | %  GetDrawInfo() initializes draw_info to default values. | 
 | 4716 | % | 
 | 4717 | %  The format of the GetDrawInfo method is: | 
 | 4718 | % | 
 | 4719 | %      void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info) | 
 | 4720 | % | 
 | 4721 | %  A description of each parameter follows: | 
 | 4722 | % | 
 | 4723 | %    o image_info: the image info.. | 
 | 4724 | % | 
 | 4725 | %    o draw_info: the draw info. | 
 | 4726 | % | 
 | 4727 | */ | 
 | 4728 | MagickExport void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info) | 
 | 4729 | { | 
 | 4730 |   const char | 
 | 4731 |     *option; | 
 | 4732 |  | 
 | 4733 |   ExceptionInfo | 
 | 4734 |     *exception; | 
 | 4735 |  | 
 | 4736 |   ImageInfo | 
 | 4737 |     *clone_info; | 
 | 4738 |  | 
 | 4739 |   /* | 
 | 4740 |     Initialize draw attributes. | 
 | 4741 |   */ | 
 | 4742 |   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); | 
 | 4743 |   assert(draw_info != (DrawInfo *) NULL); | 
 | 4744 |   (void) ResetMagickMemory(draw_info,0,sizeof(*draw_info)); | 
 | 4745 |   clone_info=CloneImageInfo(image_info); | 
 | 4746 |   GetAffineMatrix(&draw_info->affine); | 
 | 4747 |   exception=AcquireExceptionInfo(); | 
 | 4748 |   (void) QueryColorDatabase("#000F",&draw_info->fill,exception); | 
 | 4749 |   (void) QueryColorDatabase("#FFF0",&draw_info->stroke,exception); | 
 | 4750 |   draw_info->stroke_antialias=clone_info->antialias; | 
 | 4751 |   draw_info->stroke_width=1.0; | 
 | 4752 |   draw_info->opacity=OpaqueOpacity; | 
 | 4753 |   draw_info->fill_rule=EvenOddRule; | 
 | 4754 |   draw_info->linecap=ButtCap; | 
 | 4755 |   draw_info->linejoin=MiterJoin; | 
 | 4756 |   draw_info->miterlimit=10; | 
 | 4757 |   draw_info->decorate=NoDecoration; | 
 | 4758 |   if (clone_info->font != (char *) NULL) | 
 | 4759 |     draw_info->font=AcquireString(clone_info->font); | 
 | 4760 |   if (clone_info->density != (char *) NULL) | 
 | 4761 |     draw_info->density=AcquireString(clone_info->density); | 
 | 4762 |   draw_info->text_antialias=clone_info->antialias; | 
 | 4763 |   draw_info->pointsize=12.0; | 
 | 4764 |   if (clone_info->pointsize != 0.0) | 
 | 4765 |     draw_info->pointsize=clone_info->pointsize; | 
 | 4766 |   draw_info->undercolor.opacity=(Quantum) TransparentOpacity; | 
 | 4767 |   draw_info->border_color=clone_info->border_color; | 
 | 4768 |   draw_info->compose=OverCompositeOp; | 
 | 4769 |   if (clone_info->server_name != (char *) NULL) | 
 | 4770 |     draw_info->server_name=AcquireString(clone_info->server_name); | 
 | 4771 |   draw_info->render=MagickTrue; | 
 | 4772 |   draw_info->debug=IsEventLogging(); | 
 | 4773 |   option=GetImageOption(clone_info,"encoding"); | 
 | 4774 |   if (option != (const char *) NULL) | 
 | 4775 |     (void) CloneString(&draw_info->encoding,option); | 
 | 4776 |   option=GetImageOption(clone_info,"kerning"); | 
 | 4777 |   if (option != (const char *) NULL) | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 4778 |     draw_info->kerning=StringToDouble(option); | 
| cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 4779 |   option=GetImageOption(clone_info,"interline-spacing"); | 
 | 4780 |   if (option != (const char *) NULL) | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 4781 |     draw_info->interline_spacing=StringToDouble(option); | 
| cristy | 6ac8b33 | 2010-04-22 02:24:11 +0000 | [diff] [blame] | 4782 |   draw_info->direction=UndefinedDirection; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4783 |   option=GetImageOption(clone_info,"interword-spacing"); | 
 | 4784 |   if (option != (const char *) NULL) | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 4785 |     draw_info->interword_spacing=StringToDouble(option); | 
| cristy | c9b1295 | 2010-03-28 01:12:28 +0000 | [diff] [blame] | 4786 |   option=GetImageOption(clone_info,"direction"); | 
 | 4787 |   if (option != (const char *) NULL) | 
 | 4788 |     draw_info->direction=(DirectionType) ParseMagickOption( | 
 | 4789 |       MagickDirectionOptions,MagickFalse,option); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4790 |   option=GetImageOption(clone_info,"fill"); | 
 | 4791 |   if (option != (const char *) NULL) | 
 | 4792 |     (void) QueryColorDatabase(option,&draw_info->fill,exception); | 
 | 4793 |   option=GetImageOption(clone_info,"stroke"); | 
 | 4794 |   if (option != (const char *) NULL) | 
 | 4795 |     (void) QueryColorDatabase(option,&draw_info->stroke,exception); | 
 | 4796 |   option=GetImageOption(clone_info,"strokewidth"); | 
 | 4797 |   if (option != (const char *) NULL) | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 4798 |     draw_info->stroke_width=StringToDouble(option); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4799 |   option=GetImageOption(clone_info,"undercolor"); | 
 | 4800 |   if (option != (const char *) NULL) | 
 | 4801 |     (void) QueryColorDatabase(option,&draw_info->undercolor,exception); | 
 | 4802 |   option=GetImageOption(clone_info,"gravity"); | 
 | 4803 |   if (option != (const char *) NULL) | 
 | 4804 |     draw_info->gravity=(GravityType) ParseMagickOption(MagickGravityOptions, | 
 | 4805 |       MagickFalse,option); | 
 | 4806 |   exception=DestroyExceptionInfo(exception); | 
 | 4807 |   draw_info->signature=MagickSignature; | 
 | 4808 |   clone_info=DestroyImageInfo(clone_info); | 
 | 4809 | } | 
 | 4810 |  | 
 | 4811 | /* | 
 | 4812 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 4813 | %                                                                             % | 
 | 4814 | %                                                                             % | 
 | 4815 | %                                                                             % | 
 | 4816 | +   P e r m u t a t e                                                         % | 
 | 4817 | %                                                                             % | 
 | 4818 | %                                                                             % | 
 | 4819 | %                                                                             % | 
 | 4820 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 4821 | % | 
 | 4822 | %  Permutate() returns the permuation of the (n,k). | 
 | 4823 | % | 
 | 4824 | %  The format of the Permutate method is: | 
 | 4825 | % | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4826 | %      void Permutate(ssize_t n,ssize_t k) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4827 | % | 
 | 4828 | %  A description of each parameter follows: | 
 | 4829 | % | 
 | 4830 | %    o n: | 
 | 4831 | % | 
 | 4832 | %    o k: | 
 | 4833 | % | 
 | 4834 | % | 
 | 4835 | */ | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4836 | static inline MagickRealType Permutate(const ssize_t n,const ssize_t k) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4837 | { | 
 | 4838 |   MagickRealType | 
 | 4839 |     r; | 
 | 4840 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4841 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4842 |     i; | 
 | 4843 |  | 
 | 4844 |   r=1.0; | 
 | 4845 |   for (i=k+1; i <= n; i++) | 
 | 4846 |     r*=i; | 
 | 4847 |   for (i=1; i <= (n-k); i++) | 
 | 4848 |     r/=i; | 
 | 4849 |   return(r); | 
 | 4850 | } | 
 | 4851 |  | 
 | 4852 | /* | 
 | 4853 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 4854 | %                                                                             % | 
 | 4855 | %                                                                             % | 
 | 4856 | %                                                                             % | 
 | 4857 | +   T r a c e P r i m i t i v e                                               % | 
 | 4858 | %                                                                             % | 
 | 4859 | %                                                                             % | 
 | 4860 | %                                                                             % | 
 | 4861 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
 | 4862 | % | 
 | 4863 | %  TracePrimitive is a collection of methods for generating graphic | 
 | 4864 | %  primitives such as arcs, ellipses, paths, etc. | 
 | 4865 | % | 
 | 4866 | */ | 
 | 4867 |  | 
 | 4868 | static void TraceArc(PrimitiveInfo *primitive_info,const PointInfo start, | 
 | 4869 |   const PointInfo end,const PointInfo degrees) | 
 | 4870 | { | 
 | 4871 |   PointInfo | 
 | 4872 |     center, | 
 | 4873 |     radii; | 
 | 4874 |  | 
 | 4875 |   center.x=0.5*(end.x+start.x); | 
 | 4876 |   center.y=0.5*(end.y+start.y); | 
 | 4877 |   radii.x=fabs(center.x-start.x); | 
 | 4878 |   radii.y=fabs(center.y-start.y); | 
 | 4879 |   TraceEllipse(primitive_info,center,radii,degrees); | 
 | 4880 | } | 
 | 4881 |  | 
 | 4882 | static void TraceArcPath(PrimitiveInfo *primitive_info,const PointInfo start, | 
 | 4883 |   const PointInfo end,const PointInfo arc,const MagickRealType angle, | 
 | 4884 |   const MagickBooleanType large_arc,const MagickBooleanType sweep) | 
 | 4885 | { | 
 | 4886 |   MagickRealType | 
 | 4887 |     alpha, | 
 | 4888 |     beta, | 
 | 4889 |     delta, | 
 | 4890 |     factor, | 
 | 4891 |     gamma, | 
 | 4892 |     theta; | 
 | 4893 |  | 
 | 4894 |   PointInfo | 
 | 4895 |     center, | 
 | 4896 |     points[3], | 
 | 4897 |     radii; | 
 | 4898 |  | 
 | 4899 |   register MagickRealType | 
 | 4900 |     cosine, | 
 | 4901 |     sine; | 
 | 4902 |  | 
 | 4903 |   register PrimitiveInfo | 
 | 4904 |     *p; | 
 | 4905 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4906 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4907 |     i; | 
 | 4908 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4909 |   size_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4910 |     arc_segments; | 
 | 4911 |  | 
 | 4912 |   if ((start.x == end.x) && (start.y == end.y)) | 
 | 4913 |     { | 
 | 4914 |       TracePoint(primitive_info,end); | 
 | 4915 |       return; | 
 | 4916 |     } | 
 | 4917 |   radii.x=fabs(arc.x); | 
 | 4918 |   radii.y=fabs(arc.y); | 
 | 4919 |   if ((radii.x == 0.0) || (radii.y == 0.0)) | 
 | 4920 |     { | 
 | 4921 |       TraceLine(primitive_info,start,end); | 
 | 4922 |       return; | 
 | 4923 |     } | 
 | 4924 |   cosine=cos(DegreesToRadians(fmod((double) angle,360.0))); | 
 | 4925 |   sine=sin(DegreesToRadians(fmod((double) angle,360.0))); | 
 | 4926 |   center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2); | 
 | 4927 |   center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2); | 
 | 4928 |   delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/ | 
 | 4929 |     (radii.y*radii.y); | 
 | 4930 |   if (delta < MagickEpsilon) | 
 | 4931 |     { | 
 | 4932 |       TraceLine(primitive_info,start,end); | 
 | 4933 |       return; | 
 | 4934 |     } | 
 | 4935 |   if (delta > 1.0) | 
 | 4936 |     { | 
 | 4937 |       radii.x*=sqrt((double) delta); | 
 | 4938 |       radii.y*=sqrt((double) delta); | 
 | 4939 |     } | 
 | 4940 |   points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x); | 
 | 4941 |   points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y); | 
 | 4942 |   points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x); | 
 | 4943 |   points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y); | 
 | 4944 |   alpha=points[1].x-points[0].x; | 
 | 4945 |   beta=points[1].y-points[0].y; | 
 | 4946 |   factor=1.0/(alpha*alpha+beta*beta)-0.25; | 
 | 4947 |   if (factor <= 0.0) | 
 | 4948 |     factor=0.0; | 
 | 4949 |   else | 
 | 4950 |     { | 
 | 4951 |       factor=sqrt((double) factor); | 
 | 4952 |       if (sweep == large_arc) | 
 | 4953 |         factor=(-factor); | 
 | 4954 |     } | 
 | 4955 |   center.x=(double) ((points[0].x+points[1].x)/2-factor*beta); | 
 | 4956 |   center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha); | 
 | 4957 |   alpha=atan2(points[0].y-center.y,points[0].x-center.x); | 
 | 4958 |   theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha; | 
 | 4959 |   if ((theta < 0.0) && (sweep != MagickFalse)) | 
 | 4960 |     theta+=(MagickRealType) (2.0*MagickPI); | 
 | 4961 |   else | 
 | 4962 |     if ((theta > 0.0) && (sweep == MagickFalse)) | 
 | 4963 |       theta-=(MagickRealType) (2.0*MagickPI); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4964 |   arc_segments=(size_t) ceil(fabs((double) (theta/(0.5*MagickPI+ | 
| cristy | 254181b | 2010-03-18 01:08:51 +0000 | [diff] [blame] | 4965 |     MagickEpsilon)))-0.5); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4966 |   p=primitive_info; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4967 |   for (i=0; i < (ssize_t) arc_segments; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4968 |   { | 
 | 4969 |     beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments)); | 
 | 4970 |     gamma=(8.0/3.0)*sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))* | 
 | 4971 |       sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))/ | 
 | 4972 |       sin(fmod((double) beta,DegreesToRadians(360.0))); | 
 | 4973 |     points[0].x=(double) (center.x+cos(fmod((double) (alpha+(double) i*theta/ | 
 | 4974 |       arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((double) (alpha+ | 
 | 4975 |       (double) i*theta/arc_segments),DegreesToRadians(360.0)))); | 
 | 4976 |     points[0].y=(double) (center.y+sin(fmod((double) (alpha+(double) i*theta/ | 
 | 4977 |       arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((double) (alpha+ | 
 | 4978 |       (double) i*theta/arc_segments),DegreesToRadians(360.0)))); | 
 | 4979 |     points[2].x=(double) (center.x+cos(fmod((double) (alpha+(double) (i+1)* | 
 | 4980 |       theta/arc_segments),DegreesToRadians(360.0)))); | 
 | 4981 |     points[2].y=(double) (center.y+sin(fmod((double) (alpha+(double) (i+1)* | 
 | 4982 |       theta/arc_segments),DegreesToRadians(360.0)))); | 
 | 4983 |     points[1].x=(double) (points[2].x+gamma*sin(fmod((double) (alpha+(double) | 
 | 4984 |       (i+1)*theta/arc_segments),DegreesToRadians(360.0)))); | 
 | 4985 |     points[1].y=(double) (points[2].y-gamma*cos(fmod((double) (alpha+(double) | 
 | 4986 |       (i+1)*theta/arc_segments),DegreesToRadians(360.0)))); | 
 | 4987 |     p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x; | 
 | 4988 |     p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y; | 
 | 4989 |     (p+1)->point.x=(double) (cosine*radii.x*points[0].x-sine*radii.y* | 
 | 4990 |       points[0].y); | 
 | 4991 |     (p+1)->point.y=(double) (sine*radii.x*points[0].x+cosine*radii.y* | 
 | 4992 |       points[0].y); | 
 | 4993 |     (p+2)->point.x=(double) (cosine*radii.x*points[1].x-sine*radii.y* | 
 | 4994 |       points[1].y); | 
 | 4995 |     (p+2)->point.y=(double) (sine*radii.x*points[1].x+cosine*radii.y* | 
 | 4996 |       points[1].y); | 
 | 4997 |     (p+3)->point.x=(double) (cosine*radii.x*points[2].x-sine*radii.y* | 
 | 4998 |       points[2].y); | 
 | 4999 |     (p+3)->point.y=(double) (sine*radii.x*points[2].x+cosine*radii.y* | 
 | 5000 |       points[2].y); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5001 |     if (i == (ssize_t) (arc_segments-1)) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5002 |       (p+3)->point=end; | 
 | 5003 |     TraceBezier(p,4); | 
 | 5004 |     p+=p->coordinates; | 
 | 5005 |   } | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5006 |   primitive_info->coordinates=(size_t) (p-primitive_info); | 
 | 5007 |   for (i=0; i < (ssize_t) primitive_info->coordinates; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5008 |   { | 
 | 5009 |     p->primitive=primitive_info->primitive; | 
 | 5010 |     p--; | 
 | 5011 |   } | 
 | 5012 | } | 
 | 5013 |  | 
 | 5014 | static void TraceBezier(PrimitiveInfo *primitive_info, | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5015 |   const size_t number_coordinates) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5016 | { | 
 | 5017 |   MagickRealType | 
 | 5018 |     alpha, | 
 | 5019 |     *coefficients, | 
 | 5020 |     weight; | 
 | 5021 |  | 
 | 5022 |   PointInfo | 
 | 5023 |     end, | 
 | 5024 |     point, | 
 | 5025 |     *points; | 
 | 5026 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5027 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5028 |     i, | 
 | 5029 |     j; | 
 | 5030 |  | 
 | 5031 |   register PrimitiveInfo | 
 | 5032 |     *p; | 
 | 5033 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5034 |   size_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5035 |     control_points, | 
 | 5036 |     quantum; | 
 | 5037 |  | 
 | 5038 |   /* | 
 | 5039 |     Allocate coeficients. | 
 | 5040 |   */ | 
 | 5041 |   quantum=number_coordinates; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5042 |   for (i=0; i < (ssize_t) number_coordinates; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5043 |   { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5044 |     for (j=i+1; j < (ssize_t) number_coordinates; j++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5045 |     { | 
 | 5046 |       alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x); | 
 | 5047 |       if (alpha > (MagickRealType) quantum) | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5048 |         quantum=(size_t) alpha; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5049 |       alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y); | 
 | 5050 |       if (alpha > (MagickRealType) quantum) | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5051 |         quantum=(size_t) alpha; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5052 |     } | 
 | 5053 |   } | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5054 |   quantum=(size_t) MagickMin((double) quantum/number_coordinates, | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5055 |     (double) BezierQuantum); | 
 | 5056 |   control_points=quantum*number_coordinates; | 
 | 5057 |   coefficients=(MagickRealType *) AcquireQuantumMemory((size_t) | 
 | 5058 |     number_coordinates,sizeof(*coefficients)); | 
 | 5059 |   points=(PointInfo *) AcquireQuantumMemory((size_t) control_points, | 
 | 5060 |     sizeof(*points)); | 
 | 5061 |   if ((coefficients == (MagickRealType *) NULL) || | 
 | 5062 |       (points == (PointInfo *) NULL)) | 
 | 5063 |     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); | 
 | 5064 |   /* | 
 | 5065 |     Compute bezier points. | 
 | 5066 |   */ | 
 | 5067 |   end=primitive_info[number_coordinates-1].point; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5068 |   for (i=0; i < (ssize_t) number_coordinates; i++) | 
 | 5069 |     coefficients[i]=Permutate((ssize_t) number_coordinates-1,i); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5070 |   weight=0.0; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5071 |   for (i=0; i < (ssize_t) control_points; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5072 |   { | 
 | 5073 |     p=primitive_info; | 
 | 5074 |     point.x=0.0; | 
 | 5075 |     point.y=0.0; | 
 | 5076 |     alpha=pow((double) (1.0-weight),(double) number_coordinates-1.0); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5077 |     for (j=0; j < (ssize_t) number_coordinates; j++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5078 |     { | 
 | 5079 |       point.x+=alpha*coefficients[j]*p->point.x; | 
 | 5080 |       point.y+=alpha*coefficients[j]*p->point.y; | 
 | 5081 |       alpha*=weight/(1.0-weight); | 
 | 5082 |       p++; | 
 | 5083 |     } | 
 | 5084 |     points[i]=point; | 
 | 5085 |     weight+=1.0/control_points; | 
 | 5086 |   } | 
 | 5087 |   /* | 
 | 5088 |     Bezier curves are just short segmented polys. | 
 | 5089 |   */ | 
 | 5090 |   p=primitive_info; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5091 |   for (i=0; i < (ssize_t) control_points; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5092 |   { | 
 | 5093 |     TracePoint(p,points[i]); | 
 | 5094 |     p+=p->coordinates; | 
 | 5095 |   } | 
 | 5096 |   TracePoint(p,end); | 
 | 5097 |   p+=p->coordinates; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5098 |   primitive_info->coordinates=(size_t) (p-primitive_info); | 
 | 5099 |   for (i=0; i < (ssize_t) primitive_info->coordinates; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5100 |   { | 
 | 5101 |     p->primitive=primitive_info->primitive; | 
 | 5102 |     p--; | 
 | 5103 |   } | 
 | 5104 |   points=(PointInfo *) RelinquishMagickMemory(points); | 
 | 5105 |   coefficients=(MagickRealType *) RelinquishMagickMemory(coefficients); | 
 | 5106 | } | 
 | 5107 |  | 
 | 5108 | static void TraceCircle(PrimitiveInfo *primitive_info,const PointInfo start, | 
 | 5109 |   const PointInfo end) | 
 | 5110 | { | 
 | 5111 |   MagickRealType | 
 | 5112 |     alpha, | 
 | 5113 |     beta, | 
 | 5114 |     radius; | 
 | 5115 |  | 
 | 5116 |   PointInfo | 
 | 5117 |     offset, | 
 | 5118 |     degrees; | 
 | 5119 |  | 
 | 5120 |   alpha=end.x-start.x; | 
 | 5121 |   beta=end.y-start.y; | 
 | 5122 |   radius=hypot((double) alpha,(double) beta); | 
 | 5123 |   offset.x=(double) radius; | 
 | 5124 |   offset.y=(double) radius; | 
 | 5125 |   degrees.x=0.0; | 
 | 5126 |   degrees.y=360.0; | 
 | 5127 |   TraceEllipse(primitive_info,start,offset,degrees); | 
 | 5128 | } | 
 | 5129 |  | 
 | 5130 | static void TraceEllipse(PrimitiveInfo *primitive_info,const PointInfo start, | 
 | 5131 |   const PointInfo stop,const PointInfo degrees) | 
 | 5132 | { | 
 | 5133 |   MagickRealType | 
 | 5134 |     delta, | 
 | 5135 |     step, | 
 | 5136 |     y; | 
 | 5137 |  | 
 | 5138 |   PointInfo | 
 | 5139 |     angle, | 
 | 5140 |     point; | 
 | 5141 |  | 
 | 5142 |   register PrimitiveInfo | 
 | 5143 |     *p; | 
 | 5144 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5145 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5146 |     i; | 
 | 5147 |  | 
 | 5148 |   /* | 
 | 5149 |     Ellipses are just short segmented polys. | 
 | 5150 |   */ | 
 | 5151 |   if ((stop.x == 0.0) && (stop.y == 0.0)) | 
 | 5152 |     { | 
 | 5153 |       TracePoint(primitive_info,start); | 
 | 5154 |       return; | 
 | 5155 |     } | 
 | 5156 |   delta=2.0/MagickMax(stop.x,stop.y); | 
 | 5157 |   step=(MagickRealType) (MagickPI/8.0); | 
| cristy | ed11071 | 2010-03-23 01:16:38 +0000 | [diff] [blame] | 5158 |   if ((delta >= 0.0) && (delta < (MagickPI/8.0))) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5159 |     step=MagickPI/(4*(MagickPI/delta/2+0.5)); | 
 | 5160 |   angle.x=DegreesToRadians(degrees.x); | 
 | 5161 |   y=degrees.y; | 
 | 5162 |   while (y < degrees.x) | 
 | 5163 |     y+=360.0; | 
 | 5164 |   angle.y=(double) (DegreesToRadians(y)-MagickEpsilon); | 
 | 5165 |   for (p=primitive_info; angle.x < angle.y; angle.x+=step) | 
 | 5166 |   { | 
 | 5167 |     point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*stop.x+start.x; | 
 | 5168 |     point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*stop.y+start.y; | 
 | 5169 |     TracePoint(p,point); | 
 | 5170 |     p+=p->coordinates; | 
 | 5171 |   } | 
 | 5172 |   point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*stop.x+start.x; | 
 | 5173 |   point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*stop.y+start.y; | 
 | 5174 |   TracePoint(p,point); | 
 | 5175 |   p+=p->coordinates; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5176 |   primitive_info->coordinates=(size_t) (p-primitive_info); | 
 | 5177 |   for (i=0; i < (ssize_t) primitive_info->coordinates; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5178 |   { | 
 | 5179 |     p->primitive=primitive_info->primitive; | 
 | 5180 |     p--; | 
 | 5181 |   } | 
 | 5182 | } | 
 | 5183 |  | 
 | 5184 | static void TraceLine(PrimitiveInfo *primitive_info,const PointInfo start, | 
 | 5185 |   const PointInfo end) | 
 | 5186 | { | 
 | 5187 |   TracePoint(primitive_info,start); | 
 | 5188 |   if ((fabs(start.x-end.x) <= MagickEpsilon) && | 
 | 5189 |       (fabs(start.y-end.y) <= MagickEpsilon)) | 
 | 5190 |     { | 
 | 5191 |       primitive_info->primitive=PointPrimitive; | 
 | 5192 |       primitive_info->coordinates=1; | 
 | 5193 |       return; | 
 | 5194 |     } | 
 | 5195 |   TracePoint(primitive_info+1,end); | 
 | 5196 |   (primitive_info+1)->primitive=primitive_info->primitive; | 
 | 5197 |   primitive_info->coordinates=2; | 
 | 5198 | } | 
 | 5199 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5200 | static size_t TracePath(PrimitiveInfo *primitive_info,const char *path) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5201 | { | 
 | 5202 |   char | 
 | 5203 |     token[MaxTextExtent]; | 
 | 5204 |  | 
 | 5205 |   const char | 
 | 5206 |     *p; | 
 | 5207 |  | 
 | 5208 |   int | 
 | 5209 |     attribute, | 
 | 5210 |     last_attribute; | 
 | 5211 |  | 
 | 5212 |   MagickRealType | 
 | 5213 |     x, | 
 | 5214 |     y; | 
 | 5215 |  | 
 | 5216 |   PointInfo | 
 | 5217 |     end, | 
 | 5218 |     points[4], | 
 | 5219 |     point, | 
 | 5220 |     start; | 
 | 5221 |  | 
 | 5222 |   PrimitiveType | 
 | 5223 |     primitive_type; | 
 | 5224 |  | 
 | 5225 |   register PrimitiveInfo | 
 | 5226 |     *q; | 
 | 5227 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5228 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5229 |     i; | 
 | 5230 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5231 |   size_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5232 |     number_coordinates, | 
 | 5233 |     z_count; | 
 | 5234 |  | 
 | 5235 |   attribute=0; | 
 | 5236 |   point.x=0.0; | 
 | 5237 |   point.y=0.0; | 
 | 5238 |   start.x=0.0; | 
 | 5239 |   start.y=0.0; | 
 | 5240 |   number_coordinates=0; | 
 | 5241 |   z_count=0; | 
 | 5242 |   primitive_type=primitive_info->primitive; | 
 | 5243 |   q=primitive_info; | 
 | 5244 |   for (p=path; *p != '\0'; ) | 
 | 5245 |   { | 
 | 5246 |     while (isspace((int) ((unsigned char) *p)) != 0) | 
 | 5247 |       p++; | 
 | 5248 |     if (*p == '\0') | 
 | 5249 |       break; | 
 | 5250 |     last_attribute=attribute; | 
 | 5251 |     attribute=(int) (*p++); | 
 | 5252 |     switch (attribute) | 
 | 5253 |     { | 
 | 5254 |       case 'a': | 
 | 5255 |       case 'A': | 
 | 5256 |       { | 
 | 5257 |         MagickBooleanType | 
 | 5258 |           large_arc, | 
 | 5259 |           sweep; | 
 | 5260 |  | 
 | 5261 |         MagickRealType | 
 | 5262 |           angle; | 
 | 5263 |  | 
 | 5264 |         PointInfo | 
 | 5265 |           arc; | 
 | 5266 |  | 
 | 5267 |         /* | 
 | 5268 |           Compute arc points. | 
 | 5269 |         */ | 
 | 5270 |         do | 
 | 5271 |         { | 
 | 5272 |           GetMagickToken(p,&p,token); | 
 | 5273 |           if (*token == ',') | 
 | 5274 |             GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5275 |           arc.x=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5276 |           GetMagickToken(p,&p,token); | 
 | 5277 |           if (*token == ',') | 
 | 5278 |             GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5279 |           arc.y=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5280 |           GetMagickToken(p,&p,token); | 
 | 5281 |           if (*token == ',') | 
 | 5282 |             GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5283 |           angle=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5284 |           GetMagickToken(p,&p,token); | 
 | 5285 |           if (*token == ',') | 
 | 5286 |             GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5287 |           large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5288 |           GetMagickToken(p,&p,token); | 
 | 5289 |           if (*token == ',') | 
 | 5290 |             GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5291 |           sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5292 |           GetMagickToken(p,&p,token); | 
 | 5293 |           if (*token == ',') | 
 | 5294 |             GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5295 |           x=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5296 |           GetMagickToken(p,&p,token); | 
 | 5297 |           if (*token == ',') | 
 | 5298 |             GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5299 |           y=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5300 |           end.x=(double) (attribute == (int) 'A' ? x : point.x+x); | 
 | 5301 |           end.y=(double) (attribute == (int) 'A' ? y : point.y+y); | 
 | 5302 |           TraceArcPath(q,point,end,arc,angle,large_arc,sweep); | 
 | 5303 |           q+=q->coordinates; | 
 | 5304 |           point=end; | 
 | 5305 |         } while (IsPoint(p) != MagickFalse); | 
 | 5306 |         break; | 
 | 5307 |       } | 
 | 5308 |       case 'c': | 
 | 5309 |       case 'C': | 
 | 5310 |       { | 
 | 5311 |         /* | 
 | 5312 |           Compute bezier points. | 
 | 5313 |         */ | 
 | 5314 |         do | 
 | 5315 |         { | 
 | 5316 |           points[0]=point; | 
 | 5317 |           for (i=1; i < 4; i++) | 
 | 5318 |           { | 
 | 5319 |             GetMagickToken(p,&p,token); | 
 | 5320 |             if (*token == ',') | 
 | 5321 |               GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5322 |             x=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5323 |             GetMagickToken(p,&p,token); | 
 | 5324 |             if (*token == ',') | 
 | 5325 |               GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5326 |             y=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5327 |             end.x=(double) (attribute == (int) 'C' ? x : point.x+x); | 
 | 5328 |             end.y=(double) (attribute == (int) 'C' ? y : point.y+y); | 
 | 5329 |             points[i]=end; | 
 | 5330 |           } | 
 | 5331 |           for (i=0; i < 4; i++) | 
 | 5332 |             (q+i)->point=points[i]; | 
 | 5333 |           TraceBezier(q,4); | 
 | 5334 |           q+=q->coordinates; | 
 | 5335 |           point=end; | 
 | 5336 |         } while (IsPoint(p) != MagickFalse); | 
 | 5337 |         break; | 
 | 5338 |       } | 
 | 5339 |       case 'H': | 
 | 5340 |       case 'h': | 
 | 5341 |       { | 
 | 5342 |         do | 
 | 5343 |         { | 
 | 5344 |           GetMagickToken(p,&p,token); | 
 | 5345 |           if (*token == ',') | 
 | 5346 |             GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5347 |           x=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5348 |           point.x=(double) (attribute == (int) 'H' ? x: point.x+x); | 
 | 5349 |           TracePoint(q,point); | 
 | 5350 |           q+=q->coordinates; | 
 | 5351 |         } while (IsPoint(p) != MagickFalse); | 
 | 5352 |         break; | 
 | 5353 |       } | 
 | 5354 |       case 'l': | 
 | 5355 |       case 'L': | 
 | 5356 |       { | 
 | 5357 |         do | 
 | 5358 |         { | 
 | 5359 |           GetMagickToken(p,&p,token); | 
 | 5360 |           if (*token == ',') | 
 | 5361 |             GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5362 |           x=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5363 |           GetMagickToken(p,&p,token); | 
 | 5364 |           if (*token == ',') | 
 | 5365 |             GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5366 |           y=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5367 |           point.x=(double) (attribute == (int) 'L' ? x : point.x+x); | 
 | 5368 |           point.y=(double) (attribute == (int) 'L' ? y : point.y+y); | 
 | 5369 |           TracePoint(q,point); | 
 | 5370 |           q+=q->coordinates; | 
 | 5371 |         } while (IsPoint(p) != MagickFalse); | 
 | 5372 |         break; | 
 | 5373 |       } | 
 | 5374 |       case 'M': | 
 | 5375 |       case 'm': | 
 | 5376 |       { | 
 | 5377 |         if (q != primitive_info) | 
 | 5378 |           { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5379 |             primitive_info->coordinates=(size_t) (q-primitive_info); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5380 |             number_coordinates+=primitive_info->coordinates; | 
 | 5381 |             primitive_info=q; | 
 | 5382 |           } | 
 | 5383 |         i=0; | 
 | 5384 |         do | 
 | 5385 |         { | 
 | 5386 |           GetMagickToken(p,&p,token); | 
 | 5387 |           if (*token == ',') | 
 | 5388 |             GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5389 |           x=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5390 |           GetMagickToken(p,&p,token); | 
 | 5391 |           if (*token == ',') | 
 | 5392 |             GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5393 |           y=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5394 |           point.x=(double) (attribute == (int) 'M' ? x : point.x+x); | 
 | 5395 |           point.y=(double) (attribute == (int) 'M' ? y : point.y+y); | 
 | 5396 |           if (i == 0) | 
 | 5397 |             start=point; | 
 | 5398 |           i++; | 
 | 5399 |           TracePoint(q,point); | 
 | 5400 |           q+=q->coordinates; | 
 | 5401 |           if (attribute == (int) 'M') | 
 | 5402 |             { | 
 | 5403 |               TracePoint(q,point); | 
 | 5404 |               q+=q->coordinates; | 
 | 5405 |             } | 
 | 5406 |         } while (IsPoint(p) != MagickFalse); | 
 | 5407 |         break; | 
 | 5408 |       } | 
 | 5409 |       case 'q': | 
 | 5410 |       case 'Q': | 
 | 5411 |       { | 
 | 5412 |         /* | 
 | 5413 |           Compute bezier points. | 
 | 5414 |         */ | 
 | 5415 |         do | 
 | 5416 |         { | 
 | 5417 |           points[0]=point; | 
 | 5418 |           for (i=1; i < 3; i++) | 
 | 5419 |           { | 
 | 5420 |             GetMagickToken(p,&p,token); | 
 | 5421 |             if (*token == ',') | 
 | 5422 |               GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5423 |             x=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5424 |             GetMagickToken(p,&p,token); | 
 | 5425 |             if (*token == ',') | 
 | 5426 |               GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5427 |             y=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5428 |             if (*p == ',') | 
 | 5429 |               p++; | 
 | 5430 |             end.x=(double) (attribute == (int) 'Q' ? x : point.x+x); | 
 | 5431 |             end.y=(double) (attribute == (int) 'Q' ? y : point.y+y); | 
 | 5432 |             points[i]=end; | 
 | 5433 |           } | 
 | 5434 |           for (i=0; i < 3; i++) | 
 | 5435 |             (q+i)->point=points[i]; | 
 | 5436 |           TraceBezier(q,3); | 
 | 5437 |           q+=q->coordinates; | 
 | 5438 |           point=end; | 
 | 5439 |         } while (IsPoint(p) != MagickFalse); | 
 | 5440 |         break; | 
 | 5441 |       } | 
 | 5442 |       case 's': | 
 | 5443 |       case 'S': | 
 | 5444 |       { | 
 | 5445 |         /* | 
 | 5446 |           Compute bezier points. | 
 | 5447 |         */ | 
 | 5448 |         do | 
 | 5449 |         { | 
 | 5450 |           points[0]=points[3]; | 
 | 5451 |           points[1].x=2.0*points[3].x-points[2].x; | 
 | 5452 |           points[1].y=2.0*points[3].y-points[2].y; | 
 | 5453 |           for (i=2; i < 4; i++) | 
 | 5454 |           { | 
 | 5455 |             GetMagickToken(p,&p,token); | 
 | 5456 |             if (*token == ',') | 
 | 5457 |               GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5458 |             x=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5459 |             GetMagickToken(p,&p,token); | 
 | 5460 |             if (*token == ',') | 
 | 5461 |               GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5462 |             y=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5463 |             if (*p == ',') | 
 | 5464 |               p++; | 
 | 5465 |             end.x=(double) (attribute == (int) 'S' ? x : point.x+x); | 
 | 5466 |             end.y=(double) (attribute == (int) 'S' ? y : point.y+y); | 
 | 5467 |             points[i]=end; | 
 | 5468 |           } | 
 | 5469 |           if (strchr("CcSs",last_attribute) == (char *) NULL) | 
 | 5470 |             { | 
 | 5471 |               points[0]=points[2]; | 
 | 5472 |               points[1]=points[3]; | 
 | 5473 |             } | 
 | 5474 |           for (i=0; i < 4; i++) | 
 | 5475 |             (q+i)->point=points[i]; | 
 | 5476 |           TraceBezier(q,4); | 
 | 5477 |           q+=q->coordinates; | 
 | 5478 |           point=end; | 
 | 5479 |         } while (IsPoint(p) != MagickFalse); | 
 | 5480 |         break; | 
 | 5481 |       } | 
 | 5482 |       case 't': | 
 | 5483 |       case 'T': | 
 | 5484 |       { | 
 | 5485 |         /* | 
 | 5486 |           Compute bezier points. | 
 | 5487 |         */ | 
 | 5488 |         do | 
 | 5489 |         { | 
 | 5490 |           points[0]=points[2]; | 
 | 5491 |           points[1].x=2.0*points[2].x-points[1].x; | 
 | 5492 |           points[1].y=2.0*points[2].y-points[1].y; | 
 | 5493 |           for (i=2; i < 3; i++) | 
 | 5494 |           { | 
 | 5495 |             GetMagickToken(p,&p,token); | 
 | 5496 |             if (*token == ',') | 
 | 5497 |               GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5498 |             x=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5499 |             GetMagickToken(p,&p,token); | 
 | 5500 |             if (*token == ',') | 
 | 5501 |               GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5502 |             y=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5503 |             end.x=(double) (attribute == (int) 'T' ? x : point.x+x); | 
 | 5504 |             end.y=(double) (attribute == (int) 'T' ? y : point.y+y); | 
 | 5505 |             points[i]=end; | 
 | 5506 |           } | 
 | 5507 |           if (strchr("QqTt",last_attribute) == (char *) NULL) | 
 | 5508 |             { | 
 | 5509 |               points[0]=points[2]; | 
 | 5510 |               points[1]=points[3]; | 
 | 5511 |             } | 
 | 5512 |           for (i=0; i < 3; i++) | 
 | 5513 |             (q+i)->point=points[i]; | 
 | 5514 |           TraceBezier(q,3); | 
 | 5515 |           q+=q->coordinates; | 
 | 5516 |           point=end; | 
 | 5517 |         } while (IsPoint(p) != MagickFalse); | 
 | 5518 |         break; | 
 | 5519 |       } | 
 | 5520 |       case 'v': | 
 | 5521 |       case 'V': | 
 | 5522 |       { | 
 | 5523 |         do | 
 | 5524 |         { | 
 | 5525 |           GetMagickToken(p,&p,token); | 
 | 5526 |           if (*token == ',') | 
 | 5527 |             GetMagickToken(p,&p,token); | 
| cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5528 |           y=StringToDouble(token); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5529 |           point.y=(double) (attribute == (int) 'V' ? y : point.y+y); | 
 | 5530 |           TracePoint(q,point); | 
 | 5531 |           q+=q->coordinates; | 
 | 5532 |         } while (IsPoint(p) != MagickFalse); | 
 | 5533 |         break; | 
 | 5534 |       } | 
 | 5535 |       case 'z': | 
 | 5536 |       case 'Z': | 
 | 5537 |       { | 
 | 5538 |         point=start; | 
 | 5539 |         TracePoint(q,point); | 
 | 5540 |         q+=q->coordinates; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5541 |         primitive_info->coordinates=(size_t) (q-primitive_info); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5542 |         number_coordinates+=primitive_info->coordinates; | 
 | 5543 |         primitive_info=q; | 
 | 5544 |         z_count++; | 
 | 5545 |         break; | 
 | 5546 |       } | 
 | 5547 |       default: | 
 | 5548 |       { | 
 | 5549 |         if (isalpha((int) ((unsigned char) attribute)) != 0) | 
 | 5550 |           (void) fprintf(stderr,"attribute not recognized: %c\n",attribute); | 
 | 5551 |         break; | 
 | 5552 |       } | 
 | 5553 |     } | 
 | 5554 |   } | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5555 |   primitive_info->coordinates=(size_t) (q-primitive_info); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5556 |   number_coordinates+=primitive_info->coordinates; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5557 |   for (i=0; i < (ssize_t) number_coordinates; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5558 |   { | 
 | 5559 |     q--; | 
 | 5560 |     q->primitive=primitive_type; | 
 | 5561 |     if (z_count > 1) | 
 | 5562 |       q->method=FillToBorderMethod; | 
 | 5563 |   } | 
 | 5564 |   q=primitive_info; | 
 | 5565 |   return(number_coordinates); | 
 | 5566 | } | 
 | 5567 |  | 
 | 5568 | static void TraceRectangle(PrimitiveInfo *primitive_info,const PointInfo start, | 
 | 5569 |   const PointInfo end) | 
 | 5570 | { | 
 | 5571 |   PointInfo | 
 | 5572 |     point; | 
 | 5573 |  | 
 | 5574 |   register PrimitiveInfo | 
 | 5575 |     *p; | 
 | 5576 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5577 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5578 |     i; | 
 | 5579 |  | 
 | 5580 |   p=primitive_info; | 
 | 5581 |   TracePoint(p,start); | 
 | 5582 |   p+=p->coordinates; | 
 | 5583 |   point.x=start.x; | 
 | 5584 |   point.y=end.y; | 
 | 5585 |   TracePoint(p,point); | 
 | 5586 |   p+=p->coordinates; | 
 | 5587 |   TracePoint(p,end); | 
 | 5588 |   p+=p->coordinates; | 
 | 5589 |   point.x=end.x; | 
 | 5590 |   point.y=start.y; | 
 | 5591 |   TracePoint(p,point); | 
 | 5592 |   p+=p->coordinates; | 
 | 5593 |   TracePoint(p,start); | 
 | 5594 |   p+=p->coordinates; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5595 |   primitive_info->coordinates=(size_t) (p-primitive_info); | 
 | 5596 |   for (i=0; i < (ssize_t) primitive_info->coordinates; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5597 |   { | 
 | 5598 |     p->primitive=primitive_info->primitive; | 
 | 5599 |     p--; | 
 | 5600 |   } | 
 | 5601 | } | 
 | 5602 |  | 
 | 5603 | static void TraceRoundRectangle(PrimitiveInfo *primitive_info, | 
 | 5604 |   const PointInfo start,const PointInfo end,PointInfo arc) | 
 | 5605 | { | 
 | 5606 |   PointInfo | 
 | 5607 |     degrees, | 
 | 5608 |     offset, | 
 | 5609 |     point; | 
 | 5610 |  | 
 | 5611 |   register PrimitiveInfo | 
 | 5612 |     *p; | 
 | 5613 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5614 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5615 |     i; | 
 | 5616 |  | 
 | 5617 |   p=primitive_info; | 
 | 5618 |   offset.x=fabs(end.x-start.x); | 
 | 5619 |   offset.y=fabs(end.y-start.y); | 
 | 5620 |   if (arc.x > (0.5*offset.x)) | 
 | 5621 |     arc.x=0.5*offset.x; | 
 | 5622 |   if (arc.y > (0.5*offset.y)) | 
 | 5623 |     arc.y=0.5*offset.y; | 
 | 5624 |   point.x=start.x+offset.x-arc.x; | 
 | 5625 |   point.y=start.y+arc.y; | 
 | 5626 |   degrees.x=270.0; | 
 | 5627 |   degrees.y=360.0; | 
 | 5628 |   TraceEllipse(p,point,arc,degrees); | 
 | 5629 |   p+=p->coordinates; | 
 | 5630 |   point.x=start.x+offset.x-arc.x; | 
 | 5631 |   point.y=start.y+offset.y-arc.y; | 
 | 5632 |   degrees.x=0.0; | 
 | 5633 |   degrees.y=90.0; | 
 | 5634 |   TraceEllipse(p,point,arc,degrees); | 
 | 5635 |   p+=p->coordinates; | 
 | 5636 |   point.x=start.x+arc.x; | 
 | 5637 |   point.y=start.y+offset.y-arc.y; | 
 | 5638 |   degrees.x=90.0; | 
 | 5639 |   degrees.y=180.0; | 
 | 5640 |   TraceEllipse(p,point,arc,degrees); | 
 | 5641 |   p+=p->coordinates; | 
 | 5642 |   point.x=start.x+arc.x; | 
 | 5643 |   point.y=start.y+arc.y; | 
 | 5644 |   degrees.x=180.0; | 
 | 5645 |   degrees.y=270.0; | 
 | 5646 |   TraceEllipse(p,point,arc,degrees); | 
 | 5647 |   p+=p->coordinates; | 
 | 5648 |   TracePoint(p,primitive_info->point); | 
 | 5649 |   p+=p->coordinates; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5650 |   primitive_info->coordinates=(size_t) (p-primitive_info); | 
 | 5651 |   for (i=0; i < (ssize_t) primitive_info->coordinates; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5652 |   { | 
 | 5653 |     p->primitive=primitive_info->primitive; | 
 | 5654 |     p--; | 
 | 5655 |   } | 
 | 5656 | } | 
 | 5657 |  | 
 | 5658 | static void TraceSquareLinecap(PrimitiveInfo *primitive_info, | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5659 |   const size_t number_vertices,const MagickRealType offset) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5660 | { | 
 | 5661 |   MagickRealType | 
 | 5662 |     distance; | 
 | 5663 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5664 |   ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5665 |     j; | 
 | 5666 |  | 
 | 5667 |   register MagickRealType | 
 | 5668 |     dx, | 
 | 5669 |     dy; | 
 | 5670 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5671 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5672 |     i; | 
 | 5673 |  | 
 | 5674 |   dx=0.0; | 
 | 5675 |   dy=0.0; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5676 |   for (i=1; i < (ssize_t) number_vertices; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5677 |   { | 
 | 5678 |     dx=primitive_info[0].point.x-primitive_info[i].point.x; | 
 | 5679 |     dy=primitive_info[0].point.y-primitive_info[i].point.y; | 
 | 5680 |     if ((fabs((double) dx) >= MagickEpsilon) || | 
 | 5681 |         (fabs((double) dy) >= MagickEpsilon)) | 
 | 5682 |       break; | 
 | 5683 |   } | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5684 |   if (i == (ssize_t) number_vertices) | 
 | 5685 |     i=(ssize_t) number_vertices-1L; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5686 |   distance=hypot((double) dx,(double) dy); | 
 | 5687 |   primitive_info[0].point.x=(double) (primitive_info[i].point.x+ | 
 | 5688 |     dx*(distance+offset)/distance); | 
 | 5689 |   primitive_info[0].point.y=(double) (primitive_info[i].point.y+ | 
 | 5690 |     dy*(distance+offset)/distance); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5691 |   for (j=(ssize_t) number_vertices-2; j >= 0;  j--) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5692 |   { | 
 | 5693 |     dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x; | 
 | 5694 |     dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y; | 
 | 5695 |     if ((fabs((double) dx) >= MagickEpsilon) || | 
 | 5696 |         (fabs((double) dy) >= MagickEpsilon)) | 
 | 5697 |       break; | 
 | 5698 |   } | 
 | 5699 |   distance=hypot((double) dx,(double) dy); | 
 | 5700 |   primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+ | 
 | 5701 |     dx*(distance+offset)/distance); | 
 | 5702 |   primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+ | 
 | 5703 |     dy*(distance+offset)/distance); | 
 | 5704 | } | 
 | 5705 |  | 
 | 5706 | static PrimitiveInfo *TraceStrokePolygon(const DrawInfo *draw_info, | 
 | 5707 |   const PrimitiveInfo *primitive_info) | 
 | 5708 | { | 
 | 5709 |   typedef struct _LineSegment | 
 | 5710 |   { | 
 | 5711 |     double | 
 | 5712 |       p, | 
 | 5713 |       q; | 
 | 5714 |   } LineSegment; | 
 | 5715 |  | 
 | 5716 |   LineSegment | 
 | 5717 |     dx, | 
 | 5718 |     dy, | 
 | 5719 |     inverse_slope, | 
 | 5720 |     slope, | 
 | 5721 |     theta; | 
 | 5722 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5723 |   ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5724 |     j, | 
 | 5725 |     n, | 
 | 5726 |     p, | 
 | 5727 |     q; | 
 | 5728 |  | 
 | 5729 |   MagickBooleanType | 
 | 5730 |     closed_path; | 
 | 5731 |  | 
 | 5732 |   MagickRealType | 
 | 5733 |     delta_theta, | 
 | 5734 |     dot_product, | 
 | 5735 |     mid, | 
 | 5736 |     miterlimit; | 
 | 5737 |  | 
 | 5738 |   PointInfo | 
 | 5739 |     box_p[5], | 
 | 5740 |     box_q[5], | 
 | 5741 |     center, | 
 | 5742 |     offset, | 
 | 5743 |     *path_p, | 
 | 5744 |     *path_q; | 
 | 5745 |  | 
 | 5746 |   PrimitiveInfo | 
 | 5747 |     *polygon_primitive, | 
 | 5748 |     *stroke_polygon; | 
 | 5749 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5750 |   register ssize_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5751 |     i; | 
 | 5752 |  | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5753 |   size_t | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5754 |     arc_segments, | 
 | 5755 |     max_strokes, | 
 | 5756 |     number_vertices; | 
 | 5757 |  | 
 | 5758 |   /* | 
 | 5759 |     Allocate paths. | 
 | 5760 |   */ | 
 | 5761 |   number_vertices=primitive_info->coordinates; | 
 | 5762 |   max_strokes=2*number_vertices+6*BezierQuantum+360; | 
 | 5763 |   path_p=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes, | 
 | 5764 |     sizeof(*path_p)); | 
 | 5765 |   path_q=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes, | 
 | 5766 |     sizeof(*path_q)); | 
 | 5767 |   polygon_primitive=(PrimitiveInfo *) AcquireQuantumMemory((size_t) | 
 | 5768 |     number_vertices+2UL,sizeof(*polygon_primitive)); | 
 | 5769 |   if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL) || | 
 | 5770 |       (polygon_primitive == (PrimitiveInfo *) NULL)) | 
 | 5771 |     return((PrimitiveInfo *) NULL); | 
 | 5772 |   (void) CopyMagickMemory(polygon_primitive,primitive_info,(size_t) | 
 | 5773 |     number_vertices*sizeof(*polygon_primitive)); | 
 | 5774 |   closed_path= | 
 | 5775 |     (primitive_info[number_vertices-1].point.x == primitive_info[0].point.x) && | 
 | 5776 |     (primitive_info[number_vertices-1].point.y == primitive_info[0].point.y) ? | 
 | 5777 |     MagickTrue : MagickFalse; | 
 | 5778 |   if ((draw_info->linejoin == RoundJoin) || | 
 | 5779 |       ((draw_info->linejoin == MiterJoin) && (closed_path != MagickFalse))) | 
 | 5780 |     { | 
 | 5781 |       polygon_primitive[number_vertices]=primitive_info[1]; | 
 | 5782 |       number_vertices++; | 
 | 5783 |     } | 
 | 5784 |   polygon_primitive[number_vertices].primitive=UndefinedPrimitive; | 
 | 5785 |   /* | 
 | 5786 |     Compute the slope for the first line segment, p. | 
 | 5787 |   */ | 
 | 5788 |   dx.p=0.0; | 
 | 5789 |   dy.p=0.0; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5790 |   for (n=1; n < (ssize_t) number_vertices; n++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5791 |   { | 
 | 5792 |     dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x; | 
 | 5793 |     dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y; | 
 | 5794 |     if ((fabs(dx.p) >= MagickEpsilon) || (fabs(dy.p) >= MagickEpsilon)) | 
 | 5795 |       break; | 
 | 5796 |   } | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5797 |   if (n == (ssize_t) number_vertices) | 
 | 5798 |     n=(ssize_t) number_vertices-1L; | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5799 |   slope.p=0.0; | 
 | 5800 |   inverse_slope.p=0.0; | 
 | 5801 |   if (fabs(dx.p) <= MagickEpsilon) | 
 | 5802 |     { | 
 | 5803 |       if (dx.p >= 0.0) | 
 | 5804 |         slope.p=dy.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon; | 
 | 5805 |       else | 
 | 5806 |         slope.p=dy.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon; | 
 | 5807 |     } | 
 | 5808 |   else | 
 | 5809 |     if (fabs(dy.p) <= MagickEpsilon) | 
 | 5810 |       { | 
 | 5811 |         if (dy.p >= 0.0) | 
 | 5812 |           inverse_slope.p=dx.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon; | 
 | 5813 |         else | 
 | 5814 |           inverse_slope.p=dx.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon; | 
 | 5815 |       } | 
 | 5816 |     else | 
 | 5817 |       { | 
 | 5818 |         slope.p=dy.p/dx.p; | 
 | 5819 |         inverse_slope.p=(-1.0/slope.p); | 
 | 5820 |       } | 
 | 5821 |   mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0; | 
 | 5822 |   miterlimit=(MagickRealType) (draw_info->miterlimit*draw_info->miterlimit* | 
 | 5823 |     mid*mid); | 
 | 5824 |   if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse)) | 
 | 5825 |     TraceSquareLinecap(polygon_primitive,number_vertices,mid); | 
 | 5826 |   offset.x=sqrt((double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0))); | 
 | 5827 |   offset.y=(double) (offset.x*inverse_slope.p); | 
 | 5828 |   if ((dy.p*offset.x-dx.p*offset.y) > 0.0) | 
 | 5829 |     { | 
 | 5830 |       box_p[0].x=polygon_primitive[0].point.x-offset.x; | 
 | 5831 |       box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p; | 
 | 5832 |       box_p[1].x=polygon_primitive[n].point.x-offset.x; | 
 | 5833 |       box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p; | 
 | 5834 |       box_q[0].x=polygon_primitive[0].point.x+offset.x; | 
 | 5835 |       box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p; | 
 | 5836 |       box_q[1].x=polygon_primitive[n].point.x+offset.x; | 
 | 5837 |       box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p; | 
 | 5838 |     } | 
 | 5839 |   else | 
 | 5840 |     { | 
 | 5841 |       box_p[0].x=polygon_primitive[0].point.x+offset.x; | 
 | 5842 |       box_p[0].y=polygon_primitive[0].point.y+offset.y; | 
 | 5843 |       box_p[1].x=polygon_primitive[n].point.x+offset.x; | 
 | 5844 |       box_p[1].y=polygon_primitive[n].point.y+offset.y; | 
 | 5845 |       box_q[0].x=polygon_primitive[0].point.x-offset.x; | 
 | 5846 |       box_q[0].y=polygon_primitive[0].point.y-offset.y; | 
 | 5847 |       box_q[1].x=polygon_primitive[n].point.x-offset.x; | 
 | 5848 |       box_q[1].y=polygon_primitive[n].point.y-offset.y; | 
 | 5849 |     } | 
 | 5850 |   /* | 
 | 5851 |     Create strokes for the line join attribute: bevel, miter, round. | 
 | 5852 |   */ | 
 | 5853 |   p=0; | 
 | 5854 |   q=0; | 
 | 5855 |   path_q[p++]=box_q[0]; | 
 | 5856 |   path_p[q++]=box_p[0]; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5857 |   for (i=(ssize_t) n+1; i < (ssize_t) number_vertices; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5858 |   { | 
 | 5859 |     /* | 
 | 5860 |       Compute the slope for this line segment, q. | 
 | 5861 |     */ | 
 | 5862 |     dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x; | 
 | 5863 |     dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y; | 
 | 5864 |     dot_product=dx.q*dx.q+dy.q*dy.q; | 
 | 5865 |     if (dot_product < 0.25) | 
 | 5866 |       continue; | 
 | 5867 |     slope.q=0.0; | 
 | 5868 |     inverse_slope.q=0.0; | 
 | 5869 |     if (fabs(dx.q) < MagickEpsilon) | 
 | 5870 |       { | 
 | 5871 |         if (dx.q >= 0.0) | 
 | 5872 |           slope.q=dy.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon; | 
 | 5873 |         else | 
 | 5874 |           slope.q=dy.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon; | 
 | 5875 |       } | 
 | 5876 |     else | 
 | 5877 |       if (fabs(dy.q) <= MagickEpsilon) | 
 | 5878 |         { | 
 | 5879 |           if (dy.q >= 0.0) | 
 | 5880 |             inverse_slope.q=dx.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon; | 
 | 5881 |           else | 
 | 5882 |             inverse_slope.q=dx.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon; | 
 | 5883 |         } | 
 | 5884 |       else | 
 | 5885 |         { | 
 | 5886 |           slope.q=dy.q/dx.q; | 
 | 5887 |           inverse_slope.q=(-1.0/slope.q); | 
 | 5888 |         } | 
 | 5889 |     offset.x=sqrt((double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0))); | 
 | 5890 |     offset.y=(double) (offset.x*inverse_slope.q); | 
 | 5891 |     dot_product=dy.q*offset.x-dx.q*offset.y; | 
 | 5892 |     if (dot_product > 0.0) | 
 | 5893 |       { | 
 | 5894 |         box_p[2].x=polygon_primitive[n].point.x-offset.x; | 
 | 5895 |         box_p[2].y=polygon_primitive[n].point.y-offset.y; | 
 | 5896 |         box_p[3].x=polygon_primitive[i].point.x-offset.x; | 
 | 5897 |         box_p[3].y=polygon_primitive[i].point.y-offset.y; | 
 | 5898 |         box_q[2].x=polygon_primitive[n].point.x+offset.x; | 
 | 5899 |         box_q[2].y=polygon_primitive[n].point.y+offset.y; | 
 | 5900 |         box_q[3].x=polygon_primitive[i].point.x+offset.x; | 
 | 5901 |         box_q[3].y=polygon_primitive[i].point.y+offset.y; | 
 | 5902 |       } | 
 | 5903 |     else | 
 | 5904 |       { | 
 | 5905 |         box_p[2].x=polygon_primitive[n].point.x+offset.x; | 
 | 5906 |         box_p[2].y=polygon_primitive[n].point.y+offset.y; | 
 | 5907 |         box_p[3].x=polygon_primitive[i].point.x+offset.x; | 
 | 5908 |         box_p[3].y=polygon_primitive[i].point.y+offset.y; | 
 | 5909 |         box_q[2].x=polygon_primitive[n].point.x-offset.x; | 
 | 5910 |         box_q[2].y=polygon_primitive[n].point.y-offset.y; | 
 | 5911 |         box_q[3].x=polygon_primitive[i].point.x-offset.x; | 
 | 5912 |         box_q[3].y=polygon_primitive[i].point.y-offset.y; | 
 | 5913 |       } | 
 | 5914 |     if (fabs((double) (slope.p-slope.q)) <= MagickEpsilon) | 
 | 5915 |       { | 
 | 5916 |         box_p[4]=box_p[1]; | 
 | 5917 |         box_q[4]=box_q[1]; | 
 | 5918 |       } | 
 | 5919 |     else | 
 | 5920 |       { | 
 | 5921 |         box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+ | 
 | 5922 |           box_p[3].y)/(slope.p-slope.q)); | 
 | 5923 |         box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y); | 
 | 5924 |         box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+ | 
 | 5925 |           box_q[3].y)/(slope.p-slope.q)); | 
 | 5926 |         box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y); | 
 | 5927 |       } | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5928 |     if (q >= (ssize_t) (max_strokes-6*BezierQuantum-360)) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5929 |       { | 
 | 5930 |          max_strokes+=6*BezierQuantum+360; | 
 | 5931 |          path_p=(PointInfo *) ResizeQuantumMemory(path_p,(size_t) max_strokes, | 
 | 5932 |            sizeof(*path_p)); | 
 | 5933 |          path_q=(PointInfo *) ResizeQuantumMemory(path_q,(size_t) max_strokes, | 
 | 5934 |            sizeof(*path_q)); | 
 | 5935 |          if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL)) | 
 | 5936 |            { | 
 | 5937 |              polygon_primitive=(PrimitiveInfo *) | 
 | 5938 |                RelinquishMagickMemory(polygon_primitive); | 
 | 5939 |              return((PrimitiveInfo *) NULL); | 
 | 5940 |            } | 
 | 5941 |       } | 
 | 5942 |     dot_product=dx.q*dy.p-dx.p*dy.q; | 
 | 5943 |     if (dot_product <= 0.0) | 
 | 5944 |       switch (draw_info->linejoin) | 
 | 5945 |       { | 
 | 5946 |         case BevelJoin: | 
 | 5947 |         { | 
 | 5948 |           path_q[q++]=box_q[1]; | 
 | 5949 |           path_q[q++]=box_q[2]; | 
 | 5950 |           dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ | 
 | 5951 |             (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); | 
 | 5952 |           if (dot_product <= miterlimit) | 
 | 5953 |             path_p[p++]=box_p[4]; | 
 | 5954 |           else | 
 | 5955 |             { | 
 | 5956 |               path_p[p++]=box_p[1]; | 
 | 5957 |               path_p[p++]=box_p[2]; | 
 | 5958 |             } | 
 | 5959 |           break; | 
 | 5960 |         } | 
 | 5961 |         case MiterJoin: | 
 | 5962 |         { | 
 | 5963 |           dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ | 
 | 5964 |             (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); | 
 | 5965 |           if (dot_product <= miterlimit) | 
 | 5966 |             { | 
 | 5967 |               path_q[q++]=box_q[4]; | 
 | 5968 |               path_p[p++]=box_p[4]; | 
 | 5969 |             } | 
 | 5970 |           else | 
 | 5971 |             { | 
 | 5972 |               path_q[q++]=box_q[1]; | 
 | 5973 |               path_q[q++]=box_q[2]; | 
 | 5974 |               path_p[p++]=box_p[1]; | 
 | 5975 |               path_p[p++]=box_p[2]; | 
 | 5976 |             } | 
 | 5977 |           break; | 
 | 5978 |         } | 
 | 5979 |         case RoundJoin: | 
 | 5980 |         { | 
 | 5981 |           dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ | 
 | 5982 |             (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); | 
 | 5983 |           if (dot_product <= miterlimit) | 
 | 5984 |             path_p[p++]=box_p[4]; | 
 | 5985 |           else | 
 | 5986 |             { | 
 | 5987 |               path_p[p++]=box_p[1]; | 
 | 5988 |               path_p[p++]=box_p[2]; | 
 | 5989 |             } | 
 | 5990 |           center=polygon_primitive[n].point; | 
 | 5991 |           theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x); | 
 | 5992 |           theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x); | 
 | 5993 |           if (theta.q < theta.p) | 
 | 5994 |             theta.q+=(MagickRealType) (2.0*MagickPI); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5995 |           arc_segments=(size_t) ceil((double) ((theta.q-theta.p)/ | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5996 |             (2.0*sqrt((double) (1.0/mid))))); | 
 | 5997 |           path_q[q].x=box_q[1].x; | 
 | 5998 |           path_q[q].y=box_q[1].y; | 
 | 5999 |           q++; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6000 |           for (j=1; j < (ssize_t) arc_segments; j++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6001 |           { | 
 | 6002 |             delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments); | 
 | 6003 |             path_q[q].x=(double) (center.x+mid*cos(fmod((double) | 
 | 6004 |               (theta.p+delta_theta),DegreesToRadians(360.0)))); | 
 | 6005 |             path_q[q].y=(double) (center.y+mid*sin(fmod((double) | 
 | 6006 |               (theta.p+delta_theta),DegreesToRadians(360.0)))); | 
 | 6007 |             q++; | 
 | 6008 |           } | 
 | 6009 |           path_q[q++]=box_q[2]; | 
 | 6010 |           break; | 
 | 6011 |         } | 
 | 6012 |         default: | 
 | 6013 |           break; | 
 | 6014 |       } | 
 | 6015 |     else | 
 | 6016 |       switch (draw_info->linejoin) | 
 | 6017 |       { | 
 | 6018 |         case BevelJoin: | 
 | 6019 |         { | 
 | 6020 |           path_p[p++]=box_p[1]; | 
 | 6021 |           path_p[p++]=box_p[2]; | 
 | 6022 |           dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ | 
 | 6023 |             (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); | 
 | 6024 |           if (dot_product <= miterlimit) | 
 | 6025 |             path_q[q++]=box_q[4]; | 
 | 6026 |           else | 
 | 6027 |             { | 
 | 6028 |               path_q[q++]=box_q[1]; | 
 | 6029 |               path_q[q++]=box_q[2]; | 
 | 6030 |             } | 
 | 6031 |           break; | 
 | 6032 |         } | 
 | 6033 |         case MiterJoin: | 
 | 6034 |         { | 
 | 6035 |           dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ | 
 | 6036 |             (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); | 
 | 6037 |           if (dot_product <= miterlimit) | 
 | 6038 |             { | 
 | 6039 |               path_q[q++]=box_q[4]; | 
 | 6040 |               path_p[p++]=box_p[4]; | 
 | 6041 |             } | 
 | 6042 |           else | 
 | 6043 |             { | 
 | 6044 |               path_q[q++]=box_q[1]; | 
 | 6045 |               path_q[q++]=box_q[2]; | 
 | 6046 |               path_p[p++]=box_p[1]; | 
 | 6047 |               path_p[p++]=box_p[2]; | 
 | 6048 |             } | 
 | 6049 |           break; | 
 | 6050 |         } | 
 | 6051 |         case RoundJoin: | 
 | 6052 |         { | 
 | 6053 |           dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ | 
 | 6054 |             (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); | 
 | 6055 |           if (dot_product <= miterlimit) | 
 | 6056 |             path_q[q++]=box_q[4]; | 
 | 6057 |           else | 
 | 6058 |             { | 
 | 6059 |               path_q[q++]=box_q[1]; | 
 | 6060 |               path_q[q++]=box_q[2]; | 
 | 6061 |             } | 
 | 6062 |           center=polygon_primitive[n].point; | 
 | 6063 |           theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x); | 
 | 6064 |           theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x); | 
 | 6065 |           if (theta.p < theta.q) | 
 | 6066 |             theta.p+=(MagickRealType) (2.0*MagickPI); | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6067 |           arc_segments=(size_t) ceil((double) ((theta.p-theta.q)/ | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6068 |             (2.0*sqrt((double) (1.0/mid))))); | 
 | 6069 |           path_p[p++]=box_p[1]; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6070 |           for (j=1; j < (ssize_t) arc_segments; j++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6071 |           { | 
 | 6072 |             delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments); | 
 | 6073 |             path_p[p].x=(double) (center.x+mid*cos(fmod((double) | 
 | 6074 |               (theta.p+delta_theta),DegreesToRadians(360.0)))); | 
 | 6075 |             path_p[p].y=(double) (center.y+mid*sin(fmod((double) | 
 | 6076 |               (theta.p+delta_theta),DegreesToRadians(360.0)))); | 
 | 6077 |             p++; | 
 | 6078 |           } | 
 | 6079 |           path_p[p++]=box_p[2]; | 
 | 6080 |           break; | 
 | 6081 |         } | 
 | 6082 |         default: | 
 | 6083 |           break; | 
 | 6084 |       } | 
 | 6085 |     slope.p=slope.q; | 
 | 6086 |     inverse_slope.p=inverse_slope.q; | 
 | 6087 |     box_p[0]=box_p[2]; | 
 | 6088 |     box_p[1]=box_p[3]; | 
 | 6089 |     box_q[0]=box_q[2]; | 
 | 6090 |     box_q[1]=box_q[3]; | 
 | 6091 |     dx.p=dx.q; | 
 | 6092 |     dy.p=dy.q; | 
 | 6093 |     n=i; | 
 | 6094 |   } | 
 | 6095 |   path_p[p++]=box_p[1]; | 
 | 6096 |   path_q[q++]=box_q[1]; | 
 | 6097 |   /* | 
 | 6098 |     Trace stroked polygon. | 
 | 6099 |   */ | 
 | 6100 |   stroke_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t) | 
 | 6101 |     (p+q+2UL*closed_path+2UL),sizeof(*stroke_polygon)); | 
 | 6102 |   if (stroke_polygon != (PrimitiveInfo *) NULL) | 
 | 6103 |     { | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6104 |       for (i=0; i < (ssize_t) p; i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6105 |       { | 
 | 6106 |         stroke_polygon[i]=polygon_primitive[0]; | 
 | 6107 |         stroke_polygon[i].point=path_p[i]; | 
 | 6108 |       } | 
 | 6109 |       if (closed_path != MagickFalse) | 
 | 6110 |         { | 
 | 6111 |           stroke_polygon[i]=polygon_primitive[0]; | 
 | 6112 |           stroke_polygon[i].point=stroke_polygon[0].point; | 
 | 6113 |           i++; | 
 | 6114 |         } | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6115 |       for ( ; i < (ssize_t) (p+q+closed_path); i++) | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6116 |       { | 
 | 6117 |         stroke_polygon[i]=polygon_primitive[0]; | 
 | 6118 |         stroke_polygon[i].point=path_q[p+q+closed_path-(i+1)]; | 
 | 6119 |       } | 
 | 6120 |       if (closed_path != MagickFalse) | 
 | 6121 |         { | 
 | 6122 |           stroke_polygon[i]=polygon_primitive[0]; | 
 | 6123 |           stroke_polygon[i].point=stroke_polygon[p+closed_path].point; | 
 | 6124 |           i++; | 
 | 6125 |         } | 
 | 6126 |       stroke_polygon[i]=polygon_primitive[0]; | 
 | 6127 |       stroke_polygon[i].point=stroke_polygon[0].point; | 
 | 6128 |       i++; | 
 | 6129 |       stroke_polygon[i].primitive=UndefinedPrimitive; | 
| cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6130 |       stroke_polygon[0].coordinates=(size_t) (p+q+2*closed_path+1); | 
| cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6131 |     } | 
 | 6132 |   path_p=(PointInfo *) RelinquishMagickMemory(path_p); | 
 | 6133 |   path_q=(PointInfo *) RelinquishMagickMemory(path_q); | 
 | 6134 |   polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive); | 
 | 6135 |   return(stroke_polygon); | 
 | 6136 | } |