2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 % D D RRRR AAAAA W W W %
13 % MagickCore Image Drawing Methods %
21 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
22 % dedicated to making software imaging solutions freely available. %
24 % You may not use this file except in compliance with the License. You may %
25 % obtain a copy of the License at %
27 % http://www.imagemagick.org/script/license.php %
29 % Unless required by applicable law or agreed to in writing, software %
30 % distributed under the License is distributed on an "AS IS" BASIS, %
31 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
32 % See the License for the specific language governing permissions and %
33 % limitations under the License. %
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 % Bill Radcliffe of Corbis (www.corbis.com) contributed the polygon
38 % rendering code based on Paul Heckbert's "Concave Polygon Scan Conversion",
39 % Graphics Gems, 1990. Leonard Rosenthal and David Harr of Appligent
40 % (www.appligent.com) contributed the dash pattern, linecap stroking
41 % algorithm, and minor rendering improvements.
48 #include "magick/studio.h"
49 #include "magick/annotate.h"
50 #include "magick/artifact.h"
51 #include "magick/blob.h"
52 #include "magick/cache.h"
53 #include "magick/cache-view.h"
54 #include "magick/color.h"
55 #include "magick/composite.h"
56 #include "magick/composite-private.h"
57 #include "magick/constitute.h"
58 #include "magick/draw.h"
59 #include "magick/draw-private.h"
60 #include "magick/enhance.h"
61 #include "magick/exception.h"
62 #include "magick/exception-private.h"
63 #include "magick/gem.h"
64 #include "magick/geometry.h"
65 #include "magick/image-private.h"
66 #include "magick/list.h"
67 #include "magick/log.h"
68 #include "magick/monitor.h"
69 #include "magick/monitor-private.h"
70 #include "magick/option.h"
71 #include "magick/paint.h"
72 #include "magick/pixel-private.h"
73 #include "magick/property.h"
74 #include "magick/resample.h"
75 #include "magick/resample-private.h"
76 #include "magick/string_.h"
77 #include "magick/string-private.h"
78 #include "magick/thread-private.h"
79 #include "magick/token.h"
80 #include "magick/transform.h"
81 #include "magick/utility.h"
86 #define BezierQuantum 200
91 typedef struct _EdgeInfo
115 typedef struct _ElementInfo
125 typedef struct _PolygonInfo
143 typedef struct _PathInfo
153 Forward declarations.
155 static MagickBooleanType
156 DrawStrokePolygon(Image *,const DrawInfo *,const PrimitiveInfo *);
159 *TraceStrokePolygon(const DrawInfo *,const PrimitiveInfo *);
162 TracePath(PrimitiveInfo *,const char *);
165 TraceArc(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo),
166 TraceArcPath(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo,
167 const MagickRealType,const MagickBooleanType,const MagickBooleanType),
168 TraceBezier(PrimitiveInfo *,const size_t),
169 TraceCircle(PrimitiveInfo *,const PointInfo,const PointInfo),
170 TraceEllipse(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo),
171 TraceLine(PrimitiveInfo *,const PointInfo,const PointInfo),
172 TraceRectangle(PrimitiveInfo *,const PointInfo,const PointInfo),
173 TraceRoundRectangle(PrimitiveInfo *,const PointInfo,const PointInfo,
175 TraceSquareLinecap(PrimitiveInfo *,const size_t,const MagickRealType);
178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 % A c q u i r e D r a w I n f o %
186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188 % AcquireDrawInfo() returns a DrawInfo structure properly initialized.
190 % The format of the AcquireDrawInfo method is:
192 % DrawInfo *AcquireDrawInfo(void)
195 MagickExport DrawInfo *AcquireDrawInfo(void)
200 draw_info=(DrawInfo *) AcquireMagickMemory(sizeof(*draw_info));
201 if (draw_info == (DrawInfo *) NULL)
202 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
203 GetDrawInfo((ImageInfo *) NULL,draw_info);
208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212 % C l o n e D r a w I n f o %
216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 % CloneDrawInfo() makes a copy of the given draw info structure. If NULL
219 % is specified, a new image info structure is created initialized to
222 % The format of the CloneDrawInfo method is:
224 % DrawInfo *CloneDrawInfo(const ImageInfo *image_info,
225 % const DrawInfo *draw_info)
227 % A description of each parameter follows:
229 % o image_info: the image info.
231 % o draw_info: the draw info.
234 MagickExport DrawInfo *CloneDrawInfo(const ImageInfo *image_info,
235 const DrawInfo *draw_info)
240 clone_info=(DrawInfo *) AcquireMagickMemory(sizeof(*clone_info));
241 if (clone_info == (DrawInfo *) NULL)
242 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
243 GetDrawInfo(image_info,clone_info);
244 if (draw_info == (DrawInfo *) NULL)
246 if (clone_info->primitive != (char *) NULL)
247 (void) CloneString(&clone_info->primitive,draw_info->primitive);
248 if (draw_info->geometry != (char *) NULL)
249 (void) CloneString(&clone_info->geometry,draw_info->geometry);
250 clone_info->viewbox=draw_info->viewbox;
251 clone_info->affine=draw_info->affine;
252 clone_info->gravity=draw_info->gravity;
253 clone_info->fill=draw_info->fill;
254 clone_info->stroke=draw_info->stroke;
255 clone_info->stroke_width=draw_info->stroke_width;
256 if (draw_info->fill_pattern != (Image *) NULL)
257 clone_info->fill_pattern=CloneImage(draw_info->fill_pattern,0,0,MagickTrue,
258 &draw_info->fill_pattern->exception);
260 if (draw_info->tile != (Image *) NULL)
261 clone_info->fill_pattern=CloneImage(draw_info->tile,0,0,MagickTrue,
262 &draw_info->tile->exception);
263 clone_info->tile=NewImageList(); /* tile is deprecated */
264 if (draw_info->stroke_pattern != (Image *) NULL)
265 clone_info->stroke_pattern=CloneImage(draw_info->stroke_pattern,0,0,
266 MagickTrue,&draw_info->stroke_pattern->exception);
267 clone_info->stroke_antialias=draw_info->stroke_antialias;
268 clone_info->text_antialias=draw_info->text_antialias;
269 clone_info->fill_rule=draw_info->fill_rule;
270 clone_info->linecap=draw_info->linecap;
271 clone_info->linejoin=draw_info->linejoin;
272 clone_info->miterlimit=draw_info->miterlimit;
273 clone_info->dash_offset=draw_info->dash_offset;
274 clone_info->decorate=draw_info->decorate;
275 clone_info->compose=draw_info->compose;
276 if (draw_info->text != (char *) NULL)
277 (void) CloneString(&clone_info->text,draw_info->text);
278 if (draw_info->font != (char *) NULL)
279 (void) CloneString(&clone_info->font,draw_info->font);
280 if (draw_info->metrics != (char *) NULL)
281 (void) CloneString(&clone_info->metrics,draw_info->metrics);
282 if (draw_info->family != (char *) NULL)
283 (void) CloneString(&clone_info->family,draw_info->family);
284 clone_info->style=draw_info->style;
285 clone_info->stretch=draw_info->stretch;
286 clone_info->weight=draw_info->weight;
287 if (draw_info->encoding != (char *) NULL)
288 (void) CloneString(&clone_info->encoding,draw_info->encoding);
289 clone_info->pointsize=draw_info->pointsize;
290 clone_info->kerning=draw_info->kerning;
291 clone_info->interline_spacing=draw_info->interline_spacing;
292 clone_info->interword_spacing=draw_info->interword_spacing;
293 clone_info->direction=draw_info->direction;
294 if (draw_info->density != (char *) NULL)
295 (void) CloneString(&clone_info->density,draw_info->density);
296 clone_info->align=draw_info->align;
297 clone_info->undercolor=draw_info->undercolor;
298 clone_info->border_color=draw_info->border_color;
299 if (draw_info->server_name != (char *) NULL)
300 (void) CloneString(&clone_info->server_name,draw_info->server_name);
301 if (draw_info->dash_pattern != (double *) NULL)
306 for (x=0; draw_info->dash_pattern[x] != 0.0; x++) ;
307 clone_info->dash_pattern=(double *) AcquireQuantumMemory((size_t) x+1UL,
308 sizeof(*clone_info->dash_pattern));
309 if (clone_info->dash_pattern == (double *) NULL)
310 ThrowFatalException(ResourceLimitFatalError,
311 "UnableToAllocateDashPattern");
312 (void) CopyMagickMemory(clone_info->dash_pattern,draw_info->dash_pattern,
313 (size_t) (x+1)*sizeof(*clone_info->dash_pattern));
315 clone_info->gradient=draw_info->gradient;
316 if (draw_info->gradient.stops != (StopInfo *) NULL)
321 number_stops=clone_info->gradient.number_stops;
322 clone_info->gradient.stops=(StopInfo *) AcquireQuantumMemory((size_t)
323 number_stops,sizeof(*clone_info->gradient.stops));
324 if (clone_info->gradient.stops == (StopInfo *) NULL)
325 ThrowFatalException(ResourceLimitFatalError,
326 "UnableToAllocateDashPattern");
327 (void) CopyMagickMemory(clone_info->gradient.stops,
328 draw_info->gradient.stops,(size_t) number_stops*
329 sizeof(*clone_info->gradient.stops));
331 if (draw_info->clip_mask != (char *) NULL)
332 (void) CloneString(&clone_info->clip_mask,draw_info->clip_mask);
333 clone_info->bounds=draw_info->bounds;
334 clone_info->clip_units=draw_info->clip_units;
335 clone_info->render=draw_info->render;
336 clone_info->opacity=draw_info->opacity;
337 clone_info->element_reference=draw_info->element_reference;
338 clone_info->debug=IsEventLogging();
343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
347 + C o n v e r t P a t h T o P o l y g o n %
351 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353 % ConvertPathToPolygon() converts a path to the more efficient sorted
356 % The format of the ConvertPathToPolygon method is:
358 % PolygonInfo *ConvertPathToPolygon(const DrawInfo *draw_info,
359 % const PathInfo *path_info)
361 % A description of each parameter follows:
363 % o Method ConvertPathToPolygon returns the path in a more efficient sorted
364 % rendering form of type PolygonInfo.
366 % o draw_info: Specifies a pointer to an DrawInfo structure.
368 % o path_info: Specifies a pointer to an PathInfo structure.
373 #if defined(__cplusplus) || defined(c_plusplus)
377 static int CompareEdges(const void *x,const void *y)
379 register const EdgeInfo
386 p=(const EdgeInfo *) x;
387 q=(const EdgeInfo *) y;
388 if ((p->points[0].y-MagickEpsilon) > q->points[0].y)
390 if ((p->points[0].y+MagickEpsilon) < q->points[0].y)
392 if ((p->points[0].x-MagickEpsilon) > q->points[0].x)
394 if ((p->points[0].x+MagickEpsilon) < q->points[0].x)
396 if (((p->points[1].x-p->points[0].x)*(q->points[1].y-q->points[0].y)-
397 (p->points[1].y-p->points[0].y)*(q->points[1].x-q->points[0].x)) > 0.0)
402 #if defined(__cplusplus) || defined(c_plusplus)
406 static void LogPolygonInfo(const PolygonInfo *polygon_info)
415 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin active-edge");
416 p=polygon_info->edges;
417 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
419 (void) LogMagickEvent(DrawEvent,GetMagickModule()," edge %.20g:",
421 (void) LogMagickEvent(DrawEvent,GetMagickModule()," direction: %s",
422 p->direction != MagickFalse ? "down" : "up");
423 (void) LogMagickEvent(DrawEvent,GetMagickModule()," ghostline: %s",
424 p->ghostline != MagickFalse ? "transparent" : "opaque");
425 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
426 " bounds: %g,%g - %g,%g",p->bounds.x1,p->bounds.y1,
427 p->bounds.x2,p->bounds.y2);
428 for (j=0; j < (ssize_t) p->number_points; j++)
429 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %g,%g",
430 p->points[j].x,p->points[j].y);
433 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end active-edge");
436 static void ReversePoints(PointInfo *points,const size_t number_points)
444 for (i=0; i < (ssize_t) (number_points >> 1); i++)
447 points[i]=points[number_points-(i+1)];
448 points[number_points-(i+1)]=point;
452 static PolygonInfo *ConvertPathToPolygon(
453 const DrawInfo *magick_unused(draw_info),const PathInfo *path_info)
482 Convert a path to the more efficient sorted rendering form.
484 polygon_info=(PolygonInfo *) AcquireMagickMemory(sizeof(*polygon_info));
485 if (polygon_info == (PolygonInfo *) NULL)
486 return((PolygonInfo *) NULL);
488 polygon_info->edges=(EdgeInfo *) AcquireQuantumMemory((size_t) number_edges,
489 sizeof(*polygon_info->edges));
490 if (polygon_info->edges == (EdgeInfo *) NULL)
491 return((PolygonInfo *) NULL);
494 ghostline=MagickFalse;
497 points=(PointInfo *) NULL;
498 (void) ResetMagickMemory(&point,0,sizeof(point));
499 (void) ResetMagickMemory(&bounds,0,sizeof(bounds));
500 for (i=0; path_info[i].code != EndCode; i++)
502 if ((path_info[i].code == MoveToCode) || (path_info[i].code == OpenCode) ||
503 (path_info[i].code == GhostlineCode))
508 if ((points != (PointInfo *) NULL) && (n >= 2))
510 if (edge == number_edges)
513 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
514 polygon_info->edges,(size_t) number_edges,
515 sizeof(*polygon_info->edges));
516 if (polygon_info->edges == (EdgeInfo *) NULL)
517 return((PolygonInfo *) NULL);
519 polygon_info->edges[edge].number_points=(size_t) n;
520 polygon_info->edges[edge].scanline=(-1.0);
521 polygon_info->edges[edge].highwater=0;
522 polygon_info->edges[edge].ghostline=ghostline;
523 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
525 ReversePoints(points,(size_t) n);
526 polygon_info->edges[edge].points=points;
527 polygon_info->edges[edge].bounds=bounds;
528 polygon_info->edges[edge].bounds.y1=points[0].y;
529 polygon_info->edges[edge].bounds.y2=points[n-1].y;
530 points=(PointInfo *) NULL;
531 ghostline=MagickFalse;
534 if (points == (PointInfo *) NULL)
537 points=(PointInfo *) AcquireQuantumMemory((size_t) number_points,
539 if (points == (PointInfo *) NULL)
540 return((PolygonInfo *) NULL);
542 ghostline=path_info[i].code == GhostlineCode ? MagickTrue : MagickFalse;
543 point=path_info[i].point;
554 next_direction=((path_info[i].point.y > point.y) ||
555 ((path_info[i].point.y == point.y) &&
556 (path_info[i].point.x > point.x))) ? 1 : -1;
557 if ((direction != 0) && (direction != next_direction))
563 if (edge == number_edges)
566 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
567 polygon_info->edges,(size_t) number_edges,
568 sizeof(*polygon_info->edges));
569 if (polygon_info->edges == (EdgeInfo *) NULL)
570 return((PolygonInfo *) NULL);
572 polygon_info->edges[edge].number_points=(size_t) n;
573 polygon_info->edges[edge].scanline=(-1.0);
574 polygon_info->edges[edge].highwater=0;
575 polygon_info->edges[edge].ghostline=ghostline;
576 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
578 ReversePoints(points,(size_t) n);
579 polygon_info->edges[edge].points=points;
580 polygon_info->edges[edge].bounds=bounds;
581 polygon_info->edges[edge].bounds.y1=points[0].y;
582 polygon_info->edges[edge].bounds.y2=points[n-1].y;
584 points=(PointInfo *) AcquireQuantumMemory((size_t) number_points,
586 if (points == (PointInfo *) NULL)
587 return((PolygonInfo *) NULL);
589 ghostline=MagickFalse;
595 direction=next_direction;
596 if (points == (PointInfo *) NULL)
598 if (n == (ssize_t) number_points)
601 points=(PointInfo *) ResizeQuantumMemory(points,(size_t) number_points,
603 if (points == (PointInfo *) NULL)
604 return((PolygonInfo *) NULL);
606 point=path_info[i].point;
608 if (point.x < bounds.x1)
610 if (point.x > bounds.x2)
614 if (points != (PointInfo *) NULL)
617 points=(PointInfo *) RelinquishMagickMemory(points);
620 if (edge == number_edges)
623 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
624 polygon_info->edges,(size_t) number_edges,
625 sizeof(*polygon_info->edges));
626 if (polygon_info->edges == (EdgeInfo *) NULL)
627 return((PolygonInfo *) NULL);
629 polygon_info->edges[edge].number_points=(size_t) n;
630 polygon_info->edges[edge].scanline=(-1.0);
631 polygon_info->edges[edge].highwater=0;
632 polygon_info->edges[edge].ghostline=ghostline;
633 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
635 ReversePoints(points,(size_t) n);
636 polygon_info->edges[edge].points=points;
637 polygon_info->edges[edge].bounds=bounds;
638 polygon_info->edges[edge].bounds.y1=points[0].y;
639 polygon_info->edges[edge].bounds.y2=points[n-1].y;
640 ghostline=MagickFalse;
644 polygon_info->number_edges=edge;
645 qsort(polygon_info->edges,(size_t) polygon_info->number_edges,
646 sizeof(*polygon_info->edges),CompareEdges);
647 if (IsEventLogging() != MagickFalse)
648 LogPolygonInfo(polygon_info);
649 return(polygon_info);
653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
657 + C o n v e r t P r i m i t i v e T o P a t h %
661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
663 % ConvertPrimitiveToPath() converts a PrimitiveInfo structure into a vector
666 % The format of the ConvertPrimitiveToPath method is:
668 % PathInfo *ConvertPrimitiveToPath(const DrawInfo *draw_info,
669 % const PrimitiveInfo *primitive_info)
671 % A description of each parameter follows:
673 % o Method ConvertPrimitiveToPath returns a vector path structure of type
676 % o draw_info: a structure of type DrawInfo.
678 % o primitive_info: Specifies a pointer to an PrimitiveInfo structure.
683 static void LogPathInfo(const PathInfo *path_info)
685 register const PathInfo
688 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin vector-path");
689 for (p=path_info; p->code != EndCode; p++)
690 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
691 " %g,%g %s",p->point.x,p->point.y,p->code == GhostlineCode ?
692 "moveto ghostline" : p->code == OpenCode ? "moveto open" :
693 p->code == MoveToCode ? "moveto" : p->code == LineToCode ? "lineto" :
695 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end vector-path");
698 static PathInfo *ConvertPrimitiveToPath(
699 const DrawInfo *magick_unused(draw_info),const PrimitiveInfo *primitive_info)
720 Converts a PrimitiveInfo structure into a vector path structure.
722 switch (primitive_info->primitive)
729 return((PathInfo *) NULL);
733 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
734 path_info=(PathInfo *) AcquireQuantumMemory((size_t) (2UL*i+3UL),
736 if (path_info == (PathInfo *) NULL)
737 return((PathInfo *) NULL);
745 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
748 if (coordinates <= 0)
750 coordinates=(ssize_t) primitive_info[i].coordinates;
751 p=primitive_info[i].point;
757 Eliminate duplicate points.
759 if ((i == 0) || (fabs(q.x-primitive_info[i].point.x) > MagickEpsilon) ||
760 (fabs(q.y-primitive_info[i].point.y) > MagickEpsilon))
762 path_info[n].code=code;
763 path_info[n].point=primitive_info[i].point;
764 q=primitive_info[i].point;
769 if ((fabs(p.x-primitive_info[i].point.x) <= MagickEpsilon) &&
770 (fabs(p.y-primitive_info[i].point.y) <= MagickEpsilon))
773 Mark the p point as open if it does not match the q.
775 path_info[start].code=OpenCode;
776 path_info[n].code=GhostlineCode;
777 path_info[n].point=primitive_info[i].point;
779 path_info[n].code=LineToCode;
780 path_info[n].point=p;
783 path_info[n].code=EndCode;
784 path_info[n].point.x=0.0;
785 path_info[n].point.y=0.0;
786 if (IsEventLogging() != MagickFalse)
787 LogPathInfo(path_info);
792 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
796 % D e s t r o y D r a w I n f o %
800 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
802 % DestroyDrawInfo() deallocates memory associated with an DrawInfo
805 % The format of the DestroyDrawInfo method is:
807 % DrawInfo *DestroyDrawInfo(DrawInfo *draw_info)
809 % A description of each parameter follows:
811 % o draw_info: the draw info.
814 MagickExport DrawInfo *DestroyDrawInfo(DrawInfo *draw_info)
816 if (draw_info->debug != MagickFalse)
817 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
818 assert(draw_info != (DrawInfo *) NULL);
819 assert(draw_info->signature == MagickSignature);
820 if (draw_info->primitive != (char *) NULL)
821 draw_info->primitive=DestroyString(draw_info->primitive);
822 if (draw_info->text != (char *) NULL)
823 draw_info->text=DestroyString(draw_info->text);
824 if (draw_info->geometry != (char *) NULL)
825 draw_info->geometry=DestroyString(draw_info->geometry);
826 if (draw_info->tile != (Image *) NULL)
827 draw_info->tile=DestroyImage(draw_info->tile);
828 if (draw_info->fill_pattern != (Image *) NULL)
829 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
830 if (draw_info->stroke_pattern != (Image *) NULL)
831 draw_info->stroke_pattern=DestroyImage(draw_info->stroke_pattern);
832 if (draw_info->font != (char *) NULL)
833 draw_info->font=DestroyString(draw_info->font);
834 if (draw_info->metrics != (char *) NULL)
835 draw_info->metrics=DestroyString(draw_info->metrics);
836 if (draw_info->family != (char *) NULL)
837 draw_info->family=DestroyString(draw_info->family);
838 if (draw_info->encoding != (char *) NULL)
839 draw_info->encoding=DestroyString(draw_info->encoding);
840 if (draw_info->density != (char *) NULL)
841 draw_info->density=DestroyString(draw_info->density);
842 if (draw_info->server_name != (char *) NULL)
843 draw_info->server_name=(char *)
844 RelinquishMagickMemory(draw_info->server_name);
845 if (draw_info->dash_pattern != (double *) NULL)
846 draw_info->dash_pattern=(double *) RelinquishMagickMemory(
847 draw_info->dash_pattern);
848 if (draw_info->gradient.stops != (StopInfo *) NULL)
849 draw_info->gradient.stops=(StopInfo *) RelinquishMagickMemory(
850 draw_info->gradient.stops);
851 if (draw_info->clip_mask != (char *) NULL)
852 draw_info->clip_mask=DestroyString(draw_info->clip_mask);
853 draw_info->signature=(~MagickSignature);
854 draw_info=(DrawInfo *) RelinquishMagickMemory(draw_info);
859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
863 + D e s t r o y E d g e %
867 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
869 % DestroyEdge() destroys the specified polygon edge.
871 % The format of the DestroyEdge method is:
873 % ssize_t DestroyEdge(PolygonInfo *polygon_info,const int edge)
875 % A description of each parameter follows:
877 % o polygon_info: Specifies a pointer to an PolygonInfo structure.
879 % o edge: the polygon edge number to destroy.
882 static size_t DestroyEdge(PolygonInfo *polygon_info,
885 assert(edge < polygon_info->number_edges);
886 polygon_info->edges[edge].points=(PointInfo *) RelinquishMagickMemory(
887 polygon_info->edges[edge].points);
888 polygon_info->number_edges--;
889 if (edge < polygon_info->number_edges)
890 (void) CopyMagickMemory(polygon_info->edges+edge,polygon_info->edges+edge+1,
891 (size_t) (polygon_info->number_edges-edge)*sizeof(*polygon_info->edges));
892 return(polygon_info->number_edges);
896 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
900 + D e s t r o y P o l y g o n I n f o %
904 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
906 % DestroyPolygonInfo() destroys the PolygonInfo data structure.
908 % The format of the DestroyPolygonInfo method is:
910 % PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info)
912 % A description of each parameter follows:
914 % o polygon_info: Specifies a pointer to an PolygonInfo structure.
917 static PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info)
922 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
923 polygon_info->edges[i].points=(PointInfo *)
924 RelinquishMagickMemory(polygon_info->edges[i].points);
925 polygon_info->edges=(EdgeInfo *) RelinquishMagickMemory(polygon_info->edges);
926 return((PolygonInfo *) RelinquishMagickMemory(polygon_info));
930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
934 % D r a w A f f i n e I m a g e %
938 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
940 % DrawAffineImage() composites the source over the destination image as
941 % dictated by the affine transform.
943 % The format of the DrawAffineImage method is:
945 % MagickBooleanType DrawAffineImage(Image *image,const Image *source,
946 % const AffineMatrix *affine)
948 % A description of each parameter follows:
950 % o image: the image.
952 % o source: the source image.
954 % o affine: the affine transform.
957 static SegmentInfo AffineEdge(const Image *image,const AffineMatrix *affine,
958 const double y,const SegmentInfo *edge)
971 Determine left and right edges.
973 inverse_edge.x1=edge->x1;
974 inverse_edge.y1=edge->y1;
975 inverse_edge.x2=edge->x2;
976 inverse_edge.y2=edge->y2;
977 z=affine->ry*y+affine->tx;
978 if (affine->sx > MagickEpsilon)
980 intercept=(-z/affine->sx);
981 x=intercept+MagickEpsilon;
982 if (x > inverse_edge.x1)
984 intercept=(-z+(double) image->columns)/affine->sx;
985 x=intercept-MagickEpsilon;
986 if (x < inverse_edge.x2)
990 if (affine->sx < -MagickEpsilon)
992 intercept=(-z+(double) image->columns)/affine->sx;
993 x=intercept+MagickEpsilon;
994 if (x > inverse_edge.x1)
996 intercept=(-z/affine->sx);
997 x=intercept-MagickEpsilon;
998 if (x < inverse_edge.x2)
1002 if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->columns))
1004 inverse_edge.x2=edge->x1;
1005 return(inverse_edge);
1008 Determine top and bottom edges.
1010 z=affine->sy*y+affine->ty;
1011 if (affine->rx > MagickEpsilon)
1013 intercept=(-z/affine->rx);
1014 x=intercept+MagickEpsilon;
1015 if (x > inverse_edge.x1)
1017 intercept=(-z+(double) image->rows)/affine->rx;
1018 x=intercept-MagickEpsilon;
1019 if (x < inverse_edge.x2)
1023 if (affine->rx < -MagickEpsilon)
1025 intercept=(-z+(double) image->rows)/affine->rx;
1026 x=intercept+MagickEpsilon;
1027 if (x > inverse_edge.x1)
1029 intercept=(-z/affine->rx);
1030 x=intercept-MagickEpsilon;
1031 if (x < inverse_edge.x2)
1035 if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->rows))
1037 inverse_edge.x2=edge->x2;
1038 return(inverse_edge);
1040 return(inverse_edge);
1043 static AffineMatrix InverseAffineMatrix(const AffineMatrix *affine)
1051 determinant=1.0/(affine->sx*affine->sy-affine->rx*affine->ry);
1052 inverse_affine.sx=determinant*affine->sy;
1053 inverse_affine.rx=determinant*(-affine->rx);
1054 inverse_affine.ry=determinant*(-affine->ry);
1055 inverse_affine.sy=determinant*affine->sx;
1056 inverse_affine.tx=(-affine->tx)*inverse_affine.sx-affine->ty*
1058 inverse_affine.ty=(-affine->tx)*inverse_affine.rx-affine->ty*
1060 return(inverse_affine);
1063 static inline ssize_t MagickAbsoluteValue(const ssize_t x)
1070 static inline double MagickMax(const double x,const double y)
1077 static inline double MagickMin(const double x,const double y)
1084 MagickExport MagickBooleanType DrawAffineImage(Image *image,
1085 const Image *source,const AffineMatrix *affine)
1119 Determine bounding box.
1121 assert(image != (Image *) NULL);
1122 assert(image->signature == MagickSignature);
1123 if (image->debug != MagickFalse)
1124 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1125 assert(source != (const Image *) NULL);
1126 assert(source->signature == MagickSignature);
1127 assert(affine != (AffineMatrix *) NULL);
1130 extent[1].x=(double) source->columns-1.0;
1132 extent[2].x=(double) source->columns-1.0;
1133 extent[2].y=(double) source->rows-1.0;
1135 extent[3].y=(double) source->rows-1.0;
1136 for (i=0; i < 4; i++)
1139 extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx;
1140 extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty;
1144 for (i=1; i < 4; i++)
1146 if (min.x > extent[i].x)
1148 if (min.y > extent[i].y)
1150 if (max.x < extent[i].x)
1152 if (max.y < extent[i].y)
1156 Affine transform image.
1158 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
1159 return(MagickFalse);
1161 edge.x1=MagickMax(min.x,0.0);
1162 edge.y1=MagickMax(min.y,0.0);
1163 edge.x2=MagickMin(max.x,(double) image->columns-1.0);
1164 edge.y2=MagickMin(max.y,(double) image->rows-1.0);
1165 inverse_affine=InverseAffineMatrix(affine);
1166 GetMagickPixelPacket(image,&zero);
1167 exception=(&image->exception);
1168 image_view=AcquireCacheView(image);
1169 source_view=AcquireCacheView(source);
1170 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1171 #pragma omp parallel for schedule(dynamic,4) shared(status)
1173 for (y=(ssize_t) ceil(edge.y1-0.5); y <= (ssize_t) floor(edge.y2+0.5); y++)
1182 register IndexPacket
1188 register PixelPacket
1197 inverse_edge=AffineEdge(source,&inverse_affine,(double) y,&edge);
1198 if (inverse_edge.x2 < inverse_edge.x1)
1200 q=GetCacheViewAuthenticPixels(image_view,(ssize_t) ceil(inverse_edge.x1-
1201 0.5),y,(size_t) ((ssize_t) floor(inverse_edge.x2+0.5)-(ssize_t) floor(
1202 inverse_edge.x1+0.5)+1),1,exception);
1203 if (q == (PixelPacket *) NULL)
1205 indexes=GetCacheViewAuthenticIndexQueue(image_view);
1209 for (x=(ssize_t) ceil(inverse_edge.x1-0.5); x <= (ssize_t) floor(inverse_edge.x2+0.5); x++)
1211 point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+
1213 point.y=(double) x*inverse_affine.rx+y*inverse_affine.sy+
1215 (void) InterpolatePixelPacket(image,image_view,image->interpolate,
1216 point.x,point.y,&pixel,exception);
1217 SetMagickPixelPacket(image,q,indexes+x_offset,&composite);
1218 MagickPixelCompositeOver(&pixel,pixel.opacity,&composite,
1219 composite.opacity,&composite);
1220 SetPixelPacket(image,&composite,q,indexes+x_offset);
1224 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1227 source_view=DestroyCacheView(source_view);
1228 image_view=DestroyCacheView(image_view);
1233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1237 + D r a w B o u n d i n g R e c t a n g l e s %
1241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1243 % DrawBoundingRectangles() draws the bounding rectangles on the image. This
1244 % is only useful for developers debugging the rendering algorithm.
1246 % The format of the DrawBoundingRectangles method is:
1248 % void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info,
1249 % PolygonInfo *polygon_info)
1251 % A description of each parameter follows:
1253 % o image: the image.
1255 % o draw_info: the draw info.
1257 % o polygon_info: Specifies a pointer to a PolygonInfo structure.
1260 static void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info,
1261 const PolygonInfo *polygon_info)
1286 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1287 (void) QueryColorDatabase("#0000",&clone_info->fill,&image->exception);
1288 resolution.x=DefaultResolution;
1289 resolution.y=DefaultResolution;
1290 if (clone_info->density != (char *) NULL)
1298 flags=ParseGeometry(clone_info->density,&geometry_info);
1299 resolution.x=geometry_info.rho;
1300 resolution.y=geometry_info.sigma;
1301 if ((flags & SigmaValue) == MagickFalse)
1302 resolution.y=resolution.x;
1304 mid=(resolution.x/72.0)*ExpandAffine(&clone_info->affine)*
1305 clone_info->stroke_width/2.0;
1310 if (polygon_info != (PolygonInfo *) NULL)
1312 bounds=polygon_info->edges[0].bounds;
1313 for (i=1; i < (ssize_t) polygon_info->number_edges; i++)
1315 if (polygon_info->edges[i].bounds.x1 < (double) bounds.x1)
1316 bounds.x1=polygon_info->edges[i].bounds.x1;
1317 if (polygon_info->edges[i].bounds.y1 < (double) bounds.y1)
1318 bounds.y1=polygon_info->edges[i].bounds.y1;
1319 if (polygon_info->edges[i].bounds.x2 > (double) bounds.x2)
1320 bounds.x2=polygon_info->edges[i].bounds.x2;
1321 if (polygon_info->edges[i].bounds.y2 > (double) bounds.y2)
1322 bounds.y2=polygon_info->edges[i].bounds.y2;
1325 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double)
1326 image->columns ? (double) image->columns-1 : bounds.x1;
1328 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double)
1329 image->rows ? (double) image->rows-1 : bounds.y1;
1331 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double)
1332 image->columns ? (double) image->columns-1 : bounds.x2;
1334 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double)
1335 image->rows ? (double) image->rows-1 : bounds.y2;
1336 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
1338 if (polygon_info->edges[i].direction != 0)
1339 (void) QueryColorDatabase("red",&clone_info->stroke,
1342 (void) QueryColorDatabase("green",&clone_info->stroke,
1344 start.x=(double) (polygon_info->edges[i].bounds.x1-mid);
1345 start.y=(double) (polygon_info->edges[i].bounds.y1-mid);
1346 end.x=(double) (polygon_info->edges[i].bounds.x2+mid);
1347 end.y=(double) (polygon_info->edges[i].bounds.y2+mid);
1348 primitive_info[0].primitive=RectanglePrimitive;
1349 TraceRectangle(primitive_info,start,end);
1350 primitive_info[0].method=ReplaceMethod;
1351 coordinates=(ssize_t) primitive_info[0].coordinates;
1352 primitive_info[coordinates].primitive=UndefinedPrimitive;
1353 (void) DrawPrimitive(image,clone_info,primitive_info);
1356 (void) QueryColorDatabase("blue",&clone_info->stroke,&image->exception);
1357 start.x=(double) (bounds.x1-mid);
1358 start.y=(double) (bounds.y1-mid);
1359 end.x=(double) (bounds.x2+mid);
1360 end.y=(double) (bounds.y2+mid);
1361 primitive_info[0].primitive=RectanglePrimitive;
1362 TraceRectangle(primitive_info,start,end);
1363 primitive_info[0].method=ReplaceMethod;
1364 coordinates=(ssize_t) primitive_info[0].coordinates;
1365 primitive_info[coordinates].primitive=UndefinedPrimitive;
1366 (void) DrawPrimitive(image,clone_info,primitive_info);
1367 clone_info=DestroyDrawInfo(clone_info);
1371 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1375 % D r a w C l i p P a t h %
1379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1381 % DrawClipPath() draws the clip path on the image mask.
1383 % The format of the DrawClipPath method is:
1385 % MagickBooleanType DrawClipPath(Image *image,const DrawInfo *draw_info,
1388 % A description of each parameter follows:
1390 % o image: the image.
1392 % o draw_info: the draw info.
1394 % o name: the name of the clip path.
1397 MagickExport MagickBooleanType DrawClipPath(Image *image,
1398 const DrawInfo *draw_info,const char *name)
1401 clip_mask[MaxTextExtent];
1412 assert(image != (Image *) NULL);
1413 assert(image->signature == MagickSignature);
1414 if (image->debug != MagickFalse)
1415 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1416 assert(draw_info != (const DrawInfo *) NULL);
1417 (void) FormatMagickString(clip_mask,MaxTextExtent,"%s",name);
1418 value=GetImageArtifact(image,clip_mask);
1419 if (value == (const char *) NULL)
1420 return(MagickFalse);
1421 if (image->clip_mask == (Image *) NULL)
1426 clip_mask=CloneImage(image,image->columns,image->rows,MagickTrue,
1428 if (clip_mask == (Image *) NULL)
1429 return(MagickFalse);
1430 (void) SetImageClipMask(image,clip_mask);
1431 clip_mask=DestroyImage(clip_mask);
1433 (void) QueryColorDatabase("#00000000",&image->clip_mask->background_color,
1435 image->clip_mask->background_color.opacity=(Quantum) TransparentOpacity;
1436 (void) SetImageBackgroundColor(image->clip_mask);
1437 if (image->debug != MagickFalse)
1438 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"\nbegin clip-path %s",
1439 draw_info->clip_mask);
1440 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1441 (void) CloneString(&clone_info->primitive,value);
1442 (void) QueryColorDatabase("#ffffff",&clone_info->fill,&image->exception);
1443 clone_info->clip_mask=(char *) NULL;
1444 status=DrawImage(image->clip_mask,clone_info);
1445 status|=NegateImage(image->clip_mask,MagickFalse);
1446 clone_info=DestroyDrawInfo(clone_info);
1447 if (image->debug != MagickFalse)
1448 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end clip-path");
1449 return(status != 0 ? MagickTrue : MagickFalse);
1453 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1457 + D r a w D a s h P o l y g o n %
1461 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1463 % DrawDashPolygon() draws a dashed polygon (line, rectangle, ellipse) on the
1464 % image while respecting the dash offset and dash pattern attributes.
1466 % The format of the DrawDashPolygon method is:
1468 % MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info,
1469 % const PrimitiveInfo *primitive_info,Image *image)
1471 % A description of each parameter follows:
1473 % o draw_info: the draw info.
1475 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
1477 % o image: the image.
1481 static MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info,
1482 const PrimitiveInfo *primitive_info,Image *image)
1503 register MagickRealType
1514 assert(draw_info != (const DrawInfo *) NULL);
1515 if (image->debug != MagickFalse)
1516 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-dash");
1517 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1518 clone_info->miterlimit=0;
1519 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
1520 number_vertices=(size_t) i;
1521 dash_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
1522 (2UL*number_vertices+1UL),sizeof(*dash_polygon));
1523 if (dash_polygon == (PrimitiveInfo *) NULL)
1524 return(MagickFalse);
1525 dash_polygon[0]=primitive_info[0];
1526 scale=ExpandAffine(&draw_info->affine);
1527 length=scale*(draw_info->dash_pattern[0]-0.5);
1528 offset=draw_info->dash_offset != 0.0 ? scale*draw_info->dash_offset : 0.0;
1530 for (n=0; offset > 0.0; j=0)
1532 if (draw_info->dash_pattern[n] <= 0.0)
1534 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1535 if (offset > length)
1539 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1542 if (offset < length)
1554 for (i=1; i < (ssize_t) number_vertices; i++)
1556 dx=primitive_info[i].point.x-primitive_info[i-1].point.x;
1557 dy=primitive_info[i].point.y-primitive_info[i-1].point.y;
1558 maximum_length=hypot((double) dx,dy);
1562 if (draw_info->dash_pattern[n] == 0.0)
1564 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1566 for (total_length=0.0; (total_length+length) < maximum_length; )
1568 total_length+=length;
1569 if ((n & 0x01) != 0)
1571 dash_polygon[0]=primitive_info[0];
1572 dash_polygon[0].point.x=(double) (primitive_info[i-1].point.x+dx*
1573 total_length/maximum_length);
1574 dash_polygon[0].point.y=(double) (primitive_info[i-1].point.y+dy*
1575 total_length/maximum_length);
1580 if ((j+1) > (ssize_t) (2*number_vertices))
1582 dash_polygon[j]=primitive_info[i-1];
1583 dash_polygon[j].point.x=(double) (primitive_info[i-1].point.x+dx*
1584 total_length/maximum_length);
1585 dash_polygon[j].point.y=(double) (primitive_info[i-1].point.y+dy*
1586 total_length/maximum_length);
1587 dash_polygon[j].coordinates=1;
1589 dash_polygon[0].coordinates=(size_t) j;
1590 dash_polygon[j].primitive=UndefinedPrimitive;
1591 status|=DrawStrokePolygon(image,clone_info,dash_polygon);
1594 if (draw_info->dash_pattern[n] == 0.0)
1596 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1598 length-=(maximum_length-total_length);
1599 if ((n & 0x01) != 0)
1601 dash_polygon[j]=primitive_info[i];
1602 dash_polygon[j].coordinates=1;
1605 if ((total_length < maximum_length) && ((n & 0x01) == 0) && (j > 1))
1607 dash_polygon[j]=primitive_info[i-1];
1608 dash_polygon[j].point.x+=MagickEpsilon;
1609 dash_polygon[j].point.y+=MagickEpsilon;
1610 dash_polygon[j].coordinates=1;
1612 dash_polygon[0].coordinates=(size_t) j;
1613 dash_polygon[j].primitive=UndefinedPrimitive;
1614 status|=DrawStrokePolygon(image,clone_info,dash_polygon);
1616 dash_polygon=(PrimitiveInfo *) RelinquishMagickMemory(dash_polygon);
1617 clone_info=DestroyDrawInfo(clone_info);
1618 if (image->debug != MagickFalse)
1619 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-dash");
1620 return(status != 0 ? MagickTrue : MagickFalse);
1624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1628 % D r a w I m a g e %
1632 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1634 % DrawImage() draws a graphic primitive on your image. The primitive
1635 % may be represented as a string or filename. Precede the filename with an
1636 % "at" sign (@) and the contents of the file are drawn on the image. You
1637 % can affect how text is drawn by setting one or more members of the draw
1640 % The format of the DrawImage method is:
1642 % MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info)
1644 % A description of each parameter follows:
1646 % o image: the image.
1648 % o draw_info: the draw info.
1652 static inline MagickBooleanType IsPoint(const char *point)
1660 value=strtod(point,&p);
1661 return((value == 0.0) && (p == point) ? MagickFalse : MagickTrue);
1664 static inline void TracePoint(PrimitiveInfo *primitive_info,
1665 const PointInfo point)
1667 primitive_info->coordinates=1;
1668 primitive_info->point=point;
1671 MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info)
1673 #define RenderImageTag "Render/Image"
1680 key[2*MaxTextExtent],
1681 keyword[MaxTextExtent],
1682 geometry[MaxTextExtent],
1683 name[MaxTextExtent],
1684 pattern[MaxTextExtent],
1735 Ensure the annotation info is valid.
1737 assert(image != (Image *) NULL);
1738 assert(image->signature == MagickSignature);
1739 if (image->debug != MagickFalse)
1740 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1741 assert(draw_info != (DrawInfo *) NULL);
1742 assert(draw_info->signature == MagickSignature);
1743 if (image->debug != MagickFalse)
1744 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1745 if ((draw_info->primitive == (char *) NULL) ||
1746 (*draw_info->primitive == '\0'))
1747 return(MagickFalse);
1748 if (image->debug != MagickFalse)
1749 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"begin draw-image");
1750 if (*draw_info->primitive != '@')
1751 primitive=AcquireString(draw_info->primitive);
1753 primitive=FileToString(draw_info->primitive+1,~0,&image->exception);
1754 if (primitive == (char *) NULL)
1755 return(MagickFalse);
1756 primitive_extent=(MagickRealType) strlen(primitive);
1757 (void) SetImageArtifact(image,"MVG",primitive);
1760 Allocate primitive info memory.
1762 graphic_context=(DrawInfo **) AcquireMagickMemory(
1763 sizeof(*graphic_context));
1764 if (graphic_context == (DrawInfo **) NULL)
1766 primitive=DestroyString(primitive);
1767 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1771 primitive_info=(PrimitiveInfo *) AcquireQuantumMemory((size_t) number_points,
1772 sizeof(*primitive_info));
1773 if (primitive_info == (PrimitiveInfo *) NULL)
1775 primitive=DestroyString(primitive);
1776 for ( ; n >= 0; n--)
1777 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
1778 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
1779 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1782 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1783 graphic_context[n]->viewbox=image->page;
1784 if ((image->page.width == 0) || (image->page.height == 0))
1786 graphic_context[n]->viewbox.width=image->columns;
1787 graphic_context[n]->viewbox.height=image->rows;
1789 token=AcquireString(primitive);
1790 (void) QueryColorDatabase("#000000",&start_color,&image->exception);
1791 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
1792 return(MagickFalse);
1794 for (q=primitive; *q != '\0'; )
1797 Interpret graphic primitive.
1799 GetMagickToken(q,&q,keyword);
1800 if (*keyword == '\0')
1802 if (*keyword == '#')
1807 while ((*q != '\n') && (*q != '\0'))
1811 p=q-strlen(keyword)-1;
1812 primitive_type=UndefinedPrimitive;
1813 current=graphic_context[n]->affine;
1814 GetAffineMatrix(&affine);
1822 if (LocaleCompare("affine",keyword) == 0)
1824 GetMagickToken(q,&q,token);
1825 affine.sx=StringToDouble(token);
1826 GetMagickToken(q,&q,token);
1828 GetMagickToken(q,&q,token);
1829 affine.rx=StringToDouble(token);
1830 GetMagickToken(q,&q,token);
1832 GetMagickToken(q,&q,token);
1833 affine.ry=StringToDouble(token);
1834 GetMagickToken(q,&q,token);
1836 GetMagickToken(q,&q,token);
1837 affine.sy=StringToDouble(token);
1838 GetMagickToken(q,&q,token);
1840 GetMagickToken(q,&q,token);
1841 affine.tx=StringToDouble(token);
1842 GetMagickToken(q,&q,token);
1844 GetMagickToken(q,&q,token);
1845 affine.ty=StringToDouble(token);
1848 if (LocaleCompare("arc",keyword) == 0)
1850 primitive_type=ArcPrimitive;
1859 if (LocaleCompare("bezier",keyword) == 0)
1861 primitive_type=BezierPrimitive;
1864 if (LocaleCompare("border-color",keyword) == 0)
1866 GetMagickToken(q,&q,token);
1867 (void) QueryColorDatabase(token,&graphic_context[n]->border_color,
1877 if (LocaleCompare("clip-path",keyword) == 0)
1882 GetMagickToken(q,&q,token);
1883 (void) CloneString(&graphic_context[n]->clip_mask,token);
1884 (void) DrawClipPath(image,graphic_context[n],
1885 graphic_context[n]->clip_mask);
1888 if (LocaleCompare("clip-rule",keyword) == 0)
1893 GetMagickToken(q,&q,token);
1894 fill_rule=ParseMagickOption(MagickFillRuleOptions,MagickFalse,
1896 if (fill_rule == -1)
1901 graphic_context[n]->fill_rule=(FillRule) fill_rule;
1904 if (LocaleCompare("clip-units",keyword) == 0)
1909 GetMagickToken(q,&q,token);
1910 clip_units=ParseMagickOption(MagickClipPathOptions,MagickFalse,
1912 if (clip_units == -1)
1917 graphic_context[n]->clip_units=(ClipPathUnits) clip_units;
1918 if (clip_units == ObjectBoundingBox)
1920 GetAffineMatrix(¤t);
1921 affine.sx=draw_info->bounds.x2;
1922 affine.sy=draw_info->bounds.y2;
1923 affine.tx=draw_info->bounds.x1;
1924 affine.ty=draw_info->bounds.y1;
1929 if (LocaleCompare("circle",keyword) == 0)
1931 primitive_type=CirclePrimitive;
1934 if (LocaleCompare("color",keyword) == 0)
1936 primitive_type=ColorPrimitive;
1945 if (LocaleCompare("decorate",keyword) == 0)
1950 GetMagickToken(q,&q,token);
1951 decorate=ParseMagickOption(MagickDecorateOptions,MagickFalse,
1958 graphic_context[n]->decorate=(DecorationType) decorate;
1967 if (LocaleCompare("ellipse",keyword) == 0)
1969 primitive_type=EllipsePrimitive;
1972 if (LocaleCompare("encoding",keyword) == 0)
1974 GetMagickToken(q,&q,token);
1975 (void) CloneString(&graphic_context[n]->encoding,token);
1984 if (LocaleCompare("fill",keyword) == 0)
1986 GetMagickToken(q,&q,token);
1987 (void) FormatMagickString(pattern,MaxTextExtent,"%s",token);
1988 if (GetImageArtifact(image,pattern) != (const char *) NULL)
1989 (void) DrawPatternPath(image,draw_info,token,
1990 &graphic_context[n]->fill_pattern);
1993 status=QueryColorDatabase(token,&graphic_context[n]->fill,
1995 if (status == MagickFalse)
2000 pattern_info=AcquireImageInfo();
2001 (void) CopyMagickString(pattern_info->filename,token,
2003 graphic_context[n]->fill_pattern=
2004 ReadImage(pattern_info,&image->exception);
2005 CatchException(&image->exception);
2006 pattern_info=DestroyImageInfo(pattern_info);
2011 if (LocaleCompare("fill-opacity",keyword) == 0)
2013 GetMagickToken(q,&q,token);
2014 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2015 graphic_context[n]->fill.opacity=ClampToQuantum((MagickRealType)
2016 QuantumRange*(1.0-factor*StringToDouble(token)));
2019 if (LocaleCompare("fill-rule",keyword) == 0)
2024 GetMagickToken(q,&q,token);
2025 fill_rule=ParseMagickOption(MagickFillRuleOptions,MagickFalse,
2027 if (fill_rule == -1)
2032 graphic_context[n]->fill_rule=(FillRule) fill_rule;
2035 if (LocaleCompare("font",keyword) == 0)
2037 GetMagickToken(q,&q,token);
2038 (void) CloneString(&graphic_context[n]->font,token);
2039 if (LocaleCompare("none",token) == 0)
2040 graphic_context[n]->font=(char *)
2041 RelinquishMagickMemory(graphic_context[n]->font);
2044 if (LocaleCompare("font-family",keyword) == 0)
2046 GetMagickToken(q,&q,token);
2047 (void) CloneString(&graphic_context[n]->family,token);
2050 if (LocaleCompare("font-size",keyword) == 0)
2052 GetMagickToken(q,&q,token);
2053 graphic_context[n]->pointsize=StringToDouble(token);
2056 if (LocaleCompare("font-stretch",keyword) == 0)
2061 GetMagickToken(q,&q,token);
2062 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,token);
2068 graphic_context[n]->stretch=(StretchType) stretch;
2071 if (LocaleCompare("font-style",keyword) == 0)
2076 GetMagickToken(q,&q,token);
2077 style=ParseMagickOption(MagickStyleOptions,MagickFalse,token);
2083 graphic_context[n]->style=(StyleType) style;
2086 if (LocaleCompare("font-weight",keyword) == 0)
2088 GetMagickToken(q,&q,token);
2089 graphic_context[n]->weight=StringToUnsignedLong(token);
2090 if (LocaleCompare(token,"all") == 0)
2091 graphic_context[n]->weight=0;
2092 if (LocaleCompare(token,"bold") == 0)
2093 graphic_context[n]->weight=700;
2094 if (LocaleCompare(token,"bolder") == 0)
2095 if (graphic_context[n]->weight <= 800)
2096 graphic_context[n]->weight+=100;
2097 if (LocaleCompare(token,"lighter") == 0)
2098 if (graphic_context[n]->weight >= 100)
2099 graphic_context[n]->weight-=100;
2100 if (LocaleCompare(token,"normal") == 0)
2101 graphic_context[n]->weight=400;
2110 if (LocaleCompare("gradient-units",keyword) == 0)
2112 GetMagickToken(q,&q,token);
2115 if (LocaleCompare("gravity",keyword) == 0)
2120 GetMagickToken(q,&q,token);
2121 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,token);
2127 graphic_context[n]->gravity=(GravityType) gravity;
2136 if (LocaleCompare("image",keyword) == 0)
2141 primitive_type=ImagePrimitive;
2142 GetMagickToken(q,&q,token);
2143 compose=ParseMagickOption(MagickComposeOptions,MagickFalse,token);
2149 graphic_context[n]->compose=(CompositeOperator) compose;
2152 if (LocaleCompare("interline-spacing",keyword) == 0)
2154 GetMagickToken(q,&q,token);
2155 graphic_context[n]->interline_spacing=StringToDouble(token);
2158 if (LocaleCompare("interword-spacing",keyword) == 0)
2160 GetMagickToken(q,&q,token);
2161 graphic_context[n]->interword_spacing=StringToDouble(token);
2170 if (LocaleCompare("kerning",keyword) == 0)
2172 GetMagickToken(q,&q,token);
2173 graphic_context[n]->kerning=StringToDouble(token);
2182 if (LocaleCompare("line",keyword) == 0)
2184 primitive_type=LinePrimitive;
2193 if (LocaleCompare("matte",keyword) == 0)
2195 primitive_type=MattePrimitive;
2204 if (LocaleCompare("offset",keyword) == 0)
2206 GetMagickToken(q,&q,token);
2209 if (LocaleCompare("opacity",keyword) == 0)
2211 GetMagickToken(q,&q,token);
2212 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2213 graphic_context[n]->opacity=ClampToQuantum((MagickRealType)
2214 QuantumRange*(1.0-((1.0-QuantumScale*graphic_context[n]->opacity)*
2215 factor*StringToDouble(token))));
2216 graphic_context[n]->fill.opacity=graphic_context[n]->opacity;
2217 graphic_context[n]->stroke.opacity=graphic_context[n]->opacity;
2226 if (LocaleCompare("path",keyword) == 0)
2228 primitive_type=PathPrimitive;
2231 if (LocaleCompare("point",keyword) == 0)
2233 primitive_type=PointPrimitive;
2236 if (LocaleCompare("polyline",keyword) == 0)
2238 primitive_type=PolylinePrimitive;
2241 if (LocaleCompare("polygon",keyword) == 0)
2243 primitive_type=PolygonPrimitive;
2246 if (LocaleCompare("pop",keyword) == 0)
2248 GetMagickToken(q,&q,token);
2249 if (LocaleCompare("clip-path",token) == 0)
2251 if (LocaleCompare("defs",token) == 0)
2253 if (LocaleCompare("gradient",token) == 0)
2255 if (LocaleCompare("graphic-context",token) == 0)
2259 (void) ThrowMagickException(&image->exception,
2260 GetMagickModule(),DrawError,
2261 "UnbalancedGraphicContextPushPop","`%s'",token);
2265 if (graphic_context[n]->clip_mask != (char *) NULL)
2266 if (LocaleCompare(graphic_context[n]->clip_mask,
2267 graphic_context[n-1]->clip_mask) != 0)
2268 (void) SetImageClipMask(image,(Image *) NULL);
2269 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
2273 if (LocaleCompare("pattern",token) == 0)
2278 if (LocaleCompare("push",keyword) == 0)
2280 GetMagickToken(q,&q,token);
2281 if (LocaleCompare("clip-path",token) == 0)
2284 name[MaxTextExtent];
2286 GetMagickToken(q,&q,token);
2287 (void) FormatMagickString(name,MaxTextExtent,"%s",token);
2288 for (p=q; *q != '\0'; )
2290 GetMagickToken(q,&q,token);
2291 if (LocaleCompare(token,"pop") != 0)
2293 GetMagickToken(q,(const char **) NULL,token);
2294 if (LocaleCompare(token,"clip-path") != 0)
2298 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2299 (void) SetImageArtifact(image,name,token);
2300 GetMagickToken(q,&q,token);
2303 if (LocaleCompare("gradient",token) == 0)
2306 key[2*MaxTextExtent],
2307 name[MaxTextExtent],
2308 type[MaxTextExtent];
2313 GetMagickToken(q,&q,token);
2314 (void) CopyMagickString(name,token,MaxTextExtent);
2315 GetMagickToken(q,&q,token);
2316 (void) CopyMagickString(type,token,MaxTextExtent);
2317 GetMagickToken(q,&q,token);
2318 segment.x1=StringToDouble(token);
2319 GetMagickToken(q,&q,token);
2321 GetMagickToken(q,&q,token);
2322 segment.y1=StringToDouble(token);
2323 GetMagickToken(q,&q,token);
2325 GetMagickToken(q,&q,token);
2326 segment.x2=StringToDouble(token);
2327 GetMagickToken(q,&q,token);
2329 GetMagickToken(q,&q,token);
2330 segment.y2=StringToDouble(token);
2331 if (LocaleCompare(type,"radial") == 0)
2333 GetMagickToken(q,&q,token);
2335 GetMagickToken(q,&q,token);
2337 for (p=q; *q != '\0'; )
2339 GetMagickToken(q,&q,token);
2340 if (LocaleCompare(token,"pop") != 0)
2342 GetMagickToken(q,(const char **) NULL,token);
2343 if (LocaleCompare(token,"gradient") != 0)
2347 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2348 bounds.x1=graphic_context[n]->affine.sx*segment.x1+
2349 graphic_context[n]->affine.ry*segment.y1+
2350 graphic_context[n]->affine.tx;
2351 bounds.y1=graphic_context[n]->affine.rx*segment.x1+
2352 graphic_context[n]->affine.sy*segment.y1+
2353 graphic_context[n]->affine.ty;
2354 bounds.x2=graphic_context[n]->affine.sx*segment.x2+
2355 graphic_context[n]->affine.ry*segment.y2+
2356 graphic_context[n]->affine.tx;
2357 bounds.y2=graphic_context[n]->affine.rx*segment.x2+
2358 graphic_context[n]->affine.sy*segment.y2+
2359 graphic_context[n]->affine.ty;
2360 (void) FormatMagickString(key,MaxTextExtent,"%s",name);
2361 (void) SetImageArtifact(image,key,token);
2362 (void) FormatMagickString(key,MaxTextExtent,"%s-geometry",name);
2363 (void) FormatMagickString(geometry,MaxTextExtent,
2364 "%gx%g%+.15g%+.15g",
2365 MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0),
2366 MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0),
2367 bounds.x1,bounds.y1);
2368 (void) SetImageArtifact(image,key,geometry);
2369 GetMagickToken(q,&q,token);
2372 if (LocaleCompare("pattern",token) == 0)
2377 GetMagickToken(q,&q,token);
2378 (void) CopyMagickString(name,token,MaxTextExtent);
2379 GetMagickToken(q,&q,token);
2380 bounds.x=(ssize_t) ceil(StringToDouble(token)-0.5);
2381 GetMagickToken(q,&q,token);
2383 GetMagickToken(q,&q,token);
2384 bounds.y=(ssize_t) ceil(StringToDouble(token)-0.5);
2385 GetMagickToken(q,&q,token);
2387 GetMagickToken(q,&q,token);
2388 bounds.width=(size_t) floor(StringToDouble(token)+0.5);
2389 GetMagickToken(q,&q,token);
2391 GetMagickToken(q,&q,token);
2392 bounds.height=(size_t) floor(StringToDouble(token)+0.5);
2393 for (p=q; *q != '\0'; )
2395 GetMagickToken(q,&q,token);
2396 if (LocaleCompare(token,"pop") != 0)
2398 GetMagickToken(q,(const char **) NULL,token);
2399 if (LocaleCompare(token,"pattern") != 0)
2403 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2404 (void) FormatMagickString(key,MaxTextExtent,"%s",name);
2405 (void) SetImageArtifact(image,key,token);
2406 (void) FormatMagickString(key,MaxTextExtent,"%s-geometry",name);
2407 (void) FormatMagickString(geometry,MaxTextExtent,
2408 "%.20gx%.20g%+.20g%+.20g",(double) bounds.width,(double)
2409 bounds.height,(double) bounds.x,(double) bounds.y);
2410 (void) SetImageArtifact(image,key,geometry);
2411 GetMagickToken(q,&q,token);
2414 if (LocaleCompare("graphic-context",token) == 0)
2417 graphic_context=(DrawInfo **) ResizeQuantumMemory(
2418 graphic_context,(size_t) (n+1),sizeof(*graphic_context));
2419 if (graphic_context == (DrawInfo **) NULL)
2421 (void) ThrowMagickException(&image->exception,
2422 GetMagickModule(),ResourceLimitError,
2423 "MemoryAllocationFailed","`%s'",image->filename);
2426 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,
2427 graphic_context[n-1]);
2430 if (LocaleCompare("defs",token) == 0)
2441 if (LocaleCompare("rectangle",keyword) == 0)
2443 primitive_type=RectanglePrimitive;
2446 if (LocaleCompare("rotate",keyword) == 0)
2448 GetMagickToken(q,&q,token);
2449 angle=StringToDouble(token);
2450 affine.sx=cos(DegreesToRadians(fmod((double) angle,360.0)));
2451 affine.rx=sin(DegreesToRadians(fmod((double) angle,360.0)));
2452 affine.ry=(-sin(DegreesToRadians(fmod((double) angle,360.0))));
2453 affine.sy=cos(DegreesToRadians(fmod((double) angle,360.0)));
2456 if (LocaleCompare("roundRectangle",keyword) == 0)
2458 primitive_type=RoundRectanglePrimitive;
2467 if (LocaleCompare("scale",keyword) == 0)
2469 GetMagickToken(q,&q,token);
2470 affine.sx=StringToDouble(token);
2471 GetMagickToken(q,&q,token);
2473 GetMagickToken(q,&q,token);
2474 affine.sy=StringToDouble(token);
2477 if (LocaleCompare("skewX",keyword) == 0)
2479 GetMagickToken(q,&q,token);
2480 angle=StringToDouble(token);
2481 affine.ry=sin(DegreesToRadians(angle));
2484 if (LocaleCompare("skewY",keyword) == 0)
2486 GetMagickToken(q,&q,token);
2487 angle=StringToDouble(token);
2488 affine.rx=(-tan(DegreesToRadians(angle)/2.0));
2491 if (LocaleCompare("stop-color",keyword) == 0)
2496 GetMagickToken(q,&q,token);
2497 (void) QueryColorDatabase(token,&stop_color,&image->exception);
2498 (void) GradientImage(image,LinearGradient,ReflectSpread,
2499 &start_color,&stop_color);
2500 start_color=stop_color;
2501 GetMagickToken(q,&q,token);
2504 if (LocaleCompare("stroke",keyword) == 0)
2506 GetMagickToken(q,&q,token);
2507 (void) FormatMagickString(pattern,MaxTextExtent,"%s",token);
2508 if (GetImageArtifact(image,pattern) != (const char *) NULL)
2509 (void) DrawPatternPath(image,draw_info,token,
2510 &graphic_context[n]->stroke_pattern);
2513 status=QueryColorDatabase(token,&graphic_context[n]->stroke,
2515 if (status == MagickFalse)
2520 pattern_info=AcquireImageInfo();
2521 (void) CopyMagickString(pattern_info->filename,token,
2523 graphic_context[n]->stroke_pattern=
2524 ReadImage(pattern_info,&image->exception);
2525 CatchException(&image->exception);
2526 pattern_info=DestroyImageInfo(pattern_info);
2531 if (LocaleCompare("stroke-antialias",keyword) == 0)
2533 GetMagickToken(q,&q,token);
2534 graphic_context[n]->stroke_antialias=
2535 StringToLong(token) != 0 ? MagickTrue : MagickFalse;
2538 if (LocaleCompare("stroke-dasharray",keyword) == 0)
2540 if (graphic_context[n]->dash_pattern != (double *) NULL)
2541 graphic_context[n]->dash_pattern=(double *)
2542 RelinquishMagickMemory(graphic_context[n]->dash_pattern);
2543 if (IsPoint(q) != MagickFalse)
2549 GetMagickToken(p,&p,token);
2551 GetMagickToken(p,&p,token);
2552 for (x=0; IsPoint(token) != MagickFalse; x++)
2554 GetMagickToken(p,&p,token);
2556 GetMagickToken(p,&p,token);
2558 graphic_context[n]->dash_pattern=(double *)
2559 AcquireQuantumMemory((size_t) (2UL*x+1UL),
2560 sizeof(*graphic_context[n]->dash_pattern));
2561 if (graphic_context[n]->dash_pattern == (double *) NULL)
2563 (void) ThrowMagickException(&image->exception,
2564 GetMagickModule(),ResourceLimitError,
2565 "MemoryAllocationFailed","`%s'",image->filename);
2568 for (j=0; j < x; j++)
2570 GetMagickToken(q,&q,token);
2572 GetMagickToken(q,&q,token);
2573 graphic_context[n]->dash_pattern[j]=StringToDouble(token);
2575 if ((x & 0x01) != 0)
2576 for ( ; j < (2*x); j++)
2577 graphic_context[n]->dash_pattern[j]=
2578 graphic_context[n]->dash_pattern[j-x];
2579 graphic_context[n]->dash_pattern[j]=0.0;
2582 GetMagickToken(q,&q,token);
2585 if (LocaleCompare("stroke-dashoffset",keyword) == 0)
2587 GetMagickToken(q,&q,token);
2588 graphic_context[n]->dash_offset=StringToDouble(token);
2591 if (LocaleCompare("stroke-linecap",keyword) == 0)
2596 GetMagickToken(q,&q,token);
2597 linecap=ParseMagickOption(MagickLineCapOptions,MagickFalse,token);
2603 graphic_context[n]->linecap=(LineCap) linecap;
2606 if (LocaleCompare("stroke-linejoin",keyword) == 0)
2611 GetMagickToken(q,&q,token);
2612 linejoin=ParseMagickOption(MagickLineJoinOptions,MagickFalse,token);
2618 graphic_context[n]->linejoin=(LineJoin) linejoin;
2621 if (LocaleCompare("stroke-miterlimit",keyword) == 0)
2623 GetMagickToken(q,&q,token);
2624 graphic_context[n]->miterlimit=StringToUnsignedLong(token);
2627 if (LocaleCompare("stroke-opacity",keyword) == 0)
2629 GetMagickToken(q,&q,token);
2630 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2631 graphic_context[n]->stroke.opacity=ClampToQuantum((MagickRealType)
2632 QuantumRange*(1.0-factor*StringToDouble(token)));
2635 if (LocaleCompare("stroke-width",keyword) == 0)
2637 GetMagickToken(q,&q,token);
2638 graphic_context[n]->stroke_width=StringToDouble(token);
2647 if (LocaleCompare("text",keyword) == 0)
2649 primitive_type=TextPrimitive;
2652 if (LocaleCompare("text-align",keyword) == 0)
2657 GetMagickToken(q,&q,token);
2658 align=ParseMagickOption(MagickAlignOptions,MagickFalse,token);
2664 graphic_context[n]->align=(AlignType) align;
2667 if (LocaleCompare("text-anchor",keyword) == 0)
2672 GetMagickToken(q,&q,token);
2673 align=ParseMagickOption(MagickAlignOptions,MagickFalse,token);
2679 graphic_context[n]->align=(AlignType) align;
2682 if (LocaleCompare("text-antialias",keyword) == 0)
2684 GetMagickToken(q,&q,token);
2685 graphic_context[n]->text_antialias=
2686 StringToLong(token) != 0 ? MagickTrue : MagickFalse;
2689 if (LocaleCompare("text-undercolor",keyword) == 0)
2691 GetMagickToken(q,&q,token);
2692 (void) QueryColorDatabase(token,&graphic_context[n]->undercolor,
2696 if (LocaleCompare("translate",keyword) == 0)
2698 GetMagickToken(q,&q,token);
2699 affine.tx=StringToDouble(token);
2700 GetMagickToken(q,&q,token);
2702 GetMagickToken(q,&q,token);
2703 affine.ty=StringToDouble(token);
2712 if (LocaleCompare("viewbox",keyword) == 0)
2714 GetMagickToken(q,&q,token);
2715 graphic_context[n]->viewbox.x=(ssize_t) ceil(StringToDouble(token)-
2717 GetMagickToken(q,&q,token);
2719 GetMagickToken(q,&q,token);
2720 graphic_context[n]->viewbox.y=(ssize_t) ceil(StringToDouble(token)-
2722 GetMagickToken(q,&q,token);
2724 GetMagickToken(q,&q,token);
2725 graphic_context[n]->viewbox.width=(size_t) floor(
2726 StringToDouble(token)+0.5);
2727 GetMagickToken(q,&q,token);
2729 GetMagickToken(q,&q,token);
2730 graphic_context[n]->viewbox.height=(size_t) floor(
2731 StringToDouble(token)+0.5);
2743 if (status == MagickFalse)
2745 if ((affine.sx != 1.0) || (affine.rx != 0.0) || (affine.ry != 0.0) ||
2746 (affine.sy != 1.0) || (affine.tx != 0.0) || (affine.ty != 0.0))
2748 graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
2749 graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
2750 graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
2751 graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
2752 graphic_context[n]->affine.tx=current.sx*affine.tx+current.ry*affine.ty+
2754 graphic_context[n]->affine.ty=current.rx*affine.tx+current.sy*affine.ty+
2757 if (primitive_type == UndefinedPrimitive)
2759 if (image->debug != MagickFalse)
2760 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",
2765 Parse the primitive attributes.
2769 primitive_info[0].point.x=0.0;
2770 primitive_info[0].point.y=0.0;
2771 for (x=0; *q != '\0'; x++)
2776 if (IsPoint(q) == MagickFalse)
2778 GetMagickToken(q,&q,token);
2779 point.x=StringToDouble(token);
2780 GetMagickToken(q,&q,token);
2782 GetMagickToken(q,&q,token);
2783 point.y=StringToDouble(token);
2784 GetMagickToken(q,(const char **) NULL,token);
2786 GetMagickToken(q,&q,token);
2787 primitive_info[i].primitive=primitive_type;
2788 primitive_info[i].point=point;
2789 primitive_info[i].coordinates=0;
2790 primitive_info[i].method=FloodfillMethod;
2792 if (i < (ssize_t) number_points)
2795 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,
2796 (size_t) number_points,sizeof(*primitive_info));
2797 if (primitive_info == (PrimitiveInfo *) NULL)
2799 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2800 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
2804 primitive_info[j].primitive=primitive_type;
2805 primitive_info[j].coordinates=(size_t) x;
2806 primitive_info[j].method=FloodfillMethod;
2807 primitive_info[j].text=(char *) NULL;
2809 Circumscribe primitive within a circle.
2811 bounds.x1=primitive_info[j].point.x;
2812 bounds.y1=primitive_info[j].point.y;
2813 bounds.x2=primitive_info[j].point.x;
2814 bounds.y2=primitive_info[j].point.y;
2815 for (k=1; k < (ssize_t) primitive_info[j].coordinates; k++)
2817 point=primitive_info[j+k].point;
2818 if (point.x < bounds.x1)
2820 if (point.y < bounds.y1)
2822 if (point.x > bounds.x2)
2824 if (point.y > bounds.y2)
2828 Speculate how many points our primitive might consume.
2830 length=primitive_info[j].coordinates;
2831 switch (primitive_type)
2833 case RectanglePrimitive:
2838 case RoundRectanglePrimitive:
2840 length*=5+8*BezierQuantum;
2843 case BezierPrimitive:
2845 if (primitive_info[j].coordinates > 107)
2846 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2847 DrawError,"TooManyBezierCoordinates","`%s'",token);
2848 length=BezierQuantum*primitive_info[j].coordinates;
2857 GetMagickToken(q,&q,token);
2860 for (s=token; *s != '\0'; s=t)
2872 length+=BezierQuantum;
2876 case CirclePrimitive:
2878 case EllipsePrimitive:
2885 alpha=bounds.x2-bounds.x1;
2886 beta=bounds.y2-bounds.y1;
2887 radius=hypot((double) alpha,(double) beta);
2888 length=2*((size_t) (MagickPI*radius))+6*BezierQuantum+360+1;
2894 if ((size_t) (i+length) >= number_points)
2897 Resize based on speculative points required by primitive.
2899 number_points+=length+1;
2900 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,
2901 (size_t) number_points,sizeof(*primitive_info));
2902 if (primitive_info == (PrimitiveInfo *) NULL)
2904 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2905 ResourceLimitError,"MemoryAllocationFailed","`%s'",
2910 switch (primitive_type)
2912 case PointPrimitive:
2915 if (primitive_info[j].coordinates != 1)
2920 TracePoint(primitive_info+j,primitive_info[j].point);
2921 i=(ssize_t) (j+primitive_info[j].coordinates);
2926 if (primitive_info[j].coordinates != 2)
2931 TraceLine(primitive_info+j,primitive_info[j].point,
2932 primitive_info[j+1].point);
2933 i=(ssize_t) (j+primitive_info[j].coordinates);
2936 case RectanglePrimitive:
2938 if (primitive_info[j].coordinates != 2)
2943 TraceRectangle(primitive_info+j,primitive_info[j].point,
2944 primitive_info[j+1].point);
2945 i=(ssize_t) (j+primitive_info[j].coordinates);
2948 case RoundRectanglePrimitive:
2950 if (primitive_info[j].coordinates != 3)
2955 TraceRoundRectangle(primitive_info+j,primitive_info[j].point,
2956 primitive_info[j+1].point,primitive_info[j+2].point);
2957 i=(ssize_t) (j+primitive_info[j].coordinates);
2962 if (primitive_info[j].coordinates != 3)
2964 primitive_type=UndefinedPrimitive;
2967 TraceArc(primitive_info+j,primitive_info[j].point,
2968 primitive_info[j+1].point,primitive_info[j+2].point);
2969 i=(ssize_t) (j+primitive_info[j].coordinates);
2972 case EllipsePrimitive:
2974 if (primitive_info[j].coordinates != 3)
2979 TraceEllipse(primitive_info+j,primitive_info[j].point,
2980 primitive_info[j+1].point,primitive_info[j+2].point);
2981 i=(ssize_t) (j+primitive_info[j].coordinates);
2984 case CirclePrimitive:
2986 if (primitive_info[j].coordinates != 2)
2991 TraceCircle(primitive_info+j,primitive_info[j].point,
2992 primitive_info[j+1].point);
2993 i=(ssize_t) (j+primitive_info[j].coordinates);
2996 case PolylinePrimitive:
2998 case PolygonPrimitive:
3000 primitive_info[i]=primitive_info[j];
3001 primitive_info[i].coordinates=0;
3002 primitive_info[j].coordinates++;
3006 case BezierPrimitive:
3008 if (primitive_info[j].coordinates < 3)
3013 TraceBezier(primitive_info+j,primitive_info[j].coordinates);
3014 i=(ssize_t) (j+primitive_info[j].coordinates);
3019 i=(ssize_t) (j+TracePath(primitive_info+j,token));
3022 case ColorPrimitive:
3023 case MattePrimitive:
3028 if (primitive_info[j].coordinates != 1)
3033 GetMagickToken(q,&q,token);
3034 method=ParseMagickOption(MagickMethodOptions,MagickFalse,token);
3040 primitive_info[j].method=(PaintMethod) method;
3045 if (primitive_info[j].coordinates != 1)
3051 GetMagickToken(q,&q,token);
3052 primitive_info[j].text=AcquireString(token);
3055 case ImagePrimitive:
3057 if (primitive_info[j].coordinates != 2)
3062 GetMagickToken(q,&q,token);
3063 primitive_info[j].text=AcquireString(token);
3067 if (primitive_info == (PrimitiveInfo *) NULL)
3069 if (image->debug != MagickFalse)
3070 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",(int) (q-p),p);
3071 if (status == MagickFalse)
3073 primitive_info[i].primitive=UndefinedPrimitive;
3079 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
3081 point=primitive_info[i].point;
3082 primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+
3083 graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx;
3084 primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+
3085 graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty;
3086 point=primitive_info[i].point;
3087 if (point.x < graphic_context[n]->bounds.x1)
3088 graphic_context[n]->bounds.x1=point.x;
3089 if (point.y < graphic_context[n]->bounds.y1)
3090 graphic_context[n]->bounds.y1=point.y;
3091 if (point.x > graphic_context[n]->bounds.x2)
3092 graphic_context[n]->bounds.x2=point.x;
3093 if (point.y > graphic_context[n]->bounds.y2)
3094 graphic_context[n]->bounds.y2=point.y;
3095 if (primitive_info[i].primitive == ImagePrimitive)
3097 if (i >= (ssize_t) number_points)
3098 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
3100 if (graphic_context[n]->render != MagickFalse)
3102 if ((n != 0) && (graphic_context[n]->clip_mask != (char *) NULL) &&
3103 (LocaleCompare(graphic_context[n]->clip_mask,
3104 graphic_context[n-1]->clip_mask) != 0))
3105 (void) DrawClipPath(image,graphic_context[n],
3106 graphic_context[n]->clip_mask);
3107 (void) DrawPrimitive(image,graphic_context[n],primitive_info);
3109 if (primitive_info->text != (char *) NULL)
3110 primitive_info->text=(char *) RelinquishMagickMemory(
3111 primitive_info->text);
3112 proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType)
3114 if (proceed == MagickFalse)
3117 if (image->debug != MagickFalse)
3118 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end draw-image");
3120 Relinquish resources.
3122 token=DestroyString(token);
3123 if (primitive_info != (PrimitiveInfo *) NULL)
3124 primitive_info=(PrimitiveInfo *) RelinquishMagickMemory(primitive_info);
3125 primitive=DestroyString(primitive);
3126 for ( ; n >= 0; n--)
3127 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
3128 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
3129 if (status == MagickFalse)
3130 ThrowBinaryException(DrawError,"NonconformingDrawingPrimitiveDefinition",
3136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3140 % D r a w G r a d i e n t I m a g e %
3144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3146 % DrawGradientImage() draws a linear gradient on the image.
3148 % The format of the DrawGradientImage method is:
3150 % MagickBooleanType DrawGradientImage(Image *image,
3151 % const DrawInfo *draw_info)
3153 % A description of each parameter follows:
3155 % o image: the image.
3157 % o _info: the draw info.
3161 static inline MagickRealType GetStopColorOffset(const GradientInfo *gradient,
3162 const ssize_t x,const ssize_t y)
3164 switch (gradient->type)
3166 case UndefinedGradient:
3167 case LinearGradient:
3182 gradient_vector=(&gradient->gradient_vector);
3183 p.x=gradient_vector->x2-gradient_vector->x1;
3184 p.y=gradient_vector->y2-gradient_vector->y1;
3185 q.x=(double) x-gradient_vector->x1;
3186 q.y=(double) y-gradient_vector->y1;
3187 length=sqrt(q.x*q.x+q.y*q.y);
3188 gamma=sqrt(p.x*p.x+p.y*p.y)*length;
3189 gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
3190 scale=p.x*q.x+p.y*q.y;
3191 offset=gamma*scale*length;
3194 case RadialGradient:
3203 v.x=(double) x-gradient->center.x;
3204 v.y=(double) y-gradient->center.y;
3205 length=sqrt(v.x*v.x+v.y*v.y);
3206 if (gradient->spread == RepeatSpread)
3208 offset=length/gradient->radius;
3215 MagickExport MagickBooleanType DrawGradientImage(Image *image,
3216 const DrawInfo *draw_info)
3249 Draw linear or radial gradient on image.
3251 assert(image != (Image *) NULL);
3252 assert(image->signature == MagickSignature);
3253 if (image->debug != MagickFalse)
3254 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3255 assert(draw_info != (const DrawInfo *) NULL);
3256 gradient=(&draw_info->gradient);
3257 gradient_vector=(&gradient->gradient_vector);
3258 point.x=gradient_vector->x2-gradient_vector->x1;
3259 point.y=gradient_vector->y2-gradient_vector->y1;
3260 length=sqrt(point.x*point.x+point.y*point.y);
3261 bounding_box=gradient->bounding_box;
3263 exception=(&image->exception);
3264 GetMagickPixelPacket(image,&zero);
3265 image_view=AcquireCacheView(image);
3266 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3267 #pragma omp parallel for schedule(dynamic,4) shared(status)
3269 for (y=bounding_box.y; y < (ssize_t) bounding_box.height; y++)
3279 register IndexPacket
3286 register PixelPacket
3292 if (status == MagickFalse)
3294 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3295 if (q == (PixelPacket *) NULL)
3300 indexes=GetCacheViewAuthenticIndexQueue(image_view);
3303 offset=GetStopColorOffset(gradient,0,y);
3304 if (gradient->type != RadialGradient)
3306 for (x=bounding_box.x; x < (ssize_t) bounding_box.width; x++)
3308 SetMagickPixelPacket(image,q,indexes+x,&pixel);
3309 switch (gradient->spread)
3311 case UndefinedSpread:
3314 if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) ||
3315 (y != (ssize_t) ceil(gradient_vector->y1-0.5)))
3317 offset=GetStopColorOffset(gradient,x,y);
3318 if (gradient->type != RadialGradient)
3321 for (i=0; i < (ssize_t) gradient->number_stops; i++)
3322 if (offset < gradient->stops[i].offset)
3324 if ((offset < 0.0) || (i == 0))
3325 composite=gradient->stops[0].color;
3327 if ((offset > 1.0) || (i == (ssize_t) gradient->number_stops))
3328 composite=gradient->stops[gradient->number_stops-1].color;
3333 alpha=(offset-gradient->stops[i].offset)/
3334 (gradient->stops[j].offset-gradient->stops[i].offset);
3335 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3336 &gradient->stops[j].color,alpha,&composite);
3342 if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) ||
3343 (y != (ssize_t) ceil(gradient_vector->y1-0.5)))
3345 offset=GetStopColorOffset(gradient,x,y);
3346 if (gradient->type != RadialGradient)
3351 if ((ssize_t) fmod(offset,2.0) == 0)
3352 offset=fmod(offset,1.0);
3354 offset=1.0-fmod(offset,1.0);
3355 for (i=0; i < (ssize_t) gradient->number_stops; i++)
3356 if (offset < gradient->stops[i].offset)
3359 composite=gradient->stops[0].color;
3361 if (i == (ssize_t) gradient->number_stops)
3362 composite=gradient->stops[gradient->number_stops-1].color;
3367 alpha=(offset-gradient->stops[i].offset)/
3368 (gradient->stops[j].offset-gradient->stops[i].offset);
3369 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3370 &gradient->stops[j].color,alpha,&composite);
3382 antialias=MagickFalse;
3384 if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) ||
3385 (y != (ssize_t) ceil(gradient_vector->y1-0.5)))
3387 offset=GetStopColorOffset(gradient,x,y);
3388 if (gradient->type == LinearGradient)
3390 repeat=fmod(offset,length);
3392 repeat=length-fmod(-repeat,length);
3394 repeat=fmod(offset,length);
3395 antialias=(repeat < length) && ((repeat+1.0) > length) ?
3396 MagickTrue : MagickFalse;
3397 offset=repeat/length;
3401 repeat=fmod(offset,gradient->radius);
3403 repeat=gradient->radius-fmod(-repeat,gradient->radius);
3405 repeat=fmod(offset,gradient->radius);
3406 antialias=repeat+1.0 > gradient->radius ?
3407 MagickTrue : MagickFalse;
3408 offset=repeat/gradient->radius;
3411 for (i=0; i < (ssize_t) gradient->number_stops; i++)
3412 if (offset < gradient->stops[i].offset)
3415 composite=gradient->stops[0].color;
3417 if (i == (ssize_t) gradient->number_stops)
3418 composite=gradient->stops[gradient->number_stops-1].color;
3423 alpha=(offset-gradient->stops[i].offset)/
3424 (gradient->stops[j].offset-gradient->stops[i].offset);
3425 if (antialias != MagickFalse)
3427 if (gradient->type == LinearGradient)
3428 alpha=length-repeat;
3430 alpha=gradient->radius-repeat;
3432 j=(ssize_t) gradient->number_stops-1L;
3434 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3435 &gradient->stops[j].color,alpha,&composite);
3440 MagickPixelCompositeOver(&composite,composite.opacity,&pixel,
3441 pixel.opacity,&pixel);
3442 SetPixelPacket(image,&pixel,q,indexes+x);
3445 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3448 image_view=DestroyCacheView(image_view);
3453 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3457 % D r a w P a t t e r n P a t h %
3461 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3463 % DrawPatternPath() draws a pattern.
3465 % The format of the DrawPatternPath method is:
3467 % MagickBooleanType DrawPatternPath(Image *image,const DrawInfo *draw_info,
3468 % const char *name,Image **pattern)
3470 % A description of each parameter follows:
3472 % o image: the image.
3474 % o draw_info: the draw info.
3476 % o name: the pattern name.
3478 % o image: the image.
3481 MagickExport MagickBooleanType DrawPatternPath(Image *image,
3482 const DrawInfo *draw_info,const char *name,Image **pattern)
3485 property[MaxTextExtent];
3500 assert(image != (Image *) NULL);
3501 assert(image->signature == MagickSignature);
3502 if (image->debug != MagickFalse)
3503 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3504 assert(draw_info != (const DrawInfo *) NULL);
3505 assert(name != (const char *) NULL);
3506 (void) FormatMagickString(property,MaxTextExtent,"%s",name);
3507 path=GetImageArtifact(image,property);
3508 if (path == (const char *) NULL)
3509 return(MagickFalse);
3510 (void) FormatMagickString(property,MaxTextExtent,"%s-geometry",name);
3511 geometry=GetImageArtifact(image,property);
3512 if (geometry == (const char *) NULL)
3513 return(MagickFalse);
3514 if ((*pattern) != (Image *) NULL)
3515 *pattern=DestroyImage(*pattern);
3516 image_info=AcquireImageInfo();
3517 image_info->size=AcquireString(geometry);
3518 *pattern=AcquireImage(image_info);
3519 image_info=DestroyImageInfo(image_info);
3520 (void) QueryColorDatabase("#00000000",&(*pattern)->background_color,
3522 (void) SetImageBackgroundColor(*pattern);
3523 if (image->debug != MagickFalse)
3524 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
3525 "begin pattern-path %s %s",name,geometry);
3526 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
3527 clone_info->fill_pattern=NewImageList();
3528 clone_info->stroke_pattern=NewImageList();
3529 (void) CloneString(&clone_info->primitive,path);
3530 status=DrawImage(*pattern,clone_info);
3531 clone_info=DestroyDrawInfo(clone_info);
3532 if (image->debug != MagickFalse)
3533 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end pattern-path");
3538 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3542 + D r a w P o l y g o n P r i m i t i v e %
3546 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3548 % DrawPolygonPrimitive() draws a polygon on the image.
3550 % The format of the DrawPolygonPrimitive method is:
3552 % MagickBooleanType DrawPolygonPrimitive(Image *image,
3553 % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
3555 % A description of each parameter follows:
3557 % o image: the image.
3559 % o draw_info: the draw info.
3561 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
3565 static PolygonInfo **DestroyPolygonThreadSet(PolygonInfo **polygon_info)
3570 assert(polygon_info != (PolygonInfo **) NULL);
3571 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
3572 if (polygon_info[i] != (PolygonInfo *) NULL)
3573 polygon_info[i]=DestroyPolygonInfo(polygon_info[i]);
3574 polygon_info=(PolygonInfo **) RelinquishMagickMemory(polygon_info);
3575 return(polygon_info);
3578 static PolygonInfo **AcquirePolygonThreadSet(const DrawInfo *draw_info,
3579 const PrimitiveInfo *primitive_info)
3582 *restrict path_info;
3593 number_threads=GetOpenMPMaximumThreads();
3594 polygon_info=(PolygonInfo **) AcquireQuantumMemory(number_threads,
3595 sizeof(*polygon_info));
3596 if (polygon_info == (PolygonInfo **) NULL)
3597 return((PolygonInfo **) NULL);
3598 (void) ResetMagickMemory(polygon_info,0,GetOpenMPMaximumThreads()*
3599 sizeof(*polygon_info));
3600 path_info=ConvertPrimitiveToPath(draw_info,primitive_info);
3601 if (path_info == (PathInfo *) NULL)
3602 return(DestroyPolygonThreadSet(polygon_info));
3603 for (i=0; i < (ssize_t) number_threads; i++)
3605 polygon_info[i]=ConvertPathToPolygon(draw_info,path_info);
3606 if (polygon_info[i] == (PolygonInfo *) NULL)
3607 return(DestroyPolygonThreadSet(polygon_info));
3609 path_info=(PathInfo *) RelinquishMagickMemory(path_info);
3610 return(polygon_info);
3613 static MagickRealType GetPixelOpacity(PolygonInfo *polygon_info,
3614 const MagickRealType mid,const MagickBooleanType fill,
3615 const FillRule fill_rule,const double x,const double y,
3616 MagickRealType *stroke_opacity)
3630 register const PointInfo
3641 Compute fill & stroke opacity for this (x,y) point.
3643 *stroke_opacity=0.0;
3644 subpath_opacity=0.0;
3645 p=polygon_info->edges;
3646 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
3648 if (y <= (p->bounds.y1-mid-0.5))
3650 if (y > (p->bounds.y2+mid+0.5))
3652 (void) DestroyEdge(polygon_info,(size_t) j);
3655 if ((x <= (p->bounds.x1-mid-0.5)) || (x > (p->bounds.x2+mid+0.5)))
3657 i=(ssize_t) MagickMax((double) p->highwater,1.0);
3658 for ( ; i < (ssize_t) p->number_points; i++)
3660 if (y <= (p->points[i-1].y-mid-0.5))
3662 if (y > (p->points[i].y+mid+0.5))
3664 if (p->scanline != y)
3667 p->highwater=(size_t) i;
3670 Compute distance between a point and an edge.
3673 delta.x=(q+1)->x-q->x;
3674 delta.y=(q+1)->y-q->y;
3675 beta=delta.x*(x-q->x)+delta.y*(y-q->y);
3680 distance=delta.x*delta.x+delta.y*delta.y;
3684 alpha=delta.x*delta.x+delta.y*delta.y;
3689 distance=delta.x*delta.x+delta.y*delta.y;
3694 beta=delta.x*(y-q->y)-delta.y*(x-q->x);
3695 distance=alpha*beta*beta;
3699 Compute stroke & subpath opacity.
3702 if (p->ghostline == MagickFalse)
3705 if ((*stroke_opacity < 1.0) &&
3706 (distance <= ((alpha+0.25)*(alpha+0.25))))
3709 if (distance <= ((alpha+0.25)*(alpha+0.25)))
3710 *stroke_opacity=1.0;
3714 if (distance != 1.0)
3715 beta=sqrt((double) distance);
3717 if (*stroke_opacity < ((alpha-0.25)*(alpha-0.25)))
3718 *stroke_opacity=(alpha-0.25)*(alpha-0.25);
3722 if ((fill == MagickFalse) || (distance > 1.0) || (subpath_opacity >= 1.0))
3724 if (distance <= 0.0)
3726 subpath_opacity=1.0;
3734 if (distance != 1.0)
3735 beta=sqrt(distance);
3738 if (subpath_opacity < (alpha*alpha))
3739 subpath_opacity=alpha*alpha;
3743 Compute fill opacity.
3745 if (fill == MagickFalse)
3747 if (subpath_opacity >= 1.0)
3750 Determine winding number.
3753 p=polygon_info->edges;
3754 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
3756 if (y <= p->bounds.y1)
3758 if ((y > p->bounds.y2) || (x <= p->bounds.x1))
3760 if (x > p->bounds.x2)
3762 winding_number+=p->direction ? 1 : -1;
3765 i=(ssize_t) MagickMax((double) p->highwater,1.0);
3766 for ( ; i < (ssize_t) p->number_points; i++)
3767 if (y <= p->points[i].y)
3770 if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x)))
3771 winding_number+=p->direction ? 1 : -1;
3773 if (fill_rule != NonZeroRule)
3775 if ((MagickAbsoluteValue(winding_number) & 0x01) != 0)
3779 if (MagickAbsoluteValue(winding_number) != 0)
3781 return(subpath_opacity);
3784 static MagickBooleanType DrawPolygonPrimitive(Image *image,
3785 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
3801 **restrict polygon_info;
3818 Compute bounding box.
3820 assert(image != (Image *) NULL);
3821 assert(image->signature == MagickSignature);
3822 if (image->debug != MagickFalse)
3823 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3824 assert(draw_info != (DrawInfo *) NULL);
3825 assert(draw_info->signature == MagickSignature);
3826 assert(primitive_info != (PrimitiveInfo *) NULL);
3827 if (primitive_info->coordinates == 0)
3829 polygon_info=AcquirePolygonThreadSet(draw_info,primitive_info);
3830 if (polygon_info == (PolygonInfo **) NULL)
3831 return(MagickFalse);
3833 DrawBoundingRectangles(image,draw_info,polygon_info[0]);
3834 if (image->debug != MagickFalse)
3835 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-polygon");
3836 fill=(primitive_info->method == FillToBorderMethod) ||
3837 (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse;
3838 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
3839 bounds=polygon_info[0]->edges[0].bounds;
3840 for (i=1; i < (ssize_t) polygon_info[0]->number_edges; i++)
3842 p=polygon_info[0]->edges+i;
3843 if (p->bounds.x1 < bounds.x1)
3844 bounds.x1=p->bounds.x1;
3845 if (p->bounds.y1 < bounds.y1)
3846 bounds.y1=p->bounds.y1;
3847 if (p->bounds.x2 > bounds.x2)
3848 bounds.x2=p->bounds.x2;
3849 if (p->bounds.y2 > bounds.y2)
3850 bounds.y2=p->bounds.y2;
3852 bounds.x1-=(mid+1.0);
3853 bounds.x1=bounds.x1 < 0.0 ? 0.0 : (size_t) ceil(bounds.x1-0.5) >=
3854 image->columns ? (double) image->columns-1.0 : bounds.x1;
3855 bounds.y1-=(mid+1.0);
3856 bounds.y1=bounds.y1 < 0.0 ? 0.0 : (size_t) ceil(bounds.y1-0.5) >=
3857 image->rows ? (double) image->rows-1.0 : bounds.y1;
3858 bounds.x2+=(mid+1.0);
3859 bounds.x2=bounds.x2 < 0.0 ? 0.0 : (size_t) floor(bounds.x2+0.5) >=
3860 image->columns ? (double) image->columns-1.0 : bounds.x2;
3861 bounds.y2+=(mid+1.0);
3862 bounds.y2=bounds.y2 < 0.0 ? 0.0 : (size_t) floor(bounds.y2+0.5) >=
3863 image->rows ? (double) image->rows-1.0 : bounds.y2;
3865 exception=(&image->exception);
3866 start=(ssize_t) ceil(bounds.x1-0.5);
3867 stop=(ssize_t) floor(bounds.x2+0.5);
3868 image_view=AcquireCacheView(image);
3869 if (primitive_info->coordinates == 1)
3874 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3875 #pragma omp parallel for schedule(dynamic,4) shared(status)
3877 for (y=(ssize_t) ceil(bounds.y1-0.5); y <= (ssize_t) floor(bounds.y2+0.5); y++)
3885 register PixelPacket
3888 if (status == MagickFalse)
3891 q=GetCacheViewAuthenticPixels(image_view,x,y,(size_t) (stop-x+1),
3893 if (q == (PixelPacket *) NULL)
3898 for ( ; x <= stop; x++)
3900 if ((x == (ssize_t) ceil(primitive_info->point.x-0.5)) &&
3901 (y == (ssize_t) ceil(primitive_info->point.y-0.5)))
3902 (void) GetStrokeColor(draw_info,x,y,q);
3905 sync=SyncCacheViewAuthenticPixels(image_view,exception);
3906 if (sync == MagickFalse)
3909 image_view=DestroyCacheView(image_view);
3910 polygon_info=DestroyPolygonThreadSet(polygon_info);
3911 if (image->debug != MagickFalse)
3912 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
3913 " end draw-polygon");
3917 Draw polygon or line.
3919 if (image->matte == MagickFalse)
3920 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3921 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3922 #pragma omp parallel for schedule(dynamic,4) shared(status)
3924 for (y=(ssize_t) ceil(bounds.y1-0.5); y <= (ssize_t) floor(bounds.y2+0.5); y++)
3927 id = GetOpenMPThreadId();
3937 register PixelPacket
3943 if (status == MagickFalse)
3945 q=GetCacheViewAuthenticPixels(image_view,start,y,(size_t) (stop-
3946 start+1),1,exception);
3947 if (q == (PixelPacket *) NULL)
3952 for (x=start; x <= stop; x++)
3957 fill_opacity=GetPixelOpacity(polygon_info[id],mid,fill,
3958 draw_info->fill_rule,(double) x,(double) y,&stroke_opacity);
3959 if (draw_info->stroke_antialias == MagickFalse)
3961 fill_opacity=fill_opacity > 0.25 ? 1.0 : 0.0;
3962 stroke_opacity=stroke_opacity > 0.25 ? 1.0 : 0.0;
3964 (void) GetFillColor(draw_info,x,y,&fill_color);
3965 fill_opacity=(MagickRealType) (QuantumRange-fill_opacity*(QuantumRange-
3966 fill_color.opacity));
3967 MagickCompositeOver(&fill_color,fill_opacity,q,(MagickRealType)
3969 (void) GetStrokeColor(draw_info,x,y,&stroke_color);
3970 stroke_opacity=(MagickRealType) (QuantumRange-stroke_opacity*
3971 (QuantumRange-stroke_color.opacity));
3972 MagickCompositeOver(&stroke_color,stroke_opacity,q,(MagickRealType)
3976 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3979 image_view=DestroyCacheView(image_view);
3980 polygon_info=DestroyPolygonThreadSet(polygon_info);
3981 if (image->debug != MagickFalse)
3982 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-polygon");
3987 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3991 % D r a w P r i m i t i v e %
3995 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3997 % DrawPrimitive() draws a primitive (line, rectangle, ellipse) on the image.
3999 % The format of the DrawPrimitive method is:
4001 % MagickBooleanType DrawPrimitive(Image *image,const DrawInfo *draw_info,
4002 % PrimitiveInfo *primitive_info)
4004 % A description of each parameter follows:
4006 % o image: the image.
4008 % o draw_info: the draw info.
4010 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
4014 static void LogPrimitiveInfo(const PrimitiveInfo *primitive_info)
4040 x=(ssize_t) ceil(primitive_info->point.x-0.5);
4041 y=(ssize_t) ceil(primitive_info->point.y-0.5);
4042 switch (primitive_info->primitive)
4044 case PointPrimitive:
4046 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4047 "PointPrimitive %.20g,%.20g %s",(double) x,(double) y,
4048 methods[primitive_info->method]);
4051 case ColorPrimitive:
4053 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4054 "ColorPrimitive %.20g,%.20g %s",(double) x,(double) y,
4055 methods[primitive_info->method]);
4058 case MattePrimitive:
4060 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4061 "MattePrimitive %.20g,%.20g %s",(double) x,(double) y,
4062 methods[primitive_info->method]);
4067 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4068 "TextPrimitive %.20g,%.20g",(double) x,(double) y);
4071 case ImagePrimitive:
4073 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4074 "ImagePrimitive %.20g,%.20g",(double) x,(double) y);
4081 p=primitive_info[0].point;
4084 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4086 point=primitive_info[i].point;
4087 if (coordinates <= 0)
4089 coordinates=(ssize_t) primitive_info[i].coordinates;
4090 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4091 " begin open (%.20g)",(double) coordinates);
4094 point=primitive_info[i].point;
4095 if ((fabs(q.x-point.x) > MagickEpsilon) ||
4096 (fabs(q.y-point.y) > MagickEpsilon))
4097 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4098 " %.20g: %.18g,%.18g",(double) coordinates,point.x,point.y);
4100 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4101 " %.20g: %g,%g (duplicate)",(double) coordinates,point.x,point.y);
4104 if (coordinates > 0)
4106 if ((fabs(p.x-point.x) > MagickEpsilon) ||
4107 (fabs(p.y-point.y) > MagickEpsilon))
4108 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end last (%.20g)",
4109 (double) coordinates);
4111 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end open (%.20g)",
4112 (double) coordinates);
4116 MagickExport MagickBooleanType DrawPrimitive(Image *image,
4117 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4135 if (image->debug != MagickFalse)
4137 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4138 " begin draw-primitive");
4139 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4140 " affine: %g,%g,%g,%g,%g,%g",draw_info->affine.sx,
4141 draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy,
4142 draw_info->affine.tx,draw_info->affine.ty);
4145 exception=(&image->exception);
4146 x=(ssize_t) ceil(primitive_info->point.x-0.5);
4147 y=(ssize_t) ceil(primitive_info->point.y-0.5);
4148 image_view=AcquireCacheView(image);
4149 switch (primitive_info->primitive)
4151 case PointPrimitive:
4159 if ((y < 0) || (y >= (ssize_t) image->rows))
4161 if ((x < 0) || (x >= (ssize_t) image->columns))
4163 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4164 if (q == (PixelPacket *) NULL)
4166 (void) GetFillColor(draw_info,x,y,&fill_color);
4167 MagickCompositeOver(&fill_color,(MagickRealType) fill_color.opacity,q,
4168 (MagickRealType) q->opacity,q);
4169 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4172 case ColorPrimitive:
4174 switch (primitive_info->method)
4182 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4183 if (q == (PixelPacket *) NULL)
4185 (void) GetFillColor(draw_info,x,y,q);
4186 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4197 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception);
4198 for (y=0; y < (ssize_t) image->rows; y++)
4200 register PixelPacket
4203 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4205 if (q == (PixelPacket *) NULL)
4207 for (x=0; x < (ssize_t) image->columns; x++)
4209 if (IsColorSimilar(image,q,&target) == MagickFalse)
4214 (void) GetFillColor(draw_info,x,y,q);
4217 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4218 if (sync == MagickFalse)
4223 case FloodfillMethod:
4224 case FillToBorderMethod:
4229 (void) GetOneVirtualMagickPixel(image,x,y,&target,exception);
4230 if (primitive_info->method == FillToBorderMethod)
4232 target.red=(MagickRealType) draw_info->border_color.red;
4233 target.green=(MagickRealType) draw_info->border_color.green;
4234 target.blue=(MagickRealType) draw_info->border_color.blue;
4236 (void) FloodfillPaintImage(image,DefaultChannels,draw_info,&target,x,
4237 y,primitive_info->method == FloodfillMethod ? MagickFalse :
4246 for (y=0; y < (ssize_t) image->rows; y++)
4248 register PixelPacket
4254 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4256 if (q == (PixelPacket *) NULL)
4258 for (x=0; x < (ssize_t) image->columns; x++)
4260 (void) GetFillColor(draw_info,x,y,q);
4263 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4264 if (sync == MagickFalse)
4272 case MattePrimitive:
4274 if (image->matte == MagickFalse)
4275 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
4276 switch (primitive_info->method)
4287 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4288 if (q == (PixelPacket *) NULL)
4290 (void) GetFillColor(draw_info,x,y,&pixel);
4291 q->opacity=pixel.opacity;
4292 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4304 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception);
4305 for (y=0; y < (ssize_t) image->rows; y++)
4307 register PixelPacket
4313 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4315 if (q == (PixelPacket *) NULL)
4317 for (x=0; x < (ssize_t) image->columns; x++)
4319 if (IsColorSimilar(image,q,&target) == MagickFalse)
4324 (void) GetFillColor(draw_info,x,y,&pixel);
4325 q->opacity=pixel.opacity;
4328 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4329 if (sync == MagickFalse)
4334 case FloodfillMethod:
4335 case FillToBorderMethod:
4340 (void) GetOneVirtualMagickPixel(image,x,y,&target,exception);
4341 if (primitive_info->method == FillToBorderMethod)
4343 target.red=(MagickRealType) draw_info->border_color.red;
4344 target.green=(MagickRealType) draw_info->border_color.green;
4345 target.blue=(MagickRealType) draw_info->border_color.blue;
4347 (void) FloodfillPaintImage(image,OpacityChannel,draw_info,&target,x,y,
4348 primitive_info->method == FloodfillMethod ? MagickFalse :
4360 for (y=0; y < (ssize_t) image->rows; y++)
4362 register PixelPacket
4368 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4370 if (q == (PixelPacket *) NULL)
4372 for (x=0; x < (ssize_t) image->columns; x++)
4374 (void) GetFillColor(draw_info,x,y,&pixel);
4375 q->opacity=pixel.opacity;
4378 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4379 if (sync == MagickFalse)
4390 geometry[MaxTextExtent];
4395 if (primitive_info->text == (char *) NULL)
4397 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4398 (void) CloneString(&clone_info->text,primitive_info->text);
4399 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
4400 primitive_info->point.x,primitive_info->point.y);
4401 (void) CloneString(&clone_info->geometry,geometry);
4402 status=AnnotateImage(image,clone_info);
4403 clone_info=DestroyDrawInfo(clone_info);
4406 case ImagePrimitive:
4412 composite_geometry[MaxTextExtent];
4427 if (primitive_info->text == (char *) NULL)
4429 clone_info=AcquireImageInfo();
4430 if (LocaleNCompare(primitive_info->text,"data:",5) == 0)
4431 composite_image=ReadInlineImage(clone_info,primitive_info->text,
4435 (void) CopyMagickString(clone_info->filename,primitive_info->text,
4437 composite_image=ReadImage(clone_info,&image->exception);
4439 clone_info=DestroyImageInfo(clone_info);
4440 if (composite_image == (Image *) NULL)
4442 (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor)
4443 NULL,(void *) NULL);
4444 x1=(ssize_t) ceil(primitive_info[1].point.x-0.5);
4445 y1=(ssize_t) ceil(primitive_info[1].point.y-0.5);
4446 if (((x1 != 0L) && (x1 != (ssize_t) composite_image->columns)) ||
4447 ((y1 != 0L) && (y1 != (ssize_t) composite_image->rows)))
4450 geometry[MaxTextExtent];
4455 (void) FormatMagickString(geometry,MaxTextExtent,"%gx%g!",
4456 primitive_info[1].point.x,primitive_info[1].point.y);
4457 composite_image->filter=image->filter;
4458 (void) TransformImage(&composite_image,(char *) NULL,geometry);
4460 if (composite_image->matte == MagickFalse)
4461 (void) SetImageAlphaChannel(composite_image,OpaqueAlphaChannel);
4462 if (draw_info->opacity != OpaqueOpacity)
4463 (void) SetImageOpacity(composite_image,draw_info->opacity);
4464 SetGeometry(image,&geometry);
4465 image->gravity=draw_info->gravity;
4468 (void) FormatMagickString(composite_geometry,MaxTextExtent,
4469 "%.20gx%.20g%+.20g%+.20g",(double) composite_image->columns,(double)
4470 composite_image->rows,(double) geometry.x,(double) geometry.y);
4471 (void) ParseGravityGeometry(image,composite_geometry,&geometry,
4473 affine=draw_info->affine;
4474 affine.tx=(double) geometry.x;
4475 affine.ty=(double) geometry.y;
4476 composite_image->interpolate=image->interpolate;
4477 if (draw_info->compose == OverCompositeOp)
4478 (void) DrawAffineImage(image,composite_image,&affine);
4480 (void) CompositeImage(image,draw_info->compose,composite_image,
4481 geometry.x,geometry.y);
4482 composite_image=DestroyImage(composite_image);
4494 if (IsEventLogging() != MagickFalse)
4495 LogPrimitiveInfo(primitive_info);
4496 scale=ExpandAffine(&draw_info->affine);
4497 if ((draw_info->dash_pattern != (double *) NULL) &&
4498 (draw_info->dash_pattern[0] != 0.0) &&
4499 ((scale*draw_info->stroke_width) > MagickEpsilon) &&
4500 (draw_info->stroke.opacity != (Quantum) TransparentOpacity))
4505 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4506 clone_info->stroke_width=0.0;
4507 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4508 status=DrawPolygonPrimitive(image,clone_info,primitive_info);
4509 clone_info=DestroyDrawInfo(clone_info);
4510 (void) DrawDashPolygon(draw_info,primitive_info,image);
4513 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
4515 (draw_info->stroke.opacity != (Quantum) TransparentOpacity))
4521 Draw strokes while respecting line cap/join attributes.
4523 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
4525 (primitive_info[i-1].point.x == primitive_info[0].point.x) &&
4526 (primitive_info[i-1].point.y == primitive_info[0].point.y) ?
4527 MagickTrue : MagickFalse;
4528 i=(ssize_t) primitive_info[0].coordinates;
4529 if ((((draw_info->linecap == RoundCap) ||
4530 (closed_path != MagickFalse)) &&
4531 (draw_info->linejoin == RoundJoin)) ||
4532 (primitive_info[i].primitive != UndefinedPrimitive))
4534 (void) DrawPolygonPrimitive(image,draw_info,primitive_info);
4537 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4538 clone_info->stroke_width=0.0;
4539 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4540 status=DrawPolygonPrimitive(image,clone_info,primitive_info);
4541 clone_info=DestroyDrawInfo(clone_info);
4542 status|=DrawStrokePolygon(image,draw_info,primitive_info);
4545 status=DrawPolygonPrimitive(image,draw_info,primitive_info);
4549 image_view=DestroyCacheView(image_view);
4550 if (image->debug != MagickFalse)
4551 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-primitive");
4552 return(status != 0 ? MagickTrue : MagickFalse);
4556 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4560 + D r a w S t r o k e P o l y g o n %
4564 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4566 % DrawStrokePolygon() draws a stroked polygon (line, rectangle, ellipse) on
4567 % the image while respecting the line cap and join attributes.
4569 % The format of the DrawStrokePolygon method is:
4571 % MagickBooleanType DrawStrokePolygon(Image *image,
4572 % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4574 % A description of each parameter follows:
4576 % o image: the image.
4578 % o draw_info: the draw info.
4580 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
4585 static void DrawRoundLinecap(Image *image,const DrawInfo *draw_info,
4586 const PrimitiveInfo *primitive_info)
4594 for (i=0; i < 4; i++)
4595 linecap[i]=(*primitive_info);
4596 linecap[0].coordinates=4;
4597 linecap[1].point.x+=(double) (10.0*MagickEpsilon);
4598 linecap[2].point.x+=(double) (10.0*MagickEpsilon);
4599 linecap[2].point.y+=(double) (10.0*MagickEpsilon);
4600 linecap[3].point.y+=(double) (10.0*MagickEpsilon);
4601 linecap[4].primitive=UndefinedPrimitive;
4602 (void) DrawPolygonPrimitive(image,draw_info,linecap);
4605 static MagickBooleanType DrawStrokePolygon(Image *image,
4606 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4618 register const PrimitiveInfo
4623 Draw stroked polygon.
4625 if (image->debug != MagickFalse)
4626 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4627 " begin draw-stroke-polygon");
4628 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4629 clone_info->fill=draw_info->stroke;
4630 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4631 clone_info->stroke_width=0.0;
4632 clone_info->fill_rule=NonZeroRule;
4634 for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=p->coordinates)
4636 stroke_polygon=TraceStrokePolygon(draw_info,p);
4637 status=DrawPolygonPrimitive(image,clone_info,stroke_polygon);
4638 stroke_polygon=(PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon);
4639 q=p+p->coordinates-1;
4640 closed_path=(q->point.x == p->point.x) && (q->point.y == p->point.y) ?
4641 MagickTrue : MagickFalse;
4642 if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse))
4644 DrawRoundLinecap(image,draw_info,p);
4645 DrawRoundLinecap(image,draw_info,q);
4648 clone_info=DestroyDrawInfo(clone_info);
4649 if (image->debug != MagickFalse)
4650 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4651 " end draw-stroke-polygon");
4656 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4660 % G e t A f f i n e M a t r i x %
4664 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4666 % GetAffineMatrix() returns an AffineMatrix initialized to the identity
4669 % The format of the GetAffineMatrix method is:
4671 % void GetAffineMatrix(AffineMatrix *affine_matrix)
4673 % A description of each parameter follows:
4675 % o affine_matrix: the affine matrix.
4678 MagickExport void GetAffineMatrix(AffineMatrix *affine_matrix)
4680 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4681 assert(affine_matrix != (AffineMatrix *) NULL);
4682 (void) ResetMagickMemory(affine_matrix,0,sizeof(*affine_matrix));
4683 affine_matrix->sx=1.0;
4684 affine_matrix->sy=1.0;
4688 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4692 + G e t D r a w I n f o %
4696 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4698 % GetDrawInfo() initializes draw_info to default values.
4700 % The format of the GetDrawInfo method is:
4702 % void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info)
4704 % A description of each parameter follows:
4706 % o image_info: the image info..
4708 % o draw_info: the draw info.
4711 MagickExport void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info)
4723 Initialize draw attributes.
4725 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4726 assert(draw_info != (DrawInfo *) NULL);
4727 (void) ResetMagickMemory(draw_info,0,sizeof(*draw_info));
4728 clone_info=CloneImageInfo(image_info);
4729 GetAffineMatrix(&draw_info->affine);
4730 exception=AcquireExceptionInfo();
4731 (void) QueryColorDatabase("#000F",&draw_info->fill,exception);
4732 (void) QueryColorDatabase("#FFF0",&draw_info->stroke,exception);
4733 draw_info->stroke_antialias=clone_info->antialias;
4734 draw_info->stroke_width=1.0;
4735 draw_info->opacity=OpaqueOpacity;
4736 draw_info->fill_rule=EvenOddRule;
4737 draw_info->linecap=ButtCap;
4738 draw_info->linejoin=MiterJoin;
4739 draw_info->miterlimit=10;
4740 draw_info->decorate=NoDecoration;
4741 if (clone_info->font != (char *) NULL)
4742 draw_info->font=AcquireString(clone_info->font);
4743 if (clone_info->density != (char *) NULL)
4744 draw_info->density=AcquireString(clone_info->density);
4745 draw_info->text_antialias=clone_info->antialias;
4746 draw_info->pointsize=12.0;
4747 if (clone_info->pointsize != 0.0)
4748 draw_info->pointsize=clone_info->pointsize;
4749 draw_info->undercolor.opacity=(Quantum) TransparentOpacity;
4750 draw_info->border_color=clone_info->border_color;
4751 draw_info->compose=OverCompositeOp;
4752 if (clone_info->server_name != (char *) NULL)
4753 draw_info->server_name=AcquireString(clone_info->server_name);
4754 draw_info->render=MagickTrue;
4755 draw_info->debug=IsEventLogging();
4756 option=GetImageOption(clone_info,"encoding");
4757 if (option != (const char *) NULL)
4758 (void) CloneString(&draw_info->encoding,option);
4759 option=GetImageOption(clone_info,"kerning");
4760 if (option != (const char *) NULL)
4761 draw_info->kerning=StringToDouble(option);
4762 option=GetImageOption(clone_info,"interline-spacing");
4763 if (option != (const char *) NULL)
4764 draw_info->interline_spacing=StringToDouble(option);
4765 draw_info->direction=UndefinedDirection;
4766 option=GetImageOption(clone_info,"interword-spacing");
4767 if (option != (const char *) NULL)
4768 draw_info->interword_spacing=StringToDouble(option);
4769 option=GetImageOption(clone_info,"direction");
4770 if (option != (const char *) NULL)
4771 draw_info->direction=(DirectionType) ParseMagickOption(
4772 MagickDirectionOptions,MagickFalse,option);
4773 option=GetImageOption(clone_info,"fill");
4774 if (option != (const char *) NULL)
4775 (void) QueryColorDatabase(option,&draw_info->fill,exception);
4776 option=GetImageOption(clone_info,"stroke");
4777 if (option != (const char *) NULL)
4778 (void) QueryColorDatabase(option,&draw_info->stroke,exception);
4779 option=GetImageOption(clone_info,"strokewidth");
4780 if (option != (const char *) NULL)
4781 draw_info->stroke_width=StringToDouble(option);
4782 option=GetImageOption(clone_info,"undercolor");
4783 if (option != (const char *) NULL)
4784 (void) QueryColorDatabase(option,&draw_info->undercolor,exception);
4785 option=GetImageOption(clone_info,"gravity");
4786 if (option != (const char *) NULL)
4787 draw_info->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
4788 MagickFalse,option);
4789 exception=DestroyExceptionInfo(exception);
4790 draw_info->signature=MagickSignature;
4791 clone_info=DestroyImageInfo(clone_info);
4795 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4799 + P e r m u t a t e %
4803 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4805 % Permutate() returns the permuation of the (n,k).
4807 % The format of the Permutate method is:
4809 % void Permutate(ssize_t n,ssize_t k)
4811 % A description of each parameter follows:
4819 static inline MagickRealType Permutate(const ssize_t n,const ssize_t k)
4828 for (i=k+1; i <= n; i++)
4830 for (i=1; i <= (n-k); i++)
4836 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4840 + T r a c e P r i m i t i v e %
4844 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4846 % TracePrimitive is a collection of methods for generating graphic
4847 % primitives such as arcs, ellipses, paths, etc.
4851 static void TraceArc(PrimitiveInfo *primitive_info,const PointInfo start,
4852 const PointInfo end,const PointInfo degrees)
4858 center.x=0.5*(end.x+start.x);
4859 center.y=0.5*(end.y+start.y);
4860 radii.x=fabs(center.x-start.x);
4861 radii.y=fabs(center.y-start.y);
4862 TraceEllipse(primitive_info,center,radii,degrees);
4865 static void TraceArcPath(PrimitiveInfo *primitive_info,const PointInfo start,
4866 const PointInfo end,const PointInfo arc,const MagickRealType angle,
4867 const MagickBooleanType large_arc,const MagickBooleanType sweep)
4882 register MagickRealType
4886 register PrimitiveInfo
4895 if ((start.x == end.x) && (start.y == end.y))
4897 TracePoint(primitive_info,end);
4900 radii.x=fabs(arc.x);
4901 radii.y=fabs(arc.y);
4902 if ((radii.x == 0.0) || (radii.y == 0.0))
4904 TraceLine(primitive_info,start,end);
4907 cosine=cos(DegreesToRadians(fmod((double) angle,360.0)));
4908 sine=sin(DegreesToRadians(fmod((double) angle,360.0)));
4909 center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2);
4910 center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2);
4911 delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/
4913 if (delta < MagickEpsilon)
4915 TraceLine(primitive_info,start,end);
4920 radii.x*=sqrt((double) delta);
4921 radii.y*=sqrt((double) delta);
4923 points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x);
4924 points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y);
4925 points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x);
4926 points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y);
4927 alpha=points[1].x-points[0].x;
4928 beta=points[1].y-points[0].y;
4929 factor=1.0/(alpha*alpha+beta*beta)-0.25;
4934 factor=sqrt((double) factor);
4935 if (sweep == large_arc)
4938 center.x=(double) ((points[0].x+points[1].x)/2-factor*beta);
4939 center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha);
4940 alpha=atan2(points[0].y-center.y,points[0].x-center.x);
4941 theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha;
4942 if ((theta < 0.0) && (sweep != MagickFalse))
4943 theta+=(MagickRealType) (2.0*MagickPI);
4945 if ((theta > 0.0) && (sweep == MagickFalse))
4946 theta-=(MagickRealType) (2.0*MagickPI);
4947 arc_segments=(size_t) ceil(fabs((double) (theta/(0.5*MagickPI+
4950 for (i=0; i < (ssize_t) arc_segments; i++)
4952 beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments));
4953 gamma=(8.0/3.0)*sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))*
4954 sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))/
4955 sin(fmod((double) beta,DegreesToRadians(360.0)));
4956 points[0].x=(double) (center.x+cos(fmod((double) (alpha+(double) i*theta/
4957 arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((double) (alpha+
4958 (double) i*theta/arc_segments),DegreesToRadians(360.0))));
4959 points[0].y=(double) (center.y+sin(fmod((double) (alpha+(double) i*theta/
4960 arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((double) (alpha+
4961 (double) i*theta/arc_segments),DegreesToRadians(360.0))));
4962 points[2].x=(double) (center.x+cos(fmod((double) (alpha+(double) (i+1)*
4963 theta/arc_segments),DegreesToRadians(360.0))));
4964 points[2].y=(double) (center.y+sin(fmod((double) (alpha+(double) (i+1)*
4965 theta/arc_segments),DegreesToRadians(360.0))));
4966 points[1].x=(double) (points[2].x+gamma*sin(fmod((double) (alpha+(double)
4967 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
4968 points[1].y=(double) (points[2].y-gamma*cos(fmod((double) (alpha+(double)
4969 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
4970 p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x;
4971 p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y;
4972 (p+1)->point.x=(double) (cosine*radii.x*points[0].x-sine*radii.y*
4974 (p+1)->point.y=(double) (sine*radii.x*points[0].x+cosine*radii.y*
4976 (p+2)->point.x=(double) (cosine*radii.x*points[1].x-sine*radii.y*
4978 (p+2)->point.y=(double) (sine*radii.x*points[1].x+cosine*radii.y*
4980 (p+3)->point.x=(double) (cosine*radii.x*points[2].x-sine*radii.y*
4982 (p+3)->point.y=(double) (sine*radii.x*points[2].x+cosine*radii.y*
4984 if (i == (ssize_t) (arc_segments-1))
4989 primitive_info->coordinates=(size_t) (p-primitive_info);
4990 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
4992 p->primitive=primitive_info->primitive;
4997 static void TraceBezier(PrimitiveInfo *primitive_info,
4998 const size_t number_coordinates)
5010 register PrimitiveInfo
5022 Allocate coeficients.
5024 quantum=number_coordinates;
5025 for (i=0; i < (ssize_t) number_coordinates; i++)
5027 for (j=i+1; j < (ssize_t) number_coordinates; j++)
5029 alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x);
5030 if (alpha > (MagickRealType) quantum)
5031 quantum=(size_t) alpha;
5032 alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y);
5033 if (alpha > (MagickRealType) quantum)
5034 quantum=(size_t) alpha;
5037 quantum=(size_t) MagickMin((double) quantum/number_coordinates,
5038 (double) BezierQuantum);
5039 control_points=quantum*number_coordinates;
5040 coefficients=(MagickRealType *) AcquireQuantumMemory((size_t)
5041 number_coordinates,sizeof(*coefficients));
5042 points=(PointInfo *) AcquireQuantumMemory((size_t) control_points,
5044 if ((coefficients == (MagickRealType *) NULL) ||
5045 (points == (PointInfo *) NULL))
5046 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
5048 Compute bezier points.
5050 end=primitive_info[number_coordinates-1].point;
5051 for (i=0; i < (ssize_t) number_coordinates; i++)
5052 coefficients[i]=Permutate((ssize_t) number_coordinates-1,i);
5054 for (i=0; i < (ssize_t) control_points; i++)
5059 alpha=pow((double) (1.0-weight),(double) number_coordinates-1.0);
5060 for (j=0; j < (ssize_t) number_coordinates; j++)
5062 point.x+=alpha*coefficients[j]*p->point.x;
5063 point.y+=alpha*coefficients[j]*p->point.y;
5064 alpha*=weight/(1.0-weight);
5068 weight+=1.0/control_points;
5071 Bezier curves are just short segmented polys.
5074 for (i=0; i < (ssize_t) control_points; i++)
5076 TracePoint(p,points[i]);
5081 primitive_info->coordinates=(size_t) (p-primitive_info);
5082 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5084 p->primitive=primitive_info->primitive;
5087 points=(PointInfo *) RelinquishMagickMemory(points);
5088 coefficients=(MagickRealType *) RelinquishMagickMemory(coefficients);
5091 static void TraceCircle(PrimitiveInfo *primitive_info,const PointInfo start,
5092 const PointInfo end)
5103 alpha=end.x-start.x;
5105 radius=hypot((double) alpha,(double) beta);
5106 offset.x=(double) radius;
5107 offset.y=(double) radius;
5110 TraceEllipse(primitive_info,start,offset,degrees);
5113 static void TraceEllipse(PrimitiveInfo *primitive_info,const PointInfo start,
5114 const PointInfo stop,const PointInfo degrees)
5125 register PrimitiveInfo
5132 Ellipses are just short segmented polys.
5134 if ((stop.x == 0.0) && (stop.y == 0.0))
5136 TracePoint(primitive_info,start);
5139 delta=2.0/MagickMax(stop.x,stop.y);
5140 step=(MagickRealType) (MagickPI/8.0);
5141 if ((delta >= 0.0) && (delta < (MagickRealType) (MagickPI/8.0)))
5142 step=(MagickRealType) (MagickPI/(4*(MagickPI/delta/2+0.5)));
5143 angle.x=DegreesToRadians(degrees.x);
5145 while (y < degrees.x)
5147 angle.y=(double) (DegreesToRadians(y)-MagickEpsilon);
5148 for (p=primitive_info; angle.x < angle.y; angle.x+=step)
5150 point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*stop.x+start.x;
5151 point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*stop.y+start.y;
5152 TracePoint(p,point);
5155 point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*stop.x+start.x;
5156 point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*stop.y+start.y;
5157 TracePoint(p,point);
5159 primitive_info->coordinates=(size_t) (p-primitive_info);
5160 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5162 p->primitive=primitive_info->primitive;
5167 static void TraceLine(PrimitiveInfo *primitive_info,const PointInfo start,
5168 const PointInfo end)
5170 TracePoint(primitive_info,start);
5171 if ((fabs(start.x-end.x) <= MagickEpsilon) &&
5172 (fabs(start.y-end.y) <= MagickEpsilon))
5174 primitive_info->primitive=PointPrimitive;
5175 primitive_info->coordinates=1;
5178 TracePoint(primitive_info+1,end);
5179 (primitive_info+1)->primitive=primitive_info->primitive;
5180 primitive_info->coordinates=2;
5183 static size_t TracePath(PrimitiveInfo *primitive_info,const char *path)
5186 token[MaxTextExtent];
5208 register PrimitiveInfo
5223 number_coordinates=0;
5225 primitive_type=primitive_info->primitive;
5227 for (p=path; *p != '\0'; )
5229 while (isspace((int) ((unsigned char) *p)) != 0)
5233 last_attribute=attribute;
5234 attribute=(int) (*p++);
5255 GetMagickToken(p,&p,token);
5257 GetMagickToken(p,&p,token);
5258 arc.x=StringToDouble(token);
5259 GetMagickToken(p,&p,token);
5261 GetMagickToken(p,&p,token);
5262 arc.y=StringToDouble(token);
5263 GetMagickToken(p,&p,token);
5265 GetMagickToken(p,&p,token);
5266 angle=StringToDouble(token);
5267 GetMagickToken(p,&p,token);
5269 GetMagickToken(p,&p,token);
5270 large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
5271 GetMagickToken(p,&p,token);
5273 GetMagickToken(p,&p,token);
5274 sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
5275 GetMagickToken(p,&p,token);
5277 GetMagickToken(p,&p,token);
5278 x=StringToDouble(token);
5279 GetMagickToken(p,&p,token);
5281 GetMagickToken(p,&p,token);
5282 y=StringToDouble(token);
5283 end.x=(double) (attribute == (int) 'A' ? x : point.x+x);
5284 end.y=(double) (attribute == (int) 'A' ? y : point.y+y);
5285 TraceArcPath(q,point,end,arc,angle,large_arc,sweep);
5288 } while (IsPoint(p) != MagickFalse);
5295 Compute bezier points.
5300 for (i=1; i < 4; i++)
5302 GetMagickToken(p,&p,token);
5304 GetMagickToken(p,&p,token);
5305 x=StringToDouble(token);
5306 GetMagickToken(p,&p,token);
5308 GetMagickToken(p,&p,token);
5309 y=StringToDouble(token);
5310 end.x=(double) (attribute == (int) 'C' ? x : point.x+x);
5311 end.y=(double) (attribute == (int) 'C' ? y : point.y+y);
5314 for (i=0; i < 4; i++)
5315 (q+i)->point=points[i];
5319 } while (IsPoint(p) != MagickFalse);
5327 GetMagickToken(p,&p,token);
5329 GetMagickToken(p,&p,token);
5330 x=StringToDouble(token);
5331 point.x=(double) (attribute == (int) 'H' ? x: point.x+x);
5332 TracePoint(q,point);
5334 } while (IsPoint(p) != MagickFalse);
5342 GetMagickToken(p,&p,token);
5344 GetMagickToken(p,&p,token);
5345 x=StringToDouble(token);
5346 GetMagickToken(p,&p,token);
5348 GetMagickToken(p,&p,token);
5349 y=StringToDouble(token);
5350 point.x=(double) (attribute == (int) 'L' ? x : point.x+x);
5351 point.y=(double) (attribute == (int) 'L' ? y : point.y+y);
5352 TracePoint(q,point);
5354 } while (IsPoint(p) != MagickFalse);
5360 if (q != primitive_info)
5362 primitive_info->coordinates=(size_t) (q-primitive_info);
5363 number_coordinates+=primitive_info->coordinates;
5369 GetMagickToken(p,&p,token);
5371 GetMagickToken(p,&p,token);
5372 x=StringToDouble(token);
5373 GetMagickToken(p,&p,token);
5375 GetMagickToken(p,&p,token);
5376 y=StringToDouble(token);
5377 point.x=(double) (attribute == (int) 'M' ? x : point.x+x);
5378 point.y=(double) (attribute == (int) 'M' ? y : point.y+y);
5382 TracePoint(q,point);
5384 if ((i != 0) && (attribute == (int) 'M'))
5386 TracePoint(q,point);
5389 } while (IsPoint(p) != MagickFalse);
5396 Compute bezier points.
5401 for (i=1; i < 3; i++)
5403 GetMagickToken(p,&p,token);
5405 GetMagickToken(p,&p,token);
5406 x=StringToDouble(token);
5407 GetMagickToken(p,&p,token);
5409 GetMagickToken(p,&p,token);
5410 y=StringToDouble(token);
5413 end.x=(double) (attribute == (int) 'Q' ? x : point.x+x);
5414 end.y=(double) (attribute == (int) 'Q' ? y : point.y+y);
5417 for (i=0; i < 3; i++)
5418 (q+i)->point=points[i];
5422 } while (IsPoint(p) != MagickFalse);
5429 Compute bezier points.
5433 points[0]=points[3];
5434 points[1].x=2.0*points[3].x-points[2].x;
5435 points[1].y=2.0*points[3].y-points[2].y;
5436 for (i=2; i < 4; i++)
5438 GetMagickToken(p,&p,token);
5440 GetMagickToken(p,&p,token);
5441 x=StringToDouble(token);
5442 GetMagickToken(p,&p,token);
5444 GetMagickToken(p,&p,token);
5445 y=StringToDouble(token);
5448 end.x=(double) (attribute == (int) 'S' ? x : point.x+x);
5449 end.y=(double) (attribute == (int) 'S' ? y : point.y+y);
5452 if (strchr("CcSs",last_attribute) == (char *) NULL)
5454 points[0]=points[2];
5455 points[1]=points[3];
5457 for (i=0; i < 4; i++)
5458 (q+i)->point=points[i];
5462 } while (IsPoint(p) != MagickFalse);
5469 Compute bezier points.
5473 points[0]=points[2];
5474 points[1].x=2.0*points[2].x-points[1].x;
5475 points[1].y=2.0*points[2].y-points[1].y;
5476 for (i=2; i < 3; i++)
5478 GetMagickToken(p,&p,token);
5480 GetMagickToken(p,&p,token);
5481 x=StringToDouble(token);
5482 GetMagickToken(p,&p,token);
5484 GetMagickToken(p,&p,token);
5485 y=StringToDouble(token);
5486 end.x=(double) (attribute == (int) 'T' ? x : point.x+x);
5487 end.y=(double) (attribute == (int) 'T' ? y : point.y+y);
5490 if (strchr("QqTt",last_attribute) == (char *) NULL)
5492 points[0]=points[2];
5493 points[1]=points[3];
5495 for (i=0; i < 3; i++)
5496 (q+i)->point=points[i];
5500 } while (IsPoint(p) != MagickFalse);
5508 GetMagickToken(p,&p,token);
5510 GetMagickToken(p,&p,token);
5511 y=StringToDouble(token);
5512 point.y=(double) (attribute == (int) 'V' ? y : point.y+y);
5513 TracePoint(q,point);
5515 } while (IsPoint(p) != MagickFalse);
5522 TracePoint(q,point);
5524 primitive_info->coordinates=(size_t) (q-primitive_info);
5525 number_coordinates+=primitive_info->coordinates;
5532 if (isalpha((int) ((unsigned char) attribute)) != 0)
5533 (void) fprintf(stderr,"attribute not recognized: %c\n",attribute);
5538 primitive_info->coordinates=(size_t) (q-primitive_info);
5539 number_coordinates+=primitive_info->coordinates;
5540 for (i=0; i < (ssize_t) number_coordinates; i++)
5543 q->primitive=primitive_type;
5545 q->method=FillToBorderMethod;
5548 return(number_coordinates);
5551 static void TraceRectangle(PrimitiveInfo *primitive_info,const PointInfo start,
5552 const PointInfo end)
5557 register PrimitiveInfo
5564 TracePoint(p,start);
5568 TracePoint(p,point);
5574 TracePoint(p,point);
5576 TracePoint(p,start);
5578 primitive_info->coordinates=(size_t) (p-primitive_info);
5579 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5581 p->primitive=primitive_info->primitive;
5586 static void TraceRoundRectangle(PrimitiveInfo *primitive_info,
5587 const PointInfo start,const PointInfo end,PointInfo arc)
5594 register PrimitiveInfo
5601 offset.x=fabs(end.x-start.x);
5602 offset.y=fabs(end.y-start.y);
5603 if (arc.x > (0.5*offset.x))
5605 if (arc.y > (0.5*offset.y))
5607 point.x=start.x+offset.x-arc.x;
5608 point.y=start.y+arc.y;
5611 TraceEllipse(p,point,arc,degrees);
5613 point.x=start.x+offset.x-arc.x;
5614 point.y=start.y+offset.y-arc.y;
5617 TraceEllipse(p,point,arc,degrees);
5619 point.x=start.x+arc.x;
5620 point.y=start.y+offset.y-arc.y;
5623 TraceEllipse(p,point,arc,degrees);
5625 point.x=start.x+arc.x;
5626 point.y=start.y+arc.y;
5629 TraceEllipse(p,point,arc,degrees);
5631 TracePoint(p,primitive_info->point);
5633 primitive_info->coordinates=(size_t) (p-primitive_info);
5634 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5636 p->primitive=primitive_info->primitive;
5641 static void TraceSquareLinecap(PrimitiveInfo *primitive_info,
5642 const size_t number_vertices,const MagickRealType offset)
5647 register MagickRealType
5659 for (i=1; i < (ssize_t) number_vertices; i++)
5661 dx=primitive_info[0].point.x-primitive_info[i].point.x;
5662 dy=primitive_info[0].point.y-primitive_info[i].point.y;
5663 if ((fabs((double) dx) >= MagickEpsilon) ||
5664 (fabs((double) dy) >= MagickEpsilon))
5667 if (i == (ssize_t) number_vertices)
5668 i=(ssize_t) number_vertices-1L;
5669 distance=hypot((double) dx,(double) dy);
5670 primitive_info[0].point.x=(double) (primitive_info[i].point.x+
5671 dx*(distance+offset)/distance);
5672 primitive_info[0].point.y=(double) (primitive_info[i].point.y+
5673 dy*(distance+offset)/distance);
5674 for (j=(ssize_t) number_vertices-2; j >= 0; j--)
5676 dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x;
5677 dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y;
5678 if ((fabs((double) dx) >= MagickEpsilon) ||
5679 (fabs((double) dy) >= MagickEpsilon))
5682 distance=hypot((double) dx,(double) dy);
5683 primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+
5684 dx*(distance+offset)/distance);
5685 primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+
5686 dy*(distance+offset)/distance);
5689 static PrimitiveInfo *TraceStrokePolygon(const DrawInfo *draw_info,
5690 const PrimitiveInfo *primitive_info)
5692 typedef struct _LineSegment
5744 number_vertices=primitive_info->coordinates;
5745 max_strokes=2*number_vertices+6*BezierQuantum+360;
5746 path_p=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes,
5748 path_q=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes,
5750 polygon_primitive=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
5751 number_vertices+2UL,sizeof(*polygon_primitive));
5752 if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL) ||
5753 (polygon_primitive == (PrimitiveInfo *) NULL))
5754 return((PrimitiveInfo *) NULL);
5755 (void) CopyMagickMemory(polygon_primitive,primitive_info,(size_t)
5756 number_vertices*sizeof(*polygon_primitive));
5758 (primitive_info[number_vertices-1].point.x == primitive_info[0].point.x) &&
5759 (primitive_info[number_vertices-1].point.y == primitive_info[0].point.y) ?
5760 MagickTrue : MagickFalse;
5761 if ((draw_info->linejoin == RoundJoin) ||
5762 ((draw_info->linejoin == MiterJoin) && (closed_path != MagickFalse)))
5764 polygon_primitive[number_vertices]=primitive_info[1];
5767 polygon_primitive[number_vertices].primitive=UndefinedPrimitive;
5769 Compute the slope for the first line segment, p.
5773 for (n=1; n < (ssize_t) number_vertices; n++)
5775 dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x;
5776 dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y;
5777 if ((fabs(dx.p) >= MagickEpsilon) || (fabs(dy.p) >= MagickEpsilon))
5780 if (n == (ssize_t) number_vertices)
5781 n=(ssize_t) number_vertices-1L;
5783 inverse_slope.p=0.0;
5784 if (fabs(dx.p) <= MagickEpsilon)
5787 slope.p=dy.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5789 slope.p=dy.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5792 if (fabs(dy.p) <= MagickEpsilon)
5795 inverse_slope.p=dx.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5797 inverse_slope.p=dx.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5802 inverse_slope.p=(-1.0/slope.p);
5804 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5805 miterlimit=(MagickRealType) (draw_info->miterlimit*draw_info->miterlimit*
5807 if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse))
5808 TraceSquareLinecap(polygon_primitive,number_vertices,mid);
5809 offset.x=sqrt((double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0)));
5810 offset.y=(double) (offset.x*inverse_slope.p);
5811 if ((dy.p*offset.x-dx.p*offset.y) > 0.0)
5813 box_p[0].x=polygon_primitive[0].point.x-offset.x;
5814 box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p;
5815 box_p[1].x=polygon_primitive[n].point.x-offset.x;
5816 box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p;
5817 box_q[0].x=polygon_primitive[0].point.x+offset.x;
5818 box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p;
5819 box_q[1].x=polygon_primitive[n].point.x+offset.x;
5820 box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p;
5824 box_p[0].x=polygon_primitive[0].point.x+offset.x;
5825 box_p[0].y=polygon_primitive[0].point.y+offset.y;
5826 box_p[1].x=polygon_primitive[n].point.x+offset.x;
5827 box_p[1].y=polygon_primitive[n].point.y+offset.y;
5828 box_q[0].x=polygon_primitive[0].point.x-offset.x;
5829 box_q[0].y=polygon_primitive[0].point.y-offset.y;
5830 box_q[1].x=polygon_primitive[n].point.x-offset.x;
5831 box_q[1].y=polygon_primitive[n].point.y-offset.y;
5834 Create strokes for the line join attribute: bevel, miter, round.
5838 path_q[p++]=box_q[0];
5839 path_p[q++]=box_p[0];
5840 for (i=(ssize_t) n+1; i < (ssize_t) number_vertices; i++)
5843 Compute the slope for this line segment, q.
5845 dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x;
5846 dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y;
5847 dot_product=dx.q*dx.q+dy.q*dy.q;
5848 if (dot_product < 0.25)
5851 inverse_slope.q=0.0;
5852 if (fabs(dx.q) < MagickEpsilon)
5855 slope.q=dy.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5857 slope.q=dy.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5860 if (fabs(dy.q) <= MagickEpsilon)
5863 inverse_slope.q=dx.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5865 inverse_slope.q=dx.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5870 inverse_slope.q=(-1.0/slope.q);
5872 offset.x=sqrt((double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0)));
5873 offset.y=(double) (offset.x*inverse_slope.q);
5874 dot_product=dy.q*offset.x-dx.q*offset.y;
5875 if (dot_product > 0.0)
5877 box_p[2].x=polygon_primitive[n].point.x-offset.x;
5878 box_p[2].y=polygon_primitive[n].point.y-offset.y;
5879 box_p[3].x=polygon_primitive[i].point.x-offset.x;
5880 box_p[3].y=polygon_primitive[i].point.y-offset.y;
5881 box_q[2].x=polygon_primitive[n].point.x+offset.x;
5882 box_q[2].y=polygon_primitive[n].point.y+offset.y;
5883 box_q[3].x=polygon_primitive[i].point.x+offset.x;
5884 box_q[3].y=polygon_primitive[i].point.y+offset.y;
5888 box_p[2].x=polygon_primitive[n].point.x+offset.x;
5889 box_p[2].y=polygon_primitive[n].point.y+offset.y;
5890 box_p[3].x=polygon_primitive[i].point.x+offset.x;
5891 box_p[3].y=polygon_primitive[i].point.y+offset.y;
5892 box_q[2].x=polygon_primitive[n].point.x-offset.x;
5893 box_q[2].y=polygon_primitive[n].point.y-offset.y;
5894 box_q[3].x=polygon_primitive[i].point.x-offset.x;
5895 box_q[3].y=polygon_primitive[i].point.y-offset.y;
5897 if (fabs((double) (slope.p-slope.q)) <= MagickEpsilon)
5904 box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+
5905 box_p[3].y)/(slope.p-slope.q));
5906 box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y);
5907 box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+
5908 box_q[3].y)/(slope.p-slope.q));
5909 box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y);
5911 if (q >= (ssize_t) (max_strokes-6*BezierQuantum-360))
5913 max_strokes+=6*BezierQuantum+360;
5914 path_p=(PointInfo *) ResizeQuantumMemory(path_p,(size_t) max_strokes,
5916 path_q=(PointInfo *) ResizeQuantumMemory(path_q,(size_t) max_strokes,
5918 if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL))
5920 polygon_primitive=(PrimitiveInfo *)
5921 RelinquishMagickMemory(polygon_primitive);
5922 return((PrimitiveInfo *) NULL);
5925 dot_product=dx.q*dy.p-dx.p*dy.q;
5926 if (dot_product <= 0.0)
5927 switch (draw_info->linejoin)
5931 path_q[q++]=box_q[1];
5932 path_q[q++]=box_q[2];
5933 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5934 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5935 if (dot_product <= miterlimit)
5936 path_p[p++]=box_p[4];
5939 path_p[p++]=box_p[1];
5940 path_p[p++]=box_p[2];
5946 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5947 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5948 if (dot_product <= miterlimit)
5950 path_q[q++]=box_q[4];
5951 path_p[p++]=box_p[4];
5955 path_q[q++]=box_q[1];
5956 path_q[q++]=box_q[2];
5957 path_p[p++]=box_p[1];
5958 path_p[p++]=box_p[2];
5964 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5965 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5966 if (dot_product <= miterlimit)
5967 path_p[p++]=box_p[4];
5970 path_p[p++]=box_p[1];
5971 path_p[p++]=box_p[2];
5973 center=polygon_primitive[n].point;
5974 theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x);
5975 theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x);
5976 if (theta.q < theta.p)
5977 theta.q+=(MagickRealType) (2.0*MagickPI);
5978 arc_segments=(size_t) ceil((double) ((theta.q-theta.p)/
5979 (2.0*sqrt((double) (1.0/mid)))));
5980 path_q[q].x=box_q[1].x;
5981 path_q[q].y=box_q[1].y;
5983 for (j=1; j < (ssize_t) arc_segments; j++)
5985 delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments);
5986 path_q[q].x=(double) (center.x+mid*cos(fmod((double)
5987 (theta.p+delta_theta),DegreesToRadians(360.0))));
5988 path_q[q].y=(double) (center.y+mid*sin(fmod((double)
5989 (theta.p+delta_theta),DegreesToRadians(360.0))));
5992 path_q[q++]=box_q[2];
5999 switch (draw_info->linejoin)
6003 path_p[p++]=box_p[1];
6004 path_p[p++]=box_p[2];
6005 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6006 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6007 if (dot_product <= miterlimit)
6008 path_q[q++]=box_q[4];
6011 path_q[q++]=box_q[1];
6012 path_q[q++]=box_q[2];
6018 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6019 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6020 if (dot_product <= miterlimit)
6022 path_q[q++]=box_q[4];
6023 path_p[p++]=box_p[4];
6027 path_q[q++]=box_q[1];
6028 path_q[q++]=box_q[2];
6029 path_p[p++]=box_p[1];
6030 path_p[p++]=box_p[2];
6036 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6037 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6038 if (dot_product <= miterlimit)
6039 path_q[q++]=box_q[4];
6042 path_q[q++]=box_q[1];
6043 path_q[q++]=box_q[2];
6045 center=polygon_primitive[n].point;
6046 theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x);
6047 theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x);
6048 if (theta.p < theta.q)
6049 theta.p+=(MagickRealType) (2.0*MagickPI);
6050 arc_segments=(size_t) ceil((double) ((theta.p-theta.q)/
6051 (2.0*sqrt((double) (1.0/mid)))));
6052 path_p[p++]=box_p[1];
6053 for (j=1; j < (ssize_t) arc_segments; j++)
6055 delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments);
6056 path_p[p].x=(double) (center.x+mid*cos(fmod((double)
6057 (theta.p+delta_theta),DegreesToRadians(360.0))));
6058 path_p[p].y=(double) (center.y+mid*sin(fmod((double)
6059 (theta.p+delta_theta),DegreesToRadians(360.0))));
6062 path_p[p++]=box_p[2];
6069 inverse_slope.p=inverse_slope.q;
6078 path_p[p++]=box_p[1];
6079 path_q[q++]=box_q[1];
6081 Trace stroked polygon.
6083 stroke_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
6084 (p+q+2UL*closed_path+2UL),sizeof(*stroke_polygon));
6085 if (stroke_polygon != (PrimitiveInfo *) NULL)
6087 for (i=0; i < (ssize_t) p; i++)
6089 stroke_polygon[i]=polygon_primitive[0];
6090 stroke_polygon[i].point=path_p[i];
6092 if (closed_path != MagickFalse)
6094 stroke_polygon[i]=polygon_primitive[0];
6095 stroke_polygon[i].point=stroke_polygon[0].point;
6098 for ( ; i < (ssize_t) (p+q+closed_path); i++)
6100 stroke_polygon[i]=polygon_primitive[0];
6101 stroke_polygon[i].point=path_q[p+q+closed_path-(i+1)];
6103 if (closed_path != MagickFalse)
6105 stroke_polygon[i]=polygon_primitive[0];
6106 stroke_polygon[i].point=stroke_polygon[p+closed_path].point;
6109 stroke_polygon[i]=polygon_primitive[0];
6110 stroke_polygon[i].point=stroke_polygon[0].point;
6112 stroke_polygon[i].primitive=UndefinedPrimitive;
6113 stroke_polygon[0].coordinates=(size_t) (p+q+2*closed_path+1);
6115 path_p=(PointInfo *) RelinquishMagickMemory(path_p);
6116 path_q=(PointInfo *) RelinquishMagickMemory(path_q);
6117 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive);
6118 return(stroke_polygon);