2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 % D D RRRR AAAAA W W W %
13 % MagickCore Image Drawing Methods %
21 % Copyright 1999-2010 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 *) AcquireAlignedMemory(1,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 *) AcquireAlignedMemory(1,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 *) AcquireAlignedMemory(1,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)
1113 **restrict resample_filter;
1122 Determine bounding box.
1124 assert(image != (Image *) NULL);
1125 assert(image->signature == MagickSignature);
1126 if (image->debug != MagickFalse)
1127 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1128 assert(source != (const Image *) NULL);
1129 assert(source->signature == MagickSignature);
1130 assert(affine != (AffineMatrix *) NULL);
1133 extent[1].x=(double) source->columns-1.0;
1135 extent[2].x=(double) source->columns-1.0;
1136 extent[2].y=(double) source->rows-1.0;
1138 extent[3].y=(double) source->rows-1.0;
1139 for (i=0; i < 4; i++)
1142 extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx;
1143 extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty;
1147 for (i=1; i < 4; i++)
1149 if (min.x > extent[i].x)
1151 if (min.y > extent[i].y)
1153 if (max.x < extent[i].x)
1155 if (max.y < extent[i].y)
1159 Affine transform image.
1161 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
1162 return(MagickFalse);
1164 edge.x1=MagickMax(min.x,0.0);
1165 edge.y1=MagickMax(min.y,0.0);
1166 edge.x2=MagickMin(max.x,(double) image->columns-1.0);
1167 edge.y2=MagickMin(max.y,(double) image->rows-1.0);
1168 inverse_affine=InverseAffineMatrix(affine);
1169 GetMagickPixelPacket(image,&zero);
1170 exception=(&image->exception);
1171 resample_filter=AcquireResampleFilterThreadSet(source,
1172 UndefinedVirtualPixelMethod,MagickTrue,exception);
1173 image_view=AcquireCacheView(image);
1174 source_view=AcquireCacheView(source);
1175 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1176 #pragma omp parallel for schedule(dynamic,4) shared(status)
1178 for (y=(ssize_t) ceil(edge.y1-0.5); y <= (ssize_t) floor(edge.y2+0.5); y++)
1190 register IndexPacket
1196 register PixelPacket
1205 inverse_edge=AffineEdge(source,&inverse_affine,(double) y,&edge);
1206 if (inverse_edge.x2 < inverse_edge.x1)
1208 q=GetCacheViewAuthenticPixels(image_view,(ssize_t) ceil(inverse_edge.x1-
1209 0.5),y,(size_t) ((ssize_t) floor(inverse_edge.x2+0.5)-(ssize_t) floor(
1210 inverse_edge.x1+0.5)+1),1,exception);
1211 if (q == (PixelPacket *) NULL)
1213 id=GetOpenMPThreadId();
1214 indexes=GetCacheViewAuthenticIndexQueue(image_view);
1218 for (x=(ssize_t) ceil(inverse_edge.x1-0.5); x <= (ssize_t) floor(inverse_edge.x2+0.5); x++)
1220 point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+
1222 point.y=(double) x*inverse_affine.rx+y*inverse_affine.sy+
1224 (void) ResamplePixelColor(resample_filter[id],point.x,point.y,&pixel);
1225 SetMagickPixelPacket(image,q,indexes+x_offset,&composite);
1226 MagickPixelCompositeOver(&pixel,pixel.opacity,&composite,
1227 composite.opacity,&composite);
1228 SetPixelPacket(image,&composite,q,indexes+x_offset);
1232 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1235 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
1236 source_view=DestroyCacheView(source_view);
1237 image_view=DestroyCacheView(image_view);
1242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1246 + D r a w B o u n d i n g R e c t a n g l e s %
1250 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1252 % DrawBoundingRectangles() draws the bounding rectangles on the image. This
1253 % is only useful for developers debugging the rendering algorithm.
1255 % The format of the DrawBoundingRectangles method is:
1257 % void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info,
1258 % PolygonInfo *polygon_info)
1260 % A description of each parameter follows:
1262 % o image: the image.
1264 % o draw_info: the draw info.
1266 % o polygon_info: Specifies a pointer to a PolygonInfo structure.
1269 static void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info,
1270 const PolygonInfo *polygon_info)
1295 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1296 (void) QueryColorDatabase("#0000",&clone_info->fill,&image->exception);
1297 resolution.x=DefaultResolution;
1298 resolution.y=DefaultResolution;
1299 if (clone_info->density != (char *) NULL)
1307 flags=ParseGeometry(clone_info->density,&geometry_info);
1308 resolution.x=geometry_info.rho;
1309 resolution.y=geometry_info.sigma;
1310 if ((flags & SigmaValue) == MagickFalse)
1311 resolution.y=resolution.x;
1313 mid=(resolution.x/72.0)*ExpandAffine(&clone_info->affine)*
1314 clone_info->stroke_width/2.0;
1319 if (polygon_info != (PolygonInfo *) NULL)
1321 bounds=polygon_info->edges[0].bounds;
1322 for (i=1; i < (ssize_t) polygon_info->number_edges; i++)
1324 if (polygon_info->edges[i].bounds.x1 < (double) bounds.x1)
1325 bounds.x1=polygon_info->edges[i].bounds.x1;
1326 if (polygon_info->edges[i].bounds.y1 < (double) bounds.y1)
1327 bounds.y1=polygon_info->edges[i].bounds.y1;
1328 if (polygon_info->edges[i].bounds.x2 > (double) bounds.x2)
1329 bounds.x2=polygon_info->edges[i].bounds.x2;
1330 if (polygon_info->edges[i].bounds.y2 > (double) bounds.y2)
1331 bounds.y2=polygon_info->edges[i].bounds.y2;
1334 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double)
1335 image->columns ? (double) image->columns-1 : bounds.x1;
1337 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double)
1338 image->rows ? (double) image->rows-1 : bounds.y1;
1340 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double)
1341 image->columns ? (double) image->columns-1 : bounds.x2;
1343 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double)
1344 image->rows ? (double) image->rows-1 : bounds.y2;
1345 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
1347 if (polygon_info->edges[i].direction != 0)
1348 (void) QueryColorDatabase("red",&clone_info->stroke,
1351 (void) QueryColorDatabase("green",&clone_info->stroke,
1353 start.x=(double) (polygon_info->edges[i].bounds.x1-mid);
1354 start.y=(double) (polygon_info->edges[i].bounds.y1-mid);
1355 end.x=(double) (polygon_info->edges[i].bounds.x2+mid);
1356 end.y=(double) (polygon_info->edges[i].bounds.y2+mid);
1357 primitive_info[0].primitive=RectanglePrimitive;
1358 TraceRectangle(primitive_info,start,end);
1359 primitive_info[0].method=ReplaceMethod;
1360 coordinates=(ssize_t) primitive_info[0].coordinates;
1361 primitive_info[coordinates].primitive=UndefinedPrimitive;
1362 (void) DrawPrimitive(image,clone_info,primitive_info);
1365 (void) QueryColorDatabase("blue",&clone_info->stroke,&image->exception);
1366 start.x=(double) (bounds.x1-mid);
1367 start.y=(double) (bounds.y1-mid);
1368 end.x=(double) (bounds.x2+mid);
1369 end.y=(double) (bounds.y2+mid);
1370 primitive_info[0].primitive=RectanglePrimitive;
1371 TraceRectangle(primitive_info,start,end);
1372 primitive_info[0].method=ReplaceMethod;
1373 coordinates=(ssize_t) primitive_info[0].coordinates;
1374 primitive_info[coordinates].primitive=UndefinedPrimitive;
1375 (void) DrawPrimitive(image,clone_info,primitive_info);
1376 clone_info=DestroyDrawInfo(clone_info);
1380 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1384 % D r a w C l i p P a t h %
1388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1390 % DrawClipPath() draws the clip path on the image mask.
1392 % The format of the DrawClipPath method is:
1394 % MagickBooleanType DrawClipPath(Image *image,const DrawInfo *draw_info,
1397 % A description of each parameter follows:
1399 % o image: the image.
1401 % o draw_info: the draw info.
1403 % o name: the name of the clip path.
1406 MagickExport MagickBooleanType DrawClipPath(Image *image,
1407 const DrawInfo *draw_info,const char *name)
1410 clip_mask[MaxTextExtent];
1421 assert(image != (Image *) NULL);
1422 assert(image->signature == MagickSignature);
1423 if (image->debug != MagickFalse)
1424 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1425 assert(draw_info != (const DrawInfo *) NULL);
1426 (void) FormatMagickString(clip_mask,MaxTextExtent,"%s",name);
1427 value=GetImageArtifact(image,clip_mask);
1428 if (value == (const char *) NULL)
1429 return(MagickFalse);
1430 if (image->clip_mask == (Image *) NULL)
1435 clip_mask=CloneImage(image,image->columns,image->rows,MagickTrue,
1437 if (clip_mask == (Image *) NULL)
1438 return(MagickFalse);
1439 (void) SetImageClipMask(image,clip_mask);
1440 clip_mask=DestroyImage(clip_mask);
1442 (void) QueryColorDatabase("#00000000",&image->clip_mask->background_color,
1444 image->clip_mask->background_color.opacity=(Quantum) TransparentOpacity;
1445 (void) SetImageBackgroundColor(image->clip_mask);
1446 if (image->debug != MagickFalse)
1447 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"\nbegin clip-path %s",
1448 draw_info->clip_mask);
1449 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1450 (void) CloneString(&clone_info->primitive,value);
1451 (void) QueryColorDatabase("#ffffff",&clone_info->fill,&image->exception);
1452 clone_info->clip_mask=(char *) NULL;
1453 status=DrawImage(image->clip_mask,clone_info);
1454 status|=NegateImage(image->clip_mask,MagickFalse);
1455 clone_info=DestroyDrawInfo(clone_info);
1456 if (image->debug != MagickFalse)
1457 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end clip-path");
1458 return(status != 0 ? MagickTrue : MagickFalse);
1462 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1466 + D r a w D a s h P o l y g o n %
1470 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1472 % DrawDashPolygon() draws a dashed polygon (line, rectangle, ellipse) on the
1473 % image while respecting the dash offset and dash pattern attributes.
1475 % The format of the DrawDashPolygon method is:
1477 % MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info,
1478 % const PrimitiveInfo *primitive_info,Image *image)
1480 % A description of each parameter follows:
1482 % o draw_info: the draw info.
1484 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
1486 % o image: the image.
1490 static MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info,
1491 const PrimitiveInfo *primitive_info,Image *image)
1512 register MagickRealType
1523 assert(draw_info != (const DrawInfo *) NULL);
1524 if (image->debug != MagickFalse)
1525 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-dash");
1526 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1527 clone_info->miterlimit=0;
1528 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
1529 number_vertices=(size_t) i;
1530 dash_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
1531 (2UL*number_vertices+1UL),sizeof(*dash_polygon));
1532 if (dash_polygon == (PrimitiveInfo *) NULL)
1533 return(MagickFalse);
1534 dash_polygon[0]=primitive_info[0];
1535 scale=ExpandAffine(&draw_info->affine);
1536 length=scale*(draw_info->dash_pattern[0]-0.5);
1537 offset=draw_info->dash_offset != 0.0 ? scale*draw_info->dash_offset : 0.0;
1539 for (n=0; offset > 0.0; j=0)
1541 if (draw_info->dash_pattern[n] <= 0.0)
1543 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1544 if (offset > length)
1548 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1551 if (offset < length)
1563 for (i=1; i < (ssize_t) number_vertices; i++)
1565 dx=primitive_info[i].point.x-primitive_info[i-1].point.x;
1566 dy=primitive_info[i].point.y-primitive_info[i-1].point.y;
1567 maximum_length=hypot((double) dx,dy);
1571 if (draw_info->dash_pattern[n] == 0.0)
1573 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1575 for (total_length=0.0; (total_length+length) < maximum_length; )
1577 total_length+=length;
1578 if ((n & 0x01) != 0)
1580 dash_polygon[0]=primitive_info[0];
1581 dash_polygon[0].point.x=(double) (primitive_info[i-1].point.x+dx*
1582 total_length/maximum_length);
1583 dash_polygon[0].point.y=(double) (primitive_info[i-1].point.y+dy*
1584 total_length/maximum_length);
1589 if ((j+1) > (ssize_t) (2*number_vertices))
1591 dash_polygon[j]=primitive_info[i-1];
1592 dash_polygon[j].point.x=(double) (primitive_info[i-1].point.x+dx*
1593 total_length/maximum_length);
1594 dash_polygon[j].point.y=(double) (primitive_info[i-1].point.y+dy*
1595 total_length/maximum_length);
1596 dash_polygon[j].coordinates=1;
1598 dash_polygon[0].coordinates=(size_t) j;
1599 dash_polygon[j].primitive=UndefinedPrimitive;
1600 status|=DrawStrokePolygon(image,clone_info,dash_polygon);
1603 if (draw_info->dash_pattern[n] == 0.0)
1605 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1607 length-=(maximum_length-total_length);
1608 if ((n & 0x01) != 0)
1610 dash_polygon[j]=primitive_info[i];
1611 dash_polygon[j].coordinates=1;
1614 if ((total_length < maximum_length) && ((n & 0x01) == 0) && (j > 1))
1616 dash_polygon[j]=primitive_info[i-1];
1617 dash_polygon[j].point.x+=MagickEpsilon;
1618 dash_polygon[j].point.y+=MagickEpsilon;
1619 dash_polygon[j].coordinates=1;
1621 dash_polygon[0].coordinates=(size_t) j;
1622 dash_polygon[j].primitive=UndefinedPrimitive;
1623 status|=DrawStrokePolygon(image,clone_info,dash_polygon);
1625 dash_polygon=(PrimitiveInfo *) RelinquishMagickMemory(dash_polygon);
1626 clone_info=DestroyDrawInfo(clone_info);
1627 if (image->debug != MagickFalse)
1628 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-dash");
1629 return(status != 0 ? MagickTrue : MagickFalse);
1633 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1637 % D r a w I m a g e %
1641 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1643 % DrawImage() draws a graphic primitive on your image. The primitive
1644 % may be represented as a string or filename. Precede the filename with an
1645 % "at" sign (@) and the contents of the file are drawn on the image. You
1646 % can affect how text is drawn by setting one or more members of the draw
1649 % The format of the DrawImage method is:
1651 % MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info)
1653 % A description of each parameter follows:
1655 % o image: the image.
1657 % o draw_info: the draw info.
1661 static inline MagickBooleanType IsPoint(const char *point)
1669 value=strtod(point,&p);
1670 return((value == 0.0) && (p == point) ? MagickFalse : MagickTrue);
1673 static inline void TracePoint(PrimitiveInfo *primitive_info,
1674 const PointInfo point)
1676 primitive_info->coordinates=1;
1677 primitive_info->point=point;
1680 MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info)
1682 #define RenderImageTag "Render/Image"
1689 key[2*MaxTextExtent],
1690 keyword[MaxTextExtent],
1691 geometry[MaxTextExtent],
1692 name[MaxTextExtent],
1693 pattern[MaxTextExtent],
1744 Ensure the annotation info is valid.
1746 assert(image != (Image *) NULL);
1747 assert(image->signature == MagickSignature);
1748 if (image->debug != MagickFalse)
1749 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1750 assert(draw_info != (DrawInfo *) NULL);
1751 assert(draw_info->signature == MagickSignature);
1752 if (image->debug != MagickFalse)
1753 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1754 if ((draw_info->primitive == (char *) NULL) ||
1755 (*draw_info->primitive == '\0'))
1756 return(MagickFalse);
1757 if (image->debug != MagickFalse)
1758 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"begin draw-image");
1759 if (*draw_info->primitive != '@')
1760 primitive=AcquireString(draw_info->primitive);
1762 primitive=FileToString(draw_info->primitive+1,~0,&image->exception);
1763 if (primitive == (char *) NULL)
1764 return(MagickFalse);
1765 primitive_extent=(MagickRealType) strlen(primitive);
1766 (void) SetImageArtifact(image,"MVG",primitive);
1769 Allocate primitive info memory.
1771 graphic_context=(DrawInfo **) AcquireAlignedMemory(1,
1772 sizeof(*graphic_context));
1773 if (graphic_context == (DrawInfo **) NULL)
1775 primitive=DestroyString(primitive);
1776 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1780 primitive_info=(PrimitiveInfo *) AcquireQuantumMemory((size_t) number_points,
1781 sizeof(*primitive_info));
1782 if (primitive_info == (PrimitiveInfo *) NULL)
1784 primitive=DestroyString(primitive);
1785 for ( ; n >= 0; n--)
1786 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
1787 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
1788 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1791 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1792 graphic_context[n]->viewbox=image->page;
1793 if ((image->page.width == 0) || (image->page.height == 0))
1795 graphic_context[n]->viewbox.width=image->columns;
1796 graphic_context[n]->viewbox.height=image->rows;
1798 token=AcquireString(primitive);
1799 (void) QueryColorDatabase("#000000",&start_color,&image->exception);
1800 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
1801 return(MagickFalse);
1803 for (q=primitive; *q != '\0'; )
1806 Interpret graphic primitive.
1808 GetMagickToken(q,&q,keyword);
1809 if (*keyword == '\0')
1811 if (*keyword == '#')
1816 while ((*q != '\n') && (*q != '\0'))
1820 p=q-strlen(keyword)-1;
1821 primitive_type=UndefinedPrimitive;
1822 current=graphic_context[n]->affine;
1823 GetAffineMatrix(&affine);
1831 if (LocaleCompare("affine",keyword) == 0)
1833 GetMagickToken(q,&q,token);
1834 affine.sx=StringToDouble(token);
1835 GetMagickToken(q,&q,token);
1837 GetMagickToken(q,&q,token);
1838 affine.rx=StringToDouble(token);
1839 GetMagickToken(q,&q,token);
1841 GetMagickToken(q,&q,token);
1842 affine.ry=StringToDouble(token);
1843 GetMagickToken(q,&q,token);
1845 GetMagickToken(q,&q,token);
1846 affine.sy=StringToDouble(token);
1847 GetMagickToken(q,&q,token);
1849 GetMagickToken(q,&q,token);
1850 affine.tx=StringToDouble(token);
1851 GetMagickToken(q,&q,token);
1853 GetMagickToken(q,&q,token);
1854 affine.ty=StringToDouble(token);
1857 if (LocaleCompare("arc",keyword) == 0)
1859 primitive_type=ArcPrimitive;
1868 if (LocaleCompare("bezier",keyword) == 0)
1870 primitive_type=BezierPrimitive;
1873 if (LocaleCompare("border-color",keyword) == 0)
1875 GetMagickToken(q,&q,token);
1876 (void) QueryColorDatabase(token,&graphic_context[n]->border_color,
1886 if (LocaleCompare("clip-path",keyword) == 0)
1891 GetMagickToken(q,&q,token);
1892 (void) CloneString(&graphic_context[n]->clip_mask,token);
1893 (void) DrawClipPath(image,graphic_context[n],
1894 graphic_context[n]->clip_mask);
1897 if (LocaleCompare("clip-rule",keyword) == 0)
1902 GetMagickToken(q,&q,token);
1903 fill_rule=ParseMagickOption(MagickFillRuleOptions,MagickFalse,
1905 if (fill_rule == -1)
1910 graphic_context[n]->fill_rule=(FillRule) fill_rule;
1913 if (LocaleCompare("clip-units",keyword) == 0)
1918 GetMagickToken(q,&q,token);
1919 clip_units=ParseMagickOption(MagickClipPathOptions,MagickFalse,
1921 if (clip_units == -1)
1926 graphic_context[n]->clip_units=(ClipPathUnits) clip_units;
1927 if (clip_units == ObjectBoundingBox)
1929 GetAffineMatrix(¤t);
1930 affine.sx=draw_info->bounds.x2;
1931 affine.sy=draw_info->bounds.y2;
1932 affine.tx=draw_info->bounds.x1;
1933 affine.ty=draw_info->bounds.y1;
1938 if (LocaleCompare("circle",keyword) == 0)
1940 primitive_type=CirclePrimitive;
1943 if (LocaleCompare("color",keyword) == 0)
1945 primitive_type=ColorPrimitive;
1954 if (LocaleCompare("decorate",keyword) == 0)
1959 GetMagickToken(q,&q,token);
1960 decorate=ParseMagickOption(MagickDecorateOptions,MagickFalse,
1967 graphic_context[n]->decorate=(DecorationType) decorate;
1976 if (LocaleCompare("ellipse",keyword) == 0)
1978 primitive_type=EllipsePrimitive;
1981 if (LocaleCompare("encoding",keyword) == 0)
1983 GetMagickToken(q,&q,token);
1984 (void) CloneString(&graphic_context[n]->encoding,token);
1993 if (LocaleCompare("fill",keyword) == 0)
1995 GetMagickToken(q,&q,token);
1996 (void) FormatMagickString(pattern,MaxTextExtent,"%s",token);
1997 if (GetImageArtifact(image,pattern) != (const char *) NULL)
1998 (void) DrawPatternPath(image,draw_info,token,
1999 &graphic_context[n]->fill_pattern);
2002 status=QueryColorDatabase(token,&graphic_context[n]->fill,
2004 if (status == MagickFalse)
2009 pattern_info=AcquireImageInfo();
2010 (void) CopyMagickString(pattern_info->filename,token,
2012 graphic_context[n]->fill_pattern=
2013 ReadImage(pattern_info,&image->exception);
2014 CatchException(&image->exception);
2015 pattern_info=DestroyImageInfo(pattern_info);
2020 if (LocaleCompare("fill-opacity",keyword) == 0)
2022 GetMagickToken(q,&q,token);
2023 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2024 graphic_context[n]->fill.opacity=ClampToQuantum((MagickRealType)
2025 QuantumRange*(1.0-factor*StringToDouble(token)));
2028 if (LocaleCompare("fill-rule",keyword) == 0)
2033 GetMagickToken(q,&q,token);
2034 fill_rule=ParseMagickOption(MagickFillRuleOptions,MagickFalse,
2036 if (fill_rule == -1)
2041 graphic_context[n]->fill_rule=(FillRule) fill_rule;
2044 if (LocaleCompare("font",keyword) == 0)
2046 GetMagickToken(q,&q,token);
2047 (void) CloneString(&graphic_context[n]->font,token);
2048 if (LocaleCompare("none",token) == 0)
2049 graphic_context[n]->font=(char *)
2050 RelinquishMagickMemory(graphic_context[n]->font);
2053 if (LocaleCompare("font-family",keyword) == 0)
2055 GetMagickToken(q,&q,token);
2056 (void) CloneString(&graphic_context[n]->family,token);
2059 if (LocaleCompare("font-size",keyword) == 0)
2061 GetMagickToken(q,&q,token);
2062 graphic_context[n]->pointsize=StringToDouble(token);
2065 if (LocaleCompare("font-stretch",keyword) == 0)
2070 GetMagickToken(q,&q,token);
2071 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,token);
2077 graphic_context[n]->stretch=(StretchType) stretch;
2080 if (LocaleCompare("font-style",keyword) == 0)
2085 GetMagickToken(q,&q,token);
2086 style=ParseMagickOption(MagickStyleOptions,MagickFalse,token);
2092 graphic_context[n]->style=(StyleType) style;
2095 if (LocaleCompare("font-weight",keyword) == 0)
2097 GetMagickToken(q,&q,token);
2098 graphic_context[n]->weight=StringToUnsignedLong(token);
2099 if (LocaleCompare(token,"all") == 0)
2100 graphic_context[n]->weight=0;
2101 if (LocaleCompare(token,"bold") == 0)
2102 graphic_context[n]->weight=700;
2103 if (LocaleCompare(token,"bolder") == 0)
2104 if (graphic_context[n]->weight <= 800)
2105 graphic_context[n]->weight+=100;
2106 if (LocaleCompare(token,"lighter") == 0)
2107 if (graphic_context[n]->weight >= 100)
2108 graphic_context[n]->weight-=100;
2109 if (LocaleCompare(token,"normal") == 0)
2110 graphic_context[n]->weight=400;
2119 if (LocaleCompare("gradient-units",keyword) == 0)
2121 GetMagickToken(q,&q,token);
2124 if (LocaleCompare("gravity",keyword) == 0)
2129 GetMagickToken(q,&q,token);
2130 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,token);
2136 graphic_context[n]->gravity=(GravityType) gravity;
2145 if (LocaleCompare("image",keyword) == 0)
2150 primitive_type=ImagePrimitive;
2151 GetMagickToken(q,&q,token);
2152 compose=ParseMagickOption(MagickComposeOptions,MagickFalse,token);
2158 graphic_context[n]->compose=(CompositeOperator) compose;
2161 if (LocaleCompare("interline-spacing",keyword) == 0)
2163 GetMagickToken(q,&q,token);
2164 graphic_context[n]->interline_spacing=StringToDouble(token);
2167 if (LocaleCompare("interword-spacing",keyword) == 0)
2169 GetMagickToken(q,&q,token);
2170 graphic_context[n]->interword_spacing=StringToDouble(token);
2179 if (LocaleCompare("kerning",keyword) == 0)
2181 GetMagickToken(q,&q,token);
2182 graphic_context[n]->kerning=StringToDouble(token);
2191 if (LocaleCompare("line",keyword) == 0)
2193 primitive_type=LinePrimitive;
2202 if (LocaleCompare("matte",keyword) == 0)
2204 primitive_type=MattePrimitive;
2213 if (LocaleCompare("offset",keyword) == 0)
2215 GetMagickToken(q,&q,token);
2218 if (LocaleCompare("opacity",keyword) == 0)
2220 GetMagickToken(q,&q,token);
2221 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2222 graphic_context[n]->opacity=ClampToQuantum((MagickRealType)
2223 QuantumRange*(1.0-((1.0-QuantumScale*graphic_context[n]->opacity)*
2224 factor*StringToDouble(token))));
2225 graphic_context[n]->fill.opacity=graphic_context[n]->opacity;
2226 graphic_context[n]->stroke.opacity=graphic_context[n]->opacity;
2235 if (LocaleCompare("path",keyword) == 0)
2237 primitive_type=PathPrimitive;
2240 if (LocaleCompare("point",keyword) == 0)
2242 primitive_type=PointPrimitive;
2245 if (LocaleCompare("polyline",keyword) == 0)
2247 primitive_type=PolylinePrimitive;
2250 if (LocaleCompare("polygon",keyword) == 0)
2252 primitive_type=PolygonPrimitive;
2255 if (LocaleCompare("pop",keyword) == 0)
2257 GetMagickToken(q,&q,token);
2258 if (LocaleCompare("clip-path",token) == 0)
2260 if (LocaleCompare("defs",token) == 0)
2262 if (LocaleCompare("gradient",token) == 0)
2264 if (LocaleCompare("graphic-context",token) == 0)
2268 (void) ThrowMagickException(&image->exception,
2269 GetMagickModule(),DrawError,
2270 "UnbalancedGraphicContextPushPop","`%s'",token);
2274 if (graphic_context[n]->clip_mask != (char *) NULL)
2275 if (LocaleCompare(graphic_context[n]->clip_mask,
2276 graphic_context[n-1]->clip_mask) != 0)
2277 (void) SetImageClipMask(image,(Image *) NULL);
2278 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
2282 if (LocaleCompare("pattern",token) == 0)
2287 if (LocaleCompare("push",keyword) == 0)
2289 GetMagickToken(q,&q,token);
2290 if (LocaleCompare("clip-path",token) == 0)
2293 name[MaxTextExtent];
2295 GetMagickToken(q,&q,token);
2296 (void) FormatMagickString(name,MaxTextExtent,"%s",token);
2297 for (p=q; *q != '\0'; )
2299 GetMagickToken(q,&q,token);
2300 if (LocaleCompare(token,"pop") != 0)
2302 GetMagickToken(q,(const char **) NULL,token);
2303 if (LocaleCompare(token,"clip-path") != 0)
2307 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2308 (void) SetImageArtifact(image,name,token);
2309 GetMagickToken(q,&q,token);
2312 if (LocaleCompare("gradient",token) == 0)
2315 key[2*MaxTextExtent],
2316 name[MaxTextExtent],
2317 type[MaxTextExtent];
2325 GetMagickToken(q,&q,token);
2326 (void) CopyMagickString(name,token,MaxTextExtent);
2327 GetMagickToken(q,&q,token);
2328 (void) CopyMagickString(type,token,MaxTextExtent);
2329 GetMagickToken(q,&q,token);
2330 segment.x1=StringToDouble(token);
2331 element.cx=StringToDouble(token);
2332 GetMagickToken(q,&q,token);
2334 GetMagickToken(q,&q,token);
2335 segment.y1=StringToDouble(token);
2336 element.cy=StringToDouble(token);
2337 GetMagickToken(q,&q,token);
2339 GetMagickToken(q,&q,token);
2340 segment.x2=StringToDouble(token);
2341 element.major=StringToDouble(token);
2342 GetMagickToken(q,&q,token);
2344 GetMagickToken(q,&q,token);
2345 segment.y2=StringToDouble(token);
2346 element.minor=StringToDouble(token);
2347 if (LocaleCompare(type,"radial") == 0)
2349 GetMagickToken(q,&q,token);
2351 GetMagickToken(q,&q,token);
2352 element.angle=StringToDouble(token);
2354 for (p=q; *q != '\0'; )
2356 GetMagickToken(q,&q,token);
2357 if (LocaleCompare(token,"pop") != 0)
2359 GetMagickToken(q,(const char **) NULL,token);
2360 if (LocaleCompare(token,"gradient") != 0)
2364 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2365 bounds.x1=graphic_context[n]->affine.sx*segment.x1+
2366 graphic_context[n]->affine.ry*segment.y1+
2367 graphic_context[n]->affine.tx;
2368 bounds.y1=graphic_context[n]->affine.rx*segment.x1+
2369 graphic_context[n]->affine.sy*segment.y1+
2370 graphic_context[n]->affine.ty;
2371 bounds.x2=graphic_context[n]->affine.sx*segment.x2+
2372 graphic_context[n]->affine.ry*segment.y2+
2373 graphic_context[n]->affine.tx;
2374 bounds.y2=graphic_context[n]->affine.rx*segment.x2+
2375 graphic_context[n]->affine.sy*segment.y2+
2376 graphic_context[n]->affine.ty;
2377 (void) FormatMagickString(key,MaxTextExtent,"%s",name);
2378 (void) SetImageArtifact(image,key,token);
2379 (void) FormatMagickString(key,MaxTextExtent,"%s-geometry",name);
2380 (void) FormatMagickString(geometry,MaxTextExtent,
2381 "%gx%g%+.15g%+.15g",
2382 MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0),
2383 MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0),
2384 bounds.x1,bounds.y1);
2385 (void) SetImageArtifact(image,key,geometry);
2386 GetMagickToken(q,&q,token);
2389 if (LocaleCompare("pattern",token) == 0)
2394 GetMagickToken(q,&q,token);
2395 (void) CopyMagickString(name,token,MaxTextExtent);
2396 GetMagickToken(q,&q,token);
2397 bounds.x=(ssize_t) ceil(StringToDouble(token)-0.5);
2398 GetMagickToken(q,&q,token);
2400 GetMagickToken(q,&q,token);
2401 bounds.y=(ssize_t) ceil(StringToDouble(token)-0.5);
2402 GetMagickToken(q,&q,token);
2404 GetMagickToken(q,&q,token);
2405 bounds.width=(size_t) floor(StringToDouble(token)+0.5);
2406 GetMagickToken(q,&q,token);
2408 GetMagickToken(q,&q,token);
2409 bounds.height=(size_t) floor(StringToDouble(token)+0.5);
2410 for (p=q; *q != '\0'; )
2412 GetMagickToken(q,&q,token);
2413 if (LocaleCompare(token,"pop") != 0)
2415 GetMagickToken(q,(const char **) NULL,token);
2416 if (LocaleCompare(token,"pattern") != 0)
2420 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2421 (void) FormatMagickString(key,MaxTextExtent,"%s",name);
2422 (void) SetImageArtifact(image,key,token);
2423 (void) FormatMagickString(key,MaxTextExtent,"%s-geometry",name);
2424 (void) FormatMagickString(geometry,MaxTextExtent,
2425 "%.20gx%.20g%+.20g%+.20g",(double) bounds.width,(double)
2426 bounds.height,(double) bounds.x,(double) bounds.y);
2427 (void) SetImageArtifact(image,key,geometry);
2428 GetMagickToken(q,&q,token);
2431 if (LocaleCompare("graphic-context",token) == 0)
2434 graphic_context=(DrawInfo **) ResizeQuantumMemory(
2435 graphic_context,(size_t) (n+1),sizeof(*graphic_context));
2436 if (graphic_context == (DrawInfo **) NULL)
2438 (void) ThrowMagickException(&image->exception,
2439 GetMagickModule(),ResourceLimitError,
2440 "MemoryAllocationFailed","`%s'",image->filename);
2443 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,
2444 graphic_context[n-1]);
2447 if (LocaleCompare("defs",token) == 0)
2458 if (LocaleCompare("rectangle",keyword) == 0)
2460 primitive_type=RectanglePrimitive;
2463 if (LocaleCompare("rotate",keyword) == 0)
2465 GetMagickToken(q,&q,token);
2466 angle=StringToDouble(token);
2467 affine.sx=cos(DegreesToRadians(fmod((double) angle,360.0)));
2468 affine.rx=sin(DegreesToRadians(fmod((double) angle,360.0)));
2469 affine.ry=(-sin(DegreesToRadians(fmod((double) angle,360.0))));
2470 affine.sy=cos(DegreesToRadians(fmod((double) angle,360.0)));
2473 if (LocaleCompare("roundRectangle",keyword) == 0)
2475 primitive_type=RoundRectanglePrimitive;
2484 if (LocaleCompare("scale",keyword) == 0)
2486 GetMagickToken(q,&q,token);
2487 affine.sx=StringToDouble(token);
2488 GetMagickToken(q,&q,token);
2490 GetMagickToken(q,&q,token);
2491 affine.sy=StringToDouble(token);
2494 if (LocaleCompare("skewX",keyword) == 0)
2496 GetMagickToken(q,&q,token);
2497 angle=StringToDouble(token);
2498 affine.ry=sin(DegreesToRadians(angle));
2501 if (LocaleCompare("skewY",keyword) == 0)
2503 GetMagickToken(q,&q,token);
2504 angle=StringToDouble(token);
2505 affine.rx=(-tan(DegreesToRadians(angle)/2.0));
2508 if (LocaleCompare("stop-color",keyword) == 0)
2513 GetMagickToken(q,&q,token);
2514 (void) QueryColorDatabase(token,&stop_color,&image->exception);
2515 (void) GradientImage(image,LinearGradient,ReflectSpread,
2516 &start_color,&stop_color);
2517 start_color=stop_color;
2518 GetMagickToken(q,&q,token);
2521 if (LocaleCompare("stroke",keyword) == 0)
2523 GetMagickToken(q,&q,token);
2524 (void) FormatMagickString(pattern,MaxTextExtent,"%s",token);
2525 if (GetImageArtifact(image,pattern) != (const char *) NULL)
2526 (void) DrawPatternPath(image,draw_info,token,
2527 &graphic_context[n]->stroke_pattern);
2530 status=QueryColorDatabase(token,&graphic_context[n]->stroke,
2532 if (status == MagickFalse)
2537 pattern_info=AcquireImageInfo();
2538 (void) CopyMagickString(pattern_info->filename,token,
2540 graphic_context[n]->stroke_pattern=
2541 ReadImage(pattern_info,&image->exception);
2542 CatchException(&image->exception);
2543 pattern_info=DestroyImageInfo(pattern_info);
2548 if (LocaleCompare("stroke-antialias",keyword) == 0)
2550 GetMagickToken(q,&q,token);
2551 graphic_context[n]->stroke_antialias=
2552 StringToLong(token) != 0 ? MagickTrue : MagickFalse;
2555 if (LocaleCompare("stroke-dasharray",keyword) == 0)
2557 if (graphic_context[n]->dash_pattern != (double *) NULL)
2558 graphic_context[n]->dash_pattern=(double *)
2559 RelinquishMagickMemory(graphic_context[n]->dash_pattern);
2560 if (IsPoint(q) != MagickFalse)
2566 GetMagickToken(p,&p,token);
2568 GetMagickToken(p,&p,token);
2569 for (x=0; IsPoint(token) != MagickFalse; x++)
2571 GetMagickToken(p,&p,token);
2573 GetMagickToken(p,&p,token);
2575 graphic_context[n]->dash_pattern=(double *)
2576 AcquireQuantumMemory((size_t) (2UL*x+1UL),
2577 sizeof(*graphic_context[n]->dash_pattern));
2578 if (graphic_context[n]->dash_pattern == (double *) NULL)
2580 (void) ThrowMagickException(&image->exception,
2581 GetMagickModule(),ResourceLimitError,
2582 "MemoryAllocationFailed","`%s'",image->filename);
2585 for (j=0; j < x; j++)
2587 GetMagickToken(q,&q,token);
2589 GetMagickToken(q,&q,token);
2590 graphic_context[n]->dash_pattern[j]=StringToDouble(token);
2592 if ((x & 0x01) != 0)
2593 for ( ; j < (2*x); j++)
2594 graphic_context[n]->dash_pattern[j]=
2595 graphic_context[n]->dash_pattern[j-x];
2596 graphic_context[n]->dash_pattern[j]=0.0;
2599 GetMagickToken(q,&q,token);
2602 if (LocaleCompare("stroke-dashoffset",keyword) == 0)
2604 GetMagickToken(q,&q,token);
2605 graphic_context[n]->dash_offset=StringToDouble(token);
2608 if (LocaleCompare("stroke-linecap",keyword) == 0)
2613 GetMagickToken(q,&q,token);
2614 linecap=ParseMagickOption(MagickLineCapOptions,MagickFalse,token);
2620 graphic_context[n]->linecap=(LineCap) linecap;
2623 if (LocaleCompare("stroke-linejoin",keyword) == 0)
2628 GetMagickToken(q,&q,token);
2629 linejoin=ParseMagickOption(MagickLineJoinOptions,MagickFalse,token);
2635 graphic_context[n]->linejoin=(LineJoin) linejoin;
2638 if (LocaleCompare("stroke-miterlimit",keyword) == 0)
2640 GetMagickToken(q,&q,token);
2641 graphic_context[n]->miterlimit=StringToUnsignedLong(token);
2644 if (LocaleCompare("stroke-opacity",keyword) == 0)
2646 GetMagickToken(q,&q,token);
2647 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2648 graphic_context[n]->stroke.opacity=ClampToQuantum((MagickRealType)
2649 QuantumRange*(1.0-factor*StringToDouble(token)));
2652 if (LocaleCompare("stroke-width",keyword) == 0)
2654 GetMagickToken(q,&q,token);
2655 graphic_context[n]->stroke_width=StringToDouble(token);
2664 if (LocaleCompare("text",keyword) == 0)
2666 primitive_type=TextPrimitive;
2669 if (LocaleCompare("text-align",keyword) == 0)
2674 GetMagickToken(q,&q,token);
2675 align=ParseMagickOption(MagickAlignOptions,MagickFalse,token);
2681 graphic_context[n]->align=(AlignType) align;
2684 if (LocaleCompare("text-anchor",keyword) == 0)
2689 GetMagickToken(q,&q,token);
2690 align=ParseMagickOption(MagickAlignOptions,MagickFalse,token);
2696 graphic_context[n]->align=(AlignType) align;
2699 if (LocaleCompare("text-antialias",keyword) == 0)
2701 GetMagickToken(q,&q,token);
2702 graphic_context[n]->text_antialias=
2703 StringToLong(token) != 0 ? MagickTrue : MagickFalse;
2706 if (LocaleCompare("text-undercolor",keyword) == 0)
2708 GetMagickToken(q,&q,token);
2709 (void) QueryColorDatabase(token,&graphic_context[n]->undercolor,
2713 if (LocaleCompare("translate",keyword) == 0)
2715 GetMagickToken(q,&q,token);
2716 affine.tx=StringToDouble(token);
2717 GetMagickToken(q,&q,token);
2719 GetMagickToken(q,&q,token);
2720 affine.ty=StringToDouble(token);
2729 if (LocaleCompare("viewbox",keyword) == 0)
2731 GetMagickToken(q,&q,token);
2732 graphic_context[n]->viewbox.x=(ssize_t) ceil(StringToDouble(token)-
2734 GetMagickToken(q,&q,token);
2736 GetMagickToken(q,&q,token);
2737 graphic_context[n]->viewbox.y=(ssize_t) ceil(StringToDouble(token)-
2739 GetMagickToken(q,&q,token);
2741 GetMagickToken(q,&q,token);
2742 graphic_context[n]->viewbox.width=(size_t) floor(
2743 StringToDouble(token)+0.5);
2744 GetMagickToken(q,&q,token);
2746 GetMagickToken(q,&q,token);
2747 graphic_context[n]->viewbox.height=(size_t) floor(
2748 StringToDouble(token)+0.5);
2760 if (status == MagickFalse)
2762 if ((affine.sx != 1.0) || (affine.rx != 0.0) || (affine.ry != 0.0) ||
2763 (affine.sy != 1.0) || (affine.tx != 0.0) || (affine.ty != 0.0))
2765 graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
2766 graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
2767 graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
2768 graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
2769 graphic_context[n]->affine.tx=
2770 current.sx*affine.tx+current.ry*affine.ty+current.tx;
2771 graphic_context[n]->affine.ty=
2772 current.rx*affine.tx+current.sy*affine.ty+current.ty;
2774 if (primitive_type == UndefinedPrimitive)
2776 if (image->debug != MagickFalse)
2777 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",
2782 Parse the primitive attributes.
2786 primitive_info[0].point.x=0.0;
2787 primitive_info[0].point.y=0.0;
2788 for (x=0; *q != '\0'; x++)
2793 if (IsPoint(q) == MagickFalse)
2795 GetMagickToken(q,&q,token);
2796 point.x=StringToDouble(token);
2797 GetMagickToken(q,&q,token);
2799 GetMagickToken(q,&q,token);
2800 point.y=StringToDouble(token);
2801 GetMagickToken(q,(const char **) NULL,token);
2803 GetMagickToken(q,&q,token);
2804 primitive_info[i].primitive=primitive_type;
2805 primitive_info[i].point=point;
2806 primitive_info[i].coordinates=0;
2807 primitive_info[i].method=FloodfillMethod;
2809 if (i < (ssize_t) number_points)
2812 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,
2813 (size_t) number_points,sizeof(*primitive_info));
2814 if (primitive_info == (PrimitiveInfo *) NULL)
2816 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2817 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
2821 primitive_info[j].primitive=primitive_type;
2822 primitive_info[j].coordinates=(size_t) x;
2823 primitive_info[j].method=FloodfillMethod;
2824 primitive_info[j].text=(char *) NULL;
2826 Circumscribe primitive within a circle.
2828 bounds.x1=primitive_info[j].point.x;
2829 bounds.y1=primitive_info[j].point.y;
2830 bounds.x2=primitive_info[j].point.x;
2831 bounds.y2=primitive_info[j].point.y;
2832 for (k=1; k < (ssize_t) primitive_info[j].coordinates; k++)
2834 point=primitive_info[j+k].point;
2835 if (point.x < bounds.x1)
2837 if (point.y < bounds.y1)
2839 if (point.x > bounds.x2)
2841 if (point.y > bounds.y2)
2845 Speculate how many points our primitive might consume.
2847 length=primitive_info[j].coordinates;
2848 switch (primitive_type)
2850 case RectanglePrimitive:
2855 case RoundRectanglePrimitive:
2857 length*=5+8*BezierQuantum;
2860 case BezierPrimitive:
2862 if (primitive_info[j].coordinates > 107)
2863 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2864 DrawError,"TooManyBezierCoordinates","`%s'",token);
2865 length=BezierQuantum*primitive_info[j].coordinates;
2874 GetMagickToken(q,&q,token);
2877 for (s=token; *s != '\0'; s=t)
2888 length+=BezierQuantum;
2892 case CirclePrimitive:
2894 case EllipsePrimitive:
2901 alpha=bounds.x2-bounds.x1;
2902 beta=bounds.y2-bounds.y1;
2903 radius=hypot((double) alpha,(double) beta);
2904 length=2*((size_t) (MagickPI*radius))+6*BezierQuantum+360+1;
2910 if ((size_t) (i+length) >= number_points)
2913 Resize based on speculative points required by primitive.
2915 number_points+=length+1;
2916 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,
2917 (size_t) number_points,sizeof(*primitive_info));
2918 if (primitive_info == (PrimitiveInfo *) NULL)
2920 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2921 ResourceLimitError,"MemoryAllocationFailed","`%s'",
2926 switch (primitive_type)
2928 case PointPrimitive:
2931 if (primitive_info[j].coordinates != 1)
2936 TracePoint(primitive_info+j,primitive_info[j].point);
2937 i=(ssize_t) (j+primitive_info[j].coordinates);
2942 if (primitive_info[j].coordinates != 2)
2947 TraceLine(primitive_info+j,primitive_info[j].point,
2948 primitive_info[j+1].point);
2949 i=(ssize_t) (j+primitive_info[j].coordinates);
2952 case RectanglePrimitive:
2954 if (primitive_info[j].coordinates != 2)
2959 TraceRectangle(primitive_info+j,primitive_info[j].point,
2960 primitive_info[j+1].point);
2961 i=(ssize_t) (j+primitive_info[j].coordinates);
2964 case RoundRectanglePrimitive:
2966 if (primitive_info[j].coordinates != 3)
2971 TraceRoundRectangle(primitive_info+j,primitive_info[j].point,
2972 primitive_info[j+1].point,primitive_info[j+2].point);
2973 i=(ssize_t) (j+primitive_info[j].coordinates);
2978 if (primitive_info[j].coordinates != 3)
2980 primitive_type=UndefinedPrimitive;
2983 TraceArc(primitive_info+j,primitive_info[j].point,
2984 primitive_info[j+1].point,primitive_info[j+2].point);
2985 i=(ssize_t) (j+primitive_info[j].coordinates);
2988 case EllipsePrimitive:
2990 if (primitive_info[j].coordinates != 3)
2995 TraceEllipse(primitive_info+j,primitive_info[j].point,
2996 primitive_info[j+1].point,primitive_info[j+2].point);
2997 i=(ssize_t) (j+primitive_info[j].coordinates);
3000 case CirclePrimitive:
3002 if (primitive_info[j].coordinates != 2)
3007 TraceCircle(primitive_info+j,primitive_info[j].point,
3008 primitive_info[j+1].point);
3009 i=(ssize_t) (j+primitive_info[j].coordinates);
3012 case PolylinePrimitive:
3014 case PolygonPrimitive:
3016 primitive_info[i]=primitive_info[j];
3017 primitive_info[i].coordinates=0;
3018 primitive_info[j].coordinates++;
3022 case BezierPrimitive:
3024 if (primitive_info[j].coordinates < 3)
3029 TraceBezier(primitive_info+j,primitive_info[j].coordinates);
3030 i=(ssize_t) (j+primitive_info[j].coordinates);
3035 i=(ssize_t) (j+TracePath(primitive_info+j,token));
3038 case ColorPrimitive:
3039 case MattePrimitive:
3044 if (primitive_info[j].coordinates != 1)
3049 GetMagickToken(q,&q,token);
3050 method=ParseMagickOption(MagickMethodOptions,MagickFalse,token);
3056 primitive_info[j].method=(PaintMethod) method;
3061 if (primitive_info[j].coordinates != 1)
3067 GetMagickToken(q,&q,token);
3068 primitive_info[j].text=AcquireString(token);
3071 case ImagePrimitive:
3073 if (primitive_info[j].coordinates != 2)
3078 GetMagickToken(q,&q,token);
3079 primitive_info[j].text=AcquireString(token);
3083 if (primitive_info == (PrimitiveInfo *) NULL)
3085 if (image->debug != MagickFalse)
3086 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",(int) (q-p),p);
3087 if (status == MagickFalse)
3089 primitive_info[i].primitive=UndefinedPrimitive;
3095 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
3097 point=primitive_info[i].point;
3098 primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+
3099 graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx;
3100 primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+
3101 graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty;
3102 point=primitive_info[i].point;
3103 if (point.x < graphic_context[n]->bounds.x1)
3104 graphic_context[n]->bounds.x1=point.x;
3105 if (point.y < graphic_context[n]->bounds.y1)
3106 graphic_context[n]->bounds.y1=point.y;
3107 if (point.x > graphic_context[n]->bounds.x2)
3108 graphic_context[n]->bounds.x2=point.x;
3109 if (point.y > graphic_context[n]->bounds.y2)
3110 graphic_context[n]->bounds.y2=point.y;
3111 if (primitive_info[i].primitive == ImagePrimitive)
3113 if (i >= (ssize_t) number_points)
3114 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
3116 if (graphic_context[n]->render != MagickFalse)
3118 if ((n != 0) && (graphic_context[n]->clip_mask != (char *) NULL) &&
3119 (LocaleCompare(graphic_context[n]->clip_mask,
3120 graphic_context[n-1]->clip_mask) != 0))
3121 (void) DrawClipPath(image,graphic_context[n],
3122 graphic_context[n]->clip_mask);
3123 (void) DrawPrimitive(image,graphic_context[n],primitive_info);
3125 if (primitive_info->text != (char *) NULL)
3126 primitive_info->text=(char *) RelinquishMagickMemory(
3127 primitive_info->text);
3128 proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType)
3130 if (proceed == MagickFalse)
3133 if (image->debug != MagickFalse)
3134 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end draw-image");
3136 Relinquish resources.
3138 token=DestroyString(token);
3139 if (primitive_info != (PrimitiveInfo *) NULL)
3140 primitive_info=(PrimitiveInfo *) RelinquishMagickMemory(primitive_info);
3141 primitive=DestroyString(primitive);
3142 for ( ; n >= 0; n--)
3143 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
3144 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
3145 if (status == MagickFalse)
3146 ThrowBinaryException(DrawError,"NonconformingDrawingPrimitiveDefinition",
3152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3156 % D r a w G r a d i e n t I m a g e %
3160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3162 % DrawGradientImage() draws a linear gradient on the image.
3164 % The format of the DrawGradientImage method is:
3166 % MagickBooleanType DrawGradientImage(Image *image,
3167 % const DrawInfo *draw_info)
3169 % A description of each parameter follows:
3171 % o image: the image.
3173 % o _info: the draw info.
3177 static inline MagickRealType GetStopColorOffset(const GradientInfo *gradient,
3178 const ssize_t x,const ssize_t y)
3180 switch (gradient->type)
3182 case UndefinedGradient:
3183 case LinearGradient:
3198 gradient_vector=(&gradient->gradient_vector);
3199 p.x=gradient_vector->x2-gradient_vector->x1;
3200 p.y=gradient_vector->y2-gradient_vector->y1;
3201 q.x=(double) x-gradient_vector->x1;
3202 q.y=(double) y-gradient_vector->y1;
3203 length=sqrt(q.x*q.x+q.y*q.y);
3204 gamma=sqrt(p.x*p.x+p.y*p.y)*length;
3205 gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
3206 scale=p.x*q.x+p.y*q.y;
3207 offset=gamma*scale*length;
3210 case RadialGradient:
3219 v.x=(double) x-gradient->center.x;
3220 v.y=(double) y-gradient->center.y;
3221 length=sqrt(v.x*v.x+v.y*v.y);
3222 if (gradient->spread == RepeatSpread)
3224 offset=length/gradient->radius;
3231 MagickExport MagickBooleanType DrawGradientImage(Image *image,
3232 const DrawInfo *draw_info)
3265 Draw linear or radial gradient on image.
3267 assert(image != (Image *) NULL);
3268 assert(image->signature == MagickSignature);
3269 if (image->debug != MagickFalse)
3270 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3271 assert(draw_info != (const DrawInfo *) NULL);
3272 gradient=(&draw_info->gradient);
3273 gradient_vector=(&gradient->gradient_vector);
3274 point.x=gradient_vector->x2-gradient_vector->x1;
3275 point.y=gradient_vector->y2-gradient_vector->y1;
3276 length=sqrt(point.x*point.x+point.y*point.y);
3277 bounding_box=gradient->bounding_box;
3279 exception=(&image->exception);
3280 GetMagickPixelPacket(image,&zero);
3281 image_view=AcquireCacheView(image);
3282 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3283 #pragma omp parallel for schedule(dynamic,4) shared(status)
3285 for (y=bounding_box.y; y < (ssize_t) bounding_box.height; y++)
3295 register IndexPacket
3302 register PixelPacket
3308 if (status == MagickFalse)
3310 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3311 if (q == (PixelPacket *) NULL)
3316 indexes=GetCacheViewAuthenticIndexQueue(image_view);
3319 offset=GetStopColorOffset(gradient,0,y);
3320 if (gradient->type != RadialGradient)
3322 for (x=bounding_box.x; x < (ssize_t) bounding_box.width; x++)
3324 SetMagickPixelPacket(image,q,indexes+x,&pixel);
3325 switch (gradient->spread)
3327 case UndefinedSpread:
3330 if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) ||
3331 (y != (ssize_t) ceil(gradient_vector->y1-0.5)))
3333 offset=GetStopColorOffset(gradient,x,y);
3334 if (gradient->type != RadialGradient)
3337 for (i=0; i < (ssize_t) gradient->number_stops; i++)
3338 if (offset < gradient->stops[i].offset)
3340 if ((offset < 0.0) || (i == 0))
3341 composite=gradient->stops[0].color;
3343 if ((offset > 1.0) || (i == (ssize_t) gradient->number_stops))
3344 composite=gradient->stops[gradient->number_stops-1].color;
3349 alpha=(offset-gradient->stops[i].offset)/
3350 (gradient->stops[j].offset-gradient->stops[i].offset);
3351 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3352 &gradient->stops[j].color,alpha,&composite);
3358 if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) ||
3359 (y != (ssize_t) ceil(gradient_vector->y1-0.5)))
3361 offset=GetStopColorOffset(gradient,x,y);
3362 if (gradient->type != RadialGradient)
3367 if ((ssize_t) fmod(offset,2.0) == 0)
3368 offset=fmod(offset,1.0);
3370 offset=1.0-fmod(offset,1.0);
3371 for (i=0; i < (ssize_t) gradient->number_stops; i++)
3372 if (offset < gradient->stops[i].offset)
3375 composite=gradient->stops[0].color;
3377 if (i == (ssize_t) gradient->number_stops)
3378 composite=gradient->stops[gradient->number_stops-1].color;
3383 alpha=(offset-gradient->stops[i].offset)/
3384 (gradient->stops[j].offset-gradient->stops[i].offset);
3385 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3386 &gradient->stops[j].color,alpha,&composite);
3398 antialias=MagickFalse;
3400 if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) ||
3401 (y != (ssize_t) ceil(gradient_vector->y1-0.5)))
3403 offset=GetStopColorOffset(gradient,x,y);
3404 if (gradient->type == LinearGradient)
3406 repeat=fmod(offset,length);
3408 repeat=length-fmod(-repeat,length);
3410 repeat=fmod(offset,length);
3411 antialias=(repeat < length) && ((repeat+1.0) > length) ?
3412 MagickTrue : MagickFalse;
3413 offset=repeat/length;
3417 repeat=fmod(offset,gradient->radius);
3419 repeat=gradient->radius-fmod(-repeat,gradient->radius);
3421 repeat=fmod(offset,gradient->radius);
3422 antialias=repeat+1.0 > gradient->radius ?
3423 MagickTrue : MagickFalse;
3424 offset=repeat/gradient->radius;
3427 for (i=0; i < (ssize_t) gradient->number_stops; i++)
3428 if (offset < gradient->stops[i].offset)
3431 composite=gradient->stops[0].color;
3433 if (i == (ssize_t) gradient->number_stops)
3434 composite=gradient->stops[gradient->number_stops-1].color;
3439 alpha=(offset-gradient->stops[i].offset)/
3440 (gradient->stops[j].offset-gradient->stops[i].offset);
3441 if (antialias != MagickFalse)
3443 if (gradient->type == LinearGradient)
3444 alpha=length-repeat;
3446 alpha=gradient->radius-repeat;
3448 j=(ssize_t) gradient->number_stops-1L;
3450 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3451 &gradient->stops[j].color,alpha,&composite);
3456 MagickPixelCompositeOver(&composite,composite.opacity,&pixel,
3457 pixel.opacity,&pixel);
3458 SetPixelPacket(image,&pixel,q,indexes+x);
3461 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3464 image_view=DestroyCacheView(image_view);
3469 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3473 % D r a w P a t t e r n P a t h %
3477 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3479 % DrawPatternPath() draws a pattern.
3481 % The format of the DrawPatternPath method is:
3483 % MagickBooleanType DrawPatternPath(Image *image,const DrawInfo *draw_info,
3484 % const char *name,Image **pattern)
3486 % A description of each parameter follows:
3488 % o image: the image.
3490 % o draw_info: the draw info.
3492 % o name: the pattern name.
3494 % o image: the image.
3497 MagickExport MagickBooleanType DrawPatternPath(Image *image,
3498 const DrawInfo *draw_info,const char *name,Image **pattern)
3501 property[MaxTextExtent];
3516 assert(image != (Image *) NULL);
3517 assert(image->signature == MagickSignature);
3518 if (image->debug != MagickFalse)
3519 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3520 assert(draw_info != (const DrawInfo *) NULL);
3521 assert(name != (const char *) NULL);
3522 (void) FormatMagickString(property,MaxTextExtent,"%s",name);
3523 path=GetImageArtifact(image,property);
3524 if (path == (const char *) NULL)
3525 return(MagickFalse);
3526 (void) FormatMagickString(property,MaxTextExtent,"%s-geometry",name);
3527 geometry=GetImageArtifact(image,property);
3528 if (geometry == (const char *) NULL)
3529 return(MagickFalse);
3530 if ((*pattern) != (Image *) NULL)
3531 *pattern=DestroyImage(*pattern);
3532 image_info=AcquireImageInfo();
3533 image_info->size=AcquireString(geometry);
3534 *pattern=AcquireImage(image_info);
3535 image_info=DestroyImageInfo(image_info);
3536 (void) QueryColorDatabase("#00000000",&(*pattern)->background_color,
3538 (void) SetImageBackgroundColor(*pattern);
3539 if (image->debug != MagickFalse)
3540 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
3541 "begin pattern-path %s %s",name,geometry);
3542 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
3543 clone_info->fill_pattern=NewImageList();
3544 clone_info->stroke_pattern=NewImageList();
3545 (void) CloneString(&clone_info->primitive,path);
3546 status=DrawImage(*pattern,clone_info);
3547 clone_info=DestroyDrawInfo(clone_info);
3548 if (image->debug != MagickFalse)
3549 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end pattern-path");
3554 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3558 + D r a w P o l y g o n P r i m i t i v e %
3562 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3564 % DrawPolygonPrimitive() draws a polygon on the image.
3566 % The format of the DrawPolygonPrimitive method is:
3568 % MagickBooleanType DrawPolygonPrimitive(Image *image,
3569 % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
3571 % A description of each parameter follows:
3573 % o image: the image.
3575 % o draw_info: the draw info.
3577 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
3581 static PolygonInfo **DestroyPolygonThreadSet(PolygonInfo **polygon_info)
3586 assert(polygon_info != (PolygonInfo **) NULL);
3587 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
3588 if (polygon_info[i] != (PolygonInfo *) NULL)
3589 polygon_info[i]=DestroyPolygonInfo(polygon_info[i]);
3590 polygon_info=(PolygonInfo **) RelinquishAlignedMemory(polygon_info);
3591 return(polygon_info);
3594 static PolygonInfo **AcquirePolygonThreadSet(const DrawInfo *draw_info,
3595 const PrimitiveInfo *primitive_info)
3598 *restrict path_info;
3609 number_threads=GetOpenMPMaximumThreads();
3610 polygon_info=(PolygonInfo **) AcquireAlignedMemory(number_threads,
3611 sizeof(*polygon_info));
3612 if (polygon_info == (PolygonInfo **) NULL)
3613 return((PolygonInfo **) NULL);
3614 (void) ResetMagickMemory(polygon_info,0,GetOpenMPMaximumThreads()*
3615 sizeof(*polygon_info));
3616 path_info=ConvertPrimitiveToPath(draw_info,primitive_info);
3617 if (path_info == (PathInfo *) NULL)
3618 return(DestroyPolygonThreadSet(polygon_info));
3619 for (i=0; i < (ssize_t) number_threads; i++)
3621 polygon_info[i]=ConvertPathToPolygon(draw_info,path_info);
3622 if (polygon_info[i] == (PolygonInfo *) NULL)
3623 return(DestroyPolygonThreadSet(polygon_info));
3625 path_info=(PathInfo *) RelinquishMagickMemory(path_info);
3626 return(polygon_info);
3629 static MagickRealType GetPixelOpacity(PolygonInfo *polygon_info,
3630 const MagickRealType mid,const MagickBooleanType fill,
3631 const FillRule fill_rule,const double x,const double y,
3632 MagickRealType *stroke_opacity)
3646 register const PointInfo
3657 Compute fill & stroke opacity for this (x,y) point.
3659 *stroke_opacity=0.0;
3660 subpath_opacity=0.0;
3661 p=polygon_info->edges;
3662 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
3664 if (y <= (p->bounds.y1-mid-0.5))
3666 if (y > (p->bounds.y2+mid+0.5))
3668 (void) DestroyEdge(polygon_info,(size_t) j);
3671 if ((x <= (p->bounds.x1-mid-0.5)) || (x > (p->bounds.x2+mid+0.5)))
3673 i=(ssize_t) MagickMax((double) p->highwater,1.0);
3674 for ( ; i < (ssize_t) p->number_points; i++)
3676 if (y <= (p->points[i-1].y-mid-0.5))
3678 if (y > (p->points[i].y+mid+0.5))
3680 if (p->scanline != y)
3683 p->highwater=(size_t) i;
3686 Compute distance between a point and an edge.
3689 delta.x=(q+1)->x-q->x;
3690 delta.y=(q+1)->y-q->y;
3691 beta=delta.x*(x-q->x)+delta.y*(y-q->y);
3696 distance=delta.x*delta.x+delta.y*delta.y;
3700 alpha=delta.x*delta.x+delta.y*delta.y;
3705 distance=delta.x*delta.x+delta.y*delta.y;
3710 beta=delta.x*(y-q->y)-delta.y*(x-q->x);
3711 distance=alpha*beta*beta;
3715 Compute stroke & subpath opacity.
3718 if (p->ghostline == MagickFalse)
3721 if ((*stroke_opacity < 1.0) &&
3722 (distance <= ((alpha+0.25)*(alpha+0.25))))
3725 if (distance <= ((alpha+0.25)*(alpha+0.25)))
3726 *stroke_opacity=1.0;
3730 if (distance != 1.0)
3731 beta=sqrt((double) distance);
3733 if (*stroke_opacity < ((alpha-0.25)*(alpha-0.25)))
3734 *stroke_opacity=(alpha-0.25)*(alpha-0.25);
3738 if ((fill == MagickFalse) || (distance > 1.0) || (subpath_opacity >= 1.0))
3740 if (distance <= 0.0)
3742 subpath_opacity=1.0;
3750 if (distance != 1.0)
3751 beta=sqrt(distance);
3754 if (subpath_opacity < (alpha*alpha))
3755 subpath_opacity=alpha*alpha;
3759 Compute fill opacity.
3761 if (fill == MagickFalse)
3763 if (subpath_opacity >= 1.0)
3766 Determine winding number.
3769 p=polygon_info->edges;
3770 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
3772 if (y <= p->bounds.y1)
3774 if ((y > p->bounds.y2) || (x <= p->bounds.x1))
3776 if (x > p->bounds.x2)
3778 winding_number+=p->direction ? 1 : -1;
3781 i=(ssize_t) MagickMax((double) p->highwater,1.0);
3782 for ( ; i < (ssize_t) p->number_points; i++)
3783 if (y <= p->points[i].y)
3786 if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x)))
3787 winding_number+=p->direction ? 1 : -1;
3789 if (fill_rule != NonZeroRule)
3791 if ((MagickAbsoluteValue(winding_number) & 0x01) != 0)
3795 if (MagickAbsoluteValue(winding_number) != 0)
3797 return(subpath_opacity);
3800 static MagickBooleanType DrawPolygonPrimitive(Image *image,
3801 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
3817 **restrict polygon_info;
3834 Compute bounding box.
3836 assert(image != (Image *) NULL);
3837 assert(image->signature == MagickSignature);
3838 if (image->debug != MagickFalse)
3839 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3840 assert(draw_info != (DrawInfo *) NULL);
3841 assert(draw_info->signature == MagickSignature);
3842 assert(primitive_info != (PrimitiveInfo *) NULL);
3843 if (primitive_info->coordinates == 0)
3845 polygon_info=AcquirePolygonThreadSet(draw_info,primitive_info);
3846 if (polygon_info == (PolygonInfo **) NULL)
3847 return(MagickFalse);
3849 DrawBoundingRectangles(image,draw_info,polygon_info[0]);
3850 if (image->debug != MagickFalse)
3851 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-polygon");
3852 fill=(primitive_info->method == FillToBorderMethod) ||
3853 (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse;
3854 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
3855 bounds=polygon_info[0]->edges[0].bounds;
3856 for (i=1; i < (ssize_t) polygon_info[0]->number_edges; i++)
3858 p=polygon_info[0]->edges+i;
3859 if (p->bounds.x1 < bounds.x1)
3860 bounds.x1=p->bounds.x1;
3861 if (p->bounds.y1 < bounds.y1)
3862 bounds.y1=p->bounds.y1;
3863 if (p->bounds.x2 > bounds.x2)
3864 bounds.x2=p->bounds.x2;
3865 if (p->bounds.y2 > bounds.y2)
3866 bounds.y2=p->bounds.y2;
3868 bounds.x1-=(mid+1.0);
3869 bounds.x1=bounds.x1 < 0.0 ? 0.0 : (size_t) ceil(bounds.x1-0.5) >=
3870 image->columns ? (double) image->columns-1.0 : bounds.x1;
3871 bounds.y1-=(mid+1.0);
3872 bounds.y1=bounds.y1 < 0.0 ? 0.0 : (size_t) ceil(bounds.y1-0.5) >=
3873 image->rows ? (double) image->rows-1.0 : bounds.y1;
3874 bounds.x2+=(mid+1.0);
3875 bounds.x2=bounds.x2 < 0.0 ? 0.0 : (size_t) floor(bounds.x2+0.5) >=
3876 image->columns ? (double) image->columns-1.0 : bounds.x2;
3877 bounds.y2+=(mid+1.0);
3878 bounds.y2=bounds.y2 < 0.0 ? 0.0 : (size_t) floor(bounds.y2+0.5) >=
3879 image->rows ? (double) image->rows-1.0 : bounds.y2;
3881 exception=(&image->exception);
3882 start=(ssize_t) ceil(bounds.x1-0.5);
3883 stop=(ssize_t) floor(bounds.x2+0.5);
3884 image_view=AcquireCacheView(image);
3885 if (primitive_info->coordinates == 1)
3890 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3891 #pragma omp parallel for schedule(dynamic,4) shared(status)
3893 for (y=(ssize_t) ceil(bounds.y1-0.5); y <= (ssize_t) floor(bounds.y2+0.5); y++)
3901 register PixelPacket
3904 if (status == MagickFalse)
3907 q=GetCacheViewAuthenticPixels(image_view,x,y,(size_t) (stop-x+1),
3909 if (q == (PixelPacket *) NULL)
3914 for ( ; x <= stop; x++)
3916 if ((x == (ssize_t) ceil(primitive_info->point.x-0.5)) &&
3917 (y == (ssize_t) ceil(primitive_info->point.y-0.5)))
3918 (void) GetStrokeColor(draw_info,x,y,q);
3921 sync=SyncCacheViewAuthenticPixels(image_view,exception);
3922 if (sync == MagickFalse)
3925 image_view=DestroyCacheView(image_view);
3926 polygon_info=DestroyPolygonThreadSet(polygon_info);
3927 if (image->debug != MagickFalse)
3928 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
3929 " end draw-polygon");
3933 Draw polygon or line.
3935 if (image->matte == MagickFalse)
3936 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3937 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3938 #pragma omp parallel for schedule(dynamic,4) shared(status)
3940 for (y=(ssize_t) ceil(bounds.y1-0.5); y <= (ssize_t) floor(bounds.y2+0.5); y++)
3953 register PixelPacket
3959 if (status == MagickFalse)
3961 q=GetCacheViewAuthenticPixels(image_view,start,y,(size_t) (stop-
3962 start+1),1,exception);
3963 if (q == (PixelPacket *) NULL)
3968 id=GetOpenMPThreadId();
3969 for (x=start; x <= stop; x++)
3974 fill_opacity=GetPixelOpacity(polygon_info[id],mid,fill,
3975 draw_info->fill_rule,(double) x,(double) y,&stroke_opacity);
3976 if (draw_info->stroke_antialias == MagickFalse)
3978 fill_opacity=fill_opacity > 0.25 ? 1.0 : 0.0;
3979 stroke_opacity=stroke_opacity > 0.25 ? 1.0 : 0.0;
3981 (void) GetFillColor(draw_info,x,y,&fill_color);
3982 fill_opacity=(MagickRealType) (QuantumRange-fill_opacity*(QuantumRange-
3983 fill_color.opacity));
3984 MagickCompositeOver(&fill_color,fill_opacity,q,(MagickRealType)
3986 (void) GetStrokeColor(draw_info,x,y,&stroke_color);
3987 stroke_opacity=(MagickRealType) (QuantumRange-stroke_opacity*
3988 (QuantumRange-stroke_color.opacity));
3989 MagickCompositeOver(&stroke_color,stroke_opacity,q,(MagickRealType)
3993 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3996 image_view=DestroyCacheView(image_view);
3997 polygon_info=DestroyPolygonThreadSet(polygon_info);
3998 if (image->debug != MagickFalse)
3999 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-polygon");
4004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4008 % D r a w P r i m i t i v e %
4012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4014 % DrawPrimitive() draws a primitive (line, rectangle, ellipse) on the image.
4016 % The format of the DrawPrimitive method is:
4018 % MagickBooleanType DrawPrimitive(Image *image,const DrawInfo *draw_info,
4019 % PrimitiveInfo *primitive_info)
4021 % A description of each parameter follows:
4023 % o image: the image.
4025 % o draw_info: the draw info.
4027 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
4031 static void LogPrimitiveInfo(const PrimitiveInfo *primitive_info)
4057 x=(ssize_t) ceil(primitive_info->point.x-0.5);
4058 y=(ssize_t) ceil(primitive_info->point.y-0.5);
4059 switch (primitive_info->primitive)
4061 case PointPrimitive:
4063 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4064 "PointPrimitive %.20g,%.20g %s",(double) x,(double) y,
4065 methods[primitive_info->method]);
4068 case ColorPrimitive:
4070 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4071 "ColorPrimitive %.20g,%.20g %s",(double) x,(double) y,
4072 methods[primitive_info->method]);
4075 case MattePrimitive:
4077 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4078 "MattePrimitive %.20g,%.20g %s",(double) x,(double) y,
4079 methods[primitive_info->method]);
4084 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4085 "TextPrimitive %.20g,%.20g",(double) x,(double) y);
4088 case ImagePrimitive:
4090 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4091 "ImagePrimitive %.20g,%.20g",(double) x,(double) y);
4098 p=primitive_info[0].point;
4101 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4103 point=primitive_info[i].point;
4104 if (coordinates <= 0)
4106 coordinates=(ssize_t) primitive_info[i].coordinates;
4107 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4108 " begin open (%.20g)",(double) coordinates);
4111 point=primitive_info[i].point;
4112 if ((fabs(q.x-point.x) > MagickEpsilon) ||
4113 (fabs(q.y-point.y) > MagickEpsilon))
4114 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4115 " %.20g: %.18g,%.18g",(double) coordinates,point.x,point.y);
4117 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4118 " %.20g: %g,%g (duplicate)",(double) coordinates,point.x,point.y);
4121 if (coordinates > 0)
4123 if ((fabs(p.x-point.x) > MagickEpsilon) ||
4124 (fabs(p.y-point.y) > MagickEpsilon))
4125 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end last (%.20g)",
4126 (double) coordinates);
4128 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end open (%.20g)",
4129 (double) coordinates);
4133 MagickExport MagickBooleanType DrawPrimitive(Image *image,
4134 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4152 if (image->debug != MagickFalse)
4154 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4155 " begin draw-primitive");
4156 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4157 " affine: %g,%g,%g,%g,%g,%g",draw_info->affine.sx,
4158 draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy,
4159 draw_info->affine.tx,draw_info->affine.ty);
4162 exception=(&image->exception);
4163 x=(ssize_t) ceil(primitive_info->point.x-0.5);
4164 y=(ssize_t) ceil(primitive_info->point.y-0.5);
4165 image_view=AcquireCacheView(image);
4166 switch (primitive_info->primitive)
4168 case PointPrimitive:
4176 if ((y < 0) || (y >= (ssize_t) image->rows))
4178 if ((x < 0) || (x >= (ssize_t) image->columns))
4180 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4181 if (q == (PixelPacket *) NULL)
4183 (void) GetFillColor(draw_info,x,y,&fill_color);
4184 MagickCompositeOver(&fill_color,(MagickRealType) fill_color.opacity,q,
4185 (MagickRealType) q->opacity,q);
4186 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4189 case ColorPrimitive:
4191 switch (primitive_info->method)
4199 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4200 if (q == (PixelPacket *) NULL)
4202 (void) GetFillColor(draw_info,x,y,q);
4203 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4214 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception);
4215 for (y=0; y < (ssize_t) image->rows; y++)
4217 register PixelPacket
4220 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4222 if (q == (PixelPacket *) NULL)
4224 for (x=0; x < (ssize_t) image->columns; x++)
4226 if (IsColorSimilar(image,q,&target) == MagickFalse)
4231 (void) GetFillColor(draw_info,x,y,q);
4234 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4235 if (sync == MagickFalse)
4240 case FloodfillMethod:
4241 case FillToBorderMethod:
4246 (void) GetOneVirtualMagickPixel(image,x,y,&target,exception);
4247 if (primitive_info->method == FillToBorderMethod)
4249 target.red=(MagickRealType) draw_info->border_color.red;
4250 target.green=(MagickRealType) draw_info->border_color.green;
4251 target.blue=(MagickRealType) draw_info->border_color.blue;
4253 (void) FloodfillPaintImage(image,DefaultChannels,draw_info,&target,x,
4254 y,primitive_info->method == FloodfillMethod ? MagickFalse :
4263 for (y=0; y < (ssize_t) image->rows; y++)
4265 register PixelPacket
4271 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4273 if (q == (PixelPacket *) NULL)
4275 for (x=0; x < (ssize_t) image->columns; x++)
4277 (void) GetFillColor(draw_info,x,y,q);
4280 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4281 if (sync == MagickFalse)
4289 case MattePrimitive:
4291 if (image->matte == MagickFalse)
4292 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
4293 switch (primitive_info->method)
4304 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4305 if (q == (PixelPacket *) NULL)
4307 (void) GetFillColor(draw_info,x,y,&pixel);
4308 q->opacity=pixel.opacity;
4309 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4321 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception);
4322 for (y=0; y < (ssize_t) image->rows; y++)
4324 register PixelPacket
4330 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4332 if (q == (PixelPacket *) NULL)
4334 for (x=0; x < (ssize_t) image->columns; x++)
4336 if (IsColorSimilar(image,q,&target) == MagickFalse)
4341 (void) GetFillColor(draw_info,x,y,&pixel);
4342 q->opacity=pixel.opacity;
4345 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4346 if (sync == MagickFalse)
4351 case FloodfillMethod:
4352 case FillToBorderMethod:
4357 (void) GetOneVirtualMagickPixel(image,x,y,&target,exception);
4358 if (primitive_info->method == FillToBorderMethod)
4360 target.red=(MagickRealType) draw_info->border_color.red;
4361 target.green=(MagickRealType) draw_info->border_color.green;
4362 target.blue=(MagickRealType) draw_info->border_color.blue;
4364 (void) FloodfillPaintImage(image,OpacityChannel,draw_info,&target,x,y,
4365 primitive_info->method == FloodfillMethod ? MagickFalse :
4377 for (y=0; y < (ssize_t) image->rows; y++)
4379 register PixelPacket
4385 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4387 if (q == (PixelPacket *) NULL)
4389 for (x=0; x < (ssize_t) image->columns; x++)
4391 (void) GetFillColor(draw_info,x,y,&pixel);
4392 q->opacity=pixel.opacity;
4395 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4396 if (sync == MagickFalse)
4407 geometry[MaxTextExtent];
4412 if (primitive_info->text == (char *) NULL)
4414 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4415 (void) CloneString(&clone_info->text,primitive_info->text);
4416 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
4417 primitive_info->point.x,primitive_info->point.y);
4418 (void) CloneString(&clone_info->geometry,geometry);
4419 status=AnnotateImage(image,clone_info);
4420 clone_info=DestroyDrawInfo(clone_info);
4423 case ImagePrimitive:
4429 composite_geometry[MaxTextExtent];
4444 if (primitive_info->text == (char *) NULL)
4446 clone_info=AcquireImageInfo();
4447 if (LocaleNCompare(primitive_info->text,"data:",5) == 0)
4448 composite_image=ReadInlineImage(clone_info,primitive_info->text,
4452 (void) CopyMagickString(clone_info->filename,primitive_info->text,
4454 composite_image=ReadImage(clone_info,&image->exception);
4456 clone_info=DestroyImageInfo(clone_info);
4457 if (composite_image == (Image *) NULL)
4459 (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor)
4460 NULL,(void *) NULL);
4461 x1=(ssize_t) ceil(primitive_info[1].point.x-0.5);
4462 y1=(ssize_t) ceil(primitive_info[1].point.y-0.5);
4463 if (((x1 != 0L) && (x1 != (ssize_t) composite_image->columns)) ||
4464 ((y1 != 0L) && (y1 != (ssize_t) composite_image->rows)))
4467 geometry[MaxTextExtent];
4472 (void) FormatMagickString(geometry,MaxTextExtent,"%gx%g!",
4473 primitive_info[1].point.x,primitive_info[1].point.y);
4474 composite_image->filter=image->filter;
4475 (void) TransformImage(&composite_image,(char *) NULL,geometry);
4477 if (composite_image->matte == MagickFalse)
4478 (void) SetImageAlphaChannel(composite_image,OpaqueAlphaChannel);
4479 if (draw_info->opacity != OpaqueOpacity)
4480 (void) SetImageOpacity(composite_image,draw_info->opacity);
4481 SetGeometry(image,&geometry);
4482 image->gravity=draw_info->gravity;
4485 (void) FormatMagickString(composite_geometry,MaxTextExtent,
4486 "%.20gx%.20g%+.20g%+.20g",(double) composite_image->columns,(double)
4487 composite_image->rows,(double) geometry.x,(double) geometry.y);
4488 (void) ParseGravityGeometry(image,composite_geometry,&geometry,
4490 affine=draw_info->affine;
4491 affine.tx=(double) geometry.x;
4492 affine.ty=(double) geometry.y;
4493 composite_image->interpolate=image->interpolate;
4494 if (draw_info->compose == OverCompositeOp)
4495 (void) DrawAffineImage(image,composite_image,&affine);
4497 (void) CompositeImage(image,draw_info->compose,composite_image,
4498 geometry.x,geometry.y);
4499 composite_image=DestroyImage(composite_image);
4511 if (IsEventLogging() != MagickFalse)
4512 LogPrimitiveInfo(primitive_info);
4513 scale=ExpandAffine(&draw_info->affine);
4514 if ((draw_info->dash_pattern != (double *) NULL) &&
4515 (draw_info->dash_pattern[0] != 0.0) &&
4516 ((scale*draw_info->stroke_width) > MagickEpsilon) &&
4517 (draw_info->stroke.opacity != (Quantum) TransparentOpacity))
4522 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4523 clone_info->stroke_width=0.0;
4524 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4525 status=DrawPolygonPrimitive(image,clone_info,primitive_info);
4526 clone_info=DestroyDrawInfo(clone_info);
4527 (void) DrawDashPolygon(draw_info,primitive_info,image);
4530 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
4532 (draw_info->stroke.opacity != (Quantum) TransparentOpacity))
4538 Draw strokes while respecting line cap/join attributes.
4540 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
4542 (primitive_info[i-1].point.x == primitive_info[0].point.x) &&
4543 (primitive_info[i-1].point.y == primitive_info[0].point.y) ?
4544 MagickTrue : MagickFalse;
4545 i=(ssize_t) primitive_info[0].coordinates;
4546 if ((((draw_info->linecap == RoundCap) ||
4547 (closed_path != MagickFalse)) &&
4548 (draw_info->linejoin == RoundJoin)) ||
4549 (primitive_info[i].primitive != UndefinedPrimitive))
4551 (void) DrawPolygonPrimitive(image,draw_info,primitive_info);
4554 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4555 clone_info->stroke_width=0.0;
4556 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4557 status=DrawPolygonPrimitive(image,clone_info,primitive_info);
4558 clone_info=DestroyDrawInfo(clone_info);
4559 status|=DrawStrokePolygon(image,draw_info,primitive_info);
4562 status=DrawPolygonPrimitive(image,draw_info,primitive_info);
4566 image_view=DestroyCacheView(image_view);
4567 if (image->debug != MagickFalse)
4568 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-primitive");
4569 return(status != 0 ? MagickTrue : MagickFalse);
4573 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4577 + D r a w S t r o k e P o l y g o n %
4581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4583 % DrawStrokePolygon() draws a stroked polygon (line, rectangle, ellipse) on
4584 % the image while respecting the line cap and join attributes.
4586 % The format of the DrawStrokePolygon method is:
4588 % MagickBooleanType DrawStrokePolygon(Image *image,
4589 % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4591 % A description of each parameter follows:
4593 % o image: the image.
4595 % o draw_info: the draw info.
4597 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
4602 static void DrawRoundLinecap(Image *image,const DrawInfo *draw_info,
4603 const PrimitiveInfo *primitive_info)
4611 for (i=0; i < 4; i++)
4612 linecap[i]=(*primitive_info);
4613 linecap[0].coordinates=4;
4614 linecap[1].point.x+=(double) (10.0*MagickEpsilon);
4615 linecap[2].point.x+=(double) (10.0*MagickEpsilon);
4616 linecap[2].point.y+=(double) (10.0*MagickEpsilon);
4617 linecap[3].point.y+=(double) (10.0*MagickEpsilon);
4618 linecap[4].primitive=UndefinedPrimitive;
4619 (void) DrawPolygonPrimitive(image,draw_info,linecap);
4622 static MagickBooleanType DrawStrokePolygon(Image *image,
4623 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4635 register const PrimitiveInfo
4640 Draw stroked polygon.
4642 if (image->debug != MagickFalse)
4643 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4644 " begin draw-stroke-polygon");
4645 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4646 clone_info->fill=draw_info->stroke;
4647 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4648 clone_info->stroke_width=0.0;
4649 clone_info->fill_rule=NonZeroRule;
4651 for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=p->coordinates)
4653 stroke_polygon=TraceStrokePolygon(draw_info,p);
4654 status=DrawPolygonPrimitive(image,clone_info,stroke_polygon);
4655 stroke_polygon=(PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon);
4656 q=p+p->coordinates-1;
4657 closed_path=(q->point.x == p->point.x) && (q->point.y == p->point.y) ?
4658 MagickTrue : MagickFalse;
4659 if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse))
4661 DrawRoundLinecap(image,draw_info,p);
4662 DrawRoundLinecap(image,draw_info,q);
4665 clone_info=DestroyDrawInfo(clone_info);
4666 if (image->debug != MagickFalse)
4667 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4668 " end draw-stroke-polygon");
4673 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4677 % G e t A f f i n e M a t r i x %
4681 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4683 % GetAffineMatrix() returns an AffineMatrix initialized to the identity
4686 % The format of the GetAffineMatrix method is:
4688 % void GetAffineMatrix(AffineMatrix *affine_matrix)
4690 % A description of each parameter follows:
4692 % o affine_matrix: the affine matrix.
4695 MagickExport void GetAffineMatrix(AffineMatrix *affine_matrix)
4697 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4698 assert(affine_matrix != (AffineMatrix *) NULL);
4699 (void) ResetMagickMemory(affine_matrix,0,sizeof(*affine_matrix));
4700 affine_matrix->sx=1.0;
4701 affine_matrix->sy=1.0;
4705 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4709 + G e t D r a w I n f o %
4713 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4715 % GetDrawInfo() initializes draw_info to default values.
4717 % The format of the GetDrawInfo method is:
4719 % void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info)
4721 % A description of each parameter follows:
4723 % o image_info: the image info..
4725 % o draw_info: the draw info.
4728 MagickExport void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info)
4740 Initialize draw attributes.
4742 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4743 assert(draw_info != (DrawInfo *) NULL);
4744 (void) ResetMagickMemory(draw_info,0,sizeof(*draw_info));
4745 clone_info=CloneImageInfo(image_info);
4746 GetAffineMatrix(&draw_info->affine);
4747 exception=AcquireExceptionInfo();
4748 (void) QueryColorDatabase("#000F",&draw_info->fill,exception);
4749 (void) QueryColorDatabase("#FFF0",&draw_info->stroke,exception);
4750 draw_info->stroke_antialias=clone_info->antialias;
4751 draw_info->stroke_width=1.0;
4752 draw_info->opacity=OpaqueOpacity;
4753 draw_info->fill_rule=EvenOddRule;
4754 draw_info->linecap=ButtCap;
4755 draw_info->linejoin=MiterJoin;
4756 draw_info->miterlimit=10;
4757 draw_info->decorate=NoDecoration;
4758 if (clone_info->font != (char *) NULL)
4759 draw_info->font=AcquireString(clone_info->font);
4760 if (clone_info->density != (char *) NULL)
4761 draw_info->density=AcquireString(clone_info->density);
4762 draw_info->text_antialias=clone_info->antialias;
4763 draw_info->pointsize=12.0;
4764 if (clone_info->pointsize != 0.0)
4765 draw_info->pointsize=clone_info->pointsize;
4766 draw_info->undercolor.opacity=(Quantum) TransparentOpacity;
4767 draw_info->border_color=clone_info->border_color;
4768 draw_info->compose=OverCompositeOp;
4769 if (clone_info->server_name != (char *) NULL)
4770 draw_info->server_name=AcquireString(clone_info->server_name);
4771 draw_info->render=MagickTrue;
4772 draw_info->debug=IsEventLogging();
4773 option=GetImageOption(clone_info,"encoding");
4774 if (option != (const char *) NULL)
4775 (void) CloneString(&draw_info->encoding,option);
4776 option=GetImageOption(clone_info,"kerning");
4777 if (option != (const char *) NULL)
4778 draw_info->kerning=StringToDouble(option);
4779 option=GetImageOption(clone_info,"interline-spacing");
4780 if (option != (const char *) NULL)
4781 draw_info->interline_spacing=StringToDouble(option);
4782 draw_info->direction=UndefinedDirection;
4783 option=GetImageOption(clone_info,"interword-spacing");
4784 if (option != (const char *) NULL)
4785 draw_info->interword_spacing=StringToDouble(option);
4786 option=GetImageOption(clone_info,"direction");
4787 if (option != (const char *) NULL)
4788 draw_info->direction=(DirectionType) ParseMagickOption(
4789 MagickDirectionOptions,MagickFalse,option);
4790 option=GetImageOption(clone_info,"fill");
4791 if (option != (const char *) NULL)
4792 (void) QueryColorDatabase(option,&draw_info->fill,exception);
4793 option=GetImageOption(clone_info,"stroke");
4794 if (option != (const char *) NULL)
4795 (void) QueryColorDatabase(option,&draw_info->stroke,exception);
4796 option=GetImageOption(clone_info,"strokewidth");
4797 if (option != (const char *) NULL)
4798 draw_info->stroke_width=StringToDouble(option);
4799 option=GetImageOption(clone_info,"undercolor");
4800 if (option != (const char *) NULL)
4801 (void) QueryColorDatabase(option,&draw_info->undercolor,exception);
4802 option=GetImageOption(clone_info,"gravity");
4803 if (option != (const char *) NULL)
4804 draw_info->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
4805 MagickFalse,option);
4806 exception=DestroyExceptionInfo(exception);
4807 draw_info->signature=MagickSignature;
4808 clone_info=DestroyImageInfo(clone_info);
4812 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4816 + P e r m u t a t e %
4820 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4822 % Permutate() returns the permuation of the (n,k).
4824 % The format of the Permutate method is:
4826 % void Permutate(ssize_t n,ssize_t k)
4828 % A description of each parameter follows:
4836 static inline MagickRealType Permutate(const ssize_t n,const ssize_t k)
4845 for (i=k+1; i <= n; i++)
4847 for (i=1; i <= (n-k); i++)
4853 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4857 + T r a c e P r i m i t i v e %
4861 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4863 % TracePrimitive is a collection of methods for generating graphic
4864 % primitives such as arcs, ellipses, paths, etc.
4868 static void TraceArc(PrimitiveInfo *primitive_info,const PointInfo start,
4869 const PointInfo end,const PointInfo degrees)
4875 center.x=0.5*(end.x+start.x);
4876 center.y=0.5*(end.y+start.y);
4877 radii.x=fabs(center.x-start.x);
4878 radii.y=fabs(center.y-start.y);
4879 TraceEllipse(primitive_info,center,radii,degrees);
4882 static void TraceArcPath(PrimitiveInfo *primitive_info,const PointInfo start,
4883 const PointInfo end,const PointInfo arc,const MagickRealType angle,
4884 const MagickBooleanType large_arc,const MagickBooleanType sweep)
4899 register MagickRealType
4903 register PrimitiveInfo
4912 if ((start.x == end.x) && (start.y == end.y))
4914 TracePoint(primitive_info,end);
4917 radii.x=fabs(arc.x);
4918 radii.y=fabs(arc.y);
4919 if ((radii.x == 0.0) || (radii.y == 0.0))
4921 TraceLine(primitive_info,start,end);
4924 cosine=cos(DegreesToRadians(fmod((double) angle,360.0)));
4925 sine=sin(DegreesToRadians(fmod((double) angle,360.0)));
4926 center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2);
4927 center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2);
4928 delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/
4930 if (delta < MagickEpsilon)
4932 TraceLine(primitive_info,start,end);
4937 radii.x*=sqrt((double) delta);
4938 radii.y*=sqrt((double) delta);
4940 points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x);
4941 points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y);
4942 points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x);
4943 points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y);
4944 alpha=points[1].x-points[0].x;
4945 beta=points[1].y-points[0].y;
4946 factor=1.0/(alpha*alpha+beta*beta)-0.25;
4951 factor=sqrt((double) factor);
4952 if (sweep == large_arc)
4955 center.x=(double) ((points[0].x+points[1].x)/2-factor*beta);
4956 center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha);
4957 alpha=atan2(points[0].y-center.y,points[0].x-center.x);
4958 theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha;
4959 if ((theta < 0.0) && (sweep != MagickFalse))
4960 theta+=(MagickRealType) (2.0*MagickPI);
4962 if ((theta > 0.0) && (sweep == MagickFalse))
4963 theta-=(MagickRealType) (2.0*MagickPI);
4964 arc_segments=(size_t) ceil(fabs((double) (theta/(0.5*MagickPI+
4967 for (i=0; i < (ssize_t) arc_segments; i++)
4969 beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments));
4970 gamma=(8.0/3.0)*sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))*
4971 sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))/
4972 sin(fmod((double) beta,DegreesToRadians(360.0)));
4973 points[0].x=(double) (center.x+cos(fmod((double) (alpha+(double) i*theta/
4974 arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((double) (alpha+
4975 (double) i*theta/arc_segments),DegreesToRadians(360.0))));
4976 points[0].y=(double) (center.y+sin(fmod((double) (alpha+(double) i*theta/
4977 arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((double) (alpha+
4978 (double) i*theta/arc_segments),DegreesToRadians(360.0))));
4979 points[2].x=(double) (center.x+cos(fmod((double) (alpha+(double) (i+1)*
4980 theta/arc_segments),DegreesToRadians(360.0))));
4981 points[2].y=(double) (center.y+sin(fmod((double) (alpha+(double) (i+1)*
4982 theta/arc_segments),DegreesToRadians(360.0))));
4983 points[1].x=(double) (points[2].x+gamma*sin(fmod((double) (alpha+(double)
4984 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
4985 points[1].y=(double) (points[2].y-gamma*cos(fmod((double) (alpha+(double)
4986 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
4987 p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x;
4988 p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y;
4989 (p+1)->point.x=(double) (cosine*radii.x*points[0].x-sine*radii.y*
4991 (p+1)->point.y=(double) (sine*radii.x*points[0].x+cosine*radii.y*
4993 (p+2)->point.x=(double) (cosine*radii.x*points[1].x-sine*radii.y*
4995 (p+2)->point.y=(double) (sine*radii.x*points[1].x+cosine*radii.y*
4997 (p+3)->point.x=(double) (cosine*radii.x*points[2].x-sine*radii.y*
4999 (p+3)->point.y=(double) (sine*radii.x*points[2].x+cosine*radii.y*
5001 if (i == (ssize_t) (arc_segments-1))
5006 primitive_info->coordinates=(size_t) (p-primitive_info);
5007 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5009 p->primitive=primitive_info->primitive;
5014 static void TraceBezier(PrimitiveInfo *primitive_info,
5015 const size_t number_coordinates)
5027 register PrimitiveInfo
5039 Allocate coeficients.
5041 quantum=number_coordinates;
5042 for (i=0; i < (ssize_t) number_coordinates; i++)
5044 for (j=i+1; j < (ssize_t) number_coordinates; j++)
5046 alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x);
5047 if (alpha > (MagickRealType) quantum)
5048 quantum=(size_t) alpha;
5049 alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y);
5050 if (alpha > (MagickRealType) quantum)
5051 quantum=(size_t) alpha;
5054 quantum=(size_t) MagickMin((double) quantum/number_coordinates,
5055 (double) BezierQuantum);
5056 control_points=quantum*number_coordinates;
5057 coefficients=(MagickRealType *) AcquireQuantumMemory((size_t)
5058 number_coordinates,sizeof(*coefficients));
5059 points=(PointInfo *) AcquireQuantumMemory((size_t) control_points,
5061 if ((coefficients == (MagickRealType *) NULL) ||
5062 (points == (PointInfo *) NULL))
5063 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
5065 Compute bezier points.
5067 end=primitive_info[number_coordinates-1].point;
5068 for (i=0; i < (ssize_t) number_coordinates; i++)
5069 coefficients[i]=Permutate((ssize_t) number_coordinates-1,i);
5071 for (i=0; i < (ssize_t) control_points; i++)
5076 alpha=pow((double) (1.0-weight),(double) number_coordinates-1.0);
5077 for (j=0; j < (ssize_t) number_coordinates; j++)
5079 point.x+=alpha*coefficients[j]*p->point.x;
5080 point.y+=alpha*coefficients[j]*p->point.y;
5081 alpha*=weight/(1.0-weight);
5085 weight+=1.0/control_points;
5088 Bezier curves are just short segmented polys.
5091 for (i=0; i < (ssize_t) control_points; i++)
5093 TracePoint(p,points[i]);
5098 primitive_info->coordinates=(size_t) (p-primitive_info);
5099 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5101 p->primitive=primitive_info->primitive;
5104 points=(PointInfo *) RelinquishMagickMemory(points);
5105 coefficients=(MagickRealType *) RelinquishMagickMemory(coefficients);
5108 static void TraceCircle(PrimitiveInfo *primitive_info,const PointInfo start,
5109 const PointInfo end)
5120 alpha=end.x-start.x;
5122 radius=hypot((double) alpha,(double) beta);
5123 offset.x=(double) radius;
5124 offset.y=(double) radius;
5127 TraceEllipse(primitive_info,start,offset,degrees);
5130 static void TraceEllipse(PrimitiveInfo *primitive_info,const PointInfo start,
5131 const PointInfo stop,const PointInfo degrees)
5142 register PrimitiveInfo
5149 Ellipses are just short segmented polys.
5151 if ((stop.x == 0.0) && (stop.y == 0.0))
5153 TracePoint(primitive_info,start);
5156 delta=2.0/MagickMax(stop.x,stop.y);
5157 step=(MagickRealType) (MagickPI/8.0);
5158 if ((delta >= 0.0) && (delta < (MagickPI/8.0)))
5159 step=MagickPI/(4*(MagickPI/delta/2+0.5));
5160 angle.x=DegreesToRadians(degrees.x);
5162 while (y < degrees.x)
5164 angle.y=(double) (DegreesToRadians(y)-MagickEpsilon);
5165 for (p=primitive_info; angle.x < angle.y; angle.x+=step)
5167 point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*stop.x+start.x;
5168 point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*stop.y+start.y;
5169 TracePoint(p,point);
5172 point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*stop.x+start.x;
5173 point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*stop.y+start.y;
5174 TracePoint(p,point);
5176 primitive_info->coordinates=(size_t) (p-primitive_info);
5177 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5179 p->primitive=primitive_info->primitive;
5184 static void TraceLine(PrimitiveInfo *primitive_info,const PointInfo start,
5185 const PointInfo end)
5187 TracePoint(primitive_info,start);
5188 if ((fabs(start.x-end.x) <= MagickEpsilon) &&
5189 (fabs(start.y-end.y) <= MagickEpsilon))
5191 primitive_info->primitive=PointPrimitive;
5192 primitive_info->coordinates=1;
5195 TracePoint(primitive_info+1,end);
5196 (primitive_info+1)->primitive=primitive_info->primitive;
5197 primitive_info->coordinates=2;
5200 static size_t TracePath(PrimitiveInfo *primitive_info,const char *path)
5203 token[MaxTextExtent];
5225 register PrimitiveInfo
5240 number_coordinates=0;
5242 primitive_type=primitive_info->primitive;
5244 for (p=path; *p != '\0'; )
5246 while (isspace((int) ((unsigned char) *p)) != 0)
5250 last_attribute=attribute;
5251 attribute=(int) (*p++);
5272 GetMagickToken(p,&p,token);
5274 GetMagickToken(p,&p,token);
5275 arc.x=StringToDouble(token);
5276 GetMagickToken(p,&p,token);
5278 GetMagickToken(p,&p,token);
5279 arc.y=StringToDouble(token);
5280 GetMagickToken(p,&p,token);
5282 GetMagickToken(p,&p,token);
5283 angle=StringToDouble(token);
5284 GetMagickToken(p,&p,token);
5286 GetMagickToken(p,&p,token);
5287 large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
5288 GetMagickToken(p,&p,token);
5290 GetMagickToken(p,&p,token);
5291 sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
5292 GetMagickToken(p,&p,token);
5294 GetMagickToken(p,&p,token);
5295 x=StringToDouble(token);
5296 GetMagickToken(p,&p,token);
5298 GetMagickToken(p,&p,token);
5299 y=StringToDouble(token);
5300 end.x=(double) (attribute == (int) 'A' ? x : point.x+x);
5301 end.y=(double) (attribute == (int) 'A' ? y : point.y+y);
5302 TraceArcPath(q,point,end,arc,angle,large_arc,sweep);
5305 } while (IsPoint(p) != MagickFalse);
5312 Compute bezier points.
5317 for (i=1; i < 4; i++)
5319 GetMagickToken(p,&p,token);
5321 GetMagickToken(p,&p,token);
5322 x=StringToDouble(token);
5323 GetMagickToken(p,&p,token);
5325 GetMagickToken(p,&p,token);
5326 y=StringToDouble(token);
5327 end.x=(double) (attribute == (int) 'C' ? x : point.x+x);
5328 end.y=(double) (attribute == (int) 'C' ? y : point.y+y);
5331 for (i=0; i < 4; i++)
5332 (q+i)->point=points[i];
5336 } while (IsPoint(p) != MagickFalse);
5344 GetMagickToken(p,&p,token);
5346 GetMagickToken(p,&p,token);
5347 x=StringToDouble(token);
5348 point.x=(double) (attribute == (int) 'H' ? x: point.x+x);
5349 TracePoint(q,point);
5351 } while (IsPoint(p) != MagickFalse);
5359 GetMagickToken(p,&p,token);
5361 GetMagickToken(p,&p,token);
5362 x=StringToDouble(token);
5363 GetMagickToken(p,&p,token);
5365 GetMagickToken(p,&p,token);
5366 y=StringToDouble(token);
5367 point.x=(double) (attribute == (int) 'L' ? x : point.x+x);
5368 point.y=(double) (attribute == (int) 'L' ? y : point.y+y);
5369 TracePoint(q,point);
5371 } while (IsPoint(p) != MagickFalse);
5377 if (q != primitive_info)
5379 primitive_info->coordinates=(size_t) (q-primitive_info);
5380 number_coordinates+=primitive_info->coordinates;
5386 GetMagickToken(p,&p,token);
5388 GetMagickToken(p,&p,token);
5389 x=StringToDouble(token);
5390 GetMagickToken(p,&p,token);
5392 GetMagickToken(p,&p,token);
5393 y=StringToDouble(token);
5394 point.x=(double) (attribute == (int) 'M' ? x : point.x+x);
5395 point.y=(double) (attribute == (int) 'M' ? y : point.y+y);
5399 TracePoint(q,point);
5401 if ((i != 0) && (attribute == (int) 'M'))
5403 TracePoint(q,point);
5406 } while (IsPoint(p) != MagickFalse);
5413 Compute bezier points.
5418 for (i=1; i < 3; i++)
5420 GetMagickToken(p,&p,token);
5422 GetMagickToken(p,&p,token);
5423 x=StringToDouble(token);
5424 GetMagickToken(p,&p,token);
5426 GetMagickToken(p,&p,token);
5427 y=StringToDouble(token);
5430 end.x=(double) (attribute == (int) 'Q' ? x : point.x+x);
5431 end.y=(double) (attribute == (int) 'Q' ? y : point.y+y);
5434 for (i=0; i < 3; i++)
5435 (q+i)->point=points[i];
5439 } while (IsPoint(p) != MagickFalse);
5446 Compute bezier points.
5450 points[0]=points[3];
5451 points[1].x=2.0*points[3].x-points[2].x;
5452 points[1].y=2.0*points[3].y-points[2].y;
5453 for (i=2; i < 4; i++)
5455 GetMagickToken(p,&p,token);
5457 GetMagickToken(p,&p,token);
5458 x=StringToDouble(token);
5459 GetMagickToken(p,&p,token);
5461 GetMagickToken(p,&p,token);
5462 y=StringToDouble(token);
5465 end.x=(double) (attribute == (int) 'S' ? x : point.x+x);
5466 end.y=(double) (attribute == (int) 'S' ? y : point.y+y);
5469 if (strchr("CcSs",last_attribute) == (char *) NULL)
5471 points[0]=points[2];
5472 points[1]=points[3];
5474 for (i=0; i < 4; i++)
5475 (q+i)->point=points[i];
5479 } while (IsPoint(p) != MagickFalse);
5486 Compute bezier points.
5490 points[0]=points[2];
5491 points[1].x=2.0*points[2].x-points[1].x;
5492 points[1].y=2.0*points[2].y-points[1].y;
5493 for (i=2; i < 3; i++)
5495 GetMagickToken(p,&p,token);
5497 GetMagickToken(p,&p,token);
5498 x=StringToDouble(token);
5499 GetMagickToken(p,&p,token);
5501 GetMagickToken(p,&p,token);
5502 y=StringToDouble(token);
5503 end.x=(double) (attribute == (int) 'T' ? x : point.x+x);
5504 end.y=(double) (attribute == (int) 'T' ? y : point.y+y);
5507 if (strchr("QqTt",last_attribute) == (char *) NULL)
5509 points[0]=points[2];
5510 points[1]=points[3];
5512 for (i=0; i < 3; i++)
5513 (q+i)->point=points[i];
5517 } while (IsPoint(p) != MagickFalse);
5525 GetMagickToken(p,&p,token);
5527 GetMagickToken(p,&p,token);
5528 y=StringToDouble(token);
5529 point.y=(double) (attribute == (int) 'V' ? y : point.y+y);
5530 TracePoint(q,point);
5532 } while (IsPoint(p) != MagickFalse);
5539 TracePoint(q,point);
5541 primitive_info->coordinates=(size_t) (q-primitive_info);
5542 number_coordinates+=primitive_info->coordinates;
5549 if (isalpha((int) ((unsigned char) attribute)) != 0)
5550 (void) fprintf(stderr,"attribute not recognized: %c\n",attribute);
5555 primitive_info->coordinates=(size_t) (q-primitive_info);
5556 number_coordinates+=primitive_info->coordinates;
5557 for (i=0; i < (ssize_t) number_coordinates; i++)
5560 q->primitive=primitive_type;
5562 q->method=FillToBorderMethod;
5565 return(number_coordinates);
5568 static void TraceRectangle(PrimitiveInfo *primitive_info,const PointInfo start,
5569 const PointInfo end)
5574 register PrimitiveInfo
5581 TracePoint(p,start);
5585 TracePoint(p,point);
5591 TracePoint(p,point);
5593 TracePoint(p,start);
5595 primitive_info->coordinates=(size_t) (p-primitive_info);
5596 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5598 p->primitive=primitive_info->primitive;
5603 static void TraceRoundRectangle(PrimitiveInfo *primitive_info,
5604 const PointInfo start,const PointInfo end,PointInfo arc)
5611 register PrimitiveInfo
5618 offset.x=fabs(end.x-start.x);
5619 offset.y=fabs(end.y-start.y);
5620 if (arc.x > (0.5*offset.x))
5622 if (arc.y > (0.5*offset.y))
5624 point.x=start.x+offset.x-arc.x;
5625 point.y=start.y+arc.y;
5628 TraceEllipse(p,point,arc,degrees);
5630 point.x=start.x+offset.x-arc.x;
5631 point.y=start.y+offset.y-arc.y;
5634 TraceEllipse(p,point,arc,degrees);
5636 point.x=start.x+arc.x;
5637 point.y=start.y+offset.y-arc.y;
5640 TraceEllipse(p,point,arc,degrees);
5642 point.x=start.x+arc.x;
5643 point.y=start.y+arc.y;
5646 TraceEllipse(p,point,arc,degrees);
5648 TracePoint(p,primitive_info->point);
5650 primitive_info->coordinates=(size_t) (p-primitive_info);
5651 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5653 p->primitive=primitive_info->primitive;
5658 static void TraceSquareLinecap(PrimitiveInfo *primitive_info,
5659 const size_t number_vertices,const MagickRealType offset)
5664 register MagickRealType
5676 for (i=1; i < (ssize_t) number_vertices; i++)
5678 dx=primitive_info[0].point.x-primitive_info[i].point.x;
5679 dy=primitive_info[0].point.y-primitive_info[i].point.y;
5680 if ((fabs((double) dx) >= MagickEpsilon) ||
5681 (fabs((double) dy) >= MagickEpsilon))
5684 if (i == (ssize_t) number_vertices)
5685 i=(ssize_t) number_vertices-1L;
5686 distance=hypot((double) dx,(double) dy);
5687 primitive_info[0].point.x=(double) (primitive_info[i].point.x+
5688 dx*(distance+offset)/distance);
5689 primitive_info[0].point.y=(double) (primitive_info[i].point.y+
5690 dy*(distance+offset)/distance);
5691 for (j=(ssize_t) number_vertices-2; j >= 0; j--)
5693 dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x;
5694 dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y;
5695 if ((fabs((double) dx) >= MagickEpsilon) ||
5696 (fabs((double) dy) >= MagickEpsilon))
5699 distance=hypot((double) dx,(double) dy);
5700 primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+
5701 dx*(distance+offset)/distance);
5702 primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+
5703 dy*(distance+offset)/distance);
5706 static PrimitiveInfo *TraceStrokePolygon(const DrawInfo *draw_info,
5707 const PrimitiveInfo *primitive_info)
5709 typedef struct _LineSegment
5761 number_vertices=primitive_info->coordinates;
5762 max_strokes=2*number_vertices+6*BezierQuantum+360;
5763 path_p=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes,
5765 path_q=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes,
5767 polygon_primitive=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
5768 number_vertices+2UL,sizeof(*polygon_primitive));
5769 if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL) ||
5770 (polygon_primitive == (PrimitiveInfo *) NULL))
5771 return((PrimitiveInfo *) NULL);
5772 (void) CopyMagickMemory(polygon_primitive,primitive_info,(size_t)
5773 number_vertices*sizeof(*polygon_primitive));
5775 (primitive_info[number_vertices-1].point.x == primitive_info[0].point.x) &&
5776 (primitive_info[number_vertices-1].point.y == primitive_info[0].point.y) ?
5777 MagickTrue : MagickFalse;
5778 if ((draw_info->linejoin == RoundJoin) ||
5779 ((draw_info->linejoin == MiterJoin) && (closed_path != MagickFalse)))
5781 polygon_primitive[number_vertices]=primitive_info[1];
5784 polygon_primitive[number_vertices].primitive=UndefinedPrimitive;
5786 Compute the slope for the first line segment, p.
5790 for (n=1; n < (ssize_t) number_vertices; n++)
5792 dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x;
5793 dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y;
5794 if ((fabs(dx.p) >= MagickEpsilon) || (fabs(dy.p) >= MagickEpsilon))
5797 if (n == (ssize_t) number_vertices)
5798 n=(ssize_t) number_vertices-1L;
5800 inverse_slope.p=0.0;
5801 if (fabs(dx.p) <= MagickEpsilon)
5804 slope.p=dy.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5806 slope.p=dy.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5809 if (fabs(dy.p) <= MagickEpsilon)
5812 inverse_slope.p=dx.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5814 inverse_slope.p=dx.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5819 inverse_slope.p=(-1.0/slope.p);
5821 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5822 miterlimit=(MagickRealType) (draw_info->miterlimit*draw_info->miterlimit*
5824 if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse))
5825 TraceSquareLinecap(polygon_primitive,number_vertices,mid);
5826 offset.x=sqrt((double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0)));
5827 offset.y=(double) (offset.x*inverse_slope.p);
5828 if ((dy.p*offset.x-dx.p*offset.y) > 0.0)
5830 box_p[0].x=polygon_primitive[0].point.x-offset.x;
5831 box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p;
5832 box_p[1].x=polygon_primitive[n].point.x-offset.x;
5833 box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p;
5834 box_q[0].x=polygon_primitive[0].point.x+offset.x;
5835 box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p;
5836 box_q[1].x=polygon_primitive[n].point.x+offset.x;
5837 box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p;
5841 box_p[0].x=polygon_primitive[0].point.x+offset.x;
5842 box_p[0].y=polygon_primitive[0].point.y+offset.y;
5843 box_p[1].x=polygon_primitive[n].point.x+offset.x;
5844 box_p[1].y=polygon_primitive[n].point.y+offset.y;
5845 box_q[0].x=polygon_primitive[0].point.x-offset.x;
5846 box_q[0].y=polygon_primitive[0].point.y-offset.y;
5847 box_q[1].x=polygon_primitive[n].point.x-offset.x;
5848 box_q[1].y=polygon_primitive[n].point.y-offset.y;
5851 Create strokes for the line join attribute: bevel, miter, round.
5855 path_q[p++]=box_q[0];
5856 path_p[q++]=box_p[0];
5857 for (i=(ssize_t) n+1; i < (ssize_t) number_vertices; i++)
5860 Compute the slope for this line segment, q.
5862 dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x;
5863 dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y;
5864 dot_product=dx.q*dx.q+dy.q*dy.q;
5865 if (dot_product < 0.25)
5868 inverse_slope.q=0.0;
5869 if (fabs(dx.q) < MagickEpsilon)
5872 slope.q=dy.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5874 slope.q=dy.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5877 if (fabs(dy.q) <= MagickEpsilon)
5880 inverse_slope.q=dx.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5882 inverse_slope.q=dx.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5887 inverse_slope.q=(-1.0/slope.q);
5889 offset.x=sqrt((double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0)));
5890 offset.y=(double) (offset.x*inverse_slope.q);
5891 dot_product=dy.q*offset.x-dx.q*offset.y;
5892 if (dot_product > 0.0)
5894 box_p[2].x=polygon_primitive[n].point.x-offset.x;
5895 box_p[2].y=polygon_primitive[n].point.y-offset.y;
5896 box_p[3].x=polygon_primitive[i].point.x-offset.x;
5897 box_p[3].y=polygon_primitive[i].point.y-offset.y;
5898 box_q[2].x=polygon_primitive[n].point.x+offset.x;
5899 box_q[2].y=polygon_primitive[n].point.y+offset.y;
5900 box_q[3].x=polygon_primitive[i].point.x+offset.x;
5901 box_q[3].y=polygon_primitive[i].point.y+offset.y;
5905 box_p[2].x=polygon_primitive[n].point.x+offset.x;
5906 box_p[2].y=polygon_primitive[n].point.y+offset.y;
5907 box_p[3].x=polygon_primitive[i].point.x+offset.x;
5908 box_p[3].y=polygon_primitive[i].point.y+offset.y;
5909 box_q[2].x=polygon_primitive[n].point.x-offset.x;
5910 box_q[2].y=polygon_primitive[n].point.y-offset.y;
5911 box_q[3].x=polygon_primitive[i].point.x-offset.x;
5912 box_q[3].y=polygon_primitive[i].point.y-offset.y;
5914 if (fabs((double) (slope.p-slope.q)) <= MagickEpsilon)
5921 box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+
5922 box_p[3].y)/(slope.p-slope.q));
5923 box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y);
5924 box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+
5925 box_q[3].y)/(slope.p-slope.q));
5926 box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y);
5928 if (q >= (ssize_t) (max_strokes-6*BezierQuantum-360))
5930 max_strokes+=6*BezierQuantum+360;
5931 path_p=(PointInfo *) ResizeQuantumMemory(path_p,(size_t) max_strokes,
5933 path_q=(PointInfo *) ResizeQuantumMemory(path_q,(size_t) max_strokes,
5935 if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL))
5937 polygon_primitive=(PrimitiveInfo *)
5938 RelinquishMagickMemory(polygon_primitive);
5939 return((PrimitiveInfo *) NULL);
5942 dot_product=dx.q*dy.p-dx.p*dy.q;
5943 if (dot_product <= 0.0)
5944 switch (draw_info->linejoin)
5948 path_q[q++]=box_q[1];
5949 path_q[q++]=box_q[2];
5950 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5951 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5952 if (dot_product <= miterlimit)
5953 path_p[p++]=box_p[4];
5956 path_p[p++]=box_p[1];
5957 path_p[p++]=box_p[2];
5963 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5964 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5965 if (dot_product <= miterlimit)
5967 path_q[q++]=box_q[4];
5968 path_p[p++]=box_p[4];
5972 path_q[q++]=box_q[1];
5973 path_q[q++]=box_q[2];
5974 path_p[p++]=box_p[1];
5975 path_p[p++]=box_p[2];
5981 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5982 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5983 if (dot_product <= miterlimit)
5984 path_p[p++]=box_p[4];
5987 path_p[p++]=box_p[1];
5988 path_p[p++]=box_p[2];
5990 center=polygon_primitive[n].point;
5991 theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x);
5992 theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x);
5993 if (theta.q < theta.p)
5994 theta.q+=(MagickRealType) (2.0*MagickPI);
5995 arc_segments=(size_t) ceil((double) ((theta.q-theta.p)/
5996 (2.0*sqrt((double) (1.0/mid)))));
5997 path_q[q].x=box_q[1].x;
5998 path_q[q].y=box_q[1].y;
6000 for (j=1; j < (ssize_t) arc_segments; j++)
6002 delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments);
6003 path_q[q].x=(double) (center.x+mid*cos(fmod((double)
6004 (theta.p+delta_theta),DegreesToRadians(360.0))));
6005 path_q[q].y=(double) (center.y+mid*sin(fmod((double)
6006 (theta.p+delta_theta),DegreesToRadians(360.0))));
6009 path_q[q++]=box_q[2];
6016 switch (draw_info->linejoin)
6020 path_p[p++]=box_p[1];
6021 path_p[p++]=box_p[2];
6022 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6023 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6024 if (dot_product <= miterlimit)
6025 path_q[q++]=box_q[4];
6028 path_q[q++]=box_q[1];
6029 path_q[q++]=box_q[2];
6035 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6036 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6037 if (dot_product <= miterlimit)
6039 path_q[q++]=box_q[4];
6040 path_p[p++]=box_p[4];
6044 path_q[q++]=box_q[1];
6045 path_q[q++]=box_q[2];
6046 path_p[p++]=box_p[1];
6047 path_p[p++]=box_p[2];
6053 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6054 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6055 if (dot_product <= miterlimit)
6056 path_q[q++]=box_q[4];
6059 path_q[q++]=box_q[1];
6060 path_q[q++]=box_q[2];
6062 center=polygon_primitive[n].point;
6063 theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x);
6064 theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x);
6065 if (theta.p < theta.q)
6066 theta.p+=(MagickRealType) (2.0*MagickPI);
6067 arc_segments=(size_t) ceil((double) ((theta.p-theta.q)/
6068 (2.0*sqrt((double) (1.0/mid)))));
6069 path_p[p++]=box_p[1];
6070 for (j=1; j < (ssize_t) arc_segments; j++)
6072 delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments);
6073 path_p[p].x=(double) (center.x+mid*cos(fmod((double)
6074 (theta.p+delta_theta),DegreesToRadians(360.0))));
6075 path_p[p].y=(double) (center.y+mid*sin(fmod((double)
6076 (theta.p+delta_theta),DegreesToRadians(360.0))));
6079 path_p[p++]=box_p[2];
6086 inverse_slope.p=inverse_slope.q;
6095 path_p[p++]=box_p[1];
6096 path_q[q++]=box_q[1];
6098 Trace stroked polygon.
6100 stroke_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
6101 (p+q+2UL*closed_path+2UL),sizeof(*stroke_polygon));
6102 if (stroke_polygon != (PrimitiveInfo *) NULL)
6104 for (i=0; i < (ssize_t) p; i++)
6106 stroke_polygon[i]=polygon_primitive[0];
6107 stroke_polygon[i].point=path_p[i];
6109 if (closed_path != MagickFalse)
6111 stroke_polygon[i]=polygon_primitive[0];
6112 stroke_polygon[i].point=stroke_polygon[0].point;
6115 for ( ; i < (ssize_t) (p+q+closed_path); i++)
6117 stroke_polygon[i]=polygon_primitive[0];
6118 stroke_polygon[i].point=path_q[p+q+closed_path-(i+1)];
6120 if (closed_path != MagickFalse)
6122 stroke_polygon[i]=polygon_primitive[0];
6123 stroke_polygon[i].point=stroke_polygon[p+closed_path].point;
6126 stroke_polygon[i]=polygon_primitive[0];
6127 stroke_polygon[i].point=stroke_polygon[0].point;
6129 stroke_polygon[i].primitive=UndefinedPrimitive;
6130 stroke_polygon[0].coordinates=(size_t) (p+q+2*closed_path+1);
6132 path_p=(PointInfo *) RelinquishMagickMemory(path_p);
6133 path_q=(PointInfo *) RelinquishMagickMemory(path_q);
6134 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive);
6135 return(stroke_polygon);