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 *) AcquireMagickMemory(sizeof(*draw_info));
201 if (draw_info == (DrawInfo *) NULL)
202 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
203 GetDrawInfo((ImageInfo *) NULL,draw_info);
208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212 % C l o n e D r a w I n f o %
216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 % CloneDrawInfo() makes a copy of the given draw info structure. If NULL
219 % is specified, a new image info structure is created initialized to
222 % The format of the CloneDrawInfo method is:
224 % DrawInfo *CloneDrawInfo(const ImageInfo *image_info,
225 % const DrawInfo *draw_info)
227 % A description of each parameter follows:
229 % o image_info: the image info.
231 % o draw_info: the draw info.
234 MagickExport DrawInfo *CloneDrawInfo(const ImageInfo *image_info,
235 const DrawInfo *draw_info)
240 clone_info=(DrawInfo *) AcquireMagickMemory(sizeof(*clone_info));
241 if (clone_info == (DrawInfo *) NULL)
242 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
243 GetDrawInfo(image_info,clone_info);
244 if (draw_info == (DrawInfo *) NULL)
246 if (clone_info->primitive != (char *) NULL)
247 (void) CloneString(&clone_info->primitive,draw_info->primitive);
248 if (draw_info->geometry != (char *) NULL)
249 (void) CloneString(&clone_info->geometry,draw_info->geometry);
250 clone_info->viewbox=draw_info->viewbox;
251 clone_info->affine=draw_info->affine;
252 clone_info->gravity=draw_info->gravity;
253 clone_info->fill=draw_info->fill;
254 clone_info->stroke=draw_info->stroke;
255 clone_info->stroke_width=draw_info->stroke_width;
256 if (draw_info->fill_pattern != (Image *) NULL)
257 clone_info->fill_pattern=CloneImage(draw_info->fill_pattern,0,0,MagickTrue,
258 &draw_info->fill_pattern->exception);
260 if (draw_info->tile != (Image *) NULL)
261 clone_info->fill_pattern=CloneImage(draw_info->tile,0,0,MagickTrue,
262 &draw_info->tile->exception);
263 clone_info->tile=NewImageList(); /* tile is deprecated */
264 if (draw_info->stroke_pattern != (Image *) NULL)
265 clone_info->stroke_pattern=CloneImage(draw_info->stroke_pattern,0,0,
266 MagickTrue,&draw_info->stroke_pattern->exception);
267 clone_info->stroke_antialias=draw_info->stroke_antialias;
268 clone_info->text_antialias=draw_info->text_antialias;
269 clone_info->fill_rule=draw_info->fill_rule;
270 clone_info->linecap=draw_info->linecap;
271 clone_info->linejoin=draw_info->linejoin;
272 clone_info->miterlimit=draw_info->miterlimit;
273 clone_info->dash_offset=draw_info->dash_offset;
274 clone_info->decorate=draw_info->decorate;
275 clone_info->compose=draw_info->compose;
276 if (draw_info->text != (char *) NULL)
277 (void) CloneString(&clone_info->text,draw_info->text);
278 if (draw_info->font != (char *) NULL)
279 (void) CloneString(&clone_info->font,draw_info->font);
280 if (draw_info->metrics != (char *) NULL)
281 (void) CloneString(&clone_info->metrics,draw_info->metrics);
282 if (draw_info->family != (char *) NULL)
283 (void) CloneString(&clone_info->family,draw_info->family);
284 clone_info->style=draw_info->style;
285 clone_info->stretch=draw_info->stretch;
286 clone_info->weight=draw_info->weight;
287 if (draw_info->encoding != (char *) NULL)
288 (void) CloneString(&clone_info->encoding,draw_info->encoding);
289 clone_info->pointsize=draw_info->pointsize;
290 clone_info->kerning=draw_info->kerning;
291 clone_info->interline_spacing=draw_info->interline_spacing;
292 clone_info->interword_spacing=draw_info->interword_spacing;
293 clone_info->direction=draw_info->direction;
294 if (draw_info->density != (char *) NULL)
295 (void) CloneString(&clone_info->density,draw_info->density);
296 clone_info->align=draw_info->align;
297 clone_info->undercolor=draw_info->undercolor;
298 clone_info->border_color=draw_info->border_color;
299 if (draw_info->server_name != (char *) NULL)
300 (void) CloneString(&clone_info->server_name,draw_info->server_name);
301 if (draw_info->dash_pattern != (double *) NULL)
306 for (x=0; draw_info->dash_pattern[x] != 0.0; x++) ;
307 clone_info->dash_pattern=(double *) AcquireQuantumMemory((size_t) x+1UL,
308 sizeof(*clone_info->dash_pattern));
309 if (clone_info->dash_pattern == (double *) NULL)
310 ThrowFatalException(ResourceLimitFatalError,
311 "UnableToAllocateDashPattern");
312 (void) CopyMagickMemory(clone_info->dash_pattern,draw_info->dash_pattern,
313 (size_t) (x+1)*sizeof(*clone_info->dash_pattern));
315 clone_info->gradient=draw_info->gradient;
316 if (draw_info->gradient.stops != (StopInfo *) NULL)
321 number_stops=clone_info->gradient.number_stops;
322 clone_info->gradient.stops=(StopInfo *) AcquireQuantumMemory((size_t)
323 number_stops,sizeof(*clone_info->gradient.stops));
324 if (clone_info->gradient.stops == (StopInfo *) NULL)
325 ThrowFatalException(ResourceLimitFatalError,
326 "UnableToAllocateDashPattern");
327 (void) CopyMagickMemory(clone_info->gradient.stops,
328 draw_info->gradient.stops,(size_t) number_stops*
329 sizeof(*clone_info->gradient.stops));
331 if (draw_info->clip_mask != (char *) NULL)
332 (void) CloneString(&clone_info->clip_mask,draw_info->clip_mask);
333 clone_info->bounds=draw_info->bounds;
334 clone_info->clip_units=draw_info->clip_units;
335 clone_info->render=draw_info->render;
336 clone_info->opacity=draw_info->opacity;
337 clone_info->element_reference=draw_info->element_reference;
338 clone_info->debug=IsEventLogging();
343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
347 + C o n v e r t P a t h T o P o l y g o n %
351 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353 % ConvertPathToPolygon() converts a path to the more efficient sorted
356 % The format of the ConvertPathToPolygon method is:
358 % PolygonInfo *ConvertPathToPolygon(const DrawInfo *draw_info,
359 % const PathInfo *path_info)
361 % A description of each parameter follows:
363 % o Method ConvertPathToPolygon returns the path in a more efficient sorted
364 % rendering form of type PolygonInfo.
366 % o draw_info: Specifies a pointer to an DrawInfo structure.
368 % o path_info: Specifies a pointer to an PathInfo structure.
373 #if defined(__cplusplus) || defined(c_plusplus)
377 static int CompareEdges(const void *x,const void *y)
379 register const EdgeInfo
386 p=(const EdgeInfo *) x;
387 q=(const EdgeInfo *) y;
388 if ((p->points[0].y-MagickEpsilon) > q->points[0].y)
390 if ((p->points[0].y+MagickEpsilon) < q->points[0].y)
392 if ((p->points[0].x-MagickEpsilon) > q->points[0].x)
394 if ((p->points[0].x+MagickEpsilon) < q->points[0].x)
396 if (((p->points[1].x-p->points[0].x)*(q->points[1].y-q->points[0].y)-
397 (p->points[1].y-p->points[0].y)*(q->points[1].x-q->points[0].x)) > 0.0)
402 #if defined(__cplusplus) || defined(c_plusplus)
406 static void LogPolygonInfo(const PolygonInfo *polygon_info)
415 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin active-edge");
416 p=polygon_info->edges;
417 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
419 (void) LogMagickEvent(DrawEvent,GetMagickModule()," edge %.20g:",
421 (void) LogMagickEvent(DrawEvent,GetMagickModule()," direction: %s",
422 p->direction != MagickFalse ? "down" : "up");
423 (void) LogMagickEvent(DrawEvent,GetMagickModule()," ghostline: %s",
424 p->ghostline != MagickFalse ? "transparent" : "opaque");
425 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
426 " bounds: %g,%g - %g,%g",p->bounds.x1,p->bounds.y1,
427 p->bounds.x2,p->bounds.y2);
428 for (j=0; j < (ssize_t) p->number_points; j++)
429 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %g,%g",
430 p->points[j].x,p->points[j].y);
433 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end active-edge");
436 static void ReversePoints(PointInfo *points,const size_t number_points)
444 for (i=0; i < (ssize_t) (number_points >> 1); i++)
447 points[i]=points[number_points-(i+1)];
448 points[number_points-(i+1)]=point;
452 static PolygonInfo *ConvertPathToPolygon(
453 const DrawInfo *magick_unused(draw_info),const PathInfo *path_info)
482 Convert a path to the more efficient sorted rendering form.
484 polygon_info=(PolygonInfo *) AcquireMagickMemory(sizeof(*polygon_info));
485 if (polygon_info == (PolygonInfo *) NULL)
486 return((PolygonInfo *) NULL);
488 polygon_info->edges=(EdgeInfo *) AcquireQuantumMemory((size_t) number_edges,
489 sizeof(*polygon_info->edges));
490 if (polygon_info->edges == (EdgeInfo *) NULL)
491 return((PolygonInfo *) NULL);
494 ghostline=MagickFalse;
497 points=(PointInfo *) NULL;
498 (void) ResetMagickMemory(&point,0,sizeof(point));
499 (void) ResetMagickMemory(&bounds,0,sizeof(bounds));
500 for (i=0; path_info[i].code != EndCode; i++)
502 if ((path_info[i].code == MoveToCode) || (path_info[i].code == OpenCode) ||
503 (path_info[i].code == GhostlineCode))
508 if ((points != (PointInfo *) NULL) && (n >= 2))
510 if (edge == number_edges)
513 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
514 polygon_info->edges,(size_t) number_edges,
515 sizeof(*polygon_info->edges));
516 if (polygon_info->edges == (EdgeInfo *) NULL)
517 return((PolygonInfo *) NULL);
519 polygon_info->edges[edge].number_points=(size_t) n;
520 polygon_info->edges[edge].scanline=(-1.0);
521 polygon_info->edges[edge].highwater=0;
522 polygon_info->edges[edge].ghostline=ghostline;
523 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
525 ReversePoints(points,(size_t) n);
526 polygon_info->edges[edge].points=points;
527 polygon_info->edges[edge].bounds=bounds;
528 polygon_info->edges[edge].bounds.y1=points[0].y;
529 polygon_info->edges[edge].bounds.y2=points[n-1].y;
530 points=(PointInfo *) NULL;
531 ghostline=MagickFalse;
534 if (points == (PointInfo *) NULL)
537 points=(PointInfo *) AcquireQuantumMemory((size_t) number_points,
539 if (points == (PointInfo *) NULL)
540 return((PolygonInfo *) NULL);
542 ghostline=path_info[i].code == GhostlineCode ? MagickTrue : MagickFalse;
543 point=path_info[i].point;
554 next_direction=((path_info[i].point.y > point.y) ||
555 ((path_info[i].point.y == point.y) &&
556 (path_info[i].point.x > point.x))) ? 1 : -1;
557 if ((direction != 0) && (direction != next_direction))
563 if (edge == number_edges)
566 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
567 polygon_info->edges,(size_t) number_edges,
568 sizeof(*polygon_info->edges));
569 if (polygon_info->edges == (EdgeInfo *) NULL)
570 return((PolygonInfo *) NULL);
572 polygon_info->edges[edge].number_points=(size_t) n;
573 polygon_info->edges[edge].scanline=(-1.0);
574 polygon_info->edges[edge].highwater=0;
575 polygon_info->edges[edge].ghostline=ghostline;
576 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
578 ReversePoints(points,(size_t) n);
579 polygon_info->edges[edge].points=points;
580 polygon_info->edges[edge].bounds=bounds;
581 polygon_info->edges[edge].bounds.y1=points[0].y;
582 polygon_info->edges[edge].bounds.y2=points[n-1].y;
584 points=(PointInfo *) AcquireQuantumMemory((size_t) number_points,
586 if (points == (PointInfo *) NULL)
587 return((PolygonInfo *) NULL);
589 ghostline=MagickFalse;
595 direction=next_direction;
596 if (points == (PointInfo *) NULL)
598 if (n == (ssize_t) number_points)
601 points=(PointInfo *) ResizeQuantumMemory(points,(size_t) number_points,
603 if (points == (PointInfo *) NULL)
604 return((PolygonInfo *) NULL);
606 point=path_info[i].point;
608 if (point.x < bounds.x1)
610 if (point.x > bounds.x2)
614 if (points != (PointInfo *) NULL)
617 points=(PointInfo *) RelinquishMagickMemory(points);
620 if (edge == number_edges)
623 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
624 polygon_info->edges,(size_t) number_edges,
625 sizeof(*polygon_info->edges));
626 if (polygon_info->edges == (EdgeInfo *) NULL)
627 return((PolygonInfo *) NULL);
629 polygon_info->edges[edge].number_points=(size_t) n;
630 polygon_info->edges[edge].scanline=(-1.0);
631 polygon_info->edges[edge].highwater=0;
632 polygon_info->edges[edge].ghostline=ghostline;
633 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
635 ReversePoints(points,(size_t) n);
636 polygon_info->edges[edge].points=points;
637 polygon_info->edges[edge].bounds=bounds;
638 polygon_info->edges[edge].bounds.y1=points[0].y;
639 polygon_info->edges[edge].bounds.y2=points[n-1].y;
640 ghostline=MagickFalse;
644 polygon_info->number_edges=edge;
645 qsort(polygon_info->edges,(size_t) polygon_info->number_edges,
646 sizeof(*polygon_info->edges),CompareEdges);
647 if (IsEventLogging() != MagickFalse)
648 LogPolygonInfo(polygon_info);
649 return(polygon_info);
653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
657 + C o n v e r t P r i m i t i v e T o P a t h %
661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
663 % ConvertPrimitiveToPath() converts a PrimitiveInfo structure into a vector
666 % The format of the ConvertPrimitiveToPath method is:
668 % PathInfo *ConvertPrimitiveToPath(const DrawInfo *draw_info,
669 % const PrimitiveInfo *primitive_info)
671 % A description of each parameter follows:
673 % o Method ConvertPrimitiveToPath returns a vector path structure of type
676 % o draw_info: a structure of type DrawInfo.
678 % o primitive_info: Specifies a pointer to an PrimitiveInfo structure.
683 static void LogPathInfo(const PathInfo *path_info)
685 register const PathInfo
688 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin vector-path");
689 for (p=path_info; p->code != EndCode; p++)
690 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
691 " %g,%g %s",p->point.x,p->point.y,p->code == GhostlineCode ?
692 "moveto ghostline" : p->code == OpenCode ? "moveto open" :
693 p->code == MoveToCode ? "moveto" : p->code == LineToCode ? "lineto" :
695 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end vector-path");
698 static PathInfo *ConvertPrimitiveToPath(
699 const DrawInfo *magick_unused(draw_info),const PrimitiveInfo *primitive_info)
720 Converts a PrimitiveInfo structure into a vector path structure.
722 switch (primitive_info->primitive)
729 return((PathInfo *) NULL);
733 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
734 path_info=(PathInfo *) AcquireQuantumMemory((size_t) (2UL*i+3UL),
736 if (path_info == (PathInfo *) NULL)
737 return((PathInfo *) NULL);
745 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
748 if (coordinates <= 0)
750 coordinates=(ssize_t) primitive_info[i].coordinates;
751 p=primitive_info[i].point;
757 Eliminate duplicate points.
759 if ((i == 0) || (fabs(q.x-primitive_info[i].point.x) > MagickEpsilon) ||
760 (fabs(q.y-primitive_info[i].point.y) > MagickEpsilon))
762 path_info[n].code=code;
763 path_info[n].point=primitive_info[i].point;
764 q=primitive_info[i].point;
769 if ((fabs(p.x-primitive_info[i].point.x) <= MagickEpsilon) &&
770 (fabs(p.y-primitive_info[i].point.y) <= MagickEpsilon))
773 Mark the p point as open if it does not match the q.
775 path_info[start].code=OpenCode;
776 path_info[n].code=GhostlineCode;
777 path_info[n].point=primitive_info[i].point;
779 path_info[n].code=LineToCode;
780 path_info[n].point=p;
783 path_info[n].code=EndCode;
784 path_info[n].point.x=0.0;
785 path_info[n].point.y=0.0;
786 if (IsEventLogging() != MagickFalse)
787 LogPathInfo(path_info);
792 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
796 % D e s t r o y D r a w I n f o %
800 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
802 % DestroyDrawInfo() deallocates memory associated with an DrawInfo
805 % The format of the DestroyDrawInfo method is:
807 % DrawInfo *DestroyDrawInfo(DrawInfo *draw_info)
809 % A description of each parameter follows:
811 % o draw_info: the draw info.
814 MagickExport DrawInfo *DestroyDrawInfo(DrawInfo *draw_info)
816 if (draw_info->debug != MagickFalse)
817 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
818 assert(draw_info != (DrawInfo *) NULL);
819 assert(draw_info->signature == MagickSignature);
820 if (draw_info->primitive != (char *) NULL)
821 draw_info->primitive=DestroyString(draw_info->primitive);
822 if (draw_info->text != (char *) NULL)
823 draw_info->text=DestroyString(draw_info->text);
824 if (draw_info->geometry != (char *) NULL)
825 draw_info->geometry=DestroyString(draw_info->geometry);
826 if (draw_info->tile != (Image *) NULL)
827 draw_info->tile=DestroyImage(draw_info->tile);
828 if (draw_info->fill_pattern != (Image *) NULL)
829 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
830 if (draw_info->stroke_pattern != (Image *) NULL)
831 draw_info->stroke_pattern=DestroyImage(draw_info->stroke_pattern);
832 if (draw_info->font != (char *) NULL)
833 draw_info->font=DestroyString(draw_info->font);
834 if (draw_info->metrics != (char *) NULL)
835 draw_info->metrics=DestroyString(draw_info->metrics);
836 if (draw_info->family != (char *) NULL)
837 draw_info->family=DestroyString(draw_info->family);
838 if (draw_info->encoding != (char *) NULL)
839 draw_info->encoding=DestroyString(draw_info->encoding);
840 if (draw_info->density != (char *) NULL)
841 draw_info->density=DestroyString(draw_info->density);
842 if (draw_info->server_name != (char *) NULL)
843 draw_info->server_name=(char *)
844 RelinquishMagickMemory(draw_info->server_name);
845 if (draw_info->dash_pattern != (double *) NULL)
846 draw_info->dash_pattern=(double *) RelinquishMagickMemory(
847 draw_info->dash_pattern);
848 if (draw_info->gradient.stops != (StopInfo *) NULL)
849 draw_info->gradient.stops=(StopInfo *) RelinquishMagickMemory(
850 draw_info->gradient.stops);
851 if (draw_info->clip_mask != (char *) NULL)
852 draw_info->clip_mask=DestroyString(draw_info->clip_mask);
853 draw_info->signature=(~MagickSignature);
854 draw_info=(DrawInfo *) RelinquishMagickMemory(draw_info);
859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
863 + D e s t r o y E d g e %
867 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
869 % DestroyEdge() destroys the specified polygon edge.
871 % The format of the DestroyEdge method is:
873 % ssize_t DestroyEdge(PolygonInfo *polygon_info,const int edge)
875 % A description of each parameter follows:
877 % o polygon_info: Specifies a pointer to an PolygonInfo structure.
879 % o edge: the polygon edge number to destroy.
882 static size_t DestroyEdge(PolygonInfo *polygon_info,
885 assert(edge < polygon_info->number_edges);
886 polygon_info->edges[edge].points=(PointInfo *) RelinquishMagickMemory(
887 polygon_info->edges[edge].points);
888 polygon_info->number_edges--;
889 if (edge < polygon_info->number_edges)
890 (void) CopyMagickMemory(polygon_info->edges+edge,polygon_info->edges+edge+1,
891 (size_t) (polygon_info->number_edges-edge)*sizeof(*polygon_info->edges));
892 return(polygon_info->number_edges);
896 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
900 + D e s t r o y P o l y g o n I n f o %
904 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
906 % DestroyPolygonInfo() destroys the PolygonInfo data structure.
908 % The format of the DestroyPolygonInfo method is:
910 % PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info)
912 % A description of each parameter follows:
914 % o polygon_info: Specifies a pointer to an PolygonInfo structure.
917 static PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info)
922 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
923 polygon_info->edges[i].points=(PointInfo *)
924 RelinquishMagickMemory(polygon_info->edges[i].points);
925 polygon_info->edges=(EdgeInfo *) RelinquishMagickMemory(polygon_info->edges);
926 return((PolygonInfo *) RelinquishMagickMemory(polygon_info));
930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
934 % D r a w A f f i n e I m a g e %
938 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
940 % DrawAffineImage() composites the source over the destination image as
941 % dictated by the affine transform.
943 % The format of the DrawAffineImage method is:
945 % MagickBooleanType DrawAffineImage(Image *image,const Image *source,
946 % const AffineMatrix *affine)
948 % A description of each parameter follows:
950 % o image: the image.
952 % o source: the source image.
954 % o affine: the affine transform.
957 static SegmentInfo AffineEdge(const Image *image,const AffineMatrix *affine,
958 const double y,const SegmentInfo *edge)
971 Determine left and right edges.
973 inverse_edge.x1=edge->x1;
974 inverse_edge.y1=edge->y1;
975 inverse_edge.x2=edge->x2;
976 inverse_edge.y2=edge->y2;
977 z=affine->ry*y+affine->tx;
978 if (affine->sx > MagickEpsilon)
980 intercept=(-z/affine->sx);
981 x=intercept+MagickEpsilon;
982 if (x > inverse_edge.x1)
984 intercept=(-z+(double) image->columns)/affine->sx;
985 x=intercept-MagickEpsilon;
986 if (x < inverse_edge.x2)
990 if (affine->sx < -MagickEpsilon)
992 intercept=(-z+(double) image->columns)/affine->sx;
993 x=intercept+MagickEpsilon;
994 if (x > inverse_edge.x1)
996 intercept=(-z/affine->sx);
997 x=intercept-MagickEpsilon;
998 if (x < inverse_edge.x2)
1002 if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->columns))
1004 inverse_edge.x2=edge->x1;
1005 return(inverse_edge);
1008 Determine top and bottom edges.
1010 z=affine->sy*y+affine->ty;
1011 if (affine->rx > MagickEpsilon)
1013 intercept=(-z/affine->rx);
1014 x=intercept+MagickEpsilon;
1015 if (x > inverse_edge.x1)
1017 intercept=(-z+(double) image->rows)/affine->rx;
1018 x=intercept-MagickEpsilon;
1019 if (x < inverse_edge.x2)
1023 if (affine->rx < -MagickEpsilon)
1025 intercept=(-z+(double) image->rows)/affine->rx;
1026 x=intercept+MagickEpsilon;
1027 if (x > inverse_edge.x1)
1029 intercept=(-z/affine->rx);
1030 x=intercept-MagickEpsilon;
1031 if (x < inverse_edge.x2)
1035 if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->rows))
1037 inverse_edge.x2=edge->x2;
1038 return(inverse_edge);
1040 return(inverse_edge);
1043 static AffineMatrix InverseAffineMatrix(const AffineMatrix *affine)
1051 determinant=1.0/(affine->sx*affine->sy-affine->rx*affine->ry);
1052 inverse_affine.sx=determinant*affine->sy;
1053 inverse_affine.rx=determinant*(-affine->rx);
1054 inverse_affine.ry=determinant*(-affine->ry);
1055 inverse_affine.sy=determinant*affine->sx;
1056 inverse_affine.tx=(-affine->tx)*inverse_affine.sx-affine->ty*
1058 inverse_affine.ty=(-affine->tx)*inverse_affine.rx-affine->ty*
1060 return(inverse_affine);
1063 static inline ssize_t MagickAbsoluteValue(const ssize_t x)
1070 static inline double MagickMax(const double x,const double y)
1077 static inline double MagickMin(const double x,const double y)
1084 MagickExport MagickBooleanType DrawAffineImage(Image *image,
1085 const Image *source,const AffineMatrix *affine)
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++)
1181 id = GetOpenMPThreadId();
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 indexes=GetCacheViewAuthenticIndexQueue(image_view);
1217 for (x=(ssize_t) ceil(inverse_edge.x1-0.5); x <= (ssize_t) floor(inverse_edge.x2+0.5); x++)
1219 point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+
1221 point.y=(double) x*inverse_affine.rx+y*inverse_affine.sy+
1223 (void) ResamplePixelColor(resample_filter[id],point.x,point.y,&pixel);
1224 SetMagickPixelPacket(image,q,indexes+x_offset,&composite);
1225 MagickPixelCompositeOver(&pixel,pixel.opacity,&composite,
1226 composite.opacity,&composite);
1227 SetPixelPacket(image,&composite,q,indexes+x_offset);
1231 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1234 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
1235 source_view=DestroyCacheView(source_view);
1236 image_view=DestroyCacheView(image_view);
1241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1245 + D r a w B o u n d i n g R e c t a n g l e s %
1249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1251 % DrawBoundingRectangles() draws the bounding rectangles on the image. This
1252 % is only useful for developers debugging the rendering algorithm.
1254 % The format of the DrawBoundingRectangles method is:
1256 % void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info,
1257 % PolygonInfo *polygon_info)
1259 % A description of each parameter follows:
1261 % o image: the image.
1263 % o draw_info: the draw info.
1265 % o polygon_info: Specifies a pointer to a PolygonInfo structure.
1268 static void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info,
1269 const PolygonInfo *polygon_info)
1294 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1295 (void) QueryColorDatabase("#0000",&clone_info->fill,&image->exception);
1296 resolution.x=DefaultResolution;
1297 resolution.y=DefaultResolution;
1298 if (clone_info->density != (char *) NULL)
1306 flags=ParseGeometry(clone_info->density,&geometry_info);
1307 resolution.x=geometry_info.rho;
1308 resolution.y=geometry_info.sigma;
1309 if ((flags & SigmaValue) == MagickFalse)
1310 resolution.y=resolution.x;
1312 mid=(resolution.x/72.0)*ExpandAffine(&clone_info->affine)*
1313 clone_info->stroke_width/2.0;
1318 if (polygon_info != (PolygonInfo *) NULL)
1320 bounds=polygon_info->edges[0].bounds;
1321 for (i=1; i < (ssize_t) polygon_info->number_edges; i++)
1323 if (polygon_info->edges[i].bounds.x1 < (double) bounds.x1)
1324 bounds.x1=polygon_info->edges[i].bounds.x1;
1325 if (polygon_info->edges[i].bounds.y1 < (double) bounds.y1)
1326 bounds.y1=polygon_info->edges[i].bounds.y1;
1327 if (polygon_info->edges[i].bounds.x2 > (double) bounds.x2)
1328 bounds.x2=polygon_info->edges[i].bounds.x2;
1329 if (polygon_info->edges[i].bounds.y2 > (double) bounds.y2)
1330 bounds.y2=polygon_info->edges[i].bounds.y2;
1333 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double)
1334 image->columns ? (double) image->columns-1 : bounds.x1;
1336 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double)
1337 image->rows ? (double) image->rows-1 : bounds.y1;
1339 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double)
1340 image->columns ? (double) image->columns-1 : bounds.x2;
1342 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double)
1343 image->rows ? (double) image->rows-1 : bounds.y2;
1344 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
1346 if (polygon_info->edges[i].direction != 0)
1347 (void) QueryColorDatabase("red",&clone_info->stroke,
1350 (void) QueryColorDatabase("green",&clone_info->stroke,
1352 start.x=(double) (polygon_info->edges[i].bounds.x1-mid);
1353 start.y=(double) (polygon_info->edges[i].bounds.y1-mid);
1354 end.x=(double) (polygon_info->edges[i].bounds.x2+mid);
1355 end.y=(double) (polygon_info->edges[i].bounds.y2+mid);
1356 primitive_info[0].primitive=RectanglePrimitive;
1357 TraceRectangle(primitive_info,start,end);
1358 primitive_info[0].method=ReplaceMethod;
1359 coordinates=(ssize_t) primitive_info[0].coordinates;
1360 primitive_info[coordinates].primitive=UndefinedPrimitive;
1361 (void) DrawPrimitive(image,clone_info,primitive_info);
1364 (void) QueryColorDatabase("blue",&clone_info->stroke,&image->exception);
1365 start.x=(double) (bounds.x1-mid);
1366 start.y=(double) (bounds.y1-mid);
1367 end.x=(double) (bounds.x2+mid);
1368 end.y=(double) (bounds.y2+mid);
1369 primitive_info[0].primitive=RectanglePrimitive;
1370 TraceRectangle(primitive_info,start,end);
1371 primitive_info[0].method=ReplaceMethod;
1372 coordinates=(ssize_t) primitive_info[0].coordinates;
1373 primitive_info[coordinates].primitive=UndefinedPrimitive;
1374 (void) DrawPrimitive(image,clone_info,primitive_info);
1375 clone_info=DestroyDrawInfo(clone_info);
1379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1383 % D r a w C l i p P a t h %
1387 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1389 % DrawClipPath() draws the clip path on the image mask.
1391 % The format of the DrawClipPath method is:
1393 % MagickBooleanType DrawClipPath(Image *image,const DrawInfo *draw_info,
1396 % A description of each parameter follows:
1398 % o image: the image.
1400 % o draw_info: the draw info.
1402 % o name: the name of the clip path.
1405 MagickExport MagickBooleanType DrawClipPath(Image *image,
1406 const DrawInfo *draw_info,const char *name)
1409 clip_mask[MaxTextExtent];
1420 assert(image != (Image *) NULL);
1421 assert(image->signature == MagickSignature);
1422 if (image->debug != MagickFalse)
1423 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1424 assert(draw_info != (const DrawInfo *) NULL);
1425 (void) FormatMagickString(clip_mask,MaxTextExtent,"%s",name);
1426 value=GetImageArtifact(image,clip_mask);
1427 if (value == (const char *) NULL)
1428 return(MagickFalse);
1429 if (image->clip_mask == (Image *) NULL)
1434 clip_mask=CloneImage(image,image->columns,image->rows,MagickTrue,
1436 if (clip_mask == (Image *) NULL)
1437 return(MagickFalse);
1438 (void) SetImageClipMask(image,clip_mask);
1439 clip_mask=DestroyImage(clip_mask);
1441 (void) QueryColorDatabase("#00000000",&image->clip_mask->background_color,
1443 image->clip_mask->background_color.opacity=(Quantum) TransparentOpacity;
1444 (void) SetImageBackgroundColor(image->clip_mask);
1445 if (image->debug != MagickFalse)
1446 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"\nbegin clip-path %s",
1447 draw_info->clip_mask);
1448 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1449 (void) CloneString(&clone_info->primitive,value);
1450 (void) QueryColorDatabase("#ffffff",&clone_info->fill,&image->exception);
1451 clone_info->clip_mask=(char *) NULL;
1452 status=DrawImage(image->clip_mask,clone_info);
1453 status|=NegateImage(image->clip_mask,MagickFalse);
1454 clone_info=DestroyDrawInfo(clone_info);
1455 if (image->debug != MagickFalse)
1456 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end clip-path");
1457 return(status != 0 ? MagickTrue : MagickFalse);
1461 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1465 + D r a w D a s h P o l y g o n %
1469 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1471 % DrawDashPolygon() draws a dashed polygon (line, rectangle, ellipse) on the
1472 % image while respecting the dash offset and dash pattern attributes.
1474 % The format of the DrawDashPolygon method is:
1476 % MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info,
1477 % const PrimitiveInfo *primitive_info,Image *image)
1479 % A description of each parameter follows:
1481 % o draw_info: the draw info.
1483 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
1485 % o image: the image.
1489 static MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info,
1490 const PrimitiveInfo *primitive_info,Image *image)
1511 register MagickRealType
1522 assert(draw_info != (const DrawInfo *) NULL);
1523 if (image->debug != MagickFalse)
1524 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-dash");
1525 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1526 clone_info->miterlimit=0;
1527 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
1528 number_vertices=(size_t) i;
1529 dash_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
1530 (2UL*number_vertices+1UL),sizeof(*dash_polygon));
1531 if (dash_polygon == (PrimitiveInfo *) NULL)
1532 return(MagickFalse);
1533 dash_polygon[0]=primitive_info[0];
1534 scale=ExpandAffine(&draw_info->affine);
1535 length=scale*(draw_info->dash_pattern[0]-0.5);
1536 offset=draw_info->dash_offset != 0.0 ? scale*draw_info->dash_offset : 0.0;
1538 for (n=0; offset > 0.0; j=0)
1540 if (draw_info->dash_pattern[n] <= 0.0)
1542 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1543 if (offset > length)
1547 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1550 if (offset < length)
1562 for (i=1; i < (ssize_t) number_vertices; i++)
1564 dx=primitive_info[i].point.x-primitive_info[i-1].point.x;
1565 dy=primitive_info[i].point.y-primitive_info[i-1].point.y;
1566 maximum_length=hypot((double) dx,dy);
1570 if (draw_info->dash_pattern[n] == 0.0)
1572 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1574 for (total_length=0.0; (total_length+length) < maximum_length; )
1576 total_length+=length;
1577 if ((n & 0x01) != 0)
1579 dash_polygon[0]=primitive_info[0];
1580 dash_polygon[0].point.x=(double) (primitive_info[i-1].point.x+dx*
1581 total_length/maximum_length);
1582 dash_polygon[0].point.y=(double) (primitive_info[i-1].point.y+dy*
1583 total_length/maximum_length);
1588 if ((j+1) > (ssize_t) (2*number_vertices))
1590 dash_polygon[j]=primitive_info[i-1];
1591 dash_polygon[j].point.x=(double) (primitive_info[i-1].point.x+dx*
1592 total_length/maximum_length);
1593 dash_polygon[j].point.y=(double) (primitive_info[i-1].point.y+dy*
1594 total_length/maximum_length);
1595 dash_polygon[j].coordinates=1;
1597 dash_polygon[0].coordinates=(size_t) j;
1598 dash_polygon[j].primitive=UndefinedPrimitive;
1599 status|=DrawStrokePolygon(image,clone_info,dash_polygon);
1602 if (draw_info->dash_pattern[n] == 0.0)
1604 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1606 length-=(maximum_length-total_length);
1607 if ((n & 0x01) != 0)
1609 dash_polygon[j]=primitive_info[i];
1610 dash_polygon[j].coordinates=1;
1613 if ((total_length < maximum_length) && ((n & 0x01) == 0) && (j > 1))
1615 dash_polygon[j]=primitive_info[i-1];
1616 dash_polygon[j].point.x+=MagickEpsilon;
1617 dash_polygon[j].point.y+=MagickEpsilon;
1618 dash_polygon[j].coordinates=1;
1620 dash_polygon[0].coordinates=(size_t) j;
1621 dash_polygon[j].primitive=UndefinedPrimitive;
1622 status|=DrawStrokePolygon(image,clone_info,dash_polygon);
1624 dash_polygon=(PrimitiveInfo *) RelinquishMagickMemory(dash_polygon);
1625 clone_info=DestroyDrawInfo(clone_info);
1626 if (image->debug != MagickFalse)
1627 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-dash");
1628 return(status != 0 ? MagickTrue : MagickFalse);
1632 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1636 % D r a w I m a g e %
1640 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1642 % DrawImage() draws a graphic primitive on your image. The primitive
1643 % may be represented as a string or filename. Precede the filename with an
1644 % "at" sign (@) and the contents of the file are drawn on the image. You
1645 % can affect how text is drawn by setting one or more members of the draw
1648 % The format of the DrawImage method is:
1650 % MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info)
1652 % A description of each parameter follows:
1654 % o image: the image.
1656 % o draw_info: the draw info.
1660 static inline MagickBooleanType IsPoint(const char *point)
1668 value=strtod(point,&p);
1669 return((value == 0.0) && (p == point) ? MagickFalse : MagickTrue);
1672 static inline void TracePoint(PrimitiveInfo *primitive_info,
1673 const PointInfo point)
1675 primitive_info->coordinates=1;
1676 primitive_info->point=point;
1679 MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info)
1681 #define RenderImageTag "Render/Image"
1688 key[2*MaxTextExtent],
1689 keyword[MaxTextExtent],
1690 geometry[MaxTextExtent],
1691 name[MaxTextExtent],
1692 pattern[MaxTextExtent],
1743 Ensure the annotation info is valid.
1745 assert(image != (Image *) NULL);
1746 assert(image->signature == MagickSignature);
1747 if (image->debug != MagickFalse)
1748 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1749 assert(draw_info != (DrawInfo *) NULL);
1750 assert(draw_info->signature == MagickSignature);
1751 if (image->debug != MagickFalse)
1752 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1753 if ((draw_info->primitive == (char *) NULL) ||
1754 (*draw_info->primitive == '\0'))
1755 return(MagickFalse);
1756 if (image->debug != MagickFalse)
1757 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"begin draw-image");
1758 if (*draw_info->primitive != '@')
1759 primitive=AcquireString(draw_info->primitive);
1761 primitive=FileToString(draw_info->primitive+1,~0,&image->exception);
1762 if (primitive == (char *) NULL)
1763 return(MagickFalse);
1764 primitive_extent=(MagickRealType) strlen(primitive);
1765 (void) SetImageArtifact(image,"MVG",primitive);
1768 Allocate primitive info memory.
1770 graphic_context=(DrawInfo **) AcquireMagickMemory(
1771 sizeof(*graphic_context));
1772 if (graphic_context == (DrawInfo **) NULL)
1774 primitive=DestroyString(primitive);
1775 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1779 primitive_info=(PrimitiveInfo *) AcquireQuantumMemory((size_t) number_points,
1780 sizeof(*primitive_info));
1781 if (primitive_info == (PrimitiveInfo *) NULL)
1783 primitive=DestroyString(primitive);
1784 for ( ; n >= 0; n--)
1785 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
1786 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
1787 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1790 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1791 graphic_context[n]->viewbox=image->page;
1792 if ((image->page.width == 0) || (image->page.height == 0))
1794 graphic_context[n]->viewbox.width=image->columns;
1795 graphic_context[n]->viewbox.height=image->rows;
1797 token=AcquireString(primitive);
1798 (void) QueryColorDatabase("#000000",&start_color,&image->exception);
1799 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
1800 return(MagickFalse);
1802 for (q=primitive; *q != '\0'; )
1805 Interpret graphic primitive.
1807 GetMagickToken(q,&q,keyword);
1808 if (*keyword == '\0')
1810 if (*keyword == '#')
1815 while ((*q != '\n') && (*q != '\0'))
1819 p=q-strlen(keyword)-1;
1820 primitive_type=UndefinedPrimitive;
1821 current=graphic_context[n]->affine;
1822 GetAffineMatrix(&affine);
1830 if (LocaleCompare("affine",keyword) == 0)
1832 GetMagickToken(q,&q,token);
1833 affine.sx=StringToDouble(token);
1834 GetMagickToken(q,&q,token);
1836 GetMagickToken(q,&q,token);
1837 affine.rx=StringToDouble(token);
1838 GetMagickToken(q,&q,token);
1840 GetMagickToken(q,&q,token);
1841 affine.ry=StringToDouble(token);
1842 GetMagickToken(q,&q,token);
1844 GetMagickToken(q,&q,token);
1845 affine.sy=StringToDouble(token);
1846 GetMagickToken(q,&q,token);
1848 GetMagickToken(q,&q,token);
1849 affine.tx=StringToDouble(token);
1850 GetMagickToken(q,&q,token);
1852 GetMagickToken(q,&q,token);
1853 affine.ty=StringToDouble(token);
1856 if (LocaleCompare("arc",keyword) == 0)
1858 primitive_type=ArcPrimitive;
1867 if (LocaleCompare("bezier",keyword) == 0)
1869 primitive_type=BezierPrimitive;
1872 if (LocaleCompare("border-color",keyword) == 0)
1874 GetMagickToken(q,&q,token);
1875 (void) QueryColorDatabase(token,&graphic_context[n]->border_color,
1885 if (LocaleCompare("clip-path",keyword) == 0)
1890 GetMagickToken(q,&q,token);
1891 (void) CloneString(&graphic_context[n]->clip_mask,token);
1892 (void) DrawClipPath(image,graphic_context[n],
1893 graphic_context[n]->clip_mask);
1896 if (LocaleCompare("clip-rule",keyword) == 0)
1901 GetMagickToken(q,&q,token);
1902 fill_rule=ParseMagickOption(MagickFillRuleOptions,MagickFalse,
1904 if (fill_rule == -1)
1909 graphic_context[n]->fill_rule=(FillRule) fill_rule;
1912 if (LocaleCompare("clip-units",keyword) == 0)
1917 GetMagickToken(q,&q,token);
1918 clip_units=ParseMagickOption(MagickClipPathOptions,MagickFalse,
1920 if (clip_units == -1)
1925 graphic_context[n]->clip_units=(ClipPathUnits) clip_units;
1926 if (clip_units == ObjectBoundingBox)
1928 GetAffineMatrix(¤t);
1929 affine.sx=draw_info->bounds.x2;
1930 affine.sy=draw_info->bounds.y2;
1931 affine.tx=draw_info->bounds.x1;
1932 affine.ty=draw_info->bounds.y1;
1937 if (LocaleCompare("circle",keyword) == 0)
1939 primitive_type=CirclePrimitive;
1942 if (LocaleCompare("color",keyword) == 0)
1944 primitive_type=ColorPrimitive;
1953 if (LocaleCompare("decorate",keyword) == 0)
1958 GetMagickToken(q,&q,token);
1959 decorate=ParseMagickOption(MagickDecorateOptions,MagickFalse,
1966 graphic_context[n]->decorate=(DecorationType) decorate;
1975 if (LocaleCompare("ellipse",keyword) == 0)
1977 primitive_type=EllipsePrimitive;
1980 if (LocaleCompare("encoding",keyword) == 0)
1982 GetMagickToken(q,&q,token);
1983 (void) CloneString(&graphic_context[n]->encoding,token);
1992 if (LocaleCompare("fill",keyword) == 0)
1994 GetMagickToken(q,&q,token);
1995 (void) FormatMagickString(pattern,MaxTextExtent,"%s",token);
1996 if (GetImageArtifact(image,pattern) != (const char *) NULL)
1997 (void) DrawPatternPath(image,draw_info,token,
1998 &graphic_context[n]->fill_pattern);
2001 status=QueryColorDatabase(token,&graphic_context[n]->fill,
2003 if (status == MagickFalse)
2008 pattern_info=AcquireImageInfo();
2009 (void) CopyMagickString(pattern_info->filename,token,
2011 graphic_context[n]->fill_pattern=
2012 ReadImage(pattern_info,&image->exception);
2013 CatchException(&image->exception);
2014 pattern_info=DestroyImageInfo(pattern_info);
2019 if (LocaleCompare("fill-opacity",keyword) == 0)
2021 GetMagickToken(q,&q,token);
2022 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2023 graphic_context[n]->fill.opacity=ClampToQuantum((MagickRealType)
2024 QuantumRange*(1.0-factor*StringToDouble(token)));
2027 if (LocaleCompare("fill-rule",keyword) == 0)
2032 GetMagickToken(q,&q,token);
2033 fill_rule=ParseMagickOption(MagickFillRuleOptions,MagickFalse,
2035 if (fill_rule == -1)
2040 graphic_context[n]->fill_rule=(FillRule) fill_rule;
2043 if (LocaleCompare("font",keyword) == 0)
2045 GetMagickToken(q,&q,token);
2046 (void) CloneString(&graphic_context[n]->font,token);
2047 if (LocaleCompare("none",token) == 0)
2048 graphic_context[n]->font=(char *)
2049 RelinquishMagickMemory(graphic_context[n]->font);
2052 if (LocaleCompare("font-family",keyword) == 0)
2054 GetMagickToken(q,&q,token);
2055 (void) CloneString(&graphic_context[n]->family,token);
2058 if (LocaleCompare("font-size",keyword) == 0)
2060 GetMagickToken(q,&q,token);
2061 graphic_context[n]->pointsize=StringToDouble(token);
2064 if (LocaleCompare("font-stretch",keyword) == 0)
2069 GetMagickToken(q,&q,token);
2070 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,token);
2076 graphic_context[n]->stretch=(StretchType) stretch;
2079 if (LocaleCompare("font-style",keyword) == 0)
2084 GetMagickToken(q,&q,token);
2085 style=ParseMagickOption(MagickStyleOptions,MagickFalse,token);
2091 graphic_context[n]->style=(StyleType) style;
2094 if (LocaleCompare("font-weight",keyword) == 0)
2096 GetMagickToken(q,&q,token);
2097 graphic_context[n]->weight=StringToUnsignedLong(token);
2098 if (LocaleCompare(token,"all") == 0)
2099 graphic_context[n]->weight=0;
2100 if (LocaleCompare(token,"bold") == 0)
2101 graphic_context[n]->weight=700;
2102 if (LocaleCompare(token,"bolder") == 0)
2103 if (graphic_context[n]->weight <= 800)
2104 graphic_context[n]->weight+=100;
2105 if (LocaleCompare(token,"lighter") == 0)
2106 if (graphic_context[n]->weight >= 100)
2107 graphic_context[n]->weight-=100;
2108 if (LocaleCompare(token,"normal") == 0)
2109 graphic_context[n]->weight=400;
2118 if (LocaleCompare("gradient-units",keyword) == 0)
2120 GetMagickToken(q,&q,token);
2123 if (LocaleCompare("gravity",keyword) == 0)
2128 GetMagickToken(q,&q,token);
2129 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,token);
2135 graphic_context[n]->gravity=(GravityType) gravity;
2144 if (LocaleCompare("image",keyword) == 0)
2149 primitive_type=ImagePrimitive;
2150 GetMagickToken(q,&q,token);
2151 compose=ParseMagickOption(MagickComposeOptions,MagickFalse,token);
2157 graphic_context[n]->compose=(CompositeOperator) compose;
2160 if (LocaleCompare("interline-spacing",keyword) == 0)
2162 GetMagickToken(q,&q,token);
2163 graphic_context[n]->interline_spacing=StringToDouble(token);
2166 if (LocaleCompare("interword-spacing",keyword) == 0)
2168 GetMagickToken(q,&q,token);
2169 graphic_context[n]->interword_spacing=StringToDouble(token);
2178 if (LocaleCompare("kerning",keyword) == 0)
2180 GetMagickToken(q,&q,token);
2181 graphic_context[n]->kerning=StringToDouble(token);
2190 if (LocaleCompare("line",keyword) == 0)
2192 primitive_type=LinePrimitive;
2201 if (LocaleCompare("matte",keyword) == 0)
2203 primitive_type=MattePrimitive;
2212 if (LocaleCompare("offset",keyword) == 0)
2214 GetMagickToken(q,&q,token);
2217 if (LocaleCompare("opacity",keyword) == 0)
2219 GetMagickToken(q,&q,token);
2220 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2221 graphic_context[n]->opacity=ClampToQuantum((MagickRealType)
2222 QuantumRange*(1.0-((1.0-QuantumScale*graphic_context[n]->opacity)*
2223 factor*StringToDouble(token))));
2224 graphic_context[n]->fill.opacity=graphic_context[n]->opacity;
2225 graphic_context[n]->stroke.opacity=graphic_context[n]->opacity;
2234 if (LocaleCompare("path",keyword) == 0)
2236 primitive_type=PathPrimitive;
2239 if (LocaleCompare("point",keyword) == 0)
2241 primitive_type=PointPrimitive;
2244 if (LocaleCompare("polyline",keyword) == 0)
2246 primitive_type=PolylinePrimitive;
2249 if (LocaleCompare("polygon",keyword) == 0)
2251 primitive_type=PolygonPrimitive;
2254 if (LocaleCompare("pop",keyword) == 0)
2256 GetMagickToken(q,&q,token);
2257 if (LocaleCompare("clip-path",token) == 0)
2259 if (LocaleCompare("defs",token) == 0)
2261 if (LocaleCompare("gradient",token) == 0)
2263 if (LocaleCompare("graphic-context",token) == 0)
2267 (void) ThrowMagickException(&image->exception,
2268 GetMagickModule(),DrawError,
2269 "UnbalancedGraphicContextPushPop","`%s'",token);
2273 if (graphic_context[n]->clip_mask != (char *) NULL)
2274 if (LocaleCompare(graphic_context[n]->clip_mask,
2275 graphic_context[n-1]->clip_mask) != 0)
2276 (void) SetImageClipMask(image,(Image *) NULL);
2277 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
2281 if (LocaleCompare("pattern",token) == 0)
2286 if (LocaleCompare("push",keyword) == 0)
2288 GetMagickToken(q,&q,token);
2289 if (LocaleCompare("clip-path",token) == 0)
2292 name[MaxTextExtent];
2294 GetMagickToken(q,&q,token);
2295 (void) FormatMagickString(name,MaxTextExtent,"%s",token);
2296 for (p=q; *q != '\0'; )
2298 GetMagickToken(q,&q,token);
2299 if (LocaleCompare(token,"pop") != 0)
2301 GetMagickToken(q,(const char **) NULL,token);
2302 if (LocaleCompare(token,"clip-path") != 0)
2306 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2307 (void) SetImageArtifact(image,name,token);
2308 GetMagickToken(q,&q,token);
2311 if (LocaleCompare("gradient",token) == 0)
2314 key[2*MaxTextExtent],
2315 name[MaxTextExtent],
2316 type[MaxTextExtent];
2324 GetMagickToken(q,&q,token);
2325 (void) CopyMagickString(name,token,MaxTextExtent);
2326 GetMagickToken(q,&q,token);
2327 (void) CopyMagickString(type,token,MaxTextExtent);
2328 GetMagickToken(q,&q,token);
2329 segment.x1=StringToDouble(token);
2330 element.cx=StringToDouble(token);
2331 GetMagickToken(q,&q,token);
2333 GetMagickToken(q,&q,token);
2334 segment.y1=StringToDouble(token);
2335 element.cy=StringToDouble(token);
2336 GetMagickToken(q,&q,token);
2338 GetMagickToken(q,&q,token);
2339 segment.x2=StringToDouble(token);
2340 element.major=StringToDouble(token);
2341 GetMagickToken(q,&q,token);
2343 GetMagickToken(q,&q,token);
2344 segment.y2=StringToDouble(token);
2345 element.minor=StringToDouble(token);
2346 if (LocaleCompare(type,"radial") == 0)
2348 GetMagickToken(q,&q,token);
2350 GetMagickToken(q,&q,token);
2351 element.angle=StringToDouble(token);
2353 for (p=q; *q != '\0'; )
2355 GetMagickToken(q,&q,token);
2356 if (LocaleCompare(token,"pop") != 0)
2358 GetMagickToken(q,(const char **) NULL,token);
2359 if (LocaleCompare(token,"gradient") != 0)
2363 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2364 bounds.x1=graphic_context[n]->affine.sx*segment.x1+
2365 graphic_context[n]->affine.ry*segment.y1+
2366 graphic_context[n]->affine.tx;
2367 bounds.y1=graphic_context[n]->affine.rx*segment.x1+
2368 graphic_context[n]->affine.sy*segment.y1+
2369 graphic_context[n]->affine.ty;
2370 bounds.x2=graphic_context[n]->affine.sx*segment.x2+
2371 graphic_context[n]->affine.ry*segment.y2+
2372 graphic_context[n]->affine.tx;
2373 bounds.y2=graphic_context[n]->affine.rx*segment.x2+
2374 graphic_context[n]->affine.sy*segment.y2+
2375 graphic_context[n]->affine.ty;
2376 (void) FormatMagickString(key,MaxTextExtent,"%s",name);
2377 (void) SetImageArtifact(image,key,token);
2378 (void) FormatMagickString(key,MaxTextExtent,"%s-geometry",name);
2379 (void) FormatMagickString(geometry,MaxTextExtent,
2380 "%gx%g%+.15g%+.15g",
2381 MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0),
2382 MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0),
2383 bounds.x1,bounds.y1);
2384 (void) SetImageArtifact(image,key,geometry);
2385 GetMagickToken(q,&q,token);
2388 if (LocaleCompare("pattern",token) == 0)
2393 GetMagickToken(q,&q,token);
2394 (void) CopyMagickString(name,token,MaxTextExtent);
2395 GetMagickToken(q,&q,token);
2396 bounds.x=(ssize_t) ceil(StringToDouble(token)-0.5);
2397 GetMagickToken(q,&q,token);
2399 GetMagickToken(q,&q,token);
2400 bounds.y=(ssize_t) ceil(StringToDouble(token)-0.5);
2401 GetMagickToken(q,&q,token);
2403 GetMagickToken(q,&q,token);
2404 bounds.width=(size_t) floor(StringToDouble(token)+0.5);
2405 GetMagickToken(q,&q,token);
2407 GetMagickToken(q,&q,token);
2408 bounds.height=(size_t) floor(StringToDouble(token)+0.5);
2409 for (p=q; *q != '\0'; )
2411 GetMagickToken(q,&q,token);
2412 if (LocaleCompare(token,"pop") != 0)
2414 GetMagickToken(q,(const char **) NULL,token);
2415 if (LocaleCompare(token,"pattern") != 0)
2419 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2420 (void) FormatMagickString(key,MaxTextExtent,"%s",name);
2421 (void) SetImageArtifact(image,key,token);
2422 (void) FormatMagickString(key,MaxTextExtent,"%s-geometry",name);
2423 (void) FormatMagickString(geometry,MaxTextExtent,
2424 "%.20gx%.20g%+.20g%+.20g",(double) bounds.width,(double)
2425 bounds.height,(double) bounds.x,(double) bounds.y);
2426 (void) SetImageArtifact(image,key,geometry);
2427 GetMagickToken(q,&q,token);
2430 if (LocaleCompare("graphic-context",token) == 0)
2433 graphic_context=(DrawInfo **) ResizeQuantumMemory(
2434 graphic_context,(size_t) (n+1),sizeof(*graphic_context));
2435 if (graphic_context == (DrawInfo **) NULL)
2437 (void) ThrowMagickException(&image->exception,
2438 GetMagickModule(),ResourceLimitError,
2439 "MemoryAllocationFailed","`%s'",image->filename);
2442 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,
2443 graphic_context[n-1]);
2446 if (LocaleCompare("defs",token) == 0)
2457 if (LocaleCompare("rectangle",keyword) == 0)
2459 primitive_type=RectanglePrimitive;
2462 if (LocaleCompare("rotate",keyword) == 0)
2464 GetMagickToken(q,&q,token);
2465 angle=StringToDouble(token);
2466 affine.sx=cos(DegreesToRadians(fmod((double) angle,360.0)));
2467 affine.rx=sin(DegreesToRadians(fmod((double) angle,360.0)));
2468 affine.ry=(-sin(DegreesToRadians(fmod((double) angle,360.0))));
2469 affine.sy=cos(DegreesToRadians(fmod((double) angle,360.0)));
2472 if (LocaleCompare("roundRectangle",keyword) == 0)
2474 primitive_type=RoundRectanglePrimitive;
2483 if (LocaleCompare("scale",keyword) == 0)
2485 GetMagickToken(q,&q,token);
2486 affine.sx=StringToDouble(token);
2487 GetMagickToken(q,&q,token);
2489 GetMagickToken(q,&q,token);
2490 affine.sy=StringToDouble(token);
2493 if (LocaleCompare("skewX",keyword) == 0)
2495 GetMagickToken(q,&q,token);
2496 angle=StringToDouble(token);
2497 affine.ry=sin(DegreesToRadians(angle));
2500 if (LocaleCompare("skewY",keyword) == 0)
2502 GetMagickToken(q,&q,token);
2503 angle=StringToDouble(token);
2504 affine.rx=(-tan(DegreesToRadians(angle)/2.0));
2507 if (LocaleCompare("stop-color",keyword) == 0)
2512 GetMagickToken(q,&q,token);
2513 (void) QueryColorDatabase(token,&stop_color,&image->exception);
2514 (void) GradientImage(image,LinearGradient,ReflectSpread,
2515 &start_color,&stop_color);
2516 start_color=stop_color;
2517 GetMagickToken(q,&q,token);
2520 if (LocaleCompare("stroke",keyword) == 0)
2522 GetMagickToken(q,&q,token);
2523 (void) FormatMagickString(pattern,MaxTextExtent,"%s",token);
2524 if (GetImageArtifact(image,pattern) != (const char *) NULL)
2525 (void) DrawPatternPath(image,draw_info,token,
2526 &graphic_context[n]->stroke_pattern);
2529 status=QueryColorDatabase(token,&graphic_context[n]->stroke,
2531 if (status == MagickFalse)
2536 pattern_info=AcquireImageInfo();
2537 (void) CopyMagickString(pattern_info->filename,token,
2539 graphic_context[n]->stroke_pattern=
2540 ReadImage(pattern_info,&image->exception);
2541 CatchException(&image->exception);
2542 pattern_info=DestroyImageInfo(pattern_info);
2547 if (LocaleCompare("stroke-antialias",keyword) == 0)
2549 GetMagickToken(q,&q,token);
2550 graphic_context[n]->stroke_antialias=
2551 StringToLong(token) != 0 ? MagickTrue : MagickFalse;
2554 if (LocaleCompare("stroke-dasharray",keyword) == 0)
2556 if (graphic_context[n]->dash_pattern != (double *) NULL)
2557 graphic_context[n]->dash_pattern=(double *)
2558 RelinquishMagickMemory(graphic_context[n]->dash_pattern);
2559 if (IsPoint(q) != MagickFalse)
2565 GetMagickToken(p,&p,token);
2567 GetMagickToken(p,&p,token);
2568 for (x=0; IsPoint(token) != MagickFalse; x++)
2570 GetMagickToken(p,&p,token);
2572 GetMagickToken(p,&p,token);
2574 graphic_context[n]->dash_pattern=(double *)
2575 AcquireQuantumMemory((size_t) (2UL*x+1UL),
2576 sizeof(*graphic_context[n]->dash_pattern));
2577 if (graphic_context[n]->dash_pattern == (double *) NULL)
2579 (void) ThrowMagickException(&image->exception,
2580 GetMagickModule(),ResourceLimitError,
2581 "MemoryAllocationFailed","`%s'",image->filename);
2584 for (j=0; j < x; j++)
2586 GetMagickToken(q,&q,token);
2588 GetMagickToken(q,&q,token);
2589 graphic_context[n]->dash_pattern[j]=StringToDouble(token);
2591 if ((x & 0x01) != 0)
2592 for ( ; j < (2*x); j++)
2593 graphic_context[n]->dash_pattern[j]=
2594 graphic_context[n]->dash_pattern[j-x];
2595 graphic_context[n]->dash_pattern[j]=0.0;
2598 GetMagickToken(q,&q,token);
2601 if (LocaleCompare("stroke-dashoffset",keyword) == 0)
2603 GetMagickToken(q,&q,token);
2604 graphic_context[n]->dash_offset=StringToDouble(token);
2607 if (LocaleCompare("stroke-linecap",keyword) == 0)
2612 GetMagickToken(q,&q,token);
2613 linecap=ParseMagickOption(MagickLineCapOptions,MagickFalse,token);
2619 graphic_context[n]->linecap=(LineCap) linecap;
2622 if (LocaleCompare("stroke-linejoin",keyword) == 0)
2627 GetMagickToken(q,&q,token);
2628 linejoin=ParseMagickOption(MagickLineJoinOptions,MagickFalse,token);
2634 graphic_context[n]->linejoin=(LineJoin) linejoin;
2637 if (LocaleCompare("stroke-miterlimit",keyword) == 0)
2639 GetMagickToken(q,&q,token);
2640 graphic_context[n]->miterlimit=StringToUnsignedLong(token);
2643 if (LocaleCompare("stroke-opacity",keyword) == 0)
2645 GetMagickToken(q,&q,token);
2646 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2647 graphic_context[n]->stroke.opacity=ClampToQuantum((MagickRealType)
2648 QuantumRange*(1.0-factor*StringToDouble(token)));
2651 if (LocaleCompare("stroke-width",keyword) == 0)
2653 GetMagickToken(q,&q,token);
2654 graphic_context[n]->stroke_width=StringToDouble(token);
2663 if (LocaleCompare("text",keyword) == 0)
2665 primitive_type=TextPrimitive;
2668 if (LocaleCompare("text-align",keyword) == 0)
2673 GetMagickToken(q,&q,token);
2674 align=ParseMagickOption(MagickAlignOptions,MagickFalse,token);
2680 graphic_context[n]->align=(AlignType) align;
2683 if (LocaleCompare("text-anchor",keyword) == 0)
2688 GetMagickToken(q,&q,token);
2689 align=ParseMagickOption(MagickAlignOptions,MagickFalse,token);
2695 graphic_context[n]->align=(AlignType) align;
2698 if (LocaleCompare("text-antialias",keyword) == 0)
2700 GetMagickToken(q,&q,token);
2701 graphic_context[n]->text_antialias=
2702 StringToLong(token) != 0 ? MagickTrue : MagickFalse;
2705 if (LocaleCompare("text-undercolor",keyword) == 0)
2707 GetMagickToken(q,&q,token);
2708 (void) QueryColorDatabase(token,&graphic_context[n]->undercolor,
2712 if (LocaleCompare("translate",keyword) == 0)
2714 GetMagickToken(q,&q,token);
2715 affine.tx=StringToDouble(token);
2716 GetMagickToken(q,&q,token);
2718 GetMagickToken(q,&q,token);
2719 affine.ty=StringToDouble(token);
2728 if (LocaleCompare("viewbox",keyword) == 0)
2730 GetMagickToken(q,&q,token);
2731 graphic_context[n]->viewbox.x=(ssize_t) ceil(StringToDouble(token)-
2733 GetMagickToken(q,&q,token);
2735 GetMagickToken(q,&q,token);
2736 graphic_context[n]->viewbox.y=(ssize_t) ceil(StringToDouble(token)-
2738 GetMagickToken(q,&q,token);
2740 GetMagickToken(q,&q,token);
2741 graphic_context[n]->viewbox.width=(size_t) floor(
2742 StringToDouble(token)+0.5);
2743 GetMagickToken(q,&q,token);
2745 GetMagickToken(q,&q,token);
2746 graphic_context[n]->viewbox.height=(size_t) floor(
2747 StringToDouble(token)+0.5);
2759 if (status == MagickFalse)
2761 if ((affine.sx != 1.0) || (affine.rx != 0.0) || (affine.ry != 0.0) ||
2762 (affine.sy != 1.0) || (affine.tx != 0.0) || (affine.ty != 0.0))
2764 graphic_context[n]->affine.sx=affine.sx*current.sx+affine.ry*current.rx;
2765 graphic_context[n]->affine.rx=affine.rx*current.sx+affine.sy*current.rx;
2766 graphic_context[n]->affine.ry=affine.sx*current.ry+affine.ry*current.sy;
2767 graphic_context[n]->affine.sy=affine.rx*current.ry+affine.sy*current.sy;
2768 graphic_context[n]->affine.tx=affine.sx*current.tx+affine.ry*current.ty+
2770 graphic_context[n]->affine.ty=affine.rx*current.tx+affine.sy*current.ty+
2773 if (primitive_type == UndefinedPrimitive)
2775 if (image->debug != MagickFalse)
2776 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",
2781 Parse the primitive attributes.
2785 primitive_info[0].point.x=0.0;
2786 primitive_info[0].point.y=0.0;
2787 for (x=0; *q != '\0'; x++)
2792 if (IsPoint(q) == MagickFalse)
2794 GetMagickToken(q,&q,token);
2795 point.x=StringToDouble(token);
2796 GetMagickToken(q,&q,token);
2798 GetMagickToken(q,&q,token);
2799 point.y=StringToDouble(token);
2800 GetMagickToken(q,(const char **) NULL,token);
2802 GetMagickToken(q,&q,token);
2803 primitive_info[i].primitive=primitive_type;
2804 primitive_info[i].point=point;
2805 primitive_info[i].coordinates=0;
2806 primitive_info[i].method=FloodfillMethod;
2808 if (i < (ssize_t) number_points)
2811 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,
2812 (size_t) number_points,sizeof(*primitive_info));
2813 if (primitive_info == (PrimitiveInfo *) NULL)
2815 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2816 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
2820 primitive_info[j].primitive=primitive_type;
2821 primitive_info[j].coordinates=(size_t) x;
2822 primitive_info[j].method=FloodfillMethod;
2823 primitive_info[j].text=(char *) NULL;
2825 Circumscribe primitive within a circle.
2827 bounds.x1=primitive_info[j].point.x;
2828 bounds.y1=primitive_info[j].point.y;
2829 bounds.x2=primitive_info[j].point.x;
2830 bounds.y2=primitive_info[j].point.y;
2831 for (k=1; k < (ssize_t) primitive_info[j].coordinates; k++)
2833 point=primitive_info[j+k].point;
2834 if (point.x < bounds.x1)
2836 if (point.y < bounds.y1)
2838 if (point.x > bounds.x2)
2840 if (point.y > bounds.y2)
2844 Speculate how many points our primitive might consume.
2846 length=primitive_info[j].coordinates;
2847 switch (primitive_type)
2849 case RectanglePrimitive:
2854 case RoundRectanglePrimitive:
2856 length*=5+8*BezierQuantum;
2859 case BezierPrimitive:
2861 if (primitive_info[j].coordinates > 107)
2862 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2863 DrawError,"TooManyBezierCoordinates","`%s'",token);
2864 length=BezierQuantum*primitive_info[j].coordinates;
2873 GetMagickToken(q,&q,token);
2876 for (s=token; *s != '\0'; s=t)
2887 length+=BezierQuantum;
2891 case CirclePrimitive:
2893 case EllipsePrimitive:
2900 alpha=bounds.x2-bounds.x1;
2901 beta=bounds.y2-bounds.y1;
2902 radius=hypot((double) alpha,(double) beta);
2903 length=2*((size_t) (MagickPI*radius))+6*BezierQuantum+360+1;
2909 if ((size_t) (i+length) >= number_points)
2912 Resize based on speculative points required by primitive.
2914 number_points+=length+1;
2915 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,
2916 (size_t) number_points,sizeof(*primitive_info));
2917 if (primitive_info == (PrimitiveInfo *) NULL)
2919 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2920 ResourceLimitError,"MemoryAllocationFailed","`%s'",
2925 switch (primitive_type)
2927 case PointPrimitive:
2930 if (primitive_info[j].coordinates != 1)
2935 TracePoint(primitive_info+j,primitive_info[j].point);
2936 i=(ssize_t) (j+primitive_info[j].coordinates);
2941 if (primitive_info[j].coordinates != 2)
2946 TraceLine(primitive_info+j,primitive_info[j].point,
2947 primitive_info[j+1].point);
2948 i=(ssize_t) (j+primitive_info[j].coordinates);
2951 case RectanglePrimitive:
2953 if (primitive_info[j].coordinates != 2)
2958 TraceRectangle(primitive_info+j,primitive_info[j].point,
2959 primitive_info[j+1].point);
2960 i=(ssize_t) (j+primitive_info[j].coordinates);
2963 case RoundRectanglePrimitive:
2965 if (primitive_info[j].coordinates != 3)
2970 TraceRoundRectangle(primitive_info+j,primitive_info[j].point,
2971 primitive_info[j+1].point,primitive_info[j+2].point);
2972 i=(ssize_t) (j+primitive_info[j].coordinates);
2977 if (primitive_info[j].coordinates != 3)
2979 primitive_type=UndefinedPrimitive;
2982 TraceArc(primitive_info+j,primitive_info[j].point,
2983 primitive_info[j+1].point,primitive_info[j+2].point);
2984 i=(ssize_t) (j+primitive_info[j].coordinates);
2987 case EllipsePrimitive:
2989 if (primitive_info[j].coordinates != 3)
2994 TraceEllipse(primitive_info+j,primitive_info[j].point,
2995 primitive_info[j+1].point,primitive_info[j+2].point);
2996 i=(ssize_t) (j+primitive_info[j].coordinates);
2999 case CirclePrimitive:
3001 if (primitive_info[j].coordinates != 2)
3006 TraceCircle(primitive_info+j,primitive_info[j].point,
3007 primitive_info[j+1].point);
3008 i=(ssize_t) (j+primitive_info[j].coordinates);
3011 case PolylinePrimitive:
3013 case PolygonPrimitive:
3015 primitive_info[i]=primitive_info[j];
3016 primitive_info[i].coordinates=0;
3017 primitive_info[j].coordinates++;
3021 case BezierPrimitive:
3023 if (primitive_info[j].coordinates < 3)
3028 TraceBezier(primitive_info+j,primitive_info[j].coordinates);
3029 i=(ssize_t) (j+primitive_info[j].coordinates);
3034 i=(ssize_t) (j+TracePath(primitive_info+j,token));
3037 case ColorPrimitive:
3038 case MattePrimitive:
3043 if (primitive_info[j].coordinates != 1)
3048 GetMagickToken(q,&q,token);
3049 method=ParseMagickOption(MagickMethodOptions,MagickFalse,token);
3055 primitive_info[j].method=(PaintMethod) method;
3060 if (primitive_info[j].coordinates != 1)
3066 GetMagickToken(q,&q,token);
3067 primitive_info[j].text=AcquireString(token);
3070 case ImagePrimitive:
3072 if (primitive_info[j].coordinates != 2)
3077 GetMagickToken(q,&q,token);
3078 primitive_info[j].text=AcquireString(token);
3082 if (primitive_info == (PrimitiveInfo *) NULL)
3084 if (image->debug != MagickFalse)
3085 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",(int) (q-p),p);
3086 if (status == MagickFalse)
3088 primitive_info[i].primitive=UndefinedPrimitive;
3094 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
3096 point=primitive_info[i].point;
3097 primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+
3098 graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx;
3099 primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+
3100 graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty;
3101 point=primitive_info[i].point;
3102 if (point.x < graphic_context[n]->bounds.x1)
3103 graphic_context[n]->bounds.x1=point.x;
3104 if (point.y < graphic_context[n]->bounds.y1)
3105 graphic_context[n]->bounds.y1=point.y;
3106 if (point.x > graphic_context[n]->bounds.x2)
3107 graphic_context[n]->bounds.x2=point.x;
3108 if (point.y > graphic_context[n]->bounds.y2)
3109 graphic_context[n]->bounds.y2=point.y;
3110 if (primitive_info[i].primitive == ImagePrimitive)
3112 if (i >= (ssize_t) number_points)
3113 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
3115 if (graphic_context[n]->render != MagickFalse)
3117 if ((n != 0) && (graphic_context[n]->clip_mask != (char *) NULL) &&
3118 (LocaleCompare(graphic_context[n]->clip_mask,
3119 graphic_context[n-1]->clip_mask) != 0))
3120 (void) DrawClipPath(image,graphic_context[n],
3121 graphic_context[n]->clip_mask);
3122 (void) DrawPrimitive(image,graphic_context[n],primitive_info);
3124 if (primitive_info->text != (char *) NULL)
3125 primitive_info->text=(char *) RelinquishMagickMemory(
3126 primitive_info->text);
3127 proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType)
3129 if (proceed == MagickFalse)
3132 if (image->debug != MagickFalse)
3133 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end draw-image");
3135 Relinquish resources.
3137 token=DestroyString(token);
3138 if (primitive_info != (PrimitiveInfo *) NULL)
3139 primitive_info=(PrimitiveInfo *) RelinquishMagickMemory(primitive_info);
3140 primitive=DestroyString(primitive);
3141 for ( ; n >= 0; n--)
3142 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
3143 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
3144 if (status == MagickFalse)
3145 ThrowBinaryException(DrawError,"NonconformingDrawingPrimitiveDefinition",
3151 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3155 % D r a w G r a d i e n t I m a g e %
3159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3161 % DrawGradientImage() draws a linear gradient on the image.
3163 % The format of the DrawGradientImage method is:
3165 % MagickBooleanType DrawGradientImage(Image *image,
3166 % const DrawInfo *draw_info)
3168 % A description of each parameter follows:
3170 % o image: the image.
3172 % o _info: the draw info.
3176 static inline MagickRealType GetStopColorOffset(const GradientInfo *gradient,
3177 const ssize_t x,const ssize_t y)
3179 switch (gradient->type)
3181 case UndefinedGradient:
3182 case LinearGradient:
3197 gradient_vector=(&gradient->gradient_vector);
3198 p.x=gradient_vector->x2-gradient_vector->x1;
3199 p.y=gradient_vector->y2-gradient_vector->y1;
3200 q.x=(double) x-gradient_vector->x1;
3201 q.y=(double) y-gradient_vector->y1;
3202 length=sqrt(q.x*q.x+q.y*q.y);
3203 gamma=sqrt(p.x*p.x+p.y*p.y)*length;
3204 gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
3205 scale=p.x*q.x+p.y*q.y;
3206 offset=gamma*scale*length;
3209 case RadialGradient:
3218 v.x=(double) x-gradient->center.x;
3219 v.y=(double) y-gradient->center.y;
3220 length=sqrt(v.x*v.x+v.y*v.y);
3221 if (gradient->spread == RepeatSpread)
3223 offset=length/gradient->radius;
3230 MagickExport MagickBooleanType DrawGradientImage(Image *image,
3231 const DrawInfo *draw_info)
3264 Draw linear or radial gradient on image.
3266 assert(image != (Image *) NULL);
3267 assert(image->signature == MagickSignature);
3268 if (image->debug != MagickFalse)
3269 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3270 assert(draw_info != (const DrawInfo *) NULL);
3271 gradient=(&draw_info->gradient);
3272 gradient_vector=(&gradient->gradient_vector);
3273 point.x=gradient_vector->x2-gradient_vector->x1;
3274 point.y=gradient_vector->y2-gradient_vector->y1;
3275 length=sqrt(point.x*point.x+point.y*point.y);
3276 bounding_box=gradient->bounding_box;
3278 exception=(&image->exception);
3279 GetMagickPixelPacket(image,&zero);
3280 image_view=AcquireCacheView(image);
3281 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3282 #pragma omp parallel for schedule(dynamic,4) shared(status)
3284 for (y=bounding_box.y; y < (ssize_t) bounding_box.height; y++)
3294 register IndexPacket
3301 register PixelPacket
3307 if (status == MagickFalse)
3309 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3310 if (q == (PixelPacket *) NULL)
3315 indexes=GetCacheViewAuthenticIndexQueue(image_view);
3318 offset=GetStopColorOffset(gradient,0,y);
3319 if (gradient->type != RadialGradient)
3321 for (x=bounding_box.x; x < (ssize_t) bounding_box.width; x++)
3323 SetMagickPixelPacket(image,q,indexes+x,&pixel);
3324 switch (gradient->spread)
3326 case UndefinedSpread:
3329 if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) ||
3330 (y != (ssize_t) ceil(gradient_vector->y1-0.5)))
3332 offset=GetStopColorOffset(gradient,x,y);
3333 if (gradient->type != RadialGradient)
3336 for (i=0; i < (ssize_t) gradient->number_stops; i++)
3337 if (offset < gradient->stops[i].offset)
3339 if ((offset < 0.0) || (i == 0))
3340 composite=gradient->stops[0].color;
3342 if ((offset > 1.0) || (i == (ssize_t) gradient->number_stops))
3343 composite=gradient->stops[gradient->number_stops-1].color;
3348 alpha=(offset-gradient->stops[i].offset)/
3349 (gradient->stops[j].offset-gradient->stops[i].offset);
3350 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3351 &gradient->stops[j].color,alpha,&composite);
3357 if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) ||
3358 (y != (ssize_t) ceil(gradient_vector->y1-0.5)))
3360 offset=GetStopColorOffset(gradient,x,y);
3361 if (gradient->type != RadialGradient)
3366 if ((ssize_t) fmod(offset,2.0) == 0)
3367 offset=fmod(offset,1.0);
3369 offset=1.0-fmod(offset,1.0);
3370 for (i=0; i < (ssize_t) gradient->number_stops; i++)
3371 if (offset < gradient->stops[i].offset)
3374 composite=gradient->stops[0].color;
3376 if (i == (ssize_t) gradient->number_stops)
3377 composite=gradient->stops[gradient->number_stops-1].color;
3382 alpha=(offset-gradient->stops[i].offset)/
3383 (gradient->stops[j].offset-gradient->stops[i].offset);
3384 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3385 &gradient->stops[j].color,alpha,&composite);
3397 antialias=MagickFalse;
3399 if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) ||
3400 (y != (ssize_t) ceil(gradient_vector->y1-0.5)))
3402 offset=GetStopColorOffset(gradient,x,y);
3403 if (gradient->type == LinearGradient)
3405 repeat=fmod(offset,length);
3407 repeat=length-fmod(-repeat,length);
3409 repeat=fmod(offset,length);
3410 antialias=(repeat < length) && ((repeat+1.0) > length) ?
3411 MagickTrue : MagickFalse;
3412 offset=repeat/length;
3416 repeat=fmod(offset,gradient->radius);
3418 repeat=gradient->radius-fmod(-repeat,gradient->radius);
3420 repeat=fmod(offset,gradient->radius);
3421 antialias=repeat+1.0 > gradient->radius ?
3422 MagickTrue : MagickFalse;
3423 offset=repeat/gradient->radius;
3426 for (i=0; i < (ssize_t) gradient->number_stops; i++)
3427 if (offset < gradient->stops[i].offset)
3430 composite=gradient->stops[0].color;
3432 if (i == (ssize_t) gradient->number_stops)
3433 composite=gradient->stops[gradient->number_stops-1].color;
3438 alpha=(offset-gradient->stops[i].offset)/
3439 (gradient->stops[j].offset-gradient->stops[i].offset);
3440 if (antialias != MagickFalse)
3442 if (gradient->type == LinearGradient)
3443 alpha=length-repeat;
3445 alpha=gradient->radius-repeat;
3447 j=(ssize_t) gradient->number_stops-1L;
3449 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3450 &gradient->stops[j].color,alpha,&composite);
3455 MagickPixelCompositeOver(&composite,composite.opacity,&pixel,
3456 pixel.opacity,&pixel);
3457 SetPixelPacket(image,&pixel,q,indexes+x);
3460 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3463 image_view=DestroyCacheView(image_view);
3468 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3472 % D r a w P a t t e r n P a t h %
3476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3478 % DrawPatternPath() draws a pattern.
3480 % The format of the DrawPatternPath method is:
3482 % MagickBooleanType DrawPatternPath(Image *image,const DrawInfo *draw_info,
3483 % const char *name,Image **pattern)
3485 % A description of each parameter follows:
3487 % o image: the image.
3489 % o draw_info: the draw info.
3491 % o name: the pattern name.
3493 % o image: the image.
3496 MagickExport MagickBooleanType DrawPatternPath(Image *image,
3497 const DrawInfo *draw_info,const char *name,Image **pattern)
3500 property[MaxTextExtent];
3515 assert(image != (Image *) NULL);
3516 assert(image->signature == MagickSignature);
3517 if (image->debug != MagickFalse)
3518 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3519 assert(draw_info != (const DrawInfo *) NULL);
3520 assert(name != (const char *) NULL);
3521 (void) FormatMagickString(property,MaxTextExtent,"%s",name);
3522 path=GetImageArtifact(image,property);
3523 if (path == (const char *) NULL)
3524 return(MagickFalse);
3525 (void) FormatMagickString(property,MaxTextExtent,"%s-geometry",name);
3526 geometry=GetImageArtifact(image,property);
3527 if (geometry == (const char *) NULL)
3528 return(MagickFalse);
3529 if ((*pattern) != (Image *) NULL)
3530 *pattern=DestroyImage(*pattern);
3531 image_info=AcquireImageInfo();
3532 image_info->size=AcquireString(geometry);
3533 *pattern=AcquireImage(image_info);
3534 image_info=DestroyImageInfo(image_info);
3535 (void) QueryColorDatabase("#00000000",&(*pattern)->background_color,
3537 (void) SetImageBackgroundColor(*pattern);
3538 if (image->debug != MagickFalse)
3539 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
3540 "begin pattern-path %s %s",name,geometry);
3541 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
3542 clone_info->fill_pattern=NewImageList();
3543 clone_info->stroke_pattern=NewImageList();
3544 (void) CloneString(&clone_info->primitive,path);
3545 status=DrawImage(*pattern,clone_info);
3546 clone_info=DestroyDrawInfo(clone_info);
3547 if (image->debug != MagickFalse)
3548 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end pattern-path");
3553 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3557 + D r a w P o l y g o n P r i m i t i v e %
3561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3563 % DrawPolygonPrimitive() draws a polygon on the image.
3565 % The format of the DrawPolygonPrimitive method is:
3567 % MagickBooleanType DrawPolygonPrimitive(Image *image,
3568 % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
3570 % A description of each parameter follows:
3572 % o image: the image.
3574 % o draw_info: the draw info.
3576 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
3580 static PolygonInfo **DestroyPolygonThreadSet(PolygonInfo **polygon_info)
3585 assert(polygon_info != (PolygonInfo **) NULL);
3586 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
3587 if (polygon_info[i] != (PolygonInfo *) NULL)
3588 polygon_info[i]=DestroyPolygonInfo(polygon_info[i]);
3589 polygon_info=(PolygonInfo **) RelinquishMagickMemory(polygon_info);
3590 return(polygon_info);
3593 static PolygonInfo **AcquirePolygonThreadSet(const DrawInfo *draw_info,
3594 const PrimitiveInfo *primitive_info)
3597 *restrict path_info;
3608 number_threads=GetOpenMPMaximumThreads();
3609 polygon_info=(PolygonInfo **) AcquireQuantumMemory(number_threads,
3610 sizeof(*polygon_info));
3611 if (polygon_info == (PolygonInfo **) NULL)
3612 return((PolygonInfo **) NULL);
3613 (void) ResetMagickMemory(polygon_info,0,GetOpenMPMaximumThreads()*
3614 sizeof(*polygon_info));
3615 path_info=ConvertPrimitiveToPath(draw_info,primitive_info);
3616 if (path_info == (PathInfo *) NULL)
3617 return(DestroyPolygonThreadSet(polygon_info));
3618 for (i=0; i < (ssize_t) number_threads; i++)
3620 polygon_info[i]=ConvertPathToPolygon(draw_info,path_info);
3621 if (polygon_info[i] == (PolygonInfo *) NULL)
3622 return(DestroyPolygonThreadSet(polygon_info));
3624 path_info=(PathInfo *) RelinquishMagickMemory(path_info);
3625 return(polygon_info);
3628 static MagickRealType GetPixelOpacity(PolygonInfo *polygon_info,
3629 const MagickRealType mid,const MagickBooleanType fill,
3630 const FillRule fill_rule,const double x,const double y,
3631 MagickRealType *stroke_opacity)
3645 register const PointInfo
3656 Compute fill & stroke opacity for this (x,y) point.
3658 *stroke_opacity=0.0;
3659 subpath_opacity=0.0;
3660 p=polygon_info->edges;
3661 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
3663 if (y <= (p->bounds.y1-mid-0.5))
3665 if (y > (p->bounds.y2+mid+0.5))
3667 (void) DestroyEdge(polygon_info,(size_t) j);
3670 if ((x <= (p->bounds.x1-mid-0.5)) || (x > (p->bounds.x2+mid+0.5)))
3672 i=(ssize_t) MagickMax((double) p->highwater,1.0);
3673 for ( ; i < (ssize_t) p->number_points; i++)
3675 if (y <= (p->points[i-1].y-mid-0.5))
3677 if (y > (p->points[i].y+mid+0.5))
3679 if (p->scanline != y)
3682 p->highwater=(size_t) i;
3685 Compute distance between a point and an edge.
3688 delta.x=(q+1)->x-q->x;
3689 delta.y=(q+1)->y-q->y;
3690 beta=delta.x*(x-q->x)+delta.y*(y-q->y);
3695 distance=delta.x*delta.x+delta.y*delta.y;
3699 alpha=delta.x*delta.x+delta.y*delta.y;
3704 distance=delta.x*delta.x+delta.y*delta.y;
3709 beta=delta.x*(y-q->y)-delta.y*(x-q->x);
3710 distance=alpha*beta*beta;
3714 Compute stroke & subpath opacity.
3717 if (p->ghostline == MagickFalse)
3720 if ((*stroke_opacity < 1.0) &&
3721 (distance <= ((alpha+0.25)*(alpha+0.25))))
3724 if (distance <= ((alpha+0.25)*(alpha+0.25)))
3725 *stroke_opacity=1.0;
3729 if (distance != 1.0)
3730 beta=sqrt((double) distance);
3732 if (*stroke_opacity < ((alpha-0.25)*(alpha-0.25)))
3733 *stroke_opacity=(alpha-0.25)*(alpha-0.25);
3737 if ((fill == MagickFalse) || (distance > 1.0) || (subpath_opacity >= 1.0))
3739 if (distance <= 0.0)
3741 subpath_opacity=1.0;
3749 if (distance != 1.0)
3750 beta=sqrt(distance);
3753 if (subpath_opacity < (alpha*alpha))
3754 subpath_opacity=alpha*alpha;
3758 Compute fill opacity.
3760 if (fill == MagickFalse)
3762 if (subpath_opacity >= 1.0)
3765 Determine winding number.
3768 p=polygon_info->edges;
3769 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
3771 if (y <= p->bounds.y1)
3773 if ((y > p->bounds.y2) || (x <= p->bounds.x1))
3775 if (x > p->bounds.x2)
3777 winding_number+=p->direction ? 1 : -1;
3780 i=(ssize_t) MagickMax((double) p->highwater,1.0);
3781 for ( ; i < (ssize_t) p->number_points; i++)
3782 if (y <= p->points[i].y)
3785 if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x)))
3786 winding_number+=p->direction ? 1 : -1;
3788 if (fill_rule != NonZeroRule)
3790 if ((MagickAbsoluteValue(winding_number) & 0x01) != 0)
3794 if (MagickAbsoluteValue(winding_number) != 0)
3796 return(subpath_opacity);
3799 static MagickBooleanType DrawPolygonPrimitive(Image *image,
3800 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
3816 **restrict polygon_info;
3833 Compute bounding box.
3835 assert(image != (Image *) NULL);
3836 assert(image->signature == MagickSignature);
3837 if (image->debug != MagickFalse)
3838 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3839 assert(draw_info != (DrawInfo *) NULL);
3840 assert(draw_info->signature == MagickSignature);
3841 assert(primitive_info != (PrimitiveInfo *) NULL);
3842 if (primitive_info->coordinates == 0)
3844 polygon_info=AcquirePolygonThreadSet(draw_info,primitive_info);
3845 if (polygon_info == (PolygonInfo **) NULL)
3846 return(MagickFalse);
3848 DrawBoundingRectangles(image,draw_info,polygon_info[0]);
3849 if (image->debug != MagickFalse)
3850 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-polygon");
3851 fill=(primitive_info->method == FillToBorderMethod) ||
3852 (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse;
3853 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
3854 bounds=polygon_info[0]->edges[0].bounds;
3855 for (i=1; i < (ssize_t) polygon_info[0]->number_edges; i++)
3857 p=polygon_info[0]->edges+i;
3858 if (p->bounds.x1 < bounds.x1)
3859 bounds.x1=p->bounds.x1;
3860 if (p->bounds.y1 < bounds.y1)
3861 bounds.y1=p->bounds.y1;
3862 if (p->bounds.x2 > bounds.x2)
3863 bounds.x2=p->bounds.x2;
3864 if (p->bounds.y2 > bounds.y2)
3865 bounds.y2=p->bounds.y2;
3867 bounds.x1-=(mid+1.0);
3868 bounds.x1=bounds.x1 < 0.0 ? 0.0 : (size_t) ceil(bounds.x1-0.5) >=
3869 image->columns ? (double) image->columns-1.0 : bounds.x1;
3870 bounds.y1-=(mid+1.0);
3871 bounds.y1=bounds.y1 < 0.0 ? 0.0 : (size_t) ceil(bounds.y1-0.5) >=
3872 image->rows ? (double) image->rows-1.0 : bounds.y1;
3873 bounds.x2+=(mid+1.0);
3874 bounds.x2=bounds.x2 < 0.0 ? 0.0 : (size_t) floor(bounds.x2+0.5) >=
3875 image->columns ? (double) image->columns-1.0 : bounds.x2;
3876 bounds.y2+=(mid+1.0);
3877 bounds.y2=bounds.y2 < 0.0 ? 0.0 : (size_t) floor(bounds.y2+0.5) >=
3878 image->rows ? (double) image->rows-1.0 : bounds.y2;
3880 exception=(&image->exception);
3881 start=(ssize_t) ceil(bounds.x1-0.5);
3882 stop=(ssize_t) floor(bounds.x2+0.5);
3883 image_view=AcquireCacheView(image);
3884 if (primitive_info->coordinates == 1)
3889 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3890 #pragma omp parallel for schedule(dynamic,4) shared(status)
3892 for (y=(ssize_t) ceil(bounds.y1-0.5); y <= (ssize_t) floor(bounds.y2+0.5); y++)
3900 register PixelPacket
3903 if (status == MagickFalse)
3906 q=GetCacheViewAuthenticPixels(image_view,x,y,(size_t) (stop-x+1),
3908 if (q == (PixelPacket *) NULL)
3913 for ( ; x <= stop; x++)
3915 if ((x == (ssize_t) ceil(primitive_info->point.x-0.5)) &&
3916 (y == (ssize_t) ceil(primitive_info->point.y-0.5)))
3917 (void) GetStrokeColor(draw_info,x,y,q);
3920 sync=SyncCacheViewAuthenticPixels(image_view,exception);
3921 if (sync == MagickFalse)
3924 image_view=DestroyCacheView(image_view);
3925 polygon_info=DestroyPolygonThreadSet(polygon_info);
3926 if (image->debug != MagickFalse)
3927 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
3928 " end draw-polygon");
3932 Draw polygon or line.
3934 if (image->matte == MagickFalse)
3935 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3936 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3937 #pragma omp parallel for schedule(dynamic,4) shared(status)
3939 for (y=(ssize_t) ceil(bounds.y1-0.5); y <= (ssize_t) floor(bounds.y2+0.5); y++)
3942 id = GetOpenMPThreadId();
3952 register PixelPacket
3958 if (status == MagickFalse)
3960 q=GetCacheViewAuthenticPixels(image_view,start,y,(size_t) (stop-
3961 start+1),1,exception);
3962 if (q == (PixelPacket *) NULL)
3967 for (x=start; x <= stop; x++)
3972 fill_opacity=GetPixelOpacity(polygon_info[id],mid,fill,
3973 draw_info->fill_rule,(double) x,(double) y,&stroke_opacity);
3974 if (draw_info->stroke_antialias == MagickFalse)
3976 fill_opacity=fill_opacity > 0.25 ? 1.0 : 0.0;
3977 stroke_opacity=stroke_opacity > 0.25 ? 1.0 : 0.0;
3979 (void) GetFillColor(draw_info,x,y,&fill_color);
3980 fill_opacity=(MagickRealType) (QuantumRange-fill_opacity*(QuantumRange-
3981 fill_color.opacity));
3982 MagickCompositeOver(&fill_color,fill_opacity,q,(MagickRealType)
3984 (void) GetStrokeColor(draw_info,x,y,&stroke_color);
3985 stroke_opacity=(MagickRealType) (QuantumRange-stroke_opacity*
3986 (QuantumRange-stroke_color.opacity));
3987 MagickCompositeOver(&stroke_color,stroke_opacity,q,(MagickRealType)
3991 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3994 image_view=DestroyCacheView(image_view);
3995 polygon_info=DestroyPolygonThreadSet(polygon_info);
3996 if (image->debug != MagickFalse)
3997 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-polygon");
4002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4006 % D r a w P r i m i t i v e %
4010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4012 % DrawPrimitive() draws a primitive (line, rectangle, ellipse) on the image.
4014 % The format of the DrawPrimitive method is:
4016 % MagickBooleanType DrawPrimitive(Image *image,const DrawInfo *draw_info,
4017 % PrimitiveInfo *primitive_info)
4019 % A description of each parameter follows:
4021 % o image: the image.
4023 % o draw_info: the draw info.
4025 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
4029 static void LogPrimitiveInfo(const PrimitiveInfo *primitive_info)
4055 x=(ssize_t) ceil(primitive_info->point.x-0.5);
4056 y=(ssize_t) ceil(primitive_info->point.y-0.5);
4057 switch (primitive_info->primitive)
4059 case PointPrimitive:
4061 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4062 "PointPrimitive %.20g,%.20g %s",(double) x,(double) y,
4063 methods[primitive_info->method]);
4066 case ColorPrimitive:
4068 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4069 "ColorPrimitive %.20g,%.20g %s",(double) x,(double) y,
4070 methods[primitive_info->method]);
4073 case MattePrimitive:
4075 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4076 "MattePrimitive %.20g,%.20g %s",(double) x,(double) y,
4077 methods[primitive_info->method]);
4082 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4083 "TextPrimitive %.20g,%.20g",(double) x,(double) y);
4086 case ImagePrimitive:
4088 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4089 "ImagePrimitive %.20g,%.20g",(double) x,(double) y);
4096 p=primitive_info[0].point;
4099 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4101 point=primitive_info[i].point;
4102 if (coordinates <= 0)
4104 coordinates=(ssize_t) primitive_info[i].coordinates;
4105 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4106 " begin open (%.20g)",(double) coordinates);
4109 point=primitive_info[i].point;
4110 if ((fabs(q.x-point.x) > MagickEpsilon) ||
4111 (fabs(q.y-point.y) > MagickEpsilon))
4112 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4113 " %.20g: %.18g,%.18g",(double) coordinates,point.x,point.y);
4115 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4116 " %.20g: %g,%g (duplicate)",(double) coordinates,point.x,point.y);
4119 if (coordinates > 0)
4121 if ((fabs(p.x-point.x) > MagickEpsilon) ||
4122 (fabs(p.y-point.y) > MagickEpsilon))
4123 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end last (%.20g)",
4124 (double) coordinates);
4126 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end open (%.20g)",
4127 (double) coordinates);
4131 MagickExport MagickBooleanType DrawPrimitive(Image *image,
4132 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4150 if (image->debug != MagickFalse)
4152 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4153 " begin draw-primitive");
4154 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4155 " affine: %g,%g,%g,%g,%g,%g",draw_info->affine.sx,
4156 draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy,
4157 draw_info->affine.tx,draw_info->affine.ty);
4160 exception=(&image->exception);
4161 x=(ssize_t) ceil(primitive_info->point.x-0.5);
4162 y=(ssize_t) ceil(primitive_info->point.y-0.5);
4163 image_view=AcquireCacheView(image);
4164 switch (primitive_info->primitive)
4166 case PointPrimitive:
4174 if ((y < 0) || (y >= (ssize_t) image->rows))
4176 if ((x < 0) || (x >= (ssize_t) image->columns))
4178 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4179 if (q == (PixelPacket *) NULL)
4181 (void) GetFillColor(draw_info,x,y,&fill_color);
4182 MagickCompositeOver(&fill_color,(MagickRealType) fill_color.opacity,q,
4183 (MagickRealType) q->opacity,q);
4184 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4187 case ColorPrimitive:
4189 switch (primitive_info->method)
4197 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4198 if (q == (PixelPacket *) NULL)
4200 (void) GetFillColor(draw_info,x,y,q);
4201 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4212 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception);
4213 for (y=0; y < (ssize_t) image->rows; y++)
4215 register PixelPacket
4218 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4220 if (q == (PixelPacket *) NULL)
4222 for (x=0; x < (ssize_t) image->columns; x++)
4224 if (IsColorSimilar(image,q,&target) == MagickFalse)
4229 (void) GetFillColor(draw_info,x,y,q);
4232 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4233 if (sync == MagickFalse)
4238 case FloodfillMethod:
4239 case FillToBorderMethod:
4244 (void) GetOneVirtualMagickPixel(image,x,y,&target,exception);
4245 if (primitive_info->method == FillToBorderMethod)
4247 target.red=(MagickRealType) draw_info->border_color.red;
4248 target.green=(MagickRealType) draw_info->border_color.green;
4249 target.blue=(MagickRealType) draw_info->border_color.blue;
4251 (void) FloodfillPaintImage(image,DefaultChannels,draw_info,&target,x,
4252 y,primitive_info->method == FloodfillMethod ? MagickFalse :
4261 for (y=0; y < (ssize_t) image->rows; y++)
4263 register PixelPacket
4269 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4271 if (q == (PixelPacket *) NULL)
4273 for (x=0; x < (ssize_t) image->columns; x++)
4275 (void) GetFillColor(draw_info,x,y,q);
4278 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4279 if (sync == MagickFalse)
4287 case MattePrimitive:
4289 if (image->matte == MagickFalse)
4290 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
4291 switch (primitive_info->method)
4302 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4303 if (q == (PixelPacket *) NULL)
4305 (void) GetFillColor(draw_info,x,y,&pixel);
4306 q->opacity=pixel.opacity;
4307 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4319 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception);
4320 for (y=0; y < (ssize_t) image->rows; y++)
4322 register PixelPacket
4328 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4330 if (q == (PixelPacket *) NULL)
4332 for (x=0; x < (ssize_t) image->columns; x++)
4334 if (IsColorSimilar(image,q,&target) == MagickFalse)
4339 (void) GetFillColor(draw_info,x,y,&pixel);
4340 q->opacity=pixel.opacity;
4343 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4344 if (sync == MagickFalse)
4349 case FloodfillMethod:
4350 case FillToBorderMethod:
4355 (void) GetOneVirtualMagickPixel(image,x,y,&target,exception);
4356 if (primitive_info->method == FillToBorderMethod)
4358 target.red=(MagickRealType) draw_info->border_color.red;
4359 target.green=(MagickRealType) draw_info->border_color.green;
4360 target.blue=(MagickRealType) draw_info->border_color.blue;
4362 (void) FloodfillPaintImage(image,OpacityChannel,draw_info,&target,x,y,
4363 primitive_info->method == FloodfillMethod ? MagickFalse :
4375 for (y=0; y < (ssize_t) image->rows; y++)
4377 register PixelPacket
4383 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4385 if (q == (PixelPacket *) NULL)
4387 for (x=0; x < (ssize_t) image->columns; x++)
4389 (void) GetFillColor(draw_info,x,y,&pixel);
4390 q->opacity=pixel.opacity;
4393 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4394 if (sync == MagickFalse)
4405 geometry[MaxTextExtent];
4410 if (primitive_info->text == (char *) NULL)
4412 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4413 (void) CloneString(&clone_info->text,primitive_info->text);
4414 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
4415 primitive_info->point.x,primitive_info->point.y);
4416 (void) CloneString(&clone_info->geometry,geometry);
4417 status=AnnotateImage(image,clone_info);
4418 clone_info=DestroyDrawInfo(clone_info);
4421 case ImagePrimitive:
4427 composite_geometry[MaxTextExtent];
4442 if (primitive_info->text == (char *) NULL)
4444 clone_info=AcquireImageInfo();
4445 if (LocaleNCompare(primitive_info->text,"data:",5) == 0)
4446 composite_image=ReadInlineImage(clone_info,primitive_info->text,
4450 (void) CopyMagickString(clone_info->filename,primitive_info->text,
4452 composite_image=ReadImage(clone_info,&image->exception);
4454 clone_info=DestroyImageInfo(clone_info);
4455 if (composite_image == (Image *) NULL)
4457 (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor)
4458 NULL,(void *) NULL);
4459 x1=(ssize_t) ceil(primitive_info[1].point.x-0.5);
4460 y1=(ssize_t) ceil(primitive_info[1].point.y-0.5);
4461 if (((x1 != 0L) && (x1 != (ssize_t) composite_image->columns)) ||
4462 ((y1 != 0L) && (y1 != (ssize_t) composite_image->rows)))
4465 geometry[MaxTextExtent];
4470 (void) FormatMagickString(geometry,MaxTextExtent,"%gx%g!",
4471 primitive_info[1].point.x,primitive_info[1].point.y);
4472 composite_image->filter=image->filter;
4473 (void) TransformImage(&composite_image,(char *) NULL,geometry);
4475 if (composite_image->matte == MagickFalse)
4476 (void) SetImageAlphaChannel(composite_image,OpaqueAlphaChannel);
4477 if (draw_info->opacity != OpaqueOpacity)
4478 (void) SetImageOpacity(composite_image,draw_info->opacity);
4479 SetGeometry(image,&geometry);
4480 image->gravity=draw_info->gravity;
4483 (void) FormatMagickString(composite_geometry,MaxTextExtent,
4484 "%.20gx%.20g%+.20g%+.20g",(double) composite_image->columns,(double)
4485 composite_image->rows,(double) geometry.x,(double) geometry.y);
4486 (void) ParseGravityGeometry(image,composite_geometry,&geometry,
4488 affine=draw_info->affine;
4489 affine.tx=(double) geometry.x;
4490 affine.ty=(double) geometry.y;
4491 composite_image->interpolate=image->interpolate;
4492 if (draw_info->compose == OverCompositeOp)
4493 (void) DrawAffineImage(image,composite_image,&affine);
4495 (void) CompositeImage(image,draw_info->compose,composite_image,
4496 geometry.x,geometry.y);
4497 composite_image=DestroyImage(composite_image);
4509 if (IsEventLogging() != MagickFalse)
4510 LogPrimitiveInfo(primitive_info);
4511 scale=ExpandAffine(&draw_info->affine);
4512 if ((draw_info->dash_pattern != (double *) NULL) &&
4513 (draw_info->dash_pattern[0] != 0.0) &&
4514 ((scale*draw_info->stroke_width) > MagickEpsilon) &&
4515 (draw_info->stroke.opacity != (Quantum) TransparentOpacity))
4520 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4521 clone_info->stroke_width=0.0;
4522 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4523 status=DrawPolygonPrimitive(image,clone_info,primitive_info);
4524 clone_info=DestroyDrawInfo(clone_info);
4525 (void) DrawDashPolygon(draw_info,primitive_info,image);
4528 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
4530 (draw_info->stroke.opacity != (Quantum) TransparentOpacity))
4536 Draw strokes while respecting line cap/join attributes.
4538 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
4540 (primitive_info[i-1].point.x == primitive_info[0].point.x) &&
4541 (primitive_info[i-1].point.y == primitive_info[0].point.y) ?
4542 MagickTrue : MagickFalse;
4543 i=(ssize_t) primitive_info[0].coordinates;
4544 if ((((draw_info->linecap == RoundCap) ||
4545 (closed_path != MagickFalse)) &&
4546 (draw_info->linejoin == RoundJoin)) ||
4547 (primitive_info[i].primitive != UndefinedPrimitive))
4549 (void) DrawPolygonPrimitive(image,draw_info,primitive_info);
4552 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4553 clone_info->stroke_width=0.0;
4554 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4555 status=DrawPolygonPrimitive(image,clone_info,primitive_info);
4556 clone_info=DestroyDrawInfo(clone_info);
4557 status|=DrawStrokePolygon(image,draw_info,primitive_info);
4560 status=DrawPolygonPrimitive(image,draw_info,primitive_info);
4564 image_view=DestroyCacheView(image_view);
4565 if (image->debug != MagickFalse)
4566 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-primitive");
4567 return(status != 0 ? MagickTrue : MagickFalse);
4571 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4575 + D r a w S t r o k e P o l y g o n %
4579 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4581 % DrawStrokePolygon() draws a stroked polygon (line, rectangle, ellipse) on
4582 % the image while respecting the line cap and join attributes.
4584 % The format of the DrawStrokePolygon method is:
4586 % MagickBooleanType DrawStrokePolygon(Image *image,
4587 % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4589 % A description of each parameter follows:
4591 % o image: the image.
4593 % o draw_info: the draw info.
4595 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
4600 static void DrawRoundLinecap(Image *image,const DrawInfo *draw_info,
4601 const PrimitiveInfo *primitive_info)
4609 for (i=0; i < 4; i++)
4610 linecap[i]=(*primitive_info);
4611 linecap[0].coordinates=4;
4612 linecap[1].point.x+=(double) (10.0*MagickEpsilon);
4613 linecap[2].point.x+=(double) (10.0*MagickEpsilon);
4614 linecap[2].point.y+=(double) (10.0*MagickEpsilon);
4615 linecap[3].point.y+=(double) (10.0*MagickEpsilon);
4616 linecap[4].primitive=UndefinedPrimitive;
4617 (void) DrawPolygonPrimitive(image,draw_info,linecap);
4620 static MagickBooleanType DrawStrokePolygon(Image *image,
4621 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4633 register const PrimitiveInfo
4638 Draw stroked polygon.
4640 if (image->debug != MagickFalse)
4641 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4642 " begin draw-stroke-polygon");
4643 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4644 clone_info->fill=draw_info->stroke;
4645 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4646 clone_info->stroke_width=0.0;
4647 clone_info->fill_rule=NonZeroRule;
4649 for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=p->coordinates)
4651 stroke_polygon=TraceStrokePolygon(draw_info,p);
4652 status=DrawPolygonPrimitive(image,clone_info,stroke_polygon);
4653 stroke_polygon=(PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon);
4654 q=p+p->coordinates-1;
4655 closed_path=(q->point.x == p->point.x) && (q->point.y == p->point.y) ?
4656 MagickTrue : MagickFalse;
4657 if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse))
4659 DrawRoundLinecap(image,draw_info,p);
4660 DrawRoundLinecap(image,draw_info,q);
4663 clone_info=DestroyDrawInfo(clone_info);
4664 if (image->debug != MagickFalse)
4665 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4666 " end draw-stroke-polygon");
4671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4675 % G e t A f f i n e M a t r i x %
4679 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4681 % GetAffineMatrix() returns an AffineMatrix initialized to the identity
4684 % The format of the GetAffineMatrix method is:
4686 % void GetAffineMatrix(AffineMatrix *affine_matrix)
4688 % A description of each parameter follows:
4690 % o affine_matrix: the affine matrix.
4693 MagickExport void GetAffineMatrix(AffineMatrix *affine_matrix)
4695 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4696 assert(affine_matrix != (AffineMatrix *) NULL);
4697 (void) ResetMagickMemory(affine_matrix,0,sizeof(*affine_matrix));
4698 affine_matrix->sx=1.0;
4699 affine_matrix->sy=1.0;
4703 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4707 + G e t D r a w I n f o %
4711 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4713 % GetDrawInfo() initializes draw_info to default values.
4715 % The format of the GetDrawInfo method is:
4717 % void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info)
4719 % A description of each parameter follows:
4721 % o image_info: the image info..
4723 % o draw_info: the draw info.
4726 MagickExport void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info)
4738 Initialize draw attributes.
4740 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4741 assert(draw_info != (DrawInfo *) NULL);
4742 (void) ResetMagickMemory(draw_info,0,sizeof(*draw_info));
4743 clone_info=CloneImageInfo(image_info);
4744 GetAffineMatrix(&draw_info->affine);
4745 exception=AcquireExceptionInfo();
4746 (void) QueryColorDatabase("#000F",&draw_info->fill,exception);
4747 (void) QueryColorDatabase("#FFF0",&draw_info->stroke,exception);
4748 draw_info->stroke_antialias=clone_info->antialias;
4749 draw_info->stroke_width=1.0;
4750 draw_info->opacity=OpaqueOpacity;
4751 draw_info->fill_rule=EvenOddRule;
4752 draw_info->linecap=ButtCap;
4753 draw_info->linejoin=MiterJoin;
4754 draw_info->miterlimit=10;
4755 draw_info->decorate=NoDecoration;
4756 if (clone_info->font != (char *) NULL)
4757 draw_info->font=AcquireString(clone_info->font);
4758 if (clone_info->density != (char *) NULL)
4759 draw_info->density=AcquireString(clone_info->density);
4760 draw_info->text_antialias=clone_info->antialias;
4761 draw_info->pointsize=12.0;
4762 if (clone_info->pointsize != 0.0)
4763 draw_info->pointsize=clone_info->pointsize;
4764 draw_info->undercolor.opacity=(Quantum) TransparentOpacity;
4765 draw_info->border_color=clone_info->border_color;
4766 draw_info->compose=OverCompositeOp;
4767 if (clone_info->server_name != (char *) NULL)
4768 draw_info->server_name=AcquireString(clone_info->server_name);
4769 draw_info->render=MagickTrue;
4770 draw_info->debug=IsEventLogging();
4771 option=GetImageOption(clone_info,"encoding");
4772 if (option != (const char *) NULL)
4773 (void) CloneString(&draw_info->encoding,option);
4774 option=GetImageOption(clone_info,"kerning");
4775 if (option != (const char *) NULL)
4776 draw_info->kerning=StringToDouble(option);
4777 option=GetImageOption(clone_info,"interline-spacing");
4778 if (option != (const char *) NULL)
4779 draw_info->interline_spacing=StringToDouble(option);
4780 draw_info->direction=UndefinedDirection;
4781 option=GetImageOption(clone_info,"interword-spacing");
4782 if (option != (const char *) NULL)
4783 draw_info->interword_spacing=StringToDouble(option);
4784 option=GetImageOption(clone_info,"direction");
4785 if (option != (const char *) NULL)
4786 draw_info->direction=(DirectionType) ParseMagickOption(
4787 MagickDirectionOptions,MagickFalse,option);
4788 option=GetImageOption(clone_info,"fill");
4789 if (option != (const char *) NULL)
4790 (void) QueryColorDatabase(option,&draw_info->fill,exception);
4791 option=GetImageOption(clone_info,"stroke");
4792 if (option != (const char *) NULL)
4793 (void) QueryColorDatabase(option,&draw_info->stroke,exception);
4794 option=GetImageOption(clone_info,"strokewidth");
4795 if (option != (const char *) NULL)
4796 draw_info->stroke_width=StringToDouble(option);
4797 option=GetImageOption(clone_info,"undercolor");
4798 if (option != (const char *) NULL)
4799 (void) QueryColorDatabase(option,&draw_info->undercolor,exception);
4800 option=GetImageOption(clone_info,"gravity");
4801 if (option != (const char *) NULL)
4802 draw_info->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
4803 MagickFalse,option);
4804 exception=DestroyExceptionInfo(exception);
4805 draw_info->signature=MagickSignature;
4806 clone_info=DestroyImageInfo(clone_info);
4810 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4814 + P e r m u t a t e %
4818 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4820 % Permutate() returns the permuation of the (n,k).
4822 % The format of the Permutate method is:
4824 % void Permutate(ssize_t n,ssize_t k)
4826 % A description of each parameter follows:
4834 static inline MagickRealType Permutate(const ssize_t n,const ssize_t k)
4843 for (i=k+1; i <= n; i++)
4845 for (i=1; i <= (n-k); i++)
4851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4855 + T r a c e P r i m i t i v e %
4859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4861 % TracePrimitive is a collection of methods for generating graphic
4862 % primitives such as arcs, ellipses, paths, etc.
4866 static void TraceArc(PrimitiveInfo *primitive_info,const PointInfo start,
4867 const PointInfo end,const PointInfo degrees)
4873 center.x=0.5*(end.x+start.x);
4874 center.y=0.5*(end.y+start.y);
4875 radii.x=fabs(center.x-start.x);
4876 radii.y=fabs(center.y-start.y);
4877 TraceEllipse(primitive_info,center,radii,degrees);
4880 static void TraceArcPath(PrimitiveInfo *primitive_info,const PointInfo start,
4881 const PointInfo end,const PointInfo arc,const MagickRealType angle,
4882 const MagickBooleanType large_arc,const MagickBooleanType sweep)
4897 register MagickRealType
4901 register PrimitiveInfo
4910 if ((start.x == end.x) && (start.y == end.y))
4912 TracePoint(primitive_info,end);
4915 radii.x=fabs(arc.x);
4916 radii.y=fabs(arc.y);
4917 if ((radii.x == 0.0) || (radii.y == 0.0))
4919 TraceLine(primitive_info,start,end);
4922 cosine=cos(DegreesToRadians(fmod((double) angle,360.0)));
4923 sine=sin(DegreesToRadians(fmod((double) angle,360.0)));
4924 center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2);
4925 center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2);
4926 delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/
4928 if (delta < MagickEpsilon)
4930 TraceLine(primitive_info,start,end);
4935 radii.x*=sqrt((double) delta);
4936 radii.y*=sqrt((double) delta);
4938 points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x);
4939 points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y);
4940 points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x);
4941 points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y);
4942 alpha=points[1].x-points[0].x;
4943 beta=points[1].y-points[0].y;
4944 factor=1.0/(alpha*alpha+beta*beta)-0.25;
4949 factor=sqrt((double) factor);
4950 if (sweep == large_arc)
4953 center.x=(double) ((points[0].x+points[1].x)/2-factor*beta);
4954 center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha);
4955 alpha=atan2(points[0].y-center.y,points[0].x-center.x);
4956 theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha;
4957 if ((theta < 0.0) && (sweep != MagickFalse))
4958 theta+=(MagickRealType) (2.0*MagickPI);
4960 if ((theta > 0.0) && (sweep == MagickFalse))
4961 theta-=(MagickRealType) (2.0*MagickPI);
4962 arc_segments=(size_t) ceil(fabs((double) (theta/(0.5*MagickPI+
4965 for (i=0; i < (ssize_t) arc_segments; i++)
4967 beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments));
4968 gamma=(8.0/3.0)*sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))*
4969 sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))/
4970 sin(fmod((double) beta,DegreesToRadians(360.0)));
4971 points[0].x=(double) (center.x+cos(fmod((double) (alpha+(double) i*theta/
4972 arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((double) (alpha+
4973 (double) i*theta/arc_segments),DegreesToRadians(360.0))));
4974 points[0].y=(double) (center.y+sin(fmod((double) (alpha+(double) i*theta/
4975 arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((double) (alpha+
4976 (double) i*theta/arc_segments),DegreesToRadians(360.0))));
4977 points[2].x=(double) (center.x+cos(fmod((double) (alpha+(double) (i+1)*
4978 theta/arc_segments),DegreesToRadians(360.0))));
4979 points[2].y=(double) (center.y+sin(fmod((double) (alpha+(double) (i+1)*
4980 theta/arc_segments),DegreesToRadians(360.0))));
4981 points[1].x=(double) (points[2].x+gamma*sin(fmod((double) (alpha+(double)
4982 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
4983 points[1].y=(double) (points[2].y-gamma*cos(fmod((double) (alpha+(double)
4984 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
4985 p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x;
4986 p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y;
4987 (p+1)->point.x=(double) (cosine*radii.x*points[0].x-sine*radii.y*
4989 (p+1)->point.y=(double) (sine*radii.x*points[0].x+cosine*radii.y*
4991 (p+2)->point.x=(double) (cosine*radii.x*points[1].x-sine*radii.y*
4993 (p+2)->point.y=(double) (sine*radii.x*points[1].x+cosine*radii.y*
4995 (p+3)->point.x=(double) (cosine*radii.x*points[2].x-sine*radii.y*
4997 (p+3)->point.y=(double) (sine*radii.x*points[2].x+cosine*radii.y*
4999 if (i == (ssize_t) (arc_segments-1))
5004 primitive_info->coordinates=(size_t) (p-primitive_info);
5005 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5007 p->primitive=primitive_info->primitive;
5012 static void TraceBezier(PrimitiveInfo *primitive_info,
5013 const size_t number_coordinates)
5025 register PrimitiveInfo
5037 Allocate coeficients.
5039 quantum=number_coordinates;
5040 for (i=0; i < (ssize_t) number_coordinates; i++)
5042 for (j=i+1; j < (ssize_t) number_coordinates; j++)
5044 alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x);
5045 if (alpha > (MagickRealType) quantum)
5046 quantum=(size_t) alpha;
5047 alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y);
5048 if (alpha > (MagickRealType) quantum)
5049 quantum=(size_t) alpha;
5052 quantum=(size_t) MagickMin((double) quantum/number_coordinates,
5053 (double) BezierQuantum);
5054 control_points=quantum*number_coordinates;
5055 coefficients=(MagickRealType *) AcquireQuantumMemory((size_t)
5056 number_coordinates,sizeof(*coefficients));
5057 points=(PointInfo *) AcquireQuantumMemory((size_t) control_points,
5059 if ((coefficients == (MagickRealType *) NULL) ||
5060 (points == (PointInfo *) NULL))
5061 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
5063 Compute bezier points.
5065 end=primitive_info[number_coordinates-1].point;
5066 for (i=0; i < (ssize_t) number_coordinates; i++)
5067 coefficients[i]=Permutate((ssize_t) number_coordinates-1,i);
5069 for (i=0; i < (ssize_t) control_points; i++)
5074 alpha=pow((double) (1.0-weight),(double) number_coordinates-1.0);
5075 for (j=0; j < (ssize_t) number_coordinates; j++)
5077 point.x+=alpha*coefficients[j]*p->point.x;
5078 point.y+=alpha*coefficients[j]*p->point.y;
5079 alpha*=weight/(1.0-weight);
5083 weight+=1.0/control_points;
5086 Bezier curves are just short segmented polys.
5089 for (i=0; i < (ssize_t) control_points; i++)
5091 TracePoint(p,points[i]);
5096 primitive_info->coordinates=(size_t) (p-primitive_info);
5097 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5099 p->primitive=primitive_info->primitive;
5102 points=(PointInfo *) RelinquishMagickMemory(points);
5103 coefficients=(MagickRealType *) RelinquishMagickMemory(coefficients);
5106 static void TraceCircle(PrimitiveInfo *primitive_info,const PointInfo start,
5107 const PointInfo end)
5118 alpha=end.x-start.x;
5120 radius=hypot((double) alpha,(double) beta);
5121 offset.x=(double) radius;
5122 offset.y=(double) radius;
5125 TraceEllipse(primitive_info,start,offset,degrees);
5128 static void TraceEllipse(PrimitiveInfo *primitive_info,const PointInfo start,
5129 const PointInfo stop,const PointInfo degrees)
5140 register PrimitiveInfo
5147 Ellipses are just short segmented polys.
5149 if ((stop.x == 0.0) && (stop.y == 0.0))
5151 TracePoint(primitive_info,start);
5154 delta=2.0/MagickMax(stop.x,stop.y);
5155 step=(MagickRealType) (MagickPI/8.0);
5156 if ((delta >= 0.0) && (delta < (MagickPI/8.0)))
5157 step=MagickPI/(4*(MagickPI/delta/2+0.5));
5158 angle.x=DegreesToRadians(degrees.x);
5160 while (y < degrees.x)
5162 angle.y=(double) (DegreesToRadians(y)-MagickEpsilon);
5163 for (p=primitive_info; angle.x < angle.y; angle.x+=step)
5165 point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*stop.x+start.x;
5166 point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*stop.y+start.y;
5167 TracePoint(p,point);
5170 point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*stop.x+start.x;
5171 point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*stop.y+start.y;
5172 TracePoint(p,point);
5174 primitive_info->coordinates=(size_t) (p-primitive_info);
5175 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5177 p->primitive=primitive_info->primitive;
5182 static void TraceLine(PrimitiveInfo *primitive_info,const PointInfo start,
5183 const PointInfo end)
5185 TracePoint(primitive_info,start);
5186 if ((fabs(start.x-end.x) <= MagickEpsilon) &&
5187 (fabs(start.y-end.y) <= MagickEpsilon))
5189 primitive_info->primitive=PointPrimitive;
5190 primitive_info->coordinates=1;
5193 TracePoint(primitive_info+1,end);
5194 (primitive_info+1)->primitive=primitive_info->primitive;
5195 primitive_info->coordinates=2;
5198 static size_t TracePath(PrimitiveInfo *primitive_info,const char *path)
5201 token[MaxTextExtent];
5223 register PrimitiveInfo
5238 number_coordinates=0;
5240 primitive_type=primitive_info->primitive;
5242 for (p=path; *p != '\0'; )
5244 while (isspace((int) ((unsigned char) *p)) != 0)
5248 last_attribute=attribute;
5249 attribute=(int) (*p++);
5270 GetMagickToken(p,&p,token);
5272 GetMagickToken(p,&p,token);
5273 arc.x=StringToDouble(token);
5274 GetMagickToken(p,&p,token);
5276 GetMagickToken(p,&p,token);
5277 arc.y=StringToDouble(token);
5278 GetMagickToken(p,&p,token);
5280 GetMagickToken(p,&p,token);
5281 angle=StringToDouble(token);
5282 GetMagickToken(p,&p,token);
5284 GetMagickToken(p,&p,token);
5285 large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
5286 GetMagickToken(p,&p,token);
5288 GetMagickToken(p,&p,token);
5289 sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
5290 GetMagickToken(p,&p,token);
5292 GetMagickToken(p,&p,token);
5293 x=StringToDouble(token);
5294 GetMagickToken(p,&p,token);
5296 GetMagickToken(p,&p,token);
5297 y=StringToDouble(token);
5298 end.x=(double) (attribute == (int) 'A' ? x : point.x+x);
5299 end.y=(double) (attribute == (int) 'A' ? y : point.y+y);
5300 TraceArcPath(q,point,end,arc,angle,large_arc,sweep);
5303 } while (IsPoint(p) != MagickFalse);
5310 Compute bezier points.
5315 for (i=1; i < 4; i++)
5317 GetMagickToken(p,&p,token);
5319 GetMagickToken(p,&p,token);
5320 x=StringToDouble(token);
5321 GetMagickToken(p,&p,token);
5323 GetMagickToken(p,&p,token);
5324 y=StringToDouble(token);
5325 end.x=(double) (attribute == (int) 'C' ? x : point.x+x);
5326 end.y=(double) (attribute == (int) 'C' ? y : point.y+y);
5329 for (i=0; i < 4; i++)
5330 (q+i)->point=points[i];
5334 } while (IsPoint(p) != MagickFalse);
5342 GetMagickToken(p,&p,token);
5344 GetMagickToken(p,&p,token);
5345 x=StringToDouble(token);
5346 point.x=(double) (attribute == (int) 'H' ? x: point.x+x);
5347 TracePoint(q,point);
5349 } while (IsPoint(p) != MagickFalse);
5357 GetMagickToken(p,&p,token);
5359 GetMagickToken(p,&p,token);
5360 x=StringToDouble(token);
5361 GetMagickToken(p,&p,token);
5363 GetMagickToken(p,&p,token);
5364 y=StringToDouble(token);
5365 point.x=(double) (attribute == (int) 'L' ? x : point.x+x);
5366 point.y=(double) (attribute == (int) 'L' ? y : point.y+y);
5367 TracePoint(q,point);
5369 } while (IsPoint(p) != MagickFalse);
5375 if (q != primitive_info)
5377 primitive_info->coordinates=(size_t) (q-primitive_info);
5378 number_coordinates+=primitive_info->coordinates;
5384 GetMagickToken(p,&p,token);
5386 GetMagickToken(p,&p,token);
5387 x=StringToDouble(token);
5388 GetMagickToken(p,&p,token);
5390 GetMagickToken(p,&p,token);
5391 y=StringToDouble(token);
5392 point.x=(double) (attribute == (int) 'M' ? x : point.x+x);
5393 point.y=(double) (attribute == (int) 'M' ? y : point.y+y);
5397 TracePoint(q,point);
5399 if ((i != 0) && (attribute == (int) 'M'))
5401 TracePoint(q,point);
5404 } while (IsPoint(p) != MagickFalse);
5411 Compute bezier points.
5416 for (i=1; i < 3; i++)
5418 GetMagickToken(p,&p,token);
5420 GetMagickToken(p,&p,token);
5421 x=StringToDouble(token);
5422 GetMagickToken(p,&p,token);
5424 GetMagickToken(p,&p,token);
5425 y=StringToDouble(token);
5428 end.x=(double) (attribute == (int) 'Q' ? x : point.x+x);
5429 end.y=(double) (attribute == (int) 'Q' ? y : point.y+y);
5432 for (i=0; i < 3; i++)
5433 (q+i)->point=points[i];
5437 } while (IsPoint(p) != MagickFalse);
5444 Compute bezier points.
5448 points[0]=points[3];
5449 points[1].x=2.0*points[3].x-points[2].x;
5450 points[1].y=2.0*points[3].y-points[2].y;
5451 for (i=2; i < 4; i++)
5453 GetMagickToken(p,&p,token);
5455 GetMagickToken(p,&p,token);
5456 x=StringToDouble(token);
5457 GetMagickToken(p,&p,token);
5459 GetMagickToken(p,&p,token);
5460 y=StringToDouble(token);
5463 end.x=(double) (attribute == (int) 'S' ? x : point.x+x);
5464 end.y=(double) (attribute == (int) 'S' ? y : point.y+y);
5467 if (strchr("CcSs",last_attribute) == (char *) NULL)
5469 points[0]=points[2];
5470 points[1]=points[3];
5472 for (i=0; i < 4; i++)
5473 (q+i)->point=points[i];
5477 } while (IsPoint(p) != MagickFalse);
5484 Compute bezier points.
5488 points[0]=points[2];
5489 points[1].x=2.0*points[2].x-points[1].x;
5490 points[1].y=2.0*points[2].y-points[1].y;
5491 for (i=2; i < 3; i++)
5493 GetMagickToken(p,&p,token);
5495 GetMagickToken(p,&p,token);
5496 x=StringToDouble(token);
5497 GetMagickToken(p,&p,token);
5499 GetMagickToken(p,&p,token);
5500 y=StringToDouble(token);
5501 end.x=(double) (attribute == (int) 'T' ? x : point.x+x);
5502 end.y=(double) (attribute == (int) 'T' ? y : point.y+y);
5505 if (strchr("QqTt",last_attribute) == (char *) NULL)
5507 points[0]=points[2];
5508 points[1]=points[3];
5510 for (i=0; i < 3; i++)
5511 (q+i)->point=points[i];
5515 } while (IsPoint(p) != MagickFalse);
5523 GetMagickToken(p,&p,token);
5525 GetMagickToken(p,&p,token);
5526 y=StringToDouble(token);
5527 point.y=(double) (attribute == (int) 'V' ? y : point.y+y);
5528 TracePoint(q,point);
5530 } while (IsPoint(p) != MagickFalse);
5537 TracePoint(q,point);
5539 primitive_info->coordinates=(size_t) (q-primitive_info);
5540 number_coordinates+=primitive_info->coordinates;
5547 if (isalpha((int) ((unsigned char) attribute)) != 0)
5548 (void) fprintf(stderr,"attribute not recognized: %c\n",attribute);
5553 primitive_info->coordinates=(size_t) (q-primitive_info);
5554 number_coordinates+=primitive_info->coordinates;
5555 for (i=0; i < (ssize_t) number_coordinates; i++)
5558 q->primitive=primitive_type;
5560 q->method=FillToBorderMethod;
5563 return(number_coordinates);
5566 static void TraceRectangle(PrimitiveInfo *primitive_info,const PointInfo start,
5567 const PointInfo end)
5572 register PrimitiveInfo
5579 TracePoint(p,start);
5583 TracePoint(p,point);
5589 TracePoint(p,point);
5591 TracePoint(p,start);
5593 primitive_info->coordinates=(size_t) (p-primitive_info);
5594 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5596 p->primitive=primitive_info->primitive;
5601 static void TraceRoundRectangle(PrimitiveInfo *primitive_info,
5602 const PointInfo start,const PointInfo end,PointInfo arc)
5609 register PrimitiveInfo
5616 offset.x=fabs(end.x-start.x);
5617 offset.y=fabs(end.y-start.y);
5618 if (arc.x > (0.5*offset.x))
5620 if (arc.y > (0.5*offset.y))
5622 point.x=start.x+offset.x-arc.x;
5623 point.y=start.y+arc.y;
5626 TraceEllipse(p,point,arc,degrees);
5628 point.x=start.x+offset.x-arc.x;
5629 point.y=start.y+offset.y-arc.y;
5632 TraceEllipse(p,point,arc,degrees);
5634 point.x=start.x+arc.x;
5635 point.y=start.y+offset.y-arc.y;
5638 TraceEllipse(p,point,arc,degrees);
5640 point.x=start.x+arc.x;
5641 point.y=start.y+arc.y;
5644 TraceEllipse(p,point,arc,degrees);
5646 TracePoint(p,primitive_info->point);
5648 primitive_info->coordinates=(size_t) (p-primitive_info);
5649 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5651 p->primitive=primitive_info->primitive;
5656 static void TraceSquareLinecap(PrimitiveInfo *primitive_info,
5657 const size_t number_vertices,const MagickRealType offset)
5662 register MagickRealType
5674 for (i=1; i < (ssize_t) number_vertices; i++)
5676 dx=primitive_info[0].point.x-primitive_info[i].point.x;
5677 dy=primitive_info[0].point.y-primitive_info[i].point.y;
5678 if ((fabs((double) dx) >= MagickEpsilon) ||
5679 (fabs((double) dy) >= MagickEpsilon))
5682 if (i == (ssize_t) number_vertices)
5683 i=(ssize_t) number_vertices-1L;
5684 distance=hypot((double) dx,(double) dy);
5685 primitive_info[0].point.x=(double) (primitive_info[i].point.x+
5686 dx*(distance+offset)/distance);
5687 primitive_info[0].point.y=(double) (primitive_info[i].point.y+
5688 dy*(distance+offset)/distance);
5689 for (j=(ssize_t) number_vertices-2; j >= 0; j--)
5691 dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x;
5692 dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y;
5693 if ((fabs((double) dx) >= MagickEpsilon) ||
5694 (fabs((double) dy) >= MagickEpsilon))
5697 distance=hypot((double) dx,(double) dy);
5698 primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+
5699 dx*(distance+offset)/distance);
5700 primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+
5701 dy*(distance+offset)/distance);
5704 static PrimitiveInfo *TraceStrokePolygon(const DrawInfo *draw_info,
5705 const PrimitiveInfo *primitive_info)
5707 typedef struct _LineSegment
5759 number_vertices=primitive_info->coordinates;
5760 max_strokes=2*number_vertices+6*BezierQuantum+360;
5761 path_p=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes,
5763 path_q=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes,
5765 polygon_primitive=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
5766 number_vertices+2UL,sizeof(*polygon_primitive));
5767 if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL) ||
5768 (polygon_primitive == (PrimitiveInfo *) NULL))
5769 return((PrimitiveInfo *) NULL);
5770 (void) CopyMagickMemory(polygon_primitive,primitive_info,(size_t)
5771 number_vertices*sizeof(*polygon_primitive));
5773 (primitive_info[number_vertices-1].point.x == primitive_info[0].point.x) &&
5774 (primitive_info[number_vertices-1].point.y == primitive_info[0].point.y) ?
5775 MagickTrue : MagickFalse;
5776 if ((draw_info->linejoin == RoundJoin) ||
5777 ((draw_info->linejoin == MiterJoin) && (closed_path != MagickFalse)))
5779 polygon_primitive[number_vertices]=primitive_info[1];
5782 polygon_primitive[number_vertices].primitive=UndefinedPrimitive;
5784 Compute the slope for the first line segment, p.
5788 for (n=1; n < (ssize_t) number_vertices; n++)
5790 dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x;
5791 dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y;
5792 if ((fabs(dx.p) >= MagickEpsilon) || (fabs(dy.p) >= MagickEpsilon))
5795 if (n == (ssize_t) number_vertices)
5796 n=(ssize_t) number_vertices-1L;
5798 inverse_slope.p=0.0;
5799 if (fabs(dx.p) <= MagickEpsilon)
5802 slope.p=dy.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5804 slope.p=dy.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5807 if (fabs(dy.p) <= MagickEpsilon)
5810 inverse_slope.p=dx.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5812 inverse_slope.p=dx.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5817 inverse_slope.p=(-1.0/slope.p);
5819 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5820 miterlimit=(MagickRealType) (draw_info->miterlimit*draw_info->miterlimit*
5822 if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse))
5823 TraceSquareLinecap(polygon_primitive,number_vertices,mid);
5824 offset.x=sqrt((double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0)));
5825 offset.y=(double) (offset.x*inverse_slope.p);
5826 if ((dy.p*offset.x-dx.p*offset.y) > 0.0)
5828 box_p[0].x=polygon_primitive[0].point.x-offset.x;
5829 box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p;
5830 box_p[1].x=polygon_primitive[n].point.x-offset.x;
5831 box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p;
5832 box_q[0].x=polygon_primitive[0].point.x+offset.x;
5833 box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p;
5834 box_q[1].x=polygon_primitive[n].point.x+offset.x;
5835 box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p;
5839 box_p[0].x=polygon_primitive[0].point.x+offset.x;
5840 box_p[0].y=polygon_primitive[0].point.y+offset.y;
5841 box_p[1].x=polygon_primitive[n].point.x+offset.x;
5842 box_p[1].y=polygon_primitive[n].point.y+offset.y;
5843 box_q[0].x=polygon_primitive[0].point.x-offset.x;
5844 box_q[0].y=polygon_primitive[0].point.y-offset.y;
5845 box_q[1].x=polygon_primitive[n].point.x-offset.x;
5846 box_q[1].y=polygon_primitive[n].point.y-offset.y;
5849 Create strokes for the line join attribute: bevel, miter, round.
5853 path_q[p++]=box_q[0];
5854 path_p[q++]=box_p[0];
5855 for (i=(ssize_t) n+1; i < (ssize_t) number_vertices; i++)
5858 Compute the slope for this line segment, q.
5860 dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x;
5861 dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y;
5862 dot_product=dx.q*dx.q+dy.q*dy.q;
5863 if (dot_product < 0.25)
5866 inverse_slope.q=0.0;
5867 if (fabs(dx.q) < MagickEpsilon)
5870 slope.q=dy.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5872 slope.q=dy.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5875 if (fabs(dy.q) <= MagickEpsilon)
5878 inverse_slope.q=dx.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5880 inverse_slope.q=dx.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5885 inverse_slope.q=(-1.0/slope.q);
5887 offset.x=sqrt((double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0)));
5888 offset.y=(double) (offset.x*inverse_slope.q);
5889 dot_product=dy.q*offset.x-dx.q*offset.y;
5890 if (dot_product > 0.0)
5892 box_p[2].x=polygon_primitive[n].point.x-offset.x;
5893 box_p[2].y=polygon_primitive[n].point.y-offset.y;
5894 box_p[3].x=polygon_primitive[i].point.x-offset.x;
5895 box_p[3].y=polygon_primitive[i].point.y-offset.y;
5896 box_q[2].x=polygon_primitive[n].point.x+offset.x;
5897 box_q[2].y=polygon_primitive[n].point.y+offset.y;
5898 box_q[3].x=polygon_primitive[i].point.x+offset.x;
5899 box_q[3].y=polygon_primitive[i].point.y+offset.y;
5903 box_p[2].x=polygon_primitive[n].point.x+offset.x;
5904 box_p[2].y=polygon_primitive[n].point.y+offset.y;
5905 box_p[3].x=polygon_primitive[i].point.x+offset.x;
5906 box_p[3].y=polygon_primitive[i].point.y+offset.y;
5907 box_q[2].x=polygon_primitive[n].point.x-offset.x;
5908 box_q[2].y=polygon_primitive[n].point.y-offset.y;
5909 box_q[3].x=polygon_primitive[i].point.x-offset.x;
5910 box_q[3].y=polygon_primitive[i].point.y-offset.y;
5912 if (fabs((double) (slope.p-slope.q)) <= MagickEpsilon)
5919 box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+
5920 box_p[3].y)/(slope.p-slope.q));
5921 box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y);
5922 box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+
5923 box_q[3].y)/(slope.p-slope.q));
5924 box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y);
5926 if (q >= (ssize_t) (max_strokes-6*BezierQuantum-360))
5928 max_strokes+=6*BezierQuantum+360;
5929 path_p=(PointInfo *) ResizeQuantumMemory(path_p,(size_t) max_strokes,
5931 path_q=(PointInfo *) ResizeQuantumMemory(path_q,(size_t) max_strokes,
5933 if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL))
5935 polygon_primitive=(PrimitiveInfo *)
5936 RelinquishMagickMemory(polygon_primitive);
5937 return((PrimitiveInfo *) NULL);
5940 dot_product=dx.q*dy.p-dx.p*dy.q;
5941 if (dot_product <= 0.0)
5942 switch (draw_info->linejoin)
5946 path_q[q++]=box_q[1];
5947 path_q[q++]=box_q[2];
5948 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5949 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5950 if (dot_product <= miterlimit)
5951 path_p[p++]=box_p[4];
5954 path_p[p++]=box_p[1];
5955 path_p[p++]=box_p[2];
5961 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5962 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5963 if (dot_product <= miterlimit)
5965 path_q[q++]=box_q[4];
5966 path_p[p++]=box_p[4];
5970 path_q[q++]=box_q[1];
5971 path_q[q++]=box_q[2];
5972 path_p[p++]=box_p[1];
5973 path_p[p++]=box_p[2];
5979 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5980 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5981 if (dot_product <= miterlimit)
5982 path_p[p++]=box_p[4];
5985 path_p[p++]=box_p[1];
5986 path_p[p++]=box_p[2];
5988 center=polygon_primitive[n].point;
5989 theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x);
5990 theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x);
5991 if (theta.q < theta.p)
5992 theta.q+=(MagickRealType) (2.0*MagickPI);
5993 arc_segments=(size_t) ceil((double) ((theta.q-theta.p)/
5994 (2.0*sqrt((double) (1.0/mid)))));
5995 path_q[q].x=box_q[1].x;
5996 path_q[q].y=box_q[1].y;
5998 for (j=1; j < (ssize_t) arc_segments; j++)
6000 delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments);
6001 path_q[q].x=(double) (center.x+mid*cos(fmod((double)
6002 (theta.p+delta_theta),DegreesToRadians(360.0))));
6003 path_q[q].y=(double) (center.y+mid*sin(fmod((double)
6004 (theta.p+delta_theta),DegreesToRadians(360.0))));
6007 path_q[q++]=box_q[2];
6014 switch (draw_info->linejoin)
6018 path_p[p++]=box_p[1];
6019 path_p[p++]=box_p[2];
6020 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6021 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6022 if (dot_product <= miterlimit)
6023 path_q[q++]=box_q[4];
6026 path_q[q++]=box_q[1];
6027 path_q[q++]=box_q[2];
6033 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6034 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6035 if (dot_product <= miterlimit)
6037 path_q[q++]=box_q[4];
6038 path_p[p++]=box_p[4];
6042 path_q[q++]=box_q[1];
6043 path_q[q++]=box_q[2];
6044 path_p[p++]=box_p[1];
6045 path_p[p++]=box_p[2];
6051 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6052 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6053 if (dot_product <= miterlimit)
6054 path_q[q++]=box_q[4];
6057 path_q[q++]=box_q[1];
6058 path_q[q++]=box_q[2];
6060 center=polygon_primitive[n].point;
6061 theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x);
6062 theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x);
6063 if (theta.p < theta.q)
6064 theta.p+=(MagickRealType) (2.0*MagickPI);
6065 arc_segments=(size_t) ceil((double) ((theta.p-theta.q)/
6066 (2.0*sqrt((double) (1.0/mid)))));
6067 path_p[p++]=box_p[1];
6068 for (j=1; j < (ssize_t) arc_segments; j++)
6070 delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments);
6071 path_p[p].x=(double) (center.x+mid*cos(fmod((double)
6072 (theta.p+delta_theta),DegreesToRadians(360.0))));
6073 path_p[p].y=(double) (center.y+mid*sin(fmod((double)
6074 (theta.p+delta_theta),DegreesToRadians(360.0))));
6077 path_p[p++]=box_p[2];
6084 inverse_slope.p=inverse_slope.q;
6093 path_p[p++]=box_p[1];
6094 path_q[q++]=box_q[1];
6096 Trace stroked polygon.
6098 stroke_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
6099 (p+q+2UL*closed_path+2UL),sizeof(*stroke_polygon));
6100 if (stroke_polygon != (PrimitiveInfo *) NULL)
6102 for (i=0; i < (ssize_t) p; i++)
6104 stroke_polygon[i]=polygon_primitive[0];
6105 stroke_polygon[i].point=path_p[i];
6107 if (closed_path != MagickFalse)
6109 stroke_polygon[i]=polygon_primitive[0];
6110 stroke_polygon[i].point=stroke_polygon[0].point;
6113 for ( ; i < (ssize_t) (p+q+closed_path); i++)
6115 stroke_polygon[i]=polygon_primitive[0];
6116 stroke_polygon[i].point=path_q[p+q+closed_path-(i+1)];
6118 if (closed_path != MagickFalse)
6120 stroke_polygon[i]=polygon_primitive[0];
6121 stroke_polygon[i].point=stroke_polygon[p+closed_path].point;
6124 stroke_polygon[i]=polygon_primitive[0];
6125 stroke_polygon[i].point=stroke_polygon[0].point;
6127 stroke_polygon[i].primitive=UndefinedPrimitive;
6128 stroke_polygon[0].coordinates=(size_t) (p+q+2*closed_path+1);
6130 path_p=(PointInfo *) RelinquishMagickMemory(path_p);
6131 path_q=(PointInfo *) RelinquishMagickMemory(path_q);
6132 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive);
6133 return(stroke_polygon);