2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 % D D RRRR AAAAA W W W %
13 % MagickCore Image Drawing Methods %
21 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
22 % dedicated to making software imaging solutions freely available. %
24 % You may not use this file except in compliance with the License. You may %
25 % obtain a copy of the License at %
27 % http://www.imagemagick.org/script/license.php %
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. %
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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.
48 #include "magick/studio.h"
49 #include "magick/annotate.h"
50 #include "magick/artifact.h"
51 #include "magick/blob.h"
52 #include "magick/cache.h"
53 #include "magick/cache-view.h"
54 #include "magick/color.h"
55 #include "magick/composite.h"
56 #include "magick/composite-private.h"
57 #include "magick/constitute.h"
58 #include "magick/draw.h"
59 #include "magick/draw-private.h"
60 #include "magick/enhance.h"
61 #include "magick/exception.h"
62 #include "magick/exception-private.h"
63 #include "magick/gem.h"
64 #include "magick/geometry.h"
65 #include "magick/image-private.h"
66 #include "magick/list.h"
67 #include "magick/log.h"
68 #include "magick/monitor.h"
69 #include "magick/monitor-private.h"
70 #include "magick/option.h"
71 #include "magick/paint.h"
72 #include "magick/pixel-private.h"
73 #include "magick/property.h"
74 #include "magick/resample.h"
75 #include "magick/resample-private.h"
76 #include "magick/string_.h"
77 #include "magick/string-private.h"
78 #include "magick/thread-private.h"
79 #include "magick/token.h"
80 #include "magick/transform.h"
81 #include "magick/utility.h"
86 #define BezierQuantum 200
91 typedef struct _EdgeInfo
115 typedef struct _ElementInfo
125 typedef struct _PolygonInfo
143 typedef struct _PathInfo
153 Forward declarations.
155 static MagickBooleanType
156 DrawStrokePolygon(Image *,const DrawInfo *,const PrimitiveInfo *);
159 *TraceStrokePolygon(const DrawInfo *,const PrimitiveInfo *);
162 TracePath(PrimitiveInfo *,const char *);
165 TraceArc(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo),
166 TraceArcPath(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo,
167 const MagickRealType,const MagickBooleanType,const MagickBooleanType),
168 TraceBezier(PrimitiveInfo *,const size_t),
169 TraceCircle(PrimitiveInfo *,const PointInfo,const PointInfo),
170 TraceEllipse(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo),
171 TraceLine(PrimitiveInfo *,const PointInfo,const PointInfo),
172 TraceRectangle(PrimitiveInfo *,const PointInfo,const PointInfo),
173 TraceRoundRectangle(PrimitiveInfo *,const PointInfo,const PointInfo,
175 TraceSquareLinecap(PrimitiveInfo *,const size_t,const MagickRealType);
178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 % A c q u i r e D r a w I n f o %
186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188 % AcquireDrawInfo() returns a DrawInfo structure properly initialized.
190 % The format of the AcquireDrawInfo method is:
192 % DrawInfo *AcquireDrawInfo(void)
195 MagickExport DrawInfo *AcquireDrawInfo(void)
200 draw_info=(DrawInfo *) AcquireMagickMemory(sizeof(*draw_info));
201 if (draw_info == (DrawInfo *) NULL)
202 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
203 GetDrawInfo((ImageInfo *) NULL,draw_info);
208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212 % C l o n e D r a w I n f o %
216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 % CloneDrawInfo() makes a copy of the given draw info structure. If NULL
219 % is specified, a new image info structure is created initialized to
222 % The format of the CloneDrawInfo method is:
224 % DrawInfo *CloneDrawInfo(const ImageInfo *image_info,
225 % const DrawInfo *draw_info)
227 % A description of each parameter follows:
229 % o image_info: the image info.
231 % o draw_info: the draw info.
234 MagickExport DrawInfo *CloneDrawInfo(const ImageInfo *image_info,
235 const DrawInfo *draw_info)
240 clone_info=(DrawInfo *) AcquireMagickMemory(sizeof(*clone_info));
241 if (clone_info == (DrawInfo *) NULL)
242 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
243 GetDrawInfo(image_info,clone_info);
244 if (draw_info == (DrawInfo *) NULL)
246 if (clone_info->primitive != (char *) NULL)
247 (void) CloneString(&clone_info->primitive,draw_info->primitive);
248 if (draw_info->geometry != (char *) NULL)
249 (void) CloneString(&clone_info->geometry,draw_info->geometry);
250 clone_info->viewbox=draw_info->viewbox;
251 clone_info->affine=draw_info->affine;
252 clone_info->gravity=draw_info->gravity;
253 clone_info->fill=draw_info->fill;
254 clone_info->stroke=draw_info->stroke;
255 clone_info->stroke_width=draw_info->stroke_width;
256 if (draw_info->fill_pattern != (Image *) NULL)
257 clone_info->fill_pattern=CloneImage(draw_info->fill_pattern,0,0,MagickTrue,
258 &draw_info->fill_pattern->exception);
260 if (draw_info->tile != (Image *) NULL)
261 clone_info->fill_pattern=CloneImage(draw_info->tile,0,0,MagickTrue,
262 &draw_info->tile->exception);
263 clone_info->tile=NewImageList(); /* tile is deprecated */
264 if (draw_info->stroke_pattern != (Image *) NULL)
265 clone_info->stroke_pattern=CloneImage(draw_info->stroke_pattern,0,0,
266 MagickTrue,&draw_info->stroke_pattern->exception);
267 clone_info->stroke_antialias=draw_info->stroke_antialias;
268 clone_info->text_antialias=draw_info->text_antialias;
269 clone_info->fill_rule=draw_info->fill_rule;
270 clone_info->linecap=draw_info->linecap;
271 clone_info->linejoin=draw_info->linejoin;
272 clone_info->miterlimit=draw_info->miterlimit;
273 clone_info->dash_offset=draw_info->dash_offset;
274 clone_info->decorate=draw_info->decorate;
275 clone_info->compose=draw_info->compose;
276 if (draw_info->text != (char *) NULL)
277 (void) CloneString(&clone_info->text,draw_info->text);
278 if (draw_info->font != (char *) NULL)
279 (void) CloneString(&clone_info->font,draw_info->font);
280 if (draw_info->metrics != (char *) NULL)
281 (void) CloneString(&clone_info->metrics,draw_info->metrics);
282 if (draw_info->family != (char *) NULL)
283 (void) CloneString(&clone_info->family,draw_info->family);
284 clone_info->style=draw_info->style;
285 clone_info->stretch=draw_info->stretch;
286 clone_info->weight=draw_info->weight;
287 if (draw_info->encoding != (char *) NULL)
288 (void) CloneString(&clone_info->encoding,draw_info->encoding);
289 clone_info->pointsize=draw_info->pointsize;
290 clone_info->kerning=draw_info->kerning;
291 clone_info->interline_spacing=draw_info->interline_spacing;
292 clone_info->interword_spacing=draw_info->interword_spacing;
293 clone_info->direction=draw_info->direction;
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)
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));
315 clone_info->gradient=draw_info->gradient;
316 if (draw_info->gradient.stops != (StopInfo *) NULL)
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));
331 if (draw_info->clip_mask != (char *) NULL)
332 (void) CloneString(&clone_info->clip_mask,draw_info->clip_mask);
333 clone_info->bounds=draw_info->bounds;
334 clone_info->clip_units=draw_info->clip_units;
335 clone_info->render=draw_info->render;
336 clone_info->opacity=draw_info->opacity;
337 clone_info->element_reference=draw_info->element_reference;
338 clone_info->debug=IsEventLogging();
343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
347 + C o n v e r t P a t h T o P o l y g o n %
351 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353 % ConvertPathToPolygon() converts a path to the more efficient sorted
356 % The format of the ConvertPathToPolygon method is:
358 % PolygonInfo *ConvertPathToPolygon(const DrawInfo *draw_info,
359 % const PathInfo *path_info)
361 % A description of each parameter follows:
363 % o Method ConvertPathToPolygon returns the path in a more efficient sorted
364 % rendering form of type PolygonInfo.
366 % o draw_info: Specifies a pointer to an DrawInfo structure.
368 % o path_info: Specifies a pointer to an PathInfo structure.
373 #if defined(__cplusplus) || defined(c_plusplus)
377 static int CompareEdges(const void *x,const void *y)
379 register const EdgeInfo
386 p=(const EdgeInfo *) x;
387 q=(const EdgeInfo *) y;
388 if ((p->points[0].y-MagickEpsilon) > q->points[0].y)
390 if ((p->points[0].y+MagickEpsilon) < q->points[0].y)
392 if ((p->points[0].x-MagickEpsilon) > q->points[0].x)
394 if ((p->points[0].x+MagickEpsilon) < q->points[0].x)
396 if (((p->points[1].x-p->points[0].x)*(q->points[1].y-q->points[0].y)-
397 (p->points[1].y-p->points[0].y)*(q->points[1].x-q->points[0].x)) > 0.0)
402 #if defined(__cplusplus) || defined(c_plusplus)
406 static void LogPolygonInfo(const PolygonInfo *polygon_info)
415 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin active-edge");
416 p=polygon_info->edges;
417 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
419 (void) LogMagickEvent(DrawEvent,GetMagickModule()," edge %.20g:",
421 (void) LogMagickEvent(DrawEvent,GetMagickModule()," direction: %s",
422 p->direction != MagickFalse ? "down" : "up");
423 (void) LogMagickEvent(DrawEvent,GetMagickModule()," ghostline: %s",
424 p->ghostline != MagickFalse ? "transparent" : "opaque");
425 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
426 " bounds: %g,%g - %g,%g",p->bounds.x1,p->bounds.y1,
427 p->bounds.x2,p->bounds.y2);
428 for (j=0; j < (ssize_t) p->number_points; j++)
429 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %g,%g",
430 p->points[j].x,p->points[j].y);
433 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end active-edge");
436 static void ReversePoints(PointInfo *points,const size_t number_points)
444 for (i=0; i < (ssize_t) (number_points >> 1); i++)
447 points[i]=points[number_points-(i+1)];
448 points[number_points-(i+1)]=point;
452 static PolygonInfo *ConvertPathToPolygon(
453 const DrawInfo *magick_unused(draw_info),const PathInfo *path_info)
482 Convert a path to the more efficient sorted rendering form.
484 polygon_info=(PolygonInfo *) AcquireMagickMemory(sizeof(*polygon_info));
485 if (polygon_info == (PolygonInfo *) NULL)
486 return((PolygonInfo *) NULL);
488 polygon_info->edges=(EdgeInfo *) AcquireQuantumMemory((size_t) number_edges,
489 sizeof(*polygon_info->edges));
490 if (polygon_info->edges == (EdgeInfo *) NULL)
491 return((PolygonInfo *) NULL);
494 ghostline=MagickFalse;
497 points=(PointInfo *) NULL;
498 (void) ResetMagickMemory(&point,0,sizeof(point));
499 (void) ResetMagickMemory(&bounds,0,sizeof(bounds));
500 for (i=0; path_info[i].code != EndCode; i++)
502 if ((path_info[i].code == MoveToCode) || (path_info[i].code == OpenCode) ||
503 (path_info[i].code == GhostlineCode))
508 if ((points != (PointInfo *) NULL) && (n >= 2))
510 if (edge == number_edges)
513 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
514 polygon_info->edges,(size_t) number_edges,
515 sizeof(*polygon_info->edges));
516 if (polygon_info->edges == (EdgeInfo *) NULL)
517 return((PolygonInfo *) NULL);
519 polygon_info->edges[edge].number_points=(size_t) n;
520 polygon_info->edges[edge].scanline=(-1.0);
521 polygon_info->edges[edge].highwater=0;
522 polygon_info->edges[edge].ghostline=ghostline;
523 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
525 ReversePoints(points,(size_t) n);
526 polygon_info->edges[edge].points=points;
527 polygon_info->edges[edge].bounds=bounds;
528 polygon_info->edges[edge].bounds.y1=points[0].y;
529 polygon_info->edges[edge].bounds.y2=points[n-1].y;
530 points=(PointInfo *) NULL;
531 ghostline=MagickFalse;
534 if (points == (PointInfo *) NULL)
537 points=(PointInfo *) AcquireQuantumMemory((size_t) number_points,
539 if (points == (PointInfo *) NULL)
540 return((PolygonInfo *) NULL);
542 ghostline=path_info[i].code == GhostlineCode ? MagickTrue : MagickFalse;
543 point=path_info[i].point;
554 next_direction=((path_info[i].point.y > point.y) ||
555 ((path_info[i].point.y == point.y) &&
556 (path_info[i].point.x > point.x))) ? 1 : -1;
557 if ((direction != 0) && (direction != next_direction))
563 if (edge == number_edges)
566 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
567 polygon_info->edges,(size_t) number_edges,
568 sizeof(*polygon_info->edges));
569 if (polygon_info->edges == (EdgeInfo *) NULL)
570 return((PolygonInfo *) NULL);
572 polygon_info->edges[edge].number_points=(size_t) n;
573 polygon_info->edges[edge].scanline=(-1.0);
574 polygon_info->edges[edge].highwater=0;
575 polygon_info->edges[edge].ghostline=ghostline;
576 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
578 ReversePoints(points,(size_t) n);
579 polygon_info->edges[edge].points=points;
580 polygon_info->edges[edge].bounds=bounds;
581 polygon_info->edges[edge].bounds.y1=points[0].y;
582 polygon_info->edges[edge].bounds.y2=points[n-1].y;
584 points=(PointInfo *) AcquireQuantumMemory((size_t) number_points,
586 if (points == (PointInfo *) NULL)
587 return((PolygonInfo *) NULL);
589 ghostline=MagickFalse;
595 direction=next_direction;
596 if (points == (PointInfo *) NULL)
598 if (n == (ssize_t) number_points)
601 points=(PointInfo *) ResizeQuantumMemory(points,(size_t) number_points,
603 if (points == (PointInfo *) NULL)
604 return((PolygonInfo *) NULL);
606 point=path_info[i].point;
608 if (point.x < bounds.x1)
610 if (point.x > bounds.x2)
614 if (points != (PointInfo *) NULL)
617 points=(PointInfo *) RelinquishMagickMemory(points);
620 if (edge == number_edges)
623 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
624 polygon_info->edges,(size_t) number_edges,
625 sizeof(*polygon_info->edges));
626 if (polygon_info->edges == (EdgeInfo *) NULL)
627 return((PolygonInfo *) NULL);
629 polygon_info->edges[edge].number_points=(size_t) n;
630 polygon_info->edges[edge].scanline=(-1.0);
631 polygon_info->edges[edge].highwater=0;
632 polygon_info->edges[edge].ghostline=ghostline;
633 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
635 ReversePoints(points,(size_t) n);
636 polygon_info->edges[edge].points=points;
637 polygon_info->edges[edge].bounds=bounds;
638 polygon_info->edges[edge].bounds.y1=points[0].y;
639 polygon_info->edges[edge].bounds.y2=points[n-1].y;
640 ghostline=MagickFalse;
644 polygon_info->number_edges=edge;
645 qsort(polygon_info->edges,(size_t) polygon_info->number_edges,
646 sizeof(*polygon_info->edges),CompareEdges);
647 if (IsEventLogging() != MagickFalse)
648 LogPolygonInfo(polygon_info);
649 return(polygon_info);
653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
657 + C o n v e r t P r i m i t i v e T o P a t h %
661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
663 % ConvertPrimitiveToPath() converts a PrimitiveInfo structure into a vector
666 % The format of the ConvertPrimitiveToPath method is:
668 % PathInfo *ConvertPrimitiveToPath(const DrawInfo *draw_info,
669 % const PrimitiveInfo *primitive_info)
671 % A description of each parameter follows:
673 % o Method ConvertPrimitiveToPath returns a vector path structure of type
676 % o draw_info: a structure of type DrawInfo.
678 % o primitive_info: Specifies a pointer to an PrimitiveInfo structure.
683 static void LogPathInfo(const PathInfo *path_info)
685 register const PathInfo
688 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin vector-path");
689 for (p=path_info; p->code != EndCode; p++)
690 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
691 " %g,%g %s",p->point.x,p->point.y,p->code == GhostlineCode ?
692 "moveto ghostline" : p->code == OpenCode ? "moveto open" :
693 p->code == MoveToCode ? "moveto" : p->code == LineToCode ? "lineto" :
695 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end vector-path");
698 static PathInfo *ConvertPrimitiveToPath(
699 const DrawInfo *magick_unused(draw_info),const PrimitiveInfo *primitive_info)
720 Converts a PrimitiveInfo structure into a vector path structure.
722 switch (primitive_info->primitive)
729 return((PathInfo *) NULL);
733 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
734 path_info=(PathInfo *) AcquireQuantumMemory((size_t) (2UL*i+3UL),
736 if (path_info == (PathInfo *) NULL)
737 return((PathInfo *) NULL);
745 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
748 if (coordinates <= 0)
750 coordinates=(ssize_t) primitive_info[i].coordinates;
751 p=primitive_info[i].point;
757 Eliminate duplicate points.
759 if ((i == 0) || (fabs(q.x-primitive_info[i].point.x) > MagickEpsilon) ||
760 (fabs(q.y-primitive_info[i].point.y) > MagickEpsilon))
762 path_info[n].code=code;
763 path_info[n].point=primitive_info[i].point;
764 q=primitive_info[i].point;
769 if ((fabs(p.x-primitive_info[i].point.x) <= MagickEpsilon) &&
770 (fabs(p.y-primitive_info[i].point.y) <= MagickEpsilon))
773 Mark the p point as open if it does not match the q.
775 path_info[start].code=OpenCode;
776 path_info[n].code=GhostlineCode;
777 path_info[n].point=primitive_info[i].point;
779 path_info[n].code=LineToCode;
780 path_info[n].point=p;
783 path_info[n].code=EndCode;
784 path_info[n].point.x=0.0;
785 path_info[n].point.y=0.0;
786 if (IsEventLogging() != MagickFalse)
787 LogPathInfo(path_info);
792 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
796 % D e s t r o y D r a w I n f o %
800 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
802 % DestroyDrawInfo() deallocates memory associated with an DrawInfo
805 % The format of the DestroyDrawInfo method is:
807 % DrawInfo *DestroyDrawInfo(DrawInfo *draw_info)
809 % A description of each parameter follows:
811 % o draw_info: the draw info.
814 MagickExport DrawInfo *DestroyDrawInfo(DrawInfo *draw_info)
816 if (draw_info->debug != MagickFalse)
817 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
818 assert(draw_info != (DrawInfo *) NULL);
819 assert(draw_info->signature == MagickSignature);
820 if (draw_info->primitive != (char *) NULL)
821 draw_info->primitive=DestroyString(draw_info->primitive);
822 if (draw_info->text != (char *) NULL)
823 draw_info->text=DestroyString(draw_info->text);
824 if (draw_info->geometry != (char *) NULL)
825 draw_info->geometry=DestroyString(draw_info->geometry);
826 if (draw_info->tile != (Image *) NULL)
827 draw_info->tile=DestroyImage(draw_info->tile);
828 if (draw_info->fill_pattern != (Image *) NULL)
829 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
830 if (draw_info->stroke_pattern != (Image *) NULL)
831 draw_info->stroke_pattern=DestroyImage(draw_info->stroke_pattern);
832 if (draw_info->font != (char *) NULL)
833 draw_info->font=DestroyString(draw_info->font);
834 if (draw_info->metrics != (char *) NULL)
835 draw_info->metrics=DestroyString(draw_info->metrics);
836 if (draw_info->family != (char *) NULL)
837 draw_info->family=DestroyString(draw_info->family);
838 if (draw_info->encoding != (char *) NULL)
839 draw_info->encoding=DestroyString(draw_info->encoding);
840 if (draw_info->density != (char *) NULL)
841 draw_info->density=DestroyString(draw_info->density);
842 if (draw_info->server_name != (char *) NULL)
843 draw_info->server_name=(char *)
844 RelinquishMagickMemory(draw_info->server_name);
845 if (draw_info->dash_pattern != (double *) NULL)
846 draw_info->dash_pattern=(double *) RelinquishMagickMemory(
847 draw_info->dash_pattern);
848 if (draw_info->gradient.stops != (StopInfo *) NULL)
849 draw_info->gradient.stops=(StopInfo *) RelinquishMagickMemory(
850 draw_info->gradient.stops);
851 if (draw_info->clip_mask != (char *) NULL)
852 draw_info->clip_mask=DestroyString(draw_info->clip_mask);
853 draw_info->signature=(~MagickSignature);
854 draw_info=(DrawInfo *) RelinquishMagickMemory(draw_info);
859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
863 + D e s t r o y E d g e %
867 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
869 % DestroyEdge() destroys the specified polygon edge.
871 % The format of the DestroyEdge method is:
873 % ssize_t DestroyEdge(PolygonInfo *polygon_info,const int edge)
875 % A description of each parameter follows:
877 % o polygon_info: Specifies a pointer to an PolygonInfo structure.
879 % o edge: the polygon edge number to destroy.
882 static size_t DestroyEdge(PolygonInfo *polygon_info,
885 assert(edge < polygon_info->number_edges);
886 polygon_info->edges[edge].points=(PointInfo *) RelinquishMagickMemory(
887 polygon_info->edges[edge].points);
888 polygon_info->number_edges--;
889 if (edge < polygon_info->number_edges)
890 (void) CopyMagickMemory(polygon_info->edges+edge,polygon_info->edges+edge+1,
891 (size_t) (polygon_info->number_edges-edge)*sizeof(*polygon_info->edges));
892 return(polygon_info->number_edges);
896 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
900 + D e s t r o y P o l y g o n I n f o %
904 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
906 % DestroyPolygonInfo() destroys the PolygonInfo data structure.
908 % The format of the DestroyPolygonInfo method is:
910 % PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info)
912 % A description of each parameter follows:
914 % o polygon_info: Specifies a pointer to an PolygonInfo structure.
917 static PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info)
922 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
923 polygon_info->edges[i].points=(PointInfo *)
924 RelinquishMagickMemory(polygon_info->edges[i].points);
925 polygon_info->edges=(EdgeInfo *) RelinquishMagickMemory(polygon_info->edges);
926 return((PolygonInfo *) RelinquishMagickMemory(polygon_info));
930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
934 % D r a w A f f i n e I m a g e %
938 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
940 % DrawAffineImage() composites the source over the destination image as
941 % dictated by the affine transform.
943 % The format of the DrawAffineImage method is:
945 % MagickBooleanType DrawAffineImage(Image *image,const Image *source,
946 % const AffineMatrix *affine)
948 % A description of each parameter follows:
950 % o image: the image.
952 % o source: the source image.
954 % o affine: the affine transform.
957 static SegmentInfo AffineEdge(const Image *image,const AffineMatrix *affine,
958 const double y,const SegmentInfo *edge)
971 Determine left and right edges.
973 inverse_edge.x1=edge->x1;
974 inverse_edge.y1=edge->y1;
975 inverse_edge.x2=edge->x2;
976 inverse_edge.y2=edge->y2;
977 z=affine->ry*y+affine->tx;
978 if (affine->sx > MagickEpsilon)
980 intercept=(-z/affine->sx);
981 x=intercept+MagickEpsilon;
982 if (x > inverse_edge.x1)
984 intercept=(-z+(double) image->columns)/affine->sx;
985 x=intercept-MagickEpsilon;
986 if (x < inverse_edge.x2)
990 if (affine->sx < -MagickEpsilon)
992 intercept=(-z+(double) image->columns)/affine->sx;
993 x=intercept+MagickEpsilon;
994 if (x > inverse_edge.x1)
996 intercept=(-z/affine->sx);
997 x=intercept-MagickEpsilon;
998 if (x < inverse_edge.x2)
1002 if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->columns))
1004 inverse_edge.x2=edge->x1;
1005 return(inverse_edge);
1008 Determine top and bottom edges.
1010 z=affine->sy*y+affine->ty;
1011 if (affine->rx > MagickEpsilon)
1013 intercept=(-z/affine->rx);
1014 x=intercept+MagickEpsilon;
1015 if (x > inverse_edge.x1)
1017 intercept=(-z+(double) image->rows)/affine->rx;
1018 x=intercept-MagickEpsilon;
1019 if (x < inverse_edge.x2)
1023 if (affine->rx < -MagickEpsilon)
1025 intercept=(-z+(double) image->rows)/affine->rx;
1026 x=intercept+MagickEpsilon;
1027 if (x > inverse_edge.x1)
1029 intercept=(-z/affine->rx);
1030 x=intercept-MagickEpsilon;
1031 if (x < inverse_edge.x2)
1035 if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->rows))
1037 inverse_edge.x2=edge->x2;
1038 return(inverse_edge);
1040 return(inverse_edge);
1043 static AffineMatrix InverseAffineMatrix(const AffineMatrix *affine)
1051 determinant=1.0/(affine->sx*affine->sy-affine->rx*affine->ry);
1052 inverse_affine.sx=determinant*affine->sy;
1053 inverse_affine.rx=determinant*(-affine->rx);
1054 inverse_affine.ry=determinant*(-affine->ry);
1055 inverse_affine.sy=determinant*affine->sx;
1056 inverse_affine.tx=(-affine->tx)*inverse_affine.sx-affine->ty*
1058 inverse_affine.ty=(-affine->tx)*inverse_affine.rx-affine->ty*
1060 return(inverse_affine);
1063 static inline ssize_t MagickAbsoluteValue(const ssize_t x)
1070 static inline double MagickMax(const double x,const double y)
1077 static inline double MagickMin(const double x,const double y)
1084 MagickExport MagickBooleanType DrawAffineImage(Image *image,
1085 const Image *source,const AffineMatrix *affine)
1119 Determine bounding box.
1121 assert(image != (Image *) NULL);
1122 assert(image->signature == MagickSignature);
1123 if (image->debug != MagickFalse)
1124 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1125 assert(source != (const Image *) NULL);
1126 assert(source->signature == MagickSignature);
1127 assert(affine != (AffineMatrix *) NULL);
1130 extent[1].x=(double) source->columns-1.0;
1132 extent[2].x=(double) source->columns-1.0;
1133 extent[2].y=(double) source->rows-1.0;
1135 extent[3].y=(double) source->rows-1.0;
1136 for (i=0; i < 4; i++)
1139 extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx;
1140 extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty;
1144 for (i=1; i < 4; i++)
1146 if (min.x > extent[i].x)
1148 if (min.y > extent[i].y)
1150 if (max.x < extent[i].x)
1152 if (max.y < extent[i].y)
1156 Affine transform image.
1158 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
1159 return(MagickFalse);
1161 edge.x1=MagickMax(min.x,0.0);
1162 edge.y1=MagickMax(min.y,0.0);
1163 edge.x2=MagickMin(max.x,(double) image->columns-1.0);
1164 edge.y2=MagickMin(max.y,(double) image->rows-1.0);
1165 inverse_affine=InverseAffineMatrix(affine);
1166 GetMagickPixelPacket(image,&zero);
1167 exception=(&image->exception);
1168 image_view=AcquireCacheView(image);
1169 source_view=AcquireCacheView(source);
1170 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1171 #pragma omp parallel for schedule(dynamic,4) shared(status)
1173 for (y=(ssize_t) ceil(edge.y1-0.5); y <= (ssize_t) floor(edge.y2+0.5); y++)
1176 id = GetOpenMPThreadId();
1185 register IndexPacket
1191 register PixelPacket
1200 inverse_edge=AffineEdge(source,&inverse_affine,(double) y,&edge);
1201 if (inverse_edge.x2 < inverse_edge.x1)
1203 q=GetCacheViewAuthenticPixels(image_view,(ssize_t) ceil(inverse_edge.x1-
1204 0.5),y,(size_t) ((ssize_t) floor(inverse_edge.x2+0.5)-(ssize_t) floor(
1205 inverse_edge.x1+0.5)+1),1,exception);
1206 if (q == (PixelPacket *) NULL)
1208 indexes=GetCacheViewAuthenticIndexQueue(image_view);
1212 for (x=(ssize_t) ceil(inverse_edge.x1-0.5); x <= (ssize_t) floor(inverse_edge.x2+0.5); x++)
1214 point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+
1216 point.y=(double) x*inverse_affine.rx+y*inverse_affine.sy+
1218 (void) InterpolatePixelPacket(image,image_view,image->interpolate,
1219 point.x,point.y,&pixel,exception);
1220 SetMagickPixelPacket(image,q,indexes+x_offset,&composite);
1221 MagickPixelCompositeOver(&pixel,pixel.opacity,&composite,
1222 composite.opacity,&composite);
1223 SetPixelPacket(image,&composite,q,indexes+x_offset);
1227 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1230 source_view=DestroyCacheView(source_view);
1231 image_view=DestroyCacheView(image_view);
1236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1240 + D r a w B o u n d i n g R e c t a n g l e s %
1244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1246 % DrawBoundingRectangles() draws the bounding rectangles on the image. This
1247 % is only useful for developers debugging the rendering algorithm.
1249 % The format of the DrawBoundingRectangles method is:
1251 % void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info,
1252 % PolygonInfo *polygon_info)
1254 % A description of each parameter follows:
1256 % o image: the image.
1258 % o draw_info: the draw info.
1260 % o polygon_info: Specifies a pointer to a PolygonInfo structure.
1263 static void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info,
1264 const PolygonInfo *polygon_info)
1289 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1290 (void) QueryColorDatabase("#0000",&clone_info->fill,&image->exception);
1291 resolution.x=DefaultResolution;
1292 resolution.y=DefaultResolution;
1293 if (clone_info->density != (char *) NULL)
1301 flags=ParseGeometry(clone_info->density,&geometry_info);
1302 resolution.x=geometry_info.rho;
1303 resolution.y=geometry_info.sigma;
1304 if ((flags & SigmaValue) == MagickFalse)
1305 resolution.y=resolution.x;
1307 mid=(resolution.x/72.0)*ExpandAffine(&clone_info->affine)*
1308 clone_info->stroke_width/2.0;
1313 if (polygon_info != (PolygonInfo *) NULL)
1315 bounds=polygon_info->edges[0].bounds;
1316 for (i=1; i < (ssize_t) polygon_info->number_edges; i++)
1318 if (polygon_info->edges[i].bounds.x1 < (double) bounds.x1)
1319 bounds.x1=polygon_info->edges[i].bounds.x1;
1320 if (polygon_info->edges[i].bounds.y1 < (double) bounds.y1)
1321 bounds.y1=polygon_info->edges[i].bounds.y1;
1322 if (polygon_info->edges[i].bounds.x2 > (double) bounds.x2)
1323 bounds.x2=polygon_info->edges[i].bounds.x2;
1324 if (polygon_info->edges[i].bounds.y2 > (double) bounds.y2)
1325 bounds.y2=polygon_info->edges[i].bounds.y2;
1328 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double)
1329 image->columns ? (double) image->columns-1 : bounds.x1;
1331 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double)
1332 image->rows ? (double) image->rows-1 : bounds.y1;
1334 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double)
1335 image->columns ? (double) image->columns-1 : bounds.x2;
1337 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double)
1338 image->rows ? (double) image->rows-1 : bounds.y2;
1339 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
1341 if (polygon_info->edges[i].direction != 0)
1342 (void) QueryColorDatabase("red",&clone_info->stroke,
1345 (void) QueryColorDatabase("green",&clone_info->stroke,
1347 start.x=(double) (polygon_info->edges[i].bounds.x1-mid);
1348 start.y=(double) (polygon_info->edges[i].bounds.y1-mid);
1349 end.x=(double) (polygon_info->edges[i].bounds.x2+mid);
1350 end.y=(double) (polygon_info->edges[i].bounds.y2+mid);
1351 primitive_info[0].primitive=RectanglePrimitive;
1352 TraceRectangle(primitive_info,start,end);
1353 primitive_info[0].method=ReplaceMethod;
1354 coordinates=(ssize_t) primitive_info[0].coordinates;
1355 primitive_info[coordinates].primitive=UndefinedPrimitive;
1356 (void) DrawPrimitive(image,clone_info,primitive_info);
1359 (void) QueryColorDatabase("blue",&clone_info->stroke,&image->exception);
1360 start.x=(double) (bounds.x1-mid);
1361 start.y=(double) (bounds.y1-mid);
1362 end.x=(double) (bounds.x2+mid);
1363 end.y=(double) (bounds.y2+mid);
1364 primitive_info[0].primitive=RectanglePrimitive;
1365 TraceRectangle(primitive_info,start,end);
1366 primitive_info[0].method=ReplaceMethod;
1367 coordinates=(ssize_t) primitive_info[0].coordinates;
1368 primitive_info[coordinates].primitive=UndefinedPrimitive;
1369 (void) DrawPrimitive(image,clone_info,primitive_info);
1370 clone_info=DestroyDrawInfo(clone_info);
1374 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1378 % D r a w C l i p P a t h %
1382 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1384 % DrawClipPath() draws the clip path on the image mask.
1386 % The format of the DrawClipPath method is:
1388 % MagickBooleanType DrawClipPath(Image *image,const DrawInfo *draw_info,
1391 % A description of each parameter follows:
1393 % o image: the image.
1395 % o draw_info: the draw info.
1397 % o name: the name of the clip path.
1400 MagickExport MagickBooleanType DrawClipPath(Image *image,
1401 const DrawInfo *draw_info,const char *name)
1404 clip_mask[MaxTextExtent];
1415 assert(image != (Image *) NULL);
1416 assert(image->signature == MagickSignature);
1417 if (image->debug != MagickFalse)
1418 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1419 assert(draw_info != (const DrawInfo *) NULL);
1420 (void) FormatMagickString(clip_mask,MaxTextExtent,"%s",name);
1421 value=GetImageArtifact(image,clip_mask);
1422 if (value == (const char *) NULL)
1423 return(MagickFalse);
1424 if (image->clip_mask == (Image *) NULL)
1429 clip_mask=CloneImage(image,image->columns,image->rows,MagickTrue,
1431 if (clip_mask == (Image *) NULL)
1432 return(MagickFalse);
1433 (void) SetImageClipMask(image,clip_mask);
1434 clip_mask=DestroyImage(clip_mask);
1436 (void) QueryColorDatabase("#00000000",&image->clip_mask->background_color,
1438 image->clip_mask->background_color.opacity=(Quantum) TransparentOpacity;
1439 (void) SetImageBackgroundColor(image->clip_mask);
1440 if (image->debug != MagickFalse)
1441 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"\nbegin clip-path %s",
1442 draw_info->clip_mask);
1443 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1444 (void) CloneString(&clone_info->primitive,value);
1445 (void) QueryColorDatabase("#ffffff",&clone_info->fill,&image->exception);
1446 clone_info->clip_mask=(char *) NULL;
1447 status=DrawImage(image->clip_mask,clone_info);
1448 status|=NegateImage(image->clip_mask,MagickFalse);
1449 clone_info=DestroyDrawInfo(clone_info);
1450 if (image->debug != MagickFalse)
1451 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end clip-path");
1452 return(status != 0 ? MagickTrue : MagickFalse);
1456 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1460 + D r a w D a s h P o l y g o n %
1464 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1466 % DrawDashPolygon() draws a dashed polygon (line, rectangle, ellipse) on the
1467 % image while respecting the dash offset and dash pattern attributes.
1469 % The format of the DrawDashPolygon method is:
1471 % MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info,
1472 % const PrimitiveInfo *primitive_info,Image *image)
1474 % A description of each parameter follows:
1476 % o draw_info: the draw info.
1478 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
1480 % o image: the image.
1484 static MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info,
1485 const PrimitiveInfo *primitive_info,Image *image)
1506 register MagickRealType
1517 assert(draw_info != (const DrawInfo *) NULL);
1518 if (image->debug != MagickFalse)
1519 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-dash");
1520 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1521 clone_info->miterlimit=0;
1522 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
1523 number_vertices=(size_t) i;
1524 dash_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
1525 (2UL*number_vertices+1UL),sizeof(*dash_polygon));
1526 if (dash_polygon == (PrimitiveInfo *) NULL)
1527 return(MagickFalse);
1528 dash_polygon[0]=primitive_info[0];
1529 scale=ExpandAffine(&draw_info->affine);
1530 length=scale*(draw_info->dash_pattern[0]-0.5);
1531 offset=draw_info->dash_offset != 0.0 ? scale*draw_info->dash_offset : 0.0;
1533 for (n=0; offset > 0.0; j=0)
1535 if (draw_info->dash_pattern[n] <= 0.0)
1537 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1538 if (offset > length)
1542 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1545 if (offset < length)
1557 for (i=1; i < (ssize_t) number_vertices; i++)
1559 dx=primitive_info[i].point.x-primitive_info[i-1].point.x;
1560 dy=primitive_info[i].point.y-primitive_info[i-1].point.y;
1561 maximum_length=hypot((double) dx,dy);
1565 if (draw_info->dash_pattern[n] == 0.0)
1567 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1569 for (total_length=0.0; (total_length+length) < maximum_length; )
1571 total_length+=length;
1572 if ((n & 0x01) != 0)
1574 dash_polygon[0]=primitive_info[0];
1575 dash_polygon[0].point.x=(double) (primitive_info[i-1].point.x+dx*
1576 total_length/maximum_length);
1577 dash_polygon[0].point.y=(double) (primitive_info[i-1].point.y+dy*
1578 total_length/maximum_length);
1583 if ((j+1) > (ssize_t) (2*number_vertices))
1585 dash_polygon[j]=primitive_info[i-1];
1586 dash_polygon[j].point.x=(double) (primitive_info[i-1].point.x+dx*
1587 total_length/maximum_length);
1588 dash_polygon[j].point.y=(double) (primitive_info[i-1].point.y+dy*
1589 total_length/maximum_length);
1590 dash_polygon[j].coordinates=1;
1592 dash_polygon[0].coordinates=(size_t) j;
1593 dash_polygon[j].primitive=UndefinedPrimitive;
1594 status|=DrawStrokePolygon(image,clone_info,dash_polygon);
1597 if (draw_info->dash_pattern[n] == 0.0)
1599 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1601 length-=(maximum_length-total_length);
1602 if ((n & 0x01) != 0)
1604 dash_polygon[j]=primitive_info[i];
1605 dash_polygon[j].coordinates=1;
1608 if ((total_length < maximum_length) && ((n & 0x01) == 0) && (j > 1))
1610 dash_polygon[j]=primitive_info[i-1];
1611 dash_polygon[j].point.x+=MagickEpsilon;
1612 dash_polygon[j].point.y+=MagickEpsilon;
1613 dash_polygon[j].coordinates=1;
1615 dash_polygon[0].coordinates=(size_t) j;
1616 dash_polygon[j].primitive=UndefinedPrimitive;
1617 status|=DrawStrokePolygon(image,clone_info,dash_polygon);
1619 dash_polygon=(PrimitiveInfo *) RelinquishMagickMemory(dash_polygon);
1620 clone_info=DestroyDrawInfo(clone_info);
1621 if (image->debug != MagickFalse)
1622 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-dash");
1623 return(status != 0 ? MagickTrue : MagickFalse);
1627 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1631 % D r a w I m a g e %
1635 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1637 % DrawImage() draws a graphic primitive on your image. The primitive
1638 % may be represented as a string or filename. Precede the filename with an
1639 % "at" sign (@) and the contents of the file are drawn on the image. You
1640 % can affect how text is drawn by setting one or more members of the draw
1643 % The format of the DrawImage method is:
1645 % MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info)
1647 % A description of each parameter follows:
1649 % o image: the image.
1651 % o draw_info: the draw info.
1655 static inline MagickBooleanType IsPoint(const char *point)
1663 value=strtod(point,&p);
1664 return((value == 0.0) && (p == point) ? MagickFalse : MagickTrue);
1667 static inline void TracePoint(PrimitiveInfo *primitive_info,
1668 const PointInfo point)
1670 primitive_info->coordinates=1;
1671 primitive_info->point=point;
1674 MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info)
1676 #define RenderImageTag "Render/Image"
1683 key[2*MaxTextExtent],
1684 keyword[MaxTextExtent],
1685 geometry[MaxTextExtent],
1686 name[MaxTextExtent],
1687 pattern[MaxTextExtent],
1738 Ensure the annotation info is valid.
1740 assert(image != (Image *) NULL);
1741 assert(image->signature == MagickSignature);
1742 if (image->debug != MagickFalse)
1743 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1744 assert(draw_info != (DrawInfo *) NULL);
1745 assert(draw_info->signature == MagickSignature);
1746 if (image->debug != MagickFalse)
1747 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1748 if ((draw_info->primitive == (char *) NULL) ||
1749 (*draw_info->primitive == '\0'))
1750 return(MagickFalse);
1751 if (image->debug != MagickFalse)
1752 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"begin draw-image");
1753 if (*draw_info->primitive != '@')
1754 primitive=AcquireString(draw_info->primitive);
1756 primitive=FileToString(draw_info->primitive+1,~0,&image->exception);
1757 if (primitive == (char *) NULL)
1758 return(MagickFalse);
1759 primitive_extent=(MagickRealType) strlen(primitive);
1760 (void) SetImageArtifact(image,"MVG",primitive);
1763 Allocate primitive info memory.
1765 graphic_context=(DrawInfo **) AcquireMagickMemory(
1766 sizeof(*graphic_context));
1767 if (graphic_context == (DrawInfo **) NULL)
1769 primitive=DestroyString(primitive);
1770 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1774 primitive_info=(PrimitiveInfo *) AcquireQuantumMemory((size_t) number_points,
1775 sizeof(*primitive_info));
1776 if (primitive_info == (PrimitiveInfo *) NULL)
1778 primitive=DestroyString(primitive);
1779 for ( ; n >= 0; n--)
1780 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
1781 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
1782 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1785 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1786 graphic_context[n]->viewbox=image->page;
1787 if ((image->page.width == 0) || (image->page.height == 0))
1789 graphic_context[n]->viewbox.width=image->columns;
1790 graphic_context[n]->viewbox.height=image->rows;
1792 token=AcquireString(primitive);
1793 (void) QueryColorDatabase("#000000",&start_color,&image->exception);
1794 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
1795 return(MagickFalse);
1797 for (q=primitive; *q != '\0'; )
1800 Interpret graphic primitive.
1802 GetMagickToken(q,&q,keyword);
1803 if (*keyword == '\0')
1805 if (*keyword == '#')
1810 while ((*q != '\n') && (*q != '\0'))
1814 p=q-strlen(keyword)-1;
1815 primitive_type=UndefinedPrimitive;
1816 current=graphic_context[n]->affine;
1817 GetAffineMatrix(&affine);
1825 if (LocaleCompare("affine",keyword) == 0)
1827 GetMagickToken(q,&q,token);
1828 affine.sx=StringToDouble(token);
1829 GetMagickToken(q,&q,token);
1831 GetMagickToken(q,&q,token);
1832 affine.rx=StringToDouble(token);
1833 GetMagickToken(q,&q,token);
1835 GetMagickToken(q,&q,token);
1836 affine.ry=StringToDouble(token);
1837 GetMagickToken(q,&q,token);
1839 GetMagickToken(q,&q,token);
1840 affine.sy=StringToDouble(token);
1841 GetMagickToken(q,&q,token);
1843 GetMagickToken(q,&q,token);
1844 affine.tx=StringToDouble(token);
1845 GetMagickToken(q,&q,token);
1847 GetMagickToken(q,&q,token);
1848 affine.ty=StringToDouble(token);
1851 if (LocaleCompare("arc",keyword) == 0)
1853 primitive_type=ArcPrimitive;
1862 if (LocaleCompare("bezier",keyword) == 0)
1864 primitive_type=BezierPrimitive;
1867 if (LocaleCompare("border-color",keyword) == 0)
1869 GetMagickToken(q,&q,token);
1870 (void) QueryColorDatabase(token,&graphic_context[n]->border_color,
1880 if (LocaleCompare("clip-path",keyword) == 0)
1885 GetMagickToken(q,&q,token);
1886 (void) CloneString(&graphic_context[n]->clip_mask,token);
1887 (void) DrawClipPath(image,graphic_context[n],
1888 graphic_context[n]->clip_mask);
1891 if (LocaleCompare("clip-rule",keyword) == 0)
1896 GetMagickToken(q,&q,token);
1897 fill_rule=ParseMagickOption(MagickFillRuleOptions,MagickFalse,
1899 if (fill_rule == -1)
1904 graphic_context[n]->fill_rule=(FillRule) fill_rule;
1907 if (LocaleCompare("clip-units",keyword) == 0)
1912 GetMagickToken(q,&q,token);
1913 clip_units=ParseMagickOption(MagickClipPathOptions,MagickFalse,
1915 if (clip_units == -1)
1920 graphic_context[n]->clip_units=(ClipPathUnits) clip_units;
1921 if (clip_units == ObjectBoundingBox)
1923 GetAffineMatrix(¤t);
1924 affine.sx=draw_info->bounds.x2;
1925 affine.sy=draw_info->bounds.y2;
1926 affine.tx=draw_info->bounds.x1;
1927 affine.ty=draw_info->bounds.y1;
1932 if (LocaleCompare("circle",keyword) == 0)
1934 primitive_type=CirclePrimitive;
1937 if (LocaleCompare("color",keyword) == 0)
1939 primitive_type=ColorPrimitive;
1948 if (LocaleCompare("decorate",keyword) == 0)
1953 GetMagickToken(q,&q,token);
1954 decorate=ParseMagickOption(MagickDecorateOptions,MagickFalse,
1961 graphic_context[n]->decorate=(DecorationType) decorate;
1970 if (LocaleCompare("ellipse",keyword) == 0)
1972 primitive_type=EllipsePrimitive;
1975 if (LocaleCompare("encoding",keyword) == 0)
1977 GetMagickToken(q,&q,token);
1978 (void) CloneString(&graphic_context[n]->encoding,token);
1987 if (LocaleCompare("fill",keyword) == 0)
1989 GetMagickToken(q,&q,token);
1990 (void) FormatMagickString(pattern,MaxTextExtent,"%s",token);
1991 if (GetImageArtifact(image,pattern) != (const char *) NULL)
1992 (void) DrawPatternPath(image,draw_info,token,
1993 &graphic_context[n]->fill_pattern);
1996 status=QueryColorDatabase(token,&graphic_context[n]->fill,
1998 if (status == MagickFalse)
2003 pattern_info=AcquireImageInfo();
2004 (void) CopyMagickString(pattern_info->filename,token,
2006 graphic_context[n]->fill_pattern=
2007 ReadImage(pattern_info,&image->exception);
2008 CatchException(&image->exception);
2009 pattern_info=DestroyImageInfo(pattern_info);
2014 if (LocaleCompare("fill-opacity",keyword) == 0)
2016 GetMagickToken(q,&q,token);
2017 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2018 graphic_context[n]->fill.opacity=ClampToQuantum((MagickRealType)
2019 QuantumRange*(1.0-factor*StringToDouble(token)));
2022 if (LocaleCompare("fill-rule",keyword) == 0)
2027 GetMagickToken(q,&q,token);
2028 fill_rule=ParseMagickOption(MagickFillRuleOptions,MagickFalse,
2030 if (fill_rule == -1)
2035 graphic_context[n]->fill_rule=(FillRule) fill_rule;
2038 if (LocaleCompare("font",keyword) == 0)
2040 GetMagickToken(q,&q,token);
2041 (void) CloneString(&graphic_context[n]->font,token);
2042 if (LocaleCompare("none",token) == 0)
2043 graphic_context[n]->font=(char *)
2044 RelinquishMagickMemory(graphic_context[n]->font);
2047 if (LocaleCompare("font-family",keyword) == 0)
2049 GetMagickToken(q,&q,token);
2050 (void) CloneString(&graphic_context[n]->family,token);
2053 if (LocaleCompare("font-size",keyword) == 0)
2055 GetMagickToken(q,&q,token);
2056 graphic_context[n]->pointsize=StringToDouble(token);
2059 if (LocaleCompare("font-stretch",keyword) == 0)
2064 GetMagickToken(q,&q,token);
2065 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,token);
2071 graphic_context[n]->stretch=(StretchType) stretch;
2074 if (LocaleCompare("font-style",keyword) == 0)
2079 GetMagickToken(q,&q,token);
2080 style=ParseMagickOption(MagickStyleOptions,MagickFalse,token);
2086 graphic_context[n]->style=(StyleType) style;
2089 if (LocaleCompare("font-weight",keyword) == 0)
2091 GetMagickToken(q,&q,token);
2092 graphic_context[n]->weight=StringToUnsignedLong(token);
2093 if (LocaleCompare(token,"all") == 0)
2094 graphic_context[n]->weight=0;
2095 if (LocaleCompare(token,"bold") == 0)
2096 graphic_context[n]->weight=700;
2097 if (LocaleCompare(token,"bolder") == 0)
2098 if (graphic_context[n]->weight <= 800)
2099 graphic_context[n]->weight+=100;
2100 if (LocaleCompare(token,"lighter") == 0)
2101 if (graphic_context[n]->weight >= 100)
2102 graphic_context[n]->weight-=100;
2103 if (LocaleCompare(token,"normal") == 0)
2104 graphic_context[n]->weight=400;
2113 if (LocaleCompare("gradient-units",keyword) == 0)
2115 GetMagickToken(q,&q,token);
2118 if (LocaleCompare("gravity",keyword) == 0)
2123 GetMagickToken(q,&q,token);
2124 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,token);
2130 graphic_context[n]->gravity=(GravityType) gravity;
2139 if (LocaleCompare("image",keyword) == 0)
2144 primitive_type=ImagePrimitive;
2145 GetMagickToken(q,&q,token);
2146 compose=ParseMagickOption(MagickComposeOptions,MagickFalse,token);
2152 graphic_context[n]->compose=(CompositeOperator) compose;
2155 if (LocaleCompare("interline-spacing",keyword) == 0)
2157 GetMagickToken(q,&q,token);
2158 graphic_context[n]->interline_spacing=StringToDouble(token);
2161 if (LocaleCompare("interword-spacing",keyword) == 0)
2163 GetMagickToken(q,&q,token);
2164 graphic_context[n]->interword_spacing=StringToDouble(token);
2173 if (LocaleCompare("kerning",keyword) == 0)
2175 GetMagickToken(q,&q,token);
2176 graphic_context[n]->kerning=StringToDouble(token);
2185 if (LocaleCompare("line",keyword) == 0)
2187 primitive_type=LinePrimitive;
2196 if (LocaleCompare("matte",keyword) == 0)
2198 primitive_type=MattePrimitive;
2207 if (LocaleCompare("offset",keyword) == 0)
2209 GetMagickToken(q,&q,token);
2212 if (LocaleCompare("opacity",keyword) == 0)
2214 GetMagickToken(q,&q,token);
2215 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2216 graphic_context[n]->opacity=ClampToQuantum((MagickRealType)
2217 QuantumRange*(1.0-((1.0-QuantumScale*graphic_context[n]->opacity)*
2218 factor*StringToDouble(token))));
2219 graphic_context[n]->fill.opacity=graphic_context[n]->opacity;
2220 graphic_context[n]->stroke.opacity=graphic_context[n]->opacity;
2229 if (LocaleCompare("path",keyword) == 0)
2231 primitive_type=PathPrimitive;
2234 if (LocaleCompare("point",keyword) == 0)
2236 primitive_type=PointPrimitive;
2239 if (LocaleCompare("polyline",keyword) == 0)
2241 primitive_type=PolylinePrimitive;
2244 if (LocaleCompare("polygon",keyword) == 0)
2246 primitive_type=PolygonPrimitive;
2249 if (LocaleCompare("pop",keyword) == 0)
2251 GetMagickToken(q,&q,token);
2252 if (LocaleCompare("clip-path",token) == 0)
2254 if (LocaleCompare("defs",token) == 0)
2256 if (LocaleCompare("gradient",token) == 0)
2258 if (LocaleCompare("graphic-context",token) == 0)
2262 (void) ThrowMagickException(&image->exception,
2263 GetMagickModule(),DrawError,
2264 "UnbalancedGraphicContextPushPop","`%s'",token);
2268 if (graphic_context[n]->clip_mask != (char *) NULL)
2269 if (LocaleCompare(graphic_context[n]->clip_mask,
2270 graphic_context[n-1]->clip_mask) != 0)
2271 (void) SetImageClipMask(image,(Image *) NULL);
2272 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
2276 if (LocaleCompare("pattern",token) == 0)
2281 if (LocaleCompare("push",keyword) == 0)
2283 GetMagickToken(q,&q,token);
2284 if (LocaleCompare("clip-path",token) == 0)
2287 name[MaxTextExtent];
2289 GetMagickToken(q,&q,token);
2290 (void) FormatMagickString(name,MaxTextExtent,"%s",token);
2291 for (p=q; *q != '\0'; )
2293 GetMagickToken(q,&q,token);
2294 if (LocaleCompare(token,"pop") != 0)
2296 GetMagickToken(q,(const char **) NULL,token);
2297 if (LocaleCompare(token,"clip-path") != 0)
2301 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2302 (void) SetImageArtifact(image,name,token);
2303 GetMagickToken(q,&q,token);
2306 if (LocaleCompare("gradient",token) == 0)
2309 key[2*MaxTextExtent],
2310 name[MaxTextExtent],
2311 type[MaxTextExtent];
2316 GetMagickToken(q,&q,token);
2317 (void) CopyMagickString(name,token,MaxTextExtent);
2318 GetMagickToken(q,&q,token);
2319 (void) CopyMagickString(type,token,MaxTextExtent);
2320 GetMagickToken(q,&q,token);
2321 segment.x1=StringToDouble(token);
2322 GetMagickToken(q,&q,token);
2324 GetMagickToken(q,&q,token);
2325 segment.y1=StringToDouble(token);
2326 GetMagickToken(q,&q,token);
2328 GetMagickToken(q,&q,token);
2329 segment.x2=StringToDouble(token);
2330 GetMagickToken(q,&q,token);
2332 GetMagickToken(q,&q,token);
2333 segment.y2=StringToDouble(token);
2334 if (LocaleCompare(type,"radial") == 0)
2336 GetMagickToken(q,&q,token);
2338 GetMagickToken(q,&q,token);
2340 for (p=q; *q != '\0'; )
2342 GetMagickToken(q,&q,token);
2343 if (LocaleCompare(token,"pop") != 0)
2345 GetMagickToken(q,(const char **) NULL,token);
2346 if (LocaleCompare(token,"gradient") != 0)
2350 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2351 bounds.x1=graphic_context[n]->affine.sx*segment.x1+
2352 graphic_context[n]->affine.ry*segment.y1+
2353 graphic_context[n]->affine.tx;
2354 bounds.y1=graphic_context[n]->affine.rx*segment.x1+
2355 graphic_context[n]->affine.sy*segment.y1+
2356 graphic_context[n]->affine.ty;
2357 bounds.x2=graphic_context[n]->affine.sx*segment.x2+
2358 graphic_context[n]->affine.ry*segment.y2+
2359 graphic_context[n]->affine.tx;
2360 bounds.y2=graphic_context[n]->affine.rx*segment.x2+
2361 graphic_context[n]->affine.sy*segment.y2+
2362 graphic_context[n]->affine.ty;
2363 (void) FormatMagickString(key,MaxTextExtent,"%s",name);
2364 (void) SetImageArtifact(image,key,token);
2365 (void) FormatMagickString(key,MaxTextExtent,"%s-geometry",name);
2366 (void) FormatMagickString(geometry,MaxTextExtent,
2367 "%gx%g%+.15g%+.15g",
2368 MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0),
2369 MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0),
2370 bounds.x1,bounds.y1);
2371 (void) SetImageArtifact(image,key,geometry);
2372 GetMagickToken(q,&q,token);
2375 if (LocaleCompare("pattern",token) == 0)
2380 GetMagickToken(q,&q,token);
2381 (void) CopyMagickString(name,token,MaxTextExtent);
2382 GetMagickToken(q,&q,token);
2383 bounds.x=(ssize_t) ceil(StringToDouble(token)-0.5);
2384 GetMagickToken(q,&q,token);
2386 GetMagickToken(q,&q,token);
2387 bounds.y=(ssize_t) ceil(StringToDouble(token)-0.5);
2388 GetMagickToken(q,&q,token);
2390 GetMagickToken(q,&q,token);
2391 bounds.width=(size_t) floor(StringToDouble(token)+0.5);
2392 GetMagickToken(q,&q,token);
2394 GetMagickToken(q,&q,token);
2395 bounds.height=(size_t) floor(StringToDouble(token)+0.5);
2396 for (p=q; *q != '\0'; )
2398 GetMagickToken(q,&q,token);
2399 if (LocaleCompare(token,"pop") != 0)
2401 GetMagickToken(q,(const char **) NULL,token);
2402 if (LocaleCompare(token,"pattern") != 0)
2406 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2407 (void) FormatMagickString(key,MaxTextExtent,"%s",name);
2408 (void) SetImageArtifact(image,key,token);
2409 (void) FormatMagickString(key,MaxTextExtent,"%s-geometry",name);
2410 (void) FormatMagickString(geometry,MaxTextExtent,
2411 "%.20gx%.20g%+.20g%+.20g",(double) bounds.width,(double)
2412 bounds.height,(double) bounds.x,(double) bounds.y);
2413 (void) SetImageArtifact(image,key,geometry);
2414 GetMagickToken(q,&q,token);
2417 if (LocaleCompare("graphic-context",token) == 0)
2420 graphic_context=(DrawInfo **) ResizeQuantumMemory(
2421 graphic_context,(size_t) (n+1),sizeof(*graphic_context));
2422 if (graphic_context == (DrawInfo **) NULL)
2424 (void) ThrowMagickException(&image->exception,
2425 GetMagickModule(),ResourceLimitError,
2426 "MemoryAllocationFailed","`%s'",image->filename);
2429 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,
2430 graphic_context[n-1]);
2433 if (LocaleCompare("defs",token) == 0)
2444 if (LocaleCompare("rectangle",keyword) == 0)
2446 primitive_type=RectanglePrimitive;
2449 if (LocaleCompare("rotate",keyword) == 0)
2451 GetMagickToken(q,&q,token);
2452 angle=StringToDouble(token);
2453 affine.sx=cos(DegreesToRadians(fmod((double) angle,360.0)));
2454 affine.rx=sin(DegreesToRadians(fmod((double) angle,360.0)));
2455 affine.ry=(-sin(DegreesToRadians(fmod((double) angle,360.0))));
2456 affine.sy=cos(DegreesToRadians(fmod((double) angle,360.0)));
2459 if (LocaleCompare("roundRectangle",keyword) == 0)
2461 primitive_type=RoundRectanglePrimitive;
2470 if (LocaleCompare("scale",keyword) == 0)
2472 GetMagickToken(q,&q,token);
2473 affine.sx=StringToDouble(token);
2474 GetMagickToken(q,&q,token);
2476 GetMagickToken(q,&q,token);
2477 affine.sy=StringToDouble(token);
2480 if (LocaleCompare("skewX",keyword) == 0)
2482 GetMagickToken(q,&q,token);
2483 angle=StringToDouble(token);
2484 affine.ry=sin(DegreesToRadians(angle));
2487 if (LocaleCompare("skewY",keyword) == 0)
2489 GetMagickToken(q,&q,token);
2490 angle=StringToDouble(token);
2491 affine.rx=(-tan(DegreesToRadians(angle)/2.0));
2494 if (LocaleCompare("stop-color",keyword) == 0)
2499 GetMagickToken(q,&q,token);
2500 (void) QueryColorDatabase(token,&stop_color,&image->exception);
2501 (void) GradientImage(image,LinearGradient,ReflectSpread,
2502 &start_color,&stop_color);
2503 start_color=stop_color;
2504 GetMagickToken(q,&q,token);
2507 if (LocaleCompare("stroke",keyword) == 0)
2509 GetMagickToken(q,&q,token);
2510 (void) FormatMagickString(pattern,MaxTextExtent,"%s",token);
2511 if (GetImageArtifact(image,pattern) != (const char *) NULL)
2512 (void) DrawPatternPath(image,draw_info,token,
2513 &graphic_context[n]->stroke_pattern);
2516 status=QueryColorDatabase(token,&graphic_context[n]->stroke,
2518 if (status == MagickFalse)
2523 pattern_info=AcquireImageInfo();
2524 (void) CopyMagickString(pattern_info->filename,token,
2526 graphic_context[n]->stroke_pattern=
2527 ReadImage(pattern_info,&image->exception);
2528 CatchException(&image->exception);
2529 pattern_info=DestroyImageInfo(pattern_info);
2534 if (LocaleCompare("stroke-antialias",keyword) == 0)
2536 GetMagickToken(q,&q,token);
2537 graphic_context[n]->stroke_antialias=
2538 StringToLong(token) != 0 ? MagickTrue : MagickFalse;
2541 if (LocaleCompare("stroke-dasharray",keyword) == 0)
2543 if (graphic_context[n]->dash_pattern != (double *) NULL)
2544 graphic_context[n]->dash_pattern=(double *)
2545 RelinquishMagickMemory(graphic_context[n]->dash_pattern);
2546 if (IsPoint(q) != MagickFalse)
2552 GetMagickToken(p,&p,token);
2554 GetMagickToken(p,&p,token);
2555 for (x=0; IsPoint(token) != MagickFalse; x++)
2557 GetMagickToken(p,&p,token);
2559 GetMagickToken(p,&p,token);
2561 graphic_context[n]->dash_pattern=(double *)
2562 AcquireQuantumMemory((size_t) (2UL*x+1UL),
2563 sizeof(*graphic_context[n]->dash_pattern));
2564 if (graphic_context[n]->dash_pattern == (double *) NULL)
2566 (void) ThrowMagickException(&image->exception,
2567 GetMagickModule(),ResourceLimitError,
2568 "MemoryAllocationFailed","`%s'",image->filename);
2571 for (j=0; j < x; j++)
2573 GetMagickToken(q,&q,token);
2575 GetMagickToken(q,&q,token);
2576 graphic_context[n]->dash_pattern[j]=StringToDouble(token);
2578 if ((x & 0x01) != 0)
2579 for ( ; j < (2*x); j++)
2580 graphic_context[n]->dash_pattern[j]=
2581 graphic_context[n]->dash_pattern[j-x];
2582 graphic_context[n]->dash_pattern[j]=0.0;
2585 GetMagickToken(q,&q,token);
2588 if (LocaleCompare("stroke-dashoffset",keyword) == 0)
2590 GetMagickToken(q,&q,token);
2591 graphic_context[n]->dash_offset=StringToDouble(token);
2594 if (LocaleCompare("stroke-linecap",keyword) == 0)
2599 GetMagickToken(q,&q,token);
2600 linecap=ParseMagickOption(MagickLineCapOptions,MagickFalse,token);
2606 graphic_context[n]->linecap=(LineCap) linecap;
2609 if (LocaleCompare("stroke-linejoin",keyword) == 0)
2614 GetMagickToken(q,&q,token);
2615 linejoin=ParseMagickOption(MagickLineJoinOptions,MagickFalse,token);
2621 graphic_context[n]->linejoin=(LineJoin) linejoin;
2624 if (LocaleCompare("stroke-miterlimit",keyword) == 0)
2626 GetMagickToken(q,&q,token);
2627 graphic_context[n]->miterlimit=StringToUnsignedLong(token);
2630 if (LocaleCompare("stroke-opacity",keyword) == 0)
2632 GetMagickToken(q,&q,token);
2633 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2634 graphic_context[n]->stroke.opacity=ClampToQuantum((MagickRealType)
2635 QuantumRange*(1.0-factor*StringToDouble(token)));
2638 if (LocaleCompare("stroke-width",keyword) == 0)
2640 GetMagickToken(q,&q,token);
2641 graphic_context[n]->stroke_width=StringToDouble(token);
2650 if (LocaleCompare("text",keyword) == 0)
2652 primitive_type=TextPrimitive;
2655 if (LocaleCompare("text-align",keyword) == 0)
2660 GetMagickToken(q,&q,token);
2661 align=ParseMagickOption(MagickAlignOptions,MagickFalse,token);
2667 graphic_context[n]->align=(AlignType) align;
2670 if (LocaleCompare("text-anchor",keyword) == 0)
2675 GetMagickToken(q,&q,token);
2676 align=ParseMagickOption(MagickAlignOptions,MagickFalse,token);
2682 graphic_context[n]->align=(AlignType) align;
2685 if (LocaleCompare("text-antialias",keyword) == 0)
2687 GetMagickToken(q,&q,token);
2688 graphic_context[n]->text_antialias=
2689 StringToLong(token) != 0 ? MagickTrue : MagickFalse;
2692 if (LocaleCompare("text-undercolor",keyword) == 0)
2694 GetMagickToken(q,&q,token);
2695 (void) QueryColorDatabase(token,&graphic_context[n]->undercolor,
2699 if (LocaleCompare("translate",keyword) == 0)
2701 GetMagickToken(q,&q,token);
2702 affine.tx=StringToDouble(token);
2703 GetMagickToken(q,&q,token);
2705 GetMagickToken(q,&q,token);
2706 affine.ty=StringToDouble(token);
2715 if (LocaleCompare("viewbox",keyword) == 0)
2717 GetMagickToken(q,&q,token);
2718 graphic_context[n]->viewbox.x=(ssize_t) ceil(StringToDouble(token)-
2720 GetMagickToken(q,&q,token);
2722 GetMagickToken(q,&q,token);
2723 graphic_context[n]->viewbox.y=(ssize_t) ceil(StringToDouble(token)-
2725 GetMagickToken(q,&q,token);
2727 GetMagickToken(q,&q,token);
2728 graphic_context[n]->viewbox.width=(size_t) floor(
2729 StringToDouble(token)+0.5);
2730 GetMagickToken(q,&q,token);
2732 GetMagickToken(q,&q,token);
2733 graphic_context[n]->viewbox.height=(size_t) floor(
2734 StringToDouble(token)+0.5);
2746 if (status == MagickFalse)
2748 if ((affine.sx != 1.0) || (affine.rx != 0.0) || (affine.ry != 0.0) ||
2749 (affine.sy != 1.0) || (affine.tx != 0.0) || (affine.ty != 0.0))
2751 graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
2752 graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
2753 graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
2754 graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
2755 graphic_context[n]->affine.tx=current.sx*affine.tx+current.ry*affine.ty+
2757 graphic_context[n]->affine.ty=current.rx*affine.tx+current.sy*affine.ty+
2760 if (primitive_type == UndefinedPrimitive)
2762 if (image->debug != MagickFalse)
2763 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",
2768 Parse the primitive attributes.
2772 primitive_info[0].point.x=0.0;
2773 primitive_info[0].point.y=0.0;
2774 for (x=0; *q != '\0'; x++)
2779 if (IsPoint(q) == MagickFalse)
2781 GetMagickToken(q,&q,token);
2782 point.x=StringToDouble(token);
2783 GetMagickToken(q,&q,token);
2785 GetMagickToken(q,&q,token);
2786 point.y=StringToDouble(token);
2787 GetMagickToken(q,(const char **) NULL,token);
2789 GetMagickToken(q,&q,token);
2790 primitive_info[i].primitive=primitive_type;
2791 primitive_info[i].point=point;
2792 primitive_info[i].coordinates=0;
2793 primitive_info[i].method=FloodfillMethod;
2795 if (i < (ssize_t) number_points)
2798 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,
2799 (size_t) number_points,sizeof(*primitive_info));
2800 if (primitive_info == (PrimitiveInfo *) NULL)
2802 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2803 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
2807 primitive_info[j].primitive=primitive_type;
2808 primitive_info[j].coordinates=(size_t) x;
2809 primitive_info[j].method=FloodfillMethod;
2810 primitive_info[j].text=(char *) NULL;
2812 Circumscribe primitive within a circle.
2814 bounds.x1=primitive_info[j].point.x;
2815 bounds.y1=primitive_info[j].point.y;
2816 bounds.x2=primitive_info[j].point.x;
2817 bounds.y2=primitive_info[j].point.y;
2818 for (k=1; k < (ssize_t) primitive_info[j].coordinates; k++)
2820 point=primitive_info[j+k].point;
2821 if (point.x < bounds.x1)
2823 if (point.y < bounds.y1)
2825 if (point.x > bounds.x2)
2827 if (point.y > bounds.y2)
2831 Speculate how many points our primitive might consume.
2833 length=primitive_info[j].coordinates;
2834 switch (primitive_type)
2836 case RectanglePrimitive:
2841 case RoundRectanglePrimitive:
2843 length*=5+8*BezierQuantum;
2846 case BezierPrimitive:
2848 if (primitive_info[j].coordinates > 107)
2849 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2850 DrawError,"TooManyBezierCoordinates","`%s'",token);
2851 length=BezierQuantum*primitive_info[j].coordinates;
2860 GetMagickToken(q,&q,token);
2863 for (s=token; *s != '\0'; s=t)
2875 length+=BezierQuantum;
2879 case CirclePrimitive:
2881 case EllipsePrimitive:
2888 alpha=bounds.x2-bounds.x1;
2889 beta=bounds.y2-bounds.y1;
2890 radius=hypot((double) alpha,(double) beta);
2891 length=2*((size_t) (MagickPI*radius))+6*BezierQuantum+360+1;
2897 if ((size_t) (i+length) >= number_points)
2900 Resize based on speculative points required by primitive.
2902 number_points+=length+1;
2903 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,
2904 (size_t) number_points,sizeof(*primitive_info));
2905 if (primitive_info == (PrimitiveInfo *) NULL)
2907 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2908 ResourceLimitError,"MemoryAllocationFailed","`%s'",
2913 switch (primitive_type)
2915 case PointPrimitive:
2918 if (primitive_info[j].coordinates != 1)
2923 TracePoint(primitive_info+j,primitive_info[j].point);
2924 i=(ssize_t) (j+primitive_info[j].coordinates);
2929 if (primitive_info[j].coordinates != 2)
2934 TraceLine(primitive_info+j,primitive_info[j].point,
2935 primitive_info[j+1].point);
2936 i=(ssize_t) (j+primitive_info[j].coordinates);
2939 case RectanglePrimitive:
2941 if (primitive_info[j].coordinates != 2)
2946 TraceRectangle(primitive_info+j,primitive_info[j].point,
2947 primitive_info[j+1].point);
2948 i=(ssize_t) (j+primitive_info[j].coordinates);
2951 case RoundRectanglePrimitive:
2953 if (primitive_info[j].coordinates != 3)
2958 TraceRoundRectangle(primitive_info+j,primitive_info[j].point,
2959 primitive_info[j+1].point,primitive_info[j+2].point);
2960 i=(ssize_t) (j+primitive_info[j].coordinates);
2965 if (primitive_info[j].coordinates != 3)
2967 primitive_type=UndefinedPrimitive;
2970 TraceArc(primitive_info+j,primitive_info[j].point,
2971 primitive_info[j+1].point,primitive_info[j+2].point);
2972 i=(ssize_t) (j+primitive_info[j].coordinates);
2975 case EllipsePrimitive:
2977 if (primitive_info[j].coordinates != 3)
2982 TraceEllipse(primitive_info+j,primitive_info[j].point,
2983 primitive_info[j+1].point,primitive_info[j+2].point);
2984 i=(ssize_t) (j+primitive_info[j].coordinates);
2987 case CirclePrimitive:
2989 if (primitive_info[j].coordinates != 2)
2994 TraceCircle(primitive_info+j,primitive_info[j].point,
2995 primitive_info[j+1].point);
2996 i=(ssize_t) (j+primitive_info[j].coordinates);
2999 case PolylinePrimitive:
3001 case PolygonPrimitive:
3003 primitive_info[i]=primitive_info[j];
3004 primitive_info[i].coordinates=0;
3005 primitive_info[j].coordinates++;
3009 case BezierPrimitive:
3011 if (primitive_info[j].coordinates < 3)
3016 TraceBezier(primitive_info+j,primitive_info[j].coordinates);
3017 i=(ssize_t) (j+primitive_info[j].coordinates);
3022 i=(ssize_t) (j+TracePath(primitive_info+j,token));
3025 case ColorPrimitive:
3026 case MattePrimitive:
3031 if (primitive_info[j].coordinates != 1)
3036 GetMagickToken(q,&q,token);
3037 method=ParseMagickOption(MagickMethodOptions,MagickFalse,token);
3043 primitive_info[j].method=(PaintMethod) method;
3048 if (primitive_info[j].coordinates != 1)
3054 GetMagickToken(q,&q,token);
3055 primitive_info[j].text=AcquireString(token);
3058 case ImagePrimitive:
3060 if (primitive_info[j].coordinates != 2)
3065 GetMagickToken(q,&q,token);
3066 primitive_info[j].text=AcquireString(token);
3070 if (primitive_info == (PrimitiveInfo *) NULL)
3072 if (image->debug != MagickFalse)
3073 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",(int) (q-p),p);
3074 if (status == MagickFalse)
3076 primitive_info[i].primitive=UndefinedPrimitive;
3082 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
3084 point=primitive_info[i].point;
3085 primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+
3086 graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx;
3087 primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+
3088 graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty;
3089 point=primitive_info[i].point;
3090 if (point.x < graphic_context[n]->bounds.x1)
3091 graphic_context[n]->bounds.x1=point.x;
3092 if (point.y < graphic_context[n]->bounds.y1)
3093 graphic_context[n]->bounds.y1=point.y;
3094 if (point.x > graphic_context[n]->bounds.x2)
3095 graphic_context[n]->bounds.x2=point.x;
3096 if (point.y > graphic_context[n]->bounds.y2)
3097 graphic_context[n]->bounds.y2=point.y;
3098 if (primitive_info[i].primitive == ImagePrimitive)
3100 if (i >= (ssize_t) number_points)
3101 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
3103 if (graphic_context[n]->render != MagickFalse)
3105 if ((n != 0) && (graphic_context[n]->clip_mask != (char *) NULL) &&
3106 (LocaleCompare(graphic_context[n]->clip_mask,
3107 graphic_context[n-1]->clip_mask) != 0))
3108 (void) DrawClipPath(image,graphic_context[n],
3109 graphic_context[n]->clip_mask);
3110 (void) DrawPrimitive(image,graphic_context[n],primitive_info);
3112 if (primitive_info->text != (char *) NULL)
3113 primitive_info->text=(char *) RelinquishMagickMemory(
3114 primitive_info->text);
3115 proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType)
3117 if (proceed == MagickFalse)
3120 if (image->debug != MagickFalse)
3121 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end draw-image");
3123 Relinquish resources.
3125 token=DestroyString(token);
3126 if (primitive_info != (PrimitiveInfo *) NULL)
3127 primitive_info=(PrimitiveInfo *) RelinquishMagickMemory(primitive_info);
3128 primitive=DestroyString(primitive);
3129 for ( ; n >= 0; n--)
3130 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
3131 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
3132 if (status == MagickFalse)
3133 ThrowBinaryException(DrawError,"NonconformingDrawingPrimitiveDefinition",
3139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3143 % D r a w G r a d i e n t I m a g e %
3147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3149 % DrawGradientImage() draws a linear gradient on the image.
3151 % The format of the DrawGradientImage method is:
3153 % MagickBooleanType DrawGradientImage(Image *image,
3154 % const DrawInfo *draw_info)
3156 % A description of each parameter follows:
3158 % o image: the image.
3160 % o _info: the draw info.
3164 static inline MagickRealType GetStopColorOffset(const GradientInfo *gradient,
3165 const ssize_t x,const ssize_t y)
3167 switch (gradient->type)
3169 case UndefinedGradient:
3170 case LinearGradient:
3185 gradient_vector=(&gradient->gradient_vector);
3186 p.x=gradient_vector->x2-gradient_vector->x1;
3187 p.y=gradient_vector->y2-gradient_vector->y1;
3188 q.x=(double) x-gradient_vector->x1;
3189 q.y=(double) y-gradient_vector->y1;
3190 length=sqrt(q.x*q.x+q.y*q.y);
3191 gamma=sqrt(p.x*p.x+p.y*p.y)*length;
3192 gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
3193 scale=p.x*q.x+p.y*q.y;
3194 offset=gamma*scale*length;
3197 case RadialGradient:
3206 v.x=(double) x-gradient->center.x;
3207 v.y=(double) y-gradient->center.y;
3208 length=sqrt(v.x*v.x+v.y*v.y);
3209 if (gradient->spread == RepeatSpread)
3211 offset=length/gradient->radius;
3218 MagickExport MagickBooleanType DrawGradientImage(Image *image,
3219 const DrawInfo *draw_info)
3252 Draw linear or radial gradient on image.
3254 assert(image != (Image *) NULL);
3255 assert(image->signature == MagickSignature);
3256 if (image->debug != MagickFalse)
3257 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3258 assert(draw_info != (const DrawInfo *) NULL);
3259 gradient=(&draw_info->gradient);
3260 gradient_vector=(&gradient->gradient_vector);
3261 point.x=gradient_vector->x2-gradient_vector->x1;
3262 point.y=gradient_vector->y2-gradient_vector->y1;
3263 length=sqrt(point.x*point.x+point.y*point.y);
3264 bounding_box=gradient->bounding_box;
3266 exception=(&image->exception);
3267 GetMagickPixelPacket(image,&zero);
3268 image_view=AcquireCacheView(image);
3269 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3270 #pragma omp parallel for schedule(dynamic,4) shared(status)
3272 for (y=bounding_box.y; y < (ssize_t) bounding_box.height; y++)
3282 register IndexPacket
3289 register PixelPacket
3295 if (status == MagickFalse)
3297 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3298 if (q == (PixelPacket *) NULL)
3303 indexes=GetCacheViewAuthenticIndexQueue(image_view);
3306 offset=GetStopColorOffset(gradient,0,y);
3307 if (gradient->type != RadialGradient)
3309 for (x=bounding_box.x; x < (ssize_t) bounding_box.width; x++)
3311 SetMagickPixelPacket(image,q,indexes+x,&pixel);
3312 switch (gradient->spread)
3314 case UndefinedSpread:
3317 if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) ||
3318 (y != (ssize_t) ceil(gradient_vector->y1-0.5)))
3320 offset=GetStopColorOffset(gradient,x,y);
3321 if (gradient->type != RadialGradient)
3324 for (i=0; i < (ssize_t) gradient->number_stops; i++)
3325 if (offset < gradient->stops[i].offset)
3327 if ((offset < 0.0) || (i == 0))
3328 composite=gradient->stops[0].color;
3330 if ((offset > 1.0) || (i == (ssize_t) gradient->number_stops))
3331 composite=gradient->stops[gradient->number_stops-1].color;
3336 alpha=(offset-gradient->stops[i].offset)/
3337 (gradient->stops[j].offset-gradient->stops[i].offset);
3338 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3339 &gradient->stops[j].color,alpha,&composite);
3345 if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) ||
3346 (y != (ssize_t) ceil(gradient_vector->y1-0.5)))
3348 offset=GetStopColorOffset(gradient,x,y);
3349 if (gradient->type != RadialGradient)
3354 if ((ssize_t) fmod(offset,2.0) == 0)
3355 offset=fmod(offset,1.0);
3357 offset=1.0-fmod(offset,1.0);
3358 for (i=0; i < (ssize_t) gradient->number_stops; i++)
3359 if (offset < gradient->stops[i].offset)
3362 composite=gradient->stops[0].color;
3364 if (i == (ssize_t) gradient->number_stops)
3365 composite=gradient->stops[gradient->number_stops-1].color;
3370 alpha=(offset-gradient->stops[i].offset)/
3371 (gradient->stops[j].offset-gradient->stops[i].offset);
3372 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3373 &gradient->stops[j].color,alpha,&composite);
3385 antialias=MagickFalse;
3387 if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) ||
3388 (y != (ssize_t) ceil(gradient_vector->y1-0.5)))
3390 offset=GetStopColorOffset(gradient,x,y);
3391 if (gradient->type == LinearGradient)
3393 repeat=fmod(offset,length);
3395 repeat=length-fmod(-repeat,length);
3397 repeat=fmod(offset,length);
3398 antialias=(repeat < length) && ((repeat+1.0) > length) ?
3399 MagickTrue : MagickFalse;
3400 offset=repeat/length;
3404 repeat=fmod(offset,gradient->radius);
3406 repeat=gradient->radius-fmod(-repeat,gradient->radius);
3408 repeat=fmod(offset,gradient->radius);
3409 antialias=repeat+1.0 > gradient->radius ?
3410 MagickTrue : MagickFalse;
3411 offset=repeat/gradient->radius;
3414 for (i=0; i < (ssize_t) gradient->number_stops; i++)
3415 if (offset < gradient->stops[i].offset)
3418 composite=gradient->stops[0].color;
3420 if (i == (ssize_t) gradient->number_stops)
3421 composite=gradient->stops[gradient->number_stops-1].color;
3426 alpha=(offset-gradient->stops[i].offset)/
3427 (gradient->stops[j].offset-gradient->stops[i].offset);
3428 if (antialias != MagickFalse)
3430 if (gradient->type == LinearGradient)
3431 alpha=length-repeat;
3433 alpha=gradient->radius-repeat;
3435 j=(ssize_t) gradient->number_stops-1L;
3437 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3438 &gradient->stops[j].color,alpha,&composite);
3443 MagickPixelCompositeOver(&composite,composite.opacity,&pixel,
3444 pixel.opacity,&pixel);
3445 SetPixelPacket(image,&pixel,q,indexes+x);
3448 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3451 image_view=DestroyCacheView(image_view);
3456 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3460 % D r a w P a t t e r n P a t h %
3464 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3466 % DrawPatternPath() draws a pattern.
3468 % The format of the DrawPatternPath method is:
3470 % MagickBooleanType DrawPatternPath(Image *image,const DrawInfo *draw_info,
3471 % const char *name,Image **pattern)
3473 % A description of each parameter follows:
3475 % o image: the image.
3477 % o draw_info: the draw info.
3479 % o name: the pattern name.
3481 % o image: the image.
3484 MagickExport MagickBooleanType DrawPatternPath(Image *image,
3485 const DrawInfo *draw_info,const char *name,Image **pattern)
3488 property[MaxTextExtent];
3503 assert(image != (Image *) NULL);
3504 assert(image->signature == MagickSignature);
3505 if (image->debug != MagickFalse)
3506 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3507 assert(draw_info != (const DrawInfo *) NULL);
3508 assert(name != (const char *) NULL);
3509 (void) FormatMagickString(property,MaxTextExtent,"%s",name);
3510 path=GetImageArtifact(image,property);
3511 if (path == (const char *) NULL)
3512 return(MagickFalse);
3513 (void) FormatMagickString(property,MaxTextExtent,"%s-geometry",name);
3514 geometry=GetImageArtifact(image,property);
3515 if (geometry == (const char *) NULL)
3516 return(MagickFalse);
3517 if ((*pattern) != (Image *) NULL)
3518 *pattern=DestroyImage(*pattern);
3519 image_info=AcquireImageInfo();
3520 image_info->size=AcquireString(geometry);
3521 *pattern=AcquireImage(image_info);
3522 image_info=DestroyImageInfo(image_info);
3523 (void) QueryColorDatabase("#00000000",&(*pattern)->background_color,
3525 (void) SetImageBackgroundColor(*pattern);
3526 if (image->debug != MagickFalse)
3527 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
3528 "begin pattern-path %s %s",name,geometry);
3529 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
3530 clone_info->fill_pattern=NewImageList();
3531 clone_info->stroke_pattern=NewImageList();
3532 (void) CloneString(&clone_info->primitive,path);
3533 status=DrawImage(*pattern,clone_info);
3534 clone_info=DestroyDrawInfo(clone_info);
3535 if (image->debug != MagickFalse)
3536 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end pattern-path");
3541 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3545 + D r a w P o l y g o n P r i m i t i v e %
3549 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3551 % DrawPolygonPrimitive() draws a polygon on the image.
3553 % The format of the DrawPolygonPrimitive method is:
3555 % MagickBooleanType DrawPolygonPrimitive(Image *image,
3556 % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
3558 % A description of each parameter follows:
3560 % o image: the image.
3562 % o draw_info: the draw info.
3564 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
3568 static PolygonInfo **DestroyPolygonThreadSet(PolygonInfo **polygon_info)
3573 assert(polygon_info != (PolygonInfo **) NULL);
3574 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
3575 if (polygon_info[i] != (PolygonInfo *) NULL)
3576 polygon_info[i]=DestroyPolygonInfo(polygon_info[i]);
3577 polygon_info=(PolygonInfo **) RelinquishMagickMemory(polygon_info);
3578 return(polygon_info);
3581 static PolygonInfo **AcquirePolygonThreadSet(const DrawInfo *draw_info,
3582 const PrimitiveInfo *primitive_info)
3585 *restrict path_info;
3596 number_threads=GetOpenMPMaximumThreads();
3597 polygon_info=(PolygonInfo **) AcquireQuantumMemory(number_threads,
3598 sizeof(*polygon_info));
3599 if (polygon_info == (PolygonInfo **) NULL)
3600 return((PolygonInfo **) NULL);
3601 (void) ResetMagickMemory(polygon_info,0,GetOpenMPMaximumThreads()*
3602 sizeof(*polygon_info));
3603 path_info=ConvertPrimitiveToPath(draw_info,primitive_info);
3604 if (path_info == (PathInfo *) NULL)
3605 return(DestroyPolygonThreadSet(polygon_info));
3606 for (i=0; i < (ssize_t) number_threads; i++)
3608 polygon_info[i]=ConvertPathToPolygon(draw_info,path_info);
3609 if (polygon_info[i] == (PolygonInfo *) NULL)
3610 return(DestroyPolygonThreadSet(polygon_info));
3612 path_info=(PathInfo *) RelinquishMagickMemory(path_info);
3613 return(polygon_info);
3616 static MagickRealType GetPixelOpacity(PolygonInfo *polygon_info,
3617 const MagickRealType mid,const MagickBooleanType fill,
3618 const FillRule fill_rule,const double x,const double y,
3619 MagickRealType *stroke_opacity)
3633 register const PointInfo
3644 Compute fill & stroke opacity for this (x,y) point.
3646 *stroke_opacity=0.0;
3647 subpath_opacity=0.0;
3648 p=polygon_info->edges;
3649 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
3651 if (y <= (p->bounds.y1-mid-0.5))
3653 if (y > (p->bounds.y2+mid+0.5))
3655 (void) DestroyEdge(polygon_info,(size_t) j);
3658 if ((x <= (p->bounds.x1-mid-0.5)) || (x > (p->bounds.x2+mid+0.5)))
3660 i=(ssize_t) MagickMax((double) p->highwater,1.0);
3661 for ( ; i < (ssize_t) p->number_points; i++)
3663 if (y <= (p->points[i-1].y-mid-0.5))
3665 if (y > (p->points[i].y+mid+0.5))
3667 if (p->scanline != y)
3670 p->highwater=(size_t) i;
3673 Compute distance between a point and an edge.
3676 delta.x=(q+1)->x-q->x;
3677 delta.y=(q+1)->y-q->y;
3678 beta=delta.x*(x-q->x)+delta.y*(y-q->y);
3683 distance=delta.x*delta.x+delta.y*delta.y;
3687 alpha=delta.x*delta.x+delta.y*delta.y;
3692 distance=delta.x*delta.x+delta.y*delta.y;
3697 beta=delta.x*(y-q->y)-delta.y*(x-q->x);
3698 distance=alpha*beta*beta;
3702 Compute stroke & subpath opacity.
3705 if (p->ghostline == MagickFalse)
3708 if ((*stroke_opacity < 1.0) &&
3709 (distance <= ((alpha+0.25)*(alpha+0.25))))
3712 if (distance <= ((alpha+0.25)*(alpha+0.25)))
3713 *stroke_opacity=1.0;
3717 if (distance != 1.0)
3718 beta=sqrt((double) distance);
3720 if (*stroke_opacity < ((alpha-0.25)*(alpha-0.25)))
3721 *stroke_opacity=(alpha-0.25)*(alpha-0.25);
3725 if ((fill == MagickFalse) || (distance > 1.0) || (subpath_opacity >= 1.0))
3727 if (distance <= 0.0)
3729 subpath_opacity=1.0;
3737 if (distance != 1.0)
3738 beta=sqrt(distance);
3741 if (subpath_opacity < (alpha*alpha))
3742 subpath_opacity=alpha*alpha;
3746 Compute fill opacity.
3748 if (fill == MagickFalse)
3750 if (subpath_opacity >= 1.0)
3753 Determine winding number.
3756 p=polygon_info->edges;
3757 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
3759 if (y <= p->bounds.y1)
3761 if ((y > p->bounds.y2) || (x <= p->bounds.x1))
3763 if (x > p->bounds.x2)
3765 winding_number+=p->direction ? 1 : -1;
3768 i=(ssize_t) MagickMax((double) p->highwater,1.0);
3769 for ( ; i < (ssize_t) p->number_points; i++)
3770 if (y <= p->points[i].y)
3773 if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x)))
3774 winding_number+=p->direction ? 1 : -1;
3776 if (fill_rule != NonZeroRule)
3778 if ((MagickAbsoluteValue(winding_number) & 0x01) != 0)
3782 if (MagickAbsoluteValue(winding_number) != 0)
3784 return(subpath_opacity);
3787 static MagickBooleanType DrawPolygonPrimitive(Image *image,
3788 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
3804 **restrict polygon_info;
3821 Compute bounding box.
3823 assert(image != (Image *) NULL);
3824 assert(image->signature == MagickSignature);
3825 if (image->debug != MagickFalse)
3826 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3827 assert(draw_info != (DrawInfo *) NULL);
3828 assert(draw_info->signature == MagickSignature);
3829 assert(primitive_info != (PrimitiveInfo *) NULL);
3830 if (primitive_info->coordinates == 0)
3832 polygon_info=AcquirePolygonThreadSet(draw_info,primitive_info);
3833 if (polygon_info == (PolygonInfo **) NULL)
3834 return(MagickFalse);
3836 DrawBoundingRectangles(image,draw_info,polygon_info[0]);
3837 if (image->debug != MagickFalse)
3838 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-polygon");
3839 fill=(primitive_info->method == FillToBorderMethod) ||
3840 (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse;
3841 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
3842 bounds=polygon_info[0]->edges[0].bounds;
3843 for (i=1; i < (ssize_t) polygon_info[0]->number_edges; i++)
3845 p=polygon_info[0]->edges+i;
3846 if (p->bounds.x1 < bounds.x1)
3847 bounds.x1=p->bounds.x1;
3848 if (p->bounds.y1 < bounds.y1)
3849 bounds.y1=p->bounds.y1;
3850 if (p->bounds.x2 > bounds.x2)
3851 bounds.x2=p->bounds.x2;
3852 if (p->bounds.y2 > bounds.y2)
3853 bounds.y2=p->bounds.y2;
3855 bounds.x1-=(mid+1.0);
3856 bounds.x1=bounds.x1 < 0.0 ? 0.0 : (size_t) ceil(bounds.x1-0.5) >=
3857 image->columns ? (double) image->columns-1.0 : bounds.x1;
3858 bounds.y1-=(mid+1.0);
3859 bounds.y1=bounds.y1 < 0.0 ? 0.0 : (size_t) ceil(bounds.y1-0.5) >=
3860 image->rows ? (double) image->rows-1.0 : bounds.y1;
3861 bounds.x2+=(mid+1.0);
3862 bounds.x2=bounds.x2 < 0.0 ? 0.0 : (size_t) floor(bounds.x2+0.5) >=
3863 image->columns ? (double) image->columns-1.0 : bounds.x2;
3864 bounds.y2+=(mid+1.0);
3865 bounds.y2=bounds.y2 < 0.0 ? 0.0 : (size_t) floor(bounds.y2+0.5) >=
3866 image->rows ? (double) image->rows-1.0 : bounds.y2;
3868 exception=(&image->exception);
3869 start=(ssize_t) ceil(bounds.x1-0.5);
3870 stop=(ssize_t) floor(bounds.x2+0.5);
3871 image_view=AcquireCacheView(image);
3872 if (primitive_info->coordinates == 1)
3877 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3878 #pragma omp parallel for schedule(dynamic,4) shared(status)
3880 for (y=(ssize_t) ceil(bounds.y1-0.5); y <= (ssize_t) floor(bounds.y2+0.5); y++)
3888 register PixelPacket
3891 if (status == MagickFalse)
3894 q=GetCacheViewAuthenticPixels(image_view,x,y,(size_t) (stop-x+1),
3896 if (q == (PixelPacket *) NULL)
3901 for ( ; x <= stop; x++)
3903 if ((x == (ssize_t) ceil(primitive_info->point.x-0.5)) &&
3904 (y == (ssize_t) ceil(primitive_info->point.y-0.5)))
3905 (void) GetStrokeColor(draw_info,x,y,q);
3908 sync=SyncCacheViewAuthenticPixels(image_view,exception);
3909 if (sync == MagickFalse)
3912 image_view=DestroyCacheView(image_view);
3913 polygon_info=DestroyPolygonThreadSet(polygon_info);
3914 if (image->debug != MagickFalse)
3915 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
3916 " end draw-polygon");
3920 Draw polygon or line.
3922 if (image->matte == MagickFalse)
3923 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3924 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3925 #pragma omp parallel for schedule(dynamic,4) shared(status)
3927 for (y=(ssize_t) ceil(bounds.y1-0.5); y <= (ssize_t) floor(bounds.y2+0.5); y++)
3930 id = GetOpenMPThreadId();
3940 register PixelPacket
3946 if (status == MagickFalse)
3948 q=GetCacheViewAuthenticPixels(image_view,start,y,(size_t) (stop-
3949 start+1),1,exception);
3950 if (q == (PixelPacket *) NULL)
3955 for (x=start; x <= stop; x++)
3960 fill_opacity=GetPixelOpacity(polygon_info[id],mid,fill,
3961 draw_info->fill_rule,(double) x,(double) y,&stroke_opacity);
3962 if (draw_info->stroke_antialias == MagickFalse)
3964 fill_opacity=fill_opacity > 0.25 ? 1.0 : 0.0;
3965 stroke_opacity=stroke_opacity > 0.25 ? 1.0 : 0.0;
3967 (void) GetFillColor(draw_info,x,y,&fill_color);
3968 fill_opacity=(MagickRealType) (QuantumRange-fill_opacity*(QuantumRange-
3969 fill_color.opacity));
3970 MagickCompositeOver(&fill_color,fill_opacity,q,(MagickRealType)
3972 (void) GetStrokeColor(draw_info,x,y,&stroke_color);
3973 stroke_opacity=(MagickRealType) (QuantumRange-stroke_opacity*
3974 (QuantumRange-stroke_color.opacity));
3975 MagickCompositeOver(&stroke_color,stroke_opacity,q,(MagickRealType)
3979 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3982 image_view=DestroyCacheView(image_view);
3983 polygon_info=DestroyPolygonThreadSet(polygon_info);
3984 if (image->debug != MagickFalse)
3985 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-polygon");
3990 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3994 % D r a w P r i m i t i v e %
3998 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4000 % DrawPrimitive() draws a primitive (line, rectangle, ellipse) on the image.
4002 % The format of the DrawPrimitive method is:
4004 % MagickBooleanType DrawPrimitive(Image *image,const DrawInfo *draw_info,
4005 % PrimitiveInfo *primitive_info)
4007 % A description of each parameter follows:
4009 % o image: the image.
4011 % o draw_info: the draw info.
4013 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
4017 static void LogPrimitiveInfo(const PrimitiveInfo *primitive_info)
4043 x=(ssize_t) ceil(primitive_info->point.x-0.5);
4044 y=(ssize_t) ceil(primitive_info->point.y-0.5);
4045 switch (primitive_info->primitive)
4047 case PointPrimitive:
4049 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4050 "PointPrimitive %.20g,%.20g %s",(double) x,(double) y,
4051 methods[primitive_info->method]);
4054 case ColorPrimitive:
4056 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4057 "ColorPrimitive %.20g,%.20g %s",(double) x,(double) y,
4058 methods[primitive_info->method]);
4061 case MattePrimitive:
4063 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4064 "MattePrimitive %.20g,%.20g %s",(double) x,(double) y,
4065 methods[primitive_info->method]);
4070 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4071 "TextPrimitive %.20g,%.20g",(double) x,(double) y);
4074 case ImagePrimitive:
4076 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4077 "ImagePrimitive %.20g,%.20g",(double) x,(double) y);
4084 p=primitive_info[0].point;
4087 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4089 point=primitive_info[i].point;
4090 if (coordinates <= 0)
4092 coordinates=(ssize_t) primitive_info[i].coordinates;
4093 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4094 " begin open (%.20g)",(double) coordinates);
4097 point=primitive_info[i].point;
4098 if ((fabs(q.x-point.x) > MagickEpsilon) ||
4099 (fabs(q.y-point.y) > MagickEpsilon))
4100 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4101 " %.20g: %.18g,%.18g",(double) coordinates,point.x,point.y);
4103 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4104 " %.20g: %g,%g (duplicate)",(double) coordinates,point.x,point.y);
4107 if (coordinates > 0)
4109 if ((fabs(p.x-point.x) > MagickEpsilon) ||
4110 (fabs(p.y-point.y) > MagickEpsilon))
4111 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end last (%.20g)",
4112 (double) coordinates);
4114 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end open (%.20g)",
4115 (double) coordinates);
4119 MagickExport MagickBooleanType DrawPrimitive(Image *image,
4120 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4138 if (image->debug != MagickFalse)
4140 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4141 " begin draw-primitive");
4142 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4143 " affine: %g,%g,%g,%g,%g,%g",draw_info->affine.sx,
4144 draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy,
4145 draw_info->affine.tx,draw_info->affine.ty);
4148 exception=(&image->exception);
4149 x=(ssize_t) ceil(primitive_info->point.x-0.5);
4150 y=(ssize_t) ceil(primitive_info->point.y-0.5);
4151 image_view=AcquireCacheView(image);
4152 switch (primitive_info->primitive)
4154 case PointPrimitive:
4162 if ((y < 0) || (y >= (ssize_t) image->rows))
4164 if ((x < 0) || (x >= (ssize_t) image->columns))
4166 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4167 if (q == (PixelPacket *) NULL)
4169 (void) GetFillColor(draw_info,x,y,&fill_color);
4170 MagickCompositeOver(&fill_color,(MagickRealType) fill_color.opacity,q,
4171 (MagickRealType) q->opacity,q);
4172 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4175 case ColorPrimitive:
4177 switch (primitive_info->method)
4185 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4186 if (q == (PixelPacket *) NULL)
4188 (void) GetFillColor(draw_info,x,y,q);
4189 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4200 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception);
4201 for (y=0; y < (ssize_t) image->rows; y++)
4203 register PixelPacket
4206 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4208 if (q == (PixelPacket *) NULL)
4210 for (x=0; x < (ssize_t) image->columns; x++)
4212 if (IsColorSimilar(image,q,&target) == MagickFalse)
4217 (void) GetFillColor(draw_info,x,y,q);
4220 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4221 if (sync == MagickFalse)
4226 case FloodfillMethod:
4227 case FillToBorderMethod:
4232 (void) GetOneVirtualMagickPixel(image,x,y,&target,exception);
4233 if (primitive_info->method == FillToBorderMethod)
4235 target.red=(MagickRealType) draw_info->border_color.red;
4236 target.green=(MagickRealType) draw_info->border_color.green;
4237 target.blue=(MagickRealType) draw_info->border_color.blue;
4239 (void) FloodfillPaintImage(image,DefaultChannels,draw_info,&target,x,
4240 y,primitive_info->method == FloodfillMethod ? MagickFalse :
4249 for (y=0; y < (ssize_t) image->rows; y++)
4251 register PixelPacket
4257 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4259 if (q == (PixelPacket *) NULL)
4261 for (x=0; x < (ssize_t) image->columns; x++)
4263 (void) GetFillColor(draw_info,x,y,q);
4266 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4267 if (sync == MagickFalse)
4275 case MattePrimitive:
4277 if (image->matte == MagickFalse)
4278 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
4279 switch (primitive_info->method)
4290 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4291 if (q == (PixelPacket *) NULL)
4293 (void) GetFillColor(draw_info,x,y,&pixel);
4294 q->opacity=pixel.opacity;
4295 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4307 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception);
4308 for (y=0; y < (ssize_t) image->rows; y++)
4310 register PixelPacket
4316 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4318 if (q == (PixelPacket *) NULL)
4320 for (x=0; x < (ssize_t) image->columns; x++)
4322 if (IsColorSimilar(image,q,&target) == MagickFalse)
4327 (void) GetFillColor(draw_info,x,y,&pixel);
4328 q->opacity=pixel.opacity;
4331 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4332 if (sync == MagickFalse)
4337 case FloodfillMethod:
4338 case FillToBorderMethod:
4343 (void) GetOneVirtualMagickPixel(image,x,y,&target,exception);
4344 if (primitive_info->method == FillToBorderMethod)
4346 target.red=(MagickRealType) draw_info->border_color.red;
4347 target.green=(MagickRealType) draw_info->border_color.green;
4348 target.blue=(MagickRealType) draw_info->border_color.blue;
4350 (void) FloodfillPaintImage(image,OpacityChannel,draw_info,&target,x,y,
4351 primitive_info->method == FloodfillMethod ? MagickFalse :
4363 for (y=0; y < (ssize_t) image->rows; y++)
4365 register PixelPacket
4371 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4373 if (q == (PixelPacket *) NULL)
4375 for (x=0; x < (ssize_t) image->columns; x++)
4377 (void) GetFillColor(draw_info,x,y,&pixel);
4378 q->opacity=pixel.opacity;
4381 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4382 if (sync == MagickFalse)
4393 geometry[MaxTextExtent];
4398 if (primitive_info->text == (char *) NULL)
4400 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4401 (void) CloneString(&clone_info->text,primitive_info->text);
4402 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
4403 primitive_info->point.x,primitive_info->point.y);
4404 (void) CloneString(&clone_info->geometry,geometry);
4405 status=AnnotateImage(image,clone_info);
4406 clone_info=DestroyDrawInfo(clone_info);
4409 case ImagePrimitive:
4415 composite_geometry[MaxTextExtent];
4430 if (primitive_info->text == (char *) NULL)
4432 clone_info=AcquireImageInfo();
4433 if (LocaleNCompare(primitive_info->text,"data:",5) == 0)
4434 composite_image=ReadInlineImage(clone_info,primitive_info->text,
4438 (void) CopyMagickString(clone_info->filename,primitive_info->text,
4440 composite_image=ReadImage(clone_info,&image->exception);
4442 clone_info=DestroyImageInfo(clone_info);
4443 if (composite_image == (Image *) NULL)
4445 (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor)
4446 NULL,(void *) NULL);
4447 x1=(ssize_t) ceil(primitive_info[1].point.x-0.5);
4448 y1=(ssize_t) ceil(primitive_info[1].point.y-0.5);
4449 if (((x1 != 0L) && (x1 != (ssize_t) composite_image->columns)) ||
4450 ((y1 != 0L) && (y1 != (ssize_t) composite_image->rows)))
4453 geometry[MaxTextExtent];
4458 (void) FormatMagickString(geometry,MaxTextExtent,"%gx%g!",
4459 primitive_info[1].point.x,primitive_info[1].point.y);
4460 composite_image->filter=image->filter;
4461 (void) TransformImage(&composite_image,(char *) NULL,geometry);
4463 if (composite_image->matte == MagickFalse)
4464 (void) SetImageAlphaChannel(composite_image,OpaqueAlphaChannel);
4465 if (draw_info->opacity != OpaqueOpacity)
4466 (void) SetImageOpacity(composite_image,draw_info->opacity);
4467 SetGeometry(image,&geometry);
4468 image->gravity=draw_info->gravity;
4471 (void) FormatMagickString(composite_geometry,MaxTextExtent,
4472 "%.20gx%.20g%+.20g%+.20g",(double) composite_image->columns,(double)
4473 composite_image->rows,(double) geometry.x,(double) geometry.y);
4474 (void) ParseGravityGeometry(image,composite_geometry,&geometry,
4476 affine=draw_info->affine;
4477 affine.tx=(double) geometry.x;
4478 affine.ty=(double) geometry.y;
4479 composite_image->interpolate=image->interpolate;
4480 if (draw_info->compose == OverCompositeOp)
4481 (void) DrawAffineImage(image,composite_image,&affine);
4483 (void) CompositeImage(image,draw_info->compose,composite_image,
4484 geometry.x,geometry.y);
4485 composite_image=DestroyImage(composite_image);
4497 if (IsEventLogging() != MagickFalse)
4498 LogPrimitiveInfo(primitive_info);
4499 scale=ExpandAffine(&draw_info->affine);
4500 if ((draw_info->dash_pattern != (double *) NULL) &&
4501 (draw_info->dash_pattern[0] != 0.0) &&
4502 ((scale*draw_info->stroke_width) > MagickEpsilon) &&
4503 (draw_info->stroke.opacity != (Quantum) TransparentOpacity))
4508 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4509 clone_info->stroke_width=0.0;
4510 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4511 status=DrawPolygonPrimitive(image,clone_info,primitive_info);
4512 clone_info=DestroyDrawInfo(clone_info);
4513 (void) DrawDashPolygon(draw_info,primitive_info,image);
4516 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
4518 (draw_info->stroke.opacity != (Quantum) TransparentOpacity))
4524 Draw strokes while respecting line cap/join attributes.
4526 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
4528 (primitive_info[i-1].point.x == primitive_info[0].point.x) &&
4529 (primitive_info[i-1].point.y == primitive_info[0].point.y) ?
4530 MagickTrue : MagickFalse;
4531 i=(ssize_t) primitive_info[0].coordinates;
4532 if ((((draw_info->linecap == RoundCap) ||
4533 (closed_path != MagickFalse)) &&
4534 (draw_info->linejoin == RoundJoin)) ||
4535 (primitive_info[i].primitive != UndefinedPrimitive))
4537 (void) DrawPolygonPrimitive(image,draw_info,primitive_info);
4540 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4541 clone_info->stroke_width=0.0;
4542 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4543 status=DrawPolygonPrimitive(image,clone_info,primitive_info);
4544 clone_info=DestroyDrawInfo(clone_info);
4545 status|=DrawStrokePolygon(image,draw_info,primitive_info);
4548 status=DrawPolygonPrimitive(image,draw_info,primitive_info);
4552 image_view=DestroyCacheView(image_view);
4553 if (image->debug != MagickFalse)
4554 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-primitive");
4555 return(status != 0 ? MagickTrue : MagickFalse);
4559 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4563 + D r a w S t r o k e P o l y g o n %
4567 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4569 % DrawStrokePolygon() draws a stroked polygon (line, rectangle, ellipse) on
4570 % the image while respecting the line cap and join attributes.
4572 % The format of the DrawStrokePolygon method is:
4574 % MagickBooleanType DrawStrokePolygon(Image *image,
4575 % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4577 % A description of each parameter follows:
4579 % o image: the image.
4581 % o draw_info: the draw info.
4583 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
4588 static void DrawRoundLinecap(Image *image,const DrawInfo *draw_info,
4589 const PrimitiveInfo *primitive_info)
4597 for (i=0; i < 4; i++)
4598 linecap[i]=(*primitive_info);
4599 linecap[0].coordinates=4;
4600 linecap[1].point.x+=(double) (10.0*MagickEpsilon);
4601 linecap[2].point.x+=(double) (10.0*MagickEpsilon);
4602 linecap[2].point.y+=(double) (10.0*MagickEpsilon);
4603 linecap[3].point.y+=(double) (10.0*MagickEpsilon);
4604 linecap[4].primitive=UndefinedPrimitive;
4605 (void) DrawPolygonPrimitive(image,draw_info,linecap);
4608 static MagickBooleanType DrawStrokePolygon(Image *image,
4609 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4621 register const PrimitiveInfo
4626 Draw stroked polygon.
4628 if (image->debug != MagickFalse)
4629 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4630 " begin draw-stroke-polygon");
4631 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4632 clone_info->fill=draw_info->stroke;
4633 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4634 clone_info->stroke_width=0.0;
4635 clone_info->fill_rule=NonZeroRule;
4637 for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=p->coordinates)
4639 stroke_polygon=TraceStrokePolygon(draw_info,p);
4640 status=DrawPolygonPrimitive(image,clone_info,stroke_polygon);
4641 stroke_polygon=(PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon);
4642 q=p+p->coordinates-1;
4643 closed_path=(q->point.x == p->point.x) && (q->point.y == p->point.y) ?
4644 MagickTrue : MagickFalse;
4645 if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse))
4647 DrawRoundLinecap(image,draw_info,p);
4648 DrawRoundLinecap(image,draw_info,q);
4651 clone_info=DestroyDrawInfo(clone_info);
4652 if (image->debug != MagickFalse)
4653 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4654 " end draw-stroke-polygon");
4659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4663 % G e t A f f i n e M a t r i x %
4667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4669 % GetAffineMatrix() returns an AffineMatrix initialized to the identity
4672 % The format of the GetAffineMatrix method is:
4674 % void GetAffineMatrix(AffineMatrix *affine_matrix)
4676 % A description of each parameter follows:
4678 % o affine_matrix: the affine matrix.
4681 MagickExport void GetAffineMatrix(AffineMatrix *affine_matrix)
4683 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4684 assert(affine_matrix != (AffineMatrix *) NULL);
4685 (void) ResetMagickMemory(affine_matrix,0,sizeof(*affine_matrix));
4686 affine_matrix->sx=1.0;
4687 affine_matrix->sy=1.0;
4691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4695 + G e t D r a w I n f o %
4699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4701 % GetDrawInfo() initializes draw_info to default values.
4703 % The format of the GetDrawInfo method is:
4705 % void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info)
4707 % A description of each parameter follows:
4709 % o image_info: the image info..
4711 % o draw_info: the draw info.
4714 MagickExport void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info)
4726 Initialize draw attributes.
4728 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4729 assert(draw_info != (DrawInfo *) NULL);
4730 (void) ResetMagickMemory(draw_info,0,sizeof(*draw_info));
4731 clone_info=CloneImageInfo(image_info);
4732 GetAffineMatrix(&draw_info->affine);
4733 exception=AcquireExceptionInfo();
4734 (void) QueryColorDatabase("#000F",&draw_info->fill,exception);
4735 (void) QueryColorDatabase("#FFF0",&draw_info->stroke,exception);
4736 draw_info->stroke_antialias=clone_info->antialias;
4737 draw_info->stroke_width=1.0;
4738 draw_info->opacity=OpaqueOpacity;
4739 draw_info->fill_rule=EvenOddRule;
4740 draw_info->linecap=ButtCap;
4741 draw_info->linejoin=MiterJoin;
4742 draw_info->miterlimit=10;
4743 draw_info->decorate=NoDecoration;
4744 if (clone_info->font != (char *) NULL)
4745 draw_info->font=AcquireString(clone_info->font);
4746 if (clone_info->density != (char *) NULL)
4747 draw_info->density=AcquireString(clone_info->density);
4748 draw_info->text_antialias=clone_info->antialias;
4749 draw_info->pointsize=12.0;
4750 if (clone_info->pointsize != 0.0)
4751 draw_info->pointsize=clone_info->pointsize;
4752 draw_info->undercolor.opacity=(Quantum) TransparentOpacity;
4753 draw_info->border_color=clone_info->border_color;
4754 draw_info->compose=OverCompositeOp;
4755 if (clone_info->server_name != (char *) NULL)
4756 draw_info->server_name=AcquireString(clone_info->server_name);
4757 draw_info->render=MagickTrue;
4758 draw_info->debug=IsEventLogging();
4759 option=GetImageOption(clone_info,"encoding");
4760 if (option != (const char *) NULL)
4761 (void) CloneString(&draw_info->encoding,option);
4762 option=GetImageOption(clone_info,"kerning");
4763 if (option != (const char *) NULL)
4764 draw_info->kerning=StringToDouble(option);
4765 option=GetImageOption(clone_info,"interline-spacing");
4766 if (option != (const char *) NULL)
4767 draw_info->interline_spacing=StringToDouble(option);
4768 draw_info->direction=UndefinedDirection;
4769 option=GetImageOption(clone_info,"interword-spacing");
4770 if (option != (const char *) NULL)
4771 draw_info->interword_spacing=StringToDouble(option);
4772 option=GetImageOption(clone_info,"direction");
4773 if (option != (const char *) NULL)
4774 draw_info->direction=(DirectionType) ParseMagickOption(
4775 MagickDirectionOptions,MagickFalse,option);
4776 option=GetImageOption(clone_info,"fill");
4777 if (option != (const char *) NULL)
4778 (void) QueryColorDatabase(option,&draw_info->fill,exception);
4779 option=GetImageOption(clone_info,"stroke");
4780 if (option != (const char *) NULL)
4781 (void) QueryColorDatabase(option,&draw_info->stroke,exception);
4782 option=GetImageOption(clone_info,"strokewidth");
4783 if (option != (const char *) NULL)
4784 draw_info->stroke_width=StringToDouble(option);
4785 option=GetImageOption(clone_info,"undercolor");
4786 if (option != (const char *) NULL)
4787 (void) QueryColorDatabase(option,&draw_info->undercolor,exception);
4788 option=GetImageOption(clone_info,"gravity");
4789 if (option != (const char *) NULL)
4790 draw_info->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
4791 MagickFalse,option);
4792 exception=DestroyExceptionInfo(exception);
4793 draw_info->signature=MagickSignature;
4794 clone_info=DestroyImageInfo(clone_info);
4798 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4802 + P e r m u t a t e %
4806 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4808 % Permutate() returns the permuation of the (n,k).
4810 % The format of the Permutate method is:
4812 % void Permutate(ssize_t n,ssize_t k)
4814 % A description of each parameter follows:
4822 static inline MagickRealType Permutate(const ssize_t n,const ssize_t k)
4831 for (i=k+1; i <= n; i++)
4833 for (i=1; i <= (n-k); i++)
4839 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4843 + T r a c e P r i m i t i v e %
4847 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4849 % TracePrimitive is a collection of methods for generating graphic
4850 % primitives such as arcs, ellipses, paths, etc.
4854 static void TraceArc(PrimitiveInfo *primitive_info,const PointInfo start,
4855 const PointInfo end,const PointInfo degrees)
4861 center.x=0.5*(end.x+start.x);
4862 center.y=0.5*(end.y+start.y);
4863 radii.x=fabs(center.x-start.x);
4864 radii.y=fabs(center.y-start.y);
4865 TraceEllipse(primitive_info,center,radii,degrees);
4868 static void TraceArcPath(PrimitiveInfo *primitive_info,const PointInfo start,
4869 const PointInfo end,const PointInfo arc,const MagickRealType angle,
4870 const MagickBooleanType large_arc,const MagickBooleanType sweep)
4885 register MagickRealType
4889 register PrimitiveInfo
4898 if ((start.x == end.x) && (start.y == end.y))
4900 TracePoint(primitive_info,end);
4903 radii.x=fabs(arc.x);
4904 radii.y=fabs(arc.y);
4905 if ((radii.x == 0.0) || (radii.y == 0.0))
4907 TraceLine(primitive_info,start,end);
4910 cosine=cos(DegreesToRadians(fmod((double) angle,360.0)));
4911 sine=sin(DegreesToRadians(fmod((double) angle,360.0)));
4912 center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2);
4913 center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2);
4914 delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/
4916 if (delta < MagickEpsilon)
4918 TraceLine(primitive_info,start,end);
4923 radii.x*=sqrt((double) delta);
4924 radii.y*=sqrt((double) delta);
4926 points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x);
4927 points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y);
4928 points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x);
4929 points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y);
4930 alpha=points[1].x-points[0].x;
4931 beta=points[1].y-points[0].y;
4932 factor=1.0/(alpha*alpha+beta*beta)-0.25;
4937 factor=sqrt((double) factor);
4938 if (sweep == large_arc)
4941 center.x=(double) ((points[0].x+points[1].x)/2-factor*beta);
4942 center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha);
4943 alpha=atan2(points[0].y-center.y,points[0].x-center.x);
4944 theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha;
4945 if ((theta < 0.0) && (sweep != MagickFalse))
4946 theta+=(MagickRealType) (2.0*MagickPI);
4948 if ((theta > 0.0) && (sweep == MagickFalse))
4949 theta-=(MagickRealType) (2.0*MagickPI);
4950 arc_segments=(size_t) ceil(fabs((double) (theta/(0.5*MagickPI+
4953 for (i=0; i < (ssize_t) arc_segments; i++)
4955 beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments));
4956 gamma=(8.0/3.0)*sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))*
4957 sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))/
4958 sin(fmod((double) beta,DegreesToRadians(360.0)));
4959 points[0].x=(double) (center.x+cos(fmod((double) (alpha+(double) i*theta/
4960 arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((double) (alpha+
4961 (double) i*theta/arc_segments),DegreesToRadians(360.0))));
4962 points[0].y=(double) (center.y+sin(fmod((double) (alpha+(double) i*theta/
4963 arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((double) (alpha+
4964 (double) i*theta/arc_segments),DegreesToRadians(360.0))));
4965 points[2].x=(double) (center.x+cos(fmod((double) (alpha+(double) (i+1)*
4966 theta/arc_segments),DegreesToRadians(360.0))));
4967 points[2].y=(double) (center.y+sin(fmod((double) (alpha+(double) (i+1)*
4968 theta/arc_segments),DegreesToRadians(360.0))));
4969 points[1].x=(double) (points[2].x+gamma*sin(fmod((double) (alpha+(double)
4970 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
4971 points[1].y=(double) (points[2].y-gamma*cos(fmod((double) (alpha+(double)
4972 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
4973 p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x;
4974 p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y;
4975 (p+1)->point.x=(double) (cosine*radii.x*points[0].x-sine*radii.y*
4977 (p+1)->point.y=(double) (sine*radii.x*points[0].x+cosine*radii.y*
4979 (p+2)->point.x=(double) (cosine*radii.x*points[1].x-sine*radii.y*
4981 (p+2)->point.y=(double) (sine*radii.x*points[1].x+cosine*radii.y*
4983 (p+3)->point.x=(double) (cosine*radii.x*points[2].x-sine*radii.y*
4985 (p+3)->point.y=(double) (sine*radii.x*points[2].x+cosine*radii.y*
4987 if (i == (ssize_t) (arc_segments-1))
4992 primitive_info->coordinates=(size_t) (p-primitive_info);
4993 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
4995 p->primitive=primitive_info->primitive;
5000 static void TraceBezier(PrimitiveInfo *primitive_info,
5001 const size_t number_coordinates)
5013 register PrimitiveInfo
5025 Allocate coeficients.
5027 quantum=number_coordinates;
5028 for (i=0; i < (ssize_t) number_coordinates; i++)
5030 for (j=i+1; j < (ssize_t) number_coordinates; j++)
5032 alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x);
5033 if (alpha > (MagickRealType) quantum)
5034 quantum=(size_t) alpha;
5035 alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y);
5036 if (alpha > (MagickRealType) quantum)
5037 quantum=(size_t) alpha;
5040 quantum=(size_t) MagickMin((double) quantum/number_coordinates,
5041 (double) BezierQuantum);
5042 control_points=quantum*number_coordinates;
5043 coefficients=(MagickRealType *) AcquireQuantumMemory((size_t)
5044 number_coordinates,sizeof(*coefficients));
5045 points=(PointInfo *) AcquireQuantumMemory((size_t) control_points,
5047 if ((coefficients == (MagickRealType *) NULL) ||
5048 (points == (PointInfo *) NULL))
5049 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
5051 Compute bezier points.
5053 end=primitive_info[number_coordinates-1].point;
5054 for (i=0; i < (ssize_t) number_coordinates; i++)
5055 coefficients[i]=Permutate((ssize_t) number_coordinates-1,i);
5057 for (i=0; i < (ssize_t) control_points; i++)
5062 alpha=pow((double) (1.0-weight),(double) number_coordinates-1.0);
5063 for (j=0; j < (ssize_t) number_coordinates; j++)
5065 point.x+=alpha*coefficients[j]*p->point.x;
5066 point.y+=alpha*coefficients[j]*p->point.y;
5067 alpha*=weight/(1.0-weight);
5071 weight+=1.0/control_points;
5074 Bezier curves are just short segmented polys.
5077 for (i=0; i < (ssize_t) control_points; i++)
5079 TracePoint(p,points[i]);
5084 primitive_info->coordinates=(size_t) (p-primitive_info);
5085 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5087 p->primitive=primitive_info->primitive;
5090 points=(PointInfo *) RelinquishMagickMemory(points);
5091 coefficients=(MagickRealType *) RelinquishMagickMemory(coefficients);
5094 static void TraceCircle(PrimitiveInfo *primitive_info,const PointInfo start,
5095 const PointInfo end)
5106 alpha=end.x-start.x;
5108 radius=hypot((double) alpha,(double) beta);
5109 offset.x=(double) radius;
5110 offset.y=(double) radius;
5113 TraceEllipse(primitive_info,start,offset,degrees);
5116 static void TraceEllipse(PrimitiveInfo *primitive_info,const PointInfo start,
5117 const PointInfo stop,const PointInfo degrees)
5128 register PrimitiveInfo
5135 Ellipses are just short segmented polys.
5137 if ((stop.x == 0.0) && (stop.y == 0.0))
5139 TracePoint(primitive_info,start);
5142 delta=2.0/MagickMax(stop.x,stop.y);
5143 step=(MagickRealType) (MagickPI/8.0);
5144 if ((delta >= 0.0) && (delta < (MagickRealType) (MagickPI/8.0)))
5145 step=(MagickRealType) (MagickPI/(4*(MagickPI/delta/2+0.5)));
5146 angle.x=DegreesToRadians(degrees.x);
5148 while (y < degrees.x)
5150 angle.y=(double) (DegreesToRadians(y)-MagickEpsilon);
5151 for (p=primitive_info; angle.x < angle.y; angle.x+=step)
5153 point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*stop.x+start.x;
5154 point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*stop.y+start.y;
5155 TracePoint(p,point);
5158 point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*stop.x+start.x;
5159 point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*stop.y+start.y;
5160 TracePoint(p,point);
5162 primitive_info->coordinates=(size_t) (p-primitive_info);
5163 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5165 p->primitive=primitive_info->primitive;
5170 static void TraceLine(PrimitiveInfo *primitive_info,const PointInfo start,
5171 const PointInfo end)
5173 TracePoint(primitive_info,start);
5174 if ((fabs(start.x-end.x) <= MagickEpsilon) &&
5175 (fabs(start.y-end.y) <= MagickEpsilon))
5177 primitive_info->primitive=PointPrimitive;
5178 primitive_info->coordinates=1;
5181 TracePoint(primitive_info+1,end);
5182 (primitive_info+1)->primitive=primitive_info->primitive;
5183 primitive_info->coordinates=2;
5186 static size_t TracePath(PrimitiveInfo *primitive_info,const char *path)
5189 token[MaxTextExtent];
5211 register PrimitiveInfo
5226 number_coordinates=0;
5228 primitive_type=primitive_info->primitive;
5230 for (p=path; *p != '\0'; )
5232 while (isspace((int) ((unsigned char) *p)) != 0)
5236 last_attribute=attribute;
5237 attribute=(int) (*p++);
5258 GetMagickToken(p,&p,token);
5260 GetMagickToken(p,&p,token);
5261 arc.x=StringToDouble(token);
5262 GetMagickToken(p,&p,token);
5264 GetMagickToken(p,&p,token);
5265 arc.y=StringToDouble(token);
5266 GetMagickToken(p,&p,token);
5268 GetMagickToken(p,&p,token);
5269 angle=StringToDouble(token);
5270 GetMagickToken(p,&p,token);
5272 GetMagickToken(p,&p,token);
5273 large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
5274 GetMagickToken(p,&p,token);
5276 GetMagickToken(p,&p,token);
5277 sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
5278 GetMagickToken(p,&p,token);
5280 GetMagickToken(p,&p,token);
5281 x=StringToDouble(token);
5282 GetMagickToken(p,&p,token);
5284 GetMagickToken(p,&p,token);
5285 y=StringToDouble(token);
5286 end.x=(double) (attribute == (int) 'A' ? x : point.x+x);
5287 end.y=(double) (attribute == (int) 'A' ? y : point.y+y);
5288 TraceArcPath(q,point,end,arc,angle,large_arc,sweep);
5291 } while (IsPoint(p) != MagickFalse);
5298 Compute bezier points.
5303 for (i=1; i < 4; i++)
5305 GetMagickToken(p,&p,token);
5307 GetMagickToken(p,&p,token);
5308 x=StringToDouble(token);
5309 GetMagickToken(p,&p,token);
5311 GetMagickToken(p,&p,token);
5312 y=StringToDouble(token);
5313 end.x=(double) (attribute == (int) 'C' ? x : point.x+x);
5314 end.y=(double) (attribute == (int) 'C' ? y : point.y+y);
5317 for (i=0; i < 4; i++)
5318 (q+i)->point=points[i];
5322 } while (IsPoint(p) != MagickFalse);
5330 GetMagickToken(p,&p,token);
5332 GetMagickToken(p,&p,token);
5333 x=StringToDouble(token);
5334 point.x=(double) (attribute == (int) 'H' ? x: point.x+x);
5335 TracePoint(q,point);
5337 } while (IsPoint(p) != MagickFalse);
5345 GetMagickToken(p,&p,token);
5347 GetMagickToken(p,&p,token);
5348 x=StringToDouble(token);
5349 GetMagickToken(p,&p,token);
5351 GetMagickToken(p,&p,token);
5352 y=StringToDouble(token);
5353 point.x=(double) (attribute == (int) 'L' ? x : point.x+x);
5354 point.y=(double) (attribute == (int) 'L' ? y : point.y+y);
5355 TracePoint(q,point);
5357 } while (IsPoint(p) != MagickFalse);
5363 if (q != primitive_info)
5365 primitive_info->coordinates=(size_t) (q-primitive_info);
5366 number_coordinates+=primitive_info->coordinates;
5372 GetMagickToken(p,&p,token);
5374 GetMagickToken(p,&p,token);
5375 x=StringToDouble(token);
5376 GetMagickToken(p,&p,token);
5378 GetMagickToken(p,&p,token);
5379 y=StringToDouble(token);
5380 point.x=(double) (attribute == (int) 'M' ? x : point.x+x);
5381 point.y=(double) (attribute == (int) 'M' ? y : point.y+y);
5385 TracePoint(q,point);
5387 if ((i != 0) && (attribute == (int) 'M'))
5389 TracePoint(q,point);
5392 } while (IsPoint(p) != MagickFalse);
5399 Compute bezier points.
5404 for (i=1; i < 3; i++)
5406 GetMagickToken(p,&p,token);
5408 GetMagickToken(p,&p,token);
5409 x=StringToDouble(token);
5410 GetMagickToken(p,&p,token);
5412 GetMagickToken(p,&p,token);
5413 y=StringToDouble(token);
5416 end.x=(double) (attribute == (int) 'Q' ? x : point.x+x);
5417 end.y=(double) (attribute == (int) 'Q' ? y : point.y+y);
5420 for (i=0; i < 3; i++)
5421 (q+i)->point=points[i];
5425 } while (IsPoint(p) != MagickFalse);
5432 Compute bezier points.
5436 points[0]=points[3];
5437 points[1].x=2.0*points[3].x-points[2].x;
5438 points[1].y=2.0*points[3].y-points[2].y;
5439 for (i=2; i < 4; i++)
5441 GetMagickToken(p,&p,token);
5443 GetMagickToken(p,&p,token);
5444 x=StringToDouble(token);
5445 GetMagickToken(p,&p,token);
5447 GetMagickToken(p,&p,token);
5448 y=StringToDouble(token);
5451 end.x=(double) (attribute == (int) 'S' ? x : point.x+x);
5452 end.y=(double) (attribute == (int) 'S' ? y : point.y+y);
5455 if (strchr("CcSs",last_attribute) == (char *) NULL)
5457 points[0]=points[2];
5458 points[1]=points[3];
5460 for (i=0; i < 4; i++)
5461 (q+i)->point=points[i];
5465 } while (IsPoint(p) != MagickFalse);
5472 Compute bezier points.
5476 points[0]=points[2];
5477 points[1].x=2.0*points[2].x-points[1].x;
5478 points[1].y=2.0*points[2].y-points[1].y;
5479 for (i=2; i < 3; i++)
5481 GetMagickToken(p,&p,token);
5483 GetMagickToken(p,&p,token);
5484 x=StringToDouble(token);
5485 GetMagickToken(p,&p,token);
5487 GetMagickToken(p,&p,token);
5488 y=StringToDouble(token);
5489 end.x=(double) (attribute == (int) 'T' ? x : point.x+x);
5490 end.y=(double) (attribute == (int) 'T' ? y : point.y+y);
5493 if (strchr("QqTt",last_attribute) == (char *) NULL)
5495 points[0]=points[2];
5496 points[1]=points[3];
5498 for (i=0; i < 3; i++)
5499 (q+i)->point=points[i];
5503 } while (IsPoint(p) != MagickFalse);
5511 GetMagickToken(p,&p,token);
5513 GetMagickToken(p,&p,token);
5514 y=StringToDouble(token);
5515 point.y=(double) (attribute == (int) 'V' ? y : point.y+y);
5516 TracePoint(q,point);
5518 } while (IsPoint(p) != MagickFalse);
5525 TracePoint(q,point);
5527 primitive_info->coordinates=(size_t) (q-primitive_info);
5528 number_coordinates+=primitive_info->coordinates;
5535 if (isalpha((int) ((unsigned char) attribute)) != 0)
5536 (void) fprintf(stderr,"attribute not recognized: %c\n",attribute);
5541 primitive_info->coordinates=(size_t) (q-primitive_info);
5542 number_coordinates+=primitive_info->coordinates;
5543 for (i=0; i < (ssize_t) number_coordinates; i++)
5546 q->primitive=primitive_type;
5548 q->method=FillToBorderMethod;
5551 return(number_coordinates);
5554 static void TraceRectangle(PrimitiveInfo *primitive_info,const PointInfo start,
5555 const PointInfo end)
5560 register PrimitiveInfo
5567 TracePoint(p,start);
5571 TracePoint(p,point);
5577 TracePoint(p,point);
5579 TracePoint(p,start);
5581 primitive_info->coordinates=(size_t) (p-primitive_info);
5582 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5584 p->primitive=primitive_info->primitive;
5589 static void TraceRoundRectangle(PrimitiveInfo *primitive_info,
5590 const PointInfo start,const PointInfo end,PointInfo arc)
5597 register PrimitiveInfo
5604 offset.x=fabs(end.x-start.x);
5605 offset.y=fabs(end.y-start.y);
5606 if (arc.x > (0.5*offset.x))
5608 if (arc.y > (0.5*offset.y))
5610 point.x=start.x+offset.x-arc.x;
5611 point.y=start.y+arc.y;
5614 TraceEllipse(p,point,arc,degrees);
5616 point.x=start.x+offset.x-arc.x;
5617 point.y=start.y+offset.y-arc.y;
5620 TraceEllipse(p,point,arc,degrees);
5622 point.x=start.x+arc.x;
5623 point.y=start.y+offset.y-arc.y;
5626 TraceEllipse(p,point,arc,degrees);
5628 point.x=start.x+arc.x;
5629 point.y=start.y+arc.y;
5632 TraceEllipse(p,point,arc,degrees);
5634 TracePoint(p,primitive_info->point);
5636 primitive_info->coordinates=(size_t) (p-primitive_info);
5637 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5639 p->primitive=primitive_info->primitive;
5644 static void TraceSquareLinecap(PrimitiveInfo *primitive_info,
5645 const size_t number_vertices,const MagickRealType offset)
5650 register MagickRealType
5662 for (i=1; i < (ssize_t) number_vertices; i++)
5664 dx=primitive_info[0].point.x-primitive_info[i].point.x;
5665 dy=primitive_info[0].point.y-primitive_info[i].point.y;
5666 if ((fabs((double) dx) >= MagickEpsilon) ||
5667 (fabs((double) dy) >= MagickEpsilon))
5670 if (i == (ssize_t) number_vertices)
5671 i=(ssize_t) number_vertices-1L;
5672 distance=hypot((double) dx,(double) dy);
5673 primitive_info[0].point.x=(double) (primitive_info[i].point.x+
5674 dx*(distance+offset)/distance);
5675 primitive_info[0].point.y=(double) (primitive_info[i].point.y+
5676 dy*(distance+offset)/distance);
5677 for (j=(ssize_t) number_vertices-2; j >= 0; j--)
5679 dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x;
5680 dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y;
5681 if ((fabs((double) dx) >= MagickEpsilon) ||
5682 (fabs((double) dy) >= MagickEpsilon))
5685 distance=hypot((double) dx,(double) dy);
5686 primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+
5687 dx*(distance+offset)/distance);
5688 primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+
5689 dy*(distance+offset)/distance);
5692 static PrimitiveInfo *TraceStrokePolygon(const DrawInfo *draw_info,
5693 const PrimitiveInfo *primitive_info)
5695 typedef struct _LineSegment
5747 number_vertices=primitive_info->coordinates;
5748 max_strokes=2*number_vertices+6*BezierQuantum+360;
5749 path_p=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes,
5751 path_q=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes,
5753 polygon_primitive=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
5754 number_vertices+2UL,sizeof(*polygon_primitive));
5755 if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL) ||
5756 (polygon_primitive == (PrimitiveInfo *) NULL))
5757 return((PrimitiveInfo *) NULL);
5758 (void) CopyMagickMemory(polygon_primitive,primitive_info,(size_t)
5759 number_vertices*sizeof(*polygon_primitive));
5761 (primitive_info[number_vertices-1].point.x == primitive_info[0].point.x) &&
5762 (primitive_info[number_vertices-1].point.y == primitive_info[0].point.y) ?
5763 MagickTrue : MagickFalse;
5764 if ((draw_info->linejoin == RoundJoin) ||
5765 ((draw_info->linejoin == MiterJoin) && (closed_path != MagickFalse)))
5767 polygon_primitive[number_vertices]=primitive_info[1];
5770 polygon_primitive[number_vertices].primitive=UndefinedPrimitive;
5772 Compute the slope for the first line segment, p.
5776 for (n=1; n < (ssize_t) number_vertices; n++)
5778 dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x;
5779 dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y;
5780 if ((fabs(dx.p) >= MagickEpsilon) || (fabs(dy.p) >= MagickEpsilon))
5783 if (n == (ssize_t) number_vertices)
5784 n=(ssize_t) number_vertices-1L;
5786 inverse_slope.p=0.0;
5787 if (fabs(dx.p) <= MagickEpsilon)
5790 slope.p=dy.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5792 slope.p=dy.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5795 if (fabs(dy.p) <= MagickEpsilon)
5798 inverse_slope.p=dx.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5800 inverse_slope.p=dx.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5805 inverse_slope.p=(-1.0/slope.p);
5807 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5808 miterlimit=(MagickRealType) (draw_info->miterlimit*draw_info->miterlimit*
5810 if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse))
5811 TraceSquareLinecap(polygon_primitive,number_vertices,mid);
5812 offset.x=sqrt((double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0)));
5813 offset.y=(double) (offset.x*inverse_slope.p);
5814 if ((dy.p*offset.x-dx.p*offset.y) > 0.0)
5816 box_p[0].x=polygon_primitive[0].point.x-offset.x;
5817 box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p;
5818 box_p[1].x=polygon_primitive[n].point.x-offset.x;
5819 box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p;
5820 box_q[0].x=polygon_primitive[0].point.x+offset.x;
5821 box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p;
5822 box_q[1].x=polygon_primitive[n].point.x+offset.x;
5823 box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p;
5827 box_p[0].x=polygon_primitive[0].point.x+offset.x;
5828 box_p[0].y=polygon_primitive[0].point.y+offset.y;
5829 box_p[1].x=polygon_primitive[n].point.x+offset.x;
5830 box_p[1].y=polygon_primitive[n].point.y+offset.y;
5831 box_q[0].x=polygon_primitive[0].point.x-offset.x;
5832 box_q[0].y=polygon_primitive[0].point.y-offset.y;
5833 box_q[1].x=polygon_primitive[n].point.x-offset.x;
5834 box_q[1].y=polygon_primitive[n].point.y-offset.y;
5837 Create strokes for the line join attribute: bevel, miter, round.
5841 path_q[p++]=box_q[0];
5842 path_p[q++]=box_p[0];
5843 for (i=(ssize_t) n+1; i < (ssize_t) number_vertices; i++)
5846 Compute the slope for this line segment, q.
5848 dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x;
5849 dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y;
5850 dot_product=dx.q*dx.q+dy.q*dy.q;
5851 if (dot_product < 0.25)
5854 inverse_slope.q=0.0;
5855 if (fabs(dx.q) < MagickEpsilon)
5858 slope.q=dy.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5860 slope.q=dy.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5863 if (fabs(dy.q) <= MagickEpsilon)
5866 inverse_slope.q=dx.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5868 inverse_slope.q=dx.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5873 inverse_slope.q=(-1.0/slope.q);
5875 offset.x=sqrt((double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0)));
5876 offset.y=(double) (offset.x*inverse_slope.q);
5877 dot_product=dy.q*offset.x-dx.q*offset.y;
5878 if (dot_product > 0.0)
5880 box_p[2].x=polygon_primitive[n].point.x-offset.x;
5881 box_p[2].y=polygon_primitive[n].point.y-offset.y;
5882 box_p[3].x=polygon_primitive[i].point.x-offset.x;
5883 box_p[3].y=polygon_primitive[i].point.y-offset.y;
5884 box_q[2].x=polygon_primitive[n].point.x+offset.x;
5885 box_q[2].y=polygon_primitive[n].point.y+offset.y;
5886 box_q[3].x=polygon_primitive[i].point.x+offset.x;
5887 box_q[3].y=polygon_primitive[i].point.y+offset.y;
5891 box_p[2].x=polygon_primitive[n].point.x+offset.x;
5892 box_p[2].y=polygon_primitive[n].point.y+offset.y;
5893 box_p[3].x=polygon_primitive[i].point.x+offset.x;
5894 box_p[3].y=polygon_primitive[i].point.y+offset.y;
5895 box_q[2].x=polygon_primitive[n].point.x-offset.x;
5896 box_q[2].y=polygon_primitive[n].point.y-offset.y;
5897 box_q[3].x=polygon_primitive[i].point.x-offset.x;
5898 box_q[3].y=polygon_primitive[i].point.y-offset.y;
5900 if (fabs((double) (slope.p-slope.q)) <= MagickEpsilon)
5907 box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+
5908 box_p[3].y)/(slope.p-slope.q));
5909 box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y);
5910 box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+
5911 box_q[3].y)/(slope.p-slope.q));
5912 box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y);
5914 if (q >= (ssize_t) (max_strokes-6*BezierQuantum-360))
5916 max_strokes+=6*BezierQuantum+360;
5917 path_p=(PointInfo *) ResizeQuantumMemory(path_p,(size_t) max_strokes,
5919 path_q=(PointInfo *) ResizeQuantumMemory(path_q,(size_t) max_strokes,
5921 if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL))
5923 polygon_primitive=(PrimitiveInfo *)
5924 RelinquishMagickMemory(polygon_primitive);
5925 return((PrimitiveInfo *) NULL);
5928 dot_product=dx.q*dy.p-dx.p*dy.q;
5929 if (dot_product <= 0.0)
5930 switch (draw_info->linejoin)
5934 path_q[q++]=box_q[1];
5935 path_q[q++]=box_q[2];
5936 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5937 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5938 if (dot_product <= miterlimit)
5939 path_p[p++]=box_p[4];
5942 path_p[p++]=box_p[1];
5943 path_p[p++]=box_p[2];
5949 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5950 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5951 if (dot_product <= miterlimit)
5953 path_q[q++]=box_q[4];
5954 path_p[p++]=box_p[4];
5958 path_q[q++]=box_q[1];
5959 path_q[q++]=box_q[2];
5960 path_p[p++]=box_p[1];
5961 path_p[p++]=box_p[2];
5967 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5968 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5969 if (dot_product <= miterlimit)
5970 path_p[p++]=box_p[4];
5973 path_p[p++]=box_p[1];
5974 path_p[p++]=box_p[2];
5976 center=polygon_primitive[n].point;
5977 theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x);
5978 theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x);
5979 if (theta.q < theta.p)
5980 theta.q+=(MagickRealType) (2.0*MagickPI);
5981 arc_segments=(size_t) ceil((double) ((theta.q-theta.p)/
5982 (2.0*sqrt((double) (1.0/mid)))));
5983 path_q[q].x=box_q[1].x;
5984 path_q[q].y=box_q[1].y;
5986 for (j=1; j < (ssize_t) arc_segments; j++)
5988 delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments);
5989 path_q[q].x=(double) (center.x+mid*cos(fmod((double)
5990 (theta.p+delta_theta),DegreesToRadians(360.0))));
5991 path_q[q].y=(double) (center.y+mid*sin(fmod((double)
5992 (theta.p+delta_theta),DegreesToRadians(360.0))));
5995 path_q[q++]=box_q[2];
6002 switch (draw_info->linejoin)
6006 path_p[p++]=box_p[1];
6007 path_p[p++]=box_p[2];
6008 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6009 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6010 if (dot_product <= miterlimit)
6011 path_q[q++]=box_q[4];
6014 path_q[q++]=box_q[1];
6015 path_q[q++]=box_q[2];
6021 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6022 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6023 if (dot_product <= miterlimit)
6025 path_q[q++]=box_q[4];
6026 path_p[p++]=box_p[4];
6030 path_q[q++]=box_q[1];
6031 path_q[q++]=box_q[2];
6032 path_p[p++]=box_p[1];
6033 path_p[p++]=box_p[2];
6039 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6040 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6041 if (dot_product <= miterlimit)
6042 path_q[q++]=box_q[4];
6045 path_q[q++]=box_q[1];
6046 path_q[q++]=box_q[2];
6048 center=polygon_primitive[n].point;
6049 theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x);
6050 theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x);
6051 if (theta.p < theta.q)
6052 theta.p+=(MagickRealType) (2.0*MagickPI);
6053 arc_segments=(size_t) ceil((double) ((theta.p-theta.q)/
6054 (2.0*sqrt((double) (1.0/mid)))));
6055 path_p[p++]=box_p[1];
6056 for (j=1; j < (ssize_t) arc_segments; j++)
6058 delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments);
6059 path_p[p].x=(double) (center.x+mid*cos(fmod((double)
6060 (theta.p+delta_theta),DegreesToRadians(360.0))));
6061 path_p[p].y=(double) (center.y+mid*sin(fmod((double)
6062 (theta.p+delta_theta),DegreesToRadians(360.0))));
6065 path_p[p++]=box_p[2];
6072 inverse_slope.p=inverse_slope.q;
6081 path_p[p++]=box_p[1];
6082 path_q[q++]=box_q[1];
6084 Trace stroked polygon.
6086 stroke_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
6087 (p+q+2UL*closed_path+2UL),sizeof(*stroke_polygon));
6088 if (stroke_polygon != (PrimitiveInfo *) NULL)
6090 for (i=0; i < (ssize_t) p; i++)
6092 stroke_polygon[i]=polygon_primitive[0];
6093 stroke_polygon[i].point=path_p[i];
6095 if (closed_path != MagickFalse)
6097 stroke_polygon[i]=polygon_primitive[0];
6098 stroke_polygon[i].point=stroke_polygon[0].point;
6101 for ( ; i < (ssize_t) (p+q+closed_path); i++)
6103 stroke_polygon[i]=polygon_primitive[0];
6104 stroke_polygon[i].point=path_q[p+q+closed_path-(i+1)];
6106 if (closed_path != MagickFalse)
6108 stroke_polygon[i]=polygon_primitive[0];
6109 stroke_polygon[i].point=stroke_polygon[p+closed_path].point;
6112 stroke_polygon[i]=polygon_primitive[0];
6113 stroke_polygon[i].point=stroke_polygon[0].point;
6115 stroke_polygon[i].primitive=UndefinedPrimitive;
6116 stroke_polygon[0].coordinates=(size_t) (p+q+2*closed_path+1);
6118 path_p=(PointInfo *) RelinquishMagickMemory(path_p);
6119 path_q=(PointInfo *) RelinquishMagickMemory(path_q);
6120 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive);
6121 return(stroke_polygon);