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 if (draw_info->density != (char *) NULL)
294 (void) CloneString(&clone_info->density,draw_info->density);
295 clone_info->align=draw_info->align;
296 clone_info->undercolor=draw_info->undercolor;
297 clone_info->border_color=draw_info->border_color;
298 if (draw_info->server_name != (char *) NULL)
299 (void) CloneString(&clone_info->server_name,draw_info->server_name);
300 if (draw_info->dash_pattern != (double *) NULL)
305 for (x=0; draw_info->dash_pattern[x] != 0.0; x++) ;
306 clone_info->dash_pattern=(double *) AcquireQuantumMemory((size_t) x+1UL,
307 sizeof(*clone_info->dash_pattern));
308 if (clone_info->dash_pattern == (double *) NULL)
309 ThrowFatalException(ResourceLimitFatalError,
310 "UnableToAllocateDashPattern");
311 (void) CopyMagickMemory(clone_info->dash_pattern,draw_info->dash_pattern,
312 (size_t) (x+1)*sizeof(*clone_info->dash_pattern));
314 clone_info->gradient=draw_info->gradient;
315 if (draw_info->gradient.stops != (StopInfo *) NULL)
320 number_stops=clone_info->gradient.number_stops;
321 clone_info->gradient.stops=(StopInfo *) AcquireQuantumMemory((size_t)
322 number_stops,sizeof(*clone_info->gradient.stops));
323 if (clone_info->gradient.stops == (StopInfo *) NULL)
324 ThrowFatalException(ResourceLimitFatalError,
325 "UnableToAllocateDashPattern");
326 (void) CopyMagickMemory(clone_info->gradient.stops,
327 draw_info->gradient.stops,(size_t) number_stops*
328 sizeof(*clone_info->gradient.stops));
330 if (draw_info->clip_mask != (char *) NULL)
331 (void) CloneString(&clone_info->clip_mask,draw_info->clip_mask);
332 clone_info->bounds=draw_info->bounds;
333 clone_info->clip_units=draw_info->clip_units;
334 clone_info->render=draw_info->render;
335 clone_info->opacity=draw_info->opacity;
336 clone_info->element_reference=draw_info->element_reference;
337 clone_info->debug=IsEventLogging();
342 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
346 + C o n v e r t P a t h T o P o l y g o n %
350 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
352 % ConvertPathToPolygon() converts a path to the more efficient sorted
355 % The format of the ConvertPathToPolygon method is:
357 % PolygonInfo *ConvertPathToPolygon(const DrawInfo *draw_info,
358 % const PathInfo *path_info)
360 % A description of each parameter follows:
362 % o Method ConvertPathToPolygon returns the path in a more efficient sorted
363 % rendering form of type PolygonInfo.
365 % o draw_info: Specifies a pointer to an DrawInfo structure.
367 % o path_info: Specifies a pointer to an PathInfo structure.
372 #if defined(__cplusplus) || defined(c_plusplus)
376 static int CompareEdges(const void *x,const void *y)
378 register const EdgeInfo
385 p=(const EdgeInfo *) x;
386 q=(const EdgeInfo *) y;
387 if ((p->points[0].y-MagickEpsilon) > q->points[0].y)
389 if ((p->points[0].y+MagickEpsilon) < q->points[0].y)
391 if ((p->points[0].x-MagickEpsilon) > q->points[0].x)
393 if ((p->points[0].x+MagickEpsilon) < q->points[0].x)
395 if (((p->points[1].x-p->points[0].x)*(q->points[1].y-q->points[0].y)-
396 (p->points[1].y-p->points[0].y)*(q->points[1].x-q->points[0].x)) > 0.0)
401 #if defined(__cplusplus) || defined(c_plusplus)
405 static void LogPolygonInfo(const PolygonInfo *polygon_info)
414 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin active-edge");
415 p=polygon_info->edges;
416 for (i=0; i < (long) polygon_info->number_edges; i++)
418 (void) LogMagickEvent(DrawEvent,GetMagickModule()," edge %lu:",i);
419 (void) LogMagickEvent(DrawEvent,GetMagickModule()," direction: %s",
420 p->direction != MagickFalse ? "down" : "up");
421 (void) LogMagickEvent(DrawEvent,GetMagickModule()," ghostline: %s",
422 p->ghostline != MagickFalse ? "transparent" : "opaque");
423 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
424 " bounds: %g,%g - %g,%g",p->bounds.x1,p->bounds.y1,p->bounds.x2,
426 for (j=0; j < (long) p->number_points; j++)
427 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %g,%g",
428 p->points[j].x,p->points[j].y);
431 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end active-edge");
434 static void ReversePoints(PointInfo *points,const unsigned long number_points)
442 for (i=0; i < (long) (number_points >> 1); i++)
445 points[i]=points[number_points-(i+1)];
446 points[number_points-(i+1)]=point;
450 static PolygonInfo *ConvertPathToPolygon(
451 const DrawInfo *magick_unused(draw_info),const PathInfo *path_info)
480 Convert a path to the more efficient sorted rendering form.
482 polygon_info=(PolygonInfo *) AcquireAlignedMemory(1,sizeof(*polygon_info));
483 if (polygon_info == (PolygonInfo *) NULL)
484 return((PolygonInfo *) NULL);
486 polygon_info->edges=(EdgeInfo *) AcquireQuantumMemory((size_t) number_edges,
487 sizeof(*polygon_info->edges));
488 if (polygon_info->edges == (EdgeInfo *) NULL)
489 return((PolygonInfo *) NULL);
492 ghostline=MagickFalse;
495 points=(PointInfo *) NULL;
496 (void) ResetMagickMemory(&point,0,sizeof(point));
497 (void) ResetMagickMemory(&bounds,0,sizeof(bounds));
498 for (i=0; path_info[i].code != EndCode; i++)
500 if ((path_info[i].code == MoveToCode) || (path_info[i].code == OpenCode) ||
501 (path_info[i].code == GhostlineCode))
506 if ((points != (PointInfo *) NULL) && (n >= 2))
508 if (edge == number_edges)
511 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
512 polygon_info->edges,(size_t) number_edges,
513 sizeof(*polygon_info->edges));
514 if (polygon_info->edges == (EdgeInfo *) NULL)
515 return((PolygonInfo *) NULL);
517 polygon_info->edges[edge].number_points=(unsigned long) n;
518 polygon_info->edges[edge].scanline=(-1.0);
519 polygon_info->edges[edge].highwater=0;
520 polygon_info->edges[edge].ghostline=ghostline;
521 polygon_info->edges[edge].direction=(long) (direction > 0);
523 ReversePoints(points,(unsigned long) n);
524 polygon_info->edges[edge].points=points;
525 polygon_info->edges[edge].bounds=bounds;
526 polygon_info->edges[edge].bounds.y1=points[0].y;
527 polygon_info->edges[edge].bounds.y2=points[n-1].y;
528 points=(PointInfo *) NULL;
529 ghostline=MagickFalse;
532 if (points == (PointInfo *) NULL)
535 points=(PointInfo *) AcquireQuantumMemory((size_t) number_points,
537 if (points == (PointInfo *) NULL)
538 return((PolygonInfo *) NULL);
540 ghostline=path_info[i].code == GhostlineCode ? MagickTrue : MagickFalse;
541 point=path_info[i].point;
552 next_direction=((path_info[i].point.y > point.y) ||
553 ((path_info[i].point.y == point.y) &&
554 (path_info[i].point.x > point.x))) ? 1 : -1;
555 if ((direction != 0) && (direction != next_direction))
561 if (edge == number_edges)
564 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
565 polygon_info->edges,(size_t) number_edges,
566 sizeof(*polygon_info->edges));
567 if (polygon_info->edges == (EdgeInfo *) NULL)
568 return((PolygonInfo *) NULL);
570 polygon_info->edges[edge].number_points=(unsigned long) n;
571 polygon_info->edges[edge].scanline=(-1.0);
572 polygon_info->edges[edge].highwater=0;
573 polygon_info->edges[edge].ghostline=ghostline;
574 polygon_info->edges[edge].direction=(long) (direction > 0);
576 ReversePoints(points,(unsigned long) n);
577 polygon_info->edges[edge].points=points;
578 polygon_info->edges[edge].bounds=bounds;
579 polygon_info->edges[edge].bounds.y1=points[0].y;
580 polygon_info->edges[edge].bounds.y2=points[n-1].y;
582 points=(PointInfo *) AcquireQuantumMemory((size_t) number_points,
584 if (points == (PointInfo *) NULL)
585 return((PolygonInfo *) NULL);
587 ghostline=MagickFalse;
593 direction=next_direction;
594 if (points == (PointInfo *) NULL)
596 if (n == (long) number_points)
599 points=(PointInfo *) ResizeQuantumMemory(points,(size_t) number_points,
601 if (points == (PointInfo *) NULL)
602 return((PolygonInfo *) NULL);
604 point=path_info[i].point;
606 if (point.x < bounds.x1)
608 if (point.x > bounds.x2)
612 if (points != (PointInfo *) NULL)
615 points=(PointInfo *) RelinquishMagickMemory(points);
618 if (edge == number_edges)
621 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
622 polygon_info->edges,(size_t) number_edges,
623 sizeof(*polygon_info->edges));
624 if (polygon_info->edges == (EdgeInfo *) NULL)
625 return((PolygonInfo *) NULL);
627 polygon_info->edges[edge].number_points=(unsigned long) n;
628 polygon_info->edges[edge].scanline=(-1.0);
629 polygon_info->edges[edge].highwater=0;
630 polygon_info->edges[edge].ghostline=ghostline;
631 polygon_info->edges[edge].direction=(long) (direction > 0);
633 ReversePoints(points,(unsigned long) n);
634 polygon_info->edges[edge].points=points;
635 polygon_info->edges[edge].bounds=bounds;
636 polygon_info->edges[edge].bounds.y1=points[0].y;
637 polygon_info->edges[edge].bounds.y2=points[n-1].y;
638 ghostline=MagickFalse;
642 polygon_info->number_edges=edge;
643 qsort(polygon_info->edges,(size_t) polygon_info->number_edges,
644 sizeof(*polygon_info->edges),CompareEdges);
645 if (IsEventLogging() != MagickFalse)
646 LogPolygonInfo(polygon_info);
647 return(polygon_info);
651 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
655 + C o n v e r t P r i m i t i v e T o P a t h %
659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
661 % ConvertPrimitiveToPath() converts a PrimitiveInfo structure into a vector
664 % The format of the ConvertPrimitiveToPath method is:
666 % PathInfo *ConvertPrimitiveToPath(const DrawInfo *draw_info,
667 % const PrimitiveInfo *primitive_info)
669 % A description of each parameter follows:
671 % o Method ConvertPrimitiveToPath returns a vector path structure of type
674 % o draw_info: a structure of type DrawInfo.
676 % o primitive_info: Specifies a pointer to an PrimitiveInfo structure.
681 static void LogPathInfo(const PathInfo *path_info)
683 register const PathInfo
686 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin vector-path");
687 for (p=path_info; p->code != EndCode; p++)
688 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
689 " %g,%g %s",p->point.x,p->point.y,p->code == GhostlineCode ?
690 "moveto ghostline" : p->code == OpenCode ? "moveto open" :
691 p->code == MoveToCode ? "moveto" : p->code == LineToCode ? "lineto" :
693 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end vector-path");
696 static PathInfo *ConvertPrimitiveToPath(
697 const DrawInfo *magick_unused(draw_info),const PrimitiveInfo *primitive_info)
718 Converts a PrimitiveInfo structure into a vector path structure.
720 switch (primitive_info->primitive)
727 return((PathInfo *) NULL);
731 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
732 path_info=(PathInfo *) AcquireQuantumMemory((size_t) (2UL*i+3UL),
734 if (path_info == (PathInfo *) NULL)
735 return((PathInfo *) NULL);
743 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
746 if (coordinates <= 0)
748 coordinates=(long) primitive_info[i].coordinates;
749 p=primitive_info[i].point;
755 Eliminate duplicate points.
757 if ((i == 0) || (fabs(q.x-primitive_info[i].point.x) > MagickEpsilon) ||
758 (fabs(q.y-primitive_info[i].point.y) > MagickEpsilon))
760 path_info[n].code=code;
761 path_info[n].point=primitive_info[i].point;
762 q=primitive_info[i].point;
767 if ((fabs(p.x-primitive_info[i].point.x) <= MagickEpsilon) &&
768 (fabs(p.y-primitive_info[i].point.y) <= MagickEpsilon))
771 Mark the p point as open if it does not match the q.
773 path_info[start].code=OpenCode;
774 path_info[n].code=GhostlineCode;
775 path_info[n].point=primitive_info[i].point;
777 path_info[n].code=LineToCode;
778 path_info[n].point=p;
781 path_info[n].code=EndCode;
782 path_info[n].point.x=0.0;
783 path_info[n].point.y=0.0;
784 if (IsEventLogging() != MagickFalse)
785 LogPathInfo(path_info);
790 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
794 % D e s t r o y D r a w I n f o %
798 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
800 % DestroyDrawInfo() deallocates memory associated with an DrawInfo
803 % The format of the DestroyDrawInfo method is:
805 % DrawInfo *DestroyDrawInfo(DrawInfo *draw_info)
807 % A description of each parameter follows:
809 % o draw_info: the draw info.
812 MagickExport DrawInfo *DestroyDrawInfo(DrawInfo *draw_info)
814 if (draw_info->debug != MagickFalse)
815 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
816 assert(draw_info != (DrawInfo *) NULL);
817 assert(draw_info->signature == MagickSignature);
818 if (draw_info->primitive != (char *) NULL)
819 draw_info->primitive=DestroyString(draw_info->primitive);
820 if (draw_info->text != (char *) NULL)
821 draw_info->text=DestroyString(draw_info->text);
822 if (draw_info->geometry != (char *) NULL)
823 draw_info->geometry=DestroyString(draw_info->geometry);
824 if (draw_info->tile != (Image *) NULL)
825 draw_info->tile=DestroyImage(draw_info->tile);
826 if (draw_info->fill_pattern != (Image *) NULL)
827 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
828 if (draw_info->stroke_pattern != (Image *) NULL)
829 draw_info->stroke_pattern=DestroyImage(draw_info->stroke_pattern);
830 if (draw_info->font != (char *) NULL)
831 draw_info->font=DestroyString(draw_info->font);
832 if (draw_info->metrics != (char *) NULL)
833 draw_info->metrics=DestroyString(draw_info->metrics);
834 if (draw_info->family != (char *) NULL)
835 draw_info->family=DestroyString(draw_info->family);
836 if (draw_info->encoding != (char *) NULL)
837 draw_info->encoding=DestroyString(draw_info->encoding);
838 if (draw_info->density != (char *) NULL)
839 draw_info->density=DestroyString(draw_info->density);
840 if (draw_info->server_name != (char *) NULL)
841 draw_info->server_name=(char *)
842 RelinquishMagickMemory(draw_info->server_name);
843 if (draw_info->dash_pattern != (double *) NULL)
844 draw_info->dash_pattern=(double *) RelinquishMagickMemory(
845 draw_info->dash_pattern);
846 if (draw_info->gradient.stops != (StopInfo *) NULL)
847 draw_info->gradient.stops=(StopInfo *) RelinquishMagickMemory(
848 draw_info->gradient.stops);
849 if (draw_info->clip_mask != (char *) NULL)
850 draw_info->clip_mask=DestroyString(draw_info->clip_mask);
851 draw_info->signature=(~MagickSignature);
852 draw_info=(DrawInfo *) RelinquishMagickMemory(draw_info);
857 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
861 + D e s t r o y E d g e %
865 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
867 % DestroyEdge() destroys the specified polygon edge.
869 % The format of the DestroyEdge method is:
871 % long DestroyEdge(PolygonInfo *polygon_info,const int edge)
873 % A description of each parameter follows:
875 % o polygon_info: Specifies a pointer to an PolygonInfo structure.
877 % o edge: the polygon edge number to destroy.
880 static unsigned long DestroyEdge(PolygonInfo *polygon_info,
881 const unsigned long edge)
883 assert(edge < polygon_info->number_edges);
884 polygon_info->edges[edge].points=(PointInfo *) RelinquishMagickMemory(
885 polygon_info->edges[edge].points);
886 polygon_info->number_edges--;
887 if (edge < polygon_info->number_edges)
888 (void) CopyMagickMemory(polygon_info->edges+edge,polygon_info->edges+edge+1,
889 (size_t) (polygon_info->number_edges-edge)*sizeof(*polygon_info->edges));
890 return(polygon_info->number_edges);
894 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
898 + D e s t r o y P o l y g o n I n f o %
902 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
904 % DestroyPolygonInfo() destroys the PolygonInfo data structure.
906 % The format of the DestroyPolygonInfo method is:
908 % PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info)
910 % A description of each parameter follows:
912 % o polygon_info: Specifies a pointer to an PolygonInfo structure.
915 static PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info)
920 for (i=0; i < (long) polygon_info->number_edges; i++)
921 polygon_info->edges[i].points=(PointInfo *)
922 RelinquishMagickMemory(polygon_info->edges[i].points);
923 polygon_info->edges=(EdgeInfo *) RelinquishMagickMemory(polygon_info->edges);
924 return((PolygonInfo *) RelinquishMagickMemory(polygon_info));
928 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
932 % D r a w A f f i n e I m a g e %
936 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
938 % DrawAffineImage() composites the source over the destination image as
939 % dictated by the affine transform.
941 % The format of the DrawAffineImage method is:
943 % MagickBooleanType DrawAffineImage(Image *image,const Image *source,
944 % const AffineMatrix *affine)
946 % A description of each parameter follows:
948 % o image: the image.
950 % o source: the source image.
952 % o affine: the affine transform.
955 static SegmentInfo AffineEdge(const Image *image,const AffineMatrix *affine,
956 const double y,const SegmentInfo *edge)
969 Determine left and right edges.
971 inverse_edge.x1=edge->x1;
972 inverse_edge.y1=edge->y1;
973 inverse_edge.x2=edge->x2;
974 inverse_edge.y2=edge->y2;
975 z=affine->ry*y+affine->tx;
976 if (affine->sx > MagickEpsilon)
978 intercept=(-z/affine->sx);
979 x=intercept+MagickEpsilon;
980 if (x > inverse_edge.x1)
982 intercept=(-z+(double) image->columns)/affine->sx;
983 x=intercept-MagickEpsilon;
984 if (x < inverse_edge.x2)
988 if (affine->sx < -MagickEpsilon)
990 intercept=(-z+(double) image->columns)/affine->sx;
991 x=intercept+MagickEpsilon;
992 if (x > inverse_edge.x1)
994 intercept=(-z/affine->sx);
995 x=intercept-MagickEpsilon;
996 if (x < inverse_edge.x2)
1000 if ((z < 0.0) || ((unsigned long) (z+0.5) >= image->columns))
1002 inverse_edge.x2=edge->x1;
1003 return(inverse_edge);
1006 Determine top and bottom edges.
1008 z=affine->sy*y+affine->ty;
1009 if (affine->rx > MagickEpsilon)
1011 intercept=(-z/affine->rx);
1012 x=intercept+MagickEpsilon;
1013 if (x > inverse_edge.x1)
1015 intercept=(-z+(double) image->rows)/affine->rx;
1016 x=intercept-MagickEpsilon;
1017 if (x < inverse_edge.x2)
1021 if (affine->rx < -MagickEpsilon)
1023 intercept=(-z+(double) image->rows)/affine->rx;
1024 x=intercept+MagickEpsilon;
1025 if (x > inverse_edge.x1)
1027 intercept=(-z/affine->rx);
1028 x=intercept-MagickEpsilon;
1029 if (x < inverse_edge.x2)
1033 if ((z < 0.0) || ((unsigned long) (z+0.5) >= image->rows))
1035 inverse_edge.x2=edge->x2;
1036 return(inverse_edge);
1038 return(inverse_edge);
1041 static AffineMatrix InverseAffineMatrix(const AffineMatrix *affine)
1049 determinant=1.0/(affine->sx*affine->sy-affine->rx*affine->ry);
1050 inverse_affine.sx=determinant*affine->sy;
1051 inverse_affine.rx=determinant*(-affine->rx);
1052 inverse_affine.ry=determinant*(-affine->ry);
1053 inverse_affine.sy=determinant*affine->sx;
1054 inverse_affine.tx=(-affine->tx)*inverse_affine.sx-affine->ty*
1056 inverse_affine.ty=(-affine->tx)*inverse_affine.rx-affine->ty*
1058 return(inverse_affine);
1061 static inline long MagickAbsoluteValue(const long x)
1068 static inline double MagickMax(const double x,const double y)
1075 static inline double MagickMin(const double x,const double y)
1082 MagickExport MagickBooleanType DrawAffineImage(Image *image,
1083 const Image *source,const AffineMatrix *affine)
1114 **restrict resample_filter;
1120 Determine bounding box.
1122 assert(image != (Image *) NULL);
1123 assert(image->signature == MagickSignature);
1124 if (image->debug != MagickFalse)
1125 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1126 assert(source != (const Image *) NULL);
1127 assert(source->signature == MagickSignature);
1128 assert(affine != (AffineMatrix *) NULL);
1131 extent[1].x=(double) source->columns-1.0;
1133 extent[2].x=(double) source->columns-1.0;
1134 extent[2].y=(double) source->rows-1.0;
1136 extent[3].y=(double) source->rows-1.0;
1137 for (i=0; i < 4; i++)
1140 extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx;
1141 extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty;
1145 for (i=1; i < 4; i++)
1147 if (min.x > extent[i].x)
1149 if (min.y > extent[i].y)
1151 if (max.x < extent[i].x)
1153 if (max.y < extent[i].y)
1157 Affine transform image.
1159 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
1160 return(MagickFalse);
1162 edge.x1=MagickMax(min.x,0.0);
1163 edge.y1=MagickMax(min.y,0.0);
1164 edge.x2=MagickMin(max.x,(double) image->columns-1.0);
1165 edge.y2=MagickMin(max.y,(double) image->rows-1.0);
1166 inverse_affine=InverseAffineMatrix(affine);
1167 GetMagickPixelPacket(image,&zero);
1168 exception=(&image->exception);
1169 resample_filter=AcquireResampleFilterThreadSet(source,MagickTrue,exception);
1170 image_view=AcquireCacheView(image);
1171 source_view=AcquireCacheView(source);
1172 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1173 #pragma omp parallel for schedule(dynamic,4) shared(status)
1175 for (y=(long) (edge.y1+0.5); y <= (long) (edge.y2+0.5); y++)
1187 register IndexPacket
1194 register PixelPacket
1200 inverse_edge=AffineEdge(source,&inverse_affine,(double) y,&edge);
1201 if (inverse_edge.x2 < inverse_edge.x1)
1203 q=GetCacheViewAuthenticPixels(image_view,(long) (inverse_edge.x1+0.5),y,
1204 (unsigned long) ((long) (inverse_edge.x2+0.5)-(long) (inverse_edge.x1+
1205 0.5)+1),1,exception);
1206 if (q == (PixelPacket *) NULL)
1208 id=GetOpenMPThreadId();
1209 indexes=GetCacheViewAuthenticIndexQueue(image_view);
1213 for (x=(long) (inverse_edge.x1+0.5); x <= (long) (inverse_edge.x2+0.5); x++)
1215 point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+
1217 point.y=(double) x*inverse_affine.rx+y*inverse_affine.sy+
1219 (void) ResamplePixelColor(resample_filter[id],point.x,point.y,&pixel);
1220 SetMagickPixelPacket(image,q,indexes+x_offset,&composite);
1221 MagickPixelCompositeOver(&pixel,pixel.opacity,&composite,
1222 composite.opacity,&composite);
1223 SetPixelPacket(image,&composite,q,indexes+x_offset);
1227 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1230 resample_filter=DestroyResampleFilterThreadSet(resample_filter);
1231 source_view=DestroyCacheView(source_view);
1232 image_view=DestroyCacheView(image_view);
1237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1241 + D r a w B o u n d i n g R e c t a n g l e s %
1245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1247 % DrawBoundingRectangles() draws the bounding rectangles on the image. This
1248 % is only useful for developers debugging the rendering algorithm.
1250 % The format of the DrawBoundingRectangles method is:
1252 % void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info,
1253 % PolygonInfo *polygon_info)
1255 % A description of each parameter follows:
1257 % o image: the image.
1259 % o draw_info: the draw info.
1261 % o polygon_info: Specifies a pointer to a PolygonInfo structure.
1264 static void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info,
1265 const PolygonInfo *polygon_info)
1290 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1291 (void) QueryColorDatabase("#0000",&clone_info->fill,&image->exception);
1292 resolution.x=DefaultResolution;
1293 resolution.y=DefaultResolution;
1294 if (clone_info->density != (char *) NULL)
1302 flags=ParseGeometry(clone_info->density,&geometry_info);
1303 resolution.x=geometry_info.rho;
1304 resolution.y=geometry_info.sigma;
1305 if ((flags & SigmaValue) == MagickFalse)
1306 resolution.y=resolution.x;
1308 mid=(resolution.x/72.0)*ExpandAffine(&clone_info->affine)*
1309 clone_info->stroke_width/2.0;
1314 if (polygon_info != (PolygonInfo *) NULL)
1316 bounds=polygon_info->edges[0].bounds;
1317 for (i=1; i < (long) polygon_info->number_edges; i++)
1319 if (polygon_info->edges[i].bounds.x1 < (double) bounds.x1)
1320 bounds.x1=polygon_info->edges[i].bounds.x1;
1321 if (polygon_info->edges[i].bounds.y1 < (double) bounds.y1)
1322 bounds.y1=polygon_info->edges[i].bounds.y1;
1323 if (polygon_info->edges[i].bounds.x2 > (double) bounds.x2)
1324 bounds.x2=polygon_info->edges[i].bounds.x2;
1325 if (polygon_info->edges[i].bounds.y2 > (double) bounds.y2)
1326 bounds.y2=polygon_info->edges[i].bounds.y2;
1329 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double)
1330 image->columns ? (double) image->columns-1 : bounds.x1;
1332 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double)
1333 image->rows ? (double) image->rows-1 : bounds.y1;
1335 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double)
1336 image->columns ? (double) image->columns-1 : bounds.x2;
1338 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double)
1339 image->rows ? (double) image->rows-1 : bounds.y2;
1340 for (i=0; i < (long) polygon_info->number_edges; i++)
1342 if (polygon_info->edges[i].direction != 0)
1343 (void) QueryColorDatabase("red",&clone_info->stroke,
1346 (void) QueryColorDatabase("green",&clone_info->stroke,
1348 start.x=(double) (polygon_info->edges[i].bounds.x1-mid);
1349 start.y=(double) (polygon_info->edges[i].bounds.y1-mid);
1350 end.x=(double) (polygon_info->edges[i].bounds.x2+mid);
1351 end.y=(double) (polygon_info->edges[i].bounds.y2+mid);
1352 primitive_info[0].primitive=RectanglePrimitive;
1353 TraceRectangle(primitive_info,start,end);
1354 primitive_info[0].method=ReplaceMethod;
1355 coordinates=(long) primitive_info[0].coordinates;
1356 primitive_info[coordinates].primitive=UndefinedPrimitive;
1357 (void) DrawPrimitive(image,clone_info,primitive_info);
1360 (void) QueryColorDatabase("blue",&clone_info->stroke,&image->exception);
1361 start.x=(double) (bounds.x1-mid);
1362 start.y=(double) (bounds.y1-mid);
1363 end.x=(double) (bounds.x2+mid);
1364 end.y=(double) (bounds.y2+mid);
1365 primitive_info[0].primitive=RectanglePrimitive;
1366 TraceRectangle(primitive_info,start,end);
1367 primitive_info[0].method=ReplaceMethod;
1368 coordinates=(long) primitive_info[0].coordinates;
1369 primitive_info[coordinates].primitive=UndefinedPrimitive;
1370 (void) DrawPrimitive(image,clone_info,primitive_info);
1371 clone_info=DestroyDrawInfo(clone_info);
1375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1379 % D r a w C l i p P a t h %
1383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1385 % DrawClipPath() draws the clip path on the image mask.
1387 % The format of the DrawClipPath method is:
1389 % MagickBooleanType DrawClipPath(Image *image,const DrawInfo *draw_info,
1392 % A description of each parameter follows:
1394 % o image: the image.
1396 % o draw_info: the draw info.
1398 % o name: the name of the clip path.
1401 MagickExport MagickBooleanType DrawClipPath(Image *image,
1402 const DrawInfo *draw_info,const char *name)
1405 clip_mask[MaxTextExtent];
1416 assert(image != (Image *) NULL);
1417 assert(image->signature == MagickSignature);
1418 if (image->debug != MagickFalse)
1419 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1420 assert(draw_info != (const DrawInfo *) NULL);
1421 (void) FormatMagickString(clip_mask,MaxTextExtent,"%s",name);
1422 value=GetImageArtifact(image,clip_mask);
1423 if (value == (const char *) NULL)
1424 return(MagickFalse);
1425 if (image->clip_mask == (Image *) NULL)
1430 clip_mask=CloneImage(image,image->columns,image->rows,MagickTrue,
1432 if (clip_mask == (Image *) NULL)
1433 return(MagickFalse);
1434 (void) SetImageClipMask(image,clip_mask);
1435 clip_mask=DestroyImage(clip_mask);
1437 (void) QueryColorDatabase("#00000000",&image->clip_mask->background_color,
1439 image->clip_mask->background_color.opacity=(Quantum) TransparentOpacity;
1440 (void) SetImageBackgroundColor(image->clip_mask);
1441 if (image->debug != MagickFalse)
1442 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"\nbegin clip-path %s",
1443 draw_info->clip_mask);
1444 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1445 (void) CloneString(&clone_info->primitive,value);
1446 (void) QueryColorDatabase("#ffffff",&clone_info->fill,&image->exception);
1447 clone_info->clip_mask=(char *) NULL;
1448 status=DrawImage(image->clip_mask,clone_info);
1449 status|=NegateImage(image->clip_mask,MagickFalse);
1450 clone_info=DestroyDrawInfo(clone_info);
1451 if (image->debug != MagickFalse)
1452 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end clip-path");
1453 return(status != 0 ? MagickTrue : MagickFalse);
1457 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1461 + D r a w D a s h P o l y g o n %
1465 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1467 % DrawDashPolygon() draws a dashed polygon (line, rectangle, ellipse) on the
1468 % image while respecting the dash offset and dash pattern attributes.
1470 % The format of the DrawDashPolygon method is:
1472 % MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info,
1473 % const PrimitiveInfo *primitive_info,Image *image)
1475 % A description of each parameter follows:
1477 % o draw_info: the draw info.
1479 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
1481 % o image: the image.
1485 static MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info,
1486 const PrimitiveInfo *primitive_info,Image *image)
1511 register MagickRealType
1518 assert(draw_info != (const DrawInfo *) NULL);
1519 if (image->debug != MagickFalse)
1520 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-dash");
1521 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1522 clone_info->miterlimit=0;
1523 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
1524 number_vertices=(unsigned long) i;
1525 dash_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
1526 (2UL*number_vertices+1UL),sizeof(*dash_polygon));
1527 if (dash_polygon == (PrimitiveInfo *) NULL)
1528 return(MagickFalse);
1529 dash_polygon[0]=primitive_info[0];
1530 scale=ExpandAffine(&draw_info->affine);
1531 length=scale*(draw_info->dash_pattern[0]-0.5);
1532 offset=draw_info->dash_offset != 0.0 ? scale*draw_info->dash_offset : 0.0;
1534 for (n=0; offset > 0.0; j=0)
1536 if (draw_info->dash_pattern[n] <= 0.0)
1538 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1539 if (offset > length)
1543 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1546 if (offset < length)
1558 for (i=1; i < (long) number_vertices; i++)
1560 dx=primitive_info[i].point.x-primitive_info[i-1].point.x;
1561 dy=primitive_info[i].point.y-primitive_info[i-1].point.y;
1562 maximum_length=hypot((double) dx,dy);
1566 if (draw_info->dash_pattern[n] == 0.0)
1568 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1570 for (total_length=0.0; (total_length+length) < maximum_length; )
1572 total_length+=length;
1573 if ((n & 0x01) != 0)
1575 dash_polygon[0]=primitive_info[0];
1576 dash_polygon[0].point.x=(double) (primitive_info[i-1].point.x+dx*
1577 total_length/maximum_length);
1578 dash_polygon[0].point.y=(double) (primitive_info[i-1].point.y+dy*
1579 total_length/maximum_length);
1584 if ((j+1) > (long) (2*number_vertices))
1586 dash_polygon[j]=primitive_info[i-1];
1587 dash_polygon[j].point.x=(double) (primitive_info[i-1].point.x+dx*
1588 total_length/maximum_length);
1589 dash_polygon[j].point.y=(double) (primitive_info[i-1].point.y+dy*
1590 total_length/maximum_length);
1591 dash_polygon[j].coordinates=1;
1593 dash_polygon[0].coordinates=(unsigned long) j;
1594 dash_polygon[j].primitive=UndefinedPrimitive;
1595 status|=DrawStrokePolygon(image,clone_info,dash_polygon);
1598 if (draw_info->dash_pattern[n] == 0.0)
1600 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1602 length-=(maximum_length-total_length);
1603 if ((n & 0x01) != 0)
1605 dash_polygon[j]=primitive_info[i];
1606 dash_polygon[j].coordinates=1;
1609 if ((total_length < maximum_length) && ((n & 0x01) == 0) && (j > 1))
1611 dash_polygon[j]=primitive_info[i-1];
1612 dash_polygon[j].point.x+=MagickEpsilon;
1613 dash_polygon[j].point.y+=MagickEpsilon;
1614 dash_polygon[j].coordinates=1;
1616 dash_polygon[0].coordinates=(unsigned long) j;
1617 dash_polygon[j].primitive=UndefinedPrimitive;
1618 status|=DrawStrokePolygon(image,clone_info,dash_polygon);
1620 dash_polygon=(PrimitiveInfo *) RelinquishMagickMemory(dash_polygon);
1621 clone_info=DestroyDrawInfo(clone_info);
1622 if (image->debug != MagickFalse)
1623 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-dash");
1624 return(status != 0 ? MagickTrue : MagickFalse);
1628 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1632 % D r a w I m a g e %
1636 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1638 % DrawImage() draws a graphic primitive on your image. The primitive
1639 % may be represented as a string or filename. Precede the filename with an
1640 % "at" sign (@) and the contents of the file are drawn on the image. You
1641 % can affect how text is drawn by setting one or more members of the draw
1644 % The format of the DrawImage method is:
1646 % MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info)
1648 % A description of each parameter follows:
1650 % o image: the image.
1652 % o draw_info: the draw info.
1656 static inline MagickBooleanType IsPoint(const char *point)
1664 value=strtod(point,&p);
1665 return((value == 0.0) && (p == point) ? MagickFalse : MagickTrue);
1668 static inline void TracePoint(PrimitiveInfo *primitive_info,
1669 const PointInfo point)
1671 primitive_info->coordinates=1;
1672 primitive_info->point=point;
1675 MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info)
1677 #define RenderImageTag "Render/Image"
1684 key[2*MaxTextExtent],
1685 keyword[MaxTextExtent],
1686 geometry[MaxTextExtent],
1687 name[MaxTextExtent],
1688 pattern[MaxTextExtent],
1741 Ensure the annotation info is valid.
1743 assert(image != (Image *) NULL);
1744 assert(image->signature == MagickSignature);
1745 if (image->debug != MagickFalse)
1746 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1747 assert(draw_info != (DrawInfo *) NULL);
1748 assert(draw_info->signature == MagickSignature);
1749 if (image->debug != MagickFalse)
1750 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1751 if ((draw_info->primitive == (char *) NULL) ||
1752 (*draw_info->primitive == '\0'))
1753 return(MagickFalse);
1754 if (image->debug != MagickFalse)
1755 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"begin draw-image");
1756 if (*draw_info->primitive != '@')
1757 primitive=AcquireString(draw_info->primitive);
1759 primitive=FileToString(draw_info->primitive+1,~0,&image->exception);
1760 if (primitive == (char *) NULL)
1761 return(MagickFalse);
1762 primitive_extent=(MagickRealType) strlen(primitive);
1763 (void) SetImageArtifact(image,"MVG",primitive);
1766 Allocate primitive info memory.
1768 graphic_context=(DrawInfo **) AcquireAlignedMemory(1,sizeof(*graphic_context));
1769 if (graphic_context == (DrawInfo **) NULL)
1771 primitive=DestroyString(primitive);
1772 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1776 primitive_info=(PrimitiveInfo *) AcquireQuantumMemory((size_t) number_points,
1777 sizeof(*primitive_info));
1778 if (primitive_info == (PrimitiveInfo *) NULL)
1780 primitive=DestroyString(primitive);
1781 for ( ; n >= 0; n--)
1782 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
1783 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
1784 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1787 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1788 graphic_context[n]->viewbox=image->page;
1789 if ((image->page.width == 0) || (image->page.height == 0))
1791 graphic_context[n]->viewbox.width=image->columns;
1792 graphic_context[n]->viewbox.height=image->rows;
1794 token=AcquireString(primitive);
1795 (void) QueryColorDatabase("#000000",&start_color,&image->exception);
1796 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
1797 return(MagickFalse);
1799 for (q=primitive; *q != '\0'; )
1802 Interpret graphic primitive.
1804 GetMagickToken(q,&q,keyword);
1805 if (*keyword == '\0')
1807 if (*keyword == '#')
1812 while ((*q != '\n') && (*q != '\0'))
1816 p=q-strlen(keyword)-1;
1817 primitive_type=UndefinedPrimitive;
1818 current=graphic_context[n]->affine;
1819 GetAffineMatrix(&affine);
1827 if (LocaleCompare("affine",keyword) == 0)
1829 GetMagickToken(q,&q,token);
1830 affine.sx=StringToDouble(token);
1831 GetMagickToken(q,&q,token);
1833 GetMagickToken(q,&q,token);
1834 affine.rx=StringToDouble(token);
1835 GetMagickToken(q,&q,token);
1837 GetMagickToken(q,&q,token);
1838 affine.ry=StringToDouble(token);
1839 GetMagickToken(q,&q,token);
1841 GetMagickToken(q,&q,token);
1842 affine.sy=StringToDouble(token);
1843 GetMagickToken(q,&q,token);
1845 GetMagickToken(q,&q,token);
1846 affine.tx=StringToDouble(token);
1847 GetMagickToken(q,&q,token);
1849 GetMagickToken(q,&q,token);
1850 affine.ty=StringToDouble(token);
1853 if (LocaleCompare("arc",keyword) == 0)
1855 primitive_type=ArcPrimitive;
1864 if (LocaleCompare("bezier",keyword) == 0)
1866 primitive_type=BezierPrimitive;
1869 if (LocaleCompare("border-color",keyword) == 0)
1871 GetMagickToken(q,&q,token);
1872 (void) QueryColorDatabase(token,&graphic_context[n]->border_color,
1882 if (LocaleCompare("clip-path",keyword) == 0)
1887 GetMagickToken(q,&q,token);
1888 (void) CloneString(&graphic_context[n]->clip_mask,token);
1889 (void) DrawClipPath(image,graphic_context[n],
1890 graphic_context[n]->clip_mask);
1893 if (LocaleCompare("clip-rule",keyword) == 0)
1898 GetMagickToken(q,&q,token);
1899 fill_rule=ParseMagickOption(MagickFillRuleOptions,MagickFalse,
1901 if (fill_rule == -1)
1906 graphic_context[n]->fill_rule=(FillRule) fill_rule;
1909 if (LocaleCompare("clip-units",keyword) == 0)
1914 GetMagickToken(q,&q,token);
1915 clip_units=ParseMagickOption(MagickClipPathOptions,MagickFalse,
1917 if (clip_units == -1)
1922 graphic_context[n]->clip_units=(ClipPathUnits) clip_units;
1923 if (clip_units == ObjectBoundingBox)
1925 GetAffineMatrix(¤t);
1926 affine.sx=draw_info->bounds.x2;
1927 affine.sy=draw_info->bounds.y2;
1928 affine.tx=draw_info->bounds.x1;
1929 affine.ty=draw_info->bounds.y1;
1934 if (LocaleCompare("circle",keyword) == 0)
1936 primitive_type=CirclePrimitive;
1939 if (LocaleCompare("color",keyword) == 0)
1941 primitive_type=ColorPrimitive;
1950 if (LocaleCompare("decorate",keyword) == 0)
1955 GetMagickToken(q,&q,token);
1956 decorate=ParseMagickOption(MagickDecorateOptions,MagickFalse,
1963 graphic_context[n]->decorate=(DecorationType) decorate;
1972 if (LocaleCompare("ellipse",keyword) == 0)
1974 primitive_type=EllipsePrimitive;
1977 if (LocaleCompare("encoding",keyword) == 0)
1979 GetMagickToken(q,&q,token);
1980 (void) CloneString(&graphic_context[n]->encoding,token);
1989 if (LocaleCompare("fill",keyword) == 0)
1991 GetMagickToken(q,&q,token);
1992 (void) FormatMagickString(pattern,MaxTextExtent,"%s",token);
1993 if (GetImageArtifact(image,pattern) != (const char *) NULL)
1994 (void) DrawPatternPath(image,draw_info,token,
1995 &graphic_context[n]->fill_pattern);
1998 status=QueryColorDatabase(token,&graphic_context[n]->fill,
2000 if (status == MagickFalse)
2005 pattern_info=AcquireImageInfo();
2006 (void) CopyMagickString(pattern_info->filename,token,
2008 graphic_context[n]->fill_pattern=
2009 ReadImage(pattern_info,&image->exception);
2010 CatchException(&image->exception);
2011 pattern_info=DestroyImageInfo(pattern_info);
2016 if (LocaleCompare("fill-opacity",keyword) == 0)
2018 GetMagickToken(q,&q,token);
2019 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2020 graphic_context[n]->fill.opacity=RoundToQuantum((MagickRealType)
2021 QuantumRange*(1.0-factor*StringToDouble(token)));
2024 if (LocaleCompare("fill-rule",keyword) == 0)
2029 GetMagickToken(q,&q,token);
2030 fill_rule=ParseMagickOption(MagickFillRuleOptions,MagickFalse,
2032 if (fill_rule == -1)
2037 graphic_context[n]->fill_rule=(FillRule) fill_rule;
2040 if (LocaleCompare("font",keyword) == 0)
2042 GetMagickToken(q,&q,token);
2043 (void) CloneString(&graphic_context[n]->font,token);
2044 if (LocaleCompare("none",token) == 0)
2045 graphic_context[n]->font=(char *)
2046 RelinquishMagickMemory(graphic_context[n]->font);
2049 if (LocaleCompare("font-family",keyword) == 0)
2051 GetMagickToken(q,&q,token);
2052 (void) CloneString(&graphic_context[n]->family,token);
2055 if (LocaleCompare("font-size",keyword) == 0)
2057 GetMagickToken(q,&q,token);
2058 graphic_context[n]->pointsize=StringToDouble(token);
2061 if (LocaleCompare("font-stretch",keyword) == 0)
2066 GetMagickToken(q,&q,token);
2067 stretch=ParseMagickOption(MagickStretchOptions,MagickFalse,token);
2073 graphic_context[n]->stretch=(StretchType) stretch;
2076 if (LocaleCompare("font-style",keyword) == 0)
2081 GetMagickToken(q,&q,token);
2082 style=ParseMagickOption(MagickStyleOptions,MagickFalse,token);
2088 graphic_context[n]->style=(StyleType) style;
2091 if (LocaleCompare("font-weight",keyword) == 0)
2093 GetMagickToken(q,&q,token);
2094 graphic_context[n]->weight=StringToUnsignedLong(token);
2095 if (LocaleCompare(token,"all") == 0)
2096 graphic_context[n]->weight=0;
2097 if (LocaleCompare(token,"bold") == 0)
2098 graphic_context[n]->weight=700;
2099 if (LocaleCompare(token,"bolder") == 0)
2100 if (graphic_context[n]->weight <= 800)
2101 graphic_context[n]->weight+=100;
2102 if (LocaleCompare(token,"lighter") == 0)
2103 if (graphic_context[n]->weight >= 100)
2104 graphic_context[n]->weight-=100;
2105 if (LocaleCompare(token,"normal") == 0)
2106 graphic_context[n]->weight=400;
2115 if (LocaleCompare("gradient-units",keyword) == 0)
2117 GetMagickToken(q,&q,token);
2120 if (LocaleCompare("gravity",keyword) == 0)
2125 GetMagickToken(q,&q,token);
2126 gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,token);
2132 graphic_context[n]->gravity=(GravityType) gravity;
2141 if (LocaleCompare("image",keyword) == 0)
2146 primitive_type=ImagePrimitive;
2147 GetMagickToken(q,&q,token);
2148 compose=ParseMagickOption(MagickComposeOptions,MagickFalse,token);
2154 graphic_context[n]->compose=(CompositeOperator) compose;
2157 if (LocaleCompare("interline-spacing",keyword) == 0)
2159 GetMagickToken(q,&q,token);
2160 graphic_context[n]->interline_spacing=StringToDouble(token);
2163 if (LocaleCompare("interword-spacing",keyword) == 0)
2165 GetMagickToken(q,&q,token);
2166 graphic_context[n]->interword_spacing=StringToDouble(token);
2175 if (LocaleCompare("kerning",keyword) == 0)
2177 GetMagickToken(q,&q,token);
2178 graphic_context[n]->kerning=StringToDouble(token);
2187 if (LocaleCompare("line",keyword) == 0)
2189 primitive_type=LinePrimitive;
2198 if (LocaleCompare("matte",keyword) == 0)
2200 primitive_type=MattePrimitive;
2209 if (LocaleCompare("offset",keyword) == 0)
2211 GetMagickToken(q,&q,token);
2214 if (LocaleCompare("opacity",keyword) == 0)
2216 GetMagickToken(q,&q,token);
2217 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2218 graphic_context[n]->opacity=RoundToQuantum((MagickRealType)
2219 QuantumRange*(1.0-((1.0-QuantumScale*graphic_context[n]->opacity)*
2220 factor*StringToDouble(token))));
2221 graphic_context[n]->fill.opacity=graphic_context[n]->opacity;
2222 graphic_context[n]->stroke.opacity=graphic_context[n]->opacity;
2231 if (LocaleCompare("path",keyword) == 0)
2233 primitive_type=PathPrimitive;
2236 if (LocaleCompare("point",keyword) == 0)
2238 primitive_type=PointPrimitive;
2241 if (LocaleCompare("polyline",keyword) == 0)
2243 primitive_type=PolylinePrimitive;
2246 if (LocaleCompare("polygon",keyword) == 0)
2248 primitive_type=PolygonPrimitive;
2251 if (LocaleCompare("pop",keyword) == 0)
2253 GetMagickToken(q,&q,token);
2254 if (LocaleCompare("clip-path",token) == 0)
2256 if (LocaleCompare("defs",token) == 0)
2258 if (LocaleCompare("gradient",token) == 0)
2260 if (LocaleCompare("graphic-context",token) == 0)
2264 (void) ThrowMagickException(&image->exception,
2265 GetMagickModule(),DrawError,
2266 "UnbalancedGraphicContextPushPop","`%s'",token);
2270 if (graphic_context[n]->clip_mask != (char *) NULL)
2271 if (LocaleCompare(graphic_context[n]->clip_mask,
2272 graphic_context[n-1]->clip_mask) != 0)
2273 (void) SetImageClipMask(image,(Image *) NULL);
2274 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
2278 if (LocaleCompare("pattern",token) == 0)
2283 if (LocaleCompare("push",keyword) == 0)
2285 GetMagickToken(q,&q,token);
2286 if (LocaleCompare("clip-path",token) == 0)
2289 name[MaxTextExtent];
2291 GetMagickToken(q,&q,token);
2292 (void) FormatMagickString(name,MaxTextExtent,"%s",token);
2293 for (p=q; *q != '\0'; )
2295 GetMagickToken(q,&q,token);
2296 if (LocaleCompare(token,"pop") != 0)
2298 GetMagickToken(q,(const char **) NULL,token);
2299 if (LocaleCompare(token,"clip-path") != 0)
2303 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2304 (void) SetImageArtifact(image,name,token);
2305 GetMagickToken(q,&q,token);
2308 if (LocaleCompare("gradient",token) == 0)
2311 key[2*MaxTextExtent],
2312 name[MaxTextExtent],
2313 type[MaxTextExtent];
2321 GetMagickToken(q,&q,token);
2322 (void) CopyMagickString(name,token,MaxTextExtent);
2323 GetMagickToken(q,&q,token);
2324 (void) CopyMagickString(type,token,MaxTextExtent);
2325 GetMagickToken(q,&q,token);
2326 segment.x1=StringToDouble(token);
2327 element.cx=StringToDouble(token);
2328 GetMagickToken(q,&q,token);
2330 GetMagickToken(q,&q,token);
2331 segment.y1=StringToDouble(token);
2332 element.cy=StringToDouble(token);
2333 GetMagickToken(q,&q,token);
2335 GetMagickToken(q,&q,token);
2336 segment.x2=StringToDouble(token);
2337 element.major=StringToDouble(token);
2338 GetMagickToken(q,&q,token);
2340 GetMagickToken(q,&q,token);
2341 segment.y2=StringToDouble(token);
2342 element.minor=StringToDouble(token);
2343 if (LocaleCompare(type,"radial") == 0)
2345 GetMagickToken(q,&q,token);
2347 GetMagickToken(q,&q,token);
2348 element.angle=StringToDouble(token);
2350 for (p=q; *q != '\0'; )
2352 GetMagickToken(q,&q,token);
2353 if (LocaleCompare(token,"pop") != 0)
2355 GetMagickToken(q,(const char **) NULL,token);
2356 if (LocaleCompare(token,"gradient") != 0)
2360 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2361 bounds.x1=graphic_context[n]->affine.sx*segment.x1+
2362 graphic_context[n]->affine.ry*segment.y1+
2363 graphic_context[n]->affine.tx;
2364 bounds.y1=graphic_context[n]->affine.rx*segment.x1+
2365 graphic_context[n]->affine.sy*segment.y1+
2366 graphic_context[n]->affine.ty;
2367 bounds.x2=graphic_context[n]->affine.sx*segment.x2+
2368 graphic_context[n]->affine.ry*segment.y2+
2369 graphic_context[n]->affine.tx;
2370 bounds.y2=graphic_context[n]->affine.rx*segment.x2+
2371 graphic_context[n]->affine.sy*segment.y2+
2372 graphic_context[n]->affine.ty;
2373 (void) FormatMagickString(key,MaxTextExtent,"%s",name);
2374 (void) SetImageArtifact(image,key,token);
2375 (void) FormatMagickString(key,MaxTextExtent,"%s-geometry",name);
2376 (void) FormatMagickString(geometry,MaxTextExtent,"%gx%g%+f%+f",
2377 MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0),
2378 MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0),
2379 bounds.x1,bounds.y1);
2380 (void) SetImageArtifact(image,key,geometry);
2381 GetMagickToken(q,&q,token);
2384 if (LocaleCompare("pattern",token) == 0)
2389 GetMagickToken(q,&q,token);
2390 (void) CopyMagickString(name,token,MaxTextExtent);
2391 GetMagickToken(q,&q,token);
2392 bounds.x=(long) (StringToDouble(token)+0.5);
2393 GetMagickToken(q,&q,token);
2395 GetMagickToken(q,&q,token);
2396 bounds.y=(long) (StringToDouble(token)+0.5);
2397 GetMagickToken(q,&q,token);
2399 GetMagickToken(q,&q,token);
2400 bounds.width=(unsigned long) (StringToDouble(token)+0.5);
2401 GetMagickToken(q,&q,token);
2403 GetMagickToken(q,&q,token);
2404 bounds.height=(unsigned long) (StringToDouble(token)+0.5);
2405 for (p=q; *q != '\0'; )
2407 GetMagickToken(q,&q,token);
2408 if (LocaleCompare(token,"pop") != 0)
2410 GetMagickToken(q,(const char **) NULL,token);
2411 if (LocaleCompare(token,"pattern") != 0)
2415 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2416 (void) FormatMagickString(key,MaxTextExtent,"%s",name);
2417 (void) SetImageArtifact(image,key,token);
2418 (void) FormatMagickString(key,MaxTextExtent,"%s-geometry",name);
2419 (void) FormatMagickString(geometry,MaxTextExtent,
2420 "%lux%lu%+ld%+ld",bounds.width,bounds.height,bounds.x,
2422 (void) SetImageArtifact(image,key,geometry);
2423 GetMagickToken(q,&q,token);
2426 if (LocaleCompare("graphic-context",token) == 0)
2429 graphic_context=(DrawInfo **) ResizeQuantumMemory(
2430 graphic_context,(size_t) (n+1),sizeof(*graphic_context));
2431 if (graphic_context == (DrawInfo **) NULL)
2433 (void) ThrowMagickException(&image->exception,
2434 GetMagickModule(),ResourceLimitError,
2435 "MemoryAllocationFailed","`%s'",image->filename);
2438 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,
2439 graphic_context[n-1]);
2442 if (LocaleCompare("defs",token) == 0)
2453 if (LocaleCompare("rectangle",keyword) == 0)
2455 primitive_type=RectanglePrimitive;
2458 if (LocaleCompare("rotate",keyword) == 0)
2460 GetMagickToken(q,&q,token);
2461 angle=StringToDouble(token);
2462 affine.sx=cos(DegreesToRadians(fmod((double) angle,360.0)));
2463 affine.rx=sin(DegreesToRadians(fmod((double) angle,360.0)));
2464 affine.ry=(-sin(DegreesToRadians(fmod((double) angle,360.0))));
2465 affine.sy=cos(DegreesToRadians(fmod((double) angle,360.0)));
2468 if (LocaleCompare("roundRectangle",keyword) == 0)
2470 primitive_type=RoundRectanglePrimitive;
2479 if (LocaleCompare("scale",keyword) == 0)
2481 GetMagickToken(q,&q,token);
2482 affine.sx=StringToDouble(token);
2483 GetMagickToken(q,&q,token);
2485 GetMagickToken(q,&q,token);
2486 affine.sy=StringToDouble(token);
2489 if (LocaleCompare("skewX",keyword) == 0)
2491 GetMagickToken(q,&q,token);
2492 angle=StringToDouble(token);
2493 affine.ry=sin(DegreesToRadians(angle));
2496 if (LocaleCompare("skewY",keyword) == 0)
2498 GetMagickToken(q,&q,token);
2499 angle=StringToDouble(token);
2500 affine.rx=(-tan(DegreesToRadians(angle)/2.0));
2503 if (LocaleCompare("stop-color",keyword) == 0)
2508 GetMagickToken(q,&q,token);
2509 (void) QueryColorDatabase(token,&stop_color,&image->exception);
2510 (void) GradientImage(image,LinearGradient,ReflectSpread,
2511 &start_color,&stop_color);
2512 start_color=stop_color;
2513 GetMagickToken(q,&q,token);
2516 if (LocaleCompare("stroke",keyword) == 0)
2518 GetMagickToken(q,&q,token);
2519 (void) FormatMagickString(pattern,MaxTextExtent,"%s",token);
2520 if (GetImageArtifact(image,pattern) != (const char *) NULL)
2521 (void) DrawPatternPath(image,draw_info,token,
2522 &graphic_context[n]->stroke_pattern);
2525 status=QueryColorDatabase(token,&graphic_context[n]->stroke,
2527 if (status == MagickFalse)
2532 pattern_info=AcquireImageInfo();
2533 (void) CopyMagickString(pattern_info->filename,token,
2535 graphic_context[n]->stroke_pattern=
2536 ReadImage(pattern_info,&image->exception);
2537 CatchException(&image->exception);
2538 pattern_info=DestroyImageInfo(pattern_info);
2543 if (LocaleCompare("stroke-antialias",keyword) == 0)
2545 GetMagickToken(q,&q,token);
2546 graphic_context[n]->stroke_antialias=
2547 StringToLong(token) != 0 ? MagickTrue : MagickFalse;
2550 if (LocaleCompare("stroke-dasharray",keyword) == 0)
2552 if (graphic_context[n]->dash_pattern != (double *) NULL)
2553 graphic_context[n]->dash_pattern=(double *)
2554 RelinquishMagickMemory(graphic_context[n]->dash_pattern);
2555 if (IsPoint(q) != MagickFalse)
2561 GetMagickToken(p,&p,token);
2563 GetMagickToken(p,&p,token);
2564 for (x=0; IsPoint(token) != MagickFalse; x++)
2566 GetMagickToken(p,&p,token);
2568 GetMagickToken(p,&p,token);
2570 graphic_context[n]->dash_pattern=(double *)
2571 AcquireQuantumMemory((size_t) (2UL*x+1UL),
2572 sizeof(*graphic_context[n]->dash_pattern));
2573 if (graphic_context[n]->dash_pattern == (double *) NULL)
2575 (void) ThrowMagickException(&image->exception,
2576 GetMagickModule(),ResourceLimitError,
2577 "MemoryAllocationFailed","`%s'",image->filename);
2580 for (j=0; j < x; j++)
2582 GetMagickToken(q,&q,token);
2584 GetMagickToken(q,&q,token);
2585 graphic_context[n]->dash_pattern[j]=StringToDouble(token);
2587 if ((x & 0x01) != 0)
2588 for ( ; j < (2*x); j++)
2589 graphic_context[n]->dash_pattern[j]=
2590 graphic_context[n]->dash_pattern[j-x];
2591 graphic_context[n]->dash_pattern[j]=0.0;
2594 GetMagickToken(q,&q,token);
2597 if (LocaleCompare("stroke-dashoffset",keyword) == 0)
2599 GetMagickToken(q,&q,token);
2600 graphic_context[n]->dash_offset=StringToDouble(token);
2603 if (LocaleCompare("stroke-linecap",keyword) == 0)
2608 GetMagickToken(q,&q,token);
2609 linecap=ParseMagickOption(MagickLineCapOptions,MagickFalse,token);
2615 graphic_context[n]->linecap=(LineCap) linecap;
2618 if (LocaleCompare("stroke-linejoin",keyword) == 0)
2623 GetMagickToken(q,&q,token);
2624 linejoin=ParseMagickOption(MagickLineJoinOptions,MagickFalse,token);
2630 graphic_context[n]->linejoin=(LineJoin) linejoin;
2633 if (LocaleCompare("stroke-miterlimit",keyword) == 0)
2635 GetMagickToken(q,&q,token);
2636 graphic_context[n]->miterlimit=StringToUnsignedLong(token);
2639 if (LocaleCompare("stroke-opacity",keyword) == 0)
2641 GetMagickToken(q,&q,token);
2642 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2643 graphic_context[n]->stroke.opacity=RoundToQuantum((MagickRealType)
2644 QuantumRange*(1.0-factor*StringToDouble(token)));
2647 if (LocaleCompare("stroke-width",keyword) == 0)
2649 GetMagickToken(q,&q,token);
2650 graphic_context[n]->stroke_width=StringToDouble(token);
2659 if (LocaleCompare("text",keyword) == 0)
2661 primitive_type=TextPrimitive;
2664 if (LocaleCompare("text-align",keyword) == 0)
2669 GetMagickToken(q,&q,token);
2670 align=ParseMagickOption(MagickAlignOptions,MagickFalse,token);
2676 graphic_context[n]->align=(AlignType) align;
2679 if (LocaleCompare("text-anchor",keyword) == 0)
2684 GetMagickToken(q,&q,token);
2685 align=ParseMagickOption(MagickAlignOptions,MagickFalse,token);
2691 graphic_context[n]->align=(AlignType) align;
2694 if (LocaleCompare("text-antialias",keyword) == 0)
2696 GetMagickToken(q,&q,token);
2697 graphic_context[n]->text_antialias=
2698 StringToLong(token) != 0 ? MagickTrue : MagickFalse;
2701 if (LocaleCompare("text-undercolor",keyword) == 0)
2703 GetMagickToken(q,&q,token);
2704 (void) QueryColorDatabase(token,&graphic_context[n]->undercolor,
2708 if (LocaleCompare("translate",keyword) == 0)
2710 GetMagickToken(q,&q,token);
2711 affine.tx=StringToDouble(token);
2712 GetMagickToken(q,&q,token);
2714 GetMagickToken(q,&q,token);
2715 affine.ty=StringToDouble(token);
2724 if (LocaleCompare("viewbox",keyword) == 0)
2726 GetMagickToken(q,&q,token);
2727 graphic_context[n]->viewbox.x=(long) (StringToDouble(token)+0.5);
2728 GetMagickToken(q,&q,token);
2730 GetMagickToken(q,&q,token);
2731 graphic_context[n]->viewbox.y=(long) (StringToDouble(token)+0.5);
2732 GetMagickToken(q,&q,token);
2734 GetMagickToken(q,&q,token);
2735 graphic_context[n]->viewbox.width=(unsigned long) (StringToDouble(token)+0.5);
2736 GetMagickToken(q,&q,token);
2738 GetMagickToken(q,&q,token);
2739 graphic_context[n]->viewbox.height=(unsigned long) (StringToDouble(token)+
2752 if (status == MagickFalse)
2754 if ((affine.sx != 1.0) || (affine.rx != 0.0) || (affine.ry != 0.0) ||
2755 (affine.sy != 1.0) || (affine.tx != 0.0) || (affine.ty != 0.0))
2757 graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
2758 graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
2759 graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
2760 graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
2761 graphic_context[n]->affine.tx=
2762 current.sx*affine.tx+current.ry*affine.ty+current.tx;
2763 graphic_context[n]->affine.ty=
2764 current.rx*affine.tx+current.sy*affine.ty+current.ty;
2766 if (primitive_type == UndefinedPrimitive)
2768 if (image->debug != MagickFalse)
2769 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",
2774 Parse the primitive attributes.
2778 primitive_info[0].point.x=0.0;
2779 primitive_info[0].point.y=0.0;
2780 for (x=0; *q != '\0'; x++)
2785 if (IsPoint(q) == MagickFalse)
2787 GetMagickToken(q,&q,token);
2788 point.x=StringToDouble(token);
2789 GetMagickToken(q,&q,token);
2791 GetMagickToken(q,&q,token);
2792 point.y=StringToDouble(token);
2793 GetMagickToken(q,(const char **) NULL,token);
2795 GetMagickToken(q,&q,token);
2796 primitive_info[i].primitive=primitive_type;
2797 primitive_info[i].point=point;
2798 primitive_info[i].coordinates=0;
2799 primitive_info[i].method=FloodfillMethod;
2801 if (i < (long) number_points)
2804 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,
2805 (size_t) number_points,sizeof(*primitive_info));
2806 if (primitive_info == (PrimitiveInfo *) NULL)
2808 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2809 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
2813 primitive_info[j].primitive=primitive_type;
2814 primitive_info[j].coordinates=(unsigned long) x;
2815 primitive_info[j].method=FloodfillMethod;
2816 primitive_info[j].text=(char *) NULL;
2818 Circumscribe primitive within a circle.
2820 bounds.x1=primitive_info[j].point.x;
2821 bounds.y1=primitive_info[j].point.y;
2822 bounds.x2=primitive_info[j].point.x;
2823 bounds.y2=primitive_info[j].point.y;
2824 for (k=1; k < (long) primitive_info[j].coordinates; k++)
2826 point=primitive_info[j+k].point;
2827 if (point.x < bounds.x1)
2829 if (point.y < bounds.y1)
2831 if (point.x > bounds.x2)
2833 if (point.y > bounds.y2)
2837 Speculate how many points our primitive might consume.
2839 length=primitive_info[j].coordinates;
2840 switch (primitive_type)
2842 case RectanglePrimitive:
2847 case RoundRectanglePrimitive:
2849 length*=5+4*BezierQuantum;
2852 case BezierPrimitive:
2854 if (primitive_info[j].coordinates > 107)
2855 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2856 DrawError,"TooManyBezierCoordinates","`%s'",token);
2857 length=BezierQuantum*primitive_info[j].coordinates;
2866 GetMagickToken(q,&q,token);
2869 for (s=token; *s != '\0'; s=t)
2882 length+=k*BezierQuantum;
2885 case CirclePrimitive:
2887 case EllipsePrimitive:
2894 alpha=bounds.x2-bounds.x1;
2895 beta=bounds.y2-bounds.y1;
2896 radius=hypot((double) alpha,(double) beta);
2897 length=2*((size_t) (MagickPI*radius))+6*BezierQuantum+360+1;
2903 if ((unsigned long) (i+length) >= number_points)
2906 Resize based on speculative points required by primitive.
2908 while ((unsigned long) (i+length) >= number_points)
2910 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,
2911 (size_t) number_points,sizeof(*primitive_info));
2912 if (primitive_info == (PrimitiveInfo *) NULL)
2914 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2915 ResourceLimitError,"MemoryAllocationFailed","`%s'",
2920 switch (primitive_type)
2922 case PointPrimitive:
2925 if (primitive_info[j].coordinates != 1)
2930 TracePoint(primitive_info+j,primitive_info[j].point);
2931 i=(long) (j+primitive_info[j].coordinates);
2936 if (primitive_info[j].coordinates != 2)
2941 TraceLine(primitive_info+j,primitive_info[j].point,
2942 primitive_info[j+1].point);
2943 i=(long) (j+primitive_info[j].coordinates);
2946 case RectanglePrimitive:
2948 if (primitive_info[j].coordinates != 2)
2953 TraceRectangle(primitive_info+j,primitive_info[j].point,
2954 primitive_info[j+1].point);
2955 i=(long) (j+primitive_info[j].coordinates);
2958 case RoundRectanglePrimitive:
2960 if (primitive_info[j].coordinates != 3)
2965 TraceRoundRectangle(primitive_info+j,primitive_info[j].point,
2966 primitive_info[j+1].point,primitive_info[j+2].point);
2967 i=(long) (j+primitive_info[j].coordinates);
2972 if (primitive_info[j].coordinates != 3)
2974 primitive_type=UndefinedPrimitive;
2977 TraceArc(primitive_info+j,primitive_info[j].point,
2978 primitive_info[j+1].point,primitive_info[j+2].point);
2979 i=(long) (j+primitive_info[j].coordinates);
2982 case EllipsePrimitive:
2984 if (primitive_info[j].coordinates != 3)
2989 TraceEllipse(primitive_info+j,primitive_info[j].point,
2990 primitive_info[j+1].point,primitive_info[j+2].point);
2991 i=(long) (j+primitive_info[j].coordinates);
2994 case CirclePrimitive:
2996 if (primitive_info[j].coordinates != 2)
3001 TraceCircle(primitive_info+j,primitive_info[j].point,
3002 primitive_info[j+1].point);
3003 i=(long) (j+primitive_info[j].coordinates);
3006 case PolylinePrimitive:
3008 case PolygonPrimitive:
3010 primitive_info[i]=primitive_info[j];
3011 primitive_info[i].coordinates=0;
3012 primitive_info[j].coordinates++;
3016 case BezierPrimitive:
3018 if (primitive_info[j].coordinates < 3)
3023 TraceBezier(primitive_info+j,primitive_info[j].coordinates);
3024 i=(long) (j+primitive_info[j].coordinates);
3029 i=(long) (j+TracePath(primitive_info+j,token));
3032 case ColorPrimitive:
3033 case MattePrimitive:
3038 if (primitive_info[j].coordinates != 1)
3043 GetMagickToken(q,&q,token);
3044 method=ParseMagickOption(MagickMethodOptions,MagickFalse,token);
3050 primitive_info[j].method=(PaintMethod) method;
3055 if (primitive_info[j].coordinates != 1)
3061 GetMagickToken(q,&q,token);
3062 primitive_info[j].text=AcquireString(token);
3065 case ImagePrimitive:
3067 if (primitive_info[j].coordinates != 2)
3072 GetMagickToken(q,&q,token);
3073 primitive_info[j].text=AcquireString(token);
3077 if (primitive_info == (PrimitiveInfo *) NULL)
3079 if (image->debug != MagickFalse)
3080 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",(int) (q-p),p);
3081 if (status == MagickFalse)
3083 primitive_info[i].primitive=UndefinedPrimitive;
3089 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
3091 point=primitive_info[i].point;
3092 primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+
3093 graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx;
3094 primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+
3095 graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty;
3096 point=primitive_info[i].point;
3097 if (point.x < graphic_context[n]->bounds.x1)
3098 graphic_context[n]->bounds.x1=point.x;
3099 if (point.y < graphic_context[n]->bounds.y1)
3100 graphic_context[n]->bounds.y1=point.y;
3101 if (point.x > graphic_context[n]->bounds.x2)
3102 graphic_context[n]->bounds.x2=point.x;
3103 if (point.y > graphic_context[n]->bounds.y2)
3104 graphic_context[n]->bounds.y2=point.y;
3105 if (primitive_info[i].primitive == ImagePrimitive)
3108 if (i >= (long) number_points)
3109 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
3110 if (graphic_context[n]->render != MagickFalse)
3112 if ((n != 0) && (graphic_context[n]->clip_mask != (char *) NULL) &&
3113 (LocaleCompare(graphic_context[n]->clip_mask,
3114 graphic_context[n-1]->clip_mask) != 0))
3115 (void) DrawClipPath(image,graphic_context[n],
3116 graphic_context[n]->clip_mask);
3117 (void) DrawPrimitive(image,graphic_context[n],primitive_info);
3119 if (primitive_info->text != (char *) NULL)
3120 primitive_info->text=(char *) RelinquishMagickMemory(
3121 primitive_info->text);
3122 proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType)
3124 if (proceed == MagickFalse)
3127 if (image->debug != MagickFalse)
3128 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end draw-image");
3130 Relinquish resources.
3132 token=DestroyString(token);
3133 if (primitive_info != (PrimitiveInfo *) NULL)
3134 primitive_info=(PrimitiveInfo *) RelinquishMagickMemory(primitive_info);
3135 primitive=DestroyString(primitive);
3136 for ( ; n >= 0; n--)
3137 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
3138 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
3139 if (status == MagickFalse)
3140 ThrowBinaryException(DrawError,"NonconformingDrawingPrimitiveDefinition",
3146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3150 % D r a w G r a d i e n t I m a g e %
3154 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3156 % DrawGradientImage() draws a linear gradient on the image.
3158 % The format of the DrawGradientImage method is:
3160 % MagickBooleanType DrawGradientImage(Image *image,
3161 % const DrawInfo *draw_info)
3163 % A description of each parameter follows:
3165 % o image: the image.
3167 % o _info: the draw info.
3171 static inline MagickRealType GetStopColorOffset(const GradientInfo *gradient,
3172 const long x,const long y)
3174 switch (gradient->type)
3176 case UndefinedGradient:
3177 case LinearGradient:
3192 gradient_vector=(&gradient->gradient_vector);
3193 p.x=gradient_vector->x2-gradient_vector->x1;
3194 p.y=gradient_vector->y2-gradient_vector->y1;
3195 q.x=(double) x-gradient_vector->x1;
3196 q.y=(double) y-gradient_vector->y1;
3197 length=sqrt(q.x*q.x+q.y*q.y);
3198 gamma=sqrt(p.x*p.x+p.y*p.y)*length;
3199 gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
3200 scale=p.x*q.x+p.y*q.y;
3201 offset=gamma*scale*length;
3204 case RadialGradient:
3213 v.x=(double) x-gradient->center.x;
3214 v.y=(double) y-gradient->center.y;
3215 length=sqrt(v.x*v.x+v.y*v.y);
3216 if (gradient->spread == RepeatSpread)
3218 offset=length/gradient->radius;
3225 MagickExport MagickBooleanType DrawGradientImage(Image *image,
3226 const DrawInfo *draw_info)
3259 Draw linear or radial gradient on image.
3261 assert(image != (Image *) NULL);
3262 assert(image->signature == MagickSignature);
3263 if (image->debug != MagickFalse)
3264 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3265 assert(draw_info != (const DrawInfo *) NULL);
3266 gradient=(&draw_info->gradient);
3267 gradient_vector=(&gradient->gradient_vector);
3268 point.x=gradient_vector->x2-gradient_vector->x1;
3269 point.y=gradient_vector->y2-gradient_vector->y1;
3270 length=sqrt(point.x*point.x+point.y*point.y);
3271 bounding_box=gradient->bounding_box;
3273 exception=(&image->exception);
3274 GetMagickPixelPacket(image,&zero);
3275 image_view=AcquireCacheView(image);
3276 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3277 #pragma omp parallel for schedule(dynamic,4) shared(status)
3279 for (y=bounding_box.y; y < (long) bounding_box.height; y++)
3292 register IndexPacket
3299 register PixelPacket
3302 if (status == MagickFalse)
3304 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3305 if (q == (PixelPacket *) NULL)
3310 indexes=GetCacheViewAuthenticIndexQueue(image_view);
3313 offset=GetStopColorOffset(gradient,0,y);
3314 if (gradient->type != RadialGradient)
3316 for (x=bounding_box.x; x < (long) bounding_box.width; x++)
3318 SetMagickPixelPacket(image,q,indexes+x,&pixel);
3319 switch (gradient->spread)
3321 case UndefinedSpread:
3324 if ((x != (long) (gradient_vector->x1+0.5)) ||
3325 (y != (long) (gradient_vector->y1+0.5)))
3327 offset=GetStopColorOffset(gradient,x,y);
3328 if (gradient->type != RadialGradient)
3331 for (i=0; i < (long) gradient->number_stops; i++)
3332 if (offset < gradient->stops[i].offset)
3334 if ((offset < 0.0) || (i == 0))
3335 composite=gradient->stops[0].color;
3337 if ((offset > 1.0) || (i == (long) gradient->number_stops))
3338 composite=gradient->stops[gradient->number_stops-1].color;
3343 alpha=(offset-gradient->stops[i].offset)/
3344 (gradient->stops[j].offset-gradient->stops[i].offset);
3345 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3346 &gradient->stops[j].color,alpha,&composite);
3352 if ((x != (long) (gradient_vector->x1+0.5)) ||
3353 (y != (long) (gradient_vector->y1+0.5)))
3355 offset=GetStopColorOffset(gradient,x,y);
3356 if (gradient->type != RadialGradient)
3361 if ((long) fmod(offset,2.0) == 0)
3362 offset=fmod(offset,1.0);
3364 offset=1.0-fmod(offset,1.0);
3365 for (i=0; i < (long) gradient->number_stops; i++)
3366 if (offset < gradient->stops[i].offset)
3369 composite=gradient->stops[0].color;
3371 if (i == (long) gradient->number_stops)
3372 composite=gradient->stops[gradient->number_stops-1].color;
3377 alpha=(offset-gradient->stops[i].offset)/
3378 (gradient->stops[j].offset-gradient->stops[i].offset);
3379 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3380 &gradient->stops[j].color,alpha,&composite);
3392 antialias=MagickFalse;
3394 if ((x != (long) (gradient_vector->x1+0.5)) ||
3395 (y != (long) (gradient_vector->y1+0.5)))
3397 offset=GetStopColorOffset(gradient,x,y);
3398 if (gradient->type == LinearGradient)
3400 repeat=fmod(offset,length);
3402 repeat=length-fmod(-repeat,length);
3404 repeat=fmod(offset,length);
3405 antialias=(repeat < length) && ((repeat+1.0) > length) ?
3406 MagickTrue : MagickFalse;
3407 offset=repeat/length;
3411 repeat=fmod(offset,gradient->radius);
3413 repeat=gradient->radius-fmod(-repeat,gradient->radius);
3415 repeat=fmod(offset,gradient->radius);
3416 antialias=repeat+1.0 > gradient->radius ?
3417 MagickTrue : MagickFalse;
3418 offset=repeat/gradient->radius;
3421 for (i=0; i < (long) gradient->number_stops; i++)
3422 if (offset < gradient->stops[i].offset)
3425 composite=gradient->stops[0].color;
3427 if (i == (long) gradient->number_stops)
3428 composite=gradient->stops[gradient->number_stops-1].color;
3433 alpha=(offset-gradient->stops[i].offset)/
3434 (gradient->stops[j].offset-gradient->stops[i].offset);
3435 if (antialias != MagickFalse)
3437 if (gradient->type == LinearGradient)
3438 alpha=length-repeat;
3440 alpha=gradient->radius-repeat;
3442 j=(long) gradient->number_stops-1L;
3444 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3445 &gradient->stops[j].color,alpha,&composite);
3450 MagickPixelCompositeOver(&composite,composite.opacity,&pixel,
3451 pixel.opacity,&pixel);
3452 SetPixelPacket(image,&pixel,q,indexes+x);
3455 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3458 image_view=DestroyCacheView(image_view);
3463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3467 % D r a w P a t t e r n P a t h %
3471 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3473 % DrawPatternPath() draws a pattern.
3475 % The format of the DrawPatternPath method is:
3477 % MagickBooleanType DrawPatternPath(Image *image,const DrawInfo *draw_info,
3478 % const char *name,Image **pattern)
3480 % A description of each parameter follows:
3482 % o image: the image.
3484 % o draw_info: the draw info.
3486 % o name: the pattern name.
3488 % o image: the image.
3491 MagickExport MagickBooleanType DrawPatternPath(Image *image,
3492 const DrawInfo *draw_info,const char *name,Image **pattern)
3495 property[MaxTextExtent];
3510 assert(image != (Image *) NULL);
3511 assert(image->signature == MagickSignature);
3512 if (image->debug != MagickFalse)
3513 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3514 assert(draw_info != (const DrawInfo *) NULL);
3515 assert(name != (const char *) NULL);
3516 (void) FormatMagickString(property,MaxTextExtent,"%s",name);
3517 path=GetImageArtifact(image,property);
3518 if (path == (const char *) NULL)
3519 return(MagickFalse);
3520 (void) FormatMagickString(property,MaxTextExtent,"%s-geometry",name);
3521 geometry=GetImageArtifact(image,property);
3522 if (geometry == (const char *) NULL)
3523 return(MagickFalse);
3524 if ((*pattern) != (Image *) NULL)
3525 *pattern=DestroyImage(*pattern);
3526 image_info=AcquireImageInfo();
3527 image_info->size=AcquireString(geometry);
3528 *pattern=AcquireImage(image_info);
3529 image_info=DestroyImageInfo(image_info);
3530 (void) QueryColorDatabase("#00000000",&(*pattern)->background_color,
3532 (void) SetImageBackgroundColor(*pattern);
3533 if (image->debug != MagickFalse)
3534 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
3535 "begin pattern-path %s %s",name,geometry);
3536 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
3537 clone_info->fill_pattern=NewImageList();
3538 clone_info->stroke_pattern=NewImageList();
3539 (void) CloneString(&clone_info->primitive,path);
3540 status=DrawImage(*pattern,clone_info);
3541 clone_info=DestroyDrawInfo(clone_info);
3542 if (image->debug != MagickFalse)
3543 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end pattern-path");
3548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3552 + D r a w P o l y g o n P r i m i t i v e %
3556 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3558 % DrawPolygonPrimitive() draws a polygon on the image.
3560 % The format of the DrawPolygonPrimitive method is:
3562 % MagickBooleanType DrawPolygonPrimitive(Image *image,
3563 % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
3565 % A description of each parameter follows:
3567 % o image: the image.
3569 % o draw_info: the draw info.
3571 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
3575 static PolygonInfo **DestroyPolygonThreadSet(PolygonInfo **polygon_info)
3580 assert(polygon_info != (PolygonInfo **) NULL);
3581 for (i=0; i < (long) GetOpenMPMaximumThreads(); i++)
3582 if (polygon_info[i] != (PolygonInfo *) NULL)
3583 polygon_info[i]=DestroyPolygonInfo(polygon_info[i]);
3584 polygon_info=(PolygonInfo **) RelinquishAlignedMemory(polygon_info);
3585 return(polygon_info);
3588 static PolygonInfo **AcquirePolygonThreadSet(const DrawInfo *draw_info,
3589 const PrimitiveInfo *primitive_info)
3592 *restrict path_info;
3603 number_threads=GetOpenMPMaximumThreads();
3604 polygon_info=(PolygonInfo **) AcquireAlignedMemory(number_threads,
3605 sizeof(*polygon_info));
3606 if (polygon_info == (PolygonInfo **) NULL)
3607 return((PolygonInfo **) NULL);
3608 (void) ResetMagickMemory(polygon_info,0,GetOpenMPMaximumThreads()*
3609 sizeof(*polygon_info));
3610 path_info=ConvertPrimitiveToPath(draw_info,primitive_info);
3611 if (path_info == (PathInfo *) NULL)
3612 return(DestroyPolygonThreadSet(polygon_info));
3613 for (i=0; i < (long) number_threads; i++)
3615 polygon_info[i]=ConvertPathToPolygon(draw_info,path_info);
3616 if (polygon_info[i] == (PolygonInfo *) NULL)
3617 return(DestroyPolygonThreadSet(polygon_info));
3619 path_info=(PathInfo *) RelinquishMagickMemory(path_info);
3620 return(polygon_info);
3623 static MagickRealType GetPixelOpacity(PolygonInfo *polygon_info,
3624 const MagickRealType mid,const MagickBooleanType fill,
3625 const FillRule fill_rule,const long x,const long y,
3626 MagickRealType *stroke_opacity)
3646 register const PointInfo
3653 Compute fill & stroke opacity for this (x,y) point.
3655 *stroke_opacity=0.0;
3656 subpath_opacity=0.0;
3657 p=polygon_info->edges;
3658 for (j=0; j < (long) polygon_info->number_edges; j++, p++)
3660 if (y <= (p->bounds.y1-mid-0.5))
3662 if (y > (p->bounds.y2+mid+0.5))
3664 (void) DestroyEdge(polygon_info,j);
3667 if ((x <= (p->bounds.x1-mid-0.5)) || (x > (p->bounds.x2+mid+0.5)))
3669 for (i=MagickMax(p->highwater,1); i < (long) p->number_points; i++)
3671 if (y <= (p->points[i-1].y-mid-0.5))
3673 if (y > (p->points[i].y+mid+0.5))
3675 if (p->scanline != y)
3681 Compute distance between a point and an edge.
3684 delta.x=(q+1)->x-q->x;
3685 delta.y=(q+1)->y-q->y;
3686 beta=delta.x*(x-q->x)+delta.y*(y-q->y);
3691 distance=delta.x*delta.x+delta.y*delta.y;
3695 alpha=delta.x*delta.x+delta.y*delta.y;
3700 distance=delta.x*delta.x+delta.y*delta.y;
3705 beta=delta.x*(y-q->y)-delta.y*(x-q->x);
3706 distance=alpha*beta*beta;
3710 Compute stroke & subpath opacity.
3713 if (p->ghostline == MagickFalse)
3716 if ((*stroke_opacity < 1.0) &&
3717 (distance <= ((alpha+0.25)*(alpha+0.25))))
3720 if (distance <= ((alpha+0.25)*(alpha+0.25)))
3721 *stroke_opacity=1.0;
3725 if (distance != 1.0)
3726 beta=sqrt((double) distance);
3728 if (*stroke_opacity < ((alpha-0.25)*(alpha-0.25)))
3729 *stroke_opacity=(alpha-0.25)*(alpha-0.25);
3733 if ((fill == MagickFalse) || (distance > 1.0) || (subpath_opacity >= 1.0))
3735 if (distance <= 0.0)
3737 subpath_opacity=1.0;
3745 if (distance != 1.0)
3746 beta=sqrt(distance);
3749 if (subpath_opacity < (alpha*alpha))
3750 subpath_opacity=alpha*alpha;
3754 Compute fill opacity.
3756 if (fill == MagickFalse)
3758 if (subpath_opacity >= 1.0)
3761 Determine winding number.
3764 p=polygon_info->edges;
3765 for (j=0; j < (long) polygon_info->number_edges; j++, p++)
3767 if (y <= p->bounds.y1)
3769 if ((y > p->bounds.y2) || (x <= p->bounds.x1))
3771 if (x > p->bounds.x2)
3773 winding_number+=p->direction ? 1 : -1;
3776 for (i=MagickMax(p->highwater,1); i < (long) p->number_points; i++)
3777 if (y <= p->points[i].y)
3780 if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x)))
3781 winding_number+=p->direction ? 1 : -1;
3783 if (fill_rule != NonZeroRule)
3785 if ((MagickAbsoluteValue(winding_number) & 0x01) != 0)
3789 if (MagickAbsoluteValue(winding_number) != 0)
3791 return(subpath_opacity);
3794 static MagickBooleanType DrawPolygonPrimitive(Image *image,
3795 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
3816 **restrict polygon_info;
3828 Compute bounding box.
3830 assert(image != (Image *) NULL);
3831 assert(image->signature == MagickSignature);
3832 if (image->debug != MagickFalse)
3833 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3834 assert(draw_info != (DrawInfo *) NULL);
3835 assert(draw_info->signature == MagickSignature);
3836 assert(primitive_info != (PrimitiveInfo *) NULL);
3837 if (primitive_info->coordinates == 0)
3839 polygon_info=AcquirePolygonThreadSet(draw_info,primitive_info);
3840 if (polygon_info == (PolygonInfo **) NULL)
3841 return(MagickFalse);
3843 DrawBoundingRectangles(image,draw_info,polygon_info[0]);
3844 if (image->debug != MagickFalse)
3845 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-polygon");
3846 fill=(primitive_info->method == FillToBorderMethod) ||
3847 (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse;
3848 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
3849 bounds=polygon_info[0]->edges[0].bounds;
3850 for (i=1; i < (long) polygon_info[0]->number_edges; i++)
3852 p=polygon_info[0]->edges+i;
3853 if (p->bounds.x1 < bounds.x1)
3854 bounds.x1=p->bounds.x1;
3855 if (p->bounds.y1 < bounds.y1)
3856 bounds.y1=p->bounds.y1;
3857 if (p->bounds.x2 > bounds.x2)
3858 bounds.x2=p->bounds.x2;
3859 if (p->bounds.y2 > bounds.y2)
3860 bounds.y2=p->bounds.y2;
3862 bounds.x1-=(mid+1.0);
3863 bounds.x1=bounds.x1 < 0.0 ? 0.0 : (unsigned long) (bounds.x1+0.5) >=
3864 image->columns ? (double) image->columns-1.0 : bounds.x1;
3865 bounds.y1-=(mid+1.0);
3866 bounds.y1=bounds.y1 < 0.0 ? 0.0 : (unsigned long) (bounds.y1+0.5) >=
3867 image->rows ? (double) image->rows-1.0 : bounds.y1;
3868 bounds.x2+=(mid+1.0);
3869 bounds.x2=bounds.x2 < 0.0 ? 0.0 : (unsigned long) (bounds.x2+0.5) >=
3870 image->columns ? (double) image->columns-1.0 : bounds.x2;
3871 bounds.y2+=(mid+1.0);
3872 bounds.y2=bounds.y2 < 0.0 ? 0.0 : (unsigned long) (bounds.y2+0.5) >=
3873 image->rows ? (double) image->rows-1.0 : bounds.y2;
3875 exception=(&image->exception);
3876 start=(long) (bounds.x1+0.5);
3877 stop=(long) (bounds.x2+0.5);
3878 image_view=AcquireCacheView(image);
3879 if (primitive_info->coordinates == 1)
3884 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3885 #pragma omp parallel for schedule(dynamic,4) shared(status)
3887 for (y=(long) (bounds.y1+0.5); y <= (long) (bounds.y2+0.5); y++)
3895 register PixelPacket
3898 if (status == MagickFalse)
3901 q=GetCacheViewAuthenticPixels(image_view,x,y,(unsigned long) (stop-x+1),
3903 if (q == (PixelPacket *) NULL)
3908 for ( ; x <= stop; x++)
3910 if ((x == (long) (primitive_info->point.x+0.5)) &&
3911 (y == (long) (primitive_info->point.y+0.5)))
3912 (void) GetStrokeColor(draw_info,x,y,q);
3915 sync=SyncCacheViewAuthenticPixels(image_view,exception);
3916 if (sync == MagickFalse)
3919 image_view=DestroyCacheView(image_view);
3920 polygon_info=DestroyPolygonThreadSet(polygon_info);
3921 if (image->debug != MagickFalse)
3922 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
3923 " end draw-polygon");
3927 Draw polygon or line.
3929 if (image->matte == MagickFalse)
3930 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3931 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3932 #pragma omp parallel for schedule(dynamic,4) shared(status)
3934 for (y=(long) (bounds.y1+0.5); y <= (long) (bounds.y2+0.5); y++)
3948 register PixelPacket
3951 if (status == MagickFalse)
3953 q=GetCacheViewAuthenticPixels(image_view,start,y,(unsigned long) (stop-
3954 start+1),1,exception);
3955 if (q == (PixelPacket *) NULL)
3960 id=GetOpenMPThreadId();
3961 for (x=start; x <= stop; x++)
3966 fill_opacity=GetPixelOpacity(polygon_info[id],mid,fill,
3967 draw_info->fill_rule,x,y,&stroke_opacity);
3968 if (draw_info->stroke_antialias == MagickFalse)
3970 fill_opacity=fill_opacity > 0.25 ? 1.0 : 0.0;
3971 stroke_opacity=stroke_opacity > 0.25 ? 1.0 : 0.0;
3973 (void) GetFillColor(draw_info,x,y,&fill_color);
3974 fill_opacity=(MagickRealType) (QuantumRange-fill_opacity*(QuantumRange-
3975 fill_color.opacity));
3976 MagickCompositeOver(&fill_color,fill_opacity,q,(MagickRealType)
3978 (void) GetStrokeColor(draw_info,x,y,&stroke_color);
3979 stroke_opacity=(MagickRealType) (QuantumRange-stroke_opacity*
3980 (QuantumRange-stroke_color.opacity));
3981 MagickCompositeOver(&stroke_color,stroke_opacity,q,(MagickRealType)
3985 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3988 image_view=DestroyCacheView(image_view);
3989 polygon_info=DestroyPolygonThreadSet(polygon_info);
3990 if (image->debug != MagickFalse)
3991 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-polygon");
3996 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4000 % D r a w P r i m i t i v e %
4004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4006 % DrawPrimitive() draws a primitive (line, rectangle, ellipse) on the image.
4008 % The format of the DrawPrimitive method is:
4010 % MagickBooleanType DrawPrimitive(Image *image,const DrawInfo *draw_info,
4011 % PrimitiveInfo *primitive_info)
4013 % A description of each parameter follows:
4015 % o image: the image.
4017 % o draw_info: the draw info.
4019 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
4023 static void LogPrimitiveInfo(const PrimitiveInfo *primitive_info)
4049 x=(long) (primitive_info->point.x+0.5);
4050 y=(long) (primitive_info->point.y+0.5);
4051 switch (primitive_info->primitive)
4053 case PointPrimitive:
4055 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4056 "PointPrimitive %ld,%ld %s",x,y,methods[primitive_info->method]);
4059 case ColorPrimitive:
4061 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4062 "ColorPrimitive %ld,%ld %s",x,y,methods[primitive_info->method]);
4065 case MattePrimitive:
4067 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4068 "MattePrimitive %ld,%ld %s",x,y,methods[primitive_info->method]);
4073 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4074 "TextPrimitive %ld,%ld",x,y);
4077 case ImagePrimitive:
4079 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4080 "ImagePrimitive %ld,%ld",x,y);
4087 p=primitive_info[0].point;
4090 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4092 point=primitive_info[i].point;
4093 if (coordinates <= 0)
4095 coordinates=(long) primitive_info[i].coordinates;
4096 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4097 " begin open (%ld)",coordinates);
4100 point=primitive_info[i].point;
4101 if ((fabs(q.x-point.x) > MagickEpsilon) ||
4102 (fabs(q.y-point.y) > MagickEpsilon))
4103 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %ld: %g,%g",
4104 coordinates,point.x,point.y);
4106 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4107 " %ld: %g,%g (duplicate)",coordinates,point.x,point.y);
4110 if (coordinates > 0)
4112 if ((fabs(p.x-point.x) > MagickEpsilon) ||
4113 (fabs(p.y-point.y) > MagickEpsilon))
4114 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end last (%ld)",
4117 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end open (%ld)",
4122 MagickExport MagickBooleanType DrawPrimitive(Image *image,
4123 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4141 if (image->debug != MagickFalse)
4143 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4144 " begin draw-primitive");
4145 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4146 " affine: %g,%g,%g,%g,%g,%g",draw_info->affine.sx,
4147 draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy,
4148 draw_info->affine.tx,draw_info->affine.ty);
4151 exception=(&image->exception);
4152 x=(long) (primitive_info->point.x+0.5);
4153 y=(long) (primitive_info->point.y+0.5);
4154 image_view=AcquireCacheView(image);
4155 switch (primitive_info->primitive)
4157 case PointPrimitive:
4165 if ((y < 0) || (y >= (long) image->rows))
4167 if ((x < 0) || (x >= (long) image->columns))
4169 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4170 if (q == (PixelPacket *) NULL)
4172 (void) GetFillColor(draw_info,x,y,&fill_color);
4173 MagickCompositeOver(&fill_color,(MagickRealType) fill_color.opacity,q,
4174 (MagickRealType) q->opacity,q);
4175 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4178 case ColorPrimitive:
4180 switch (primitive_info->method)
4188 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4189 if (q == (PixelPacket *) NULL)
4191 (void) GetFillColor(draw_info,x,y,q);
4192 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4203 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception);
4204 for (y=0; y < (long) image->rows; y++)
4206 register PixelPacket
4209 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4211 if (q == (PixelPacket *) NULL)
4213 for (x=0; x < (long) image->columns; x++)
4215 if (IsColorSimilar(image,q,&target) == MagickFalse)
4220 (void) GetFillColor(draw_info,x,y,q);
4223 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4224 if (sync == MagickFalse)
4229 case FloodfillMethod:
4230 case FillToBorderMethod:
4235 (void) GetOneVirtualMagickPixel(image,x,y,&target,exception);
4236 if (primitive_info->method == FillToBorderMethod)
4238 target.red=(MagickRealType) draw_info->border_color.red;
4239 target.green=(MagickRealType) draw_info->border_color.green;
4240 target.blue=(MagickRealType) draw_info->border_color.blue;
4242 (void) FloodfillPaintImage(image,DefaultChannels,draw_info,&target,x,
4243 y,primitive_info->method == FloodfillMethod ? MagickFalse :
4252 for (y=0; y < (long) image->rows; y++)
4257 register PixelPacket
4260 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4262 if (q == (PixelPacket *) NULL)
4264 for (x=0; x < (long) image->columns; x++)
4266 (void) GetFillColor(draw_info,x,y,q);
4269 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4270 if (sync == MagickFalse)
4278 case MattePrimitive:
4280 if (image->matte == MagickFalse)
4281 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
4282 switch (primitive_info->method)
4293 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4294 if (q == (PixelPacket *) NULL)
4296 (void) GetFillColor(draw_info,x,y,&pixel);
4297 q->opacity=pixel.opacity;
4298 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4310 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception);
4311 for (y=0; y < (long) image->rows; y++)
4316 register PixelPacket
4319 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4321 if (q == (PixelPacket *) NULL)
4323 for (x=0; x < (long) image->columns; x++)
4325 if (IsColorSimilar(image,q,&target) == MagickFalse)
4330 (void) GetFillColor(draw_info,x,y,&pixel);
4331 q->opacity=pixel.opacity;
4334 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4335 if (sync == MagickFalse)
4340 case FloodfillMethod:
4341 case FillToBorderMethod:
4346 (void) GetOneVirtualMagickPixel(image,x,y,&target,exception);
4347 if (primitive_info->method == FillToBorderMethod)
4349 target.red=(MagickRealType) draw_info->border_color.red;
4350 target.green=(MagickRealType) draw_info->border_color.green;
4351 target.blue=(MagickRealType) draw_info->border_color.blue;
4353 (void) FloodfillPaintImage(image,OpacityChannel,draw_info,&target,x,y,
4354 primitive_info->method == FloodfillMethod ? MagickFalse :
4366 for (y=0; y < (long) image->rows; y++)
4371 register PixelPacket
4374 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4376 if (q == (PixelPacket *) NULL)
4378 for (x=0; x < (long) image->columns; x++)
4380 (void) GetFillColor(draw_info,x,y,&pixel);
4381 q->opacity=pixel.opacity;
4384 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4385 if (sync == MagickFalse)
4396 geometry[MaxTextExtent];
4401 if (primitive_info->text == (char *) NULL)
4403 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4404 (void) CloneString(&clone_info->text,primitive_info->text);
4405 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
4406 primitive_info->point.x,primitive_info->point.y);
4407 (void) CloneString(&clone_info->geometry,geometry);
4408 status=AnnotateImage(image,clone_info);
4409 clone_info=DestroyDrawInfo(clone_info);
4412 case ImagePrimitive:
4418 composite_geometry[MaxTextExtent];
4433 if (primitive_info->text == (char *) NULL)
4435 clone_info=AcquireImageInfo();
4436 if (LocaleNCompare(primitive_info->text,"data:",5) == 0)
4437 composite_image=ReadInlineImage(clone_info,primitive_info->text,
4441 (void) CopyMagickString(clone_info->filename,primitive_info->text,
4443 composite_image=ReadImage(clone_info,&image->exception);
4445 clone_info=DestroyImageInfo(clone_info);
4446 if (composite_image == (Image *) NULL)
4448 (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor)
4449 NULL,(void *) NULL);
4450 x1=(long) (primitive_info[1].point.x+0.5);
4451 y1=(long) (primitive_info[1].point.y+0.5);
4452 if (((x1 != 0L) && (x1 != (long) composite_image->columns)) ||
4453 ((y1 != 0L) && (y1 != (long) composite_image->rows)))
4456 geometry[MaxTextExtent];
4461 (void) FormatMagickString(geometry,MaxTextExtent,"%gx%g!",
4462 primitive_info[1].point.x,primitive_info[1].point.y);
4463 composite_image->filter=image->filter;
4464 (void) TransformImage(&composite_image,(char *) NULL,geometry);
4466 if (composite_image->matte == MagickFalse)
4467 (void) SetImageAlphaChannel(composite_image,OpaqueAlphaChannel);
4468 if (draw_info->opacity != OpaqueOpacity)
4469 (void) SetImageOpacity(composite_image,draw_info->opacity);
4470 SetGeometry(image,&geometry);
4471 image->gravity=draw_info->gravity;
4474 (void) FormatMagickString(composite_geometry,MaxTextExtent,
4475 "%lux%lu%+ld%+ld",composite_image->columns,composite_image->rows,
4476 geometry.x,geometry.y);
4477 (void) ParseGravityGeometry(image,composite_geometry,&geometry,
4479 affine=draw_info->affine;
4480 affine.tx=(double) geometry.x;
4481 affine.ty=(double) geometry.y;
4482 composite_image->interpolate=image->interpolate;
4483 if (draw_info->compose == OverCompositeOp)
4484 (void) DrawAffineImage(image,composite_image,&affine);
4486 (void) CompositeImage(image,draw_info->compose,composite_image,
4487 geometry.x,geometry.y);
4488 composite_image=DestroyImage(composite_image);
4500 if (IsEventLogging() != MagickFalse)
4501 LogPrimitiveInfo(primitive_info);
4502 scale=ExpandAffine(&draw_info->affine);
4503 if ((draw_info->dash_pattern != (double *) NULL) &&
4504 (draw_info->dash_pattern[0] != 0.0) &&
4505 ((scale*draw_info->stroke_width) > MagickEpsilon) &&
4506 (draw_info->stroke.opacity != (Quantum) TransparentOpacity))
4511 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4512 clone_info->stroke_width=0.0;
4513 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4514 status=DrawPolygonPrimitive(image,clone_info,primitive_info);
4515 clone_info=DestroyDrawInfo(clone_info);
4516 (void) DrawDashPolygon(draw_info,primitive_info,image);
4519 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
4521 (draw_info->stroke.opacity != (Quantum) TransparentOpacity))
4527 Draw strokes while respecting line cap/join attributes.
4529 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
4531 (primitive_info[i-1].point.x == primitive_info[0].point.x) &&
4532 (primitive_info[i-1].point.y == primitive_info[0].point.y) ?
4533 MagickTrue : MagickFalse;
4534 i=(long) primitive_info[0].coordinates;
4535 if ((((draw_info->linecap == RoundCap) ||
4536 (closed_path != MagickFalse)) &&
4537 (draw_info->linejoin == RoundJoin)) ||
4538 (primitive_info[i].primitive != UndefinedPrimitive))
4540 (void) DrawPolygonPrimitive(image,draw_info,primitive_info);
4543 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4544 clone_info->stroke_width=0.0;
4545 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4546 status=DrawPolygonPrimitive(image,clone_info,primitive_info);
4547 clone_info=DestroyDrawInfo(clone_info);
4548 status|=DrawStrokePolygon(image,draw_info,primitive_info);
4551 status=DrawPolygonPrimitive(image,draw_info,primitive_info);
4555 image_view=DestroyCacheView(image_view);
4556 if (image->debug != MagickFalse)
4557 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-primitive");
4558 return(status != 0 ? MagickTrue : MagickFalse);
4562 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4566 + D r a w S t r o k e P o l y g o n %
4570 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4572 % DrawStrokePolygon() draws a stroked polygon (line, rectangle, ellipse) on
4573 % the image while respecting the line cap and join attributes.
4575 % The format of the DrawStrokePolygon method is:
4577 % MagickBooleanType DrawStrokePolygon(Image *image,
4578 % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4580 % A description of each parameter follows:
4582 % o image: the image.
4584 % o draw_info: the draw info.
4586 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
4591 static void DrawRoundLinecap(Image *image,const DrawInfo *draw_info,
4592 const PrimitiveInfo *primitive_info)
4600 for (i=0; i < 4; i++)
4601 linecap[i]=(*primitive_info);
4602 linecap[0].coordinates=4;
4603 linecap[1].point.x+=(double) (10.0*MagickEpsilon);
4604 linecap[2].point.x+=(double) (10.0*MagickEpsilon);
4605 linecap[2].point.y+=(double) (10.0*MagickEpsilon);
4606 linecap[3].point.y+=(double) (10.0*MagickEpsilon);
4607 linecap[4].primitive=UndefinedPrimitive;
4608 (void) DrawPolygonPrimitive(image,draw_info,linecap);
4611 static MagickBooleanType DrawStrokePolygon(Image *image,
4612 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4624 register const PrimitiveInfo
4629 Draw stroked polygon.
4631 if (image->debug != MagickFalse)
4632 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4633 " begin draw-stroke-polygon");
4634 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4635 clone_info->fill=draw_info->stroke;
4636 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4637 clone_info->stroke_width=0.0;
4638 clone_info->fill_rule=NonZeroRule;
4640 for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=p->coordinates)
4642 stroke_polygon=TraceStrokePolygon(draw_info,p);
4643 status=DrawPolygonPrimitive(image,clone_info,stroke_polygon);
4644 stroke_polygon=(PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon);
4645 q=p+p->coordinates-1;
4646 closed_path=(q->point.x == p->point.x) && (q->point.y == p->point.y) ?
4647 MagickTrue : MagickFalse;
4648 if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse))
4650 DrawRoundLinecap(image,draw_info,p);
4651 DrawRoundLinecap(image,draw_info,q);
4654 clone_info=DestroyDrawInfo(clone_info);
4655 if (image->debug != MagickFalse)
4656 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4657 " end draw-stroke-polygon");
4662 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4666 % G e t A f f i n e M a t r i x %
4670 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4672 % GetAffineMatrix() returns an AffineMatrix initialized to the identity
4675 % The format of the GetAffineMatrix method is:
4677 % void GetAffineMatrix(AffineMatrix *affine_matrix)
4679 % A description of each parameter follows:
4681 % o affine_matrix: the affine matrix.
4684 MagickExport void GetAffineMatrix(AffineMatrix *affine_matrix)
4686 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4687 assert(affine_matrix != (AffineMatrix *) NULL);
4688 (void) ResetMagickMemory(affine_matrix,0,sizeof(*affine_matrix));
4689 affine_matrix->sx=1.0;
4690 affine_matrix->sy=1.0;
4694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4698 + G e t D r a w I n f o %
4702 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4704 % GetDrawInfo() initializes draw_info to default values.
4706 % The format of the GetDrawInfo method is:
4708 % void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info)
4710 % A description of each parameter follows:
4712 % o image_info: the image info..
4714 % o draw_info: the draw info.
4717 MagickExport void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info)
4729 Initialize draw attributes.
4731 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4732 assert(draw_info != (DrawInfo *) NULL);
4733 (void) ResetMagickMemory(draw_info,0,sizeof(*draw_info));
4734 clone_info=CloneImageInfo(image_info);
4735 GetAffineMatrix(&draw_info->affine);
4736 exception=AcquireExceptionInfo();
4737 (void) QueryColorDatabase("#000F",&draw_info->fill,exception);
4738 (void) QueryColorDatabase("#FFF0",&draw_info->stroke,exception);
4739 draw_info->stroke_antialias=clone_info->antialias;
4740 draw_info->stroke_width=1.0;
4741 draw_info->opacity=OpaqueOpacity;
4742 draw_info->fill_rule=EvenOddRule;
4743 draw_info->linecap=ButtCap;
4744 draw_info->linejoin=MiterJoin;
4745 draw_info->miterlimit=10;
4746 draw_info->decorate=NoDecoration;
4747 if (clone_info->font != (char *) NULL)
4748 draw_info->font=AcquireString(clone_info->font);
4749 if (clone_info->density != (char *) NULL)
4750 draw_info->density=AcquireString(clone_info->density);
4751 draw_info->text_antialias=clone_info->antialias;
4752 draw_info->pointsize=12.0;
4753 if (clone_info->pointsize != 0.0)
4754 draw_info->pointsize=clone_info->pointsize;
4755 draw_info->undercolor.opacity=(Quantum) TransparentOpacity;
4756 draw_info->border_color=clone_info->border_color;
4757 draw_info->compose=OverCompositeOp;
4758 if (clone_info->server_name != (char *) NULL)
4759 draw_info->server_name=AcquireString(clone_info->server_name);
4760 draw_info->render=MagickTrue;
4761 draw_info->debug=IsEventLogging();
4762 option=GetImageOption(clone_info,"encoding");
4763 if (option != (const char *) NULL)
4764 (void) CloneString(&draw_info->encoding,option);
4765 option=GetImageOption(clone_info,"kerning");
4766 if (option != (const char *) NULL)
4767 draw_info->kerning=StringToDouble(option);
4768 option=GetImageOption(clone_info,"interline-spacing");
4769 if (option != (const char *) NULL)
4770 draw_info->interline_spacing=StringToDouble(option);
4771 option=GetImageOption(clone_info,"interword-spacing");
4772 if (option != (const char *) NULL)
4773 draw_info->interword_spacing=StringToDouble(option);
4774 option=GetImageOption(clone_info,"fill");
4775 if (option != (const char *) NULL)
4776 (void) QueryColorDatabase(option,&draw_info->fill,exception);
4777 option=GetImageOption(clone_info,"stroke");
4778 if (option != (const char *) NULL)
4779 (void) QueryColorDatabase(option,&draw_info->stroke,exception);
4780 option=GetImageOption(clone_info,"strokewidth");
4781 if (option != (const char *) NULL)
4782 draw_info->stroke_width=StringToDouble(option);
4783 option=GetImageOption(clone_info,"undercolor");
4784 if (option != (const char *) NULL)
4785 (void) QueryColorDatabase(option,&draw_info->undercolor,exception);
4786 option=GetImageOption(clone_info,"gravity");
4787 if (option != (const char *) NULL)
4788 draw_info->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
4789 MagickFalse,option);
4790 exception=DestroyExceptionInfo(exception);
4791 draw_info->signature=MagickSignature;
4792 clone_info=DestroyImageInfo(clone_info);
4796 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4800 + P e r m u t a t e %
4804 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4806 % Permutate() returns the permuation of the (n,k).
4808 % The format of the Permutate method is:
4810 % void Permutate(long n,long k)
4812 % A description of each parameter follows:
4820 static inline MagickRealType Permutate(const long n,const long k)
4829 for (i=k+1; i <= n; i++)
4831 for (i=1; i <= (n-k); i++)
4837 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4841 + T r a c e P r i m i t i v e %
4845 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4847 % TracePrimitive is a collection of methods for generating graphic
4848 % primitives such as arcs, ellipses, paths, etc.
4852 static void TraceArc(PrimitiveInfo *primitive_info,const PointInfo start,
4853 const PointInfo end,const PointInfo degrees)
4859 center.x=0.5*(end.x+start.x);
4860 center.y=0.5*(end.y+start.y);
4861 radii.x=fabs(center.x-start.x);
4862 radii.y=fabs(center.y-start.y);
4863 TraceEllipse(primitive_info,center,radii,degrees);
4866 static void TraceArcPath(PrimitiveInfo *primitive_info,const PointInfo start,
4867 const PointInfo end,const PointInfo arc,const MagickRealType angle,
4868 const MagickBooleanType large_arc,const MagickBooleanType sweep)
4883 register MagickRealType
4887 register PrimitiveInfo
4896 if ((start.x == end.x) && (start.y == end.y))
4898 TracePoint(primitive_info,end);
4901 radii.x=fabs(arc.x);
4902 radii.y=fabs(arc.y);
4903 if ((radii.x == 0.0) || (radii.y == 0.0))
4905 TraceLine(primitive_info,start,end);
4908 cosine=cos(DegreesToRadians(fmod((double) angle,360.0)));
4909 sine=sin(DegreesToRadians(fmod((double) angle,360.0)));
4910 center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2);
4911 center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2);
4912 delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/
4914 if (delta < MagickEpsilon)
4916 TraceLine(primitive_info,start,end);
4921 radii.x*=sqrt((double) delta);
4922 radii.y*=sqrt((double) delta);
4924 points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x);
4925 points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y);
4926 points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x);
4927 points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y);
4928 alpha=points[1].x-points[0].x;
4929 beta=points[1].y-points[0].y;
4930 factor=1.0/(alpha*alpha+beta*beta)-0.25;
4935 factor=sqrt((double) factor);
4936 if (sweep == large_arc)
4939 center.x=(double) ((points[0].x+points[1].x)/2-factor*beta);
4940 center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha);
4941 alpha=atan2(points[0].y-center.y,points[0].x-center.x);
4942 theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha;
4943 if ((theta < 0.0) && (sweep != MagickFalse))
4944 theta+=(MagickRealType) (2.0*MagickPI);
4946 if ((theta > 0.0) && (sweep == MagickFalse))
4947 theta-=(MagickRealType) (2.0*MagickPI);
4948 arc_segments=(unsigned long) ceil(fabs((double) (theta/(0.5*MagickPI+
4951 for (i=0; i < (long) arc_segments; i++)
4953 beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments));
4954 gamma=(8.0/3.0)*sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))*
4955 sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))/
4956 sin(fmod((double) beta,DegreesToRadians(360.0)));
4957 points[0].x=(double) (center.x+cos(fmod((double) (alpha+(double) i*theta/
4958 arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((double) (alpha+
4959 (double) i*theta/arc_segments),DegreesToRadians(360.0))));
4960 points[0].y=(double) (center.y+sin(fmod((double) (alpha+(double) i*theta/
4961 arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((double) (alpha+
4962 (double) i*theta/arc_segments),DegreesToRadians(360.0))));
4963 points[2].x=(double) (center.x+cos(fmod((double) (alpha+(double) (i+1)*
4964 theta/arc_segments),DegreesToRadians(360.0))));
4965 points[2].y=(double) (center.y+sin(fmod((double) (alpha+(double) (i+1)*
4966 theta/arc_segments),DegreesToRadians(360.0))));
4967 points[1].x=(double) (points[2].x+gamma*sin(fmod((double) (alpha+(double)
4968 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
4969 points[1].y=(double) (points[2].y-gamma*cos(fmod((double) (alpha+(double)
4970 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
4971 p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x;
4972 p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y;
4973 (p+1)->point.x=(double) (cosine*radii.x*points[0].x-sine*radii.y*
4975 (p+1)->point.y=(double) (sine*radii.x*points[0].x+cosine*radii.y*
4977 (p+2)->point.x=(double) (cosine*radii.x*points[1].x-sine*radii.y*
4979 (p+2)->point.y=(double) (sine*radii.x*points[1].x+cosine*radii.y*
4981 (p+3)->point.x=(double) (cosine*radii.x*points[2].x-sine*radii.y*
4983 (p+3)->point.y=(double) (sine*radii.x*points[2].x+cosine*radii.y*
4985 if (i == (long) (arc_segments-1))
4990 primitive_info->coordinates=(unsigned long) (p-primitive_info);
4991 for (i=0; i < (long) primitive_info->coordinates; i++)
4993 p->primitive=primitive_info->primitive;
4998 static void TraceBezier(PrimitiveInfo *primitive_info,
4999 const unsigned long number_coordinates)
5015 register PrimitiveInfo
5023 Allocate coeficients.
5025 quantum=number_coordinates;
5026 for (i=0; i < (long) number_coordinates; i++)
5028 for (j=i+1; j < (long) number_coordinates; j++)
5030 alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x);
5031 if (alpha > (MagickRealType) quantum)
5032 quantum=(unsigned long) alpha;
5033 alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y);
5034 if (alpha > (MagickRealType) quantum)
5035 quantum=(unsigned long) alpha;
5038 quantum=(unsigned long) MagickMin((double) quantum/number_coordinates,
5039 (double) BezierQuantum);
5040 control_points=quantum*number_coordinates;
5041 coefficients=(MagickRealType *) AcquireQuantumMemory((size_t)
5042 number_coordinates,sizeof(*coefficients));
5043 points=(PointInfo *) AcquireQuantumMemory((size_t) control_points,
5045 if ((coefficients == (MagickRealType *) NULL) ||
5046 (points == (PointInfo *) NULL))
5047 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
5049 Compute bezier points.
5051 end=primitive_info[number_coordinates-1].point;
5052 for (i=0; i < (long) number_coordinates; i++)
5053 coefficients[i]=Permutate((long) number_coordinates-1,i);
5055 for (i=0; i < (long) control_points; i++)
5060 alpha=pow((double) (1.0-weight),(double) number_coordinates-1.0);
5061 for (j=0; j < (long) number_coordinates; j++)
5063 point.x+=alpha*coefficients[j]*p->point.x;
5064 point.y+=alpha*coefficients[j]*p->point.y;
5065 alpha*=weight/(1.0-weight);
5069 weight+=1.0/control_points;
5072 Bezier curves are just short segmented polys.
5075 for (i=0; i < (long) control_points; i++)
5077 TracePoint(p,points[i]);
5082 primitive_info->coordinates=(unsigned long) (p-primitive_info);
5083 for (i=0; i < (long) primitive_info->coordinates; i++)
5085 p->primitive=primitive_info->primitive;
5088 points=(PointInfo *) RelinquishMagickMemory(points);
5089 coefficients=(MagickRealType *) RelinquishMagickMemory(coefficients);
5092 static void TraceCircle(PrimitiveInfo *primitive_info,const PointInfo start,
5093 const PointInfo end)
5104 alpha=end.x-start.x;
5106 radius=hypot((double) alpha,(double) beta);
5107 offset.x=(double) radius;
5108 offset.y=(double) radius;
5111 TraceEllipse(primitive_info,start,offset,degrees);
5114 static void TraceEllipse(PrimitiveInfo *primitive_info,const PointInfo start,
5115 const PointInfo stop,const PointInfo degrees)
5126 register PrimitiveInfo
5133 Ellipses are just short segmented polys.
5135 if ((stop.x == 0.0) && (stop.y == 0.0))
5137 TracePoint(primitive_info,start);
5140 delta=2.0/MagickMax(stop.x,stop.y);
5141 step=(MagickRealType) (MagickPI/8.0);
5142 if (delta < (MagickPI/8.0))
5143 step=MagickPI/(4*(MagickPI/delta/2+0.5));
5144 angle.x=DegreesToRadians(degrees.x);
5146 while (y < degrees.x)
5148 angle.y=(double) (DegreesToRadians(y)-MagickEpsilon);
5149 for (p=primitive_info; angle.x < angle.y; angle.x+=step)
5151 point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*stop.x+start.x;
5152 point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*stop.y+start.y;
5153 TracePoint(p,point);
5156 point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*stop.x+start.x;
5157 point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*stop.y+start.y;
5158 TracePoint(p,point);
5160 primitive_info->coordinates=(unsigned long) (p-primitive_info);
5161 for (i=0; i < (long) primitive_info->coordinates; i++)
5163 p->primitive=primitive_info->primitive;
5168 static void TraceLine(PrimitiveInfo *primitive_info,const PointInfo start,
5169 const PointInfo end)
5171 TracePoint(primitive_info,start);
5172 if ((fabs(start.x-end.x) <= MagickEpsilon) &&
5173 (fabs(start.y-end.y) <= MagickEpsilon))
5175 primitive_info->primitive=PointPrimitive;
5176 primitive_info->coordinates=1;
5179 TracePoint(primitive_info+1,end);
5180 (primitive_info+1)->primitive=primitive_info->primitive;
5181 primitive_info->coordinates=2;
5184 static unsigned long TracePath(PrimitiveInfo *primitive_info,const char *path)
5187 token[MaxTextExtent];
5209 register PrimitiveInfo
5224 number_coordinates=0;
5226 primitive_type=primitive_info->primitive;
5228 for (p=path; *p != '\0'; )
5230 while (isspace((int) ((unsigned char) *p)) != 0)
5234 last_attribute=attribute;
5235 attribute=(int) (*p++);
5256 GetMagickToken(p,&p,token);
5258 GetMagickToken(p,&p,token);
5259 arc.x=StringToDouble(token);
5260 GetMagickToken(p,&p,token);
5262 GetMagickToken(p,&p,token);
5263 arc.y=StringToDouble(token);
5264 GetMagickToken(p,&p,token);
5266 GetMagickToken(p,&p,token);
5267 angle=StringToDouble(token);
5268 GetMagickToken(p,&p,token);
5270 GetMagickToken(p,&p,token);
5271 large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
5272 GetMagickToken(p,&p,token);
5274 GetMagickToken(p,&p,token);
5275 sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
5276 GetMagickToken(p,&p,token);
5278 GetMagickToken(p,&p,token);
5279 x=StringToDouble(token);
5280 GetMagickToken(p,&p,token);
5282 GetMagickToken(p,&p,token);
5283 y=StringToDouble(token);
5284 end.x=(double) (attribute == (int) 'A' ? x : point.x+x);
5285 end.y=(double) (attribute == (int) 'A' ? y : point.y+y);
5286 TraceArcPath(q,point,end,arc,angle,large_arc,sweep);
5289 } while (IsPoint(p) != MagickFalse);
5296 Compute bezier points.
5301 for (i=1; i < 4; i++)
5303 GetMagickToken(p,&p,token);
5305 GetMagickToken(p,&p,token);
5306 x=StringToDouble(token);
5307 GetMagickToken(p,&p,token);
5309 GetMagickToken(p,&p,token);
5310 y=StringToDouble(token);
5311 end.x=(double) (attribute == (int) 'C' ? x : point.x+x);
5312 end.y=(double) (attribute == (int) 'C' ? y : point.y+y);
5315 for (i=0; i < 4; i++)
5316 (q+i)->point=points[i];
5320 } while (IsPoint(p) != MagickFalse);
5328 GetMagickToken(p,&p,token);
5330 GetMagickToken(p,&p,token);
5331 x=StringToDouble(token);
5332 point.x=(double) (attribute == (int) 'H' ? x: point.x+x);
5333 TracePoint(q,point);
5335 } while (IsPoint(p) != MagickFalse);
5343 GetMagickToken(p,&p,token);
5345 GetMagickToken(p,&p,token);
5346 x=StringToDouble(token);
5347 GetMagickToken(p,&p,token);
5349 GetMagickToken(p,&p,token);
5350 y=StringToDouble(token);
5351 point.x=(double) (attribute == (int) 'L' ? x : point.x+x);
5352 point.y=(double) (attribute == (int) 'L' ? y : point.y+y);
5353 TracePoint(q,point);
5355 } while (IsPoint(p) != MagickFalse);
5361 if (q != primitive_info)
5363 primitive_info->coordinates=(unsigned long) (q-primitive_info);
5364 number_coordinates+=primitive_info->coordinates;
5370 GetMagickToken(p,&p,token);
5372 GetMagickToken(p,&p,token);
5373 x=StringToDouble(token);
5374 GetMagickToken(p,&p,token);
5376 GetMagickToken(p,&p,token);
5377 y=StringToDouble(token);
5378 point.x=(double) (attribute == (int) 'M' ? x : point.x+x);
5379 point.y=(double) (attribute == (int) 'M' ? y : point.y+y);
5383 TracePoint(q,point);
5385 if (attribute == (int) 'M')
5387 TracePoint(q,point);
5390 } while (IsPoint(p) != MagickFalse);
5397 Compute bezier points.
5402 for (i=1; i < 3; i++)
5404 GetMagickToken(p,&p,token);
5406 GetMagickToken(p,&p,token);
5407 x=StringToDouble(token);
5408 GetMagickToken(p,&p,token);
5410 GetMagickToken(p,&p,token);
5411 y=StringToDouble(token);
5414 end.x=(double) (attribute == (int) 'Q' ? x : point.x+x);
5415 end.y=(double) (attribute == (int) 'Q' ? y : point.y+y);
5418 for (i=0; i < 3; i++)
5419 (q+i)->point=points[i];
5423 } while (IsPoint(p) != MagickFalse);
5430 Compute bezier points.
5434 points[0]=points[3];
5435 points[1].x=2.0*points[3].x-points[2].x;
5436 points[1].y=2.0*points[3].y-points[2].y;
5437 for (i=2; i < 4; i++)
5439 GetMagickToken(p,&p,token);
5441 GetMagickToken(p,&p,token);
5442 x=StringToDouble(token);
5443 GetMagickToken(p,&p,token);
5445 GetMagickToken(p,&p,token);
5446 y=StringToDouble(token);
5449 end.x=(double) (attribute == (int) 'S' ? x : point.x+x);
5450 end.y=(double) (attribute == (int) 'S' ? y : point.y+y);
5453 if (strchr("CcSs",last_attribute) == (char *) NULL)
5455 points[0]=points[2];
5456 points[1]=points[3];
5458 for (i=0; i < 4; i++)
5459 (q+i)->point=points[i];
5463 } while (IsPoint(p) != MagickFalse);
5470 Compute bezier points.
5474 points[0]=points[2];
5475 points[1].x=2.0*points[2].x-points[1].x;
5476 points[1].y=2.0*points[2].y-points[1].y;
5477 for (i=2; i < 3; i++)
5479 GetMagickToken(p,&p,token);
5481 GetMagickToken(p,&p,token);
5482 x=StringToDouble(token);
5483 GetMagickToken(p,&p,token);
5485 GetMagickToken(p,&p,token);
5486 y=StringToDouble(token);
5487 end.x=(double) (attribute == (int) 'T' ? x : point.x+x);
5488 end.y=(double) (attribute == (int) 'T' ? y : point.y+y);
5491 if (strchr("QqTt",last_attribute) == (char *) NULL)
5493 points[0]=points[2];
5494 points[1]=points[3];
5496 for (i=0; i < 3; i++)
5497 (q+i)->point=points[i];
5501 } while (IsPoint(p) != MagickFalse);
5509 GetMagickToken(p,&p,token);
5511 GetMagickToken(p,&p,token);
5512 y=StringToDouble(token);
5513 point.y=(double) (attribute == (int) 'V' ? y : point.y+y);
5514 TracePoint(q,point);
5516 } while (IsPoint(p) != MagickFalse);
5523 TracePoint(q,point);
5525 primitive_info->coordinates=(unsigned long) (q-primitive_info);
5526 number_coordinates+=primitive_info->coordinates;
5533 if (isalpha((int) ((unsigned char) attribute)) != 0)
5534 (void) fprintf(stderr,"attribute not recognized: %c\n",attribute);
5539 primitive_info->coordinates=(unsigned long) (q-primitive_info);
5540 number_coordinates+=primitive_info->coordinates;
5541 for (i=0; i < (long) number_coordinates; i++)
5544 q->primitive=primitive_type;
5546 q->method=FillToBorderMethod;
5549 return(number_coordinates);
5552 static void TraceRectangle(PrimitiveInfo *primitive_info,const PointInfo start,
5553 const PointInfo end)
5558 register PrimitiveInfo
5565 TracePoint(p,start);
5569 TracePoint(p,point);
5575 TracePoint(p,point);
5577 TracePoint(p,start);
5579 primitive_info->coordinates=(unsigned long) (p-primitive_info);
5580 for (i=0; i < (long) primitive_info->coordinates; i++)
5582 p->primitive=primitive_info->primitive;
5587 static void TraceRoundRectangle(PrimitiveInfo *primitive_info,
5588 const PointInfo start,const PointInfo end,PointInfo arc)
5595 register PrimitiveInfo
5602 offset.x=fabs(end.x-start.x);
5603 offset.y=fabs(end.y-start.y);
5604 if (arc.x > (0.5*offset.x))
5606 if (arc.y > (0.5*offset.y))
5608 point.x=start.x+offset.x-arc.x;
5609 point.y=start.y+arc.y;
5612 TraceEllipse(p,point,arc,degrees);
5614 point.x=start.x+offset.x-arc.x;
5615 point.y=start.y+offset.y-arc.y;
5618 TraceEllipse(p,point,arc,degrees);
5620 point.x=start.x+arc.x;
5621 point.y=start.y+offset.y-arc.y;
5624 TraceEllipse(p,point,arc,degrees);
5626 point.x=start.x+arc.x;
5627 point.y=start.y+arc.y;
5630 TraceEllipse(p,point,arc,degrees);
5632 TracePoint(p,primitive_info->point);
5634 primitive_info->coordinates=(unsigned long) (p-primitive_info);
5635 for (i=0; i < (long) primitive_info->coordinates; i++)
5637 p->primitive=primitive_info->primitive;
5642 static void TraceSquareLinecap(PrimitiveInfo *primitive_info,
5643 const unsigned long number_vertices,const MagickRealType offset)
5651 register MagickRealType
5660 for (i=1; i < (long) number_vertices; i++)
5662 dx=primitive_info[0].point.x-primitive_info[i].point.x;
5663 dy=primitive_info[0].point.y-primitive_info[i].point.y;
5664 if ((fabs((double) dx) >= MagickEpsilon) ||
5665 (fabs((double) dy) >= MagickEpsilon))
5668 if (i == (long) number_vertices)
5669 i=(long) number_vertices-1L;
5670 distance=hypot((double) dx,(double) dy);
5671 primitive_info[0].point.x=(double) (primitive_info[i].point.x+
5672 dx*(distance+offset)/distance);
5673 primitive_info[0].point.y=(double) (primitive_info[i].point.y+
5674 dy*(distance+offset)/distance);
5675 for (j=(long) number_vertices-2; j >= 0; j--)
5677 dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x;
5678 dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y;
5679 if ((fabs((double) dx) >= MagickEpsilon) ||
5680 (fabs((double) dy) >= MagickEpsilon))
5683 distance=hypot((double) dx,(double) dy);
5684 primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+
5685 dx*(distance+offset)/distance);
5686 primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+
5687 dy*(distance+offset)/distance);
5690 static PrimitiveInfo *TraceStrokePolygon(const DrawInfo *draw_info,
5691 const PrimitiveInfo *primitive_info)
5693 typedef struct _LineSegment
5745 number_vertices=primitive_info->coordinates;
5746 max_strokes=2*number_vertices+6*BezierQuantum+360;
5747 path_p=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes,
5749 path_q=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes,
5751 polygon_primitive=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
5752 number_vertices+2UL,sizeof(*polygon_primitive));
5753 if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL) ||
5754 (polygon_primitive == (PrimitiveInfo *) NULL))
5755 return((PrimitiveInfo *) NULL);
5756 (void) CopyMagickMemory(polygon_primitive,primitive_info,(size_t)
5757 number_vertices*sizeof(*polygon_primitive));
5759 (primitive_info[number_vertices-1].point.x == primitive_info[0].point.x) &&
5760 (primitive_info[number_vertices-1].point.y == primitive_info[0].point.y) ?
5761 MagickTrue : MagickFalse;
5762 if ((draw_info->linejoin == RoundJoin) ||
5763 ((draw_info->linejoin == MiterJoin) && (closed_path != MagickFalse)))
5765 polygon_primitive[number_vertices]=primitive_info[1];
5768 polygon_primitive[number_vertices].primitive=UndefinedPrimitive;
5770 Compute the slope for the first line segment, p.
5774 for (n=1; n < (long) number_vertices; n++)
5776 dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x;
5777 dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y;
5778 if ((fabs(dx.p) >= MagickEpsilon) || (fabs(dy.p) >= MagickEpsilon))
5781 if (n == (long) number_vertices)
5782 n=(long) number_vertices-1L;
5784 inverse_slope.p=0.0;
5785 if (fabs(dx.p) <= MagickEpsilon)
5788 slope.p=dy.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5790 slope.p=dy.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5793 if (fabs(dy.p) <= MagickEpsilon)
5796 inverse_slope.p=dx.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5798 inverse_slope.p=dx.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5803 inverse_slope.p=(-1.0/slope.p);
5805 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5806 miterlimit=(MagickRealType) (draw_info->miterlimit*draw_info->miterlimit*
5808 if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse))
5809 TraceSquareLinecap(polygon_primitive,number_vertices,mid);
5810 offset.x=sqrt((double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0)));
5811 offset.y=(double) (offset.x*inverse_slope.p);
5812 if ((dy.p*offset.x-dx.p*offset.y) > 0.0)
5814 box_p[0].x=polygon_primitive[0].point.x-offset.x;
5815 box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p;
5816 box_p[1].x=polygon_primitive[n].point.x-offset.x;
5817 box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p;
5818 box_q[0].x=polygon_primitive[0].point.x+offset.x;
5819 box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p;
5820 box_q[1].x=polygon_primitive[n].point.x+offset.x;
5821 box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p;
5825 box_p[0].x=polygon_primitive[0].point.x+offset.x;
5826 box_p[0].y=polygon_primitive[0].point.y+offset.y;
5827 box_p[1].x=polygon_primitive[n].point.x+offset.x;
5828 box_p[1].y=polygon_primitive[n].point.y+offset.y;
5829 box_q[0].x=polygon_primitive[0].point.x-offset.x;
5830 box_q[0].y=polygon_primitive[0].point.y-offset.y;
5831 box_q[1].x=polygon_primitive[n].point.x-offset.x;
5832 box_q[1].y=polygon_primitive[n].point.y-offset.y;
5835 Create strokes for the line join attribute: bevel, miter, round.
5839 path_q[p++]=box_q[0];
5840 path_p[q++]=box_p[0];
5841 for (i=(long) n+1; i < (long) number_vertices; i++)
5844 Compute the slope for this line segment, q.
5846 dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x;
5847 dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y;
5848 dot_product=dx.q*dx.q+dy.q*dy.q;
5849 if (dot_product < 0.25)
5852 inverse_slope.q=0.0;
5853 if (fabs(dx.q) < MagickEpsilon)
5856 slope.q=dy.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5858 slope.q=dy.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5861 if (fabs(dy.q) <= MagickEpsilon)
5864 inverse_slope.q=dx.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5866 inverse_slope.q=dx.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5871 inverse_slope.q=(-1.0/slope.q);
5873 offset.x=sqrt((double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0)));
5874 offset.y=(double) (offset.x*inverse_slope.q);
5875 dot_product=dy.q*offset.x-dx.q*offset.y;
5876 if (dot_product > 0.0)
5878 box_p[2].x=polygon_primitive[n].point.x-offset.x;
5879 box_p[2].y=polygon_primitive[n].point.y-offset.y;
5880 box_p[3].x=polygon_primitive[i].point.x-offset.x;
5881 box_p[3].y=polygon_primitive[i].point.y-offset.y;
5882 box_q[2].x=polygon_primitive[n].point.x+offset.x;
5883 box_q[2].y=polygon_primitive[n].point.y+offset.y;
5884 box_q[3].x=polygon_primitive[i].point.x+offset.x;
5885 box_q[3].y=polygon_primitive[i].point.y+offset.y;
5889 box_p[2].x=polygon_primitive[n].point.x+offset.x;
5890 box_p[2].y=polygon_primitive[n].point.y+offset.y;
5891 box_p[3].x=polygon_primitive[i].point.x+offset.x;
5892 box_p[3].y=polygon_primitive[i].point.y+offset.y;
5893 box_q[2].x=polygon_primitive[n].point.x-offset.x;
5894 box_q[2].y=polygon_primitive[n].point.y-offset.y;
5895 box_q[3].x=polygon_primitive[i].point.x-offset.x;
5896 box_q[3].y=polygon_primitive[i].point.y-offset.y;
5898 if (fabs((double) (slope.p-slope.q)) <= MagickEpsilon)
5905 box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+
5906 box_p[3].y)/(slope.p-slope.q));
5907 box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y);
5908 box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+
5909 box_q[3].y)/(slope.p-slope.q));
5910 box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y);
5912 if (q >= (long) (max_strokes-6*BezierQuantum-360))
5914 max_strokes+=6*BezierQuantum+360;
5915 path_p=(PointInfo *) ResizeQuantumMemory(path_p,(size_t) max_strokes,
5917 path_q=(PointInfo *) ResizeQuantumMemory(path_q,(size_t) max_strokes,
5919 if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL))
5921 polygon_primitive=(PrimitiveInfo *)
5922 RelinquishMagickMemory(polygon_primitive);
5923 return((PrimitiveInfo *) NULL);
5926 dot_product=dx.q*dy.p-dx.p*dy.q;
5927 if (dot_product <= 0.0)
5928 switch (draw_info->linejoin)
5932 path_q[q++]=box_q[1];
5933 path_q[q++]=box_q[2];
5934 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5935 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5936 if (dot_product <= miterlimit)
5937 path_p[p++]=box_p[4];
5940 path_p[p++]=box_p[1];
5941 path_p[p++]=box_p[2];
5947 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5948 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5949 if (dot_product <= miterlimit)
5951 path_q[q++]=box_q[4];
5952 path_p[p++]=box_p[4];
5956 path_q[q++]=box_q[1];
5957 path_q[q++]=box_q[2];
5958 path_p[p++]=box_p[1];
5959 path_p[p++]=box_p[2];
5965 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5966 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5967 if (dot_product <= miterlimit)
5968 path_p[p++]=box_p[4];
5971 path_p[p++]=box_p[1];
5972 path_p[p++]=box_p[2];
5974 center=polygon_primitive[n].point;
5975 theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x);
5976 theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x);
5977 if (theta.q < theta.p)
5978 theta.q+=(MagickRealType) (2.0*MagickPI);
5979 arc_segments=(unsigned long) ceil((double) ((theta.q-theta.p)/
5980 (2.0*sqrt((double) (1.0/mid)))));
5981 path_q[q].x=box_q[1].x;
5982 path_q[q].y=box_q[1].y;
5984 for (j=1; j < (long) arc_segments; j++)
5986 delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments);
5987 path_q[q].x=(double) (center.x+mid*cos(fmod((double)
5988 (theta.p+delta_theta),DegreesToRadians(360.0))));
5989 path_q[q].y=(double) (center.y+mid*sin(fmod((double)
5990 (theta.p+delta_theta),DegreesToRadians(360.0))));
5993 path_q[q++]=box_q[2];
6000 switch (draw_info->linejoin)
6004 path_p[p++]=box_p[1];
6005 path_p[p++]=box_p[2];
6006 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6007 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6008 if (dot_product <= miterlimit)
6009 path_q[q++]=box_q[4];
6012 path_q[q++]=box_q[1];
6013 path_q[q++]=box_q[2];
6019 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6020 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6021 if (dot_product <= miterlimit)
6023 path_q[q++]=box_q[4];
6024 path_p[p++]=box_p[4];
6028 path_q[q++]=box_q[1];
6029 path_q[q++]=box_q[2];
6030 path_p[p++]=box_p[1];
6031 path_p[p++]=box_p[2];
6037 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6038 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6039 if (dot_product <= miterlimit)
6040 path_q[q++]=box_q[4];
6043 path_q[q++]=box_q[1];
6044 path_q[q++]=box_q[2];
6046 center=polygon_primitive[n].point;
6047 theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x);
6048 theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x);
6049 if (theta.p < theta.q)
6050 theta.p+=(MagickRealType) (2.0*MagickPI);
6051 arc_segments=(unsigned long) ceil((double) ((theta.p-theta.q)/
6052 (2.0*sqrt((double) (1.0/mid)))));
6053 path_p[p++]=box_p[1];
6054 for (j=1; j < (long) arc_segments; j++)
6056 delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments);
6057 path_p[p].x=(double) (center.x+mid*cos(fmod((double)
6058 (theta.p+delta_theta),DegreesToRadians(360.0))));
6059 path_p[p].y=(double) (center.y+mid*sin(fmod((double)
6060 (theta.p+delta_theta),DegreesToRadians(360.0))));
6063 path_p[p++]=box_p[2];
6070 inverse_slope.p=inverse_slope.q;
6079 path_p[p++]=box_p[1];
6080 path_q[q++]=box_q[1];
6082 Trace stroked polygon.
6084 stroke_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
6085 (p+q+2UL*closed_path+2UL),sizeof(*stroke_polygon));
6086 if (stroke_polygon != (PrimitiveInfo *) NULL)
6088 for (i=0; i < (long) p; i++)
6090 stroke_polygon[i]=polygon_primitive[0];
6091 stroke_polygon[i].point=path_p[i];
6093 if (closed_path != MagickFalse)
6095 stroke_polygon[i]=polygon_primitive[0];
6096 stroke_polygon[i].point=stroke_polygon[0].point;
6099 for ( ; i < (long) (p+q+closed_path); i++)
6101 stroke_polygon[i]=polygon_primitive[0];
6102 stroke_polygon[i].point=path_q[p+q+closed_path-(i+1)];
6104 if (closed_path != MagickFalse)
6106 stroke_polygon[i]=polygon_primitive[0];
6107 stroke_polygon[i].point=stroke_polygon[p+closed_path].point;
6110 stroke_polygon[i]=polygon_primitive[0];
6111 stroke_polygon[i].point=stroke_polygon[0].point;
6113 stroke_polygon[i].primitive=UndefinedPrimitive;
6114 stroke_polygon[0].coordinates=(unsigned long) (p+q+2*closed_path+1);
6116 path_p=(PointInfo *) RelinquishMagickMemory(path_p);
6117 path_q=(PointInfo *) RelinquishMagickMemory(path_q);
6118 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive);
6119 return(stroke_polygon);