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 |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 156 | DrawStrokePolygon(Image *,const DrawInfo *,const PrimitiveInfo *, |
| 157 | ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 158 | |
| 159 | static PrimitiveInfo |
| 160 | *TraceStrokePolygon(const DrawInfo *,const PrimitiveInfo *); |
| 161 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 162 | static size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 163 | TracePath(PrimitiveInfo *,const char *); |
| 164 | |
| 165 | static void |
| 166 | TraceArc(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo), |
| 167 | TraceArcPath(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo, |
| 168 | const MagickRealType,const MagickBooleanType,const MagickBooleanType), |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 169 | TraceBezier(PrimitiveInfo *,const size_t), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 170 | TraceCircle(PrimitiveInfo *,const PointInfo,const PointInfo), |
| 171 | TraceEllipse(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo), |
| 172 | TraceLine(PrimitiveInfo *,const PointInfo,const PointInfo), |
| 173 | TraceRectangle(PrimitiveInfo *,const PointInfo,const PointInfo), |
| 174 | TraceRoundRectangle(PrimitiveInfo *,const PointInfo,const PointInfo, |
| 175 | PointInfo), |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 176 | TraceSquareLinecap(PrimitiveInfo *,const size_t,const MagickRealType); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 177 | |
| 178 | /* |
| 179 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 180 | % % |
| 181 | % % |
| 182 | % % |
| 183 | % A c q u i r e D r a w I n f o % |
| 184 | % % |
| 185 | % % |
| 186 | % % |
| 187 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 188 | % |
| 189 | % AcquireDrawInfo() returns a DrawInfo structure properly initialized. |
| 190 | % |
| 191 | % The format of the AcquireDrawInfo method is: |
| 192 | % |
| 193 | % DrawInfo *AcquireDrawInfo(void) |
| 194 | % |
| 195 | */ |
| 196 | MagickExport DrawInfo *AcquireDrawInfo(void) |
| 197 | { |
| 198 | DrawInfo |
| 199 | *draw_info; |
| 200 | |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 201 | draw_info=(DrawInfo *) AcquireMagickMemory(sizeof(*draw_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 202 | if (draw_info == (DrawInfo *) NULL) |
| 203 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 204 | GetDrawInfo((ImageInfo *) NULL,draw_info); |
| 205 | return(draw_info); |
| 206 | } |
| 207 | |
| 208 | /* |
| 209 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 210 | % % |
| 211 | % % |
| 212 | % % |
| 213 | % C l o n e D r a w I n f o % |
| 214 | % % |
| 215 | % % |
| 216 | % % |
| 217 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 218 | % |
anthony | 36fe175 | 2011-09-29 11:28:37 +0000 | [diff] [blame] | 219 | % CloneDrawInfo() makes a copy of the given draw_info structure. If NULL |
| 220 | % is specified, a new draw_info structure is created initialized to |
| 221 | % default values, according to the given image_info. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 222 | % |
| 223 | % The format of the CloneDrawInfo method is: |
| 224 | % |
| 225 | % DrawInfo *CloneDrawInfo(const ImageInfo *image_info, |
| 226 | % const DrawInfo *draw_info) |
| 227 | % |
| 228 | % A description of each parameter follows: |
| 229 | % |
| 230 | % o image_info: the image info. |
| 231 | % |
| 232 | % o draw_info: the draw info. |
| 233 | % |
| 234 | */ |
| 235 | MagickExport DrawInfo *CloneDrawInfo(const ImageInfo *image_info, |
| 236 | const DrawInfo *draw_info) |
| 237 | { |
| 238 | DrawInfo |
| 239 | *clone_info; |
| 240 | |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 241 | ExceptionInfo |
| 242 | *exception; |
| 243 | |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 244 | clone_info=(DrawInfo *) AcquireMagickMemory(sizeof(*clone_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 245 | if (clone_info == (DrawInfo *) NULL) |
| 246 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 247 | GetDrawInfo(image_info,clone_info); |
| 248 | if (draw_info == (DrawInfo *) NULL) |
| 249 | return(clone_info); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 250 | exception=AcquireExceptionInfo(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 251 | if (clone_info->primitive != (char *) NULL) |
| 252 | (void) CloneString(&clone_info->primitive,draw_info->primitive); |
| 253 | if (draw_info->geometry != (char *) NULL) |
| 254 | (void) CloneString(&clone_info->geometry,draw_info->geometry); |
| 255 | clone_info->viewbox=draw_info->viewbox; |
| 256 | clone_info->affine=draw_info->affine; |
| 257 | clone_info->gravity=draw_info->gravity; |
| 258 | clone_info->fill=draw_info->fill; |
| 259 | clone_info->stroke=draw_info->stroke; |
| 260 | clone_info->stroke_width=draw_info->stroke_width; |
| 261 | if (draw_info->fill_pattern != (Image *) NULL) |
| 262 | clone_info->fill_pattern=CloneImage(draw_info->fill_pattern,0,0,MagickTrue, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 263 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 264 | if (draw_info->stroke_pattern != (Image *) NULL) |
| 265 | clone_info->stroke_pattern=CloneImage(draw_info->stroke_pattern,0,0, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 266 | MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 267 | clone_info->stroke_antialias=draw_info->stroke_antialias; |
| 268 | clone_info->text_antialias=draw_info->text_antialias; |
| 269 | clone_info->fill_rule=draw_info->fill_rule; |
| 270 | clone_info->linecap=draw_info->linecap; |
| 271 | clone_info->linejoin=draw_info->linejoin; |
| 272 | clone_info->miterlimit=draw_info->miterlimit; |
| 273 | clone_info->dash_offset=draw_info->dash_offset; |
| 274 | clone_info->decorate=draw_info->decorate; |
| 275 | clone_info->compose=draw_info->compose; |
| 276 | if (draw_info->text != (char *) NULL) |
| 277 | (void) CloneString(&clone_info->text,draw_info->text); |
| 278 | if (draw_info->font != (char *) NULL) |
| 279 | (void) CloneString(&clone_info->font,draw_info->font); |
| 280 | if (draw_info->metrics != (char *) NULL) |
| 281 | (void) CloneString(&clone_info->metrics,draw_info->metrics); |
| 282 | if (draw_info->family != (char *) NULL) |
| 283 | (void) CloneString(&clone_info->family,draw_info->family); |
| 284 | clone_info->style=draw_info->style; |
| 285 | clone_info->stretch=draw_info->stretch; |
| 286 | clone_info->weight=draw_info->weight; |
| 287 | if (draw_info->encoding != (char *) NULL) |
| 288 | (void) CloneString(&clone_info->encoding,draw_info->encoding); |
| 289 | clone_info->pointsize=draw_info->pointsize; |
| 290 | clone_info->kerning=draw_info->kerning; |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 291 | clone_info->interline_spacing=draw_info->interline_spacing; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 292 | clone_info->interword_spacing=draw_info->interword_spacing; |
cristy | c9b1295 | 2010-03-28 01:12:28 +0000 | [diff] [blame] | 293 | clone_info->direction=draw_info->direction; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 294 | if (draw_info->density != (char *) NULL) |
| 295 | (void) CloneString(&clone_info->density,draw_info->density); |
| 296 | clone_info->align=draw_info->align; |
| 297 | clone_info->undercolor=draw_info->undercolor; |
| 298 | clone_info->border_color=draw_info->border_color; |
| 299 | if (draw_info->server_name != (char *) NULL) |
| 300 | (void) CloneString(&clone_info->server_name,draw_info->server_name); |
| 301 | if (draw_info->dash_pattern != (double *) NULL) |
| 302 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 303 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 304 | x; |
| 305 | |
| 306 | for (x=0; draw_info->dash_pattern[x] != 0.0; x++) ; |
| 307 | clone_info->dash_pattern=(double *) AcquireQuantumMemory((size_t) x+1UL, |
| 308 | sizeof(*clone_info->dash_pattern)); |
| 309 | if (clone_info->dash_pattern == (double *) NULL) |
| 310 | ThrowFatalException(ResourceLimitFatalError, |
| 311 | "UnableToAllocateDashPattern"); |
| 312 | (void) CopyMagickMemory(clone_info->dash_pattern,draw_info->dash_pattern, |
| 313 | (size_t) (x+1)*sizeof(*clone_info->dash_pattern)); |
| 314 | } |
| 315 | clone_info->gradient=draw_info->gradient; |
| 316 | if (draw_info->gradient.stops != (StopInfo *) NULL) |
| 317 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 318 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 319 | number_stops; |
| 320 | |
| 321 | number_stops=clone_info->gradient.number_stops; |
| 322 | clone_info->gradient.stops=(StopInfo *) AcquireQuantumMemory((size_t) |
| 323 | number_stops,sizeof(*clone_info->gradient.stops)); |
| 324 | if (clone_info->gradient.stops == (StopInfo *) NULL) |
| 325 | ThrowFatalException(ResourceLimitFatalError, |
| 326 | "UnableToAllocateDashPattern"); |
| 327 | (void) CopyMagickMemory(clone_info->gradient.stops, |
| 328 | draw_info->gradient.stops,(size_t) number_stops* |
| 329 | sizeof(*clone_info->gradient.stops)); |
| 330 | } |
| 331 | if (draw_info->clip_mask != (char *) NULL) |
| 332 | (void) CloneString(&clone_info->clip_mask,draw_info->clip_mask); |
| 333 | clone_info->bounds=draw_info->bounds; |
| 334 | clone_info->clip_units=draw_info->clip_units; |
| 335 | clone_info->render=draw_info->render; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 336 | clone_info->alpha=draw_info->alpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 337 | clone_info->element_reference=draw_info->element_reference; |
| 338 | clone_info->debug=IsEventLogging(); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 339 | exception=DestroyExceptionInfo(exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 340 | return(clone_info); |
| 341 | } |
| 342 | |
| 343 | /* |
| 344 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 345 | % % |
| 346 | % % |
| 347 | % % |
| 348 | + C o n v e r t P a t h T o P o l y g o n % |
| 349 | % % |
| 350 | % % |
| 351 | % % |
| 352 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 353 | % |
| 354 | % ConvertPathToPolygon() converts a path to the more efficient sorted |
| 355 | % rendering form. |
| 356 | % |
| 357 | % The format of the ConvertPathToPolygon method is: |
| 358 | % |
| 359 | % PolygonInfo *ConvertPathToPolygon(const DrawInfo *draw_info, |
| 360 | % const PathInfo *path_info) |
| 361 | % |
| 362 | % A description of each parameter follows: |
| 363 | % |
| 364 | % o Method ConvertPathToPolygon returns the path in a more efficient sorted |
| 365 | % rendering form of type PolygonInfo. |
| 366 | % |
| 367 | % o draw_info: Specifies a pointer to an DrawInfo structure. |
| 368 | % |
| 369 | % o path_info: Specifies a pointer to an PathInfo structure. |
| 370 | % |
| 371 | % |
| 372 | */ |
| 373 | |
| 374 | #if defined(__cplusplus) || defined(c_plusplus) |
| 375 | extern "C" { |
| 376 | #endif |
| 377 | |
| 378 | static int CompareEdges(const void *x,const void *y) |
| 379 | { |
| 380 | register const EdgeInfo |
| 381 | *p, |
| 382 | *q; |
| 383 | |
| 384 | /* |
| 385 | Compare two edges. |
| 386 | */ |
| 387 | p=(const EdgeInfo *) x; |
| 388 | q=(const EdgeInfo *) y; |
| 389 | if ((p->points[0].y-MagickEpsilon) > q->points[0].y) |
| 390 | return(1); |
| 391 | if ((p->points[0].y+MagickEpsilon) < q->points[0].y) |
| 392 | return(-1); |
| 393 | if ((p->points[0].x-MagickEpsilon) > q->points[0].x) |
| 394 | return(1); |
| 395 | if ((p->points[0].x+MagickEpsilon) < q->points[0].x) |
| 396 | return(-1); |
| 397 | if (((p->points[1].x-p->points[0].x)*(q->points[1].y-q->points[0].y)- |
| 398 | (p->points[1].y-p->points[0].y)*(q->points[1].x-q->points[0].x)) > 0.0) |
| 399 | return(1); |
| 400 | return(-1); |
| 401 | } |
| 402 | |
| 403 | #if defined(__cplusplus) || defined(c_plusplus) |
| 404 | } |
| 405 | #endif |
| 406 | |
| 407 | static void LogPolygonInfo(const PolygonInfo *polygon_info) |
| 408 | { |
| 409 | register EdgeInfo |
| 410 | *p; |
| 411 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 412 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 413 | i, |
| 414 | j; |
| 415 | |
| 416 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin active-edge"); |
| 417 | p=polygon_info->edges; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 418 | for (i=0; i < (ssize_t) polygon_info->number_edges; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 419 | { |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 420 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," edge %.20g:", |
| 421 | (double) i); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 422 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," direction: %s", |
| 423 | p->direction != MagickFalse ? "down" : "up"); |
| 424 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," ghostline: %s", |
| 425 | p->ghostline != MagickFalse ? "transparent" : "opaque"); |
| 426 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | 14388de | 2011-05-15 14:57:16 +0000 | [diff] [blame] | 427 | " bounds: %g %g - %g %g",p->bounds.x1,p->bounds.y1, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 428 | p->bounds.x2,p->bounds.y2); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 429 | for (j=0; j < (ssize_t) p->number_points; j++) |
cristy | 14388de | 2011-05-15 14:57:16 +0000 | [diff] [blame] | 430 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," %g %g", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 431 | p->points[j].x,p->points[j].y); |
| 432 | p++; |
| 433 | } |
| 434 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end active-edge"); |
| 435 | } |
| 436 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 437 | static void ReversePoints(PointInfo *points,const size_t number_points) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 438 | { |
| 439 | PointInfo |
| 440 | point; |
| 441 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 442 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 443 | i; |
| 444 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 445 | for (i=0; i < (ssize_t) (number_points >> 1); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 446 | { |
| 447 | point=points[i]; |
| 448 | points[i]=points[number_points-(i+1)]; |
| 449 | points[number_points-(i+1)]=point; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | static PolygonInfo *ConvertPathToPolygon( |
| 454 | const DrawInfo *magick_unused(draw_info),const PathInfo *path_info) |
| 455 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 456 | long |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 457 | direction, |
| 458 | next_direction; |
| 459 | |
| 460 | PointInfo |
| 461 | point, |
| 462 | *points; |
| 463 | |
| 464 | PolygonInfo |
| 465 | *polygon_info; |
| 466 | |
| 467 | SegmentInfo |
| 468 | bounds; |
| 469 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 470 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 471 | i, |
| 472 | n; |
| 473 | |
| 474 | MagickBooleanType |
| 475 | ghostline; |
| 476 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 477 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 478 | edge, |
| 479 | number_edges, |
| 480 | number_points; |
| 481 | |
| 482 | /* |
| 483 | Convert a path to the more efficient sorted rendering form. |
| 484 | */ |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 485 | polygon_info=(PolygonInfo *) AcquireMagickMemory(sizeof(*polygon_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 486 | if (polygon_info == (PolygonInfo *) NULL) |
| 487 | return((PolygonInfo *) NULL); |
| 488 | number_edges=16; |
| 489 | polygon_info->edges=(EdgeInfo *) AcquireQuantumMemory((size_t) number_edges, |
| 490 | sizeof(*polygon_info->edges)); |
| 491 | if (polygon_info->edges == (EdgeInfo *) NULL) |
| 492 | return((PolygonInfo *) NULL); |
| 493 | direction=0; |
| 494 | edge=0; |
| 495 | ghostline=MagickFalse; |
| 496 | n=0; |
| 497 | number_points=0; |
| 498 | points=(PointInfo *) NULL; |
| 499 | (void) ResetMagickMemory(&point,0,sizeof(point)); |
| 500 | (void) ResetMagickMemory(&bounds,0,sizeof(bounds)); |
| 501 | for (i=0; path_info[i].code != EndCode; i++) |
| 502 | { |
| 503 | if ((path_info[i].code == MoveToCode) || (path_info[i].code == OpenCode) || |
| 504 | (path_info[i].code == GhostlineCode)) |
| 505 | { |
| 506 | /* |
| 507 | Move to. |
| 508 | */ |
| 509 | if ((points != (PointInfo *) NULL) && (n >= 2)) |
| 510 | { |
| 511 | if (edge == number_edges) |
| 512 | { |
| 513 | number_edges<<=1; |
| 514 | polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory( |
| 515 | polygon_info->edges,(size_t) number_edges, |
| 516 | sizeof(*polygon_info->edges)); |
| 517 | if (polygon_info->edges == (EdgeInfo *) NULL) |
| 518 | return((PolygonInfo *) NULL); |
| 519 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 520 | polygon_info->edges[edge].number_points=(size_t) n; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 521 | polygon_info->edges[edge].scanline=(-1.0); |
| 522 | polygon_info->edges[edge].highwater=0; |
| 523 | polygon_info->edges[edge].ghostline=ghostline; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 524 | polygon_info->edges[edge].direction=(ssize_t) (direction > 0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 525 | if (direction < 0) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 526 | ReversePoints(points,(size_t) n); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 527 | polygon_info->edges[edge].points=points; |
| 528 | polygon_info->edges[edge].bounds=bounds; |
| 529 | polygon_info->edges[edge].bounds.y1=points[0].y; |
| 530 | polygon_info->edges[edge].bounds.y2=points[n-1].y; |
| 531 | points=(PointInfo *) NULL; |
| 532 | ghostline=MagickFalse; |
| 533 | edge++; |
| 534 | } |
| 535 | if (points == (PointInfo *) NULL) |
| 536 | { |
| 537 | number_points=16; |
| 538 | points=(PointInfo *) AcquireQuantumMemory((size_t) number_points, |
| 539 | sizeof(*points)); |
| 540 | if (points == (PointInfo *) NULL) |
| 541 | return((PolygonInfo *) NULL); |
| 542 | } |
| 543 | ghostline=path_info[i].code == GhostlineCode ? MagickTrue : MagickFalse; |
| 544 | point=path_info[i].point; |
| 545 | points[0]=point; |
| 546 | bounds.x1=point.x; |
| 547 | bounds.x2=point.x; |
| 548 | direction=0; |
| 549 | n=1; |
| 550 | continue; |
| 551 | } |
| 552 | /* |
| 553 | Line to. |
| 554 | */ |
| 555 | next_direction=((path_info[i].point.y > point.y) || |
| 556 | ((path_info[i].point.y == point.y) && |
| 557 | (path_info[i].point.x > point.x))) ? 1 : -1; |
| 558 | if ((direction != 0) && (direction != next_direction)) |
| 559 | { |
| 560 | /* |
| 561 | New edge. |
| 562 | */ |
| 563 | point=points[n-1]; |
| 564 | if (edge == number_edges) |
| 565 | { |
| 566 | number_edges<<=1; |
| 567 | polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory( |
| 568 | polygon_info->edges,(size_t) number_edges, |
| 569 | sizeof(*polygon_info->edges)); |
| 570 | if (polygon_info->edges == (EdgeInfo *) NULL) |
| 571 | return((PolygonInfo *) NULL); |
| 572 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 573 | polygon_info->edges[edge].number_points=(size_t) n; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 574 | polygon_info->edges[edge].scanline=(-1.0); |
| 575 | polygon_info->edges[edge].highwater=0; |
| 576 | polygon_info->edges[edge].ghostline=ghostline; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 577 | polygon_info->edges[edge].direction=(ssize_t) (direction > 0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 578 | if (direction < 0) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 579 | ReversePoints(points,(size_t) n); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 580 | polygon_info->edges[edge].points=points; |
| 581 | polygon_info->edges[edge].bounds=bounds; |
| 582 | polygon_info->edges[edge].bounds.y1=points[0].y; |
| 583 | polygon_info->edges[edge].bounds.y2=points[n-1].y; |
| 584 | number_points=16; |
| 585 | points=(PointInfo *) AcquireQuantumMemory((size_t) number_points, |
| 586 | sizeof(*points)); |
| 587 | if (points == (PointInfo *) NULL) |
| 588 | return((PolygonInfo *) NULL); |
| 589 | n=1; |
| 590 | ghostline=MagickFalse; |
| 591 | points[0]=point; |
| 592 | bounds.x1=point.x; |
| 593 | bounds.x2=point.x; |
| 594 | edge++; |
| 595 | } |
| 596 | direction=next_direction; |
| 597 | if (points == (PointInfo *) NULL) |
| 598 | continue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 599 | if (n == (ssize_t) number_points) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 600 | { |
| 601 | number_points<<=1; |
| 602 | points=(PointInfo *) ResizeQuantumMemory(points,(size_t) number_points, |
| 603 | sizeof(*points)); |
| 604 | if (points == (PointInfo *) NULL) |
| 605 | return((PolygonInfo *) NULL); |
| 606 | } |
| 607 | point=path_info[i].point; |
| 608 | points[n]=point; |
| 609 | if (point.x < bounds.x1) |
| 610 | bounds.x1=point.x; |
| 611 | if (point.x > bounds.x2) |
| 612 | bounds.x2=point.x; |
| 613 | n++; |
| 614 | } |
| 615 | if (points != (PointInfo *) NULL) |
| 616 | { |
| 617 | if (n < 2) |
| 618 | points=(PointInfo *) RelinquishMagickMemory(points); |
| 619 | else |
| 620 | { |
| 621 | if (edge == number_edges) |
| 622 | { |
| 623 | number_edges<<=1; |
| 624 | polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory( |
| 625 | polygon_info->edges,(size_t) number_edges, |
| 626 | sizeof(*polygon_info->edges)); |
| 627 | if (polygon_info->edges == (EdgeInfo *) NULL) |
| 628 | return((PolygonInfo *) NULL); |
| 629 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 630 | polygon_info->edges[edge].number_points=(size_t) n; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 631 | polygon_info->edges[edge].scanline=(-1.0); |
| 632 | polygon_info->edges[edge].highwater=0; |
| 633 | polygon_info->edges[edge].ghostline=ghostline; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 634 | polygon_info->edges[edge].direction=(ssize_t) (direction > 0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 635 | if (direction < 0) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 636 | ReversePoints(points,(size_t) n); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 637 | polygon_info->edges[edge].points=points; |
| 638 | polygon_info->edges[edge].bounds=bounds; |
| 639 | polygon_info->edges[edge].bounds.y1=points[0].y; |
| 640 | polygon_info->edges[edge].bounds.y2=points[n-1].y; |
| 641 | ghostline=MagickFalse; |
| 642 | edge++; |
| 643 | } |
| 644 | } |
| 645 | polygon_info->number_edges=edge; |
| 646 | qsort(polygon_info->edges,(size_t) polygon_info->number_edges, |
| 647 | sizeof(*polygon_info->edges),CompareEdges); |
| 648 | if (IsEventLogging() != MagickFalse) |
| 649 | LogPolygonInfo(polygon_info); |
| 650 | return(polygon_info); |
| 651 | } |
| 652 | |
| 653 | /* |
| 654 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 655 | % % |
| 656 | % % |
| 657 | % % |
| 658 | + C o n v e r t P r i m i t i v e T o P a t h % |
| 659 | % % |
| 660 | % % |
| 661 | % % |
| 662 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 663 | % |
| 664 | % ConvertPrimitiveToPath() converts a PrimitiveInfo structure into a vector |
| 665 | % path structure. |
| 666 | % |
| 667 | % The format of the ConvertPrimitiveToPath method is: |
| 668 | % |
| 669 | % PathInfo *ConvertPrimitiveToPath(const DrawInfo *draw_info, |
| 670 | % const PrimitiveInfo *primitive_info) |
| 671 | % |
| 672 | % A description of each parameter follows: |
| 673 | % |
| 674 | % o Method ConvertPrimitiveToPath returns a vector path structure of type |
| 675 | % PathInfo. |
| 676 | % |
| 677 | % o draw_info: a structure of type DrawInfo. |
| 678 | % |
| 679 | % o primitive_info: Specifies a pointer to an PrimitiveInfo structure. |
| 680 | % |
| 681 | % |
| 682 | */ |
| 683 | |
| 684 | static void LogPathInfo(const PathInfo *path_info) |
| 685 | { |
| 686 | register const PathInfo |
| 687 | *p; |
| 688 | |
| 689 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin vector-path"); |
| 690 | for (p=path_info; p->code != EndCode; p++) |
| 691 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | 14388de | 2011-05-15 14:57:16 +0000 | [diff] [blame] | 692 | " %g %g %s",p->point.x,p->point.y,p->code == GhostlineCode ? |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 693 | "moveto ghostline" : p->code == OpenCode ? "moveto open" : |
| 694 | p->code == MoveToCode ? "moveto" : p->code == LineToCode ? "lineto" : |
| 695 | "?"); |
| 696 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end vector-path"); |
| 697 | } |
| 698 | |
| 699 | static PathInfo *ConvertPrimitiveToPath( |
| 700 | const DrawInfo *magick_unused(draw_info),const PrimitiveInfo *primitive_info) |
| 701 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 702 | PathInfo |
| 703 | *path_info; |
| 704 | |
| 705 | PathInfoCode |
| 706 | code; |
| 707 | |
| 708 | PointInfo |
| 709 | p, |
| 710 | q; |
| 711 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 712 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 713 | i, |
| 714 | n; |
| 715 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 716 | ssize_t |
| 717 | coordinates, |
| 718 | start; |
| 719 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 720 | /* |
| 721 | Converts a PrimitiveInfo structure into a vector path structure. |
| 722 | */ |
| 723 | switch (primitive_info->primitive) |
| 724 | { |
| 725 | case PointPrimitive: |
| 726 | case ColorPrimitive: |
| 727 | case MattePrimitive: |
| 728 | case TextPrimitive: |
| 729 | case ImagePrimitive: |
| 730 | return((PathInfo *) NULL); |
| 731 | default: |
| 732 | break; |
| 733 | } |
| 734 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ; |
| 735 | path_info=(PathInfo *) AcquireQuantumMemory((size_t) (2UL*i+3UL), |
| 736 | sizeof(*path_info)); |
| 737 | if (path_info == (PathInfo *) NULL) |
| 738 | return((PathInfo *) NULL); |
| 739 | coordinates=0; |
| 740 | n=0; |
| 741 | p.x=(-1.0); |
| 742 | p.y=(-1.0); |
| 743 | q.x=(-1.0); |
| 744 | q.y=(-1.0); |
| 745 | start=0; |
| 746 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) |
| 747 | { |
| 748 | code=LineToCode; |
| 749 | if (coordinates <= 0) |
| 750 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 751 | coordinates=(ssize_t) primitive_info[i].coordinates; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 752 | p=primitive_info[i].point; |
| 753 | start=n; |
| 754 | code=MoveToCode; |
| 755 | } |
| 756 | coordinates--; |
| 757 | /* |
| 758 | Eliminate duplicate points. |
| 759 | */ |
| 760 | if ((i == 0) || (fabs(q.x-primitive_info[i].point.x) > MagickEpsilon) || |
| 761 | (fabs(q.y-primitive_info[i].point.y) > MagickEpsilon)) |
| 762 | { |
| 763 | path_info[n].code=code; |
| 764 | path_info[n].point=primitive_info[i].point; |
| 765 | q=primitive_info[i].point; |
| 766 | n++; |
| 767 | } |
| 768 | if (coordinates > 0) |
| 769 | continue; |
| 770 | if ((fabs(p.x-primitive_info[i].point.x) <= MagickEpsilon) && |
| 771 | (fabs(p.y-primitive_info[i].point.y) <= MagickEpsilon)) |
| 772 | continue; |
| 773 | /* |
| 774 | Mark the p point as open if it does not match the q. |
| 775 | */ |
| 776 | path_info[start].code=OpenCode; |
| 777 | path_info[n].code=GhostlineCode; |
| 778 | path_info[n].point=primitive_info[i].point; |
| 779 | n++; |
| 780 | path_info[n].code=LineToCode; |
| 781 | path_info[n].point=p; |
| 782 | n++; |
| 783 | } |
| 784 | path_info[n].code=EndCode; |
| 785 | path_info[n].point.x=0.0; |
| 786 | path_info[n].point.y=0.0; |
| 787 | if (IsEventLogging() != MagickFalse) |
| 788 | LogPathInfo(path_info); |
| 789 | return(path_info); |
| 790 | } |
| 791 | |
| 792 | /* |
| 793 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 794 | % % |
| 795 | % % |
| 796 | % % |
| 797 | % D e s t r o y D r a w I n f o % |
| 798 | % % |
| 799 | % % |
| 800 | % % |
| 801 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 802 | % |
| 803 | % DestroyDrawInfo() deallocates memory associated with an DrawInfo |
| 804 | % structure. |
| 805 | % |
| 806 | % The format of the DestroyDrawInfo method is: |
| 807 | % |
| 808 | % DrawInfo *DestroyDrawInfo(DrawInfo *draw_info) |
| 809 | % |
| 810 | % A description of each parameter follows: |
| 811 | % |
| 812 | % o draw_info: the draw info. |
| 813 | % |
| 814 | */ |
| 815 | MagickExport DrawInfo *DestroyDrawInfo(DrawInfo *draw_info) |
| 816 | { |
| 817 | if (draw_info->debug != MagickFalse) |
| 818 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 819 | assert(draw_info != (DrawInfo *) NULL); |
| 820 | assert(draw_info->signature == MagickSignature); |
| 821 | if (draw_info->primitive != (char *) NULL) |
| 822 | draw_info->primitive=DestroyString(draw_info->primitive); |
| 823 | if (draw_info->text != (char *) NULL) |
| 824 | draw_info->text=DestroyString(draw_info->text); |
| 825 | if (draw_info->geometry != (char *) NULL) |
| 826 | draw_info->geometry=DestroyString(draw_info->geometry); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 827 | if (draw_info->fill_pattern != (Image *) NULL) |
| 828 | draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern); |
| 829 | if (draw_info->stroke_pattern != (Image *) NULL) |
| 830 | draw_info->stroke_pattern=DestroyImage(draw_info->stroke_pattern); |
| 831 | if (draw_info->font != (char *) NULL) |
| 832 | draw_info->font=DestroyString(draw_info->font); |
| 833 | if (draw_info->metrics != (char *) NULL) |
| 834 | draw_info->metrics=DestroyString(draw_info->metrics); |
| 835 | if (draw_info->family != (char *) NULL) |
| 836 | draw_info->family=DestroyString(draw_info->family); |
| 837 | if (draw_info->encoding != (char *) NULL) |
| 838 | draw_info->encoding=DestroyString(draw_info->encoding); |
| 839 | if (draw_info->density != (char *) NULL) |
| 840 | draw_info->density=DestroyString(draw_info->density); |
| 841 | if (draw_info->server_name != (char *) NULL) |
| 842 | draw_info->server_name=(char *) |
| 843 | RelinquishMagickMemory(draw_info->server_name); |
| 844 | if (draw_info->dash_pattern != (double *) NULL) |
| 845 | draw_info->dash_pattern=(double *) RelinquishMagickMemory( |
| 846 | draw_info->dash_pattern); |
| 847 | if (draw_info->gradient.stops != (StopInfo *) NULL) |
| 848 | draw_info->gradient.stops=(StopInfo *) RelinquishMagickMemory( |
| 849 | draw_info->gradient.stops); |
| 850 | if (draw_info->clip_mask != (char *) NULL) |
| 851 | draw_info->clip_mask=DestroyString(draw_info->clip_mask); |
| 852 | draw_info->signature=(~MagickSignature); |
| 853 | draw_info=(DrawInfo *) RelinquishMagickMemory(draw_info); |
| 854 | return(draw_info); |
| 855 | } |
| 856 | |
| 857 | /* |
| 858 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 859 | % % |
| 860 | % % |
| 861 | % % |
| 862 | + D e s t r o y E d g e % |
| 863 | % % |
| 864 | % % |
| 865 | % % |
| 866 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 867 | % |
| 868 | % DestroyEdge() destroys the specified polygon edge. |
| 869 | % |
| 870 | % The format of the DestroyEdge method is: |
| 871 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 872 | % ssize_t DestroyEdge(PolygonInfo *polygon_info,const int edge) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 873 | % |
| 874 | % A description of each parameter follows: |
| 875 | % |
| 876 | % o polygon_info: Specifies a pointer to an PolygonInfo structure. |
| 877 | % |
| 878 | % o edge: the polygon edge number to destroy. |
| 879 | % |
| 880 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 881 | static size_t DestroyEdge(PolygonInfo *polygon_info, |
| 882 | const size_t edge) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 883 | { |
| 884 | assert(edge < polygon_info->number_edges); |
| 885 | polygon_info->edges[edge].points=(PointInfo *) RelinquishMagickMemory( |
| 886 | polygon_info->edges[edge].points); |
| 887 | polygon_info->number_edges--; |
| 888 | if (edge < polygon_info->number_edges) |
| 889 | (void) CopyMagickMemory(polygon_info->edges+edge,polygon_info->edges+edge+1, |
| 890 | (size_t) (polygon_info->number_edges-edge)*sizeof(*polygon_info->edges)); |
| 891 | return(polygon_info->number_edges); |
| 892 | } |
| 893 | |
| 894 | /* |
| 895 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 896 | % % |
| 897 | % % |
| 898 | % % |
| 899 | + D e s t r o y P o l y g o n I n f o % |
| 900 | % % |
| 901 | % % |
| 902 | % % |
| 903 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 904 | % |
| 905 | % DestroyPolygonInfo() destroys the PolygonInfo data structure. |
| 906 | % |
| 907 | % The format of the DestroyPolygonInfo method is: |
| 908 | % |
| 909 | % PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info) |
| 910 | % |
| 911 | % A description of each parameter follows: |
| 912 | % |
| 913 | % o polygon_info: Specifies a pointer to an PolygonInfo structure. |
| 914 | % |
| 915 | */ |
| 916 | static PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info) |
| 917 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 918 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 919 | i; |
| 920 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 921 | for (i=0; i < (ssize_t) polygon_info->number_edges; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 922 | polygon_info->edges[i].points=(PointInfo *) |
| 923 | RelinquishMagickMemory(polygon_info->edges[i].points); |
| 924 | polygon_info->edges=(EdgeInfo *) RelinquishMagickMemory(polygon_info->edges); |
| 925 | return((PolygonInfo *) RelinquishMagickMemory(polygon_info)); |
| 926 | } |
| 927 | |
| 928 | /* |
| 929 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 930 | % % |
| 931 | % % |
| 932 | % % |
| 933 | % D r a w A f f i n e I m a g e % |
| 934 | % % |
| 935 | % % |
| 936 | % % |
| 937 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 938 | % |
| 939 | % DrawAffineImage() composites the source over the destination image as |
| 940 | % dictated by the affine transform. |
| 941 | % |
| 942 | % The format of the DrawAffineImage method is: |
| 943 | % |
| 944 | % MagickBooleanType DrawAffineImage(Image *image,const Image *source, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 945 | % const AffineMatrix *affine,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 946 | % |
| 947 | % A description of each parameter follows: |
| 948 | % |
| 949 | % o image: the image. |
| 950 | % |
| 951 | % o source: the source image. |
| 952 | % |
| 953 | % o affine: the affine transform. |
| 954 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 955 | % o exception: return any errors or warnings in this structure. |
| 956 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 957 | */ |
| 958 | static SegmentInfo AffineEdge(const Image *image,const AffineMatrix *affine, |
| 959 | const double y,const SegmentInfo *edge) |
| 960 | { |
| 961 | double |
| 962 | intercept, |
| 963 | z; |
| 964 | |
| 965 | register double |
| 966 | x; |
| 967 | |
| 968 | SegmentInfo |
| 969 | inverse_edge; |
| 970 | |
| 971 | /* |
| 972 | Determine left and right edges. |
| 973 | */ |
| 974 | inverse_edge.x1=edge->x1; |
| 975 | inverse_edge.y1=edge->y1; |
| 976 | inverse_edge.x2=edge->x2; |
| 977 | inverse_edge.y2=edge->y2; |
| 978 | z=affine->ry*y+affine->tx; |
| 979 | if (affine->sx > MagickEpsilon) |
| 980 | { |
| 981 | intercept=(-z/affine->sx); |
| 982 | x=intercept+MagickEpsilon; |
| 983 | if (x > inverse_edge.x1) |
| 984 | inverse_edge.x1=x; |
| 985 | intercept=(-z+(double) image->columns)/affine->sx; |
| 986 | x=intercept-MagickEpsilon; |
| 987 | if (x < inverse_edge.x2) |
| 988 | inverse_edge.x2=x; |
| 989 | } |
| 990 | else |
| 991 | if (affine->sx < -MagickEpsilon) |
| 992 | { |
| 993 | intercept=(-z+(double) image->columns)/affine->sx; |
| 994 | x=intercept+MagickEpsilon; |
| 995 | if (x > inverse_edge.x1) |
| 996 | inverse_edge.x1=x; |
| 997 | intercept=(-z/affine->sx); |
| 998 | x=intercept-MagickEpsilon; |
| 999 | if (x < inverse_edge.x2) |
| 1000 | inverse_edge.x2=x; |
| 1001 | } |
| 1002 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1003 | if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->columns)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1004 | { |
| 1005 | inverse_edge.x2=edge->x1; |
| 1006 | return(inverse_edge); |
| 1007 | } |
| 1008 | /* |
| 1009 | Determine top and bottom edges. |
| 1010 | */ |
| 1011 | z=affine->sy*y+affine->ty; |
| 1012 | if (affine->rx > MagickEpsilon) |
| 1013 | { |
| 1014 | intercept=(-z/affine->rx); |
| 1015 | x=intercept+MagickEpsilon; |
| 1016 | if (x > inverse_edge.x1) |
| 1017 | inverse_edge.x1=x; |
| 1018 | intercept=(-z+(double) image->rows)/affine->rx; |
| 1019 | x=intercept-MagickEpsilon; |
| 1020 | if (x < inverse_edge.x2) |
| 1021 | inverse_edge.x2=x; |
| 1022 | } |
| 1023 | else |
| 1024 | if (affine->rx < -MagickEpsilon) |
| 1025 | { |
| 1026 | intercept=(-z+(double) image->rows)/affine->rx; |
| 1027 | x=intercept+MagickEpsilon; |
| 1028 | if (x > inverse_edge.x1) |
| 1029 | inverse_edge.x1=x; |
| 1030 | intercept=(-z/affine->rx); |
| 1031 | x=intercept-MagickEpsilon; |
| 1032 | if (x < inverse_edge.x2) |
| 1033 | inverse_edge.x2=x; |
| 1034 | } |
| 1035 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1036 | if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1037 | { |
| 1038 | inverse_edge.x2=edge->x2; |
| 1039 | return(inverse_edge); |
| 1040 | } |
| 1041 | return(inverse_edge); |
| 1042 | } |
| 1043 | |
| 1044 | static AffineMatrix InverseAffineMatrix(const AffineMatrix *affine) |
| 1045 | { |
| 1046 | AffineMatrix |
| 1047 | inverse_affine; |
| 1048 | |
| 1049 | double |
| 1050 | determinant; |
| 1051 | |
| 1052 | determinant=1.0/(affine->sx*affine->sy-affine->rx*affine->ry); |
| 1053 | inverse_affine.sx=determinant*affine->sy; |
| 1054 | inverse_affine.rx=determinant*(-affine->rx); |
| 1055 | inverse_affine.ry=determinant*(-affine->ry); |
| 1056 | inverse_affine.sy=determinant*affine->sx; |
| 1057 | inverse_affine.tx=(-affine->tx)*inverse_affine.sx-affine->ty* |
| 1058 | inverse_affine.ry; |
| 1059 | inverse_affine.ty=(-affine->tx)*inverse_affine.rx-affine->ty* |
| 1060 | inverse_affine.sy; |
| 1061 | return(inverse_affine); |
| 1062 | } |
| 1063 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1064 | static inline ssize_t MagickAbsoluteValue(const ssize_t x) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1065 | { |
| 1066 | if (x < 0) |
| 1067 | return(-x); |
| 1068 | return(x); |
| 1069 | } |
| 1070 | |
| 1071 | static inline double MagickMax(const double x,const double y) |
| 1072 | { |
| 1073 | if (x > y) |
| 1074 | return(x); |
| 1075 | return(y); |
| 1076 | } |
| 1077 | |
| 1078 | static inline double MagickMin(const double x,const double y) |
| 1079 | { |
| 1080 | if (x < y) |
| 1081 | return(x); |
| 1082 | return(y); |
| 1083 | } |
| 1084 | |
| 1085 | MagickExport MagickBooleanType DrawAffineImage(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1086 | const Image *source,const AffineMatrix *affine,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1087 | { |
| 1088 | AffineMatrix |
| 1089 | inverse_affine; |
| 1090 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 1091 | CacheView |
| 1092 | *image_view, |
| 1093 | *source_view; |
| 1094 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1095 | MagickBooleanType |
| 1096 | status; |
| 1097 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1098 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1099 | zero; |
| 1100 | |
| 1101 | PointInfo |
| 1102 | extent[4], |
| 1103 | min, |
| 1104 | max, |
| 1105 | point; |
| 1106 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1107 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1108 | i; |
| 1109 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1110 | SegmentInfo |
| 1111 | edge; |
| 1112 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1113 | ssize_t |
| 1114 | y; |
| 1115 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1116 | /* |
| 1117 | Determine bounding box. |
| 1118 | */ |
| 1119 | assert(image != (Image *) NULL); |
| 1120 | assert(image->signature == MagickSignature); |
| 1121 | if (image->debug != MagickFalse) |
| 1122 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1123 | assert(source != (const Image *) NULL); |
| 1124 | assert(source->signature == MagickSignature); |
| 1125 | assert(affine != (AffineMatrix *) NULL); |
| 1126 | extent[0].x=0.0; |
| 1127 | extent[0].y=0.0; |
| 1128 | extent[1].x=(double) source->columns-1.0; |
| 1129 | extent[1].y=0.0; |
| 1130 | extent[2].x=(double) source->columns-1.0; |
| 1131 | extent[2].y=(double) source->rows-1.0; |
| 1132 | extent[3].x=0.0; |
| 1133 | extent[3].y=(double) source->rows-1.0; |
| 1134 | for (i=0; i < 4; i++) |
| 1135 | { |
| 1136 | point=extent[i]; |
| 1137 | extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx; |
| 1138 | extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty; |
| 1139 | } |
| 1140 | min=extent[0]; |
| 1141 | max=extent[0]; |
| 1142 | for (i=1; i < 4; i++) |
| 1143 | { |
| 1144 | if (min.x > extent[i].x) |
| 1145 | min.x=extent[i].x; |
| 1146 | if (min.y > extent[i].y) |
| 1147 | min.y=extent[i].y; |
| 1148 | if (max.x < extent[i].x) |
| 1149 | max.x=extent[i].x; |
| 1150 | if (max.y < extent[i].y) |
| 1151 | max.y=extent[i].y; |
| 1152 | } |
| 1153 | /* |
| 1154 | Affine transform image. |
| 1155 | */ |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 1156 | if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1157 | return(MagickFalse); |
| 1158 | status=MagickTrue; |
| 1159 | edge.x1=MagickMax(min.x,0.0); |
| 1160 | edge.y1=MagickMax(min.y,0.0); |
| 1161 | edge.x2=MagickMin(max.x,(double) image->columns-1.0); |
| 1162 | edge.y2=MagickMin(max.y,(double) image->rows-1.0); |
| 1163 | inverse_affine=InverseAffineMatrix(affine); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1164 | GetPixelInfo(image,&zero); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1165 | image_view=AcquireCacheView(image); |
| 1166 | source_view=AcquireCacheView(source); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 1167 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 1168 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1169 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1170 | 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] | 1171 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1172 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1173 | composite, |
| 1174 | pixel; |
| 1175 | |
| 1176 | PointInfo |
| 1177 | point; |
| 1178 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1179 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1180 | x; |
| 1181 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1182 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1183 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1184 | |
| 1185 | SegmentInfo |
| 1186 | inverse_edge; |
| 1187 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1188 | ssize_t |
| 1189 | x_offset; |
| 1190 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1191 | inverse_edge=AffineEdge(source,&inverse_affine,(double) y,&edge); |
| 1192 | if (inverse_edge.x2 < inverse_edge.x1) |
| 1193 | continue; |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1194 | q=GetCacheViewAuthenticPixels(image_view,(ssize_t) ceil(inverse_edge.x1- |
| 1195 | 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] | 1196 | inverse_edge.x1+0.5)+1),1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1197 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1198 | continue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1199 | pixel=zero; |
| 1200 | composite=zero; |
| 1201 | x_offset=0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1202 | 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] | 1203 | { |
| 1204 | point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+ |
| 1205 | inverse_affine.tx; |
| 1206 | point.y=(double) x*inverse_affine.rx+y*inverse_affine.sy+ |
| 1207 | inverse_affine.ty; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1208 | (void) InterpolatePixelInfo(source,source_view,UndefinedInterpolatePixel, |
| 1209 | point.x,point.y,&pixel,exception); |
| 1210 | SetPixelInfo(image,q,&composite); |
| 1211 | CompositePixelInfoOver(&pixel,pixel.alpha,&composite,composite.alpha, |
| 1212 | &composite); |
| 1213 | SetPixelPixelInfo(image,&composite,q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1214 | x_offset++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1215 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1216 | } |
| 1217 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 1218 | status=MagickFalse; |
| 1219 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1220 | source_view=DestroyCacheView(source_view); |
| 1221 | image_view=DestroyCacheView(image_view); |
| 1222 | return(status); |
| 1223 | } |
| 1224 | |
| 1225 | /* |
| 1226 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1227 | % % |
| 1228 | % % |
| 1229 | % % |
| 1230 | + D r a w B o u n d i n g R e c t a n g l e s % |
| 1231 | % % |
| 1232 | % % |
| 1233 | % % |
| 1234 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1235 | % |
| 1236 | % DrawBoundingRectangles() draws the bounding rectangles on the image. This |
| 1237 | % is only useful for developers debugging the rendering algorithm. |
| 1238 | % |
| 1239 | % The format of the DrawBoundingRectangles method is: |
| 1240 | % |
| 1241 | % void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1242 | % PolygonInfo *polygon_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1243 | % |
| 1244 | % A description of each parameter follows: |
| 1245 | % |
| 1246 | % o image: the image. |
| 1247 | % |
| 1248 | % o draw_info: the draw info. |
| 1249 | % |
| 1250 | % o polygon_info: Specifies a pointer to a PolygonInfo structure. |
| 1251 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1252 | % o exception: return any errors or warnings in this structure. |
| 1253 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1254 | */ |
| 1255 | static void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1256 | const PolygonInfo *polygon_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1257 | { |
| 1258 | DrawInfo |
| 1259 | *clone_info; |
| 1260 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1261 | MagickRealType |
| 1262 | mid; |
| 1263 | |
| 1264 | PointInfo |
| 1265 | end, |
| 1266 | resolution, |
| 1267 | start; |
| 1268 | |
| 1269 | PrimitiveInfo |
| 1270 | primitive_info[6]; |
| 1271 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1272 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1273 | i; |
| 1274 | |
| 1275 | SegmentInfo |
| 1276 | bounds; |
| 1277 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1278 | ssize_t |
| 1279 | coordinates; |
| 1280 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1281 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1282 | (void) QueryColorCompliance("#0000",AllCompliance,&clone_info->fill, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1283 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1284 | resolution.x=DefaultResolution; |
| 1285 | resolution.y=DefaultResolution; |
| 1286 | if (clone_info->density != (char *) NULL) |
| 1287 | { |
| 1288 | GeometryInfo |
| 1289 | geometry_info; |
| 1290 | |
| 1291 | MagickStatusType |
| 1292 | flags; |
| 1293 | |
| 1294 | flags=ParseGeometry(clone_info->density,&geometry_info); |
| 1295 | resolution.x=geometry_info.rho; |
| 1296 | resolution.y=geometry_info.sigma; |
| 1297 | if ((flags & SigmaValue) == MagickFalse) |
| 1298 | resolution.y=resolution.x; |
| 1299 | } |
| 1300 | mid=(resolution.x/72.0)*ExpandAffine(&clone_info->affine)* |
| 1301 | clone_info->stroke_width/2.0; |
| 1302 | bounds.x1=0.0; |
| 1303 | bounds.y1=0.0; |
| 1304 | bounds.x2=0.0; |
| 1305 | bounds.y2=0.0; |
| 1306 | if (polygon_info != (PolygonInfo *) NULL) |
| 1307 | { |
| 1308 | bounds=polygon_info->edges[0].bounds; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1309 | for (i=1; i < (ssize_t) polygon_info->number_edges; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1310 | { |
| 1311 | if (polygon_info->edges[i].bounds.x1 < (double) bounds.x1) |
| 1312 | bounds.x1=polygon_info->edges[i].bounds.x1; |
| 1313 | if (polygon_info->edges[i].bounds.y1 < (double) bounds.y1) |
| 1314 | bounds.y1=polygon_info->edges[i].bounds.y1; |
| 1315 | if (polygon_info->edges[i].bounds.x2 > (double) bounds.x2) |
| 1316 | bounds.x2=polygon_info->edges[i].bounds.x2; |
| 1317 | if (polygon_info->edges[i].bounds.y2 > (double) bounds.y2) |
| 1318 | bounds.y2=polygon_info->edges[i].bounds.y2; |
| 1319 | } |
| 1320 | bounds.x1-=mid; |
| 1321 | bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double) |
| 1322 | image->columns ? (double) image->columns-1 : bounds.x1; |
| 1323 | bounds.y1-=mid; |
| 1324 | bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double) |
| 1325 | image->rows ? (double) image->rows-1 : bounds.y1; |
| 1326 | bounds.x2+=mid; |
| 1327 | bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double) |
| 1328 | image->columns ? (double) image->columns-1 : bounds.x2; |
| 1329 | bounds.y2+=mid; |
| 1330 | bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double) |
| 1331 | image->rows ? (double) image->rows-1 : bounds.y2; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1332 | for (i=0; i < (ssize_t) polygon_info->number_edges; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1333 | { |
| 1334 | if (polygon_info->edges[i].direction != 0) |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1335 | (void) QueryColorCompliance("red",AllCompliance,&clone_info->stroke, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1336 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1337 | else |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1338 | (void) QueryColorCompliance("green",AllCompliance,&clone_info->stroke, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1339 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1340 | start.x=(double) (polygon_info->edges[i].bounds.x1-mid); |
| 1341 | start.y=(double) (polygon_info->edges[i].bounds.y1-mid); |
| 1342 | end.x=(double) (polygon_info->edges[i].bounds.x2+mid); |
| 1343 | end.y=(double) (polygon_info->edges[i].bounds.y2+mid); |
| 1344 | primitive_info[0].primitive=RectanglePrimitive; |
| 1345 | TraceRectangle(primitive_info,start,end); |
| 1346 | primitive_info[0].method=ReplaceMethod; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1347 | coordinates=(ssize_t) primitive_info[0].coordinates; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1348 | primitive_info[coordinates].primitive=UndefinedPrimitive; |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1349 | (void) DrawPrimitive(image,clone_info,primitive_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1350 | } |
| 1351 | } |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1352 | (void) QueryColorCompliance("blue",AllCompliance,&clone_info->stroke, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1353 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1354 | start.x=(double) (bounds.x1-mid); |
| 1355 | start.y=(double) (bounds.y1-mid); |
| 1356 | end.x=(double) (bounds.x2+mid); |
| 1357 | end.y=(double) (bounds.y2+mid); |
| 1358 | primitive_info[0].primitive=RectanglePrimitive; |
| 1359 | TraceRectangle(primitive_info,start,end); |
| 1360 | primitive_info[0].method=ReplaceMethod; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1361 | coordinates=(ssize_t) primitive_info[0].coordinates; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1362 | primitive_info[coordinates].primitive=UndefinedPrimitive; |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1363 | (void) DrawPrimitive(image,clone_info,primitive_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1364 | clone_info=DestroyDrawInfo(clone_info); |
| 1365 | } |
| 1366 | |
| 1367 | /* |
| 1368 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1369 | % % |
| 1370 | % % |
| 1371 | % % |
| 1372 | % D r a w C l i p P a t h % |
| 1373 | % % |
| 1374 | % % |
| 1375 | % % |
| 1376 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1377 | % |
| 1378 | % DrawClipPath() draws the clip path on the image mask. |
| 1379 | % |
| 1380 | % The format of the DrawClipPath method is: |
| 1381 | % |
| 1382 | % MagickBooleanType DrawClipPath(Image *image,const DrawInfo *draw_info, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1383 | % const char *name,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1384 | % |
| 1385 | % A description of each parameter follows: |
| 1386 | % |
| 1387 | % o image: the image. |
| 1388 | % |
| 1389 | % o draw_info: the draw info. |
| 1390 | % |
| 1391 | % o name: the name of the clip path. |
| 1392 | % |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1393 | % o exception: return any errors or warnings in this structure. |
| 1394 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1395 | */ |
| 1396 | MagickExport MagickBooleanType DrawClipPath(Image *image, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1397 | const DrawInfo *draw_info,const char *name,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1398 | { |
| 1399 | char |
| 1400 | clip_mask[MaxTextExtent]; |
| 1401 | |
| 1402 | const char |
| 1403 | *value; |
| 1404 | |
| 1405 | DrawInfo |
| 1406 | *clone_info; |
| 1407 | |
| 1408 | MagickStatusType |
| 1409 | status; |
| 1410 | |
| 1411 | assert(image != (Image *) NULL); |
| 1412 | assert(image->signature == MagickSignature); |
| 1413 | if (image->debug != MagickFalse) |
| 1414 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1415 | assert(draw_info != (const DrawInfo *) NULL); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1416 | (void) FormatLocaleString(clip_mask,MaxTextExtent,"%s",name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1417 | value=GetImageArtifact(image,clip_mask); |
| 1418 | if (value == (const char *) NULL) |
| 1419 | return(MagickFalse); |
| 1420 | if (image->clip_mask == (Image *) NULL) |
| 1421 | { |
| 1422 | Image |
| 1423 | *clip_mask; |
| 1424 | |
| 1425 | clip_mask=CloneImage(image,image->columns,image->rows,MagickTrue, |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 1426 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1427 | if (clip_mask == (Image *) NULL) |
| 1428 | return(MagickFalse); |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1429 | (void) SetImageClipMask(image,clip_mask,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1430 | clip_mask=DestroyImage(clip_mask); |
| 1431 | } |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1432 | (void) QueryColorCompliance("#00000000",AllCompliance, |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 1433 | &image->clip_mask->background_color,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1434 | image->clip_mask->background_color.alpha=(Quantum) TransparentAlpha; |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 1435 | (void) SetImageBackgroundColor(image->clip_mask,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1436 | if (image->debug != MagickFalse) |
| 1437 | (void) LogMagickEvent(DrawEvent,GetMagickModule(),"\nbegin clip-path %s", |
| 1438 | draw_info->clip_mask); |
| 1439 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 1440 | (void) CloneString(&clone_info->primitive,value); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1441 | (void) QueryColorCompliance("#ffffff",AllCompliance,&clone_info->fill, |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 1442 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1443 | clone_info->clip_mask=(char *) NULL; |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1444 | status=DrawImage(image->clip_mask,clone_info,exception); |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 1445 | status|=NegateImage(image->clip_mask,MagickFalse,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1446 | clone_info=DestroyDrawInfo(clone_info); |
| 1447 | if (image->debug != MagickFalse) |
| 1448 | (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end clip-path"); |
| 1449 | return(status != 0 ? MagickTrue : MagickFalse); |
| 1450 | } |
| 1451 | |
| 1452 | /* |
| 1453 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1454 | % % |
| 1455 | % % |
| 1456 | % % |
| 1457 | + D r a w D a s h P o l y g o n % |
| 1458 | % % |
| 1459 | % % |
| 1460 | % % |
| 1461 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1462 | % |
| 1463 | % DrawDashPolygon() draws a dashed polygon (line, rectangle, ellipse) on the |
| 1464 | % image while respecting the dash offset and dash pattern attributes. |
| 1465 | % |
| 1466 | % The format of the DrawDashPolygon method is: |
| 1467 | % |
| 1468 | % MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1469 | % const PrimitiveInfo *primitive_info,Image *image, |
| 1470 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1471 | % |
| 1472 | % A description of each parameter follows: |
| 1473 | % |
| 1474 | % o draw_info: the draw info. |
| 1475 | % |
| 1476 | % o primitive_info: Specifies a pointer to a PrimitiveInfo structure. |
| 1477 | % |
| 1478 | % o image: the image. |
| 1479 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1480 | % o exception: return any errors or warnings in this structure. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1481 | % |
| 1482 | */ |
| 1483 | static MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1484 | const PrimitiveInfo *primitive_info,Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1485 | { |
| 1486 | DrawInfo |
| 1487 | *clone_info; |
| 1488 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1489 | MagickRealType |
| 1490 | length, |
| 1491 | maximum_length, |
| 1492 | offset, |
| 1493 | scale, |
| 1494 | total_length; |
| 1495 | |
| 1496 | MagickStatusType |
| 1497 | status; |
| 1498 | |
| 1499 | PrimitiveInfo |
| 1500 | *dash_polygon; |
| 1501 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1502 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1503 | i; |
| 1504 | |
| 1505 | register MagickRealType |
| 1506 | dx, |
| 1507 | dy; |
| 1508 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1509 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1510 | number_vertices; |
| 1511 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1512 | ssize_t |
| 1513 | j, |
| 1514 | n; |
| 1515 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1516 | assert(draw_info != (const DrawInfo *) NULL); |
| 1517 | if (image->debug != MagickFalse) |
| 1518 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-dash"); |
| 1519 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 1520 | clone_info->miterlimit=0; |
| 1521 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1522 | number_vertices=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1523 | dash_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t) |
| 1524 | (2UL*number_vertices+1UL),sizeof(*dash_polygon)); |
| 1525 | if (dash_polygon == (PrimitiveInfo *) NULL) |
| 1526 | return(MagickFalse); |
| 1527 | dash_polygon[0]=primitive_info[0]; |
| 1528 | scale=ExpandAffine(&draw_info->affine); |
| 1529 | length=scale*(draw_info->dash_pattern[0]-0.5); |
| 1530 | offset=draw_info->dash_offset != 0.0 ? scale*draw_info->dash_offset : 0.0; |
| 1531 | j=1; |
| 1532 | for (n=0; offset > 0.0; j=0) |
| 1533 | { |
| 1534 | if (draw_info->dash_pattern[n] <= 0.0) |
| 1535 | break; |
| 1536 | length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5)); |
| 1537 | if (offset > length) |
| 1538 | { |
| 1539 | offset-=length; |
| 1540 | n++; |
| 1541 | length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5)); |
| 1542 | continue; |
| 1543 | } |
| 1544 | if (offset < length) |
| 1545 | { |
| 1546 | length-=offset; |
| 1547 | offset=0.0; |
| 1548 | break; |
| 1549 | } |
| 1550 | offset=0.0; |
| 1551 | n++; |
| 1552 | } |
| 1553 | status=MagickTrue; |
| 1554 | maximum_length=0.0; |
| 1555 | total_length=0.0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1556 | for (i=1; i < (ssize_t) number_vertices; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1557 | { |
| 1558 | dx=primitive_info[i].point.x-primitive_info[i-1].point.x; |
| 1559 | dy=primitive_info[i].point.y-primitive_info[i-1].point.y; |
| 1560 | maximum_length=hypot((double) dx,dy); |
| 1561 | if (length == 0.0) |
| 1562 | { |
| 1563 | n++; |
| 1564 | if (draw_info->dash_pattern[n] == 0.0) |
| 1565 | n=0; |
| 1566 | length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5)); |
| 1567 | } |
| 1568 | for (total_length=0.0; (total_length+length) < maximum_length; ) |
| 1569 | { |
| 1570 | total_length+=length; |
| 1571 | if ((n & 0x01) != 0) |
| 1572 | { |
| 1573 | dash_polygon[0]=primitive_info[0]; |
| 1574 | dash_polygon[0].point.x=(double) (primitive_info[i-1].point.x+dx* |
| 1575 | total_length/maximum_length); |
| 1576 | dash_polygon[0].point.y=(double) (primitive_info[i-1].point.y+dy* |
| 1577 | total_length/maximum_length); |
| 1578 | j=1; |
| 1579 | } |
| 1580 | else |
| 1581 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1582 | if ((j+1) > (ssize_t) (2*number_vertices)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1583 | break; |
| 1584 | dash_polygon[j]=primitive_info[i-1]; |
| 1585 | dash_polygon[j].point.x=(double) (primitive_info[i-1].point.x+dx* |
| 1586 | total_length/maximum_length); |
| 1587 | dash_polygon[j].point.y=(double) (primitive_info[i-1].point.y+dy* |
| 1588 | total_length/maximum_length); |
| 1589 | dash_polygon[j].coordinates=1; |
| 1590 | j++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1591 | dash_polygon[0].coordinates=(size_t) j; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1592 | dash_polygon[j].primitive=UndefinedPrimitive; |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1593 | status|=DrawStrokePolygon(image,clone_info,dash_polygon,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1594 | } |
| 1595 | n++; |
| 1596 | if (draw_info->dash_pattern[n] == 0.0) |
| 1597 | n=0; |
| 1598 | length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5)); |
| 1599 | } |
| 1600 | length-=(maximum_length-total_length); |
| 1601 | if ((n & 0x01) != 0) |
| 1602 | continue; |
| 1603 | dash_polygon[j]=primitive_info[i]; |
| 1604 | dash_polygon[j].coordinates=1; |
| 1605 | j++; |
| 1606 | } |
| 1607 | if ((total_length < maximum_length) && ((n & 0x01) == 0) && (j > 1)) |
| 1608 | { |
| 1609 | dash_polygon[j]=primitive_info[i-1]; |
| 1610 | dash_polygon[j].point.x+=MagickEpsilon; |
| 1611 | dash_polygon[j].point.y+=MagickEpsilon; |
| 1612 | dash_polygon[j].coordinates=1; |
| 1613 | j++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1614 | dash_polygon[0].coordinates=(size_t) j; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1615 | dash_polygon[j].primitive=UndefinedPrimitive; |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1616 | status|=DrawStrokePolygon(image,clone_info,dash_polygon,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1617 | } |
| 1618 | dash_polygon=(PrimitiveInfo *) RelinquishMagickMemory(dash_polygon); |
| 1619 | clone_info=DestroyDrawInfo(clone_info); |
| 1620 | if (image->debug != MagickFalse) |
| 1621 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-dash"); |
| 1622 | return(status != 0 ? MagickTrue : MagickFalse); |
| 1623 | } |
| 1624 | |
| 1625 | /* |
| 1626 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1627 | % % |
| 1628 | % % |
| 1629 | % % |
| 1630 | % D r a w I m a g e % |
| 1631 | % % |
| 1632 | % % |
| 1633 | % % |
| 1634 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1635 | % |
| 1636 | % DrawImage() draws a graphic primitive on your image. The primitive |
| 1637 | % may be represented as a string or filename. Precede the filename with an |
| 1638 | % "at" sign (@) and the contents of the file are drawn on the image. You |
| 1639 | % can affect how text is drawn by setting one or more members of the draw |
| 1640 | % info structure. |
| 1641 | % |
| 1642 | % The format of the DrawImage method is: |
| 1643 | % |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1644 | % MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info, |
| 1645 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1646 | % |
| 1647 | % A description of each parameter follows: |
| 1648 | % |
| 1649 | % o image: the image. |
| 1650 | % |
| 1651 | % o draw_info: the draw info. |
| 1652 | % |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1653 | % o exception: return any errors or warnings in this structure. |
| 1654 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1655 | */ |
| 1656 | |
| 1657 | static inline MagickBooleanType IsPoint(const char *point) |
| 1658 | { |
| 1659 | char |
| 1660 | *p; |
| 1661 | |
| 1662 | double |
| 1663 | value; |
| 1664 | |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1665 | value=InterpretLocaleValue(point,&p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1666 | return((value == 0.0) && (p == point) ? MagickFalse : MagickTrue); |
| 1667 | } |
| 1668 | |
| 1669 | static inline void TracePoint(PrimitiveInfo *primitive_info, |
| 1670 | const PointInfo point) |
| 1671 | { |
| 1672 | primitive_info->coordinates=1; |
| 1673 | primitive_info->point=point; |
| 1674 | } |
| 1675 | |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1676 | MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info, |
| 1677 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1678 | { |
| 1679 | #define RenderImageTag "Render/Image" |
| 1680 | |
| 1681 | AffineMatrix |
| 1682 | affine, |
| 1683 | current; |
| 1684 | |
| 1685 | char |
| 1686 | key[2*MaxTextExtent], |
| 1687 | keyword[MaxTextExtent], |
| 1688 | geometry[MaxTextExtent], |
| 1689 | name[MaxTextExtent], |
| 1690 | pattern[MaxTextExtent], |
| 1691 | *primitive, |
| 1692 | *token; |
| 1693 | |
| 1694 | const char |
| 1695 | *q; |
| 1696 | |
| 1697 | DrawInfo |
| 1698 | **graphic_context; |
| 1699 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1700 | MagickBooleanType |
| 1701 | proceed, |
| 1702 | status; |
| 1703 | |
| 1704 | MagickRealType |
| 1705 | angle, |
| 1706 | factor, |
| 1707 | primitive_extent; |
| 1708 | |
| 1709 | PointInfo |
| 1710 | point; |
| 1711 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 1712 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1713 | start_color; |
| 1714 | |
| 1715 | PrimitiveInfo |
| 1716 | *primitive_info; |
| 1717 | |
| 1718 | PrimitiveType |
| 1719 | primitive_type; |
| 1720 | |
| 1721 | register const char |
| 1722 | *p; |
| 1723 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1724 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1725 | i, |
| 1726 | x; |
| 1727 | |
| 1728 | SegmentInfo |
| 1729 | bounds; |
| 1730 | |
| 1731 | size_t |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1732 | length, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1733 | number_points; |
| 1734 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1735 | ssize_t |
| 1736 | j, |
| 1737 | k, |
| 1738 | n; |
| 1739 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1740 | /* |
| 1741 | Ensure the annotation info is valid. |
| 1742 | */ |
| 1743 | assert(image != (Image *) NULL); |
| 1744 | assert(image->signature == MagickSignature); |
| 1745 | if (image->debug != MagickFalse) |
| 1746 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1747 | assert(draw_info != (DrawInfo *) NULL); |
| 1748 | assert(draw_info->signature == MagickSignature); |
| 1749 | if (image->debug != MagickFalse) |
| 1750 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 1751 | if ((draw_info->primitive == (char *) NULL) || |
| 1752 | (*draw_info->primitive == '\0')) |
| 1753 | return(MagickFalse); |
| 1754 | if (image->debug != MagickFalse) |
| 1755 | (void) LogMagickEvent(DrawEvent,GetMagickModule(),"begin draw-image"); |
| 1756 | if (*draw_info->primitive != '@') |
| 1757 | primitive=AcquireString(draw_info->primitive); |
| 1758 | else |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1759 | primitive=FileToString(draw_info->primitive+1,~0,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1760 | if (primitive == (char *) NULL) |
| 1761 | return(MagickFalse); |
| 1762 | primitive_extent=(MagickRealType) strlen(primitive); |
| 1763 | (void) SetImageArtifact(image,"MVG",primitive); |
| 1764 | n=0; |
| 1765 | /* |
| 1766 | Allocate primitive info memory. |
| 1767 | */ |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 1768 | graphic_context=(DrawInfo **) AcquireMagickMemory( |
cristy | ed11071 | 2010-03-23 01:16:38 +0000 | [diff] [blame] | 1769 | sizeof(*graphic_context)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1770 | if (graphic_context == (DrawInfo **) NULL) |
| 1771 | { |
| 1772 | primitive=DestroyString(primitive); |
| 1773 | ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", |
| 1774 | image->filename); |
| 1775 | } |
| 1776 | number_points=2047; |
| 1777 | primitive_info=(PrimitiveInfo *) AcquireQuantumMemory((size_t) number_points, |
| 1778 | sizeof(*primitive_info)); |
| 1779 | if (primitive_info == (PrimitiveInfo *) NULL) |
| 1780 | { |
| 1781 | primitive=DestroyString(primitive); |
| 1782 | for ( ; n >= 0; n--) |
| 1783 | graphic_context[n]=DestroyDrawInfo(graphic_context[n]); |
| 1784 | graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context); |
| 1785 | ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", |
| 1786 | image->filename); |
| 1787 | } |
| 1788 | graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 1789 | graphic_context[n]->viewbox=image->page; |
| 1790 | if ((image->page.width == 0) || (image->page.height == 0)) |
| 1791 | { |
| 1792 | graphic_context[n]->viewbox.width=image->columns; |
| 1793 | graphic_context[n]->viewbox.height=image->rows; |
| 1794 | } |
| 1795 | token=AcquireString(primitive); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1796 | (void) QueryColorCompliance("#000000",AllCompliance,&start_color, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1797 | exception); |
| 1798 | if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1799 | return(MagickFalse); |
| 1800 | status=MagickTrue; |
| 1801 | for (q=primitive; *q != '\0'; ) |
| 1802 | { |
| 1803 | /* |
| 1804 | Interpret graphic primitive. |
| 1805 | */ |
| 1806 | GetMagickToken(q,&q,keyword); |
| 1807 | if (*keyword == '\0') |
| 1808 | break; |
| 1809 | if (*keyword == '#') |
| 1810 | { |
| 1811 | /* |
| 1812 | Comment. |
| 1813 | */ |
| 1814 | while ((*q != '\n') && (*q != '\0')) |
| 1815 | q++; |
| 1816 | continue; |
| 1817 | } |
| 1818 | p=q-strlen(keyword)-1; |
| 1819 | primitive_type=UndefinedPrimitive; |
| 1820 | current=graphic_context[n]->affine; |
| 1821 | GetAffineMatrix(&affine); |
| 1822 | switch (*keyword) |
| 1823 | { |
| 1824 | case ';': |
| 1825 | break; |
| 1826 | case 'a': |
| 1827 | case 'A': |
| 1828 | { |
| 1829 | if (LocaleCompare("affine",keyword) == 0) |
| 1830 | { |
| 1831 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1832 | affine.sx=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.rx=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.ry=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.sy=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1845 | GetMagickToken(q,&q,token); |
| 1846 | if (*token == ',') |
| 1847 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1848 | affine.tx=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1849 | GetMagickToken(q,&q,token); |
| 1850 | if (*token == ',') |
| 1851 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1852 | affine.ty=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1853 | break; |
| 1854 | } |
| 1855 | if (LocaleCompare("arc",keyword) == 0) |
| 1856 | { |
| 1857 | primitive_type=ArcPrimitive; |
| 1858 | break; |
| 1859 | } |
| 1860 | status=MagickFalse; |
| 1861 | break; |
| 1862 | } |
| 1863 | case 'b': |
| 1864 | case 'B': |
| 1865 | { |
| 1866 | if (LocaleCompare("bezier",keyword) == 0) |
| 1867 | { |
| 1868 | primitive_type=BezierPrimitive; |
| 1869 | break; |
| 1870 | } |
| 1871 | if (LocaleCompare("border-color",keyword) == 0) |
| 1872 | { |
| 1873 | GetMagickToken(q,&q,token); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1874 | (void) QueryColorCompliance(token,AllCompliance, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1875 | &graphic_context[n]->border_color,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1876 | break; |
| 1877 | } |
| 1878 | status=MagickFalse; |
| 1879 | break; |
| 1880 | } |
| 1881 | case 'c': |
| 1882 | case 'C': |
| 1883 | { |
| 1884 | if (LocaleCompare("clip-path",keyword) == 0) |
| 1885 | { |
| 1886 | /* |
| 1887 | Create clip mask. |
| 1888 | */ |
| 1889 | GetMagickToken(q,&q,token); |
| 1890 | (void) CloneString(&graphic_context[n]->clip_mask,token); |
| 1891 | (void) DrawClipPath(image,graphic_context[n], |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1892 | graphic_context[n]->clip_mask,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1893 | break; |
| 1894 | } |
| 1895 | if (LocaleCompare("clip-rule",keyword) == 0) |
| 1896 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1897 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1898 | fill_rule; |
| 1899 | |
| 1900 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1901 | fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1902 | token); |
| 1903 | if (fill_rule == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 1904 | status=MagickFalse; |
| 1905 | else |
| 1906 | graphic_context[n]->fill_rule=(FillRule) fill_rule; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1907 | break; |
| 1908 | } |
| 1909 | if (LocaleCompare("clip-units",keyword) == 0) |
| 1910 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1911 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1912 | clip_units; |
| 1913 | |
| 1914 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1915 | clip_units=ParseCommandOption(MagickClipPathOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1916 | token); |
| 1917 | if (clip_units == -1) |
| 1918 | { |
| 1919 | status=MagickFalse; |
| 1920 | break; |
| 1921 | } |
| 1922 | graphic_context[n]->clip_units=(ClipPathUnits) clip_units; |
| 1923 | if (clip_units == ObjectBoundingBox) |
| 1924 | { |
| 1925 | GetAffineMatrix(¤t); |
| 1926 | affine.sx=draw_info->bounds.x2; |
| 1927 | affine.sy=draw_info->bounds.y2; |
| 1928 | affine.tx=draw_info->bounds.x1; |
| 1929 | affine.ty=draw_info->bounds.y1; |
| 1930 | break; |
| 1931 | } |
| 1932 | break; |
| 1933 | } |
| 1934 | if (LocaleCompare("circle",keyword) == 0) |
| 1935 | { |
| 1936 | primitive_type=CirclePrimitive; |
| 1937 | break; |
| 1938 | } |
| 1939 | if (LocaleCompare("color",keyword) == 0) |
| 1940 | { |
| 1941 | primitive_type=ColorPrimitive; |
| 1942 | break; |
| 1943 | } |
| 1944 | status=MagickFalse; |
| 1945 | break; |
| 1946 | } |
| 1947 | case 'd': |
| 1948 | case 'D': |
| 1949 | { |
| 1950 | if (LocaleCompare("decorate",keyword) == 0) |
| 1951 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1952 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1953 | decorate; |
| 1954 | |
| 1955 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1956 | decorate=ParseCommandOption(MagickDecorateOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1957 | token); |
| 1958 | if (decorate == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 1959 | status=MagickFalse; |
| 1960 | else |
| 1961 | graphic_context[n]->decorate=(DecorationType) decorate; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1962 | break; |
| 1963 | } |
| 1964 | status=MagickFalse; |
| 1965 | break; |
| 1966 | } |
| 1967 | case 'e': |
| 1968 | case 'E': |
| 1969 | { |
| 1970 | if (LocaleCompare("ellipse",keyword) == 0) |
| 1971 | { |
| 1972 | primitive_type=EllipsePrimitive; |
| 1973 | break; |
| 1974 | } |
| 1975 | if (LocaleCompare("encoding",keyword) == 0) |
| 1976 | { |
| 1977 | GetMagickToken(q,&q,token); |
| 1978 | (void) CloneString(&graphic_context[n]->encoding,token); |
| 1979 | break; |
| 1980 | } |
| 1981 | status=MagickFalse; |
| 1982 | break; |
| 1983 | } |
| 1984 | case 'f': |
| 1985 | case 'F': |
| 1986 | { |
| 1987 | if (LocaleCompare("fill",keyword) == 0) |
| 1988 | { |
| 1989 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1990 | (void) FormatLocaleString(pattern,MaxTextExtent,"%s",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1991 | if (GetImageArtifact(image,pattern) != (const char *) NULL) |
| 1992 | (void) DrawPatternPath(image,draw_info,token, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1993 | &graphic_context[n]->fill_pattern,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1994 | else |
| 1995 | { |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1996 | status=QueryColorCompliance(token,AllCompliance, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1997 | &graphic_context[n]->fill,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1998 | if (status == MagickFalse) |
| 1999 | { |
| 2000 | ImageInfo |
| 2001 | *pattern_info; |
| 2002 | |
| 2003 | pattern_info=AcquireImageInfo(); |
| 2004 | (void) CopyMagickString(pattern_info->filename,token, |
| 2005 | MaxTextExtent); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2006 | graphic_context[n]->fill_pattern=ReadImage(pattern_info, |
| 2007 | exception); |
| 2008 | CatchException(exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2009 | pattern_info=DestroyImageInfo(pattern_info); |
| 2010 | } |
| 2011 | } |
| 2012 | break; |
| 2013 | } |
| 2014 | if (LocaleCompare("fill-opacity",keyword) == 0) |
| 2015 | { |
| 2016 | GetMagickToken(q,&q,token); |
| 2017 | factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0; |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 2018 | graphic_context[n]->fill.alpha=(MagickRealType) QuantumRange* |
| 2019 | factor*InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2020 | break; |
| 2021 | } |
| 2022 | if (LocaleCompare("fill-rule",keyword) == 0) |
| 2023 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2024 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2025 | fill_rule; |
| 2026 | |
| 2027 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2028 | fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2029 | token); |
| 2030 | if (fill_rule == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2031 | status=MagickFalse; |
| 2032 | else |
| 2033 | graphic_context[n]->fill_rule=(FillRule) fill_rule; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2034 | break; |
| 2035 | } |
| 2036 | if (LocaleCompare("font",keyword) == 0) |
| 2037 | { |
| 2038 | GetMagickToken(q,&q,token); |
| 2039 | (void) CloneString(&graphic_context[n]->font,token); |
| 2040 | if (LocaleCompare("none",token) == 0) |
| 2041 | graphic_context[n]->font=(char *) |
| 2042 | RelinquishMagickMemory(graphic_context[n]->font); |
| 2043 | break; |
| 2044 | } |
| 2045 | if (LocaleCompare("font-family",keyword) == 0) |
| 2046 | { |
| 2047 | GetMagickToken(q,&q,token); |
| 2048 | (void) CloneString(&graphic_context[n]->family,token); |
| 2049 | break; |
| 2050 | } |
| 2051 | if (LocaleCompare("font-size",keyword) == 0) |
| 2052 | { |
| 2053 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2054 | graphic_context[n]->pointsize=InterpretLocaleValue(token, |
| 2055 | (char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2056 | break; |
| 2057 | } |
| 2058 | if (LocaleCompare("font-stretch",keyword) == 0) |
| 2059 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2060 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2061 | stretch; |
| 2062 | |
| 2063 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2064 | stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2065 | if (stretch == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2066 | status=MagickFalse; |
| 2067 | else |
| 2068 | graphic_context[n]->stretch=(StretchType) stretch; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2069 | break; |
| 2070 | } |
| 2071 | if (LocaleCompare("font-style",keyword) == 0) |
| 2072 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2073 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2074 | style; |
| 2075 | |
| 2076 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2077 | style=ParseCommandOption(MagickStyleOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2078 | if (style == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2079 | status=MagickFalse; |
| 2080 | else |
| 2081 | graphic_context[n]->style=(StyleType) style; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2082 | break; |
| 2083 | } |
| 2084 | if (LocaleCompare("font-weight",keyword) == 0) |
| 2085 | { |
| 2086 | GetMagickToken(q,&q,token); |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 2087 | graphic_context[n]->weight=StringToUnsignedLong(token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2088 | if (LocaleCompare(token,"all") == 0) |
| 2089 | graphic_context[n]->weight=0; |
| 2090 | if (LocaleCompare(token,"bold") == 0) |
| 2091 | graphic_context[n]->weight=700; |
| 2092 | if (LocaleCompare(token,"bolder") == 0) |
| 2093 | if (graphic_context[n]->weight <= 800) |
| 2094 | graphic_context[n]->weight+=100; |
| 2095 | if (LocaleCompare(token,"lighter") == 0) |
| 2096 | if (graphic_context[n]->weight >= 100) |
| 2097 | graphic_context[n]->weight-=100; |
| 2098 | if (LocaleCompare(token,"normal") == 0) |
| 2099 | graphic_context[n]->weight=400; |
| 2100 | break; |
| 2101 | } |
| 2102 | status=MagickFalse; |
| 2103 | break; |
| 2104 | } |
| 2105 | case 'g': |
| 2106 | case 'G': |
| 2107 | { |
| 2108 | if (LocaleCompare("gradient-units",keyword) == 0) |
| 2109 | { |
| 2110 | GetMagickToken(q,&q,token); |
| 2111 | break; |
| 2112 | } |
| 2113 | if (LocaleCompare("gravity",keyword) == 0) |
| 2114 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2115 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2116 | gravity; |
| 2117 | |
| 2118 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2119 | gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2120 | if (gravity == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2121 | status=MagickFalse; |
| 2122 | else |
| 2123 | graphic_context[n]->gravity=(GravityType) gravity; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2124 | break; |
| 2125 | } |
| 2126 | status=MagickFalse; |
| 2127 | break; |
| 2128 | } |
| 2129 | case 'i': |
| 2130 | case 'I': |
| 2131 | { |
| 2132 | if (LocaleCompare("image",keyword) == 0) |
| 2133 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2134 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2135 | compose; |
| 2136 | |
| 2137 | primitive_type=ImagePrimitive; |
| 2138 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2139 | compose=ParseCommandOption(MagickComposeOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2140 | if (compose == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2141 | status=MagickFalse; |
| 2142 | else |
| 2143 | graphic_context[n]->compose=(CompositeOperator) compose; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2144 | break; |
| 2145 | } |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2146 | if (LocaleCompare("interline-spacing",keyword) == 0) |
| 2147 | { |
| 2148 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2149 | graphic_context[n]->interline_spacing=InterpretLocaleValue(token, |
| 2150 | (char **) NULL); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2151 | break; |
| 2152 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2153 | if (LocaleCompare("interword-spacing",keyword) == 0) |
| 2154 | { |
| 2155 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2156 | graphic_context[n]->interword_spacing=InterpretLocaleValue(token, |
| 2157 | (char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2158 | break; |
| 2159 | } |
| 2160 | status=MagickFalse; |
| 2161 | break; |
| 2162 | } |
| 2163 | case 'k': |
| 2164 | case 'K': |
| 2165 | { |
| 2166 | if (LocaleCompare("kerning",keyword) == 0) |
| 2167 | { |
| 2168 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2169 | graphic_context[n]->kerning=InterpretLocaleValue(token, |
| 2170 | (char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2171 | break; |
| 2172 | } |
| 2173 | status=MagickFalse; |
| 2174 | break; |
| 2175 | } |
| 2176 | case 'l': |
| 2177 | case 'L': |
| 2178 | { |
| 2179 | if (LocaleCompare("line",keyword) == 0) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2180 | primitive_type=LinePrimitive; |
| 2181 | else |
| 2182 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2183 | break; |
| 2184 | } |
| 2185 | case 'm': |
| 2186 | case 'M': |
| 2187 | { |
| 2188 | if (LocaleCompare("matte",keyword) == 0) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2189 | primitive_type=MattePrimitive; |
| 2190 | else |
| 2191 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2192 | break; |
| 2193 | } |
| 2194 | case 'o': |
| 2195 | case 'O': |
| 2196 | { |
| 2197 | if (LocaleCompare("offset",keyword) == 0) |
| 2198 | { |
| 2199 | GetMagickToken(q,&q,token); |
| 2200 | break; |
| 2201 | } |
| 2202 | if (LocaleCompare("opacity",keyword) == 0) |
| 2203 | { |
| 2204 | GetMagickToken(q,&q,token); |
| 2205 | factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2206 | graphic_context[n]->alpha=ClampToQuantum((MagickRealType) |
| 2207 | QuantumRange*(1.0-((1.0-QuantumScale*graphic_context[n]->alpha)* |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2208 | factor*InterpretLocaleValue(token,(char **) NULL)))); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 2209 | graphic_context[n]->fill.alpha=(double) graphic_context[n]->alpha; |
| 2210 | graphic_context[n]->stroke.alpha=(double) graphic_context[n]->alpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2211 | break; |
| 2212 | } |
| 2213 | status=MagickFalse; |
| 2214 | break; |
| 2215 | } |
| 2216 | case 'p': |
| 2217 | case 'P': |
| 2218 | { |
| 2219 | if (LocaleCompare("path",keyword) == 0) |
| 2220 | { |
| 2221 | primitive_type=PathPrimitive; |
| 2222 | break; |
| 2223 | } |
| 2224 | if (LocaleCompare("point",keyword) == 0) |
| 2225 | { |
| 2226 | primitive_type=PointPrimitive; |
| 2227 | break; |
| 2228 | } |
| 2229 | if (LocaleCompare("polyline",keyword) == 0) |
| 2230 | { |
| 2231 | primitive_type=PolylinePrimitive; |
| 2232 | break; |
| 2233 | } |
| 2234 | if (LocaleCompare("polygon",keyword) == 0) |
| 2235 | { |
| 2236 | primitive_type=PolygonPrimitive; |
| 2237 | break; |
| 2238 | } |
| 2239 | if (LocaleCompare("pop",keyword) == 0) |
| 2240 | { |
| 2241 | GetMagickToken(q,&q,token); |
| 2242 | if (LocaleCompare("clip-path",token) == 0) |
| 2243 | break; |
| 2244 | if (LocaleCompare("defs",token) == 0) |
| 2245 | break; |
| 2246 | if (LocaleCompare("gradient",token) == 0) |
| 2247 | break; |
| 2248 | if (LocaleCompare("graphic-context",token) == 0) |
| 2249 | { |
| 2250 | if (n <= 0) |
| 2251 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2252 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 2253 | DrawError,"UnbalancedGraphicContextPushPop","`%s'",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2254 | n=0; |
| 2255 | break; |
| 2256 | } |
| 2257 | if (graphic_context[n]->clip_mask != (char *) NULL) |
| 2258 | if (LocaleCompare(graphic_context[n]->clip_mask, |
| 2259 | graphic_context[n-1]->clip_mask) != 0) |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 2260 | (void) SetImageClipMask(image,(Image *) NULL,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2261 | graphic_context[n]=DestroyDrawInfo(graphic_context[n]); |
| 2262 | n--; |
| 2263 | break; |
| 2264 | } |
| 2265 | if (LocaleCompare("pattern",token) == 0) |
| 2266 | break; |
| 2267 | status=MagickFalse; |
| 2268 | break; |
| 2269 | } |
| 2270 | if (LocaleCompare("push",keyword) == 0) |
| 2271 | { |
| 2272 | GetMagickToken(q,&q,token); |
| 2273 | if (LocaleCompare("clip-path",token) == 0) |
| 2274 | { |
| 2275 | char |
| 2276 | name[MaxTextExtent]; |
| 2277 | |
| 2278 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2279 | (void) FormatLocaleString(name,MaxTextExtent,"%s",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2280 | for (p=q; *q != '\0'; ) |
| 2281 | { |
| 2282 | GetMagickToken(q,&q,token); |
| 2283 | if (LocaleCompare(token,"pop") != 0) |
| 2284 | continue; |
| 2285 | GetMagickToken(q,(const char **) NULL,token); |
| 2286 | if (LocaleCompare(token,"clip-path") != 0) |
| 2287 | continue; |
| 2288 | break; |
| 2289 | } |
| 2290 | (void) CopyMagickString(token,p,(size_t) (q-p-4+1)); |
| 2291 | (void) SetImageArtifact(image,name,token); |
| 2292 | GetMagickToken(q,&q,token); |
| 2293 | break; |
| 2294 | } |
| 2295 | if (LocaleCompare("gradient",token) == 0) |
| 2296 | { |
| 2297 | char |
| 2298 | key[2*MaxTextExtent], |
| 2299 | name[MaxTextExtent], |
| 2300 | type[MaxTextExtent]; |
| 2301 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2302 | SegmentInfo |
| 2303 | segment; |
| 2304 | |
| 2305 | GetMagickToken(q,&q,token); |
| 2306 | (void) CopyMagickString(name,token,MaxTextExtent); |
| 2307 | GetMagickToken(q,&q,token); |
| 2308 | (void) CopyMagickString(type,token,MaxTextExtent); |
| 2309 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2310 | segment.x1=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2311 | GetMagickToken(q,&q,token); |
| 2312 | if (*token == ',') |
| 2313 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2314 | segment.y1=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2315 | GetMagickToken(q,&q,token); |
| 2316 | if (*token == ',') |
| 2317 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2318 | segment.x2=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2319 | GetMagickToken(q,&q,token); |
| 2320 | if (*token == ',') |
| 2321 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2322 | segment.y2=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2323 | if (LocaleCompare(type,"radial") == 0) |
| 2324 | { |
| 2325 | GetMagickToken(q,&q,token); |
| 2326 | if (*token == ',') |
| 2327 | GetMagickToken(q,&q,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2328 | } |
| 2329 | for (p=q; *q != '\0'; ) |
| 2330 | { |
| 2331 | GetMagickToken(q,&q,token); |
| 2332 | if (LocaleCompare(token,"pop") != 0) |
| 2333 | continue; |
| 2334 | GetMagickToken(q,(const char **) NULL,token); |
| 2335 | if (LocaleCompare(token,"gradient") != 0) |
| 2336 | continue; |
| 2337 | break; |
| 2338 | } |
| 2339 | (void) CopyMagickString(token,p,(size_t) (q-p-4+1)); |
| 2340 | bounds.x1=graphic_context[n]->affine.sx*segment.x1+ |
| 2341 | graphic_context[n]->affine.ry*segment.y1+ |
| 2342 | graphic_context[n]->affine.tx; |
| 2343 | bounds.y1=graphic_context[n]->affine.rx*segment.x1+ |
| 2344 | graphic_context[n]->affine.sy*segment.y1+ |
| 2345 | graphic_context[n]->affine.ty; |
| 2346 | bounds.x2=graphic_context[n]->affine.sx*segment.x2+ |
| 2347 | graphic_context[n]->affine.ry*segment.y2+ |
| 2348 | graphic_context[n]->affine.tx; |
| 2349 | bounds.y2=graphic_context[n]->affine.rx*segment.x2+ |
| 2350 | graphic_context[n]->affine.sy*segment.y2+ |
| 2351 | graphic_context[n]->affine.ty; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2352 | (void) FormatLocaleString(key,MaxTextExtent,"%s",name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2353 | (void) SetImageArtifact(image,key,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2354 | (void) FormatLocaleString(key,MaxTextExtent,"%s-geometry",name); |
| 2355 | (void) FormatLocaleString(geometry,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 2356 | "%gx%g%+.15g%+.15g", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2357 | MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0), |
| 2358 | MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0), |
| 2359 | bounds.x1,bounds.y1); |
| 2360 | (void) SetImageArtifact(image,key,geometry); |
| 2361 | GetMagickToken(q,&q,token); |
| 2362 | break; |
| 2363 | } |
| 2364 | if (LocaleCompare("pattern",token) == 0) |
| 2365 | { |
| 2366 | RectangleInfo |
| 2367 | bounds; |
| 2368 | |
| 2369 | GetMagickToken(q,&q,token); |
| 2370 | (void) CopyMagickString(name,token,MaxTextExtent); |
| 2371 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2372 | bounds.x=(ssize_t) ceil(InterpretLocaleValue(token, |
| 2373 | (char **) NULL)-0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2374 | GetMagickToken(q,&q,token); |
| 2375 | if (*token == ',') |
| 2376 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2377 | bounds.y=(ssize_t) ceil(InterpretLocaleValue(token, |
| 2378 | (char **) NULL)-0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2379 | GetMagickToken(q,&q,token); |
| 2380 | if (*token == ',') |
| 2381 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2382 | bounds.width=(size_t) floor(InterpretLocaleValue(token, |
| 2383 | (char **) NULL)+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2384 | GetMagickToken(q,&q,token); |
| 2385 | if (*token == ',') |
| 2386 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2387 | bounds.height=(size_t) floor(InterpretLocaleValue(token, |
| 2388 | (char **) NULL)+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2389 | for (p=q; *q != '\0'; ) |
| 2390 | { |
| 2391 | GetMagickToken(q,&q,token); |
| 2392 | if (LocaleCompare(token,"pop") != 0) |
| 2393 | continue; |
| 2394 | GetMagickToken(q,(const char **) NULL,token); |
| 2395 | if (LocaleCompare(token,"pattern") != 0) |
| 2396 | continue; |
| 2397 | break; |
| 2398 | } |
| 2399 | (void) CopyMagickString(token,p,(size_t) (q-p-4+1)); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2400 | (void) FormatLocaleString(key,MaxTextExtent,"%s",name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2401 | (void) SetImageArtifact(image,key,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2402 | (void) FormatLocaleString(key,MaxTextExtent,"%s-geometry",name); |
| 2403 | (void) FormatLocaleString(geometry,MaxTextExtent, |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 2404 | "%.20gx%.20g%+.20g%+.20g",(double) bounds.width,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 2405 | bounds.height,(double) bounds.x,(double) bounds.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2406 | (void) SetImageArtifact(image,key,geometry); |
| 2407 | GetMagickToken(q,&q,token); |
| 2408 | break; |
| 2409 | } |
| 2410 | if (LocaleCompare("graphic-context",token) == 0) |
| 2411 | { |
| 2412 | n++; |
| 2413 | graphic_context=(DrawInfo **) ResizeQuantumMemory( |
| 2414 | graphic_context,(size_t) (n+1),sizeof(*graphic_context)); |
| 2415 | if (graphic_context == (DrawInfo **) NULL) |
| 2416 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2417 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 2418 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 2419 | image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2420 | break; |
| 2421 | } |
| 2422 | graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL, |
| 2423 | graphic_context[n-1]); |
| 2424 | break; |
| 2425 | } |
| 2426 | if (LocaleCompare("defs",token) == 0) |
| 2427 | break; |
| 2428 | status=MagickFalse; |
| 2429 | break; |
| 2430 | } |
| 2431 | status=MagickFalse; |
| 2432 | break; |
| 2433 | } |
| 2434 | case 'r': |
| 2435 | case 'R': |
| 2436 | { |
| 2437 | if (LocaleCompare("rectangle",keyword) == 0) |
| 2438 | { |
| 2439 | primitive_type=RectanglePrimitive; |
| 2440 | break; |
| 2441 | } |
| 2442 | if (LocaleCompare("rotate",keyword) == 0) |
| 2443 | { |
| 2444 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2445 | angle=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2446 | affine.sx=cos(DegreesToRadians(fmod((double) angle,360.0))); |
| 2447 | affine.rx=sin(DegreesToRadians(fmod((double) angle,360.0))); |
| 2448 | affine.ry=(-sin(DegreesToRadians(fmod((double) angle,360.0)))); |
| 2449 | affine.sy=cos(DegreesToRadians(fmod((double) angle,360.0))); |
| 2450 | break; |
| 2451 | } |
| 2452 | if (LocaleCompare("roundRectangle",keyword) == 0) |
| 2453 | { |
| 2454 | primitive_type=RoundRectanglePrimitive; |
| 2455 | break; |
| 2456 | } |
| 2457 | status=MagickFalse; |
| 2458 | break; |
| 2459 | } |
| 2460 | case 's': |
| 2461 | case 'S': |
| 2462 | { |
| 2463 | if (LocaleCompare("scale",keyword) == 0) |
| 2464 | { |
| 2465 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2466 | affine.sx=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2467 | GetMagickToken(q,&q,token); |
| 2468 | if (*token == ',') |
| 2469 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2470 | affine.sy=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2471 | break; |
| 2472 | } |
| 2473 | if (LocaleCompare("skewX",keyword) == 0) |
| 2474 | { |
| 2475 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2476 | angle=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2477 | affine.ry=sin(DegreesToRadians(angle)); |
| 2478 | break; |
| 2479 | } |
| 2480 | if (LocaleCompare("skewY",keyword) == 0) |
| 2481 | { |
| 2482 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2483 | angle=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2484 | affine.rx=(-tan(DegreesToRadians(angle)/2.0)); |
| 2485 | break; |
| 2486 | } |
| 2487 | if (LocaleCompare("stop-color",keyword) == 0) |
| 2488 | { |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 2489 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2490 | stop_color; |
| 2491 | |
| 2492 | GetMagickToken(q,&q,token); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 2493 | (void) QueryColorCompliance(token,AllCompliance,&stop_color, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2494 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2495 | (void) GradientImage(image,LinearGradient,ReflectSpread, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2496 | &start_color,&stop_color,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2497 | start_color=stop_color; |
| 2498 | GetMagickToken(q,&q,token); |
| 2499 | break; |
| 2500 | } |
| 2501 | if (LocaleCompare("stroke",keyword) == 0) |
| 2502 | { |
| 2503 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2504 | (void) FormatLocaleString(pattern,MaxTextExtent,"%s",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2505 | if (GetImageArtifact(image,pattern) != (const char *) NULL) |
| 2506 | (void) DrawPatternPath(image,draw_info,token, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 2507 | &graphic_context[n]->stroke_pattern,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2508 | else |
| 2509 | { |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 2510 | status=QueryColorCompliance(token,AllCompliance, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2511 | &graphic_context[n]->stroke,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2512 | if (status == MagickFalse) |
| 2513 | { |
| 2514 | ImageInfo |
| 2515 | *pattern_info; |
| 2516 | |
| 2517 | pattern_info=AcquireImageInfo(); |
| 2518 | (void) CopyMagickString(pattern_info->filename,token, |
| 2519 | MaxTextExtent); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2520 | graphic_context[n]->stroke_pattern=ReadImage(pattern_info, |
| 2521 | exception); |
| 2522 | CatchException(exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2523 | pattern_info=DestroyImageInfo(pattern_info); |
| 2524 | } |
| 2525 | } |
| 2526 | break; |
| 2527 | } |
| 2528 | if (LocaleCompare("stroke-antialias",keyword) == 0) |
| 2529 | { |
| 2530 | GetMagickToken(q,&q,token); |
| 2531 | graphic_context[n]->stroke_antialias= |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2532 | StringToLong(token) != 0 ? MagickTrue : MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2533 | break; |
| 2534 | } |
| 2535 | if (LocaleCompare("stroke-dasharray",keyword) == 0) |
| 2536 | { |
| 2537 | if (graphic_context[n]->dash_pattern != (double *) NULL) |
| 2538 | graphic_context[n]->dash_pattern=(double *) |
| 2539 | RelinquishMagickMemory(graphic_context[n]->dash_pattern); |
| 2540 | if (IsPoint(q) != MagickFalse) |
| 2541 | { |
| 2542 | const char |
| 2543 | *p; |
| 2544 | |
| 2545 | p=q; |
| 2546 | GetMagickToken(p,&p,token); |
| 2547 | if (*token == ',') |
| 2548 | GetMagickToken(p,&p,token); |
| 2549 | for (x=0; IsPoint(token) != MagickFalse; x++) |
| 2550 | { |
| 2551 | GetMagickToken(p,&p,token); |
| 2552 | if (*token == ',') |
| 2553 | GetMagickToken(p,&p,token); |
| 2554 | } |
| 2555 | graphic_context[n]->dash_pattern=(double *) |
| 2556 | AcquireQuantumMemory((size_t) (2UL*x+1UL), |
| 2557 | sizeof(*graphic_context[n]->dash_pattern)); |
| 2558 | if (graphic_context[n]->dash_pattern == (double *) NULL) |
| 2559 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2560 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 2561 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 2562 | image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2563 | break; |
| 2564 | } |
| 2565 | for (j=0; j < x; j++) |
| 2566 | { |
| 2567 | GetMagickToken(q,&q,token); |
| 2568 | if (*token == ',') |
| 2569 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2570 | graphic_context[n]->dash_pattern[j]=InterpretLocaleValue( |
| 2571 | token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2572 | } |
| 2573 | if ((x & 0x01) != 0) |
| 2574 | for ( ; j < (2*x); j++) |
| 2575 | graphic_context[n]->dash_pattern[j]= |
| 2576 | graphic_context[n]->dash_pattern[j-x]; |
| 2577 | graphic_context[n]->dash_pattern[j]=0.0; |
| 2578 | break; |
| 2579 | } |
| 2580 | GetMagickToken(q,&q,token); |
| 2581 | break; |
| 2582 | } |
| 2583 | if (LocaleCompare("stroke-dashoffset",keyword) == 0) |
| 2584 | { |
| 2585 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2586 | graphic_context[n]->dash_offset=InterpretLocaleValue(token, |
| 2587 | (char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2588 | break; |
| 2589 | } |
| 2590 | if (LocaleCompare("stroke-linecap",keyword) == 0) |
| 2591 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2592 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2593 | linecap; |
| 2594 | |
| 2595 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2596 | linecap=ParseCommandOption(MagickLineCapOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2597 | if (linecap == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2598 | status=MagickFalse; |
| 2599 | else |
| 2600 | graphic_context[n]->linecap=(LineCap) linecap; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2601 | break; |
| 2602 | } |
| 2603 | if (LocaleCompare("stroke-linejoin",keyword) == 0) |
| 2604 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2605 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2606 | linejoin; |
| 2607 | |
| 2608 | GetMagickToken(q,&q,token); |
cristy | 7118edf | 2011-10-08 13:33:25 +0000 | [diff] [blame] | 2609 | linejoin=ParseCommandOption(MagickLineJoinOptions,MagickFalse, |
| 2610 | token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2611 | if (linejoin == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2612 | status=MagickFalse; |
| 2613 | else |
| 2614 | graphic_context[n]->linejoin=(LineJoin) linejoin; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2615 | break; |
| 2616 | } |
| 2617 | if (LocaleCompare("stroke-miterlimit",keyword) == 0) |
| 2618 | { |
| 2619 | GetMagickToken(q,&q,token); |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 2620 | graphic_context[n]->miterlimit=StringToUnsignedLong(token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2621 | break; |
| 2622 | } |
| 2623 | if (LocaleCompare("stroke-opacity",keyword) == 0) |
| 2624 | { |
| 2625 | GetMagickToken(q,&q,token); |
| 2626 | factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0; |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 2627 | graphic_context[n]->stroke.alpha=(MagickRealType) QuantumRange* |
| 2628 | factor*InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2629 | break; |
| 2630 | } |
| 2631 | if (LocaleCompare("stroke-width",keyword) == 0) |
| 2632 | { |
| 2633 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2634 | graphic_context[n]->stroke_width=InterpretLocaleValue(token, |
| 2635 | (char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2636 | break; |
| 2637 | } |
| 2638 | status=MagickFalse; |
| 2639 | break; |
| 2640 | } |
| 2641 | case 't': |
| 2642 | case 'T': |
| 2643 | { |
| 2644 | if (LocaleCompare("text",keyword) == 0) |
| 2645 | { |
| 2646 | primitive_type=TextPrimitive; |
| 2647 | break; |
| 2648 | } |
| 2649 | if (LocaleCompare("text-align",keyword) == 0) |
| 2650 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2651 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2652 | align; |
| 2653 | |
| 2654 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2655 | align=ParseCommandOption(MagickAlignOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2656 | if (align == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2657 | status=MagickFalse; |
| 2658 | else |
| 2659 | graphic_context[n]->align=(AlignType) align; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2660 | break; |
| 2661 | } |
| 2662 | if (LocaleCompare("text-anchor",keyword) == 0) |
| 2663 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2664 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2665 | align; |
| 2666 | |
| 2667 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2668 | align=ParseCommandOption(MagickAlignOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2669 | if (align == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2670 | status=MagickFalse; |
| 2671 | else |
| 2672 | graphic_context[n]->align=(AlignType) align; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2673 | break; |
| 2674 | } |
| 2675 | if (LocaleCompare("text-antialias",keyword) == 0) |
| 2676 | { |
| 2677 | GetMagickToken(q,&q,token); |
| 2678 | graphic_context[n]->text_antialias= |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2679 | StringToLong(token) != 0 ? MagickTrue : MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2680 | break; |
| 2681 | } |
| 2682 | if (LocaleCompare("text-undercolor",keyword) == 0) |
| 2683 | { |
| 2684 | GetMagickToken(q,&q,token); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 2685 | (void) QueryColorCompliance(token,AllCompliance, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2686 | &graphic_context[n]->undercolor,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2687 | break; |
| 2688 | } |
| 2689 | if (LocaleCompare("translate",keyword) == 0) |
| 2690 | { |
| 2691 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2692 | affine.tx=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2693 | GetMagickToken(q,&q,token); |
| 2694 | if (*token == ',') |
| 2695 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2696 | affine.ty=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2697 | break; |
| 2698 | } |
| 2699 | status=MagickFalse; |
| 2700 | break; |
| 2701 | } |
| 2702 | case 'v': |
| 2703 | case 'V': |
| 2704 | { |
| 2705 | if (LocaleCompare("viewbox",keyword) == 0) |
| 2706 | { |
| 2707 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2708 | graphic_context[n]->viewbox.x=(ssize_t) ceil(InterpretLocaleValue( |
| 2709 | token,(char **) NULL)-0.5); |
cristy | 06609ee | 2010-03-17 20:21:27 +0000 | [diff] [blame] | 2710 | GetMagickToken(q,&q,token); |
| 2711 | if (*token == ',') |
| 2712 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2713 | graphic_context[n]->viewbox.y=(ssize_t) ceil(InterpretLocaleValue( |
| 2714 | token,(char **) NULL)-0.5); |
cristy | 06609ee | 2010-03-17 20:21:27 +0000 | [diff] [blame] | 2715 | GetMagickToken(q,&q,token); |
| 2716 | if (*token == ',') |
| 2717 | GetMagickToken(q,&q,token); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2718 | graphic_context[n]->viewbox.width=(size_t) floor( |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2719 | InterpretLocaleValue(token,(char **) NULL)+0.5); |
cristy | 06609ee | 2010-03-17 20:21:27 +0000 | [diff] [blame] | 2720 | GetMagickToken(q,&q,token); |
| 2721 | if (*token == ',') |
| 2722 | GetMagickToken(q,&q,token); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2723 | graphic_context[n]->viewbox.height=(size_t) floor( |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2724 | InterpretLocaleValue(token,(char **) NULL)+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2725 | break; |
| 2726 | } |
| 2727 | status=MagickFalse; |
| 2728 | break; |
| 2729 | } |
| 2730 | default: |
| 2731 | { |
| 2732 | status=MagickFalse; |
| 2733 | break; |
| 2734 | } |
| 2735 | } |
| 2736 | if (status == MagickFalse) |
| 2737 | break; |
| 2738 | if ((affine.sx != 1.0) || (affine.rx != 0.0) || (affine.ry != 0.0) || |
| 2739 | (affine.sy != 1.0) || (affine.tx != 0.0) || (affine.ty != 0.0)) |
| 2740 | { |
cristy | fbd7009 | 2010-12-01 19:31:14 +0000 | [diff] [blame] | 2741 | graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx; |
| 2742 | graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx; |
| 2743 | graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy; |
| 2744 | graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy; |
| 2745 | graphic_context[n]->affine.tx=current.sx*affine.tx+current.ry*affine.ty+ |
| 2746 | current.tx; |
| 2747 | graphic_context[n]->affine.ty=current.rx*affine.tx+current.sy*affine.ty+ |
| 2748 | current.ty; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2749 | } |
| 2750 | if (primitive_type == UndefinedPrimitive) |
| 2751 | { |
| 2752 | if (image->debug != MagickFalse) |
| 2753 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s", |
| 2754 | (int) (q-p),p); |
| 2755 | continue; |
| 2756 | } |
| 2757 | /* |
| 2758 | Parse the primitive attributes. |
| 2759 | */ |
| 2760 | i=0; |
| 2761 | j=0; |
| 2762 | primitive_info[0].point.x=0.0; |
| 2763 | primitive_info[0].point.y=0.0; |
| 2764 | for (x=0; *q != '\0'; x++) |
| 2765 | { |
| 2766 | /* |
| 2767 | Define points. |
| 2768 | */ |
| 2769 | if (IsPoint(q) == MagickFalse) |
| 2770 | break; |
| 2771 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2772 | point.x=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2773 | GetMagickToken(q,&q,token); |
| 2774 | if (*token == ',') |
| 2775 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2776 | point.y=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2777 | GetMagickToken(q,(const char **) NULL,token); |
| 2778 | if (*token == ',') |
| 2779 | GetMagickToken(q,&q,token); |
| 2780 | primitive_info[i].primitive=primitive_type; |
| 2781 | primitive_info[i].point=point; |
| 2782 | primitive_info[i].coordinates=0; |
| 2783 | primitive_info[i].method=FloodfillMethod; |
| 2784 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2785 | if (i < (ssize_t) number_points) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2786 | continue; |
| 2787 | number_points<<=1; |
| 2788 | primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info, |
| 2789 | (size_t) number_points,sizeof(*primitive_info)); |
| 2790 | if (primitive_info == (PrimitiveInfo *) NULL) |
| 2791 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2792 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2793 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
| 2794 | break; |
| 2795 | } |
| 2796 | } |
| 2797 | primitive_info[j].primitive=primitive_type; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2798 | primitive_info[j].coordinates=(size_t) x; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2799 | primitive_info[j].method=FloodfillMethod; |
| 2800 | primitive_info[j].text=(char *) NULL; |
| 2801 | /* |
| 2802 | Circumscribe primitive within a circle. |
| 2803 | */ |
| 2804 | bounds.x1=primitive_info[j].point.x; |
| 2805 | bounds.y1=primitive_info[j].point.y; |
| 2806 | bounds.x2=primitive_info[j].point.x; |
| 2807 | bounds.y2=primitive_info[j].point.y; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2808 | for (k=1; k < (ssize_t) primitive_info[j].coordinates; k++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2809 | { |
| 2810 | point=primitive_info[j+k].point; |
| 2811 | if (point.x < bounds.x1) |
| 2812 | bounds.x1=point.x; |
| 2813 | if (point.y < bounds.y1) |
| 2814 | bounds.y1=point.y; |
| 2815 | if (point.x > bounds.x2) |
| 2816 | bounds.x2=point.x; |
| 2817 | if (point.y > bounds.y2) |
| 2818 | bounds.y2=point.y; |
| 2819 | } |
| 2820 | /* |
| 2821 | Speculate how many points our primitive might consume. |
| 2822 | */ |
| 2823 | length=primitive_info[j].coordinates; |
| 2824 | switch (primitive_type) |
| 2825 | { |
| 2826 | case RectanglePrimitive: |
| 2827 | { |
| 2828 | length*=5; |
| 2829 | break; |
| 2830 | } |
| 2831 | case RoundRectanglePrimitive: |
| 2832 | { |
cristy | 78817ad | 2010-05-07 12:25:34 +0000 | [diff] [blame] | 2833 | length*=5+8*BezierQuantum; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2834 | break; |
| 2835 | } |
| 2836 | case BezierPrimitive: |
| 2837 | { |
| 2838 | if (primitive_info[j].coordinates > 107) |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2839 | (void) ThrowMagickException(exception,GetMagickModule(),DrawError, |
| 2840 | "TooManyBezierCoordinates","`%s'",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2841 | length=BezierQuantum*primitive_info[j].coordinates; |
| 2842 | break; |
| 2843 | } |
| 2844 | case PathPrimitive: |
| 2845 | { |
| 2846 | char |
| 2847 | *s, |
| 2848 | *t; |
| 2849 | |
| 2850 | GetMagickToken(q,&q,token); |
cristy | 40a08ad | 2010-02-09 02:27:44 +0000 | [diff] [blame] | 2851 | length=1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2852 | t=token; |
| 2853 | for (s=token; *s != '\0'; s=t) |
| 2854 | { |
cristy | 00976d8 | 2011-02-20 20:31:28 +0000 | [diff] [blame] | 2855 | double |
| 2856 | value; |
| 2857 | |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2858 | value=InterpretLocaleValue(s,&t); |
cristy | 00976d8 | 2011-02-20 20:31:28 +0000 | [diff] [blame] | 2859 | (void) value; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2860 | if (s == t) |
| 2861 | { |
| 2862 | t++; |
| 2863 | continue; |
| 2864 | } |
cristy | ef7a6ce | 2011-05-14 15:01:11 +0000 | [diff] [blame] | 2865 | length++; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2866 | } |
cristy | d2f832c | 2011-06-28 12:35:24 +0000 | [diff] [blame] | 2867 | length=length*BezierQuantum/2; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2868 | break; |
| 2869 | } |
| 2870 | case CirclePrimitive: |
| 2871 | case ArcPrimitive: |
| 2872 | case EllipsePrimitive: |
| 2873 | { |
| 2874 | MagickRealType |
| 2875 | alpha, |
| 2876 | beta, |
| 2877 | radius; |
| 2878 | |
| 2879 | alpha=bounds.x2-bounds.x1; |
| 2880 | beta=bounds.y2-bounds.y1; |
| 2881 | radius=hypot((double) alpha,(double) beta); |
cristy | f53f26f | 2011-05-16 00:56:05 +0000 | [diff] [blame] | 2882 | length=2*((size_t) ceil((double) MagickPI*radius))+6*BezierQuantum+360; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2883 | break; |
| 2884 | } |
| 2885 | default: |
| 2886 | break; |
| 2887 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2888 | if ((size_t) (i+length) >= number_points) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2889 | { |
| 2890 | /* |
| 2891 | Resize based on speculative points required by primitive. |
| 2892 | */ |
cristy | 9ce61b9 | 2010-05-12 16:30:26 +0000 | [diff] [blame] | 2893 | number_points+=length+1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2894 | primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info, |
| 2895 | (size_t) number_points,sizeof(*primitive_info)); |
| 2896 | if (primitive_info == (PrimitiveInfo *) NULL) |
| 2897 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2898 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2899 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 2900 | image->filename); |
| 2901 | break; |
| 2902 | } |
| 2903 | } |
| 2904 | switch (primitive_type) |
| 2905 | { |
| 2906 | case PointPrimitive: |
| 2907 | default: |
| 2908 | { |
| 2909 | if (primitive_info[j].coordinates != 1) |
| 2910 | { |
| 2911 | status=MagickFalse; |
| 2912 | break; |
| 2913 | } |
| 2914 | TracePoint(primitive_info+j,primitive_info[j].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2915 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2916 | break; |
| 2917 | } |
| 2918 | case LinePrimitive: |
| 2919 | { |
| 2920 | if (primitive_info[j].coordinates != 2) |
| 2921 | { |
| 2922 | status=MagickFalse; |
| 2923 | break; |
| 2924 | } |
| 2925 | TraceLine(primitive_info+j,primitive_info[j].point, |
| 2926 | primitive_info[j+1].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2927 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2928 | break; |
| 2929 | } |
| 2930 | case RectanglePrimitive: |
| 2931 | { |
| 2932 | if (primitive_info[j].coordinates != 2) |
| 2933 | { |
| 2934 | status=MagickFalse; |
| 2935 | break; |
| 2936 | } |
| 2937 | TraceRectangle(primitive_info+j,primitive_info[j].point, |
| 2938 | primitive_info[j+1].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2939 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2940 | break; |
| 2941 | } |
| 2942 | case RoundRectanglePrimitive: |
| 2943 | { |
| 2944 | if (primitive_info[j].coordinates != 3) |
| 2945 | { |
| 2946 | status=MagickFalse; |
| 2947 | break; |
| 2948 | } |
| 2949 | TraceRoundRectangle(primitive_info+j,primitive_info[j].point, |
| 2950 | primitive_info[j+1].point,primitive_info[j+2].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2951 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2952 | break; |
| 2953 | } |
| 2954 | case ArcPrimitive: |
| 2955 | { |
| 2956 | if (primitive_info[j].coordinates != 3) |
| 2957 | { |
| 2958 | primitive_type=UndefinedPrimitive; |
| 2959 | break; |
| 2960 | } |
| 2961 | TraceArc(primitive_info+j,primitive_info[j].point, |
| 2962 | primitive_info[j+1].point,primitive_info[j+2].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2963 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2964 | break; |
| 2965 | } |
| 2966 | case EllipsePrimitive: |
| 2967 | { |
| 2968 | if (primitive_info[j].coordinates != 3) |
| 2969 | { |
| 2970 | status=MagickFalse; |
| 2971 | break; |
| 2972 | } |
| 2973 | TraceEllipse(primitive_info+j,primitive_info[j].point, |
| 2974 | primitive_info[j+1].point,primitive_info[j+2].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2975 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2976 | break; |
| 2977 | } |
| 2978 | case CirclePrimitive: |
| 2979 | { |
| 2980 | if (primitive_info[j].coordinates != 2) |
| 2981 | { |
| 2982 | status=MagickFalse; |
| 2983 | break; |
| 2984 | } |
| 2985 | TraceCircle(primitive_info+j,primitive_info[j].point, |
| 2986 | primitive_info[j+1].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2987 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2988 | break; |
| 2989 | } |
| 2990 | case PolylinePrimitive: |
| 2991 | break; |
| 2992 | case PolygonPrimitive: |
| 2993 | { |
| 2994 | primitive_info[i]=primitive_info[j]; |
| 2995 | primitive_info[i].coordinates=0; |
| 2996 | primitive_info[j].coordinates++; |
| 2997 | i++; |
| 2998 | break; |
| 2999 | } |
| 3000 | case BezierPrimitive: |
| 3001 | { |
| 3002 | if (primitive_info[j].coordinates < 3) |
| 3003 | { |
| 3004 | status=MagickFalse; |
| 3005 | break; |
| 3006 | } |
| 3007 | TraceBezier(primitive_info+j,primitive_info[j].coordinates); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3008 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3009 | break; |
| 3010 | } |
| 3011 | case PathPrimitive: |
| 3012 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3013 | i=(ssize_t) (j+TracePath(primitive_info+j,token)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3014 | break; |
| 3015 | } |
| 3016 | case ColorPrimitive: |
| 3017 | case MattePrimitive: |
| 3018 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3019 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3020 | method; |
| 3021 | |
| 3022 | if (primitive_info[j].coordinates != 1) |
| 3023 | { |
| 3024 | status=MagickFalse; |
| 3025 | break; |
| 3026 | } |
| 3027 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 3028 | method=ParseCommandOption(MagickMethodOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3029 | if (method == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 3030 | status=MagickFalse; |
| 3031 | else |
| 3032 | primitive_info[j].method=(PaintMethod) method; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3033 | break; |
| 3034 | } |
| 3035 | case TextPrimitive: |
| 3036 | { |
| 3037 | if (primitive_info[j].coordinates != 1) |
| 3038 | { |
| 3039 | status=MagickFalse; |
| 3040 | break; |
| 3041 | } |
| 3042 | if (*token != ',') |
| 3043 | GetMagickToken(q,&q,token); |
| 3044 | primitive_info[j].text=AcquireString(token); |
| 3045 | break; |
| 3046 | } |
| 3047 | case ImagePrimitive: |
| 3048 | { |
| 3049 | if (primitive_info[j].coordinates != 2) |
| 3050 | { |
| 3051 | status=MagickFalse; |
| 3052 | break; |
| 3053 | } |
| 3054 | GetMagickToken(q,&q,token); |
| 3055 | primitive_info[j].text=AcquireString(token); |
| 3056 | break; |
| 3057 | } |
| 3058 | } |
| 3059 | if (primitive_info == (PrimitiveInfo *) NULL) |
| 3060 | break; |
| 3061 | if (image->debug != MagickFalse) |
| 3062 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",(int) (q-p),p); |
| 3063 | if (status == MagickFalse) |
| 3064 | break; |
| 3065 | primitive_info[i].primitive=UndefinedPrimitive; |
| 3066 | if (i == 0) |
| 3067 | continue; |
| 3068 | /* |
| 3069 | Transform points. |
| 3070 | */ |
| 3071 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) |
| 3072 | { |
| 3073 | point=primitive_info[i].point; |
| 3074 | primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+ |
| 3075 | graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx; |
| 3076 | primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+ |
| 3077 | graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty; |
| 3078 | point=primitive_info[i].point; |
| 3079 | if (point.x < graphic_context[n]->bounds.x1) |
| 3080 | graphic_context[n]->bounds.x1=point.x; |
| 3081 | if (point.y < graphic_context[n]->bounds.y1) |
| 3082 | graphic_context[n]->bounds.y1=point.y; |
| 3083 | if (point.x > graphic_context[n]->bounds.x2) |
| 3084 | graphic_context[n]->bounds.x2=point.x; |
| 3085 | if (point.y > graphic_context[n]->bounds.y2) |
| 3086 | graphic_context[n]->bounds.y2=point.y; |
| 3087 | if (primitive_info[i].primitive == ImagePrimitive) |
| 3088 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3089 | if (i >= (ssize_t) number_points) |
cristy | 9ce61b9 | 2010-05-12 16:30:26 +0000 | [diff] [blame] | 3090 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3091 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3092 | if (graphic_context[n]->render != MagickFalse) |
| 3093 | { |
| 3094 | if ((n != 0) && (graphic_context[n]->clip_mask != (char *) NULL) && |
| 3095 | (LocaleCompare(graphic_context[n]->clip_mask, |
| 3096 | graphic_context[n-1]->clip_mask) != 0)) |
| 3097 | (void) DrawClipPath(image,graphic_context[n], |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 3098 | graphic_context[n]->clip_mask,exception); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3099 | (void) DrawPrimitive(image,graphic_context[n],primitive_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3100 | } |
| 3101 | if (primitive_info->text != (char *) NULL) |
| 3102 | primitive_info->text=(char *) RelinquishMagickMemory( |
| 3103 | primitive_info->text); |
| 3104 | proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType) |
| 3105 | primitive_extent); |
| 3106 | if (proceed == MagickFalse) |
| 3107 | break; |
| 3108 | } |
| 3109 | if (image->debug != MagickFalse) |
| 3110 | (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end draw-image"); |
| 3111 | /* |
| 3112 | Relinquish resources. |
| 3113 | */ |
| 3114 | token=DestroyString(token); |
| 3115 | if (primitive_info != (PrimitiveInfo *) NULL) |
| 3116 | primitive_info=(PrimitiveInfo *) RelinquishMagickMemory(primitive_info); |
| 3117 | primitive=DestroyString(primitive); |
| 3118 | for ( ; n >= 0; n--) |
| 3119 | graphic_context[n]=DestroyDrawInfo(graphic_context[n]); |
| 3120 | graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context); |
| 3121 | if (status == MagickFalse) |
| 3122 | ThrowBinaryException(DrawError,"NonconformingDrawingPrimitiveDefinition", |
| 3123 | keyword); |
| 3124 | return(status); |
| 3125 | } |
| 3126 | |
| 3127 | /* |
| 3128 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3129 | % % |
| 3130 | % % |
| 3131 | % % |
| 3132 | % D r a w G r a d i e n t I m a g e % |
| 3133 | % % |
| 3134 | % % |
| 3135 | % % |
| 3136 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3137 | % |
| 3138 | % DrawGradientImage() draws a linear gradient on the image. |
| 3139 | % |
| 3140 | % The format of the DrawGradientImage method is: |
| 3141 | % |
| 3142 | % MagickBooleanType DrawGradientImage(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3143 | % const DrawInfo *draw_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3144 | % |
| 3145 | % A description of each parameter follows: |
| 3146 | % |
| 3147 | % o image: the image. |
| 3148 | % |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 3149 | % o draw_info: the draw info. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3150 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3151 | % o exception: return any errors or warnings in this structure. |
| 3152 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3153 | */ |
| 3154 | |
| 3155 | static inline MagickRealType GetStopColorOffset(const GradientInfo *gradient, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3156 | const ssize_t x,const ssize_t y) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3157 | { |
| 3158 | switch (gradient->type) |
| 3159 | { |
| 3160 | case UndefinedGradient: |
| 3161 | case LinearGradient: |
| 3162 | { |
| 3163 | MagickRealType |
| 3164 | gamma, |
| 3165 | length, |
| 3166 | offset, |
| 3167 | scale; |
| 3168 | |
| 3169 | PointInfo |
| 3170 | p, |
| 3171 | q; |
| 3172 | |
| 3173 | const SegmentInfo |
| 3174 | *gradient_vector; |
| 3175 | |
| 3176 | gradient_vector=(&gradient->gradient_vector); |
| 3177 | p.x=gradient_vector->x2-gradient_vector->x1; |
| 3178 | p.y=gradient_vector->y2-gradient_vector->y1; |
| 3179 | q.x=(double) x-gradient_vector->x1; |
| 3180 | q.y=(double) y-gradient_vector->y1; |
| 3181 | length=sqrt(q.x*q.x+q.y*q.y); |
| 3182 | gamma=sqrt(p.x*p.x+p.y*p.y)*length; |
| 3183 | gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma); |
| 3184 | scale=p.x*q.x+p.y*q.y; |
| 3185 | offset=gamma*scale*length; |
| 3186 | return(offset); |
| 3187 | } |
| 3188 | case RadialGradient: |
| 3189 | { |
| 3190 | MagickRealType |
| 3191 | length, |
| 3192 | offset; |
| 3193 | |
| 3194 | PointInfo |
| 3195 | v; |
| 3196 | |
| 3197 | v.x=(double) x-gradient->center.x; |
| 3198 | v.y=(double) y-gradient->center.y; |
| 3199 | length=sqrt(v.x*v.x+v.y*v.y); |
| 3200 | if (gradient->spread == RepeatSpread) |
| 3201 | return(length); |
| 3202 | offset=length/gradient->radius; |
| 3203 | return(offset); |
| 3204 | } |
| 3205 | } |
| 3206 | return(0.0); |
| 3207 | } |
| 3208 | |
| 3209 | MagickExport MagickBooleanType DrawGradientImage(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3210 | const DrawInfo *draw_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3211 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 3212 | CacheView |
| 3213 | *image_view; |
| 3214 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3215 | const GradientInfo |
| 3216 | *gradient; |
| 3217 | |
| 3218 | const SegmentInfo |
| 3219 | *gradient_vector; |
| 3220 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3221 | MagickBooleanType |
| 3222 | status; |
| 3223 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3224 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3225 | zero; |
| 3226 | |
| 3227 | MagickRealType |
| 3228 | length; |
| 3229 | |
| 3230 | PointInfo |
| 3231 | point; |
| 3232 | |
| 3233 | RectangleInfo |
| 3234 | bounding_box; |
| 3235 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 3236 | ssize_t |
| 3237 | y; |
| 3238 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3239 | /* |
| 3240 | Draw linear or radial gradient on image. |
| 3241 | */ |
| 3242 | assert(image != (Image *) NULL); |
| 3243 | assert(image->signature == MagickSignature); |
| 3244 | if (image->debug != MagickFalse) |
| 3245 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3246 | assert(draw_info != (const DrawInfo *) NULL); |
| 3247 | gradient=(&draw_info->gradient); |
| 3248 | gradient_vector=(&gradient->gradient_vector); |
| 3249 | point.x=gradient_vector->x2-gradient_vector->x1; |
| 3250 | point.y=gradient_vector->y2-gradient_vector->y1; |
| 3251 | length=sqrt(point.x*point.x+point.y*point.y); |
| 3252 | bounding_box=gradient->bounding_box; |
| 3253 | status=MagickTrue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3254 | GetPixelInfo(image,&zero); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3255 | image_view=AcquireCacheView(image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3256 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 3257 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3258 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3259 | for (y=bounding_box.y; y < (ssize_t) bounding_box.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3260 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3261 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3262 | composite, |
| 3263 | pixel; |
| 3264 | |
| 3265 | MagickRealType |
| 3266 | alpha, |
| 3267 | offset; |
| 3268 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3269 | register Quantum |
| 3270 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3271 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3272 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3273 | i, |
| 3274 | x; |
| 3275 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 3276 | ssize_t |
| 3277 | j; |
| 3278 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3279 | if (status == MagickFalse) |
| 3280 | continue; |
| 3281 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3282 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3283 | { |
| 3284 | status=MagickFalse; |
| 3285 | continue; |
| 3286 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3287 | pixel=zero; |
| 3288 | composite=zero; |
| 3289 | offset=GetStopColorOffset(gradient,0,y); |
| 3290 | if (gradient->type != RadialGradient) |
| 3291 | offset/=length; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3292 | for (x=bounding_box.x; x < (ssize_t) bounding_box.width; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3293 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3294 | SetPixelInfo(image,q,&pixel); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3295 | switch (gradient->spread) |
| 3296 | { |
| 3297 | case UndefinedSpread: |
| 3298 | case PadSpread: |
| 3299 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3300 | if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) || |
| 3301 | (y != (ssize_t) ceil(gradient_vector->y1-0.5))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3302 | { |
| 3303 | offset=GetStopColorOffset(gradient,x,y); |
| 3304 | if (gradient->type != RadialGradient) |
| 3305 | offset/=length; |
| 3306 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3307 | for (i=0; i < (ssize_t) gradient->number_stops; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3308 | if (offset < gradient->stops[i].offset) |
| 3309 | break; |
| 3310 | if ((offset < 0.0) || (i == 0)) |
| 3311 | composite=gradient->stops[0].color; |
| 3312 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3313 | if ((offset > 1.0) || (i == (ssize_t) gradient->number_stops)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3314 | composite=gradient->stops[gradient->number_stops-1].color; |
| 3315 | else |
| 3316 | { |
| 3317 | j=i; |
| 3318 | i--; |
| 3319 | alpha=(offset-gradient->stops[i].offset)/ |
| 3320 | (gradient->stops[j].offset-gradient->stops[i].offset); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3321 | CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3322 | &gradient->stops[j].color,alpha,&composite); |
| 3323 | } |
| 3324 | break; |
| 3325 | } |
| 3326 | case ReflectSpread: |
| 3327 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3328 | if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) || |
| 3329 | (y != (ssize_t) ceil(gradient_vector->y1-0.5))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3330 | { |
| 3331 | offset=GetStopColorOffset(gradient,x,y); |
| 3332 | if (gradient->type != RadialGradient) |
| 3333 | offset/=length; |
| 3334 | } |
| 3335 | if (offset < 0.0) |
| 3336 | offset=(-offset); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3337 | if ((ssize_t) fmod(offset,2.0) == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3338 | offset=fmod(offset,1.0); |
| 3339 | else |
| 3340 | offset=1.0-fmod(offset,1.0); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3341 | for (i=0; i < (ssize_t) gradient->number_stops; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3342 | if (offset < gradient->stops[i].offset) |
| 3343 | break; |
| 3344 | if (i == 0) |
| 3345 | composite=gradient->stops[0].color; |
| 3346 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3347 | if (i == (ssize_t) gradient->number_stops) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3348 | composite=gradient->stops[gradient->number_stops-1].color; |
| 3349 | else |
| 3350 | { |
| 3351 | j=i; |
| 3352 | i--; |
| 3353 | alpha=(offset-gradient->stops[i].offset)/ |
| 3354 | (gradient->stops[j].offset-gradient->stops[i].offset); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3355 | CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3356 | &gradient->stops[j].color,alpha,&composite); |
| 3357 | } |
| 3358 | break; |
| 3359 | } |
| 3360 | case RepeatSpread: |
| 3361 | { |
| 3362 | MagickBooleanType |
| 3363 | antialias; |
| 3364 | |
| 3365 | MagickRealType |
| 3366 | repeat; |
| 3367 | |
| 3368 | antialias=MagickFalse; |
| 3369 | repeat=0.0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3370 | if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) || |
| 3371 | (y != (ssize_t) ceil(gradient_vector->y1-0.5))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3372 | { |
| 3373 | offset=GetStopColorOffset(gradient,x,y); |
| 3374 | if (gradient->type == LinearGradient) |
| 3375 | { |
| 3376 | repeat=fmod(offset,length); |
| 3377 | if (repeat < 0.0) |
| 3378 | repeat=length-fmod(-repeat,length); |
| 3379 | else |
| 3380 | repeat=fmod(offset,length); |
| 3381 | antialias=(repeat < length) && ((repeat+1.0) > length) ? |
| 3382 | MagickTrue : MagickFalse; |
| 3383 | offset=repeat/length; |
| 3384 | } |
| 3385 | else |
| 3386 | { |
| 3387 | repeat=fmod(offset,gradient->radius); |
| 3388 | if (repeat < 0.0) |
| 3389 | repeat=gradient->radius-fmod(-repeat,gradient->radius); |
| 3390 | else |
| 3391 | repeat=fmod(offset,gradient->radius); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3392 | antialias=repeat+1.0 > gradient->radius ? MagickTrue : |
| 3393 | MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3394 | offset=repeat/gradient->radius; |
| 3395 | } |
| 3396 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3397 | for (i=0; i < (ssize_t) gradient->number_stops; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3398 | if (offset < gradient->stops[i].offset) |
| 3399 | break; |
| 3400 | if (i == 0) |
| 3401 | composite=gradient->stops[0].color; |
| 3402 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3403 | if (i == (ssize_t) gradient->number_stops) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3404 | composite=gradient->stops[gradient->number_stops-1].color; |
| 3405 | else |
| 3406 | { |
| 3407 | j=i; |
| 3408 | i--; |
| 3409 | alpha=(offset-gradient->stops[i].offset)/ |
| 3410 | (gradient->stops[j].offset-gradient->stops[i].offset); |
| 3411 | if (antialias != MagickFalse) |
| 3412 | { |
| 3413 | if (gradient->type == LinearGradient) |
| 3414 | alpha=length-repeat; |
| 3415 | else |
| 3416 | alpha=gradient->radius-repeat; |
| 3417 | i=0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3418 | j=(ssize_t) gradient->number_stops-1L; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3419 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3420 | CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3421 | &gradient->stops[j].color,alpha,&composite); |
| 3422 | } |
| 3423 | break; |
| 3424 | } |
| 3425 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3426 | CompositePixelInfoOver(&composite,composite.alpha,&pixel,pixel.alpha, |
| 3427 | &pixel); |
| 3428 | SetPixelPixelInfo(image,&pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3429 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3430 | } |
| 3431 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 3432 | status=MagickFalse; |
| 3433 | } |
| 3434 | image_view=DestroyCacheView(image_view); |
| 3435 | return(status); |
| 3436 | } |
| 3437 | |
| 3438 | /* |
| 3439 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3440 | % % |
| 3441 | % % |
| 3442 | % % |
| 3443 | % D r a w P a t t e r n P a t h % |
| 3444 | % % |
| 3445 | % % |
| 3446 | % % |
| 3447 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3448 | % |
| 3449 | % DrawPatternPath() draws a pattern. |
| 3450 | % |
| 3451 | % The format of the DrawPatternPath method is: |
| 3452 | % |
| 3453 | % MagickBooleanType DrawPatternPath(Image *image,const DrawInfo *draw_info, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 3454 | % const char *name,Image **pattern,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3455 | % |
| 3456 | % A description of each parameter follows: |
| 3457 | % |
| 3458 | % o image: the image. |
| 3459 | % |
| 3460 | % o draw_info: the draw info. |
| 3461 | % |
| 3462 | % o name: the pattern name. |
| 3463 | % |
| 3464 | % o image: the image. |
| 3465 | % |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 3466 | % o exception: return any errors or warnings in this structure. |
| 3467 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3468 | */ |
| 3469 | MagickExport MagickBooleanType DrawPatternPath(Image *image, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 3470 | const DrawInfo *draw_info,const char *name,Image **pattern, |
| 3471 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3472 | { |
| 3473 | char |
| 3474 | property[MaxTextExtent]; |
| 3475 | |
| 3476 | const char |
| 3477 | *geometry, |
| 3478 | *path; |
| 3479 | |
| 3480 | DrawInfo |
| 3481 | *clone_info; |
| 3482 | |
| 3483 | ImageInfo |
| 3484 | *image_info; |
| 3485 | |
| 3486 | MagickBooleanType |
| 3487 | status; |
| 3488 | |
| 3489 | assert(image != (Image *) NULL); |
| 3490 | assert(image->signature == MagickSignature); |
| 3491 | if (image->debug != MagickFalse) |
| 3492 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3493 | assert(draw_info != (const DrawInfo *) NULL); |
| 3494 | assert(name != (const char *) NULL); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3495 | (void) FormatLocaleString(property,MaxTextExtent,"%s",name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3496 | path=GetImageArtifact(image,property); |
| 3497 | if (path == (const char *) NULL) |
| 3498 | return(MagickFalse); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3499 | (void) FormatLocaleString(property,MaxTextExtent,"%s-geometry",name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3500 | geometry=GetImageArtifact(image,property); |
| 3501 | if (geometry == (const char *) NULL) |
| 3502 | return(MagickFalse); |
| 3503 | if ((*pattern) != (Image *) NULL) |
| 3504 | *pattern=DestroyImage(*pattern); |
| 3505 | image_info=AcquireImageInfo(); |
| 3506 | image_info->size=AcquireString(geometry); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3507 | *pattern=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3508 | image_info=DestroyImageInfo(image_info); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 3509 | (void) QueryColorCompliance("#00000000",AllCompliance, |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 3510 | &(*pattern)->background_color,exception); |
| 3511 | (void) SetImageBackgroundColor(*pattern,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3512 | if (image->debug != MagickFalse) |
| 3513 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
| 3514 | "begin pattern-path %s %s",name,geometry); |
| 3515 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 3516 | clone_info->fill_pattern=NewImageList(); |
| 3517 | clone_info->stroke_pattern=NewImageList(); |
| 3518 | (void) CloneString(&clone_info->primitive,path); |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 3519 | status=DrawImage(*pattern,clone_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3520 | clone_info=DestroyDrawInfo(clone_info); |
| 3521 | if (image->debug != MagickFalse) |
| 3522 | (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end pattern-path"); |
| 3523 | return(status); |
| 3524 | } |
| 3525 | |
| 3526 | /* |
| 3527 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3528 | % % |
| 3529 | % % |
| 3530 | % % |
| 3531 | + D r a w P o l y g o n P r i m i t i v e % |
| 3532 | % % |
| 3533 | % % |
| 3534 | % % |
| 3535 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3536 | % |
| 3537 | % DrawPolygonPrimitive() draws a polygon on the image. |
| 3538 | % |
| 3539 | % The format of the DrawPolygonPrimitive method is: |
| 3540 | % |
| 3541 | % MagickBooleanType DrawPolygonPrimitive(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3542 | % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info, |
| 3543 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3544 | % |
| 3545 | % A description of each parameter follows: |
| 3546 | % |
| 3547 | % o image: the image. |
| 3548 | % |
| 3549 | % o draw_info: the draw info. |
| 3550 | % |
| 3551 | % o primitive_info: Specifies a pointer to a PrimitiveInfo structure. |
| 3552 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3553 | % o exception: return any errors or warnings in this structure. |
| 3554 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3555 | */ |
| 3556 | |
| 3557 | static PolygonInfo **DestroyPolygonThreadSet(PolygonInfo **polygon_info) |
| 3558 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3559 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3560 | i; |
| 3561 | |
| 3562 | assert(polygon_info != (PolygonInfo **) NULL); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3563 | for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3564 | if (polygon_info[i] != (PolygonInfo *) NULL) |
| 3565 | polygon_info[i]=DestroyPolygonInfo(polygon_info[i]); |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 3566 | polygon_info=(PolygonInfo **) RelinquishMagickMemory(polygon_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3567 | return(polygon_info); |
| 3568 | } |
| 3569 | |
| 3570 | static PolygonInfo **AcquirePolygonThreadSet(const DrawInfo *draw_info, |
| 3571 | const PrimitiveInfo *primitive_info) |
| 3572 | { |
| 3573 | PathInfo |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3574 | *restrict path_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3575 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3576 | PolygonInfo |
| 3577 | **polygon_info; |
| 3578 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 3579 | register ssize_t |
| 3580 | i; |
| 3581 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3582 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3583 | number_threads; |
| 3584 | |
| 3585 | number_threads=GetOpenMPMaximumThreads(); |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 3586 | polygon_info=(PolygonInfo **) AcquireQuantumMemory(number_threads, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3587 | sizeof(*polygon_info)); |
| 3588 | if (polygon_info == (PolygonInfo **) NULL) |
| 3589 | return((PolygonInfo **) NULL); |
| 3590 | (void) ResetMagickMemory(polygon_info,0,GetOpenMPMaximumThreads()* |
| 3591 | sizeof(*polygon_info)); |
| 3592 | path_info=ConvertPrimitiveToPath(draw_info,primitive_info); |
| 3593 | if (path_info == (PathInfo *) NULL) |
| 3594 | return(DestroyPolygonThreadSet(polygon_info)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3595 | for (i=0; i < (ssize_t) number_threads; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3596 | { |
| 3597 | polygon_info[i]=ConvertPathToPolygon(draw_info,path_info); |
| 3598 | if (polygon_info[i] == (PolygonInfo *) NULL) |
| 3599 | return(DestroyPolygonThreadSet(polygon_info)); |
| 3600 | } |
| 3601 | path_info=(PathInfo *) RelinquishMagickMemory(path_info); |
| 3602 | return(polygon_info); |
| 3603 | } |
| 3604 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3605 | static MagickRealType GetPixelOpacity(PolygonInfo *polygon_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3606 | const MagickRealType mid,const MagickBooleanType fill, |
cristy | 77f38fb | 2010-04-22 15:51:47 +0000 | [diff] [blame] | 3607 | const FillRule fill_rule,const double x,const double y, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3608 | MagickRealType *stroke_opacity) |
| 3609 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3610 | MagickRealType |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3611 | alpha, |
| 3612 | beta, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3613 | distance, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3614 | subpath_opacity; |
| 3615 | |
| 3616 | PointInfo |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3617 | delta; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3618 | |
| 3619 | register EdgeInfo |
| 3620 | *p; |
| 3621 | |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3622 | register const PointInfo |
| 3623 | *q; |
| 3624 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3625 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3626 | i; |
| 3627 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 3628 | ssize_t |
| 3629 | j, |
| 3630 | winding_number; |
| 3631 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3632 | /* |
| 3633 | Compute fill & stroke opacity for this (x,y) point. |
| 3634 | */ |
| 3635 | *stroke_opacity=0.0; |
| 3636 | subpath_opacity=0.0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3637 | p=polygon_info->edges; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3638 | for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3639 | { |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3640 | if (y <= (p->bounds.y1-mid-0.5)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3641 | break; |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3642 | if (y > (p->bounds.y2+mid+0.5)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3643 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3644 | (void) DestroyEdge(polygon_info,(size_t) j); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3645 | continue; |
| 3646 | } |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3647 | 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] | 3648 | continue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3649 | i=(ssize_t) MagickMax((double) p->highwater,1.0); |
| 3650 | for ( ; i < (ssize_t) p->number_points; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3651 | { |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3652 | if (y <= (p->points[i-1].y-mid-0.5)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3653 | break; |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3654 | if (y > (p->points[i].y+mid+0.5)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3655 | continue; |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3656 | if (p->scanline != y) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3657 | { |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3658 | p->scanline=y; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3659 | p->highwater=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3660 | } |
| 3661 | /* |
| 3662 | Compute distance between a point and an edge. |
| 3663 | */ |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3664 | q=p->points+i-1; |
| 3665 | delta.x=(q+1)->x-q->x; |
| 3666 | delta.y=(q+1)->y-q->y; |
| 3667 | beta=delta.x*(x-q->x)+delta.y*(y-q->y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3668 | if (beta < 0.0) |
| 3669 | { |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3670 | delta.x=x-q->x; |
| 3671 | delta.y=y-q->y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3672 | distance=delta.x*delta.x+delta.y*delta.y; |
| 3673 | } |
| 3674 | else |
| 3675 | { |
| 3676 | alpha=delta.x*delta.x+delta.y*delta.y; |
| 3677 | if (beta > alpha) |
| 3678 | { |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3679 | delta.x=x-(q+1)->x; |
| 3680 | delta.y=y-(q+1)->y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3681 | distance=delta.x*delta.x+delta.y*delta.y; |
| 3682 | } |
| 3683 | else |
| 3684 | { |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3685 | alpha=1.0/alpha; |
| 3686 | beta=delta.x*(y-q->y)-delta.y*(x-q->x); |
| 3687 | distance=alpha*beta*beta; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3688 | } |
| 3689 | } |
| 3690 | /* |
| 3691 | Compute stroke & subpath opacity. |
| 3692 | */ |
| 3693 | beta=0.0; |
| 3694 | if (p->ghostline == MagickFalse) |
| 3695 | { |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3696 | alpha=mid+0.5; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3697 | if ((*stroke_opacity < 1.0) && |
| 3698 | (distance <= ((alpha+0.25)*(alpha+0.25)))) |
| 3699 | { |
| 3700 | alpha=mid-0.5; |
| 3701 | if (distance <= ((alpha+0.25)*(alpha+0.25))) |
| 3702 | *stroke_opacity=1.0; |
| 3703 | else |
| 3704 | { |
| 3705 | beta=1.0; |
| 3706 | if (distance != 1.0) |
| 3707 | beta=sqrt((double) distance); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3708 | alpha=beta-mid-0.5; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3709 | if (*stroke_opacity < ((alpha-0.25)*(alpha-0.25))) |
| 3710 | *stroke_opacity=(alpha-0.25)*(alpha-0.25); |
| 3711 | } |
| 3712 | } |
| 3713 | } |
| 3714 | if ((fill == MagickFalse) || (distance > 1.0) || (subpath_opacity >= 1.0)) |
| 3715 | continue; |
| 3716 | if (distance <= 0.0) |
| 3717 | { |
| 3718 | subpath_opacity=1.0; |
| 3719 | continue; |
| 3720 | } |
| 3721 | if (distance > 1.0) |
| 3722 | continue; |
| 3723 | if (beta == 0.0) |
| 3724 | { |
| 3725 | beta=1.0; |
| 3726 | if (distance != 1.0) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3727 | beta=sqrt(distance); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3728 | } |
| 3729 | alpha=beta-1.0; |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3730 | if (subpath_opacity < (alpha*alpha)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3731 | subpath_opacity=alpha*alpha; |
| 3732 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3733 | } |
| 3734 | /* |
| 3735 | Compute fill opacity. |
| 3736 | */ |
| 3737 | if (fill == MagickFalse) |
| 3738 | return(0.0); |
| 3739 | if (subpath_opacity >= 1.0) |
| 3740 | return(1.0); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3741 | /* |
| 3742 | Determine winding number. |
| 3743 | */ |
| 3744 | winding_number=0; |
| 3745 | p=polygon_info->edges; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3746 | for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3747 | { |
| 3748 | if (y <= p->bounds.y1) |
| 3749 | break; |
| 3750 | if ((y > p->bounds.y2) || (x <= p->bounds.x1)) |
| 3751 | continue; |
| 3752 | if (x > p->bounds.x2) |
| 3753 | { |
| 3754 | winding_number+=p->direction ? 1 : -1; |
| 3755 | continue; |
| 3756 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3757 | i=(ssize_t) MagickMax((double) p->highwater,1.0); |
| 3758 | for ( ; i < (ssize_t) p->number_points; i++) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3759 | if (y <= p->points[i].y) |
| 3760 | break; |
| 3761 | q=p->points+i-1; |
| 3762 | if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x))) |
| 3763 | winding_number+=p->direction ? 1 : -1; |
| 3764 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3765 | if (fill_rule != NonZeroRule) |
| 3766 | { |
| 3767 | if ((MagickAbsoluteValue(winding_number) & 0x01) != 0) |
| 3768 | return(1.0); |
| 3769 | } |
| 3770 | else |
| 3771 | if (MagickAbsoluteValue(winding_number) != 0) |
| 3772 | return(1.0); |
| 3773 | return(subpath_opacity); |
| 3774 | } |
| 3775 | |
| 3776 | static MagickBooleanType DrawPolygonPrimitive(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3777 | const DrawInfo *draw_info,const PrimitiveInfo *primitive_info, |
| 3778 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3779 | { |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3780 | CacheView |
| 3781 | *image_view; |
| 3782 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3783 | MagickBooleanType |
| 3784 | fill, |
| 3785 | status; |
| 3786 | |
| 3787 | MagickRealType |
| 3788 | mid; |
| 3789 | |
| 3790 | PolygonInfo |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3791 | **restrict polygon_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3792 | |
| 3793 | register EdgeInfo |
| 3794 | *p; |
| 3795 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3796 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3797 | i; |
| 3798 | |
| 3799 | SegmentInfo |
| 3800 | bounds; |
| 3801 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 3802 | ssize_t |
| 3803 | start, |
| 3804 | stop, |
| 3805 | y; |
| 3806 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3807 | /* |
| 3808 | Compute bounding box. |
| 3809 | */ |
| 3810 | assert(image != (Image *) NULL); |
| 3811 | assert(image->signature == MagickSignature); |
| 3812 | if (image->debug != MagickFalse) |
| 3813 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3814 | assert(draw_info != (DrawInfo *) NULL); |
| 3815 | assert(draw_info->signature == MagickSignature); |
| 3816 | assert(primitive_info != (PrimitiveInfo *) NULL); |
| 3817 | if (primitive_info->coordinates == 0) |
| 3818 | return(MagickTrue); |
| 3819 | polygon_info=AcquirePolygonThreadSet(draw_info,primitive_info); |
| 3820 | if (polygon_info == (PolygonInfo **) NULL) |
| 3821 | return(MagickFalse); |
| 3822 | if (0) |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3823 | DrawBoundingRectangles(image,draw_info,polygon_info[0],exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3824 | if (image->debug != MagickFalse) |
| 3825 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-polygon"); |
| 3826 | fill=(primitive_info->method == FillToBorderMethod) || |
| 3827 | (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse; |
| 3828 | mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0; |
| 3829 | bounds=polygon_info[0]->edges[0].bounds; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3830 | for (i=1; i < (ssize_t) polygon_info[0]->number_edges; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3831 | { |
| 3832 | p=polygon_info[0]->edges+i; |
| 3833 | if (p->bounds.x1 < bounds.x1) |
| 3834 | bounds.x1=p->bounds.x1; |
| 3835 | if (p->bounds.y1 < bounds.y1) |
| 3836 | bounds.y1=p->bounds.y1; |
| 3837 | if (p->bounds.x2 > bounds.x2) |
| 3838 | bounds.x2=p->bounds.x2; |
| 3839 | if (p->bounds.y2 > bounds.y2) |
| 3840 | bounds.y2=p->bounds.y2; |
| 3841 | } |
| 3842 | bounds.x1-=(mid+1.0); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3843 | 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] | 3844 | image->columns ? (double) image->columns-1.0 : bounds.x1; |
| 3845 | bounds.y1-=(mid+1.0); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3846 | 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] | 3847 | image->rows ? (double) image->rows-1.0 : bounds.y1; |
| 3848 | bounds.x2+=(mid+1.0); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3849 | 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] | 3850 | image->columns ? (double) image->columns-1.0 : bounds.x2; |
| 3851 | bounds.y2+=(mid+1.0); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3852 | 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] | 3853 | image->rows ? (double) image->rows-1.0 : bounds.y2; |
| 3854 | status=MagickTrue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3855 | start=(ssize_t) ceil(bounds.x1-0.5); |
| 3856 | stop=(ssize_t) floor(bounds.x2+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3857 | image_view=AcquireCacheView(image); |
| 3858 | if (primitive_info->coordinates == 1) |
| 3859 | { |
| 3860 | /* |
| 3861 | Draw point. |
| 3862 | */ |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3863 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 3864 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3865 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3866 | 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] | 3867 | { |
| 3868 | MagickBooleanType |
| 3869 | sync; |
| 3870 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 3871 | PixelInfo |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3872 | pixel; |
| 3873 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3874 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3875 | x; |
| 3876 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3877 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3878 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3879 | |
| 3880 | if (status == MagickFalse) |
| 3881 | continue; |
| 3882 | x=start; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3883 | q=GetCacheViewAuthenticPixels(image_view,x,y,(size_t) (stop-x+1), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3884 | 1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3885 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3886 | { |
| 3887 | status=MagickFalse; |
| 3888 | continue; |
| 3889 | } |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 3890 | GetPixelInfo(image,&pixel); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3891 | for ( ; x <= stop; x++) |
| 3892 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3893 | if ((x == (ssize_t) ceil(primitive_info->point.x-0.5)) && |
| 3894 | (y == (ssize_t) ceil(primitive_info->point.y-0.5))) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3895 | { |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 3896 | (void) GetStrokeColor(draw_info,x,y,&pixel,exception); |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 3897 | SetPixelPixelInfo(image,&pixel,q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3898 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3899 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3900 | } |
| 3901 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 3902 | if (sync == MagickFalse) |
| 3903 | status=MagickFalse; |
| 3904 | } |
| 3905 | image_view=DestroyCacheView(image_view); |
| 3906 | polygon_info=DestroyPolygonThreadSet(polygon_info); |
| 3907 | if (image->debug != MagickFalse) |
| 3908 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
| 3909 | " end draw-polygon"); |
| 3910 | return(status); |
| 3911 | } |
| 3912 | /* |
| 3913 | Draw polygon or line. |
| 3914 | */ |
| 3915 | if (image->matte == MagickFalse) |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 3916 | (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3917 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 3918 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3919 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3920 | 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] | 3921 | { |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 3922 | const int |
| 3923 | id = GetOpenMPThreadId(); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 3924 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3925 | MagickRealType |
| 3926 | fill_opacity, |
| 3927 | stroke_opacity; |
| 3928 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 3929 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3930 | fill_color, |
| 3931 | stroke_color; |
| 3932 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3933 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3934 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3935 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 3936 | register ssize_t |
| 3937 | x; |
| 3938 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3939 | if (status == MagickFalse) |
| 3940 | continue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3941 | q=GetCacheViewAuthenticPixels(image_view,start,y,(size_t) (stop- |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3942 | start+1),1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3943 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3944 | { |
| 3945 | status=MagickFalse; |
| 3946 | continue; |
| 3947 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3948 | for (x=start; x <= stop; x++) |
| 3949 | { |
| 3950 | /* |
| 3951 | Fill and/or stroke. |
| 3952 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3953 | fill_opacity=GetPixelOpacity(polygon_info[id],mid,fill, |
cristy | 77f38fb | 2010-04-22 15:51:47 +0000 | [diff] [blame] | 3954 | draw_info->fill_rule,(double) x,(double) y,&stroke_opacity); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3955 | if (draw_info->stroke_antialias == MagickFalse) |
| 3956 | { |
| 3957 | fill_opacity=fill_opacity > 0.25 ? 1.0 : 0.0; |
| 3958 | stroke_opacity=stroke_opacity > 0.25 ? 1.0 : 0.0; |
| 3959 | } |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 3960 | (void) GetFillColor(draw_info,x,y,&fill_color,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3961 | fill_opacity=fill_opacity*fill_color.alpha; |
| 3962 | CompositePixelOver(image,&fill_color,fill_opacity,q,(MagickRealType) |
| 3963 | GetPixelAlpha(image,q),q); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 3964 | (void) GetStrokeColor(draw_info,x,y,&stroke_color,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3965 | stroke_opacity=stroke_opacity*stroke_color.alpha; |
| 3966 | CompositePixelOver(image,&stroke_color,stroke_opacity,q,(MagickRealType) |
| 3967 | GetPixelAlpha(image,q),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3968 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3969 | } |
| 3970 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 3971 | status=MagickFalse; |
| 3972 | } |
| 3973 | image_view=DestroyCacheView(image_view); |
| 3974 | polygon_info=DestroyPolygonThreadSet(polygon_info); |
| 3975 | if (image->debug != MagickFalse) |
| 3976 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-polygon"); |
| 3977 | return(status); |
| 3978 | } |
| 3979 | |
| 3980 | /* |
| 3981 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3982 | % % |
| 3983 | % % |
| 3984 | % % |
| 3985 | % D r a w P r i m i t i v e % |
| 3986 | % % |
| 3987 | % % |
| 3988 | % % |
| 3989 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3990 | % |
| 3991 | % DrawPrimitive() draws a primitive (line, rectangle, ellipse) on the image. |
| 3992 | % |
| 3993 | % The format of the DrawPrimitive method is: |
| 3994 | % |
| 3995 | % MagickBooleanType DrawPrimitive(Image *image,const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3996 | % PrimitiveInfo *primitive_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3997 | % |
| 3998 | % A description of each parameter follows: |
| 3999 | % |
| 4000 | % o image: the image. |
| 4001 | % |
| 4002 | % o draw_info: the draw info. |
| 4003 | % |
| 4004 | % o primitive_info: Specifies a pointer to a PrimitiveInfo structure. |
| 4005 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4006 | % o exception: return any errors or warnings in this structure. |
| 4007 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4008 | */ |
| 4009 | |
| 4010 | static void LogPrimitiveInfo(const PrimitiveInfo *primitive_info) |
| 4011 | { |
| 4012 | const char |
| 4013 | *methods[] = |
| 4014 | { |
| 4015 | "point", |
| 4016 | "replace", |
| 4017 | "floodfill", |
| 4018 | "filltoborder", |
| 4019 | "reset", |
| 4020 | "?" |
| 4021 | }; |
| 4022 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4023 | PointInfo |
| 4024 | p, |
| 4025 | q, |
| 4026 | point; |
| 4027 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4028 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4029 | i, |
| 4030 | x; |
| 4031 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 4032 | ssize_t |
| 4033 | coordinates, |
| 4034 | y; |
| 4035 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4036 | x=(ssize_t) ceil(primitive_info->point.x-0.5); |
| 4037 | y=(ssize_t) ceil(primitive_info->point.y-0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4038 | switch (primitive_info->primitive) |
| 4039 | { |
| 4040 | case PointPrimitive: |
| 4041 | { |
| 4042 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4043 | "PointPrimitive %.20g,%.20g %s",(double) x,(double) y, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4044 | methods[primitive_info->method]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4045 | return; |
| 4046 | } |
| 4047 | case ColorPrimitive: |
| 4048 | { |
| 4049 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4050 | "ColorPrimitive %.20g,%.20g %s",(double) x,(double) y, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4051 | methods[primitive_info->method]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4052 | return; |
| 4053 | } |
| 4054 | case MattePrimitive: |
| 4055 | { |
| 4056 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4057 | "MattePrimitive %.20g,%.20g %s",(double) x,(double) y, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4058 | methods[primitive_info->method]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4059 | return; |
| 4060 | } |
| 4061 | case TextPrimitive: |
| 4062 | { |
| 4063 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4064 | "TextPrimitive %.20g,%.20g",(double) x,(double) y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4065 | return; |
| 4066 | } |
| 4067 | case ImagePrimitive: |
| 4068 | { |
| 4069 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4070 | "ImagePrimitive %.20g,%.20g",(double) x,(double) y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4071 | return; |
| 4072 | } |
| 4073 | default: |
| 4074 | break; |
| 4075 | } |
| 4076 | coordinates=0; |
| 4077 | p=primitive_info[0].point; |
| 4078 | q.x=(-1.0); |
| 4079 | q.y=(-1.0); |
| 4080 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) |
| 4081 | { |
| 4082 | point=primitive_info[i].point; |
| 4083 | if (coordinates <= 0) |
| 4084 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4085 | coordinates=(ssize_t) primitive_info[i].coordinates; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4086 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4087 | " begin open (%.20g)",(double) coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4088 | p=point; |
| 4089 | } |
| 4090 | point=primitive_info[i].point; |
| 4091 | if ((fabs(q.x-point.x) > MagickEpsilon) || |
| 4092 | (fabs(q.y-point.y) > MagickEpsilon)) |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 4093 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4094 | " %.20g: %.18g,%.18g",(double) coordinates,point.x,point.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4095 | else |
| 4096 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | 14388de | 2011-05-15 14:57:16 +0000 | [diff] [blame] | 4097 | " %.20g: %g %g (duplicate)",(double) coordinates,point.x,point.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4098 | q=point; |
| 4099 | coordinates--; |
| 4100 | if (coordinates > 0) |
| 4101 | continue; |
| 4102 | if ((fabs(p.x-point.x) > MagickEpsilon) || |
| 4103 | (fabs(p.y-point.y) > MagickEpsilon)) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4104 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end last (%.20g)", |
| 4105 | (double) coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4106 | else |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4107 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end open (%.20g)", |
| 4108 | (double) coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4109 | } |
| 4110 | } |
| 4111 | |
| 4112 | MagickExport MagickBooleanType DrawPrimitive(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4113 | const DrawInfo *draw_info,const PrimitiveInfo *primitive_info, |
| 4114 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4115 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 4116 | CacheView |
| 4117 | *image_view; |
| 4118 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4119 | MagickStatusType |
| 4120 | status; |
| 4121 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4122 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4123 | i, |
| 4124 | x; |
| 4125 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 4126 | ssize_t |
| 4127 | y; |
| 4128 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4129 | if (image->debug != MagickFalse) |
| 4130 | { |
| 4131 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
| 4132 | " begin draw-primitive"); |
| 4133 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | 14388de | 2011-05-15 14:57:16 +0000 | [diff] [blame] | 4134 | " affine: %g %g %g %g %g %g",draw_info->affine.sx, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4135 | draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy, |
| 4136 | draw_info->affine.tx,draw_info->affine.ty); |
| 4137 | } |
| 4138 | status=MagickTrue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4139 | x=(ssize_t) ceil(primitive_info->point.x-0.5); |
| 4140 | y=(ssize_t) ceil(primitive_info->point.y-0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4141 | image_view=AcquireCacheView(image); |
| 4142 | switch (primitive_info->primitive) |
| 4143 | { |
| 4144 | case PointPrimitive: |
| 4145 | { |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4146 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4147 | fill_color; |
| 4148 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4149 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4150 | *q; |
| 4151 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4152 | if ((y < 0) || (y >= (ssize_t) image->rows)) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 4153 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4154 | if ((x < 0) || (x >= (ssize_t) image->columns)) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 4155 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4156 | q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4157 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4158 | break; |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4159 | (void) GetFillColor(draw_info,x,y,&fill_color,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4160 | CompositePixelOver(image,&fill_color,(MagickRealType) fill_color.alpha,q, |
| 4161 | (MagickRealType) GetPixelAlpha(image,q),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4162 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
| 4163 | break; |
| 4164 | } |
| 4165 | case ColorPrimitive: |
| 4166 | { |
| 4167 | switch (primitive_info->method) |
| 4168 | { |
| 4169 | case PointMethod: |
| 4170 | default: |
| 4171 | { |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4172 | PixelInfo |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4173 | pixel; |
| 4174 | |
| 4175 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4176 | *q; |
| 4177 | |
| 4178 | q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4179 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4180 | break; |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4181 | GetPixelInfo(image,&pixel); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4182 | (void) GetFillColor(draw_info,x,y,&pixel,exception); |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4183 | SetPixelPixelInfo(image,&pixel,q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4184 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
| 4185 | break; |
| 4186 | } |
| 4187 | case ReplaceMethod: |
| 4188 | { |
| 4189 | MagickBooleanType |
| 4190 | sync; |
| 4191 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4192 | PixelInfo |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4193 | pixel, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4194 | target; |
| 4195 | |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4196 | Quantum |
| 4197 | virtual_pixel[MaxPixelChannels]; |
| 4198 | |
| 4199 | (void) GetOneCacheViewVirtualPixel(image_view,x,y,virtual_pixel, |
| 4200 | exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 4201 | target.red=(double) virtual_pixel[RedPixelChannel]; |
| 4202 | target.green=(double) virtual_pixel[GreenPixelChannel]; |
| 4203 | target.blue=(double) virtual_pixel[BluePixelChannel]; |
| 4204 | target.alpha=(double) virtual_pixel[AlphaPixelChannel]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4205 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4206 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4207 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4208 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4209 | |
| 4210 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, |
| 4211 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4212 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4213 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4214 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4215 | { |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4216 | GetPixelInfoPixel(image,q,&pixel); |
| 4217 | if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4218 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4219 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4220 | continue; |
| 4221 | } |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4222 | (void) GetFillColor(draw_info,x,y,&pixel,exception); |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4223 | SetPixelPixelInfo(image,&pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4224 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4225 | } |
| 4226 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 4227 | if (sync == MagickFalse) |
| 4228 | break; |
| 4229 | } |
| 4230 | break; |
| 4231 | } |
| 4232 | case FloodfillMethod: |
| 4233 | case FillToBorderMethod: |
| 4234 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4235 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4236 | target; |
| 4237 | |
cristy | 5201002 | 2011-10-21 18:07:37 +0000 | [diff] [blame^] | 4238 | (void) GetOneVirtualMagickPixel(image,TileVirtualPixelMethod,x,y, |
| 4239 | &target,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4240 | if (primitive_info->method == FillToBorderMethod) |
| 4241 | { |
| 4242 | target.red=(MagickRealType) draw_info->border_color.red; |
| 4243 | target.green=(MagickRealType) draw_info->border_color.green; |
| 4244 | target.blue=(MagickRealType) draw_info->border_color.blue; |
| 4245 | } |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 4246 | (void) FloodfillPaintImage(image,draw_info,&target,x,y, |
| 4247 | primitive_info->method == FloodfillMethod ? MagickFalse : |
cristy | 189e84c | 2011-08-27 18:08:53 +0000 | [diff] [blame] | 4248 | MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4249 | break; |
| 4250 | } |
| 4251 | case ResetMethod: |
| 4252 | { |
| 4253 | MagickBooleanType |
| 4254 | sync; |
| 4255 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4256 | PixelInfo |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4257 | pixel; |
| 4258 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4259 | GetPixelInfo(image,&pixel); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4260 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4261 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4262 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4263 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4264 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 4265 | register ssize_t |
| 4266 | x; |
| 4267 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4268 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, |
| 4269 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4270 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4271 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4272 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4273 | { |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4274 | (void) GetFillColor(draw_info,x,y,&pixel,exception); |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4275 | SetPixelPixelInfo(image,&pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4276 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4277 | } |
| 4278 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 4279 | if (sync == MagickFalse) |
| 4280 | break; |
| 4281 | } |
| 4282 | break; |
| 4283 | } |
| 4284 | } |
| 4285 | break; |
| 4286 | } |
| 4287 | case MattePrimitive: |
| 4288 | { |
| 4289 | if (image->matte == MagickFalse) |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 4290 | (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4291 | switch (primitive_info->method) |
| 4292 | { |
| 4293 | case PointMethod: |
| 4294 | default: |
| 4295 | { |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4296 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4297 | pixel; |
| 4298 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4299 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4300 | *q; |
| 4301 | |
| 4302 | q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4303 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4304 | break; |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4305 | (void) GetFillColor(draw_info,x,y,&pixel,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 4306 | SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4307 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
| 4308 | break; |
| 4309 | } |
| 4310 | case ReplaceMethod: |
| 4311 | { |
| 4312 | MagickBooleanType |
| 4313 | sync; |
| 4314 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4315 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4316 | pixel, |
| 4317 | target; |
| 4318 | |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4319 | Quantum |
| 4320 | virtual_pixel[MaxPixelChannels]; |
| 4321 | |
| 4322 | (void) GetOneCacheViewVirtualPixel(image_view,x,y,virtual_pixel, |
| 4323 | exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 4324 | target.red=(double) virtual_pixel[RedPixelChannel]; |
| 4325 | target.green=(double) virtual_pixel[GreenPixelChannel]; |
| 4326 | target.blue=(double) virtual_pixel[BluePixelChannel]; |
| 4327 | target.alpha=(double) virtual_pixel[AlphaPixelChannel]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4328 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4329 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4330 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4331 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4332 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 4333 | register ssize_t |
| 4334 | x; |
| 4335 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4336 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, |
| 4337 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4338 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4339 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4340 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4341 | { |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4342 | GetPixelInfoPixel(image,q,&pixel); |
| 4343 | if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4344 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4345 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4346 | continue; |
| 4347 | } |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4348 | (void) GetFillColor(draw_info,x,y,&pixel,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 4349 | SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q); |
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 | } |
| 4352 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 4353 | if (sync == MagickFalse) |
| 4354 | break; |
| 4355 | } |
| 4356 | break; |
| 4357 | } |
| 4358 | case FloodfillMethod: |
| 4359 | case FillToBorderMethod: |
| 4360 | { |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 4361 | ChannelType |
| 4362 | channel_mask; |
| 4363 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4364 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4365 | target; |
| 4366 | |
cristy | 5201002 | 2011-10-21 18:07:37 +0000 | [diff] [blame^] | 4367 | (void) GetOneVirtualMagickPixel(image,TileVirtualPixelMethod,x,y, |
| 4368 | &target,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4369 | if (primitive_info->method == FillToBorderMethod) |
| 4370 | { |
| 4371 | target.red=(MagickRealType) draw_info->border_color.red; |
| 4372 | target.green=(MagickRealType) draw_info->border_color.green; |
| 4373 | target.blue=(MagickRealType) draw_info->border_color.blue; |
| 4374 | } |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 4375 | channel_mask=SetPixelChannelMask(image,AlphaChannel); |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 4376 | (void) FloodfillPaintImage(image,draw_info,&target,x,y, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4377 | primitive_info->method == FloodfillMethod ? MagickFalse : |
cristy | 189e84c | 2011-08-27 18:08:53 +0000 | [diff] [blame] | 4378 | MagickTrue,exception); |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 4379 | (void) SetPixelChannelMask(image,channel_mask); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4380 | break; |
| 4381 | } |
| 4382 | case ResetMethod: |
| 4383 | { |
| 4384 | MagickBooleanType |
| 4385 | sync; |
| 4386 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4387 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4388 | pixel; |
| 4389 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4390 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4391 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4392 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4393 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4394 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 4395 | register ssize_t |
| 4396 | x; |
| 4397 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4398 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, |
| 4399 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4400 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4401 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4402 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4403 | { |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4404 | (void) GetFillColor(draw_info,x,y,&pixel,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 4405 | SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4406 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4407 | } |
| 4408 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 4409 | if (sync == MagickFalse) |
| 4410 | break; |
| 4411 | } |
| 4412 | break; |
| 4413 | } |
| 4414 | } |
| 4415 | break; |
| 4416 | } |
| 4417 | case TextPrimitive: |
| 4418 | { |
| 4419 | char |
| 4420 | geometry[MaxTextExtent]; |
| 4421 | |
| 4422 | DrawInfo |
| 4423 | *clone_info; |
| 4424 | |
| 4425 | if (primitive_info->text == (char *) NULL) |
| 4426 | break; |
| 4427 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 4428 | (void) CloneString(&clone_info->text,primitive_info->text); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4429 | (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4430 | primitive_info->point.x,primitive_info->point.y); |
| 4431 | (void) CloneString(&clone_info->geometry,geometry); |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 4432 | status=AnnotateImage(image,clone_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4433 | clone_info=DestroyDrawInfo(clone_info); |
| 4434 | break; |
| 4435 | } |
| 4436 | case ImagePrimitive: |
| 4437 | { |
| 4438 | AffineMatrix |
| 4439 | affine; |
| 4440 | |
| 4441 | char |
| 4442 | composite_geometry[MaxTextExtent]; |
| 4443 | |
| 4444 | Image |
| 4445 | *composite_image; |
| 4446 | |
| 4447 | ImageInfo |
| 4448 | *clone_info; |
| 4449 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 4450 | RectangleInfo |
| 4451 | geometry; |
| 4452 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4453 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4454 | x1, |
| 4455 | y1; |
| 4456 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4457 | if (primitive_info->text == (char *) NULL) |
| 4458 | break; |
| 4459 | clone_info=AcquireImageInfo(); |
| 4460 | if (LocaleNCompare(primitive_info->text,"data:",5) == 0) |
| 4461 | composite_image=ReadInlineImage(clone_info,primitive_info->text, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4462 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4463 | else |
| 4464 | { |
| 4465 | (void) CopyMagickString(clone_info->filename,primitive_info->text, |
| 4466 | MaxTextExtent); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4467 | composite_image=ReadImage(clone_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4468 | } |
| 4469 | clone_info=DestroyImageInfo(clone_info); |
| 4470 | if (composite_image == (Image *) NULL) |
| 4471 | break; |
| 4472 | (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor) |
| 4473 | NULL,(void *) NULL); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4474 | x1=(ssize_t) ceil(primitive_info[1].point.x-0.5); |
| 4475 | y1=(ssize_t) ceil(primitive_info[1].point.y-0.5); |
| 4476 | if (((x1 != 0L) && (x1 != (ssize_t) composite_image->columns)) || |
| 4477 | ((y1 != 0L) && (y1 != (ssize_t) composite_image->rows))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4478 | { |
| 4479 | char |
| 4480 | geometry[MaxTextExtent]; |
| 4481 | |
| 4482 | /* |
| 4483 | Resize image. |
| 4484 | */ |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4485 | (void) FormatLocaleString(geometry,MaxTextExtent,"%gx%g!", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4486 | primitive_info[1].point.x,primitive_info[1].point.y); |
| 4487 | composite_image->filter=image->filter; |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 4488 | (void) TransformImage(&composite_image,(char *) NULL,geometry, |
| 4489 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4490 | } |
| 4491 | if (composite_image->matte == MagickFalse) |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 4492 | (void) SetImageAlphaChannel(composite_image,OpaqueAlphaChannel, |
| 4493 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4494 | if (draw_info->alpha != OpaqueAlpha) |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 4495 | (void) SetImageAlpha(composite_image,draw_info->alpha,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4496 | SetGeometry(image,&geometry); |
| 4497 | image->gravity=draw_info->gravity; |
| 4498 | geometry.x=x; |
| 4499 | geometry.y=y; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4500 | (void) FormatLocaleString(composite_geometry,MaxTextExtent, |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 4501 | "%.20gx%.20g%+.20g%+.20g",(double) composite_image->columns,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4502 | composite_image->rows,(double) geometry.x,(double) geometry.y); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4503 | (void) ParseGravityGeometry(image,composite_geometry,&geometry,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4504 | affine=draw_info->affine; |
| 4505 | affine.tx=(double) geometry.x; |
| 4506 | affine.ty=(double) geometry.y; |
| 4507 | composite_image->interpolate=image->interpolate; |
cristy | d5f3fc3 | 2011-04-26 14:44:36 +0000 | [diff] [blame] | 4508 | if (draw_info->compose == OverCompositeOp) |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4509 | (void) DrawAffineImage(image,composite_image,&affine,exception); |
cristy | d5f3fc3 | 2011-04-26 14:44:36 +0000 | [diff] [blame] | 4510 | else |
| 4511 | (void) CompositeImage(image,draw_info->compose,composite_image, |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 4512 | geometry.x,geometry.y,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4513 | composite_image=DestroyImage(composite_image); |
| 4514 | break; |
| 4515 | } |
| 4516 | default: |
| 4517 | { |
| 4518 | MagickRealType |
| 4519 | mid, |
| 4520 | scale; |
| 4521 | |
| 4522 | DrawInfo |
| 4523 | *clone_info; |
| 4524 | |
| 4525 | if (IsEventLogging() != MagickFalse) |
| 4526 | LogPrimitiveInfo(primitive_info); |
| 4527 | scale=ExpandAffine(&draw_info->affine); |
| 4528 | if ((draw_info->dash_pattern != (double *) NULL) && |
| 4529 | (draw_info->dash_pattern[0] != 0.0) && |
| 4530 | ((scale*draw_info->stroke_width) > MagickEpsilon) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4531 | (draw_info->stroke.alpha != (Quantum) TransparentAlpha)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4532 | { |
| 4533 | /* |
| 4534 | Draw dash polygon. |
| 4535 | */ |
| 4536 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 4537 | clone_info->stroke_width=0.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4538 | clone_info->stroke.alpha=(Quantum) TransparentAlpha; |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4539 | status=DrawPolygonPrimitive(image,clone_info,primitive_info, |
| 4540 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4541 | clone_info=DestroyDrawInfo(clone_info); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4542 | (void) DrawDashPolygon(draw_info,primitive_info,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4543 | break; |
| 4544 | } |
| 4545 | mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0; |
| 4546 | if ((mid > 1.0) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4547 | (draw_info->stroke.alpha != (Quantum) TransparentAlpha)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4548 | { |
| 4549 | MagickBooleanType |
| 4550 | closed_path; |
| 4551 | |
| 4552 | /* |
| 4553 | Draw strokes while respecting line cap/join attributes. |
| 4554 | */ |
| 4555 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ; |
| 4556 | closed_path= |
| 4557 | (primitive_info[i-1].point.x == primitive_info[0].point.x) && |
| 4558 | (primitive_info[i-1].point.y == primitive_info[0].point.y) ? |
| 4559 | MagickTrue : MagickFalse; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4560 | i=(ssize_t) primitive_info[0].coordinates; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4561 | if ((((draw_info->linecap == RoundCap) || |
| 4562 | (closed_path != MagickFalse)) && |
| 4563 | (draw_info->linejoin == RoundJoin)) || |
| 4564 | (primitive_info[i].primitive != UndefinedPrimitive)) |
| 4565 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4566 | (void) DrawPolygonPrimitive(image,draw_info,primitive_info, |
| 4567 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4568 | break; |
| 4569 | } |
| 4570 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 4571 | clone_info->stroke_width=0.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4572 | clone_info->stroke.alpha=(Quantum) TransparentAlpha; |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4573 | status=DrawPolygonPrimitive(image,clone_info,primitive_info, |
| 4574 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4575 | clone_info=DestroyDrawInfo(clone_info); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4576 | status|=DrawStrokePolygon(image,draw_info,primitive_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4577 | break; |
| 4578 | } |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4579 | status=DrawPolygonPrimitive(image,draw_info,primitive_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4580 | break; |
| 4581 | } |
| 4582 | } |
| 4583 | image_view=DestroyCacheView(image_view); |
| 4584 | if (image->debug != MagickFalse) |
| 4585 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-primitive"); |
| 4586 | return(status != 0 ? MagickTrue : MagickFalse); |
| 4587 | } |
| 4588 | |
| 4589 | /* |
| 4590 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4591 | % % |
| 4592 | % % |
| 4593 | % % |
| 4594 | + D r a w S t r o k e P o l y g o n % |
| 4595 | % % |
| 4596 | % % |
| 4597 | % % |
| 4598 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4599 | % |
| 4600 | % DrawStrokePolygon() draws a stroked polygon (line, rectangle, ellipse) on |
| 4601 | % the image while respecting the line cap and join attributes. |
| 4602 | % |
| 4603 | % The format of the DrawStrokePolygon method is: |
| 4604 | % |
| 4605 | % MagickBooleanType DrawStrokePolygon(Image *image, |
| 4606 | % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info) |
| 4607 | % |
| 4608 | % A description of each parameter follows: |
| 4609 | % |
| 4610 | % o image: the image. |
| 4611 | % |
| 4612 | % o draw_info: the draw info. |
| 4613 | % |
| 4614 | % o primitive_info: Specifies a pointer to a PrimitiveInfo structure. |
| 4615 | % |
| 4616 | % |
| 4617 | */ |
| 4618 | |
| 4619 | static void DrawRoundLinecap(Image *image,const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4620 | const PrimitiveInfo *primitive_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4621 | { |
| 4622 | PrimitiveInfo |
| 4623 | linecap[5]; |
| 4624 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4625 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4626 | i; |
| 4627 | |
| 4628 | for (i=0; i < 4; i++) |
| 4629 | linecap[i]=(*primitive_info); |
| 4630 | linecap[0].coordinates=4; |
| 4631 | linecap[1].point.x+=(double) (10.0*MagickEpsilon); |
| 4632 | linecap[2].point.x+=(double) (10.0*MagickEpsilon); |
| 4633 | linecap[2].point.y+=(double) (10.0*MagickEpsilon); |
| 4634 | linecap[3].point.y+=(double) (10.0*MagickEpsilon); |
| 4635 | linecap[4].primitive=UndefinedPrimitive; |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4636 | (void) DrawPolygonPrimitive(image,draw_info,linecap,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | static MagickBooleanType DrawStrokePolygon(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4640 | const DrawInfo *draw_info,const PrimitiveInfo *primitive_info, |
| 4641 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4672 | status=DrawPolygonPrimitive(image,clone_info,stroke_polygon,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4679 | DrawRoundLinecap(image,draw_info,p,exception); |
| 4680 | DrawRoundLinecap(image,draw_info,q,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4754 | /* |
| 4755 | Initialize draw attributes. |
| 4756 | */ |
| 4757 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 4758 | assert(draw_info != (DrawInfo *) NULL); |
| 4759 | (void) ResetMagickMemory(draw_info,0,sizeof(*draw_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4760 | GetAffineMatrix(&draw_info->affine); |
| 4761 | exception=AcquireExceptionInfo(); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 4762 | (void) QueryColorCompliance("#000F",AllCompliance,&draw_info->fill, |
| 4763 | exception); |
| 4764 | (void) QueryColorCompliance("#FFF0",AllCompliance,&draw_info->stroke, |
| 4765 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4766 | draw_info->stroke_width=1.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4767 | draw_info->alpha=OpaqueAlpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4768 | draw_info->fill_rule=EvenOddRule; |
| 4769 | draw_info->linecap=ButtCap; |
| 4770 | draw_info->linejoin=MiterJoin; |
| 4771 | draw_info->miterlimit=10; |
| 4772 | draw_info->decorate=NoDecoration; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4773 | draw_info->pointsize=12.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4774 | draw_info->undercolor.alpha=(Quantum) TransparentAlpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4775 | draw_info->compose=OverCompositeOp; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4776 | draw_info->render=MagickTrue; |
| 4777 | draw_info->debug=IsEventLogging(); |
cristy | 0245b5d | 2011-10-05 12:03:49 +0000 | [diff] [blame] | 4778 | if (image_info != (ImageInfo *) NULL) |
| 4779 | { |
| 4780 | draw_info->stroke_antialias=image_info->antialias; |
| 4781 | if (image_info->font != (char *) NULL) |
| 4782 | draw_info->font=AcquireString(image_info->font); |
| 4783 | if (image_info->density != (char *) NULL) |
| 4784 | draw_info->density=AcquireString(image_info->density); |
| 4785 | draw_info->text_antialias=image_info->antialias; |
| 4786 | if (image_info->pointsize != 0.0) |
| 4787 | draw_info->pointsize=image_info->pointsize; |
| 4788 | draw_info->border_color=image_info->border_color; |
| 4789 | if (image_info->server_name != (char *) NULL) |
| 4790 | draw_info->server_name=AcquireString(image_info->server_name); |
| 4791 | option=GetImageOption(image_info,"encoding"); |
| 4792 | if (option != (const char *) NULL) |
| 4793 | (void) CloneString(&draw_info->encoding,option); |
| 4794 | option=GetImageOption(image_info,"kerning"); |
| 4795 | if (option != (const char *) NULL) |
| 4796 | draw_info->kerning=InterpretLocaleValue(option,(char **) NULL); |
| 4797 | option=GetImageOption(image_info,"interline-spacing"); |
| 4798 | if (option != (const char *) NULL) |
| 4799 | draw_info->interline_spacing=InterpretLocaleValue(option, |
| 4800 | (char **) NULL); |
| 4801 | draw_info->direction=UndefinedDirection; |
| 4802 | option=GetImageOption(image_info,"interword-spacing"); |
| 4803 | if (option != (const char *) NULL) |
| 4804 | draw_info->interword_spacing=InterpretLocaleValue(option, |
| 4805 | (char **) NULL); |
| 4806 | option=GetImageOption(image_info,"direction"); |
| 4807 | if (option != (const char *) NULL) |
| 4808 | draw_info->direction=(DirectionType) ParseCommandOption( |
| 4809 | MagickDirectionOptions,MagickFalse,option); |
| 4810 | option=GetImageOption(image_info,"fill"); |
| 4811 | if (option != (const char *) NULL) |
| 4812 | (void) QueryColorCompliance(option,AllCompliance,&draw_info->fill, |
| 4813 | exception); |
| 4814 | option=GetImageOption(image_info,"stroke"); |
| 4815 | if (option != (const char *) NULL) |
| 4816 | (void) QueryColorCompliance(option,AllCompliance,&draw_info->stroke, |
| 4817 | exception); |
| 4818 | option=GetImageOption(image_info,"strokewidth"); |
| 4819 | if (option != (const char *) NULL) |
| 4820 | draw_info->stroke_width=InterpretLocaleValue(option,(char **) NULL); |
| 4821 | option=GetImageOption(image_info,"undercolor"); |
| 4822 | if (option != (const char *) NULL) |
| 4823 | (void) QueryColorCompliance(option,AllCompliance,&draw_info->undercolor, |
| 4824 | exception); |
| 4825 | option=GetImageOption(image_info,"gravity"); |
| 4826 | if (option != (const char *) NULL) |
| 4827 | draw_info->gravity=(GravityType) ParseCommandOption( |
| 4828 | MagickGravityOptions,MagickFalse,option); |
| 4829 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4830 | exception=DestroyExceptionInfo(exception); |
| 4831 | draw_info->signature=MagickSignature; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | } |