2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 % D D RRRR AAAAA W W W %
13 % MagickCore Image Drawing Methods %
21 % Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
22 % dedicated to making software imaging solutions freely available. %
24 % You may not use this file except in compliance with the License. You may %
25 % obtain a copy of the License at %
27 % http://www.imagemagick.org/script/license.php %
29 % Unless required by applicable law or agreed to in writing, software %
30 % distributed under the License is distributed on an "AS IS" BASIS, %
31 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
32 % See the License for the specific language governing permissions and %
33 % limitations under the License. %
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 % Bill Radcliffe of Corbis (www.corbis.com) contributed the polygon
38 % rendering code based on Paul Heckbert's "Concave Polygon Scan Conversion",
39 % Graphics Gems, 1990. Leonard Rosenthal and David Harr of Appligent
40 % (www.appligent.com) contributed the dash pattern, linecap stroking
41 % algorithm, and minor rendering improvements.
48 #include "magick/studio.h"
49 #include "magick/annotate.h"
50 #include "magick/artifact.h"
51 #include "magick/blob.h"
52 #include "magick/cache.h"
53 #include "magick/cache-view.h"
54 #include "magick/color.h"
55 #include "magick/composite.h"
56 #include "magick/composite-private.h"
57 #include "magick/constitute.h"
58 #include "magick/draw.h"
59 #include "magick/draw-private.h"
60 #include "magick/enhance.h"
61 #include "magick/exception.h"
62 #include "magick/exception-private.h"
63 #include "magick/gem.h"
64 #include "magick/geometry.h"
65 #include "magick/image-private.h"
66 #include "magick/list.h"
67 #include "magick/log.h"
68 #include "magick/monitor.h"
69 #include "magick/monitor-private.h"
70 #include "magick/option.h"
71 #include "magick/paint.h"
72 #include "magick/pixel-private.h"
73 #include "magick/property.h"
74 #include "magick/resample.h"
75 #include "magick/resample-private.h"
76 #include "magick/string_.h"
77 #include "magick/string-private.h"
78 #include "magick/thread-private.h"
79 #include "magick/token.h"
80 #include "magick/transform.h"
81 #include "magick/utility.h"
86 #define BezierQuantum 200
91 typedef struct _EdgeInfo
115 typedef struct _ElementInfo
125 typedef struct _PolygonInfo
143 typedef struct _PathInfo
153 Forward declarations.
155 static MagickBooleanType
156 DrawStrokePolygon(Image *,const DrawInfo *,const PrimitiveInfo *);
159 *TraceStrokePolygon(const DrawInfo *,const PrimitiveInfo *);
162 TracePath(PrimitiveInfo *,const char *);
165 TraceArc(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo),
166 TraceArcPath(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo,
167 const MagickRealType,const MagickBooleanType,const MagickBooleanType),
168 TraceBezier(PrimitiveInfo *,const unsigned long),
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 unsigned long,const MagickRealType);
178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 % A c q u i r e D r a w I n f o %
186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188 % AcquireDrawInfo() returns a DrawInfo structure properly initialized.
190 % The format of the AcquireDrawInfo method is:
192 % DrawInfo *AcquireDrawInfo(void)
195 MagickExport DrawInfo *AcquireDrawInfo(void)
200 draw_info=(DrawInfo *) AcquireAlignedMemory(1,sizeof(*draw_info));
201 if (draw_info == (DrawInfo *) NULL)
202 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
203 GetDrawInfo((ImageInfo *) NULL,draw_info);
208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212 % C l o n e D r a w I n f o %
216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 % CloneDrawInfo() makes a copy of the given draw info structure. If NULL
219 % is specified, a new image info structure is created initialized to
222 % The format of the CloneDrawInfo method is:
224 % DrawInfo *CloneDrawInfo(const ImageInfo *image_info,
225 % const DrawInfo *draw_info)
227 % A description of each parameter follows:
229 % o image_info: the image info.
231 % o draw_info: the draw info.
234 MagickExport DrawInfo *CloneDrawInfo(const ImageInfo *image_info,
235 const DrawInfo *draw_info)
240 clone_info=(DrawInfo *) AcquireAlignedMemory(1,sizeof(*clone_info));
241 if (clone_info == (DrawInfo *) NULL)
242 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
243 GetDrawInfo(image_info,clone_info);
244 if (draw_info == (DrawInfo *) NULL)
246 if (clone_info->primitive != (char *) NULL)
247 (void) CloneString(&clone_info->primitive,draw_info->primitive);
248 if (draw_info->geometry != (char *) NULL)
249 (void) CloneString(&clone_info->geometry,draw_info->geometry);
250 clone_info->viewbox=draw_info->viewbox;
251 clone_info->affine=draw_info->affine;
252 clone_info->gravity=draw_info->gravity;
253 clone_info->fill=draw_info->fill;
254 clone_info->stroke=draw_info->stroke;
255 clone_info->stroke_width=draw_info->stroke_width;
256 if (draw_info->fill_pattern != (Image *) NULL)
257 clone_info->fill_pattern=CloneImage(draw_info->fill_pattern,0,0,MagickTrue,
258 &draw_info->fill_pattern->exception);
260 if (draw_info->tile != (Image *) NULL)
261 clone_info->fill_pattern=CloneImage(draw_info->tile,0,0,MagickTrue,
262 &draw_info->tile->exception);
263 clone_info->tile=NewImageList(); /* tile is deprecated */
264 if (draw_info->stroke_pattern != (Image *) NULL)
265 clone_info->stroke_pattern=CloneImage(draw_info->stroke_pattern,0,0,
266 MagickTrue,&draw_info->stroke_pattern->exception);
267 clone_info->stroke_antialias=draw_info->stroke_antialias;
268 clone_info->text_antialias=draw_info->text_antialias;
269 clone_info->fill_rule=draw_info->fill_rule;
270 clone_info->linecap=draw_info->linecap;
271 clone_info->linejoin=draw_info->linejoin;
272 clone_info->miterlimit=draw_info->miterlimit;
273 clone_info->dash_offset=draw_info->dash_offset;
274 clone_info->decorate=draw_info->decorate;
275 clone_info->compose=draw_info->compose;
276 if (draw_info->text != (char *) NULL)
277 (void) CloneString(&clone_info->text,draw_info->text);
278 if (draw_info->font != (char *) NULL)
279 (void) CloneString(&clone_info->font,draw_info->font);
280 if (draw_info->metrics != (char *) NULL)
281 (void) CloneString(&clone_info->metrics,draw_info->metrics);
282 if (draw_info->family != (char *) NULL)
283 (void) CloneString(&clone_info->family,draw_info->family);
284 clone_info->style=draw_info->style;
285 clone_info->stretch=draw_info->stretch;
286 clone_info->weight=draw_info->weight;
287 if (draw_info->encoding != (char *) NULL)
288 (void) CloneString(&clone_info->encoding,draw_info->encoding);
289 clone_info->pointsize=draw_info->pointsize;
290 clone_info->kerning=draw_info->kerning;
291 clone_info->interline_spacing=draw_info->interline_spacing;
292 clone_info->interword_spacing=draw_info->interword_spacing;
293 clone_info->direction=draw_info->direction;
294 if (draw_info->density != (char *) NULL)
295 (void) CloneString(&clone_info->density,draw_info->density);
296 clone_info->align=draw_info->align;
297 clone_info->undercolor=draw_info->undercolor;
298 clone_info->border_color=draw_info->border_color;
299 if (draw_info->server_name != (char *) NULL)
300 (void) CloneString(&clone_info->server_name,draw_info->server_name);
301 if (draw_info->dash_pattern != (double *) NULL)
306 for (x=0; draw_info->dash_pattern[x] != 0.0; x++) ;
307 clone_info->dash_pattern=(double *) AcquireQuantumMemory((size_t) x+1UL,
308 sizeof(*clone_info->dash_pattern));
309 if (clone_info->dash_pattern == (double *) NULL)
310 ThrowFatalException(ResourceLimitFatalError,
311 "UnableToAllocateDashPattern");
312 (void) CopyMagickMemory(clone_info->dash_pattern,draw_info->dash_pattern,
313 (size_t) (x+1)*sizeof(*clone_info->dash_pattern));
315 clone_info->gradient=draw_info->gradient;
316 if (draw_info->gradient.stops != (StopInfo *) NULL)
321 number_stops=clone_info->gradient.number_stops;
322 clone_info->gradient.stops=(StopInfo *) AcquireQuantumMemory((size_t)
323 number_stops,sizeof(*clone_info->gradient.stops));
324 if (clone_info->gradient.stops == (StopInfo *) NULL)
325 ThrowFatalException(ResourceLimitFatalError,
326 "UnableToAllocateDashPattern");
327 (void) CopyMagickMemory(clone_info->gradient.stops,
328 draw_info->gradient.stops,(size_t) number_stops*
329 sizeof(*clone_info->gradient.stops));
331 if (draw_info->clip_mask != (char *) NULL)
332 (void) CloneString(&clone_info->clip_mask,draw_info->clip_mask);
333 clone_info->bounds=draw_info->bounds;
334 clone_info->clip_units=draw_info->clip_units;
335 clone_info->render=draw_info->render;
336 clone_info->opacity=draw_info->opacity;
337 clone_info->element_reference=draw_info->element_reference;
338 clone_info->debug=IsEventLogging();
343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
347 + C o n v e r t P a t h T o P o l y g o n %
351 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353 % ConvertPathToPolygon() converts a path to the more efficient sorted
356 % The format of the ConvertPathToPolygon method is:
358 % PolygonInfo *ConvertPathToPolygon(const DrawInfo *draw_info,
359 % const PathInfo *path_info)
361 % A description of each parameter follows:
363 % o Method ConvertPathToPolygon returns the path in a more efficient sorted
364 % rendering form of type PolygonInfo.
366 % o draw_info: Specifies a pointer to an DrawInfo structure.
368 % o path_info: Specifies a pointer to an PathInfo structure.
373 #if defined(__cplusplus) || defined(c_plusplus)
377 static int CompareEdges(const void *x,const void *y)
379 register const EdgeInfo
386 p=(const EdgeInfo *) x;
387 q=(const EdgeInfo *) y;
388 if ((p->points[0].y-MagickEpsilon) > q->points[0].y)
390 if ((p->points[0].y+MagickEpsilon) < q->points[0].y)
392 if ((p->points[0].x-MagickEpsilon) > q->points[0].x)
394 if ((p->points[0].x+MagickEpsilon) < q->points[0].x)
396 if (((p->points[1].x-p->points[0].x)*(q->points[1].y-q->points[0].y)-
397 (p->points[1].y-p->points[0].y)*(q->points[1].x-q->points[0].x)) > 0.0)
402 #if defined(__cplusplus) || defined(c_plusplus)
406 static void LogPolygonInfo(const PolygonInfo *polygon_info)
415 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin active-edge");
416 p=polygon_info->edges;
417 for (i=0; i < (long) polygon_info->number_edges; i++)
419 (void) LogMagickEvent(DrawEvent,GetMagickModule()," edge %lu:",i);
420 (void) LogMagickEvent(DrawEvent,GetMagickModule()," direction: %s",
421 p->direction != MagickFalse ? "down" : "up");
422 (void) LogMagickEvent(DrawEvent,GetMagickModule()," ghostline: %s",
423 p->ghostline != MagickFalse ? "transparent" : "opaque");
424 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
425 " bounds: %g,%g - %g,%g",p->bounds.x1,p->bounds.y1,
426 p->bounds.x2,p->bounds.y2);
427 for (j=0; j < (long) p->number_points; j++)
428 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %g,%g",
429 p->points[j].x,p->points[j].y);
432 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end active-edge");
435 static void ReversePoints(PointInfo *points,const unsigned long number_points)
443 for (i=0; i < (long) (number_points >> 1); i++)
446 points[i]=points[number_points-(i+1)];
447 points[number_points-(i+1)]=point;
451 static PolygonInfo *ConvertPathToPolygon(
452 const DrawInfo *magick_unused(draw_info),const PathInfo *path_info)
481 Convert a path to the more efficient sorted rendering form.
483 polygon_info=(PolygonInfo *) AcquireAlignedMemory(1,sizeof(*polygon_info));
484 if (polygon_info == (PolygonInfo *) NULL)
485 return((PolygonInfo *) NULL);
487 polygon_info->edges=(EdgeInfo *) AcquireQuantumMemory((size_t) number_edges,
488 sizeof(*polygon_info->edges));
489 if (polygon_info->edges == (EdgeInfo *) NULL)
490 return((PolygonInfo *) NULL);
493 ghostline=MagickFalse;
496 points=(PointInfo *) NULL;
497 (void) ResetMagickMemory(&point,0,sizeof(point));
498 (void) ResetMagickMemory(&bounds,0,sizeof(bounds));
499 for (i=0; path_info[i].code != EndCode; i++)
501 if ((path_info[i].code == MoveToCode) || (path_info[i].code == OpenCode) ||
502 (path_info[i].code == GhostlineCode))
507 if ((points != (PointInfo *) NULL) && (n >= 2))
509 if (edge == number_edges)
512 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
513 polygon_info->edges,(size_t) number_edges,
514 sizeof(*polygon_info->edges));
515 if (polygon_info->edges == (EdgeInfo *) NULL)
516 return((PolygonInfo *) NULL);
518 polygon_info->edges[edge].number_points=(unsigned long) n;
519 polygon_info->edges[edge].scanline=(-1.0);
520 polygon_info->edges[edge].highwater=0;
521 polygon_info->edges[edge].ghostline=ghostline;
522 polygon_info->edges[edge].direction=(long) (direction > 0);
524 ReversePoints(points,(unsigned long) n);
525 polygon_info->edges[edge].points=points;
526 polygon_info->edges[edge].bounds=bounds;
527 polygon_info->edges[edge].bounds.y1=points[0].y;
528 polygon_info->edges[edge].bounds.y2=points[n-1].y;
529 points=(PointInfo *) NULL;
530 ghostline=MagickFalse;
533 if (points == (PointInfo *) NULL)
536 points=(PointInfo *) AcquireQuantumMemory((size_t) number_points,
538 if (points == (PointInfo *) NULL)
539 return((PolygonInfo *) NULL);
541 ghostline=path_info[i].code == GhostlineCode ? MagickTrue : MagickFalse;
542 point=path_info[i].point;
553 next_direction=((path_info[i].point.y > point.y) ||
554 ((path_info[i].point.y == point.y) &&
555 (path_info[i].point.x > point.x))) ? 1 : -1;
556 if ((direction != 0) && (direction != next_direction))
562 if (edge == number_edges)
565 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
566 polygon_info->edges,(size_t) number_edges,
567 sizeof(*polygon_info->edges));
568 if (polygon_info->edges == (EdgeInfo *) NULL)
569 return((PolygonInfo *) NULL);
571 polygon_info->edges[edge].number_points=(unsigned long) n;
572 polygon_info->edges[edge].scanline=(-1.0);
573 polygon_info->edges[edge].highwater=0;
574 polygon_info->edges[edge].ghostline=ghostline;
575 polygon_info->edges[edge].direction=(long) (direction > 0);
577 ReversePoints(points,(unsigned long) n);
578 polygon_info->edges[edge].points=points;
579 polygon_info->edges[edge].bounds=bounds;
580 polygon_info->edges[edge].bounds.y1=points[0].y;
581 polygon_info->edges[edge].bounds.y2=points[n-1].y;
583 points=(PointInfo *) AcquireQuantumMemory((size_t) number_points,
585 if (points == (PointInfo *) NULL)
586 return((PolygonInfo *) NULL);
588 ghostline=MagickFalse;
594 direction=next_direction;
595 if (points == (PointInfo *) NULL)
597 if (n == (long) number_points)
600 points=(PointInfo *) ResizeQuantumMemory(points,(size_t) number_points,
602 if (points == (PointInfo *) NULL)
603 return((PolygonInfo *) NULL);
605 point=path_info[i].point;
607 if (point.x < bounds.x1)
609 if (point.x > bounds.x2)
613 if (points != (PointInfo *) NULL)
616 points=(PointInfo *) RelinquishMagickMemory(points);
619 if (edge == number_edges)
622 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
623 polygon_info->edges,(size_t) number_edges,
624 sizeof(*polygon_info->edges));
625 if (polygon_info->edges == (EdgeInfo *) NULL)
626 return((PolygonInfo *) NULL);
628 polygon_info->edges[edge].number_points=(unsigned long) n;
629 polygon_info->edges[edge].scanline=(-1.0);
630 polygon_info->edges[edge].highwater=0;
631 polygon_info->edges[edge].ghostline=ghostline;
632 polygon_info->edges[edge].direction=(long) (direction > 0);
634 ReversePoints(points,(unsigned long) n);
635 polygon_info->edges[edge].points=points;
636 polygon_info->edges[edge].bounds=bounds;
637 polygon_info->edges[edge].bounds.y1=points[0].y;
638 polygon_info->edges[edge].bounds.y2=points[n-1].y;
639 ghostline=MagickFalse;
643 polygon_info->number_edges=edge;
644 qsort(polygon_info->edges,(size_t) polygon_info->number_edges,
645 sizeof(*polygon_info->edges),CompareEdges);
646 if (IsEventLogging() != MagickFalse)
647 LogPolygonInfo(polygon_info);
648 return(polygon_info);
652 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
656 + C o n v e r t P r i m i t i v e T o P a t h %
660 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
662 % ConvertPrimitiveToPath() converts a PrimitiveInfo structure into a vector
665 % The format of the ConvertPrimitiveToPath method is:
667 % PathInfo *ConvertPrimitiveToPath(const DrawInfo *draw_info,
668 % const PrimitiveInfo *primitive_info)
670 % A description of each parameter follows:
672 % o Method ConvertPrimitiveToPath returns a vector path structure of type
675 % o draw_info: a structure of type DrawInfo.
677 % o primitive_info: Specifies a pointer to an PrimitiveInfo structure.
682 static void LogPathInfo(const PathInfo *path_info)
684 register const PathInfo
687 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin vector-path");
688 for (p=path_info; p->code != EndCode; p++)
689 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
690 " %g,%g %s",p->point.x,p->point.y,p->code == GhostlineCode ?
691 "moveto ghostline" : p->code == OpenCode ? "moveto open" :
692 p->code == MoveToCode ? "moveto" : p->code == LineToCode ? "lineto" :
694 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end vector-path");
697 static PathInfo *ConvertPrimitiveToPath(
698 const DrawInfo *magick_unused(draw_info),const PrimitiveInfo *primitive_info)
719 Converts a PrimitiveInfo structure into a vector path structure.
721 switch (primitive_info->primitive)
728 return((PathInfo *) NULL);
732 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
733 path_info=(PathInfo *) AcquireQuantumMemory((size_t) (2UL*i+3UL),
735 if (path_info == (PathInfo *) NULL)
736 return((PathInfo *) NULL);
744 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
747 if (coordinates <= 0)
749 coordinates=(long) primitive_info[i].coordinates;
750 p=primitive_info[i].point;
756 Eliminate duplicate points.
758 if ((i == 0) || (fabs(q.x-primitive_info[i].point.x) > MagickEpsilon) ||
759 (fabs(q.y-primitive_info[i].point.y) > MagickEpsilon))
761 path_info[n].code=code;
762 path_info[n].point=primitive_info[i].point;
763 q=primitive_info[i].point;
768 if ((fabs(p.x-primitive_info[i].point.x) <= MagickEpsilon) &&
769 (fabs(p.y-primitive_info[i].point.y) <= MagickEpsilon))
772 Mark the p point as open if it does not match the q.
774 path_info[start].code=OpenCode;
775 path_info[n].code=GhostlineCode;
776 path_info[n].point=primitive_info[i].point;
778 path_info[n].code=LineToCode;
779 path_info[n].point=p;
782 path_info[n].code=EndCode;
783 path_info[n].point.x=0.0;
784 path_info[n].point.y=0.0;
785 if (IsEventLogging() != MagickFalse)
786 LogPathInfo(path_info);
791 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
795 % D e s t r o y D r a w I n f o %
799 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
801 % DestroyDrawInfo() deallocates memory associated with an DrawInfo
804 % The format of the DestroyDrawInfo method is:
806 % DrawInfo *DestroyDrawInfo(DrawInfo *draw_info)
808 % A description of each parameter follows:
810 % o draw_info: the draw info.
813 MagickExport DrawInfo *DestroyDrawInfo(DrawInfo *draw_info)
815 if (draw_info->debug != MagickFalse)
816 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
817 assert(draw_info != (DrawInfo *) NULL);
818 assert(draw_info->signature == MagickSignature);
819 if (draw_info->primitive != (char *) NULL)
820 draw_info->primitive=DestroyString(draw_info->primitive);
821 if (draw_info->text != (char *) NULL)
822 draw_info->text=DestroyString(draw_info->text);
823 if (draw_info->geometry != (char *) NULL)
824 draw_info->geometry=DestroyString(draw_info->geometry);
825 if (draw_info->tile != (Image *) NULL)
826 draw_info->tile=DestroyImage(draw_info->tile);
827 if (draw_info->fill_pattern != (Image *) NULL)
828 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
829 if (draw_info->stroke_pattern != (Image *) NULL)
830 draw_info->stroke_pattern=DestroyImage(draw_info->stroke_pattern);
831 if (draw_info->font != (char *) NULL)
832 draw_info->font=DestroyString(draw_info->font);
833 if (draw_info->metrics != (char *) NULL)
834 draw_info->metrics=DestroyString(draw_info->metrics);
835 if (draw_info->family != (char *) NULL)
836 draw_info->family=DestroyString(draw_info->family);
837 if (draw_info->encoding != (char *) NULL)
838 draw_info->encoding=DestroyString(draw_info->encoding);
839 if (draw_info->density != (char *) NULL)
840 draw_info->density=DestroyString(draw_info->density);
841 if (draw_info->server_name != (char *) NULL)
842 draw_info->server_name=(char *)
843 RelinquishMagickMemory(draw_info->server_name);
844 if (draw_info->dash_pattern != (double *) NULL)
845 draw_info->dash_pattern=(double *) RelinquishMagickMemory(
846 draw_info->dash_pattern);
847 if (draw_info->gradient.stops != (StopInfo *) NULL)
848 draw_info->gradient.stops=(StopInfo *) RelinquishMagickMemory(
849 draw_info->gradient.stops);
850 if (draw_info->clip_mask != (char *) NULL)
851 draw_info->clip_mask=DestroyString(draw_info->clip_mask);
852 draw_info->signature=(~MagickSignature);
853 draw_info=(DrawInfo *) RelinquishMagickMemory(draw_info);
858 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
862 + D e s t r o y E d g e %
866 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
868 % DestroyEdge() destroys the specified polygon edge.
870 % The format of the DestroyEdge method is:
872 % long DestroyEdge(PolygonInfo *polygon_info,const int edge)
874 % A description of each parameter follows:
876 % o polygon_info: Specifies a pointer to an PolygonInfo structure.
878 % o edge: the polygon edge number to destroy.
881 static unsigned long DestroyEdge(PolygonInfo *polygon_info,
882 const unsigned long edge)
884 assert(edge < polygon_info->number_edges);
885 polygon_info->edges[edge].points=(PointInfo *) RelinquishMagickMemory(
886 polygon_info->edges[edge].points);
887 polygon_info->number_edges--;
888 if (edge < polygon_info->number_edges)
889 (void) CopyMagickMemory(polygon_info->edges+edge,polygon_info->edges+edge+1,
890 (size_t) (polygon_info->number_edges-edge)*sizeof(*polygon_info->edges));
891 return(polygon_info->number_edges);
895 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
899 + D e s t r o y P o l y g o n I n f o %
903 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
905 % DestroyPolygonInfo() destroys the PolygonInfo data structure.
907 % The format of the DestroyPolygonInfo method is:
909 % PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info)
911 % A description of each parameter follows:
913 % o polygon_info: Specifies a pointer to an PolygonInfo structure.
916 static PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info)
921 for (i=0; i < (long) polygon_info->number_edges; i++)
922 polygon_info->edges[i].points=(PointInfo *)
923 RelinquishMagickMemory(polygon_info->edges[i].points);
924 polygon_info->edges=(EdgeInfo *) RelinquishMagickMemory(polygon_info->edges);
925 return((PolygonInfo *) RelinquishMagickMemory(polygon_info));
929 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
933 % D r a w A f f i n e I m a g e %
937 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
939 % DrawAffineImage() composites the source over the destination image as
940 % dictated by the affine transform.
942 % The format of the DrawAffineImage method is:
944 % MagickBooleanType DrawAffineImage(Image *image,const Image *source,
945 % const AffineMatrix *affine)
947 % A description of each parameter follows:
949 % o image: the image.
951 % o source: the source image.
953 % o affine: the affine transform.
956 static SegmentInfo AffineEdge(const Image *image,const AffineMatrix *affine,
957 const double y,const SegmentInfo *edge)
970 Determine left and right edges.
972 inverse_edge.x1=edge->x1;
973 inverse_edge.y1=edge->y1;
974 inverse_edge.x2=edge->x2;
975 inverse_edge.y2=edge->y2;
976 z=affine->ry*y+affine->tx;
977 if (affine->sx > MagickEpsilon)
979 intercept=(-z/affine->sx);
980 x=intercept+MagickEpsilon;
981 if (x > inverse_edge.x1)
983 intercept=(-z+(double) image->columns)/affine->sx;
984 x=intercept-MagickEpsilon;
985 if (x < inverse_edge.x2)
989 if (affine->sx < -MagickEpsilon)
991 intercept=(-z+(double) image->columns)/affine->sx;
992 x=intercept+MagickEpsilon;
993 if (x > inverse_edge.x1)
995 intercept=(-z/affine->sx);
996 x=intercept-MagickEpsilon;
997 if (x < inverse_edge.x2)
1001 if ((z < 0.0) || ((unsigned long) floor(z+0.5) >= image->columns))
1003 inverse_edge.x2=edge->x1;
1004 return(inverse_edge);
1007 Determine top and bottom edges.
1009 z=affine->sy*y+affine->ty;
1010 if (affine->rx > MagickEpsilon)
1012 intercept=(-z/affine->rx);
1013 x=intercept+MagickEpsilon;
1014 if (x > inverse_edge.x1)
1016 intercept=(-z+(double) image->rows)/affine->rx;
1017 x=intercept-MagickEpsilon;
1018 if (x < inverse_edge.x2)
1022 if (affine->rx < -MagickEpsilon)
1024 intercept=(-z+(double) image->rows)/affine->rx;
1025 x=intercept+MagickEpsilon;
1026 if (x > inverse_edge.x1)
1028 intercept=(-z/affine->rx);
1029 x=intercept-MagickEpsilon;
1030 if (x < inverse_edge.x2)
1034 if ((z < 0.0) || ((unsigned long) floor(z+0.5) >= image->rows))
1036 inverse_edge.x2=edge->x2;
1037 return(inverse_edge);
1039 return(inverse_edge);
1042 static AffineMatrix InverseAffineMatrix(const AffineMatrix *affine)
1050 determinant=1.0/(affine->sx*affine->sy-affine->rx*affine->ry);
1051 inverse_affine.sx=determinant*affine->sy;
1052 inverse_affine.rx=determinant*(-affine->rx);
1053 inverse_affine.ry=determinant*(-affine->ry);
1054 inverse_affine.sy=determinant*affine->sx;
1055 inverse_affine.tx=(-affine->tx)*inverse_affine.sx-affine->ty*
1057 inverse_affine.ty=(-affine->tx)*inverse_affine.rx-affine->ty*
1059 return(inverse_affine);
1062 static inline long MagickAbsoluteValue(const long x)
1069 static inline double MagickMax(const double x,const double y)
1076 static inline double MagickMin(const double x,const double y)
1083 MagickExport MagickBooleanType DrawAffineImage(Image *image,
1084 const Image *source,const AffineMatrix *affine)
1115 **restrict resample_filter;
1121 Determine bounding box.
1123 assert(image != (Image *) NULL);
1124 assert(image->signature == MagickSignature);
1125 if (image->debug != MagickFalse)
1126 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1127 assert(source != (const Image *) NULL);
1128 assert(source->signature == MagickSignature);
1129 assert(affine != (AffineMatrix *) NULL);
1132 extent[1].x=(double) source->columns-1.0;
1134 extent[2].x=(double) source->columns-1.0;
1135 extent[2].y=(double) source->rows-1.0;
1137 extent[3].y=(double) source->rows-1.0;
1138 for (i=0; i < 4; i++)
1141 extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx;
1142 extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty;
1146 for (i=1; i < 4; i++)
1148 if (min.x > extent[i].x)
1150 if (min.y > extent[i].y)
1152 if (max.x < extent[i].x)
1154 if (max.y < extent[i].y)
1158 Affine transform image.
1160 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
1161 return(MagickFalse);
1163 edge.x1=MagickMax(min.x,0.0);
1164 edge.y1=MagickMax(min.y,0.0);
1165 edge.x2=MagickMin(max.x,(double) image->columns-1.0);
1166 edge.y2=MagickMin(max.y,(double) image->rows-1.0);
1167 inverse_affine=InverseAffineMatrix(affine);
1168 GetMagickPixelPacket(image,&zero);
1169 exception=(&image->exception);
1170 resample_filter=AcquireResampleFilterThreadSet(source,
1171 UndefinedVirtualPixelMethod,MagickTrue,exception);
1172 image_view=AcquireCacheView(image);
1173 source_view=AcquireCacheView(source);
1174 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1175 #pragma omp parallel for schedule(dynamic,4) shared(status)
1177 for (y=(long) ceil(edge.y1-0.5); y <= (long) floor(edge.y2+0.5); y++)
1189 register IndexPacket
1196 register PixelPacket
1202 inverse_edge=AffineEdge(source,&inverse_affine,(double) y,&edge);
1203 if (inverse_edge.x2 < inverse_edge.x1)
1205 q=GetCacheViewAuthenticPixels(image_view,(long) ceil(inverse_edge.x1-0.5),y,
1206 (unsigned long) ((long) floor(inverse_edge.x2+0.5)-(long) floor(
1207 inverse_edge.x1+0.5)+1),1,exception);
1208 if (q == (PixelPacket *) NULL)
1210 id=GetOpenMPThreadId();
1211 indexes=GetCacheViewAuthenticIndexQueue(image_view);
1215 for (x=(long) ceil(inverse_edge.x1-0.5); x <= (long) floor(inverse_edge.x2+0.5); x++)
1217 point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+
1219 point.y=(double) x*inverse_affine.rx+y*inverse_affine.sy+
1221 (void) ResamplePixelColor(resample_filter[id],point.x,point.y,&pixel);
1222 SetMagickPixelPacket(image,q,indexes+x_offset,&composite);
1223 MagickPixelCompositeOver(&pixel,pixel.opacity,&composite,
1224 composite.opacity,&composite);
1225 SetPixelPacket(image,&composite,q,indexes+x_offset);
1229 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1232 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
1233 source_view=DestroyCacheView(source_view);
1234 image_view=DestroyCacheView(image_view);
1239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1243 + D r a w B o u n d i n g R e c t a n g l e s %
1247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1249 % DrawBoundingRectangles() draws the bounding rectangles on the image. This
1250 % is only useful for developers debugging the rendering algorithm.
1252 % The format of the DrawBoundingRectangles method is:
1254 % void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info,
1255 % PolygonInfo *polygon_info)
1257 % A description of each parameter follows:
1259 % o image: the image.
1261 % o draw_info: the draw info.
1263 % o polygon_info: Specifies a pointer to a PolygonInfo structure.
1266 static void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info,
1267 const PolygonInfo *polygon_info)
1292 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1293 (void) QueryColorDatabase("#0000",&clone_info->fill,&image->exception);
1294 resolution.x=DefaultResolution;
1295 resolution.y=DefaultResolution;
1296 if (clone_info->density != (char *) NULL)
1304 flags=ParseGeometry(clone_info->density,&geometry_info);
1305 resolution.x=geometry_info.rho;
1306 resolution.y=geometry_info.sigma;
1307 if ((flags & SigmaValue) == MagickFalse)
1308 resolution.y=resolution.x;
1310 mid=(resolution.x/72.0)*ExpandAffine(&clone_info->affine)*
1311 clone_info->stroke_width/2.0;
1316 if (polygon_info != (PolygonInfo *) NULL)
1318 bounds=polygon_info->edges[0].bounds;
1319 for (i=1; i < (long) polygon_info->number_edges; i++)
1321 if (polygon_info->edges[i].bounds.x1 < (double) bounds.x1)
1322 bounds.x1=polygon_info->edges[i].bounds.x1;
1323 if (polygon_info->edges[i].bounds.y1 < (double) bounds.y1)
1324 bounds.y1=polygon_info->edges[i].bounds.y1;
1325 if (polygon_info->edges[i].bounds.x2 > (double) bounds.x2)
1326 bounds.x2=polygon_info->edges[i].bounds.x2;
1327 if (polygon_info->edges[i].bounds.y2 > (double) bounds.y2)
1328 bounds.y2=polygon_info->edges[i].bounds.y2;
1331 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double)
1332 image->columns ? (double) image->columns-1 : bounds.x1;
1334 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double)
1335 image->rows ? (double) image->rows-1 : bounds.y1;
1337 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double)
1338 image->columns ? (double) image->columns-1 : bounds.x2;
1340 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double)
1341 image->rows ? (double) image->rows-1 : bounds.y2;
1342 for (i=0; i < (long) polygon_info->number_edges; i++)
1344 if (polygon_info->edges[i].direction != 0)
1345 (void) QueryColorDatabase("red",&clone_info->stroke,
1348 (void) QueryColorDatabase("green",&clone_info->stroke,
1350 start.x=(double) (polygon_info->edges[i].bounds.x1-mid);
1351 start.y=(double) (polygon_info->edges[i].bounds.y1-mid);
1352 end.x=(double) (polygon_info->edges[i].bounds.x2+mid);
1353 end.y=(double) (polygon_info->edges[i].bounds.y2+mid);
1354 primitive_info[0].primitive=RectanglePrimitive;
1355 TraceRectangle(primitive_info,start,end);
1356 primitive_info[0].method=ReplaceMethod;
1357 coordinates=(long) primitive_info[0].coordinates;
1358 primitive_info[coordinates].primitive=UndefinedPrimitive;
1359 (void) DrawPrimitive(image,clone_info,primitive_info);
1362 (void) QueryColorDatabase("blue",&clone_info->stroke,&image->exception);
1363 start.x=(double) (bounds.x1-mid);
1364 start.y=(double) (bounds.y1-mid);
1365 end.x=(double) (bounds.x2+mid);
1366 end.y=(double) (bounds.y2+mid);
1367 primitive_info[0].primitive=RectanglePrimitive;
1368 TraceRectangle(primitive_info,start,end);
1369 primitive_info[0].method=ReplaceMethod;
1370 coordinates=(long) primitive_info[0].coordinates;
1371 primitive_info[coordinates].primitive=UndefinedPrimitive;
1372 (void) DrawPrimitive(image,clone_info,primitive_info);
1373 clone_info=DestroyDrawInfo(clone_info);
1377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1381 % D r a w C l i p P a t h %
1385 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1387 % DrawClipPath() draws the clip path on the image mask.
1389 % The format of the DrawClipPath method is:
1391 % MagickBooleanType DrawClipPath(Image *image,const DrawInfo *draw_info,
1394 % A description of each parameter follows:
1396 % o image: the image.
1398 % o draw_info: the draw info.
1400 % o name: the name of the clip path.
1403 MagickExport MagickBooleanType DrawClipPath(Image *image,
1404 const DrawInfo *draw_info,const char *name)
1407 clip_mask[MaxTextExtent];
1418 assert(image != (Image *) NULL);
1419 assert(image->signature == MagickSignature);
1420 if (image->debug != MagickFalse)
1421 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1422 assert(draw_info != (const DrawInfo *) NULL);
1423 (void) FormatMagickString(clip_mask,MaxTextExtent,"%s",name);
1424 value=GetImageArtifact(image,clip_mask);
1425 if (value == (const char *) NULL)
1426 return(MagickFalse);
1427 if (image->clip_mask == (Image *) NULL)
1432 clip_mask=CloneImage(image,image->columns,image->rows,MagickTrue,
1434 if (clip_mask == (Image *) NULL)
1435 return(MagickFalse);
1436 (void) SetImageClipMask(image,clip_mask);
1437 clip_mask=DestroyImage(clip_mask);
1439 (void) QueryColorDatabase("#00000000",&image->clip_mask->background_color,
1441 image->clip_mask->background_color.opacity=(Quantum) TransparentOpacity;
1442 (void) SetImageBackgroundColor(image->clip_mask);
1443 if (image->debug != MagickFalse)
1444 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"\nbegin clip-path %s",
1445 draw_info->clip_mask);
1446 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1447 (void) CloneString(&clone_info->primitive,value);
1448 (void) QueryColorDatabase("#ffffff",&clone_info->fill,&image->exception);
1449 clone_info->clip_mask=(char *) NULL;
1450 status=DrawImage(image->clip_mask,clone_info);
1451 status|=NegateImage(image->clip_mask,MagickFalse);
1452 clone_info=DestroyDrawInfo(clone_info);
1453 if (image->debug != MagickFalse)
1454 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end clip-path");
1455 return(status != 0 ? MagickTrue : MagickFalse);
1459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1463 + D r a w D a s h P o l y g o n %
1467 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1469 % DrawDashPolygon() draws a dashed polygon (line, rectangle, ellipse) on the
1470 % image while respecting the dash offset and dash pattern attributes.
1472 % The format of the DrawDashPolygon method is:
1474 % MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info,
1475 % const PrimitiveInfo *primitive_info,Image *image)
1477 % A description of each parameter follows:
1479 % o draw_info: the draw info.
1481 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
1483 % o image: the image.
1487 static MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info,
1488 const PrimitiveInfo *primitive_info,Image *image)
1513 register MagickRealType
1520 assert(draw_info != (const DrawInfo *) NULL);
1521 if (image->debug != MagickFalse)
1522 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-dash");
1523 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1524 clone_info->miterlimit=0;
1525 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
1526 number_vertices=(unsigned long) i;
1527 dash_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
1528 (2UL*number_vertices+1UL),sizeof(*dash_polygon));
1529 if (dash_polygon == (PrimitiveInfo *) NULL)
1530 return(MagickFalse);
1531 dash_polygon[0]=primitive_info[0];
1532 scale=ExpandAffine(&draw_info->affine);
1533 length=scale*(draw_info->dash_pattern[0]-0.5);
1534 offset=draw_info->dash_offset != 0.0 ? scale*draw_info->dash_offset : 0.0;
1536 for (n=0; offset > 0.0; j=0)
1538 if (draw_info->dash_pattern[n] <= 0.0)
1540 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1541 if (offset > length)
1545 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1548 if (offset < length)
1560 for (i=1; i < (long) number_vertices; i++)
1562 dx=primitive_info[i].point.x-primitive_info[i-1].point.x;
1563 dy=primitive_info[i].point.y-primitive_info[i-1].point.y;
1564 maximum_length=hypot((double) dx,dy);
1568 if (draw_info->dash_pattern[n] == 0.0)
1570 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1572 for (total_length=0.0; (total_length+length) < maximum_length; )
1574 total_length+=length;
1575 if ((n & 0x01) != 0)
1577 dash_polygon[0]=primitive_info[0];
1578 dash_polygon[0].point.x=(double) (primitive_info[i-1].point.x+dx*
1579 total_length/maximum_length);
1580 dash_polygon[0].point.y=(double) (primitive_info[i-1].point.y+dy*
1581 total_length/maximum_length);
1586 if ((j+1) > (long) (2*number_vertices))
1588 dash_polygon[j]=primitive_info[i-1];
1589 dash_polygon[j].point.x=(double) (primitive_info[i-1].point.x+dx*
1590 total_length/maximum_length);
1591 dash_polygon[j].point.y=(double) (primitive_info[i-1].point.y+dy*
1592 total_length/maximum_length);
1593 dash_polygon[j].coordinates=1;
1595 dash_polygon[0].coordinates=(unsigned long) j;
1596 dash_polygon[j].primitive=UndefinedPrimitive;
1597 status|=DrawStrokePolygon(image,clone_info,dash_polygon);
1600 if (draw_info->dash_pattern[n] == 0.0)
1602 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1604 length-=(maximum_length-total_length);
1605 if ((n & 0x01) != 0)
1607 dash_polygon[j]=primitive_info[i];
1608 dash_polygon[j].coordinates=1;
1611 if ((total_length < maximum_length) && ((n & 0x01) == 0) && (j > 1))
1613 dash_polygon[j]=primitive_info[i-1];
1614 dash_polygon[j].point.x+=MagickEpsilon;
1615 dash_polygon[j].point.y+=MagickEpsilon;
1616 dash_polygon[j].coordinates=1;
1618 dash_polygon[0].coordinates=(unsigned long) j;
1619 dash_polygon[j].primitive=UndefinedPrimitive;
1620 status|=DrawStrokePolygon(image,clone_info,dash_polygon);
1622 dash_polygon=(PrimitiveInfo *) RelinquishMagickMemory(dash_polygon);
1623 clone_info=DestroyDrawInfo(clone_info);
1624 if (image->debug != MagickFalse)
1625 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-dash");
1626 return(status != 0 ? MagickTrue : MagickFalse);
1630 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1634 % D r a w I m a g e %
1638 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1640 % DrawImage() draws a graphic primitive on your image. The primitive
1641 % may be represented as a string or filename. Precede the filename with an
1642 % "at" sign (@) and the contents of the file are drawn on the image. You
1643 % can affect how text is drawn by setting one or more members of the draw
1646 % The format of the DrawImage method is:
1648 % MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info)
1650 % A description of each parameter follows:
1652 % o image: the image.
1654 % o draw_info: the draw info.
1658 static inline MagickBooleanType IsPoint(const char *point)
1666 value=strtod(point,&p);
1667 return((value == 0.0) && (p == point) ? MagickFalse : MagickTrue);
1670 static inline void TracePoint(PrimitiveInfo *primitive_info,
1671 const PointInfo point)
1673 primitive_info->coordinates=1;
1674 primitive_info->point=point;
1677 MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info)
1679 #define RenderImageTag "Render/Image"
1686 key[2*MaxTextExtent],
1687 keyword[MaxTextExtent],
1688 geometry[MaxTextExtent],
1689 name[MaxTextExtent],
1690 pattern[MaxTextExtent],
1743 Ensure the annotation info is valid.
1745 assert(image != (Image *) NULL);
1746 assert(image->signature == MagickSignature);
1747 if (image->debug != MagickFalse)
1748 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1749 assert(draw_info != (DrawInfo *) NULL);
1750 assert(draw_info->signature == MagickSignature);
1751 if (image->debug != MagickFalse)
1752 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1753 if ((draw_info->primitive == (char *) NULL) ||
1754 (*draw_info->primitive == '\0'))
1755 return(MagickFalse);
1756 if (image->debug != MagickFalse)
1757 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"begin draw-image");
1758 if (*draw_info->primitive != '@')
1759 primitive=AcquireString(draw_info->primitive);
1761 primitive=FileToString(draw_info->primitive+1,~0,&image->exception);
1762 if (primitive == (char *) NULL)
1763 return(MagickFalse);
1764 primitive_extent=(MagickRealType) strlen(primitive);
1765 (void) SetImageArtifact(image,"MVG",primitive);
1768 Allocate primitive info memory.
1770 graphic_context=(DrawInfo **) AcquireAlignedMemory(1,
1771 sizeof(*graphic_context));
1772 if (graphic_context == (DrawInfo **) NULL)
1774 primitive=DestroyString(primitive);
1775 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1779 primitive_info=(PrimitiveInfo *) AcquireQuantumMemory((size_t) number_points,
1780 sizeof(*primitive_info));
1781 if (primitive_info == (PrimitiveInfo *) NULL)
1783 primitive=DestroyString(primitive);
1784 for ( ; n >= 0; n--)
1785 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
1786 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
1787 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1790 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1791 graphic_context[n]->viewbox=image->page;
1792 if ((image->page.width == 0) || (image->page.height == 0))
1794 graphic_context[n]->viewbox.width=image->columns;
1795 graphic_context[n]->viewbox.height=image->rows;
1797 token=AcquireString(primitive);
1798 (void) QueryColorDatabase("#000000",&start_color,&image->exception);
1799 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
1800 return(MagickFalse);
1802 for (q=primitive; *q != '\0'; )
1805 Interpret graphic primitive.
1807 GetMagickToken(q,&q,keyword);
1808 if (*keyword == '\0')
1810 if (*keyword == '#')
1815 while ((*q != '\n') && (*q != '\0'))
1819 p=q-strlen(keyword)-1;
1820 primitive_type=UndefinedPrimitive;
1821 current=graphic_context[n]->affine;
1822 GetAffineMatrix(&affine);
1830 if (LocaleCompare("affine",keyword) == 0)
1832 GetMagickToken(q,&q,token);
1833 affine.sx=StringToDouble(token);
1834 GetMagickToken(q,&q,token);
1836 GetMagickToken(q,&q,token);
1837 affine.rx=StringToDouble(token);
1838 GetMagickToken(q,&q,token);
1840 GetMagickToken(q,&q,token);
1841 affine.ry=StringToDouble(token);
1842 GetMagickToken(q,&q,token);
1844 GetMagickToken(q,&q,token);
1845 affine.sy=StringToDouble(token);
1846 GetMagickToken(q,&q,token);
1848 GetMagickToken(q,&q,token);
1849 affine.tx=StringToDouble(token);
1850 GetMagickToken(q,&q,token);
1852 GetMagickToken(q,&q,token);
1853 affine.ty=StringToDouble(token);
1856 if (LocaleCompare("arc",keyword) == 0)
1858 primitive_type=ArcPrimitive;
1867 if (LocaleCompare("bezier",keyword) == 0)
1869 primitive_type=BezierPrimitive;
1872 if (LocaleCompare("border-color",keyword) == 0)
1874 GetMagickToken(q,&q,token);
1875 (void) QueryColorDatabase(token,&graphic_context[n]->border_color,
1885 if (LocaleCompare("clip-path",keyword) == 0)
1890 GetMagickToken(q,&q,token);
1891 (void) CloneString(&graphic_context[n]->clip_mask,token);
1892 (void) DrawClipPath(image,graphic_context[n],
1893 graphic_context[n]->clip_mask);
1896 if (LocaleCompare("clip-rule",keyword) == 0)
1901 GetMagickToken(q,&q,token);
1902 fill_rule=ParseMagickOption(MagickFillRuleOptions,MagickFalse,
1904 if (fill_rule == -1)
1909 graphic_context[n]->fill_rule=(FillRule) fill_rule;
1912 if (LocaleCompare("clip-units",keyword) == 0)
1917 GetMagickToken(q,&q,token);
1918 clip_units=ParseMagickOption(MagickClipPathOptions,MagickFalse,
1920 if (clip_units == -1)
1925 graphic_context[n]->clip_units=(ClipPathUnits) clip_units;
1926 if (clip_units == ObjectBoundingBox)
1928 GetAffineMatrix(¤t);
1929 affine.sx=draw_info->bounds.x2;
1930 affine.sy=draw_info->bounds.y2;
1931 affine.tx=draw_info->bounds.x1;
1932 affine.ty=draw_info->bounds.y1;
1937 if (LocaleCompare("circle",keyword) == 0)
1939 primitive_type=CirclePrimitive;
1942 if (LocaleCompare("color",keyword) == 0)
1944 primitive_type=ColorPrimitive;
1953 if (LocaleCompare("decorate",keyword) == 0)
1958 GetMagickToken(q,&q,token);
1959 decorate=ParseMagickOption(MagickDecorateOptions,MagickFalse,
1966 graphic_context[n]->decorate=(DecorationType) decorate;
1975 if (LocaleCompare("ellipse",keyword) == 0)
1977 primitive_type=EllipsePrimitive;
1980 if (LocaleCompare("encoding",keyword) == 0)
1982 GetMagickToken(q,&q,token);
1983 (void) CloneString(&graphic_context[n]->encoding,token);
1992 if (LocaleCompare("fill",keyword) == 0)
1994 GetMagickToken(q,&q,token);
1995 (void) FormatMagickString(pattern,MaxTextExtent,"%s",token);
1996 if (GetImageArtifact(image,pattern) != (const char *) NULL)
1997 (void) DrawPatternPath(image,draw_info,token,
1998 &graphic_context[n]->fill_pattern);
2001 status=QueryColorDatabase(token,&graphic_context[n]->fill,
2003 if (status == MagickFalse)
2008 pattern_info=AcquireImageInfo();
2009 (void) CopyMagickString(pattern_info->filename,token,
2011 graphic_context[n]->fill_pattern=
2012 ReadImage(pattern_info,&image->exception);
2013 CatchException(&image->exception);
2014 pattern_info=DestroyImageInfo(pattern_info);
2019 if (LocaleCompare("fill-opacity",keyword) == 0)
2021 GetMagickToken(q,&q,token);
2022 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2023 graphic_context[n]->fill.opacity=ClampToQuantum((MagickRealType)
2024 QuantumRange*(1.0-factor*StringToDouble(token)));
2027 if (LocaleCompare("fill-rule",keyword) == 0)
2032 GetMagickToken(q,&q,token);
2033 fill_rule=ParseMagickOption(MagickFillRuleOptions,MagickFalse,
2035 if (fill_rule == -1)
2040 graphic_context[n]->fill_rule=(FillRule) fill_rule;
2043 if (LocaleCompare("font",keyword) == 0)
2045 GetMagickToken(q,&q,token);
2046 (void) CloneString(&graphic_context[n]->font,token);
2047 if (LocaleCompare("none",token) == 0)
2048 graphic_context[n]->font=(char *)
2049 RelinquishMagickMemory(graphic_context[n]->font);
2052 if (LocaleCompare("font-family",keyword) == 0)
2054 GetMagickToken(q,&q,token);
2055 (void) CloneString(&graphic_context[n]->family,token);
2058 if (LocaleCompare("font-size",keyword) == 0)
2060 GetMagickToken(q,&q,token);
2061 graphic_context[n]->pointsize=StringToDouble(token);
2064 if (LocaleCompare("font-stretch",keyword) == 0)
2069 GetMagickToken(q,&q,token);
2070 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,token);
2076 graphic_context[n]->stretch=(StretchType) stretch;
2079 if (LocaleCompare("font-style",keyword) == 0)
2084 GetMagickToken(q,&q,token);
2085 style=ParseMagickOption(MagickStyleOptions,MagickFalse,token);
2091 graphic_context[n]->style=(StyleType) style;
2094 if (LocaleCompare("font-weight",keyword) == 0)
2096 GetMagickToken(q,&q,token);
2097 graphic_context[n]->weight=StringToUnsignedLong(token);
2098 if (LocaleCompare(token,"all") == 0)
2099 graphic_context[n]->weight=0;
2100 if (LocaleCompare(token,"bold") == 0)
2101 graphic_context[n]->weight=700;
2102 if (LocaleCompare(token,"bolder") == 0)
2103 if (graphic_context[n]->weight <= 800)
2104 graphic_context[n]->weight+=100;
2105 if (LocaleCompare(token,"lighter") == 0)
2106 if (graphic_context[n]->weight >= 100)
2107 graphic_context[n]->weight-=100;
2108 if (LocaleCompare(token,"normal") == 0)
2109 graphic_context[n]->weight=400;
2118 if (LocaleCompare("gradient-units",keyword) == 0)
2120 GetMagickToken(q,&q,token);
2123 if (LocaleCompare("gravity",keyword) == 0)
2128 GetMagickToken(q,&q,token);
2129 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,token);
2135 graphic_context[n]->gravity=(GravityType) gravity;
2144 if (LocaleCompare("image",keyword) == 0)
2149 primitive_type=ImagePrimitive;
2150 GetMagickToken(q,&q,token);
2151 compose=ParseMagickOption(MagickComposeOptions,MagickFalse,token);
2157 graphic_context[n]->compose=(CompositeOperator) compose;
2160 if (LocaleCompare("interline-spacing",keyword) == 0)
2162 GetMagickToken(q,&q,token);
2163 graphic_context[n]->interline_spacing=StringToDouble(token);
2166 if (LocaleCompare("interword-spacing",keyword) == 0)
2168 GetMagickToken(q,&q,token);
2169 graphic_context[n]->interword_spacing=StringToDouble(token);
2178 if (LocaleCompare("kerning",keyword) == 0)
2180 GetMagickToken(q,&q,token);
2181 graphic_context[n]->kerning=StringToDouble(token);
2190 if (LocaleCompare("line",keyword) == 0)
2192 primitive_type=LinePrimitive;
2201 if (LocaleCompare("matte",keyword) == 0)
2203 primitive_type=MattePrimitive;
2212 if (LocaleCompare("offset",keyword) == 0)
2214 GetMagickToken(q,&q,token);
2217 if (LocaleCompare("opacity",keyword) == 0)
2219 GetMagickToken(q,&q,token);
2220 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2221 graphic_context[n]->opacity=ClampToQuantum((MagickRealType)
2222 QuantumRange*(1.0-((1.0-QuantumScale*graphic_context[n]->opacity)*
2223 factor*StringToDouble(token))));
2224 graphic_context[n]->fill.opacity=graphic_context[n]->opacity;
2225 graphic_context[n]->stroke.opacity=graphic_context[n]->opacity;
2234 if (LocaleCompare("path",keyword) == 0)
2236 primitive_type=PathPrimitive;
2239 if (LocaleCompare("point",keyword) == 0)
2241 primitive_type=PointPrimitive;
2244 if (LocaleCompare("polyline",keyword) == 0)
2246 primitive_type=PolylinePrimitive;
2249 if (LocaleCompare("polygon",keyword) == 0)
2251 primitive_type=PolygonPrimitive;
2254 if (LocaleCompare("pop",keyword) == 0)
2256 GetMagickToken(q,&q,token);
2257 if (LocaleCompare("clip-path",token) == 0)
2259 if (LocaleCompare("defs",token) == 0)
2261 if (LocaleCompare("gradient",token) == 0)
2263 if (LocaleCompare("graphic-context",token) == 0)
2267 (void) ThrowMagickException(&image->exception,
2268 GetMagickModule(),DrawError,
2269 "UnbalancedGraphicContextPushPop","`%s'",token);
2273 if (graphic_context[n]->clip_mask != (char *) NULL)
2274 if (LocaleCompare(graphic_context[n]->clip_mask,
2275 graphic_context[n-1]->clip_mask) != 0)
2276 (void) SetImageClipMask(image,(Image *) NULL);
2277 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
2281 if (LocaleCompare("pattern",token) == 0)
2286 if (LocaleCompare("push",keyword) == 0)
2288 GetMagickToken(q,&q,token);
2289 if (LocaleCompare("clip-path",token) == 0)
2292 name[MaxTextExtent];
2294 GetMagickToken(q,&q,token);
2295 (void) FormatMagickString(name,MaxTextExtent,"%s",token);
2296 for (p=q; *q != '\0'; )
2298 GetMagickToken(q,&q,token);
2299 if (LocaleCompare(token,"pop") != 0)
2301 GetMagickToken(q,(const char **) NULL,token);
2302 if (LocaleCompare(token,"clip-path") != 0)
2306 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2307 (void) SetImageArtifact(image,name,token);
2308 GetMagickToken(q,&q,token);
2311 if (LocaleCompare("gradient",token) == 0)
2314 key[2*MaxTextExtent],
2315 name[MaxTextExtent],
2316 type[MaxTextExtent];
2324 GetMagickToken(q,&q,token);
2325 (void) CopyMagickString(name,token,MaxTextExtent);
2326 GetMagickToken(q,&q,token);
2327 (void) CopyMagickString(type,token,MaxTextExtent);
2328 GetMagickToken(q,&q,token);
2329 segment.x1=StringToDouble(token);
2330 element.cx=StringToDouble(token);
2331 GetMagickToken(q,&q,token);
2333 GetMagickToken(q,&q,token);
2334 segment.y1=StringToDouble(token);
2335 element.cy=StringToDouble(token);
2336 GetMagickToken(q,&q,token);
2338 GetMagickToken(q,&q,token);
2339 segment.x2=StringToDouble(token);
2340 element.major=StringToDouble(token);
2341 GetMagickToken(q,&q,token);
2343 GetMagickToken(q,&q,token);
2344 segment.y2=StringToDouble(token);
2345 element.minor=StringToDouble(token);
2346 if (LocaleCompare(type,"radial") == 0)
2348 GetMagickToken(q,&q,token);
2350 GetMagickToken(q,&q,token);
2351 element.angle=StringToDouble(token);
2353 for (p=q; *q != '\0'; )
2355 GetMagickToken(q,&q,token);
2356 if (LocaleCompare(token,"pop") != 0)
2358 GetMagickToken(q,(const char **) NULL,token);
2359 if (LocaleCompare(token,"gradient") != 0)
2363 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2364 bounds.x1=graphic_context[n]->affine.sx*segment.x1+
2365 graphic_context[n]->affine.ry*segment.y1+
2366 graphic_context[n]->affine.tx;
2367 bounds.y1=graphic_context[n]->affine.rx*segment.x1+
2368 graphic_context[n]->affine.sy*segment.y1+
2369 graphic_context[n]->affine.ty;
2370 bounds.x2=graphic_context[n]->affine.sx*segment.x2+
2371 graphic_context[n]->affine.ry*segment.y2+
2372 graphic_context[n]->affine.tx;
2373 bounds.y2=graphic_context[n]->affine.rx*segment.x2+
2374 graphic_context[n]->affine.sy*segment.y2+
2375 graphic_context[n]->affine.ty;
2376 (void) FormatMagickString(key,MaxTextExtent,"%s",name);
2377 (void) SetImageArtifact(image,key,token);
2378 (void) FormatMagickString(key,MaxTextExtent,"%s-geometry",name);
2379 (void) FormatMagickString(geometry,MaxTextExtent,
2380 "%gx%g%+.15g%+.15g",
2381 MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0),
2382 MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0),
2383 bounds.x1,bounds.y1);
2384 (void) SetImageArtifact(image,key,geometry);
2385 GetMagickToken(q,&q,token);
2388 if (LocaleCompare("pattern",token) == 0)
2393 GetMagickToken(q,&q,token);
2394 (void) CopyMagickString(name,token,MaxTextExtent);
2395 GetMagickToken(q,&q,token);
2396 bounds.x=(long) ceil(StringToDouble(token)-0.5);
2397 GetMagickToken(q,&q,token);
2399 GetMagickToken(q,&q,token);
2400 bounds.y=(long) ceil(StringToDouble(token)-0.5);
2401 GetMagickToken(q,&q,token);
2403 GetMagickToken(q,&q,token);
2404 bounds.width=(unsigned long) floor(StringToDouble(token)+0.5);
2405 GetMagickToken(q,&q,token);
2407 GetMagickToken(q,&q,token);
2408 bounds.height=(unsigned long) floor(StringToDouble(token)+0.5);
2409 for (p=q; *q != '\0'; )
2411 GetMagickToken(q,&q,token);
2412 if (LocaleCompare(token,"pop") != 0)
2414 GetMagickToken(q,(const char **) NULL,token);
2415 if (LocaleCompare(token,"pattern") != 0)
2419 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2420 (void) FormatMagickString(key,MaxTextExtent,"%s",name);
2421 (void) SetImageArtifact(image,key,token);
2422 (void) FormatMagickString(key,MaxTextExtent,"%s-geometry",name);
2423 (void) FormatMagickString(geometry,MaxTextExtent,
2424 "%lux%lu%+ld%+ld",bounds.width,bounds.height,bounds.x,
2426 (void) SetImageArtifact(image,key,geometry);
2427 GetMagickToken(q,&q,token);
2430 if (LocaleCompare("graphic-context",token) == 0)
2433 graphic_context=(DrawInfo **) ResizeQuantumMemory(
2434 graphic_context,(size_t) (n+1),sizeof(*graphic_context));
2435 if (graphic_context == (DrawInfo **) NULL)
2437 (void) ThrowMagickException(&image->exception,
2438 GetMagickModule(),ResourceLimitError,
2439 "MemoryAllocationFailed","`%s'",image->filename);
2442 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,
2443 graphic_context[n-1]);
2446 if (LocaleCompare("defs",token) == 0)
2457 if (LocaleCompare("rectangle",keyword) == 0)
2459 primitive_type=RectanglePrimitive;
2462 if (LocaleCompare("rotate",keyword) == 0)
2464 GetMagickToken(q,&q,token);
2465 angle=StringToDouble(token);
2466 affine.sx=cos(DegreesToRadians(fmod((double) angle,360.0)));
2467 affine.rx=sin(DegreesToRadians(fmod((double) angle,360.0)));
2468 affine.ry=(-sin(DegreesToRadians(fmod((double) angle,360.0))));
2469 affine.sy=cos(DegreesToRadians(fmod((double) angle,360.0)));
2472 if (LocaleCompare("roundRectangle",keyword) == 0)
2474 primitive_type=RoundRectanglePrimitive;
2483 if (LocaleCompare("scale",keyword) == 0)
2485 GetMagickToken(q,&q,token);
2486 affine.sx=StringToDouble(token);
2487 GetMagickToken(q,&q,token);
2489 GetMagickToken(q,&q,token);
2490 affine.sy=StringToDouble(token);
2493 if (LocaleCompare("skewX",keyword) == 0)
2495 GetMagickToken(q,&q,token);
2496 angle=StringToDouble(token);
2497 affine.ry=sin(DegreesToRadians(angle));
2500 if (LocaleCompare("skewY",keyword) == 0)
2502 GetMagickToken(q,&q,token);
2503 angle=StringToDouble(token);
2504 affine.rx=(-tan(DegreesToRadians(angle)/2.0));
2507 if (LocaleCompare("stop-color",keyword) == 0)
2512 GetMagickToken(q,&q,token);
2513 (void) QueryColorDatabase(token,&stop_color,&image->exception);
2514 (void) GradientImage(image,LinearGradient,ReflectSpread,
2515 &start_color,&stop_color);
2516 start_color=stop_color;
2517 GetMagickToken(q,&q,token);
2520 if (LocaleCompare("stroke",keyword) == 0)
2522 GetMagickToken(q,&q,token);
2523 (void) FormatMagickString(pattern,MaxTextExtent,"%s",token);
2524 if (GetImageArtifact(image,pattern) != (const char *) NULL)
2525 (void) DrawPatternPath(image,draw_info,token,
2526 &graphic_context[n]->stroke_pattern);
2529 status=QueryColorDatabase(token,&graphic_context[n]->stroke,
2531 if (status == MagickFalse)
2536 pattern_info=AcquireImageInfo();
2537 (void) CopyMagickString(pattern_info->filename,token,
2539 graphic_context[n]->stroke_pattern=
2540 ReadImage(pattern_info,&image->exception);
2541 CatchException(&image->exception);
2542 pattern_info=DestroyImageInfo(pattern_info);
2547 if (LocaleCompare("stroke-antialias",keyword) == 0)
2549 GetMagickToken(q,&q,token);
2550 graphic_context[n]->stroke_antialias=
2551 StringToLong(token) != 0 ? MagickTrue : MagickFalse;
2554 if (LocaleCompare("stroke-dasharray",keyword) == 0)
2556 if (graphic_context[n]->dash_pattern != (double *) NULL)
2557 graphic_context[n]->dash_pattern=(double *)
2558 RelinquishMagickMemory(graphic_context[n]->dash_pattern);
2559 if (IsPoint(q) != MagickFalse)
2565 GetMagickToken(p,&p,token);
2567 GetMagickToken(p,&p,token);
2568 for (x=0; IsPoint(token) != MagickFalse; x++)
2570 GetMagickToken(p,&p,token);
2572 GetMagickToken(p,&p,token);
2574 graphic_context[n]->dash_pattern=(double *)
2575 AcquireQuantumMemory((size_t) (2UL*x+1UL),
2576 sizeof(*graphic_context[n]->dash_pattern));
2577 if (graphic_context[n]->dash_pattern == (double *) NULL)
2579 (void) ThrowMagickException(&image->exception,
2580 GetMagickModule(),ResourceLimitError,
2581 "MemoryAllocationFailed","`%s'",image->filename);
2584 for (j=0; j < x; j++)
2586 GetMagickToken(q,&q,token);
2588 GetMagickToken(q,&q,token);
2589 graphic_context[n]->dash_pattern[j]=StringToDouble(token);
2591 if ((x & 0x01) != 0)
2592 for ( ; j < (2*x); j++)
2593 graphic_context[n]->dash_pattern[j]=
2594 graphic_context[n]->dash_pattern[j-x];
2595 graphic_context[n]->dash_pattern[j]=0.0;
2598 GetMagickToken(q,&q,token);
2601 if (LocaleCompare("stroke-dashoffset",keyword) == 0)
2603 GetMagickToken(q,&q,token);
2604 graphic_context[n]->dash_offset=StringToDouble(token);
2607 if (LocaleCompare("stroke-linecap",keyword) == 0)
2612 GetMagickToken(q,&q,token);
2613 linecap=ParseMagickOption(MagickLineCapOptions,MagickFalse,token);
2619 graphic_context[n]->linecap=(LineCap) linecap;
2622 if (LocaleCompare("stroke-linejoin",keyword) == 0)
2627 GetMagickToken(q,&q,token);
2628 linejoin=ParseMagickOption(MagickLineJoinOptions,MagickFalse,token);
2634 graphic_context[n]->linejoin=(LineJoin) linejoin;
2637 if (LocaleCompare("stroke-miterlimit",keyword) == 0)
2639 GetMagickToken(q,&q,token);
2640 graphic_context[n]->miterlimit=StringToUnsignedLong(token);
2643 if (LocaleCompare("stroke-opacity",keyword) == 0)
2645 GetMagickToken(q,&q,token);
2646 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2647 graphic_context[n]->stroke.opacity=ClampToQuantum((MagickRealType)
2648 QuantumRange*(1.0-factor*StringToDouble(token)));
2651 if (LocaleCompare("stroke-width",keyword) == 0)
2653 GetMagickToken(q,&q,token);
2654 graphic_context[n]->stroke_width=StringToDouble(token);
2663 if (LocaleCompare("text",keyword) == 0)
2665 primitive_type=TextPrimitive;
2668 if (LocaleCompare("text-align",keyword) == 0)
2673 GetMagickToken(q,&q,token);
2674 align=ParseMagickOption(MagickAlignOptions,MagickFalse,token);
2680 graphic_context[n]->align=(AlignType) align;
2683 if (LocaleCompare("text-anchor",keyword) == 0)
2688 GetMagickToken(q,&q,token);
2689 align=ParseMagickOption(MagickAlignOptions,MagickFalse,token);
2695 graphic_context[n]->align=(AlignType) align;
2698 if (LocaleCompare("text-antialias",keyword) == 0)
2700 GetMagickToken(q,&q,token);
2701 graphic_context[n]->text_antialias=
2702 StringToLong(token) != 0 ? MagickTrue : MagickFalse;
2705 if (LocaleCompare("text-undercolor",keyword) == 0)
2707 GetMagickToken(q,&q,token);
2708 (void) QueryColorDatabase(token,&graphic_context[n]->undercolor,
2712 if (LocaleCompare("translate",keyword) == 0)
2714 GetMagickToken(q,&q,token);
2715 affine.tx=StringToDouble(token);
2716 GetMagickToken(q,&q,token);
2718 GetMagickToken(q,&q,token);
2719 affine.ty=StringToDouble(token);
2728 if (LocaleCompare("viewbox",keyword) == 0)
2730 GetMagickToken(q,&q,token);
2731 graphic_context[n]->viewbox.x=(long) ceil(StringToDouble(token)-
2733 GetMagickToken(q,&q,token);
2735 GetMagickToken(q,&q,token);
2736 graphic_context[n]->viewbox.y=(long) ceil(StringToDouble(token)-
2738 GetMagickToken(q,&q,token);
2740 GetMagickToken(q,&q,token);
2741 graphic_context[n]->viewbox.width=(unsigned long) floor(
2742 StringToDouble(token)+0.5);
2743 GetMagickToken(q,&q,token);
2745 GetMagickToken(q,&q,token);
2746 graphic_context[n]->viewbox.height=(unsigned long) floor(
2747 StringToDouble(token)+0.5);
2759 if (status == MagickFalse)
2761 if ((affine.sx != 1.0) || (affine.rx != 0.0) || (affine.ry != 0.0) ||
2762 (affine.sy != 1.0) || (affine.tx != 0.0) || (affine.ty != 0.0))
2764 graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
2765 graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
2766 graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
2767 graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
2768 graphic_context[n]->affine.tx=
2769 current.sx*affine.tx+current.ry*affine.ty+current.tx;
2770 graphic_context[n]->affine.ty=
2771 current.rx*affine.tx+current.sy*affine.ty+current.ty;
2773 if (primitive_type == UndefinedPrimitive)
2775 if (image->debug != MagickFalse)
2776 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",
2781 Parse the primitive attributes.
2785 primitive_info[0].point.x=0.0;
2786 primitive_info[0].point.y=0.0;
2787 for (x=0; *q != '\0'; x++)
2792 if (IsPoint(q) == MagickFalse)
2794 GetMagickToken(q,&q,token);
2795 point.x=StringToDouble(token);
2796 GetMagickToken(q,&q,token);
2798 GetMagickToken(q,&q,token);
2799 point.y=StringToDouble(token);
2800 GetMagickToken(q,(const char **) NULL,token);
2802 GetMagickToken(q,&q,token);
2803 primitive_info[i].primitive=primitive_type;
2804 primitive_info[i].point=point;
2805 primitive_info[i].coordinates=0;
2806 primitive_info[i].method=FloodfillMethod;
2808 if (i < (long) number_points)
2811 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,
2812 (size_t) number_points,sizeof(*primitive_info));
2813 if (primitive_info == (PrimitiveInfo *) NULL)
2815 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2816 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
2820 primitive_info[j].primitive=primitive_type;
2821 primitive_info[j].coordinates=(unsigned long) x;
2822 primitive_info[j].method=FloodfillMethod;
2823 primitive_info[j].text=(char *) NULL;
2825 Circumscribe primitive within a circle.
2827 bounds.x1=primitive_info[j].point.x;
2828 bounds.y1=primitive_info[j].point.y;
2829 bounds.x2=primitive_info[j].point.x;
2830 bounds.y2=primitive_info[j].point.y;
2831 for (k=1; k < (long) primitive_info[j].coordinates; k++)
2833 point=primitive_info[j+k].point;
2834 if (point.x < bounds.x1)
2836 if (point.y < bounds.y1)
2838 if (point.x > bounds.x2)
2840 if (point.y > bounds.y2)
2844 Speculate how many points our primitive might consume.
2846 length=primitive_info[j].coordinates;
2847 switch (primitive_type)
2849 case RectanglePrimitive:
2854 case RoundRectanglePrimitive:
2856 length*=5+4*BezierQuantum;
2859 case BezierPrimitive:
2861 if (primitive_info[j].coordinates > 107)
2862 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2863 DrawError,"TooManyBezierCoordinates","`%s'",token);
2864 length=BezierQuantum*primitive_info[j].coordinates;
2873 GetMagickToken(q,&q,token);
2876 for (s=token; *s != '\0'; s=t)
2889 length=6*(3*length/2+BezierQuantum)+360+1;
2892 case CirclePrimitive:
2894 case EllipsePrimitive:
2901 alpha=bounds.x2-bounds.x1;
2902 beta=bounds.y2-bounds.y1;
2903 radius=hypot((double) alpha,(double) beta);
2904 length=2*((size_t) (MagickPI*radius))+6*BezierQuantum+360+1;
2910 if ((unsigned long) (i+length) >= number_points)
2913 Resize based on speculative points required by primitive.
2915 while ((unsigned long) (i+length) >= number_points)
2917 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,
2918 (size_t) number_points,sizeof(*primitive_info));
2919 if (primitive_info == (PrimitiveInfo *) NULL)
2921 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2922 ResourceLimitError,"MemoryAllocationFailed","`%s'",
2927 switch (primitive_type)
2929 case PointPrimitive:
2932 if (primitive_info[j].coordinates != 1)
2937 TracePoint(primitive_info+j,primitive_info[j].point);
2938 i=(long) (j+primitive_info[j].coordinates);
2943 if (primitive_info[j].coordinates != 2)
2948 TraceLine(primitive_info+j,primitive_info[j].point,
2949 primitive_info[j+1].point);
2950 i=(long) (j+primitive_info[j].coordinates);
2953 case RectanglePrimitive:
2955 if (primitive_info[j].coordinates != 2)
2960 TraceRectangle(primitive_info+j,primitive_info[j].point,
2961 primitive_info[j+1].point);
2962 i=(long) (j+primitive_info[j].coordinates);
2965 case RoundRectanglePrimitive:
2967 if (primitive_info[j].coordinates != 3)
2972 TraceRoundRectangle(primitive_info+j,primitive_info[j].point,
2973 primitive_info[j+1].point,primitive_info[j+2].point);
2974 i=(long) (j+primitive_info[j].coordinates);
2979 if (primitive_info[j].coordinates != 3)
2981 primitive_type=UndefinedPrimitive;
2984 TraceArc(primitive_info+j,primitive_info[j].point,
2985 primitive_info[j+1].point,primitive_info[j+2].point);
2986 i=(long) (j+primitive_info[j].coordinates);
2989 case EllipsePrimitive:
2991 if (primitive_info[j].coordinates != 3)
2996 TraceEllipse(primitive_info+j,primitive_info[j].point,
2997 primitive_info[j+1].point,primitive_info[j+2].point);
2998 i=(long) (j+primitive_info[j].coordinates);
3001 case CirclePrimitive:
3003 if (primitive_info[j].coordinates != 2)
3008 TraceCircle(primitive_info+j,primitive_info[j].point,
3009 primitive_info[j+1].point);
3010 i=(long) (j+primitive_info[j].coordinates);
3013 case PolylinePrimitive:
3015 case PolygonPrimitive:
3017 primitive_info[i]=primitive_info[j];
3018 primitive_info[i].coordinates=0;
3019 primitive_info[j].coordinates++;
3023 case BezierPrimitive:
3025 if (primitive_info[j].coordinates < 3)
3030 TraceBezier(primitive_info+j,primitive_info[j].coordinates);
3031 i=(long) (j+primitive_info[j].coordinates);
3036 i=(long) (j+TracePath(primitive_info+j,token));
3039 case ColorPrimitive:
3040 case MattePrimitive:
3045 if (primitive_info[j].coordinates != 1)
3050 GetMagickToken(q,&q,token);
3051 method=ParseMagickOption(MagickMethodOptions,MagickFalse,token);
3057 primitive_info[j].method=(PaintMethod) method;
3062 if (primitive_info[j].coordinates != 1)
3068 GetMagickToken(q,&q,token);
3069 primitive_info[j].text=AcquireString(token);
3072 case ImagePrimitive:
3074 if (primitive_info[j].coordinates != 2)
3079 GetMagickToken(q,&q,token);
3080 primitive_info[j].text=AcquireString(token);
3084 if (primitive_info == (PrimitiveInfo *) NULL)
3086 if (image->debug != MagickFalse)
3087 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",(int) (q-p),p);
3088 if (status == MagickFalse)
3090 primitive_info[i].primitive=UndefinedPrimitive;
3096 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
3098 point=primitive_info[i].point;
3099 primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+
3100 graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx;
3101 primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+
3102 graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty;
3103 point=primitive_info[i].point;
3104 if (point.x < graphic_context[n]->bounds.x1)
3105 graphic_context[n]->bounds.x1=point.x;
3106 if (point.y < graphic_context[n]->bounds.y1)
3107 graphic_context[n]->bounds.y1=point.y;
3108 if (point.x > graphic_context[n]->bounds.x2)
3109 graphic_context[n]->bounds.x2=point.x;
3110 if (point.y > graphic_context[n]->bounds.y2)
3111 graphic_context[n]->bounds.y2=point.y;
3112 if (primitive_info[i].primitive == ImagePrimitive)
3115 if (i >= (long) number_points)
3116 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
3117 if (graphic_context[n]->render != MagickFalse)
3119 if ((n != 0) && (graphic_context[n]->clip_mask != (char *) NULL) &&
3120 (LocaleCompare(graphic_context[n]->clip_mask,
3121 graphic_context[n-1]->clip_mask) != 0))
3122 (void) DrawClipPath(image,graphic_context[n],
3123 graphic_context[n]->clip_mask);
3124 (void) DrawPrimitive(image,graphic_context[n],primitive_info);
3126 if (primitive_info->text != (char *) NULL)
3127 primitive_info->text=(char *) RelinquishMagickMemory(
3128 primitive_info->text);
3129 proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType)
3131 if (proceed == MagickFalse)
3134 if (image->debug != MagickFalse)
3135 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end draw-image");
3137 Relinquish resources.
3139 token=DestroyString(token);
3140 if (primitive_info != (PrimitiveInfo *) NULL)
3141 primitive_info=(PrimitiveInfo *) RelinquishMagickMemory(primitive_info);
3142 primitive=DestroyString(primitive);
3143 for ( ; n >= 0; n--)
3144 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
3145 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
3146 if (status == MagickFalse)
3147 ThrowBinaryException(DrawError,"NonconformingDrawingPrimitiveDefinition",
3153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3157 % D r a w G r a d i e n t I m a g e %
3161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3163 % DrawGradientImage() draws a linear gradient on the image.
3165 % The format of the DrawGradientImage method is:
3167 % MagickBooleanType DrawGradientImage(Image *image,
3168 % const DrawInfo *draw_info)
3170 % A description of each parameter follows:
3172 % o image: the image.
3174 % o _info: the draw info.
3178 static inline MagickRealType GetStopColorOffset(const GradientInfo *gradient,
3179 const long x,const long y)
3181 switch (gradient->type)
3183 case UndefinedGradient:
3184 case LinearGradient:
3199 gradient_vector=(&gradient->gradient_vector);
3200 p.x=gradient_vector->x2-gradient_vector->x1;
3201 p.y=gradient_vector->y2-gradient_vector->y1;
3202 q.x=(double) x-gradient_vector->x1;
3203 q.y=(double) y-gradient_vector->y1;
3204 length=sqrt(q.x*q.x+q.y*q.y);
3205 gamma=sqrt(p.x*p.x+p.y*p.y)*length;
3206 gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
3207 scale=p.x*q.x+p.y*q.y;
3208 offset=gamma*scale*length;
3211 case RadialGradient:
3220 v.x=(double) x-gradient->center.x;
3221 v.y=(double) y-gradient->center.y;
3222 length=sqrt(v.x*v.x+v.y*v.y);
3223 if (gradient->spread == RepeatSpread)
3225 offset=length/gradient->radius;
3232 MagickExport MagickBooleanType DrawGradientImage(Image *image,
3233 const DrawInfo *draw_info)
3266 Draw linear or radial gradient on image.
3268 assert(image != (Image *) NULL);
3269 assert(image->signature == MagickSignature);
3270 if (image->debug != MagickFalse)
3271 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3272 assert(draw_info != (const DrawInfo *) NULL);
3273 gradient=(&draw_info->gradient);
3274 gradient_vector=(&gradient->gradient_vector);
3275 point.x=gradient_vector->x2-gradient_vector->x1;
3276 point.y=gradient_vector->y2-gradient_vector->y1;
3277 length=sqrt(point.x*point.x+point.y*point.y);
3278 bounding_box=gradient->bounding_box;
3280 exception=(&image->exception);
3281 GetMagickPixelPacket(image,&zero);
3282 image_view=AcquireCacheView(image);
3283 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3284 #pragma omp parallel for schedule(dynamic,4) shared(status)
3286 for (y=bounding_box.y; y < (long) bounding_box.height; y++)
3299 register IndexPacket
3306 register PixelPacket
3309 if (status == MagickFalse)
3311 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3312 if (q == (PixelPacket *) NULL)
3317 indexes=GetCacheViewAuthenticIndexQueue(image_view);
3320 offset=GetStopColorOffset(gradient,0,y);
3321 if (gradient->type != RadialGradient)
3323 for (x=bounding_box.x; x < (long) bounding_box.width; x++)
3325 SetMagickPixelPacket(image,q,indexes+x,&pixel);
3326 switch (gradient->spread)
3328 case UndefinedSpread:
3331 if ((x != (long) ceil(gradient_vector->x1-0.5)) ||
3332 (y != (long) ceil(gradient_vector->y1-0.5)))
3334 offset=GetStopColorOffset(gradient,x,y);
3335 if (gradient->type != RadialGradient)
3338 for (i=0; i < (long) gradient->number_stops; i++)
3339 if (offset < gradient->stops[i].offset)
3341 if ((offset < 0.0) || (i == 0))
3342 composite=gradient->stops[0].color;
3344 if ((offset > 1.0) || (i == (long) gradient->number_stops))
3345 composite=gradient->stops[gradient->number_stops-1].color;
3350 alpha=(offset-gradient->stops[i].offset)/
3351 (gradient->stops[j].offset-gradient->stops[i].offset);
3352 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3353 &gradient->stops[j].color,alpha,&composite);
3359 if ((x != (long) ceil(gradient_vector->x1-0.5)) ||
3360 (y != (long) ceil(gradient_vector->y1-0.5)))
3362 offset=GetStopColorOffset(gradient,x,y);
3363 if (gradient->type != RadialGradient)
3368 if ((long) fmod(offset,2.0) == 0)
3369 offset=fmod(offset,1.0);
3371 offset=1.0-fmod(offset,1.0);
3372 for (i=0; i < (long) gradient->number_stops; i++)
3373 if (offset < gradient->stops[i].offset)
3376 composite=gradient->stops[0].color;
3378 if (i == (long) gradient->number_stops)
3379 composite=gradient->stops[gradient->number_stops-1].color;
3384 alpha=(offset-gradient->stops[i].offset)/
3385 (gradient->stops[j].offset-gradient->stops[i].offset);
3386 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3387 &gradient->stops[j].color,alpha,&composite);
3399 antialias=MagickFalse;
3401 if ((x != (long) ceil(gradient_vector->x1-0.5)) ||
3402 (y != (long) ceil(gradient_vector->y1-0.5)))
3404 offset=GetStopColorOffset(gradient,x,y);
3405 if (gradient->type == LinearGradient)
3407 repeat=fmod(offset,length);
3409 repeat=length-fmod(-repeat,length);
3411 repeat=fmod(offset,length);
3412 antialias=(repeat < length) && ((repeat+1.0) > length) ?
3413 MagickTrue : MagickFalse;
3414 offset=repeat/length;
3418 repeat=fmod(offset,gradient->radius);
3420 repeat=gradient->radius-fmod(-repeat,gradient->radius);
3422 repeat=fmod(offset,gradient->radius);
3423 antialias=repeat+1.0 > gradient->radius ?
3424 MagickTrue : MagickFalse;
3425 offset=repeat/gradient->radius;
3428 for (i=0; i < (long) gradient->number_stops; i++)
3429 if (offset < gradient->stops[i].offset)
3432 composite=gradient->stops[0].color;
3434 if (i == (long) gradient->number_stops)
3435 composite=gradient->stops[gradient->number_stops-1].color;
3440 alpha=(offset-gradient->stops[i].offset)/
3441 (gradient->stops[j].offset-gradient->stops[i].offset);
3442 if (antialias != MagickFalse)
3444 if (gradient->type == LinearGradient)
3445 alpha=length-repeat;
3447 alpha=gradient->radius-repeat;
3449 j=(long) gradient->number_stops-1L;
3451 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3452 &gradient->stops[j].color,alpha,&composite);
3457 MagickPixelCompositeOver(&composite,composite.opacity,&pixel,
3458 pixel.opacity,&pixel);
3459 SetPixelPacket(image,&pixel,q,indexes+x);
3462 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3465 image_view=DestroyCacheView(image_view);
3470 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3474 % D r a w P a t t e r n P a t h %
3478 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3480 % DrawPatternPath() draws a pattern.
3482 % The format of the DrawPatternPath method is:
3484 % MagickBooleanType DrawPatternPath(Image *image,const DrawInfo *draw_info,
3485 % const char *name,Image **pattern)
3487 % A description of each parameter follows:
3489 % o image: the image.
3491 % o draw_info: the draw info.
3493 % o name: the pattern name.
3495 % o image: the image.
3498 MagickExport MagickBooleanType DrawPatternPath(Image *image,
3499 const DrawInfo *draw_info,const char *name,Image **pattern)
3502 property[MaxTextExtent];
3517 assert(image != (Image *) NULL);
3518 assert(image->signature == MagickSignature);
3519 if (image->debug != MagickFalse)
3520 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3521 assert(draw_info != (const DrawInfo *) NULL);
3522 assert(name != (const char *) NULL);
3523 (void) FormatMagickString(property,MaxTextExtent,"%s",name);
3524 path=GetImageArtifact(image,property);
3525 if (path == (const char *) NULL)
3526 return(MagickFalse);
3527 (void) FormatMagickString(property,MaxTextExtent,"%s-geometry",name);
3528 geometry=GetImageArtifact(image,property);
3529 if (geometry == (const char *) NULL)
3530 return(MagickFalse);
3531 if ((*pattern) != (Image *) NULL)
3532 *pattern=DestroyImage(*pattern);
3533 image_info=AcquireImageInfo();
3534 image_info->size=AcquireString(geometry);
3535 *pattern=AcquireImage(image_info);
3536 image_info=DestroyImageInfo(image_info);
3537 (void) QueryColorDatabase("#00000000",&(*pattern)->background_color,
3539 (void) SetImageBackgroundColor(*pattern);
3540 if (image->debug != MagickFalse)
3541 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
3542 "begin pattern-path %s %s",name,geometry);
3543 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
3544 clone_info->fill_pattern=NewImageList();
3545 clone_info->stroke_pattern=NewImageList();
3546 (void) CloneString(&clone_info->primitive,path);
3547 status=DrawImage(*pattern,clone_info);
3548 clone_info=DestroyDrawInfo(clone_info);
3549 if (image->debug != MagickFalse)
3550 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end pattern-path");
3555 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3559 + D r a w P o l y g o n P r i m i t i v e %
3563 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3565 % DrawPolygonPrimitive() draws a polygon on the image.
3567 % The format of the DrawPolygonPrimitive method is:
3569 % MagickBooleanType DrawPolygonPrimitive(Image *image,
3570 % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
3572 % A description of each parameter follows:
3574 % o image: the image.
3576 % o draw_info: the draw info.
3578 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
3582 static PolygonInfo **DestroyPolygonThreadSet(PolygonInfo **polygon_info)
3587 assert(polygon_info != (PolygonInfo **) NULL);
3588 for (i=0; i < (long) GetOpenMPMaximumThreads(); i++)
3589 if (polygon_info[i] != (PolygonInfo *) NULL)
3590 polygon_info[i]=DestroyPolygonInfo(polygon_info[i]);
3591 polygon_info=(PolygonInfo **) RelinquishAlignedMemory(polygon_info);
3592 return(polygon_info);
3595 static PolygonInfo **AcquirePolygonThreadSet(const DrawInfo *draw_info,
3596 const PrimitiveInfo *primitive_info)
3599 *restrict path_info;
3610 number_threads=GetOpenMPMaximumThreads();
3611 polygon_info=(PolygonInfo **) AcquireAlignedMemory(number_threads,
3612 sizeof(*polygon_info));
3613 if (polygon_info == (PolygonInfo **) NULL)
3614 return((PolygonInfo **) NULL);
3615 (void) ResetMagickMemory(polygon_info,0,GetOpenMPMaximumThreads()*
3616 sizeof(*polygon_info));
3617 path_info=ConvertPrimitiveToPath(draw_info,primitive_info);
3618 if (path_info == (PathInfo *) NULL)
3619 return(DestroyPolygonThreadSet(polygon_info));
3620 for (i=0; i < (long) number_threads; i++)
3622 polygon_info[i]=ConvertPathToPolygon(draw_info,path_info);
3623 if (polygon_info[i] == (PolygonInfo *) NULL)
3624 return(DestroyPolygonThreadSet(polygon_info));
3626 path_info=(PathInfo *) RelinquishMagickMemory(path_info);
3627 return(polygon_info);
3630 static MagickRealType GetPixelOpacity(PolygonInfo *polygon_info,
3631 const MagickRealType mid,const MagickBooleanType fill,
3632 const FillRule fill_rule,const long x,const long y,
3633 MagickRealType *stroke_opacity)
3653 register const PointInfo
3660 Compute fill & stroke opacity for this (x,y) point.
3662 *stroke_opacity=0.0;
3663 subpath_opacity=0.0;
3664 p=polygon_info->edges;
3665 for (j=0; j < (long) polygon_info->number_edges; j++, p++)
3667 if (y <= (p->bounds.y1-mid-0.5))
3669 if (y > (p->bounds.y2+mid+0.5))
3671 (void) DestroyEdge(polygon_info,j);
3674 if ((x <= (p->bounds.x1-mid-0.5)) || (x > (p->bounds.x2+mid+0.5)))
3676 for (i=MagickMax(p->highwater,1); i < (long) p->number_points; i++)
3678 if (y <= (p->points[i-1].y-mid-0.5))
3680 if (y > (p->points[i].y+mid+0.5))
3682 if (p->scanline != y)
3688 Compute distance between a point and an edge.
3691 delta.x=(q+1)->x-q->x;
3692 delta.y=(q+1)->y-q->y;
3693 beta=delta.x*(x-q->x)+delta.y*(y-q->y);
3698 distance=delta.x*delta.x+delta.y*delta.y;
3702 alpha=delta.x*delta.x+delta.y*delta.y;
3707 distance=delta.x*delta.x+delta.y*delta.y;
3712 beta=delta.x*(y-q->y)-delta.y*(x-q->x);
3713 distance=alpha*beta*beta;
3717 Compute stroke & subpath opacity.
3720 if (p->ghostline == MagickFalse)
3723 if ((*stroke_opacity < 1.0) &&
3724 (distance <= ((alpha+0.25)*(alpha+0.25))))
3727 if (distance <= ((alpha+0.25)*(alpha+0.25)))
3728 *stroke_opacity=1.0;
3732 if (distance != 1.0)
3733 beta=sqrt((double) distance);
3735 if (*stroke_opacity < ((alpha-0.25)*(alpha-0.25)))
3736 *stroke_opacity=(alpha-0.25)*(alpha-0.25);
3740 if ((fill == MagickFalse) || (distance > 1.0) || (subpath_opacity >= 1.0))
3742 if (distance <= 0.0)
3744 subpath_opacity=1.0;
3752 if (distance != 1.0)
3753 beta=sqrt(distance);
3756 if (subpath_opacity < (alpha*alpha))
3757 subpath_opacity=alpha*alpha;
3761 Compute fill opacity.
3763 if (fill == MagickFalse)
3765 if (subpath_opacity >= 1.0)
3768 Determine winding number.
3771 p=polygon_info->edges;
3772 for (j=0; j < (long) polygon_info->number_edges; j++, p++)
3774 if (y <= p->bounds.y1)
3776 if ((y > p->bounds.y2) || (x <= p->bounds.x1))
3778 if (x > p->bounds.x2)
3780 winding_number+=p->direction ? 1 : -1;
3783 for (i=MagickMax(p->highwater,1); i < (long) p->number_points; i++)
3784 if (y <= p->points[i].y)
3787 if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x)))
3788 winding_number+=p->direction ? 1 : -1;
3790 if (fill_rule != NonZeroRule)
3792 if ((MagickAbsoluteValue(winding_number) & 0x01) != 0)
3796 if (MagickAbsoluteValue(winding_number) != 0)
3798 return(subpath_opacity);
3801 static MagickBooleanType DrawPolygonPrimitive(Image *image,
3802 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
3823 **restrict polygon_info;
3835 Compute bounding box.
3837 assert(image != (Image *) NULL);
3838 assert(image->signature == MagickSignature);
3839 if (image->debug != MagickFalse)
3840 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3841 assert(draw_info != (DrawInfo *) NULL);
3842 assert(draw_info->signature == MagickSignature);
3843 assert(primitive_info != (PrimitiveInfo *) NULL);
3844 if (primitive_info->coordinates == 0)
3846 polygon_info=AcquirePolygonThreadSet(draw_info,primitive_info);
3847 if (polygon_info == (PolygonInfo **) NULL)
3848 return(MagickFalse);
3850 DrawBoundingRectangles(image,draw_info,polygon_info[0]);
3851 if (image->debug != MagickFalse)
3852 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-polygon");
3853 fill=(primitive_info->method == FillToBorderMethod) ||
3854 (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse;
3855 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
3856 bounds=polygon_info[0]->edges[0].bounds;
3857 for (i=1; i < (long) polygon_info[0]->number_edges; i++)
3859 p=polygon_info[0]->edges+i;
3860 if (p->bounds.x1 < bounds.x1)
3861 bounds.x1=p->bounds.x1;
3862 if (p->bounds.y1 < bounds.y1)
3863 bounds.y1=p->bounds.y1;
3864 if (p->bounds.x2 > bounds.x2)
3865 bounds.x2=p->bounds.x2;
3866 if (p->bounds.y2 > bounds.y2)
3867 bounds.y2=p->bounds.y2;
3869 bounds.x1-=(mid+1.0);
3870 bounds.x1=bounds.x1 < 0.0 ? 0.0 : (unsigned long) ceil(bounds.x1-0.5) >=
3871 image->columns ? (double) image->columns-1.0 : bounds.x1;
3872 bounds.y1-=(mid+1.0);
3873 bounds.y1=bounds.y1 < 0.0 ? 0.0 : (unsigned long) ceil(bounds.y1-0.5) >=
3874 image->rows ? (double) image->rows-1.0 : bounds.y1;
3875 bounds.x2+=(mid+1.0);
3876 bounds.x2=bounds.x2 < 0.0 ? 0.0 : (unsigned long) floor(bounds.x2+0.5) >=
3877 image->columns ? (double) image->columns-1.0 : bounds.x2;
3878 bounds.y2+=(mid+1.0);
3879 bounds.y2=bounds.y2 < 0.0 ? 0.0 : (unsigned long) floor(bounds.y2+0.5) >=
3880 image->rows ? (double) image->rows-1.0 : bounds.y2;
3882 exception=(&image->exception);
3883 start=(long) ceil(bounds.x1-0.5);
3884 stop=(long) floor(bounds.x2+0.5);
3885 image_view=AcquireCacheView(image);
3886 if (primitive_info->coordinates == 1)
3891 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3892 #pragma omp parallel for schedule(dynamic,4) shared(status)
3894 for (y=(long) ceil(bounds.y1-0.5); y <= (long) floor(bounds.y2+0.5); y++)
3902 register PixelPacket
3905 if (status == MagickFalse)
3908 q=GetCacheViewAuthenticPixels(image_view,x,y,(unsigned long) (stop-x+1),
3910 if (q == (PixelPacket *) NULL)
3915 for ( ; x <= stop; x++)
3917 if ((x == (long) ceil(primitive_info->point.x-0.5)) &&
3918 (y == (long) ceil(primitive_info->point.y-0.5)))
3919 (void) GetStrokeColor(draw_info,x,y,q);
3922 sync=SyncCacheViewAuthenticPixels(image_view,exception);
3923 if (sync == MagickFalse)
3926 image_view=DestroyCacheView(image_view);
3927 polygon_info=DestroyPolygonThreadSet(polygon_info);
3928 if (image->debug != MagickFalse)
3929 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
3930 " end draw-polygon");
3934 Draw polygon or line.
3936 if (image->matte == MagickFalse)
3937 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3938 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3939 #pragma omp parallel for schedule(dynamic,4) shared(status)
3941 for (y=(long) ceil(bounds.y1-0.5); y <= (long) floor(bounds.y2+0.5); y++)
3955 register PixelPacket
3958 if (status == MagickFalse)
3960 q=GetCacheViewAuthenticPixels(image_view,start,y,(unsigned long) (stop-
3961 start+1),1,exception);
3962 if (q == (PixelPacket *) NULL)
3967 id=GetOpenMPThreadId();
3968 for (x=start; x <= stop; x++)
3973 fill_opacity=GetPixelOpacity(polygon_info[id],mid,fill,
3974 draw_info->fill_rule,x,y,&stroke_opacity);
3975 if (draw_info->stroke_antialias == MagickFalse)
3977 fill_opacity=fill_opacity > 0.25 ? 1.0 : 0.0;
3978 stroke_opacity=stroke_opacity > 0.25 ? 1.0 : 0.0;
3980 (void) GetFillColor(draw_info,x,y,&fill_color);
3981 fill_opacity=(MagickRealType) (QuantumRange-fill_opacity*(QuantumRange-
3982 fill_color.opacity));
3983 MagickCompositeOver(&fill_color,fill_opacity,q,(MagickRealType)
3985 (void) GetStrokeColor(draw_info,x,y,&stroke_color);
3986 stroke_opacity=(MagickRealType) (QuantumRange-stroke_opacity*
3987 (QuantumRange-stroke_color.opacity));
3988 MagickCompositeOver(&stroke_color,stroke_opacity,q,(MagickRealType)
3992 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3995 image_view=DestroyCacheView(image_view);
3996 polygon_info=DestroyPolygonThreadSet(polygon_info);
3997 if (image->debug != MagickFalse)
3998 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-polygon");
4003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4007 % D r a w P r i m i t i v e %
4011 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4013 % DrawPrimitive() draws a primitive (line, rectangle, ellipse) on the image.
4015 % The format of the DrawPrimitive method is:
4017 % MagickBooleanType DrawPrimitive(Image *image,const DrawInfo *draw_info,
4018 % PrimitiveInfo *primitive_info)
4020 % A description of each parameter follows:
4022 % o image: the image.
4024 % o draw_info: the draw info.
4026 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
4030 static void LogPrimitiveInfo(const PrimitiveInfo *primitive_info)
4056 x=(long) ceil(primitive_info->point.x-0.5);
4057 y=(long) ceil(primitive_info->point.y-0.5);
4058 switch (primitive_info->primitive)
4060 case PointPrimitive:
4062 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4063 "PointPrimitive %ld,%ld %s",x,y,methods[primitive_info->method]);
4066 case ColorPrimitive:
4068 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4069 "ColorPrimitive %ld,%ld %s",x,y,methods[primitive_info->method]);
4072 case MattePrimitive:
4074 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4075 "MattePrimitive %ld,%ld %s",x,y,methods[primitive_info->method]);
4080 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4081 "TextPrimitive %ld,%ld",x,y);
4084 case ImagePrimitive:
4086 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4087 "ImagePrimitive %ld,%ld",x,y);
4094 p=primitive_info[0].point;
4097 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4099 point=primitive_info[i].point;
4100 if (coordinates <= 0)
4102 coordinates=(long) primitive_info[i].coordinates;
4103 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4104 " begin open (%ld)",coordinates);
4107 point=primitive_info[i].point;
4108 if ((fabs(q.x-point.x) > MagickEpsilon) ||
4109 (fabs(q.y-point.y) > MagickEpsilon))
4110 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4111 " %ld: %.18g,%.18g",coordinates,point.x,point.y);
4113 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4114 " %ld: %g,%g (duplicate)",coordinates,point.x,point.y);
4117 if (coordinates > 0)
4119 if ((fabs(p.x-point.x) > MagickEpsilon) ||
4120 (fabs(p.y-point.y) > MagickEpsilon))
4121 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end last (%ld)",
4124 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end open (%ld)",
4129 MagickExport MagickBooleanType DrawPrimitive(Image *image,
4130 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4148 if (image->debug != MagickFalse)
4150 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4151 " begin draw-primitive");
4152 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4153 " affine: %g,%g,%g,%g,%g,%g",draw_info->affine.sx,
4154 draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy,
4155 draw_info->affine.tx,draw_info->affine.ty);
4158 exception=(&image->exception);
4159 x=(long) ceil(primitive_info->point.x-0.5);
4160 y=(long) ceil(primitive_info->point.y-0.5);
4161 image_view=AcquireCacheView(image);
4162 switch (primitive_info->primitive)
4164 case PointPrimitive:
4172 if ((y < 0) || (y >= (long) image->rows))
4174 if ((x < 0) || (x >= (long) image->columns))
4176 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4177 if (q == (PixelPacket *) NULL)
4179 (void) GetFillColor(draw_info,x,y,&fill_color);
4180 MagickCompositeOver(&fill_color,(MagickRealType) fill_color.opacity,q,
4181 (MagickRealType) q->opacity,q);
4182 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4185 case ColorPrimitive:
4187 switch (primitive_info->method)
4195 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4196 if (q == (PixelPacket *) NULL)
4198 (void) GetFillColor(draw_info,x,y,q);
4199 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4210 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception);
4211 for (y=0; y < (long) image->rows; y++)
4213 register PixelPacket
4216 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4218 if (q == (PixelPacket *) NULL)
4220 for (x=0; x < (long) image->columns; x++)
4222 if (IsColorSimilar(image,q,&target) == MagickFalse)
4227 (void) GetFillColor(draw_info,x,y,q);
4230 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4231 if (sync == MagickFalse)
4236 case FloodfillMethod:
4237 case FillToBorderMethod:
4242 (void) GetOneVirtualMagickPixel(image,x,y,&target,exception);
4243 if (primitive_info->method == FillToBorderMethod)
4245 target.red=(MagickRealType) draw_info->border_color.red;
4246 target.green=(MagickRealType) draw_info->border_color.green;
4247 target.blue=(MagickRealType) draw_info->border_color.blue;
4249 (void) FloodfillPaintImage(image,DefaultChannels,draw_info,&target,x,
4250 y,primitive_info->method == FloodfillMethod ? MagickFalse :
4259 for (y=0; y < (long) image->rows; y++)
4264 register PixelPacket
4267 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4269 if (q == (PixelPacket *) NULL)
4271 for (x=0; x < (long) image->columns; x++)
4273 (void) GetFillColor(draw_info,x,y,q);
4276 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4277 if (sync == MagickFalse)
4285 case MattePrimitive:
4287 if (image->matte == MagickFalse)
4288 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
4289 switch (primitive_info->method)
4300 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4301 if (q == (PixelPacket *) NULL)
4303 (void) GetFillColor(draw_info,x,y,&pixel);
4304 q->opacity=pixel.opacity;
4305 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4317 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception);
4318 for (y=0; y < (long) image->rows; y++)
4323 register PixelPacket
4326 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4328 if (q == (PixelPacket *) NULL)
4330 for (x=0; x < (long) image->columns; x++)
4332 if (IsColorSimilar(image,q,&target) == MagickFalse)
4337 (void) GetFillColor(draw_info,x,y,&pixel);
4338 q->opacity=pixel.opacity;
4341 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4342 if (sync == MagickFalse)
4347 case FloodfillMethod:
4348 case FillToBorderMethod:
4353 (void) GetOneVirtualMagickPixel(image,x,y,&target,exception);
4354 if (primitive_info->method == FillToBorderMethod)
4356 target.red=(MagickRealType) draw_info->border_color.red;
4357 target.green=(MagickRealType) draw_info->border_color.green;
4358 target.blue=(MagickRealType) draw_info->border_color.blue;
4360 (void) FloodfillPaintImage(image,OpacityChannel,draw_info,&target,x,y,
4361 primitive_info->method == FloodfillMethod ? MagickFalse :
4373 for (y=0; y < (long) image->rows; y++)
4378 register PixelPacket
4381 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4383 if (q == (PixelPacket *) NULL)
4385 for (x=0; x < (long) image->columns; x++)
4387 (void) GetFillColor(draw_info,x,y,&pixel);
4388 q->opacity=pixel.opacity;
4391 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4392 if (sync == MagickFalse)
4403 geometry[MaxTextExtent];
4408 if (primitive_info->text == (char *) NULL)
4410 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4411 (void) CloneString(&clone_info->text,primitive_info->text);
4412 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
4413 primitive_info->point.x,primitive_info->point.y);
4414 (void) CloneString(&clone_info->geometry,geometry);
4415 status=AnnotateImage(image,clone_info);
4416 clone_info=DestroyDrawInfo(clone_info);
4419 case ImagePrimitive:
4425 composite_geometry[MaxTextExtent];
4440 if (primitive_info->text == (char *) NULL)
4442 clone_info=AcquireImageInfo();
4443 if (LocaleNCompare(primitive_info->text,"data:",5) == 0)
4444 composite_image=ReadInlineImage(clone_info,primitive_info->text,
4448 (void) CopyMagickString(clone_info->filename,primitive_info->text,
4450 composite_image=ReadImage(clone_info,&image->exception);
4452 clone_info=DestroyImageInfo(clone_info);
4453 if (composite_image == (Image *) NULL)
4455 (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor)
4456 NULL,(void *) NULL);
4457 x1=(long) ceil(primitive_info[1].point.x-0.5);
4458 y1=(long) ceil(primitive_info[1].point.y-0.5);
4459 if (((x1 != 0L) && (x1 != (long) composite_image->columns)) ||
4460 ((y1 != 0L) && (y1 != (long) composite_image->rows)))
4463 geometry[MaxTextExtent];
4468 (void) FormatMagickString(geometry,MaxTextExtent,"%gx%g!",
4469 primitive_info[1].point.x,primitive_info[1].point.y);
4470 composite_image->filter=image->filter;
4471 (void) TransformImage(&composite_image,(char *) NULL,geometry);
4473 if (composite_image->matte == MagickFalse)
4474 (void) SetImageAlphaChannel(composite_image,OpaqueAlphaChannel);
4475 if (draw_info->opacity != OpaqueOpacity)
4476 (void) SetImageOpacity(composite_image,draw_info->opacity);
4477 SetGeometry(image,&geometry);
4478 image->gravity=draw_info->gravity;
4481 (void) FormatMagickString(composite_geometry,MaxTextExtent,
4482 "%lux%lu%+ld%+ld",composite_image->columns,composite_image->rows,
4483 geometry.x,geometry.y);
4484 (void) ParseGravityGeometry(image,composite_geometry,&geometry,
4486 affine=draw_info->affine;
4487 affine.tx=(double) geometry.x;
4488 affine.ty=(double) geometry.y;
4489 composite_image->interpolate=image->interpolate;
4490 if (draw_info->compose == OverCompositeOp)
4491 (void) DrawAffineImage(image,composite_image,&affine);
4493 (void) CompositeImage(image,draw_info->compose,composite_image,
4494 geometry.x,geometry.y);
4495 composite_image=DestroyImage(composite_image);
4507 if (IsEventLogging() != MagickFalse)
4508 LogPrimitiveInfo(primitive_info);
4509 scale=ExpandAffine(&draw_info->affine);
4510 if ((draw_info->dash_pattern != (double *) NULL) &&
4511 (draw_info->dash_pattern[0] != 0.0) &&
4512 ((scale*draw_info->stroke_width) > MagickEpsilon) &&
4513 (draw_info->stroke.opacity != (Quantum) TransparentOpacity))
4518 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4519 clone_info->stroke_width=0.0;
4520 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4521 status=DrawPolygonPrimitive(image,clone_info,primitive_info);
4522 clone_info=DestroyDrawInfo(clone_info);
4523 (void) DrawDashPolygon(draw_info,primitive_info,image);
4526 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
4528 (draw_info->stroke.opacity != (Quantum) TransparentOpacity))
4534 Draw strokes while respecting line cap/join attributes.
4536 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
4538 (primitive_info[i-1].point.x == primitive_info[0].point.x) &&
4539 (primitive_info[i-1].point.y == primitive_info[0].point.y) ?
4540 MagickTrue : MagickFalse;
4541 i=(long) primitive_info[0].coordinates;
4542 if ((((draw_info->linecap == RoundCap) ||
4543 (closed_path != MagickFalse)) &&
4544 (draw_info->linejoin == RoundJoin)) ||
4545 (primitive_info[i].primitive != UndefinedPrimitive))
4547 (void) DrawPolygonPrimitive(image,draw_info,primitive_info);
4550 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4551 clone_info->stroke_width=0.0;
4552 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4553 status=DrawPolygonPrimitive(image,clone_info,primitive_info);
4554 clone_info=DestroyDrawInfo(clone_info);
4555 status|=DrawStrokePolygon(image,draw_info,primitive_info);
4558 status=DrawPolygonPrimitive(image,draw_info,primitive_info);
4562 image_view=DestroyCacheView(image_view);
4563 if (image->debug != MagickFalse)
4564 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-primitive");
4565 return(status != 0 ? MagickTrue : MagickFalse);
4569 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4573 + D r a w S t r o k e P o l y g o n %
4577 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4579 % DrawStrokePolygon() draws a stroked polygon (line, rectangle, ellipse) on
4580 % the image while respecting the line cap and join attributes.
4582 % The format of the DrawStrokePolygon method is:
4584 % MagickBooleanType DrawStrokePolygon(Image *image,
4585 % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4587 % A description of each parameter follows:
4589 % o image: the image.
4591 % o draw_info: the draw info.
4593 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
4598 static void DrawRoundLinecap(Image *image,const DrawInfo *draw_info,
4599 const PrimitiveInfo *primitive_info)
4607 for (i=0; i < 4; i++)
4608 linecap[i]=(*primitive_info);
4609 linecap[0].coordinates=4;
4610 linecap[1].point.x+=(double) (10.0*MagickEpsilon);
4611 linecap[2].point.x+=(double) (10.0*MagickEpsilon);
4612 linecap[2].point.y+=(double) (10.0*MagickEpsilon);
4613 linecap[3].point.y+=(double) (10.0*MagickEpsilon);
4614 linecap[4].primitive=UndefinedPrimitive;
4615 (void) DrawPolygonPrimitive(image,draw_info,linecap);
4618 static MagickBooleanType DrawStrokePolygon(Image *image,
4619 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4631 register const PrimitiveInfo
4636 Draw stroked polygon.
4638 if (image->debug != MagickFalse)
4639 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4640 " begin draw-stroke-polygon");
4641 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4642 clone_info->fill=draw_info->stroke;
4643 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4644 clone_info->stroke_width=0.0;
4645 clone_info->fill_rule=NonZeroRule;
4647 for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=p->coordinates)
4649 stroke_polygon=TraceStrokePolygon(draw_info,p);
4650 status=DrawPolygonPrimitive(image,clone_info,stroke_polygon);
4651 stroke_polygon=(PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon);
4652 q=p+p->coordinates-1;
4653 closed_path=(q->point.x == p->point.x) && (q->point.y == p->point.y) ?
4654 MagickTrue : MagickFalse;
4655 if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse))
4657 DrawRoundLinecap(image,draw_info,p);
4658 DrawRoundLinecap(image,draw_info,q);
4661 clone_info=DestroyDrawInfo(clone_info);
4662 if (image->debug != MagickFalse)
4663 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4664 " end draw-stroke-polygon");
4669 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4673 % G e t A f f i n e M a t r i x %
4677 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4679 % GetAffineMatrix() returns an AffineMatrix initialized to the identity
4682 % The format of the GetAffineMatrix method is:
4684 % void GetAffineMatrix(AffineMatrix *affine_matrix)
4686 % A description of each parameter follows:
4688 % o affine_matrix: the affine matrix.
4691 MagickExport void GetAffineMatrix(AffineMatrix *affine_matrix)
4693 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4694 assert(affine_matrix != (AffineMatrix *) NULL);
4695 (void) ResetMagickMemory(affine_matrix,0,sizeof(*affine_matrix));
4696 affine_matrix->sx=1.0;
4697 affine_matrix->sy=1.0;
4701 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4705 + G e t D r a w I n f o %
4709 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4711 % GetDrawInfo() initializes draw_info to default values.
4713 % The format of the GetDrawInfo method is:
4715 % void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info)
4717 % A description of each parameter follows:
4719 % o image_info: the image info..
4721 % o draw_info: the draw info.
4724 MagickExport void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info)
4736 Initialize draw attributes.
4738 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4739 assert(draw_info != (DrawInfo *) NULL);
4740 (void) ResetMagickMemory(draw_info,0,sizeof(*draw_info));
4741 clone_info=CloneImageInfo(image_info);
4742 GetAffineMatrix(&draw_info->affine);
4743 exception=AcquireExceptionInfo();
4744 (void) QueryColorDatabase("#000F",&draw_info->fill,exception);
4745 (void) QueryColorDatabase("#FFF0",&draw_info->stroke,exception);
4746 draw_info->stroke_antialias=clone_info->antialias;
4747 draw_info->stroke_width=1.0;
4748 draw_info->opacity=OpaqueOpacity;
4749 draw_info->fill_rule=EvenOddRule;
4750 draw_info->linecap=ButtCap;
4751 draw_info->linejoin=MiterJoin;
4752 draw_info->miterlimit=10;
4753 draw_info->decorate=NoDecoration;
4754 if (clone_info->font != (char *) NULL)
4755 draw_info->font=AcquireString(clone_info->font);
4756 if (clone_info->density != (char *) NULL)
4757 draw_info->density=AcquireString(clone_info->density);
4758 draw_info->text_antialias=clone_info->antialias;
4759 draw_info->pointsize=12.0;
4760 if (clone_info->pointsize != 0.0)
4761 draw_info->pointsize=clone_info->pointsize;
4762 draw_info->undercolor.opacity=(Quantum) TransparentOpacity;
4763 draw_info->border_color=clone_info->border_color;
4764 draw_info->compose=OverCompositeOp;
4765 if (clone_info->server_name != (char *) NULL)
4766 draw_info->server_name=AcquireString(clone_info->server_name);
4767 draw_info->render=MagickTrue;
4768 draw_info->debug=IsEventLogging();
4769 option=GetImageOption(clone_info,"encoding");
4770 if (option != (const char *) NULL)
4771 (void) CloneString(&draw_info->encoding,option);
4772 option=GetImageOption(clone_info,"kerning");
4773 if (option != (const char *) NULL)
4774 draw_info->kerning=StringToDouble(option);
4775 option=GetImageOption(clone_info,"interline-spacing");
4776 if (option != (const char *) NULL)
4777 draw_info->interline_spacing=StringToDouble(option);
4778 draw_info->direction=1.0;
4779 option=GetImageOption(clone_info,"interword-spacing");
4780 if (option != (const char *) NULL)
4781 draw_info->interword_spacing=StringToDouble(option);
4782 option=GetImageOption(clone_info,"direction");
4783 if (option != (const char *) NULL)
4784 draw_info->direction=(DirectionType) ParseMagickOption(
4785 MagickDirectionOptions,MagickFalse,option);
4786 option=GetImageOption(clone_info,"fill");
4787 if (option != (const char *) NULL)
4788 (void) QueryColorDatabase(option,&draw_info->fill,exception);
4789 option=GetImageOption(clone_info,"stroke");
4790 if (option != (const char *) NULL)
4791 (void) QueryColorDatabase(option,&draw_info->stroke,exception);
4792 option=GetImageOption(clone_info,"strokewidth");
4793 if (option != (const char *) NULL)
4794 draw_info->stroke_width=StringToDouble(option);
4795 option=GetImageOption(clone_info,"undercolor");
4796 if (option != (const char *) NULL)
4797 (void) QueryColorDatabase(option,&draw_info->undercolor,exception);
4798 option=GetImageOption(clone_info,"gravity");
4799 if (option != (const char *) NULL)
4800 draw_info->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
4801 MagickFalse,option);
4802 exception=DestroyExceptionInfo(exception);
4803 draw_info->signature=MagickSignature;
4804 clone_info=DestroyImageInfo(clone_info);
4808 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4812 + P e r m u t a t e %
4816 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4818 % Permutate() returns the permuation of the (n,k).
4820 % The format of the Permutate method is:
4822 % void Permutate(long n,long k)
4824 % A description of each parameter follows:
4832 static inline MagickRealType Permutate(const long n,const long k)
4841 for (i=k+1; i <= n; i++)
4843 for (i=1; i <= (n-k); i++)
4849 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4853 + T r a c e P r i m i t i v e %
4857 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4859 % TracePrimitive is a collection of methods for generating graphic
4860 % primitives such as arcs, ellipses, paths, etc.
4864 static void TraceArc(PrimitiveInfo *primitive_info,const PointInfo start,
4865 const PointInfo end,const PointInfo degrees)
4871 center.x=0.5*(end.x+start.x);
4872 center.y=0.5*(end.y+start.y);
4873 radii.x=fabs(center.x-start.x);
4874 radii.y=fabs(center.y-start.y);
4875 TraceEllipse(primitive_info,center,radii,degrees);
4878 static void TraceArcPath(PrimitiveInfo *primitive_info,const PointInfo start,
4879 const PointInfo end,const PointInfo arc,const MagickRealType angle,
4880 const MagickBooleanType large_arc,const MagickBooleanType sweep)
4895 register MagickRealType
4899 register PrimitiveInfo
4908 if ((start.x == end.x) && (start.y == end.y))
4910 TracePoint(primitive_info,end);
4913 radii.x=fabs(arc.x);
4914 radii.y=fabs(arc.y);
4915 if ((radii.x == 0.0) || (radii.y == 0.0))
4917 TraceLine(primitive_info,start,end);
4920 cosine=cos(DegreesToRadians(fmod((double) angle,360.0)));
4921 sine=sin(DegreesToRadians(fmod((double) angle,360.0)));
4922 center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2);
4923 center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2);
4924 delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/
4926 if (delta < MagickEpsilon)
4928 TraceLine(primitive_info,start,end);
4933 radii.x*=sqrt((double) delta);
4934 radii.y*=sqrt((double) delta);
4936 points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x);
4937 points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y);
4938 points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x);
4939 points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y);
4940 alpha=points[1].x-points[0].x;
4941 beta=points[1].y-points[0].y;
4942 factor=1.0/(alpha*alpha+beta*beta)-0.25;
4947 factor=sqrt((double) factor);
4948 if (sweep == large_arc)
4951 center.x=(double) ((points[0].x+points[1].x)/2-factor*beta);
4952 center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha);
4953 alpha=atan2(points[0].y-center.y,points[0].x-center.x);
4954 theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha;
4955 if ((theta < 0.0) && (sweep != MagickFalse))
4956 theta+=(MagickRealType) (2.0*MagickPI);
4958 if ((theta > 0.0) && (sweep == MagickFalse))
4959 theta-=(MagickRealType) (2.0*MagickPI);
4960 arc_segments=(unsigned long) ceil(fabs((double) (theta/(0.5*MagickPI+
4961 MagickEpsilon)))-0.5);
4963 for (i=0; i < (long) arc_segments; i++)
4965 beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments));
4966 gamma=(8.0/3.0)*sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))*
4967 sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))/
4968 sin(fmod((double) beta,DegreesToRadians(360.0)));
4969 points[0].x=(double) (center.x+cos(fmod((double) (alpha+(double) i*theta/
4970 arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((double) (alpha+
4971 (double) i*theta/arc_segments),DegreesToRadians(360.0))));
4972 points[0].y=(double) (center.y+sin(fmod((double) (alpha+(double) i*theta/
4973 arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((double) (alpha+
4974 (double) i*theta/arc_segments),DegreesToRadians(360.0))));
4975 points[2].x=(double) (center.x+cos(fmod((double) (alpha+(double) (i+1)*
4976 theta/arc_segments),DegreesToRadians(360.0))));
4977 points[2].y=(double) (center.y+sin(fmod((double) (alpha+(double) (i+1)*
4978 theta/arc_segments),DegreesToRadians(360.0))));
4979 points[1].x=(double) (points[2].x+gamma*sin(fmod((double) (alpha+(double)
4980 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
4981 points[1].y=(double) (points[2].y-gamma*cos(fmod((double) (alpha+(double)
4982 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
4983 p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x;
4984 p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y;
4985 (p+1)->point.x=(double) (cosine*radii.x*points[0].x-sine*radii.y*
4987 (p+1)->point.y=(double) (sine*radii.x*points[0].x+cosine*radii.y*
4989 (p+2)->point.x=(double) (cosine*radii.x*points[1].x-sine*radii.y*
4991 (p+2)->point.y=(double) (sine*radii.x*points[1].x+cosine*radii.y*
4993 (p+3)->point.x=(double) (cosine*radii.x*points[2].x-sine*radii.y*
4995 (p+3)->point.y=(double) (sine*radii.x*points[2].x+cosine*radii.y*
4997 if (i == (long) (arc_segments-1))
5002 primitive_info->coordinates=(unsigned long) (p-primitive_info);
5003 for (i=0; i < (long) primitive_info->coordinates; i++)
5005 p->primitive=primitive_info->primitive;
5010 static void TraceBezier(PrimitiveInfo *primitive_info,
5011 const unsigned long number_coordinates)
5027 register PrimitiveInfo
5035 Allocate coeficients.
5037 quantum=number_coordinates;
5038 for (i=0; i < (long) number_coordinates; i++)
5040 for (j=i+1; j < (long) number_coordinates; j++)
5042 alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x);
5043 if (alpha > (MagickRealType) quantum)
5044 quantum=(unsigned long) alpha;
5045 alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y);
5046 if (alpha > (MagickRealType) quantum)
5047 quantum=(unsigned long) alpha;
5050 quantum=(unsigned long) MagickMin((double) quantum/number_coordinates,
5051 (double) BezierQuantum);
5052 control_points=quantum*number_coordinates;
5053 coefficients=(MagickRealType *) AcquireQuantumMemory((size_t)
5054 number_coordinates,sizeof(*coefficients));
5055 points=(PointInfo *) AcquireQuantumMemory((size_t) control_points,
5057 if ((coefficients == (MagickRealType *) NULL) ||
5058 (points == (PointInfo *) NULL))
5059 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
5061 Compute bezier points.
5063 end=primitive_info[number_coordinates-1].point;
5064 for (i=0; i < (long) number_coordinates; i++)
5065 coefficients[i]=Permutate((long) number_coordinates-1,i);
5067 for (i=0; i < (long) control_points; i++)
5072 alpha=pow((double) (1.0-weight),(double) number_coordinates-1.0);
5073 for (j=0; j < (long) number_coordinates; j++)
5075 point.x+=alpha*coefficients[j]*p->point.x;
5076 point.y+=alpha*coefficients[j]*p->point.y;
5077 alpha*=weight/(1.0-weight);
5081 weight+=1.0/control_points;
5084 Bezier curves are just short segmented polys.
5087 for (i=0; i < (long) control_points; i++)
5089 TracePoint(p,points[i]);
5094 primitive_info->coordinates=(unsigned long) (p-primitive_info);
5095 for (i=0; i < (long) primitive_info->coordinates; i++)
5097 p->primitive=primitive_info->primitive;
5100 points=(PointInfo *) RelinquishMagickMemory(points);
5101 coefficients=(MagickRealType *) RelinquishMagickMemory(coefficients);
5104 static void TraceCircle(PrimitiveInfo *primitive_info,const PointInfo start,
5105 const PointInfo end)
5116 alpha=end.x-start.x;
5118 radius=hypot((double) alpha,(double) beta);
5119 offset.x=(double) radius;
5120 offset.y=(double) radius;
5123 TraceEllipse(primitive_info,start,offset,degrees);
5126 static void TraceEllipse(PrimitiveInfo *primitive_info,const PointInfo start,
5127 const PointInfo stop,const PointInfo degrees)
5138 register PrimitiveInfo
5145 Ellipses are just short segmented polys.
5147 if ((stop.x == 0.0) && (stop.y == 0.0))
5149 TracePoint(primitive_info,start);
5152 delta=2.0/MagickMax(stop.x,stop.y);
5153 step=(MagickRealType) (MagickPI/8.0);
5154 if ((delta >= 0.0) && (delta < (MagickPI/8.0)))
5155 step=MagickPI/(4*(MagickPI/delta/2+0.5));
5156 angle.x=DegreesToRadians(degrees.x);
5158 while (y < degrees.x)
5160 angle.y=(double) (DegreesToRadians(y)-MagickEpsilon);
5161 for (p=primitive_info; angle.x < angle.y; angle.x+=step)
5163 point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*stop.x+start.x;
5164 point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*stop.y+start.y;
5165 TracePoint(p,point);
5168 point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*stop.x+start.x;
5169 point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*stop.y+start.y;
5170 TracePoint(p,point);
5172 primitive_info->coordinates=(unsigned long) (p-primitive_info);
5173 for (i=0; i < (long) primitive_info->coordinates; i++)
5175 p->primitive=primitive_info->primitive;
5180 static void TraceLine(PrimitiveInfo *primitive_info,const PointInfo start,
5181 const PointInfo end)
5183 TracePoint(primitive_info,start);
5184 if ((fabs(start.x-end.x) <= MagickEpsilon) &&
5185 (fabs(start.y-end.y) <= MagickEpsilon))
5187 primitive_info->primitive=PointPrimitive;
5188 primitive_info->coordinates=1;
5191 TracePoint(primitive_info+1,end);
5192 (primitive_info+1)->primitive=primitive_info->primitive;
5193 primitive_info->coordinates=2;
5196 static unsigned long TracePath(PrimitiveInfo *primitive_info,const char *path)
5199 token[MaxTextExtent];
5221 register PrimitiveInfo
5236 number_coordinates=0;
5238 primitive_type=primitive_info->primitive;
5240 for (p=path; *p != '\0'; )
5242 while (isspace((int) ((unsigned char) *p)) != 0)
5246 last_attribute=attribute;
5247 attribute=(int) (*p++);
5268 GetMagickToken(p,&p,token);
5270 GetMagickToken(p,&p,token);
5271 arc.x=StringToDouble(token);
5272 GetMagickToken(p,&p,token);
5274 GetMagickToken(p,&p,token);
5275 arc.y=StringToDouble(token);
5276 GetMagickToken(p,&p,token);
5278 GetMagickToken(p,&p,token);
5279 angle=StringToDouble(token);
5280 GetMagickToken(p,&p,token);
5282 GetMagickToken(p,&p,token);
5283 large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
5284 GetMagickToken(p,&p,token);
5286 GetMagickToken(p,&p,token);
5287 sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
5288 GetMagickToken(p,&p,token);
5290 GetMagickToken(p,&p,token);
5291 x=StringToDouble(token);
5292 GetMagickToken(p,&p,token);
5294 GetMagickToken(p,&p,token);
5295 y=StringToDouble(token);
5296 end.x=(double) (attribute == (int) 'A' ? x : point.x+x);
5297 end.y=(double) (attribute == (int) 'A' ? y : point.y+y);
5298 TraceArcPath(q,point,end,arc,angle,large_arc,sweep);
5301 } while (IsPoint(p) != MagickFalse);
5308 Compute bezier points.
5313 for (i=1; i < 4; i++)
5315 GetMagickToken(p,&p,token);
5317 GetMagickToken(p,&p,token);
5318 x=StringToDouble(token);
5319 GetMagickToken(p,&p,token);
5321 GetMagickToken(p,&p,token);
5322 y=StringToDouble(token);
5323 end.x=(double) (attribute == (int) 'C' ? x : point.x+x);
5324 end.y=(double) (attribute == (int) 'C' ? y : point.y+y);
5327 for (i=0; i < 4; i++)
5328 (q+i)->point=points[i];
5332 } while (IsPoint(p) != MagickFalse);
5340 GetMagickToken(p,&p,token);
5342 GetMagickToken(p,&p,token);
5343 x=StringToDouble(token);
5344 point.x=(double) (attribute == (int) 'H' ? x: point.x+x);
5345 TracePoint(q,point);
5347 } while (IsPoint(p) != MagickFalse);
5355 GetMagickToken(p,&p,token);
5357 GetMagickToken(p,&p,token);
5358 x=StringToDouble(token);
5359 GetMagickToken(p,&p,token);
5361 GetMagickToken(p,&p,token);
5362 y=StringToDouble(token);
5363 point.x=(double) (attribute == (int) 'L' ? x : point.x+x);
5364 point.y=(double) (attribute == (int) 'L' ? y : point.y+y);
5365 TracePoint(q,point);
5367 } while (IsPoint(p) != MagickFalse);
5373 if (q != primitive_info)
5375 primitive_info->coordinates=(unsigned long) (q-primitive_info);
5376 number_coordinates+=primitive_info->coordinates;
5382 GetMagickToken(p,&p,token);
5384 GetMagickToken(p,&p,token);
5385 x=StringToDouble(token);
5386 GetMagickToken(p,&p,token);
5388 GetMagickToken(p,&p,token);
5389 y=StringToDouble(token);
5390 point.x=(double) (attribute == (int) 'M' ? x : point.x+x);
5391 point.y=(double) (attribute == (int) 'M' ? y : point.y+y);
5395 TracePoint(q,point);
5397 if (attribute == (int) 'M')
5399 TracePoint(q,point);
5402 } while (IsPoint(p) != MagickFalse);
5409 Compute bezier points.
5414 for (i=1; i < 3; i++)
5416 GetMagickToken(p,&p,token);
5418 GetMagickToken(p,&p,token);
5419 x=StringToDouble(token);
5420 GetMagickToken(p,&p,token);
5422 GetMagickToken(p,&p,token);
5423 y=StringToDouble(token);
5426 end.x=(double) (attribute == (int) 'Q' ? x : point.x+x);
5427 end.y=(double) (attribute == (int) 'Q' ? y : point.y+y);
5430 for (i=0; i < 3; i++)
5431 (q+i)->point=points[i];
5435 } while (IsPoint(p) != MagickFalse);
5442 Compute bezier points.
5446 points[0]=points[3];
5447 points[1].x=2.0*points[3].x-points[2].x;
5448 points[1].y=2.0*points[3].y-points[2].y;
5449 for (i=2; i < 4; i++)
5451 GetMagickToken(p,&p,token);
5453 GetMagickToken(p,&p,token);
5454 x=StringToDouble(token);
5455 GetMagickToken(p,&p,token);
5457 GetMagickToken(p,&p,token);
5458 y=StringToDouble(token);
5461 end.x=(double) (attribute == (int) 'S' ? x : point.x+x);
5462 end.y=(double) (attribute == (int) 'S' ? y : point.y+y);
5465 if (strchr("CcSs",last_attribute) == (char *) NULL)
5467 points[0]=points[2];
5468 points[1]=points[3];
5470 for (i=0; i < 4; i++)
5471 (q+i)->point=points[i];
5475 } while (IsPoint(p) != MagickFalse);
5482 Compute bezier points.
5486 points[0]=points[2];
5487 points[1].x=2.0*points[2].x-points[1].x;
5488 points[1].y=2.0*points[2].y-points[1].y;
5489 for (i=2; i < 3; i++)
5491 GetMagickToken(p,&p,token);
5493 GetMagickToken(p,&p,token);
5494 x=StringToDouble(token);
5495 GetMagickToken(p,&p,token);
5497 GetMagickToken(p,&p,token);
5498 y=StringToDouble(token);
5499 end.x=(double) (attribute == (int) 'T' ? x : point.x+x);
5500 end.y=(double) (attribute == (int) 'T' ? y : point.y+y);
5503 if (strchr("QqTt",last_attribute) == (char *) NULL)
5505 points[0]=points[2];
5506 points[1]=points[3];
5508 for (i=0; i < 3; i++)
5509 (q+i)->point=points[i];
5513 } while (IsPoint(p) != MagickFalse);
5521 GetMagickToken(p,&p,token);
5523 GetMagickToken(p,&p,token);
5524 y=StringToDouble(token);
5525 point.y=(double) (attribute == (int) 'V' ? y : point.y+y);
5526 TracePoint(q,point);
5528 } while (IsPoint(p) != MagickFalse);
5535 TracePoint(q,point);
5537 primitive_info->coordinates=(unsigned long) (q-primitive_info);
5538 number_coordinates+=primitive_info->coordinates;
5545 if (isalpha((int) ((unsigned char) attribute)) != 0)
5546 (void) fprintf(stderr,"attribute not recognized: %c\n",attribute);
5551 primitive_info->coordinates=(unsigned long) (q-primitive_info);
5552 number_coordinates+=primitive_info->coordinates;
5553 for (i=0; i < (long) number_coordinates; i++)
5556 q->primitive=primitive_type;
5558 q->method=FillToBorderMethod;
5561 return(number_coordinates);
5564 static void TraceRectangle(PrimitiveInfo *primitive_info,const PointInfo start,
5565 const PointInfo end)
5570 register PrimitiveInfo
5577 TracePoint(p,start);
5581 TracePoint(p,point);
5587 TracePoint(p,point);
5589 TracePoint(p,start);
5591 primitive_info->coordinates=(unsigned long) (p-primitive_info);
5592 for (i=0; i < (long) primitive_info->coordinates; i++)
5594 p->primitive=primitive_info->primitive;
5599 static void TraceRoundRectangle(PrimitiveInfo *primitive_info,
5600 const PointInfo start,const PointInfo end,PointInfo arc)
5607 register PrimitiveInfo
5614 offset.x=fabs(end.x-start.x);
5615 offset.y=fabs(end.y-start.y);
5616 if (arc.x > (0.5*offset.x))
5618 if (arc.y > (0.5*offset.y))
5620 point.x=start.x+offset.x-arc.x;
5621 point.y=start.y+arc.y;
5624 TraceEllipse(p,point,arc,degrees);
5626 point.x=start.x+offset.x-arc.x;
5627 point.y=start.y+offset.y-arc.y;
5630 TraceEllipse(p,point,arc,degrees);
5632 point.x=start.x+arc.x;
5633 point.y=start.y+offset.y-arc.y;
5636 TraceEllipse(p,point,arc,degrees);
5638 point.x=start.x+arc.x;
5639 point.y=start.y+arc.y;
5642 TraceEllipse(p,point,arc,degrees);
5644 TracePoint(p,primitive_info->point);
5646 primitive_info->coordinates=(unsigned long) (p-primitive_info);
5647 for (i=0; i < (long) primitive_info->coordinates; i++)
5649 p->primitive=primitive_info->primitive;
5654 static void TraceSquareLinecap(PrimitiveInfo *primitive_info,
5655 const unsigned long number_vertices,const MagickRealType offset)
5663 register MagickRealType
5672 for (i=1; i < (long) number_vertices; i++)
5674 dx=primitive_info[0].point.x-primitive_info[i].point.x;
5675 dy=primitive_info[0].point.y-primitive_info[i].point.y;
5676 if ((fabs((double) dx) >= MagickEpsilon) ||
5677 (fabs((double) dy) >= MagickEpsilon))
5680 if (i == (long) number_vertices)
5681 i=(long) number_vertices-1L;
5682 distance=hypot((double) dx,(double) dy);
5683 primitive_info[0].point.x=(double) (primitive_info[i].point.x+
5684 dx*(distance+offset)/distance);
5685 primitive_info[0].point.y=(double) (primitive_info[i].point.y+
5686 dy*(distance+offset)/distance);
5687 for (j=(long) number_vertices-2; j >= 0; j--)
5689 dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x;
5690 dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y;
5691 if ((fabs((double) dx) >= MagickEpsilon) ||
5692 (fabs((double) dy) >= MagickEpsilon))
5695 distance=hypot((double) dx,(double) dy);
5696 primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+
5697 dx*(distance+offset)/distance);
5698 primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+
5699 dy*(distance+offset)/distance);
5702 static PrimitiveInfo *TraceStrokePolygon(const DrawInfo *draw_info,
5703 const PrimitiveInfo *primitive_info)
5705 typedef struct _LineSegment
5757 number_vertices=primitive_info->coordinates;
5758 max_strokes=2*number_vertices+6*BezierQuantum+360;
5759 path_p=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes,
5761 path_q=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes,
5763 polygon_primitive=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
5764 number_vertices+2UL,sizeof(*polygon_primitive));
5765 if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL) ||
5766 (polygon_primitive == (PrimitiveInfo *) NULL))
5767 return((PrimitiveInfo *) NULL);
5768 (void) CopyMagickMemory(polygon_primitive,primitive_info,(size_t)
5769 number_vertices*sizeof(*polygon_primitive));
5771 (primitive_info[number_vertices-1].point.x == primitive_info[0].point.x) &&
5772 (primitive_info[number_vertices-1].point.y == primitive_info[0].point.y) ?
5773 MagickTrue : MagickFalse;
5774 if ((draw_info->linejoin == RoundJoin) ||
5775 ((draw_info->linejoin == MiterJoin) && (closed_path != MagickFalse)))
5777 polygon_primitive[number_vertices]=primitive_info[1];
5780 polygon_primitive[number_vertices].primitive=UndefinedPrimitive;
5782 Compute the slope for the first line segment, p.
5786 for (n=1; n < (long) number_vertices; n++)
5788 dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x;
5789 dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y;
5790 if ((fabs(dx.p) >= MagickEpsilon) || (fabs(dy.p) >= MagickEpsilon))
5793 if (n == (long) number_vertices)
5794 n=(long) number_vertices-1L;
5796 inverse_slope.p=0.0;
5797 if (fabs(dx.p) <= MagickEpsilon)
5800 slope.p=dy.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5802 slope.p=dy.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5805 if (fabs(dy.p) <= MagickEpsilon)
5808 inverse_slope.p=dx.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5810 inverse_slope.p=dx.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5815 inverse_slope.p=(-1.0/slope.p);
5817 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5818 miterlimit=(MagickRealType) (draw_info->miterlimit*draw_info->miterlimit*
5820 if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse))
5821 TraceSquareLinecap(polygon_primitive,number_vertices,mid);
5822 offset.x=sqrt((double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0)));
5823 offset.y=(double) (offset.x*inverse_slope.p);
5824 if ((dy.p*offset.x-dx.p*offset.y) > 0.0)
5826 box_p[0].x=polygon_primitive[0].point.x-offset.x;
5827 box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p;
5828 box_p[1].x=polygon_primitive[n].point.x-offset.x;
5829 box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p;
5830 box_q[0].x=polygon_primitive[0].point.x+offset.x;
5831 box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p;
5832 box_q[1].x=polygon_primitive[n].point.x+offset.x;
5833 box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p;
5837 box_p[0].x=polygon_primitive[0].point.x+offset.x;
5838 box_p[0].y=polygon_primitive[0].point.y+offset.y;
5839 box_p[1].x=polygon_primitive[n].point.x+offset.x;
5840 box_p[1].y=polygon_primitive[n].point.y+offset.y;
5841 box_q[0].x=polygon_primitive[0].point.x-offset.x;
5842 box_q[0].y=polygon_primitive[0].point.y-offset.y;
5843 box_q[1].x=polygon_primitive[n].point.x-offset.x;
5844 box_q[1].y=polygon_primitive[n].point.y-offset.y;
5847 Create strokes for the line join attribute: bevel, miter, round.
5851 path_q[p++]=box_q[0];
5852 path_p[q++]=box_p[0];
5853 for (i=(long) n+1; i < (long) number_vertices; i++)
5856 Compute the slope for this line segment, q.
5858 dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x;
5859 dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y;
5860 dot_product=dx.q*dx.q+dy.q*dy.q;
5861 if (dot_product < 0.25)
5864 inverse_slope.q=0.0;
5865 if (fabs(dx.q) < MagickEpsilon)
5868 slope.q=dy.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5870 slope.q=dy.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5873 if (fabs(dy.q) <= MagickEpsilon)
5876 inverse_slope.q=dx.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5878 inverse_slope.q=dx.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5883 inverse_slope.q=(-1.0/slope.q);
5885 offset.x=sqrt((double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0)));
5886 offset.y=(double) (offset.x*inverse_slope.q);
5887 dot_product=dy.q*offset.x-dx.q*offset.y;
5888 if (dot_product > 0.0)
5890 box_p[2].x=polygon_primitive[n].point.x-offset.x;
5891 box_p[2].y=polygon_primitive[n].point.y-offset.y;
5892 box_p[3].x=polygon_primitive[i].point.x-offset.x;
5893 box_p[3].y=polygon_primitive[i].point.y-offset.y;
5894 box_q[2].x=polygon_primitive[n].point.x+offset.x;
5895 box_q[2].y=polygon_primitive[n].point.y+offset.y;
5896 box_q[3].x=polygon_primitive[i].point.x+offset.x;
5897 box_q[3].y=polygon_primitive[i].point.y+offset.y;
5901 box_p[2].x=polygon_primitive[n].point.x+offset.x;
5902 box_p[2].y=polygon_primitive[n].point.y+offset.y;
5903 box_p[3].x=polygon_primitive[i].point.x+offset.x;
5904 box_p[3].y=polygon_primitive[i].point.y+offset.y;
5905 box_q[2].x=polygon_primitive[n].point.x-offset.x;
5906 box_q[2].y=polygon_primitive[n].point.y-offset.y;
5907 box_q[3].x=polygon_primitive[i].point.x-offset.x;
5908 box_q[3].y=polygon_primitive[i].point.y-offset.y;
5910 if (fabs((double) (slope.p-slope.q)) <= MagickEpsilon)
5917 box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+
5918 box_p[3].y)/(slope.p-slope.q));
5919 box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y);
5920 box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+
5921 box_q[3].y)/(slope.p-slope.q));
5922 box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y);
5924 if (q >= (long) (max_strokes-6*BezierQuantum-360))
5926 max_strokes+=6*BezierQuantum+360;
5927 path_p=(PointInfo *) ResizeQuantumMemory(path_p,(size_t) max_strokes,
5929 path_q=(PointInfo *) ResizeQuantumMemory(path_q,(size_t) max_strokes,
5931 if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL))
5933 polygon_primitive=(PrimitiveInfo *)
5934 RelinquishMagickMemory(polygon_primitive);
5935 return((PrimitiveInfo *) NULL);
5938 dot_product=dx.q*dy.p-dx.p*dy.q;
5939 if (dot_product <= 0.0)
5940 switch (draw_info->linejoin)
5944 path_q[q++]=box_q[1];
5945 path_q[q++]=box_q[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)
5949 path_p[p++]=box_p[4];
5952 path_p[p++]=box_p[1];
5953 path_p[p++]=box_p[2];
5959 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5960 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5961 if (dot_product <= miterlimit)
5963 path_q[q++]=box_q[4];
5964 path_p[p++]=box_p[4];
5968 path_q[q++]=box_q[1];
5969 path_q[q++]=box_q[2];
5970 path_p[p++]=box_p[1];
5971 path_p[p++]=box_p[2];
5977 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5978 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5979 if (dot_product <= miterlimit)
5980 path_p[p++]=box_p[4];
5983 path_p[p++]=box_p[1];
5984 path_p[p++]=box_p[2];
5986 center=polygon_primitive[n].point;
5987 theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x);
5988 theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x);
5989 if (theta.q < theta.p)
5990 theta.q+=(MagickRealType) (2.0*MagickPI);
5991 arc_segments=(unsigned long) ceil((double) ((theta.q-theta.p)/
5992 (2.0*sqrt((double) (1.0/mid)))));
5993 path_q[q].x=box_q[1].x;
5994 path_q[q].y=box_q[1].y;
5996 for (j=1; j < (long) arc_segments; j++)
5998 delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments);
5999 path_q[q].x=(double) (center.x+mid*cos(fmod((double)
6000 (theta.p+delta_theta),DegreesToRadians(360.0))));
6001 path_q[q].y=(double) (center.y+mid*sin(fmod((double)
6002 (theta.p+delta_theta),DegreesToRadians(360.0))));
6005 path_q[q++]=box_q[2];
6012 switch (draw_info->linejoin)
6016 path_p[p++]=box_p[1];
6017 path_p[p++]=box_p[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)
6021 path_q[q++]=box_q[4];
6024 path_q[q++]=box_q[1];
6025 path_q[q++]=box_q[2];
6031 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6032 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6033 if (dot_product <= miterlimit)
6035 path_q[q++]=box_q[4];
6036 path_p[p++]=box_p[4];
6040 path_q[q++]=box_q[1];
6041 path_q[q++]=box_q[2];
6042 path_p[p++]=box_p[1];
6043 path_p[p++]=box_p[2];
6049 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6050 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6051 if (dot_product <= miterlimit)
6052 path_q[q++]=box_q[4];
6055 path_q[q++]=box_q[1];
6056 path_q[q++]=box_q[2];
6058 center=polygon_primitive[n].point;
6059 theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x);
6060 theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x);
6061 if (theta.p < theta.q)
6062 theta.p+=(MagickRealType) (2.0*MagickPI);
6063 arc_segments=(unsigned long) ceil((double) ((theta.p-theta.q)/
6064 (2.0*sqrt((double) (1.0/mid)))));
6065 path_p[p++]=box_p[1];
6066 for (j=1; j < (long) arc_segments; j++)
6068 delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments);
6069 path_p[p].x=(double) (center.x+mid*cos(fmod((double)
6070 (theta.p+delta_theta),DegreesToRadians(360.0))));
6071 path_p[p].y=(double) (center.y+mid*sin(fmod((double)
6072 (theta.p+delta_theta),DegreesToRadians(360.0))));
6075 path_p[p++]=box_p[2];
6082 inverse_slope.p=inverse_slope.q;
6091 path_p[p++]=box_p[1];
6092 path_q[q++]=box_q[1];
6094 Trace stroked polygon.
6096 stroke_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
6097 (p+q+2UL*closed_path+2UL),sizeof(*stroke_polygon));
6098 if (stroke_polygon != (PrimitiveInfo *) NULL)
6100 for (i=0; i < (long) p; i++)
6102 stroke_polygon[i]=polygon_primitive[0];
6103 stroke_polygon[i].point=path_p[i];
6105 if (closed_path != MagickFalse)
6107 stroke_polygon[i]=polygon_primitive[0];
6108 stroke_polygon[i].point=stroke_polygon[0].point;
6111 for ( ; i < (long) (p+q+closed_path); i++)
6113 stroke_polygon[i]=polygon_primitive[0];
6114 stroke_polygon[i].point=path_q[p+q+closed_path-(i+1)];
6116 if (closed_path != MagickFalse)
6118 stroke_polygon[i]=polygon_primitive[0];
6119 stroke_polygon[i].point=stroke_polygon[p+closed_path].point;
6122 stroke_polygon[i]=polygon_primitive[0];
6123 stroke_polygon[i].point=stroke_polygon[0].point;
6125 stroke_polygon[i].primitive=UndefinedPrimitive;
6126 stroke_polygon[0].coordinates=(unsigned long) (p+q+2*closed_path+1);
6128 path_p=(PointInfo *) RelinquishMagickMemory(path_p);
6129 path_q=(PointInfo *) RelinquishMagickMemory(path_q);
6130 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive);
6131 return(stroke_polygon);