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