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: %.15g,%.15g - %.15g,%.15g",p->bounds.x1,p->bounds.y1,
425 p->bounds.x2,p->bounds.y2);
426 for (j=0; j < (long) p->number_points; j++)
427 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.15g,%.15g",
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 " %.15g,%.15g %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,
2377 "%.15gx%.15g%+.15g%+.15g",
2378 MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0),
2379 MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0),
2380 bounds.x1,bounds.y1);
2381 (void) SetImageArtifact(image,key,geometry);
2382 GetMagickToken(q,&q,token);
2385 if (LocaleCompare("pattern",token) == 0)
2390 GetMagickToken(q,&q,token);
2391 (void) CopyMagickString(name,token,MaxTextExtent);
2392 GetMagickToken(q,&q,token);
2393 bounds.x=(long) (StringToDouble(token)+0.5);
2394 GetMagickToken(q,&q,token);
2396 GetMagickToken(q,&q,token);
2397 bounds.y=(long) (StringToDouble(token)+0.5);
2398 GetMagickToken(q,&q,token);
2400 GetMagickToken(q,&q,token);
2401 bounds.width=(unsigned long) (StringToDouble(token)+0.5);
2402 GetMagickToken(q,&q,token);
2404 GetMagickToken(q,&q,token);
2405 bounds.height=(unsigned long) (StringToDouble(token)+0.5);
2406 for (p=q; *q != '\0'; )
2408 GetMagickToken(q,&q,token);
2409 if (LocaleCompare(token,"pop") != 0)
2411 GetMagickToken(q,(const char **) NULL,token);
2412 if (LocaleCompare(token,"pattern") != 0)
2416 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2417 (void) FormatMagickString(key,MaxTextExtent,"%s",name);
2418 (void) SetImageArtifact(image,key,token);
2419 (void) FormatMagickString(key,MaxTextExtent,"%s-geometry",name);
2420 (void) FormatMagickString(geometry,MaxTextExtent,
2421 "%lux%lu%+ld%+ld",bounds.width,bounds.height,bounds.x,
2423 (void) SetImageArtifact(image,key,geometry);
2424 GetMagickToken(q,&q,token);
2427 if (LocaleCompare("graphic-context",token) == 0)
2430 graphic_context=(DrawInfo **) ResizeQuantumMemory(
2431 graphic_context,(size_t) (n+1),sizeof(*graphic_context));
2432 if (graphic_context == (DrawInfo **) NULL)
2434 (void) ThrowMagickException(&image->exception,
2435 GetMagickModule(),ResourceLimitError,
2436 "MemoryAllocationFailed","`%s'",image->filename);
2439 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,
2440 graphic_context[n-1]);
2443 if (LocaleCompare("defs",token) == 0)
2454 if (LocaleCompare("rectangle",keyword) == 0)
2456 primitive_type=RectanglePrimitive;
2459 if (LocaleCompare("rotate",keyword) == 0)
2461 GetMagickToken(q,&q,token);
2462 angle=StringToDouble(token);
2463 affine.sx=cos(DegreesToRadians(fmod((double) angle,360.0)));
2464 affine.rx=sin(DegreesToRadians(fmod((double) angle,360.0)));
2465 affine.ry=(-sin(DegreesToRadians(fmod((double) angle,360.0))));
2466 affine.sy=cos(DegreesToRadians(fmod((double) angle,360.0)));
2469 if (LocaleCompare("roundRectangle",keyword) == 0)
2471 primitive_type=RoundRectanglePrimitive;
2480 if (LocaleCompare("scale",keyword) == 0)
2482 GetMagickToken(q,&q,token);
2483 affine.sx=StringToDouble(token);
2484 GetMagickToken(q,&q,token);
2486 GetMagickToken(q,&q,token);
2487 affine.sy=StringToDouble(token);
2490 if (LocaleCompare("skewX",keyword) == 0)
2492 GetMagickToken(q,&q,token);
2493 angle=StringToDouble(token);
2494 affine.ry=sin(DegreesToRadians(angle));
2497 if (LocaleCompare("skewY",keyword) == 0)
2499 GetMagickToken(q,&q,token);
2500 angle=StringToDouble(token);
2501 affine.rx=(-tan(DegreesToRadians(angle)/2.0));
2504 if (LocaleCompare("stop-color",keyword) == 0)
2509 GetMagickToken(q,&q,token);
2510 (void) QueryColorDatabase(token,&stop_color,&image->exception);
2511 (void) GradientImage(image,LinearGradient,ReflectSpread,
2512 &start_color,&stop_color);
2513 start_color=stop_color;
2514 GetMagickToken(q,&q,token);
2517 if (LocaleCompare("stroke",keyword) == 0)
2519 GetMagickToken(q,&q,token);
2520 (void) FormatMagickString(pattern,MaxTextExtent,"%s",token);
2521 if (GetImageArtifact(image,pattern) != (const char *) NULL)
2522 (void) DrawPatternPath(image,draw_info,token,
2523 &graphic_context[n]->stroke_pattern);
2526 status=QueryColorDatabase(token,&graphic_context[n]->stroke,
2528 if (status == MagickFalse)
2533 pattern_info=AcquireImageInfo();
2534 (void) CopyMagickString(pattern_info->filename,token,
2536 graphic_context[n]->stroke_pattern=
2537 ReadImage(pattern_info,&image->exception);
2538 CatchException(&image->exception);
2539 pattern_info=DestroyImageInfo(pattern_info);
2544 if (LocaleCompare("stroke-antialias",keyword) == 0)
2546 GetMagickToken(q,&q,token);
2547 graphic_context[n]->stroke_antialias=
2548 StringToLong(token) != 0 ? MagickTrue : MagickFalse;
2551 if (LocaleCompare("stroke-dasharray",keyword) == 0)
2553 if (graphic_context[n]->dash_pattern != (double *) NULL)
2554 graphic_context[n]->dash_pattern=(double *)
2555 RelinquishMagickMemory(graphic_context[n]->dash_pattern);
2556 if (IsPoint(q) != MagickFalse)
2562 GetMagickToken(p,&p,token);
2564 GetMagickToken(p,&p,token);
2565 for (x=0; IsPoint(token) != MagickFalse; x++)
2567 GetMagickToken(p,&p,token);
2569 GetMagickToken(p,&p,token);
2571 graphic_context[n]->dash_pattern=(double *)
2572 AcquireQuantumMemory((size_t) (2UL*x+1UL),
2573 sizeof(*graphic_context[n]->dash_pattern));
2574 if (graphic_context[n]->dash_pattern == (double *) NULL)
2576 (void) ThrowMagickException(&image->exception,
2577 GetMagickModule(),ResourceLimitError,
2578 "MemoryAllocationFailed","`%s'",image->filename);
2581 for (j=0; j < x; j++)
2583 GetMagickToken(q,&q,token);
2585 GetMagickToken(q,&q,token);
2586 graphic_context[n]->dash_pattern[j]=StringToDouble(token);
2588 if ((x & 0x01) != 0)
2589 for ( ; j < (2*x); j++)
2590 graphic_context[n]->dash_pattern[j]=
2591 graphic_context[n]->dash_pattern[j-x];
2592 graphic_context[n]->dash_pattern[j]=0.0;
2595 GetMagickToken(q,&q,token);
2598 if (LocaleCompare("stroke-dashoffset",keyword) == 0)
2600 GetMagickToken(q,&q,token);
2601 graphic_context[n]->dash_offset=StringToDouble(token);
2604 if (LocaleCompare("stroke-linecap",keyword) == 0)
2609 GetMagickToken(q,&q,token);
2610 linecap=ParseMagickOption(MagickLineCapOptions,MagickFalse,token);
2616 graphic_context[n]->linecap=(LineCap) linecap;
2619 if (LocaleCompare("stroke-linejoin",keyword) == 0)
2624 GetMagickToken(q,&q,token);
2625 linejoin=ParseMagickOption(MagickLineJoinOptions,MagickFalse,token);
2631 graphic_context[n]->linejoin=(LineJoin) linejoin;
2634 if (LocaleCompare("stroke-miterlimit",keyword) == 0)
2636 GetMagickToken(q,&q,token);
2637 graphic_context[n]->miterlimit=StringToUnsignedLong(token);
2640 if (LocaleCompare("stroke-opacity",keyword) == 0)
2642 GetMagickToken(q,&q,token);
2643 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2644 graphic_context[n]->stroke.opacity=RoundToQuantum((MagickRealType)
2645 QuantumRange*(1.0-factor*StringToDouble(token)));
2648 if (LocaleCompare("stroke-width",keyword) == 0)
2650 GetMagickToken(q,&q,token);
2651 graphic_context[n]->stroke_width=StringToDouble(token);
2660 if (LocaleCompare("text",keyword) == 0)
2662 primitive_type=TextPrimitive;
2665 if (LocaleCompare("text-align",keyword) == 0)
2670 GetMagickToken(q,&q,token);
2671 align=ParseMagickOption(MagickAlignOptions,MagickFalse,token);
2677 graphic_context[n]->align=(AlignType) align;
2680 if (LocaleCompare("text-anchor",keyword) == 0)
2685 GetMagickToken(q,&q,token);
2686 align=ParseMagickOption(MagickAlignOptions,MagickFalse,token);
2692 graphic_context[n]->align=(AlignType) align;
2695 if (LocaleCompare("text-antialias",keyword) == 0)
2697 GetMagickToken(q,&q,token);
2698 graphic_context[n]->text_antialias=
2699 StringToLong(token) != 0 ? MagickTrue : MagickFalse;
2702 if (LocaleCompare("text-undercolor",keyword) == 0)
2704 GetMagickToken(q,&q,token);
2705 (void) QueryColorDatabase(token,&graphic_context[n]->undercolor,
2709 if (LocaleCompare("translate",keyword) == 0)
2711 GetMagickToken(q,&q,token);
2712 affine.tx=StringToDouble(token);
2713 GetMagickToken(q,&q,token);
2715 GetMagickToken(q,&q,token);
2716 affine.ty=StringToDouble(token);
2725 if (LocaleCompare("viewbox",keyword) == 0)
2727 GetMagickToken(q,&q,token);
2728 graphic_context[n]->viewbox.x=(long) (StringToDouble(token)+0.5);
2729 GetMagickToken(q,&q,token);
2731 GetMagickToken(q,&q,token);
2732 graphic_context[n]->viewbox.y=(long) (StringToDouble(token)+0.5);
2733 GetMagickToken(q,&q,token);
2735 GetMagickToken(q,&q,token);
2736 graphic_context[n]->viewbox.width=(unsigned long) (StringToDouble(token)+0.5);
2737 GetMagickToken(q,&q,token);
2739 GetMagickToken(q,&q,token);
2740 graphic_context[n]->viewbox.height=(unsigned long) (StringToDouble(token)+
2753 if (status == MagickFalse)
2755 if ((affine.sx != 1.0) || (affine.rx != 0.0) || (affine.ry != 0.0) ||
2756 (affine.sy != 1.0) || (affine.tx != 0.0) || (affine.ty != 0.0))
2758 graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
2759 graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
2760 graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
2761 graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
2762 graphic_context[n]->affine.tx=
2763 current.sx*affine.tx+current.ry*affine.ty+current.tx;
2764 graphic_context[n]->affine.ty=
2765 current.rx*affine.tx+current.sy*affine.ty+current.ty;
2767 if (primitive_type == UndefinedPrimitive)
2769 if (image->debug != MagickFalse)
2770 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",
2775 Parse the primitive attributes.
2779 primitive_info[0].point.x=0.0;
2780 primitive_info[0].point.y=0.0;
2781 for (x=0; *q != '\0'; x++)
2786 if (IsPoint(q) == MagickFalse)
2788 GetMagickToken(q,&q,token);
2789 point.x=StringToDouble(token);
2790 GetMagickToken(q,&q,token);
2792 GetMagickToken(q,&q,token);
2793 point.y=StringToDouble(token);
2794 GetMagickToken(q,(const char **) NULL,token);
2796 GetMagickToken(q,&q,token);
2797 primitive_info[i].primitive=primitive_type;
2798 primitive_info[i].point=point;
2799 primitive_info[i].coordinates=0;
2800 primitive_info[i].method=FloodfillMethod;
2802 if (i < (long) number_points)
2805 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,
2806 (size_t) number_points,sizeof(*primitive_info));
2807 if (primitive_info == (PrimitiveInfo *) NULL)
2809 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2810 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
2814 primitive_info[j].primitive=primitive_type;
2815 primitive_info[j].coordinates=(unsigned long) x;
2816 primitive_info[j].method=FloodfillMethod;
2817 primitive_info[j].text=(char *) NULL;
2819 Circumscribe primitive within a circle.
2821 bounds.x1=primitive_info[j].point.x;
2822 bounds.y1=primitive_info[j].point.y;
2823 bounds.x2=primitive_info[j].point.x;
2824 bounds.y2=primitive_info[j].point.y;
2825 for (k=1; k < (long) primitive_info[j].coordinates; k++)
2827 point=primitive_info[j+k].point;
2828 if (point.x < bounds.x1)
2830 if (point.y < bounds.y1)
2832 if (point.x > bounds.x2)
2834 if (point.y > bounds.y2)
2838 Speculate how many points our primitive might consume.
2840 length=primitive_info[j].coordinates;
2841 switch (primitive_type)
2843 case RectanglePrimitive:
2848 case RoundRectanglePrimitive:
2850 length*=5+4*BezierQuantum;
2853 case BezierPrimitive:
2855 if (primitive_info[j].coordinates > 107)
2856 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2857 DrawError,"TooManyBezierCoordinates","`%s'",token);
2858 length=BezierQuantum*primitive_info[j].coordinates;
2867 GetMagickToken(q,&q,token);
2870 for (s=token; *s != '\0'; s=t)
2883 length+=k*BezierQuantum;
2886 case CirclePrimitive:
2888 case EllipsePrimitive:
2895 alpha=bounds.x2-bounds.x1;
2896 beta=bounds.y2-bounds.y1;
2897 radius=hypot((double) alpha,(double) beta);
2898 length=2*((size_t) (MagickPI*radius))+6*BezierQuantum+360+1;
2904 if ((unsigned long) (i+length) >= number_points)
2907 Resize based on speculative points required by primitive.
2909 while ((unsigned long) (i+length) >= number_points)
2911 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,
2912 (size_t) number_points,sizeof(*primitive_info));
2913 if (primitive_info == (PrimitiveInfo *) NULL)
2915 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2916 ResourceLimitError,"MemoryAllocationFailed","`%s'",
2921 switch (primitive_type)
2923 case PointPrimitive:
2926 if (primitive_info[j].coordinates != 1)
2931 TracePoint(primitive_info+j,primitive_info[j].point);
2932 i=(long) (j+primitive_info[j].coordinates);
2937 if (primitive_info[j].coordinates != 2)
2942 TraceLine(primitive_info+j,primitive_info[j].point,
2943 primitive_info[j+1].point);
2944 i=(long) (j+primitive_info[j].coordinates);
2947 case RectanglePrimitive:
2949 if (primitive_info[j].coordinates != 2)
2954 TraceRectangle(primitive_info+j,primitive_info[j].point,
2955 primitive_info[j+1].point);
2956 i=(long) (j+primitive_info[j].coordinates);
2959 case RoundRectanglePrimitive:
2961 if (primitive_info[j].coordinates != 3)
2966 TraceRoundRectangle(primitive_info+j,primitive_info[j].point,
2967 primitive_info[j+1].point,primitive_info[j+2].point);
2968 i=(long) (j+primitive_info[j].coordinates);
2973 if (primitive_info[j].coordinates != 3)
2975 primitive_type=UndefinedPrimitive;
2978 TraceArc(primitive_info+j,primitive_info[j].point,
2979 primitive_info[j+1].point,primitive_info[j+2].point);
2980 i=(long) (j+primitive_info[j].coordinates);
2983 case EllipsePrimitive:
2985 if (primitive_info[j].coordinates != 3)
2990 TraceEllipse(primitive_info+j,primitive_info[j].point,
2991 primitive_info[j+1].point,primitive_info[j+2].point);
2992 i=(long) (j+primitive_info[j].coordinates);
2995 case CirclePrimitive:
2997 if (primitive_info[j].coordinates != 2)
3002 TraceCircle(primitive_info+j,primitive_info[j].point,
3003 primitive_info[j+1].point);
3004 i=(long) (j+primitive_info[j].coordinates);
3007 case PolylinePrimitive:
3009 case PolygonPrimitive:
3011 primitive_info[i]=primitive_info[j];
3012 primitive_info[i].coordinates=0;
3013 primitive_info[j].coordinates++;
3017 case BezierPrimitive:
3019 if (primitive_info[j].coordinates < 3)
3024 TraceBezier(primitive_info+j,primitive_info[j].coordinates);
3025 i=(long) (j+primitive_info[j].coordinates);
3030 i=(long) (j+TracePath(primitive_info+j,token));
3033 case ColorPrimitive:
3034 case MattePrimitive:
3039 if (primitive_info[j].coordinates != 1)
3044 GetMagickToken(q,&q,token);
3045 method=ParseMagickOption(MagickMethodOptions,MagickFalse,token);
3051 primitive_info[j].method=(PaintMethod) method;
3056 if (primitive_info[j].coordinates != 1)
3062 GetMagickToken(q,&q,token);
3063 primitive_info[j].text=AcquireString(token);
3066 case ImagePrimitive:
3068 if (primitive_info[j].coordinates != 2)
3073 GetMagickToken(q,&q,token);
3074 primitive_info[j].text=AcquireString(token);
3078 if (primitive_info == (PrimitiveInfo *) NULL)
3080 if (image->debug != MagickFalse)
3081 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",(int) (q-p),p);
3082 if (status == MagickFalse)
3084 primitive_info[i].primitive=UndefinedPrimitive;
3090 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
3092 point=primitive_info[i].point;
3093 primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+
3094 graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx;
3095 primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+
3096 graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty;
3097 point=primitive_info[i].point;
3098 if (point.x < graphic_context[n]->bounds.x1)
3099 graphic_context[n]->bounds.x1=point.x;
3100 if (point.y < graphic_context[n]->bounds.y1)
3101 graphic_context[n]->bounds.y1=point.y;
3102 if (point.x > graphic_context[n]->bounds.x2)
3103 graphic_context[n]->bounds.x2=point.x;
3104 if (point.y > graphic_context[n]->bounds.y2)
3105 graphic_context[n]->bounds.y2=point.y;
3106 if (primitive_info[i].primitive == ImagePrimitive)
3109 if (i >= (long) number_points)
3110 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
3111 if (graphic_context[n]->render != MagickFalse)
3113 if ((n != 0) && (graphic_context[n]->clip_mask != (char *) NULL) &&
3114 (LocaleCompare(graphic_context[n]->clip_mask,
3115 graphic_context[n-1]->clip_mask) != 0))
3116 (void) DrawClipPath(image,graphic_context[n],
3117 graphic_context[n]->clip_mask);
3118 (void) DrawPrimitive(image,graphic_context[n],primitive_info);
3120 if (primitive_info->text != (char *) NULL)
3121 primitive_info->text=(char *) RelinquishMagickMemory(
3122 primitive_info->text);
3123 proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType)
3125 if (proceed == MagickFalse)
3128 if (image->debug != MagickFalse)
3129 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end draw-image");
3131 Relinquish resources.
3133 token=DestroyString(token);
3134 if (primitive_info != (PrimitiveInfo *) NULL)
3135 primitive_info=(PrimitiveInfo *) RelinquishMagickMemory(primitive_info);
3136 primitive=DestroyString(primitive);
3137 for ( ; n >= 0; n--)
3138 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
3139 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
3140 if (status == MagickFalse)
3141 ThrowBinaryException(DrawError,"NonconformingDrawingPrimitiveDefinition",
3147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3151 % D r a w G r a d i e n t I m a g e %
3155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3157 % DrawGradientImage() draws a linear gradient on the image.
3159 % The format of the DrawGradientImage method is:
3161 % MagickBooleanType DrawGradientImage(Image *image,
3162 % const DrawInfo *draw_info)
3164 % A description of each parameter follows:
3166 % o image: the image.
3168 % o _info: the draw info.
3172 static inline MagickRealType GetStopColorOffset(const GradientInfo *gradient,
3173 const long x,const long y)
3175 switch (gradient->type)
3177 case UndefinedGradient:
3178 case LinearGradient:
3193 gradient_vector=(&gradient->gradient_vector);
3194 p.x=gradient_vector->x2-gradient_vector->x1;
3195 p.y=gradient_vector->y2-gradient_vector->y1;
3196 q.x=(double) x-gradient_vector->x1;
3197 q.y=(double) y-gradient_vector->y1;
3198 length=sqrt(q.x*q.x+q.y*q.y);
3199 gamma=sqrt(p.x*p.x+p.y*p.y)*length;
3200 gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
3201 scale=p.x*q.x+p.y*q.y;
3202 offset=gamma*scale*length;
3205 case RadialGradient:
3214 v.x=(double) x-gradient->center.x;
3215 v.y=(double) y-gradient->center.y;
3216 length=sqrt(v.x*v.x+v.y*v.y);
3217 if (gradient->spread == RepeatSpread)
3219 offset=length/gradient->radius;
3226 MagickExport MagickBooleanType DrawGradientImage(Image *image,
3227 const DrawInfo *draw_info)
3260 Draw linear or radial gradient on image.
3262 assert(image != (Image *) NULL);
3263 assert(image->signature == MagickSignature);
3264 if (image->debug != MagickFalse)
3265 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3266 assert(draw_info != (const DrawInfo *) NULL);
3267 gradient=(&draw_info->gradient);
3268 gradient_vector=(&gradient->gradient_vector);
3269 point.x=gradient_vector->x2-gradient_vector->x1;
3270 point.y=gradient_vector->y2-gradient_vector->y1;
3271 length=sqrt(point.x*point.x+point.y*point.y);
3272 bounding_box=gradient->bounding_box;
3274 exception=(&image->exception);
3275 GetMagickPixelPacket(image,&zero);
3276 image_view=AcquireCacheView(image);
3277 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3278 #pragma omp parallel for schedule(dynamic,4) shared(status)
3280 for (y=bounding_box.y; y < (long) bounding_box.height; y++)
3293 register IndexPacket
3300 register PixelPacket
3303 if (status == MagickFalse)
3305 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3306 if (q == (PixelPacket *) NULL)
3311 indexes=GetCacheViewAuthenticIndexQueue(image_view);
3314 offset=GetStopColorOffset(gradient,0,y);
3315 if (gradient->type != RadialGradient)
3317 for (x=bounding_box.x; x < (long) bounding_box.width; x++)
3319 SetMagickPixelPacket(image,q,indexes+x,&pixel);
3320 switch (gradient->spread)
3322 case UndefinedSpread:
3325 if ((x != (long) (gradient_vector->x1+0.5)) ||
3326 (y != (long) (gradient_vector->y1+0.5)))
3328 offset=GetStopColorOffset(gradient,x,y);
3329 if (gradient->type != RadialGradient)
3332 for (i=0; i < (long) gradient->number_stops; i++)
3333 if (offset < gradient->stops[i].offset)
3335 if ((offset < 0.0) || (i == 0))
3336 composite=gradient->stops[0].color;
3338 if ((offset > 1.0) || (i == (long) gradient->number_stops))
3339 composite=gradient->stops[gradient->number_stops-1].color;
3344 alpha=(offset-gradient->stops[i].offset)/
3345 (gradient->stops[j].offset-gradient->stops[i].offset);
3346 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3347 &gradient->stops[j].color,alpha,&composite);
3353 if ((x != (long) (gradient_vector->x1+0.5)) ||
3354 (y != (long) (gradient_vector->y1+0.5)))
3356 offset=GetStopColorOffset(gradient,x,y);
3357 if (gradient->type != RadialGradient)
3362 if ((long) fmod(offset,2.0) == 0)
3363 offset=fmod(offset,1.0);
3365 offset=1.0-fmod(offset,1.0);
3366 for (i=0; i < (long) gradient->number_stops; i++)
3367 if (offset < gradient->stops[i].offset)
3370 composite=gradient->stops[0].color;
3372 if (i == (long) gradient->number_stops)
3373 composite=gradient->stops[gradient->number_stops-1].color;
3378 alpha=(offset-gradient->stops[i].offset)/
3379 (gradient->stops[j].offset-gradient->stops[i].offset);
3380 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3381 &gradient->stops[j].color,alpha,&composite);
3393 antialias=MagickFalse;
3395 if ((x != (long) (gradient_vector->x1+0.5)) ||
3396 (y != (long) (gradient_vector->y1+0.5)))
3398 offset=GetStopColorOffset(gradient,x,y);
3399 if (gradient->type == LinearGradient)
3401 repeat=fmod(offset,length);
3403 repeat=length-fmod(-repeat,length);
3405 repeat=fmod(offset,length);
3406 antialias=(repeat < length) && ((repeat+1.0) > length) ?
3407 MagickTrue : MagickFalse;
3408 offset=repeat/length;
3412 repeat=fmod(offset,gradient->radius);
3414 repeat=gradient->radius-fmod(-repeat,gradient->radius);
3416 repeat=fmod(offset,gradient->radius);
3417 antialias=repeat+1.0 > gradient->radius ?
3418 MagickTrue : MagickFalse;
3419 offset=repeat/gradient->radius;
3422 for (i=0; i < (long) gradient->number_stops; i++)
3423 if (offset < gradient->stops[i].offset)
3426 composite=gradient->stops[0].color;
3428 if (i == (long) gradient->number_stops)
3429 composite=gradient->stops[gradient->number_stops-1].color;
3434 alpha=(offset-gradient->stops[i].offset)/
3435 (gradient->stops[j].offset-gradient->stops[i].offset);
3436 if (antialias != MagickFalse)
3438 if (gradient->type == LinearGradient)
3439 alpha=length-repeat;
3441 alpha=gradient->radius-repeat;
3443 j=(long) gradient->number_stops-1L;
3445 MagickPixelCompositeBlend(&gradient->stops[i].color,1.0-alpha,
3446 &gradient->stops[j].color,alpha,&composite);
3451 MagickPixelCompositeOver(&composite,composite.opacity,&pixel,
3452 pixel.opacity,&pixel);
3453 SetPixelPacket(image,&pixel,q,indexes+x);
3456 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3459 image_view=DestroyCacheView(image_view);
3464 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3468 % D r a w P a t t e r n P a t h %
3472 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3474 % DrawPatternPath() draws a pattern.
3476 % The format of the DrawPatternPath method is:
3478 % MagickBooleanType DrawPatternPath(Image *image,const DrawInfo *draw_info,
3479 % const char *name,Image **pattern)
3481 % A description of each parameter follows:
3483 % o image: the image.
3485 % o draw_info: the draw info.
3487 % o name: the pattern name.
3489 % o image: the image.
3492 MagickExport MagickBooleanType DrawPatternPath(Image *image,
3493 const DrawInfo *draw_info,const char *name,Image **pattern)
3496 property[MaxTextExtent];
3511 assert(image != (Image *) NULL);
3512 assert(image->signature == MagickSignature);
3513 if (image->debug != MagickFalse)
3514 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3515 assert(draw_info != (const DrawInfo *) NULL);
3516 assert(name != (const char *) NULL);
3517 (void) FormatMagickString(property,MaxTextExtent,"%s",name);
3518 path=GetImageArtifact(image,property);
3519 if (path == (const char *) NULL)
3520 return(MagickFalse);
3521 (void) FormatMagickString(property,MaxTextExtent,"%s-geometry",name);
3522 geometry=GetImageArtifact(image,property);
3523 if (geometry == (const char *) NULL)
3524 return(MagickFalse);
3525 if ((*pattern) != (Image *) NULL)
3526 *pattern=DestroyImage(*pattern);
3527 image_info=AcquireImageInfo();
3528 image_info->size=AcquireString(geometry);
3529 *pattern=AcquireImage(image_info);
3530 image_info=DestroyImageInfo(image_info);
3531 (void) QueryColorDatabase("#00000000",&(*pattern)->background_color,
3533 (void) SetImageBackgroundColor(*pattern);
3534 if (image->debug != MagickFalse)
3535 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
3536 "begin pattern-path %s %s",name,geometry);
3537 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
3538 clone_info->fill_pattern=NewImageList();
3539 clone_info->stroke_pattern=NewImageList();
3540 (void) CloneString(&clone_info->primitive,path);
3541 status=DrawImage(*pattern,clone_info);
3542 clone_info=DestroyDrawInfo(clone_info);
3543 if (image->debug != MagickFalse)
3544 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end pattern-path");
3549 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3553 + D r a w P o l y g o n P r i m i t i v e %
3557 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3559 % DrawPolygonPrimitive() draws a polygon on the image.
3561 % The format of the DrawPolygonPrimitive method is:
3563 % MagickBooleanType DrawPolygonPrimitive(Image *image,
3564 % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
3566 % A description of each parameter follows:
3568 % o image: the image.
3570 % o draw_info: the draw info.
3572 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
3576 static PolygonInfo **DestroyPolygonThreadSet(PolygonInfo **polygon_info)
3581 assert(polygon_info != (PolygonInfo **) NULL);
3582 for (i=0; i < (long) GetOpenMPMaximumThreads(); i++)
3583 if (polygon_info[i] != (PolygonInfo *) NULL)
3584 polygon_info[i]=DestroyPolygonInfo(polygon_info[i]);
3585 polygon_info=(PolygonInfo **) RelinquishAlignedMemory(polygon_info);
3586 return(polygon_info);
3589 static PolygonInfo **AcquirePolygonThreadSet(const DrawInfo *draw_info,
3590 const PrimitiveInfo *primitive_info)
3593 *restrict path_info;
3604 number_threads=GetOpenMPMaximumThreads();
3605 polygon_info=(PolygonInfo **) AcquireAlignedMemory(number_threads,
3606 sizeof(*polygon_info));
3607 if (polygon_info == (PolygonInfo **) NULL)
3608 return((PolygonInfo **) NULL);
3609 (void) ResetMagickMemory(polygon_info,0,GetOpenMPMaximumThreads()*
3610 sizeof(*polygon_info));
3611 path_info=ConvertPrimitiveToPath(draw_info,primitive_info);
3612 if (path_info == (PathInfo *) NULL)
3613 return(DestroyPolygonThreadSet(polygon_info));
3614 for (i=0; i < (long) number_threads; i++)
3616 polygon_info[i]=ConvertPathToPolygon(draw_info,path_info);
3617 if (polygon_info[i] == (PolygonInfo *) NULL)
3618 return(DestroyPolygonThreadSet(polygon_info));
3620 path_info=(PathInfo *) RelinquishMagickMemory(path_info);
3621 return(polygon_info);
3624 static MagickRealType GetPixelOpacity(PolygonInfo *polygon_info,
3625 const MagickRealType mid,const MagickBooleanType fill,
3626 const FillRule fill_rule,const long x,const long y,
3627 MagickRealType *stroke_opacity)
3647 register const PointInfo
3654 Compute fill & stroke opacity for this (x,y) point.
3656 *stroke_opacity=0.0;
3657 subpath_opacity=0.0;
3658 p=polygon_info->edges;
3659 for (j=0; j < (long) polygon_info->number_edges; j++, p++)
3661 if (y <= (p->bounds.y1-mid-0.5))
3663 if (y > (p->bounds.y2+mid+0.5))
3665 (void) DestroyEdge(polygon_info,j);
3668 if ((x <= (p->bounds.x1-mid-0.5)) || (x > (p->bounds.x2+mid+0.5)))
3670 for (i=MagickMax(p->highwater,1); i < (long) p->number_points; i++)
3672 if (y <= (p->points[i-1].y-mid-0.5))
3674 if (y > (p->points[i].y+mid+0.5))
3676 if (p->scanline != y)
3682 Compute distance between a point and an edge.
3685 delta.x=(q+1)->x-q->x;
3686 delta.y=(q+1)->y-q->y;
3687 beta=delta.x*(x-q->x)+delta.y*(y-q->y);
3692 distance=delta.x*delta.x+delta.y*delta.y;
3696 alpha=delta.x*delta.x+delta.y*delta.y;
3701 distance=delta.x*delta.x+delta.y*delta.y;
3706 beta=delta.x*(y-q->y)-delta.y*(x-q->x);
3707 distance=alpha*beta*beta;
3711 Compute stroke & subpath opacity.
3714 if (p->ghostline == MagickFalse)
3717 if ((*stroke_opacity < 1.0) &&
3718 (distance <= ((alpha+0.25)*(alpha+0.25))))
3721 if (distance <= ((alpha+0.25)*(alpha+0.25)))
3722 *stroke_opacity=1.0;
3726 if (distance != 1.0)
3727 beta=sqrt((double) distance);
3729 if (*stroke_opacity < ((alpha-0.25)*(alpha-0.25)))
3730 *stroke_opacity=(alpha-0.25)*(alpha-0.25);
3734 if ((fill == MagickFalse) || (distance > 1.0) || (subpath_opacity >= 1.0))
3736 if (distance <= 0.0)
3738 subpath_opacity=1.0;
3746 if (distance != 1.0)
3747 beta=sqrt(distance);
3750 if (subpath_opacity < (alpha*alpha))
3751 subpath_opacity=alpha*alpha;
3755 Compute fill opacity.
3757 if (fill == MagickFalse)
3759 if (subpath_opacity >= 1.0)
3762 Determine winding number.
3765 p=polygon_info->edges;
3766 for (j=0; j < (long) polygon_info->number_edges; j++, p++)
3768 if (y <= p->bounds.y1)
3770 if ((y > p->bounds.y2) || (x <= p->bounds.x1))
3772 if (x > p->bounds.x2)
3774 winding_number+=p->direction ? 1 : -1;
3777 for (i=MagickMax(p->highwater,1); i < (long) p->number_points; i++)
3778 if (y <= p->points[i].y)
3781 if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x)))
3782 winding_number+=p->direction ? 1 : -1;
3784 if (fill_rule != NonZeroRule)
3786 if ((MagickAbsoluteValue(winding_number) & 0x01) != 0)
3790 if (MagickAbsoluteValue(winding_number) != 0)
3792 return(subpath_opacity);
3795 static MagickBooleanType DrawPolygonPrimitive(Image *image,
3796 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
3817 **restrict polygon_info;
3829 Compute bounding box.
3831 assert(image != (Image *) NULL);
3832 assert(image->signature == MagickSignature);
3833 if (image->debug != MagickFalse)
3834 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3835 assert(draw_info != (DrawInfo *) NULL);
3836 assert(draw_info->signature == MagickSignature);
3837 assert(primitive_info != (PrimitiveInfo *) NULL);
3838 if (primitive_info->coordinates == 0)
3840 polygon_info=AcquirePolygonThreadSet(draw_info,primitive_info);
3841 if (polygon_info == (PolygonInfo **) NULL)
3842 return(MagickFalse);
3844 DrawBoundingRectangles(image,draw_info,polygon_info[0]);
3845 if (image->debug != MagickFalse)
3846 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-polygon");
3847 fill=(primitive_info->method == FillToBorderMethod) ||
3848 (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse;
3849 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
3850 bounds=polygon_info[0]->edges[0].bounds;
3851 for (i=1; i < (long) polygon_info[0]->number_edges; i++)
3853 p=polygon_info[0]->edges+i;
3854 if (p->bounds.x1 < bounds.x1)
3855 bounds.x1=p->bounds.x1;
3856 if (p->bounds.y1 < bounds.y1)
3857 bounds.y1=p->bounds.y1;
3858 if (p->bounds.x2 > bounds.x2)
3859 bounds.x2=p->bounds.x2;
3860 if (p->bounds.y2 > bounds.y2)
3861 bounds.y2=p->bounds.y2;
3863 bounds.x1-=(mid+1.0);
3864 bounds.x1=bounds.x1 < 0.0 ? 0.0 : (unsigned long) (bounds.x1+0.5) >=
3865 image->columns ? (double) image->columns-1.0 : bounds.x1;
3866 bounds.y1-=(mid+1.0);
3867 bounds.y1=bounds.y1 < 0.0 ? 0.0 : (unsigned long) (bounds.y1+0.5) >=
3868 image->rows ? (double) image->rows-1.0 : bounds.y1;
3869 bounds.x2+=(mid+1.0);
3870 bounds.x2=bounds.x2 < 0.0 ? 0.0 : (unsigned long) (bounds.x2+0.5) >=
3871 image->columns ? (double) image->columns-1.0 : bounds.x2;
3872 bounds.y2+=(mid+1.0);
3873 bounds.y2=bounds.y2 < 0.0 ? 0.0 : (unsigned long) (bounds.y2+0.5) >=
3874 image->rows ? (double) image->rows-1.0 : bounds.y2;
3876 exception=(&image->exception);
3877 start=(long) (bounds.x1+0.5);
3878 stop=(long) (bounds.x2+0.5);
3879 image_view=AcquireCacheView(image);
3880 if (primitive_info->coordinates == 1)
3885 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3886 #pragma omp parallel for schedule(dynamic,4) shared(status)
3888 for (y=(long) (bounds.y1+0.5); y <= (long) (bounds.y2+0.5); y++)
3896 register PixelPacket
3899 if (status == MagickFalse)
3902 q=GetCacheViewAuthenticPixels(image_view,x,y,(unsigned long) (stop-x+1),
3904 if (q == (PixelPacket *) NULL)
3909 for ( ; x <= stop; x++)
3911 if ((x == (long) (primitive_info->point.x+0.5)) &&
3912 (y == (long) (primitive_info->point.y+0.5)))
3913 (void) GetStrokeColor(draw_info,x,y,q);
3916 sync=SyncCacheViewAuthenticPixels(image_view,exception);
3917 if (sync == MagickFalse)
3920 image_view=DestroyCacheView(image_view);
3921 polygon_info=DestroyPolygonThreadSet(polygon_info);
3922 if (image->debug != MagickFalse)
3923 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
3924 " end draw-polygon");
3928 Draw polygon or line.
3930 if (image->matte == MagickFalse)
3931 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3932 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3933 #pragma omp parallel for schedule(dynamic,4) shared(status)
3935 for (y=(long) (bounds.y1+0.5); y <= (long) (bounds.y2+0.5); y++)
3949 register PixelPacket
3952 if (status == MagickFalse)
3954 q=GetCacheViewAuthenticPixels(image_view,start,y,(unsigned long) (stop-
3955 start+1),1,exception);
3956 if (q == (PixelPacket *) NULL)
3961 id=GetOpenMPThreadId();
3962 for (x=start; x <= stop; x++)
3967 fill_opacity=GetPixelOpacity(polygon_info[id],mid,fill,
3968 draw_info->fill_rule,x,y,&stroke_opacity);
3969 if (draw_info->stroke_antialias == MagickFalse)
3971 fill_opacity=fill_opacity > 0.25 ? 1.0 : 0.0;
3972 stroke_opacity=stroke_opacity > 0.25 ? 1.0 : 0.0;
3974 (void) GetFillColor(draw_info,x,y,&fill_color);
3975 fill_opacity=(MagickRealType) (QuantumRange-fill_opacity*(QuantumRange-
3976 fill_color.opacity));
3977 MagickCompositeOver(&fill_color,fill_opacity,q,(MagickRealType)
3979 (void) GetStrokeColor(draw_info,x,y,&stroke_color);
3980 stroke_opacity=(MagickRealType) (QuantumRange-stroke_opacity*
3981 (QuantumRange-stroke_color.opacity));
3982 MagickCompositeOver(&stroke_color,stroke_opacity,q,(MagickRealType)
3986 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3989 image_view=DestroyCacheView(image_view);
3990 polygon_info=DestroyPolygonThreadSet(polygon_info);
3991 if (image->debug != MagickFalse)
3992 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-polygon");
3997 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4001 % D r a w P r i m i t i v e %
4005 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4007 % DrawPrimitive() draws a primitive (line, rectangle, ellipse) on the image.
4009 % The format of the DrawPrimitive method is:
4011 % MagickBooleanType DrawPrimitive(Image *image,const DrawInfo *draw_info,
4012 % PrimitiveInfo *primitive_info)
4014 % A description of each parameter follows:
4016 % o image: the image.
4018 % o draw_info: the draw info.
4020 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
4024 static void LogPrimitiveInfo(const PrimitiveInfo *primitive_info)
4050 x=(long) (primitive_info->point.x+0.5);
4051 y=(long) (primitive_info->point.y+0.5);
4052 switch (primitive_info->primitive)
4054 case PointPrimitive:
4056 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4057 "PointPrimitive %ld,%ld %s",x,y,methods[primitive_info->method]);
4060 case ColorPrimitive:
4062 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4063 "ColorPrimitive %ld,%ld %s",x,y,methods[primitive_info->method]);
4066 case MattePrimitive:
4068 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4069 "MattePrimitive %ld,%ld %s",x,y,methods[primitive_info->method]);
4074 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4075 "TextPrimitive %ld,%ld",x,y);
4078 case ImagePrimitive:
4080 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4081 "ImagePrimitive %ld,%ld",x,y);
4088 p=primitive_info[0].point;
4091 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4093 point=primitive_info[i].point;
4094 if (coordinates <= 0)
4096 coordinates=(long) primitive_info[i].coordinates;
4097 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4098 " begin open (%ld)",coordinates);
4101 point=primitive_info[i].point;
4102 if ((fabs(q.x-point.x) > MagickEpsilon) ||
4103 (fabs(q.y-point.y) > MagickEpsilon))
4104 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4105 " %ld: %.18g,%.18g",coordinates,point.x,point.y);
4107 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4108 " %ld: %.15g,%.15g (duplicate)",coordinates,point.x,point.y);
4111 if (coordinates > 0)
4113 if ((fabs(p.x-point.x) > MagickEpsilon) ||
4114 (fabs(p.y-point.y) > MagickEpsilon))
4115 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end last (%ld)",
4118 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end open (%ld)",
4123 MagickExport MagickBooleanType DrawPrimitive(Image *image,
4124 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4142 if (image->debug != MagickFalse)
4144 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4145 " begin draw-primitive");
4146 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4147 " affine: %.15g,%.15g,%.15g,%.15g,%.15g,%.15g",draw_info->affine.sx,
4148 draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy,
4149 draw_info->affine.tx,draw_info->affine.ty);
4152 exception=(&image->exception);
4153 x=(long) (primitive_info->point.x+0.5);
4154 y=(long) (primitive_info->point.y+0.5);
4155 image_view=AcquireCacheView(image);
4156 switch (primitive_info->primitive)
4158 case PointPrimitive:
4166 if ((y < 0) || (y >= (long) image->rows))
4168 if ((x < 0) || (x >= (long) image->columns))
4170 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4171 if (q == (PixelPacket *) NULL)
4173 (void) GetFillColor(draw_info,x,y,&fill_color);
4174 MagickCompositeOver(&fill_color,(MagickRealType) fill_color.opacity,q,
4175 (MagickRealType) q->opacity,q);
4176 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4179 case ColorPrimitive:
4181 switch (primitive_info->method)
4189 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4190 if (q == (PixelPacket *) NULL)
4192 (void) GetFillColor(draw_info,x,y,q);
4193 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4204 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception);
4205 for (y=0; y < (long) image->rows; y++)
4207 register PixelPacket
4210 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4212 if (q == (PixelPacket *) NULL)
4214 for (x=0; x < (long) image->columns; x++)
4216 if (IsColorSimilar(image,q,&target) == MagickFalse)
4221 (void) GetFillColor(draw_info,x,y,q);
4224 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4225 if (sync == MagickFalse)
4230 case FloodfillMethod:
4231 case FillToBorderMethod:
4236 (void) GetOneVirtualMagickPixel(image,x,y,&target,exception);
4237 if (primitive_info->method == FillToBorderMethod)
4239 target.red=(MagickRealType) draw_info->border_color.red;
4240 target.green=(MagickRealType) draw_info->border_color.green;
4241 target.blue=(MagickRealType) draw_info->border_color.blue;
4243 (void) FloodfillPaintImage(image,DefaultChannels,draw_info,&target,x,
4244 y,primitive_info->method == FloodfillMethod ? MagickFalse :
4253 for (y=0; y < (long) image->rows; y++)
4258 register PixelPacket
4261 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4263 if (q == (PixelPacket *) NULL)
4265 for (x=0; x < (long) image->columns; x++)
4267 (void) GetFillColor(draw_info,x,y,q);
4270 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4271 if (sync == MagickFalse)
4279 case MattePrimitive:
4281 if (image->matte == MagickFalse)
4282 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
4283 switch (primitive_info->method)
4294 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4295 if (q == (PixelPacket *) NULL)
4297 (void) GetFillColor(draw_info,x,y,&pixel);
4298 q->opacity=pixel.opacity;
4299 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4311 (void) GetOneCacheViewVirtualPixel(image_view,x,y,&target,exception);
4312 for (y=0; y < (long) image->rows; y++)
4317 register PixelPacket
4320 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4322 if (q == (PixelPacket *) NULL)
4324 for (x=0; x < (long) image->columns; x++)
4326 if (IsColorSimilar(image,q,&target) == MagickFalse)
4331 (void) GetFillColor(draw_info,x,y,&pixel);
4332 q->opacity=pixel.opacity;
4335 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4336 if (sync == MagickFalse)
4341 case FloodfillMethod:
4342 case FillToBorderMethod:
4347 (void) GetOneVirtualMagickPixel(image,x,y,&target,exception);
4348 if (primitive_info->method == FillToBorderMethod)
4350 target.red=(MagickRealType) draw_info->border_color.red;
4351 target.green=(MagickRealType) draw_info->border_color.green;
4352 target.blue=(MagickRealType) draw_info->border_color.blue;
4354 (void) FloodfillPaintImage(image,OpacityChannel,draw_info,&target,x,y,
4355 primitive_info->method == FloodfillMethod ? MagickFalse :
4367 for (y=0; y < (long) image->rows; y++)
4372 register PixelPacket
4375 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4377 if (q == (PixelPacket *) NULL)
4379 for (x=0; x < (long) image->columns; x++)
4381 (void) GetFillColor(draw_info,x,y,&pixel);
4382 q->opacity=pixel.opacity;
4385 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4386 if (sync == MagickFalse)
4397 geometry[MaxTextExtent];
4402 if (primitive_info->text == (char *) NULL)
4404 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4405 (void) CloneString(&clone_info->text,primitive_info->text);
4406 (void) FormatMagickString(geometry,MaxTextExtent,"%+f%+f",
4407 primitive_info->point.x,primitive_info->point.y);
4408 (void) CloneString(&clone_info->geometry,geometry);
4409 status=AnnotateImage(image,clone_info);
4410 clone_info=DestroyDrawInfo(clone_info);
4413 case ImagePrimitive:
4419 composite_geometry[MaxTextExtent];
4434 if (primitive_info->text == (char *) NULL)
4436 clone_info=AcquireImageInfo();
4437 if (LocaleNCompare(primitive_info->text,"data:",5) == 0)
4438 composite_image=ReadInlineImage(clone_info,primitive_info->text,
4442 (void) CopyMagickString(clone_info->filename,primitive_info->text,
4444 composite_image=ReadImage(clone_info,&image->exception);
4446 clone_info=DestroyImageInfo(clone_info);
4447 if (composite_image == (Image *) NULL)
4449 (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor)
4450 NULL,(void *) NULL);
4451 x1=(long) (primitive_info[1].point.x+0.5);
4452 y1=(long) (primitive_info[1].point.y+0.5);
4453 if (((x1 != 0L) && (x1 != (long) composite_image->columns)) ||
4454 ((y1 != 0L) && (y1 != (long) composite_image->rows)))
4457 geometry[MaxTextExtent];
4462 (void) FormatMagickString(geometry,MaxTextExtent,"%.15gx%.15g!",
4463 primitive_info[1].point.x,primitive_info[1].point.y);
4464 composite_image->filter=image->filter;
4465 (void) TransformImage(&composite_image,(char *) NULL,geometry);
4467 if (composite_image->matte == MagickFalse)
4468 (void) SetImageAlphaChannel(composite_image,OpaqueAlphaChannel);
4469 if (draw_info->opacity != OpaqueOpacity)
4470 (void) SetImageOpacity(composite_image,draw_info->opacity);
4471 SetGeometry(image,&geometry);
4472 image->gravity=draw_info->gravity;
4475 (void) FormatMagickString(composite_geometry,MaxTextExtent,
4476 "%lux%lu%+ld%+ld",composite_image->columns,composite_image->rows,
4477 geometry.x,geometry.y);
4478 (void) ParseGravityGeometry(image,composite_geometry,&geometry,
4480 affine=draw_info->affine;
4481 affine.tx=(double) geometry.x;
4482 affine.ty=(double) geometry.y;
4483 composite_image->interpolate=image->interpolate;
4484 if (draw_info->compose == OverCompositeOp)
4485 (void) DrawAffineImage(image,composite_image,&affine);
4487 (void) CompositeImage(image,draw_info->compose,composite_image,
4488 geometry.x,geometry.y);
4489 composite_image=DestroyImage(composite_image);
4501 if (IsEventLogging() != MagickFalse)
4502 LogPrimitiveInfo(primitive_info);
4503 scale=ExpandAffine(&draw_info->affine);
4504 if ((draw_info->dash_pattern != (double *) NULL) &&
4505 (draw_info->dash_pattern[0] != 0.0) &&
4506 ((scale*draw_info->stroke_width) > MagickEpsilon) &&
4507 (draw_info->stroke.opacity != (Quantum) TransparentOpacity))
4512 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4513 clone_info->stroke_width=0.0;
4514 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4515 status=DrawPolygonPrimitive(image,clone_info,primitive_info);
4516 clone_info=DestroyDrawInfo(clone_info);
4517 (void) DrawDashPolygon(draw_info,primitive_info,image);
4520 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
4522 (draw_info->stroke.opacity != (Quantum) TransparentOpacity))
4528 Draw strokes while respecting line cap/join attributes.
4530 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
4532 (primitive_info[i-1].point.x == primitive_info[0].point.x) &&
4533 (primitive_info[i-1].point.y == primitive_info[0].point.y) ?
4534 MagickTrue : MagickFalse;
4535 i=(long) primitive_info[0].coordinates;
4536 if ((((draw_info->linecap == RoundCap) ||
4537 (closed_path != MagickFalse)) &&
4538 (draw_info->linejoin == RoundJoin)) ||
4539 (primitive_info[i].primitive != UndefinedPrimitive))
4541 (void) DrawPolygonPrimitive(image,draw_info,primitive_info);
4544 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4545 clone_info->stroke_width=0.0;
4546 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4547 status=DrawPolygonPrimitive(image,clone_info,primitive_info);
4548 clone_info=DestroyDrawInfo(clone_info);
4549 status|=DrawStrokePolygon(image,draw_info,primitive_info);
4552 status=DrawPolygonPrimitive(image,draw_info,primitive_info);
4556 image_view=DestroyCacheView(image_view);
4557 if (image->debug != MagickFalse)
4558 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-primitive");
4559 return(status != 0 ? MagickTrue : MagickFalse);
4563 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4567 + D r a w S t r o k e P o l y g o n %
4571 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4573 % DrawStrokePolygon() draws a stroked polygon (line, rectangle, ellipse) on
4574 % the image while respecting the line cap and join attributes.
4576 % The format of the DrawStrokePolygon method is:
4578 % MagickBooleanType DrawStrokePolygon(Image *image,
4579 % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4581 % A description of each parameter follows:
4583 % o image: the image.
4585 % o draw_info: the draw info.
4587 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
4592 static void DrawRoundLinecap(Image *image,const DrawInfo *draw_info,
4593 const PrimitiveInfo *primitive_info)
4601 for (i=0; i < 4; i++)
4602 linecap[i]=(*primitive_info);
4603 linecap[0].coordinates=4;
4604 linecap[1].point.x+=(double) (10.0*MagickEpsilon);
4605 linecap[2].point.x+=(double) (10.0*MagickEpsilon);
4606 linecap[2].point.y+=(double) (10.0*MagickEpsilon);
4607 linecap[3].point.y+=(double) (10.0*MagickEpsilon);
4608 linecap[4].primitive=UndefinedPrimitive;
4609 (void) DrawPolygonPrimitive(image,draw_info,linecap);
4612 static MagickBooleanType DrawStrokePolygon(Image *image,
4613 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4625 register const PrimitiveInfo
4630 Draw stroked polygon.
4632 if (image->debug != MagickFalse)
4633 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4634 " begin draw-stroke-polygon");
4635 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4636 clone_info->fill=draw_info->stroke;
4637 clone_info->stroke.opacity=(Quantum) TransparentOpacity;
4638 clone_info->stroke_width=0.0;
4639 clone_info->fill_rule=NonZeroRule;
4641 for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=p->coordinates)
4643 stroke_polygon=TraceStrokePolygon(draw_info,p);
4644 status=DrawPolygonPrimitive(image,clone_info,stroke_polygon);
4645 stroke_polygon=(PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon);
4646 q=p+p->coordinates-1;
4647 closed_path=(q->point.x == p->point.x) && (q->point.y == p->point.y) ?
4648 MagickTrue : MagickFalse;
4649 if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse))
4651 DrawRoundLinecap(image,draw_info,p);
4652 DrawRoundLinecap(image,draw_info,q);
4655 clone_info=DestroyDrawInfo(clone_info);
4656 if (image->debug != MagickFalse)
4657 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4658 " end draw-stroke-polygon");
4663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4667 % G e t A f f i n e M a t r i x %
4671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4673 % GetAffineMatrix() returns an AffineMatrix initialized to the identity
4676 % The format of the GetAffineMatrix method is:
4678 % void GetAffineMatrix(AffineMatrix *affine_matrix)
4680 % A description of each parameter follows:
4682 % o affine_matrix: the affine matrix.
4685 MagickExport void GetAffineMatrix(AffineMatrix *affine_matrix)
4687 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4688 assert(affine_matrix != (AffineMatrix *) NULL);
4689 (void) ResetMagickMemory(affine_matrix,0,sizeof(*affine_matrix));
4690 affine_matrix->sx=1.0;
4691 affine_matrix->sy=1.0;
4695 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4699 + G e t D r a w I n f o %
4703 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4705 % GetDrawInfo() initializes draw_info to default values.
4707 % The format of the GetDrawInfo method is:
4709 % void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info)
4711 % A description of each parameter follows:
4713 % o image_info: the image info..
4715 % o draw_info: the draw info.
4718 MagickExport void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info)
4730 Initialize draw attributes.
4732 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4733 assert(draw_info != (DrawInfo *) NULL);
4734 (void) ResetMagickMemory(draw_info,0,sizeof(*draw_info));
4735 clone_info=CloneImageInfo(image_info);
4736 GetAffineMatrix(&draw_info->affine);
4737 exception=AcquireExceptionInfo();
4738 (void) QueryColorDatabase("#000F",&draw_info->fill,exception);
4739 (void) QueryColorDatabase("#FFF0",&draw_info->stroke,exception);
4740 draw_info->stroke_antialias=clone_info->antialias;
4741 draw_info->stroke_width=1.0;
4742 draw_info->opacity=OpaqueOpacity;
4743 draw_info->fill_rule=EvenOddRule;
4744 draw_info->linecap=ButtCap;
4745 draw_info->linejoin=MiterJoin;
4746 draw_info->miterlimit=10;
4747 draw_info->decorate=NoDecoration;
4748 if (clone_info->font != (char *) NULL)
4749 draw_info->font=AcquireString(clone_info->font);
4750 if (clone_info->density != (char *) NULL)
4751 draw_info->density=AcquireString(clone_info->density);
4752 draw_info->text_antialias=clone_info->antialias;
4753 draw_info->pointsize=12.0;
4754 if (clone_info->pointsize != 0.0)
4755 draw_info->pointsize=clone_info->pointsize;
4756 draw_info->undercolor.opacity=(Quantum) TransparentOpacity;
4757 draw_info->border_color=clone_info->border_color;
4758 draw_info->compose=OverCompositeOp;
4759 if (clone_info->server_name != (char *) NULL)
4760 draw_info->server_name=AcquireString(clone_info->server_name);
4761 draw_info->render=MagickTrue;
4762 draw_info->debug=IsEventLogging();
4763 option=GetImageOption(clone_info,"encoding");
4764 if (option != (const char *) NULL)
4765 (void) CloneString(&draw_info->encoding,option);
4766 option=GetImageOption(clone_info,"kerning");
4767 if (option != (const char *) NULL)
4768 draw_info->kerning=StringToDouble(option);
4769 option=GetImageOption(clone_info,"interline-spacing");
4770 if (option != (const char *) NULL)
4771 draw_info->interline_spacing=StringToDouble(option);
4772 option=GetImageOption(clone_info,"interword-spacing");
4773 if (option != (const char *) NULL)
4774 draw_info->interword_spacing=StringToDouble(option);
4775 option=GetImageOption(clone_info,"fill");
4776 if (option != (const char *) NULL)
4777 (void) QueryColorDatabase(option,&draw_info->fill,exception);
4778 option=GetImageOption(clone_info,"stroke");
4779 if (option != (const char *) NULL)
4780 (void) QueryColorDatabase(option,&draw_info->stroke,exception);
4781 option=GetImageOption(clone_info,"strokewidth");
4782 if (option != (const char *) NULL)
4783 draw_info->stroke_width=StringToDouble(option);
4784 option=GetImageOption(clone_info,"undercolor");
4785 if (option != (const char *) NULL)
4786 (void) QueryColorDatabase(option,&draw_info->undercolor,exception);
4787 option=GetImageOption(clone_info,"gravity");
4788 if (option != (const char *) NULL)
4789 draw_info->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
4790 MagickFalse,option);
4791 exception=DestroyExceptionInfo(exception);
4792 draw_info->signature=MagickSignature;
4793 clone_info=DestroyImageInfo(clone_info);
4797 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4801 + P e r m u t a t e %
4805 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4807 % Permutate() returns the permuation of the (n,k).
4809 % The format of the Permutate method is:
4811 % void Permutate(long n,long k)
4813 % A description of each parameter follows:
4821 static inline MagickRealType Permutate(const long n,const long k)
4830 for (i=k+1; i <= n; i++)
4832 for (i=1; i <= (n-k); i++)
4838 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4842 + T r a c e P r i m i t i v e %
4846 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4848 % TracePrimitive is a collection of methods for generating graphic
4849 % primitives such as arcs, ellipses, paths, etc.
4853 static void TraceArc(PrimitiveInfo *primitive_info,const PointInfo start,
4854 const PointInfo end,const PointInfo degrees)
4860 center.x=0.5*(end.x+start.x);
4861 center.y=0.5*(end.y+start.y);
4862 radii.x=fabs(center.x-start.x);
4863 radii.y=fabs(center.y-start.y);
4864 TraceEllipse(primitive_info,center,radii,degrees);
4867 static void TraceArcPath(PrimitiveInfo *primitive_info,const PointInfo start,
4868 const PointInfo end,const PointInfo arc,const MagickRealType angle,
4869 const MagickBooleanType large_arc,const MagickBooleanType sweep)
4884 register MagickRealType
4888 register PrimitiveInfo
4897 if ((start.x == end.x) && (start.y == end.y))
4899 TracePoint(primitive_info,end);
4902 radii.x=fabs(arc.x);
4903 radii.y=fabs(arc.y);
4904 if ((radii.x == 0.0) || (radii.y == 0.0))
4906 TraceLine(primitive_info,start,end);
4909 cosine=cos(DegreesToRadians(fmod((double) angle,360.0)));
4910 sine=sin(DegreesToRadians(fmod((double) angle,360.0)));
4911 center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2);
4912 center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2);
4913 delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/
4915 if (delta < MagickEpsilon)
4917 TraceLine(primitive_info,start,end);
4922 radii.x*=sqrt((double) delta);
4923 radii.y*=sqrt((double) delta);
4925 points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x);
4926 points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y);
4927 points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x);
4928 points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y);
4929 alpha=points[1].x-points[0].x;
4930 beta=points[1].y-points[0].y;
4931 factor=1.0/(alpha*alpha+beta*beta)-0.25;
4936 factor=sqrt((double) factor);
4937 if (sweep == large_arc)
4940 center.x=(double) ((points[0].x+points[1].x)/2-factor*beta);
4941 center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha);
4942 alpha=atan2(points[0].y-center.y,points[0].x-center.x);
4943 theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha;
4944 if ((theta < 0.0) && (sweep != MagickFalse))
4945 theta+=(MagickRealType) (2.0*MagickPI);
4947 if ((theta > 0.0) && (sweep == MagickFalse))
4948 theta-=(MagickRealType) (2.0*MagickPI);
4949 arc_segments=(unsigned long) ceil(fabs((double) (theta/(0.5*MagickPI+
4952 for (i=0; i < (long) arc_segments; i++)
4954 beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments));
4955 gamma=(8.0/3.0)*sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))*
4956 sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))/
4957 sin(fmod((double) beta,DegreesToRadians(360.0)));
4958 points[0].x=(double) (center.x+cos(fmod((double) (alpha+(double) i*theta/
4959 arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((double) (alpha+
4960 (double) i*theta/arc_segments),DegreesToRadians(360.0))));
4961 points[0].y=(double) (center.y+sin(fmod((double) (alpha+(double) i*theta/
4962 arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((double) (alpha+
4963 (double) i*theta/arc_segments),DegreesToRadians(360.0))));
4964 points[2].x=(double) (center.x+cos(fmod((double) (alpha+(double) (i+1)*
4965 theta/arc_segments),DegreesToRadians(360.0))));
4966 points[2].y=(double) (center.y+sin(fmod((double) (alpha+(double) (i+1)*
4967 theta/arc_segments),DegreesToRadians(360.0))));
4968 points[1].x=(double) (points[2].x+gamma*sin(fmod((double) (alpha+(double)
4969 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
4970 points[1].y=(double) (points[2].y-gamma*cos(fmod((double) (alpha+(double)
4971 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
4972 p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x;
4973 p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y;
4974 (p+1)->point.x=(double) (cosine*radii.x*points[0].x-sine*radii.y*
4976 (p+1)->point.y=(double) (sine*radii.x*points[0].x+cosine*radii.y*
4978 (p+2)->point.x=(double) (cosine*radii.x*points[1].x-sine*radii.y*
4980 (p+2)->point.y=(double) (sine*radii.x*points[1].x+cosine*radii.y*
4982 (p+3)->point.x=(double) (cosine*radii.x*points[2].x-sine*radii.y*
4984 (p+3)->point.y=(double) (sine*radii.x*points[2].x+cosine*radii.y*
4986 if (i == (long) (arc_segments-1))
4991 primitive_info->coordinates=(unsigned long) (p-primitive_info);
4992 for (i=0; i < (long) primitive_info->coordinates; i++)
4994 p->primitive=primitive_info->primitive;
4999 static void TraceBezier(PrimitiveInfo *primitive_info,
5000 const unsigned long number_coordinates)
5016 register PrimitiveInfo
5024 Allocate coeficients.
5026 quantum=number_coordinates;
5027 for (i=0; i < (long) number_coordinates; i++)
5029 for (j=i+1; j < (long) number_coordinates; j++)
5031 alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x);
5032 if (alpha > (MagickRealType) quantum)
5033 quantum=(unsigned long) alpha;
5034 alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y);
5035 if (alpha > (MagickRealType) quantum)
5036 quantum=(unsigned long) alpha;
5039 quantum=(unsigned long) MagickMin((double) quantum/number_coordinates,
5040 (double) BezierQuantum);
5041 control_points=quantum*number_coordinates;
5042 coefficients=(MagickRealType *) AcquireQuantumMemory((size_t)
5043 number_coordinates,sizeof(*coefficients));
5044 points=(PointInfo *) AcquireQuantumMemory((size_t) control_points,
5046 if ((coefficients == (MagickRealType *) NULL) ||
5047 (points == (PointInfo *) NULL))
5048 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
5050 Compute bezier points.
5052 end=primitive_info[number_coordinates-1].point;
5053 for (i=0; i < (long) number_coordinates; i++)
5054 coefficients[i]=Permutate((long) number_coordinates-1,i);
5056 for (i=0; i < (long) control_points; i++)
5061 alpha=pow((double) (1.0-weight),(double) number_coordinates-1.0);
5062 for (j=0; j < (long) number_coordinates; j++)
5064 point.x+=alpha*coefficients[j]*p->point.x;
5065 point.y+=alpha*coefficients[j]*p->point.y;
5066 alpha*=weight/(1.0-weight);
5070 weight+=1.0/control_points;
5073 Bezier curves are just short segmented polys.
5076 for (i=0; i < (long) control_points; i++)
5078 TracePoint(p,points[i]);
5083 primitive_info->coordinates=(unsigned long) (p-primitive_info);
5084 for (i=0; i < (long) primitive_info->coordinates; i++)
5086 p->primitive=primitive_info->primitive;
5089 points=(PointInfo *) RelinquishMagickMemory(points);
5090 coefficients=(MagickRealType *) RelinquishMagickMemory(coefficients);
5093 static void TraceCircle(PrimitiveInfo *primitive_info,const PointInfo start,
5094 const PointInfo end)
5105 alpha=end.x-start.x;
5107 radius=hypot((double) alpha,(double) beta);
5108 offset.x=(double) radius;
5109 offset.y=(double) radius;
5112 TraceEllipse(primitive_info,start,offset,degrees);
5115 static void TraceEllipse(PrimitiveInfo *primitive_info,const PointInfo start,
5116 const PointInfo stop,const PointInfo degrees)
5127 register PrimitiveInfo
5134 Ellipses are just short segmented polys.
5136 if ((stop.x == 0.0) && (stop.y == 0.0))
5138 TracePoint(primitive_info,start);
5141 delta=2.0/MagickMax(stop.x,stop.y);
5142 step=(MagickRealType) (MagickPI/8.0);
5143 if (delta < (MagickPI/8.0))
5144 step=MagickPI/(4*(MagickPI/delta/2+0.5));
5145 angle.x=DegreesToRadians(degrees.x);
5147 while (y < degrees.x)
5149 angle.y=(double) (DegreesToRadians(y)-MagickEpsilon);
5150 for (p=primitive_info; angle.x < angle.y; angle.x+=step)
5152 point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*stop.x+start.x;
5153 point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*stop.y+start.y;
5154 TracePoint(p,point);
5157 point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*stop.x+start.x;
5158 point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*stop.y+start.y;
5159 TracePoint(p,point);
5161 primitive_info->coordinates=(unsigned long) (p-primitive_info);
5162 for (i=0; i < (long) primitive_info->coordinates; i++)
5164 p->primitive=primitive_info->primitive;
5169 static void TraceLine(PrimitiveInfo *primitive_info,const PointInfo start,
5170 const PointInfo end)
5172 TracePoint(primitive_info,start);
5173 if ((fabs(start.x-end.x) <= MagickEpsilon) &&
5174 (fabs(start.y-end.y) <= MagickEpsilon))
5176 primitive_info->primitive=PointPrimitive;
5177 primitive_info->coordinates=1;
5180 TracePoint(primitive_info+1,end);
5181 (primitive_info+1)->primitive=primitive_info->primitive;
5182 primitive_info->coordinates=2;
5185 static unsigned long TracePath(PrimitiveInfo *primitive_info,const char *path)
5188 token[MaxTextExtent];
5210 register PrimitiveInfo
5225 number_coordinates=0;
5227 primitive_type=primitive_info->primitive;
5229 for (p=path; *p != '\0'; )
5231 while (isspace((int) ((unsigned char) *p)) != 0)
5235 last_attribute=attribute;
5236 attribute=(int) (*p++);
5257 GetMagickToken(p,&p,token);
5259 GetMagickToken(p,&p,token);
5260 arc.x=StringToDouble(token);
5261 GetMagickToken(p,&p,token);
5263 GetMagickToken(p,&p,token);
5264 arc.y=StringToDouble(token);
5265 GetMagickToken(p,&p,token);
5267 GetMagickToken(p,&p,token);
5268 angle=StringToDouble(token);
5269 GetMagickToken(p,&p,token);
5271 GetMagickToken(p,&p,token);
5272 large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
5273 GetMagickToken(p,&p,token);
5275 GetMagickToken(p,&p,token);
5276 sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
5277 GetMagickToken(p,&p,token);
5279 GetMagickToken(p,&p,token);
5280 x=StringToDouble(token);
5281 GetMagickToken(p,&p,token);
5283 GetMagickToken(p,&p,token);
5284 y=StringToDouble(token);
5285 end.x=(double) (attribute == (int) 'A' ? x : point.x+x);
5286 end.y=(double) (attribute == (int) 'A' ? y : point.y+y);
5287 TraceArcPath(q,point,end,arc,angle,large_arc,sweep);
5290 } while (IsPoint(p) != MagickFalse);
5297 Compute bezier points.
5302 for (i=1; i < 4; i++)
5304 GetMagickToken(p,&p,token);
5306 GetMagickToken(p,&p,token);
5307 x=StringToDouble(token);
5308 GetMagickToken(p,&p,token);
5310 GetMagickToken(p,&p,token);
5311 y=StringToDouble(token);
5312 end.x=(double) (attribute == (int) 'C' ? x : point.x+x);
5313 end.y=(double) (attribute == (int) 'C' ? y : point.y+y);
5316 for (i=0; i < 4; i++)
5317 (q+i)->point=points[i];
5321 } while (IsPoint(p) != MagickFalse);
5329 GetMagickToken(p,&p,token);
5331 GetMagickToken(p,&p,token);
5332 x=StringToDouble(token);
5333 point.x=(double) (attribute == (int) 'H' ? x: point.x+x);
5334 TracePoint(q,point);
5336 } while (IsPoint(p) != MagickFalse);
5344 GetMagickToken(p,&p,token);
5346 GetMagickToken(p,&p,token);
5347 x=StringToDouble(token);
5348 GetMagickToken(p,&p,token);
5350 GetMagickToken(p,&p,token);
5351 y=StringToDouble(token);
5352 point.x=(double) (attribute == (int) 'L' ? x : point.x+x);
5353 point.y=(double) (attribute == (int) 'L' ? y : point.y+y);
5354 TracePoint(q,point);
5356 } while (IsPoint(p) != MagickFalse);
5362 if (q != primitive_info)
5364 primitive_info->coordinates=(unsigned long) (q-primitive_info);
5365 number_coordinates+=primitive_info->coordinates;
5371 GetMagickToken(p,&p,token);
5373 GetMagickToken(p,&p,token);
5374 x=StringToDouble(token);
5375 GetMagickToken(p,&p,token);
5377 GetMagickToken(p,&p,token);
5378 y=StringToDouble(token);
5379 point.x=(double) (attribute == (int) 'M' ? x : point.x+x);
5380 point.y=(double) (attribute == (int) 'M' ? y : point.y+y);
5384 TracePoint(q,point);
5386 if (attribute == (int) 'M')
5388 TracePoint(q,point);
5391 } while (IsPoint(p) != MagickFalse);
5398 Compute bezier points.
5403 for (i=1; i < 3; i++)
5405 GetMagickToken(p,&p,token);
5407 GetMagickToken(p,&p,token);
5408 x=StringToDouble(token);
5409 GetMagickToken(p,&p,token);
5411 GetMagickToken(p,&p,token);
5412 y=StringToDouble(token);
5415 end.x=(double) (attribute == (int) 'Q' ? x : point.x+x);
5416 end.y=(double) (attribute == (int) 'Q' ? y : point.y+y);
5419 for (i=0; i < 3; i++)
5420 (q+i)->point=points[i];
5424 } while (IsPoint(p) != MagickFalse);
5431 Compute bezier points.
5435 points[0]=points[3];
5436 points[1].x=2.0*points[3].x-points[2].x;
5437 points[1].y=2.0*points[3].y-points[2].y;
5438 for (i=2; i < 4; i++)
5440 GetMagickToken(p,&p,token);
5442 GetMagickToken(p,&p,token);
5443 x=StringToDouble(token);
5444 GetMagickToken(p,&p,token);
5446 GetMagickToken(p,&p,token);
5447 y=StringToDouble(token);
5450 end.x=(double) (attribute == (int) 'S' ? x : point.x+x);
5451 end.y=(double) (attribute == (int) 'S' ? y : point.y+y);
5454 if (strchr("CcSs",last_attribute) == (char *) NULL)
5456 points[0]=points[2];
5457 points[1]=points[3];
5459 for (i=0; i < 4; i++)
5460 (q+i)->point=points[i];
5464 } while (IsPoint(p) != MagickFalse);
5471 Compute bezier points.
5475 points[0]=points[2];
5476 points[1].x=2.0*points[2].x-points[1].x;
5477 points[1].y=2.0*points[2].y-points[1].y;
5478 for (i=2; i < 3; i++)
5480 GetMagickToken(p,&p,token);
5482 GetMagickToken(p,&p,token);
5483 x=StringToDouble(token);
5484 GetMagickToken(p,&p,token);
5486 GetMagickToken(p,&p,token);
5487 y=StringToDouble(token);
5488 end.x=(double) (attribute == (int) 'T' ? x : point.x+x);
5489 end.y=(double) (attribute == (int) 'T' ? y : point.y+y);
5492 if (strchr("QqTt",last_attribute) == (char *) NULL)
5494 points[0]=points[2];
5495 points[1]=points[3];
5497 for (i=0; i < 3; i++)
5498 (q+i)->point=points[i];
5502 } while (IsPoint(p) != MagickFalse);
5510 GetMagickToken(p,&p,token);
5512 GetMagickToken(p,&p,token);
5513 y=StringToDouble(token);
5514 point.y=(double) (attribute == (int) 'V' ? y : point.y+y);
5515 TracePoint(q,point);
5517 } while (IsPoint(p) != MagickFalse);
5524 TracePoint(q,point);
5526 primitive_info->coordinates=(unsigned long) (q-primitive_info);
5527 number_coordinates+=primitive_info->coordinates;
5534 if (isalpha((int) ((unsigned char) attribute)) != 0)
5535 (void) fprintf(stderr,"attribute not recognized: %c\n",attribute);
5540 primitive_info->coordinates=(unsigned long) (q-primitive_info);
5541 number_coordinates+=primitive_info->coordinates;
5542 for (i=0; i < (long) number_coordinates; i++)
5545 q->primitive=primitive_type;
5547 q->method=FillToBorderMethod;
5550 return(number_coordinates);
5553 static void TraceRectangle(PrimitiveInfo *primitive_info,const PointInfo start,
5554 const PointInfo end)
5559 register PrimitiveInfo
5566 TracePoint(p,start);
5570 TracePoint(p,point);
5576 TracePoint(p,point);
5578 TracePoint(p,start);
5580 primitive_info->coordinates=(unsigned long) (p-primitive_info);
5581 for (i=0; i < (long) primitive_info->coordinates; i++)
5583 p->primitive=primitive_info->primitive;
5588 static void TraceRoundRectangle(PrimitiveInfo *primitive_info,
5589 const PointInfo start,const PointInfo end,PointInfo arc)
5596 register PrimitiveInfo
5603 offset.x=fabs(end.x-start.x);
5604 offset.y=fabs(end.y-start.y);
5605 if (arc.x > (0.5*offset.x))
5607 if (arc.y > (0.5*offset.y))
5609 point.x=start.x+offset.x-arc.x;
5610 point.y=start.y+arc.y;
5613 TraceEllipse(p,point,arc,degrees);
5615 point.x=start.x+offset.x-arc.x;
5616 point.y=start.y+offset.y-arc.y;
5619 TraceEllipse(p,point,arc,degrees);
5621 point.x=start.x+arc.x;
5622 point.y=start.y+offset.y-arc.y;
5625 TraceEllipse(p,point,arc,degrees);
5627 point.x=start.x+arc.x;
5628 point.y=start.y+arc.y;
5631 TraceEllipse(p,point,arc,degrees);
5633 TracePoint(p,primitive_info->point);
5635 primitive_info->coordinates=(unsigned long) (p-primitive_info);
5636 for (i=0; i < (long) primitive_info->coordinates; i++)
5638 p->primitive=primitive_info->primitive;
5643 static void TraceSquareLinecap(PrimitiveInfo *primitive_info,
5644 const unsigned long number_vertices,const MagickRealType offset)
5652 register MagickRealType
5661 for (i=1; i < (long) number_vertices; i++)
5663 dx=primitive_info[0].point.x-primitive_info[i].point.x;
5664 dy=primitive_info[0].point.y-primitive_info[i].point.y;
5665 if ((fabs((double) dx) >= MagickEpsilon) ||
5666 (fabs((double) dy) >= MagickEpsilon))
5669 if (i == (long) number_vertices)
5670 i=(long) number_vertices-1L;
5671 distance=hypot((double) dx,(double) dy);
5672 primitive_info[0].point.x=(double) (primitive_info[i].point.x+
5673 dx*(distance+offset)/distance);
5674 primitive_info[0].point.y=(double) (primitive_info[i].point.y+
5675 dy*(distance+offset)/distance);
5676 for (j=(long) number_vertices-2; j >= 0; j--)
5678 dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x;
5679 dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y;
5680 if ((fabs((double) dx) >= MagickEpsilon) ||
5681 (fabs((double) dy) >= MagickEpsilon))
5684 distance=hypot((double) dx,(double) dy);
5685 primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+
5686 dx*(distance+offset)/distance);
5687 primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+
5688 dy*(distance+offset)/distance);
5691 static PrimitiveInfo *TraceStrokePolygon(const DrawInfo *draw_info,
5692 const PrimitiveInfo *primitive_info)
5694 typedef struct _LineSegment
5746 number_vertices=primitive_info->coordinates;
5747 max_strokes=2*number_vertices+6*BezierQuantum+360;
5748 path_p=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes,
5750 path_q=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes,
5752 polygon_primitive=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
5753 number_vertices+2UL,sizeof(*polygon_primitive));
5754 if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL) ||
5755 (polygon_primitive == (PrimitiveInfo *) NULL))
5756 return((PrimitiveInfo *) NULL);
5757 (void) CopyMagickMemory(polygon_primitive,primitive_info,(size_t)
5758 number_vertices*sizeof(*polygon_primitive));
5760 (primitive_info[number_vertices-1].point.x == primitive_info[0].point.x) &&
5761 (primitive_info[number_vertices-1].point.y == primitive_info[0].point.y) ?
5762 MagickTrue : MagickFalse;
5763 if ((draw_info->linejoin == RoundJoin) ||
5764 ((draw_info->linejoin == MiterJoin) && (closed_path != MagickFalse)))
5766 polygon_primitive[number_vertices]=primitive_info[1];
5769 polygon_primitive[number_vertices].primitive=UndefinedPrimitive;
5771 Compute the slope for the first line segment, p.
5775 for (n=1; n < (long) number_vertices; n++)
5777 dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x;
5778 dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y;
5779 if ((fabs(dx.p) >= MagickEpsilon) || (fabs(dy.p) >= MagickEpsilon))
5782 if (n == (long) number_vertices)
5783 n=(long) number_vertices-1L;
5785 inverse_slope.p=0.0;
5786 if (fabs(dx.p) <= MagickEpsilon)
5789 slope.p=dy.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5791 slope.p=dy.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5794 if (fabs(dy.p) <= MagickEpsilon)
5797 inverse_slope.p=dx.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5799 inverse_slope.p=dx.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5804 inverse_slope.p=(-1.0/slope.p);
5806 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5807 miterlimit=(MagickRealType) (draw_info->miterlimit*draw_info->miterlimit*
5809 if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse))
5810 TraceSquareLinecap(polygon_primitive,number_vertices,mid);
5811 offset.x=sqrt((double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0)));
5812 offset.y=(double) (offset.x*inverse_slope.p);
5813 if ((dy.p*offset.x-dx.p*offset.y) > 0.0)
5815 box_p[0].x=polygon_primitive[0].point.x-offset.x;
5816 box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p;
5817 box_p[1].x=polygon_primitive[n].point.x-offset.x;
5818 box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p;
5819 box_q[0].x=polygon_primitive[0].point.x+offset.x;
5820 box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p;
5821 box_q[1].x=polygon_primitive[n].point.x+offset.x;
5822 box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p;
5826 box_p[0].x=polygon_primitive[0].point.x+offset.x;
5827 box_p[0].y=polygon_primitive[0].point.y+offset.y;
5828 box_p[1].x=polygon_primitive[n].point.x+offset.x;
5829 box_p[1].y=polygon_primitive[n].point.y+offset.y;
5830 box_q[0].x=polygon_primitive[0].point.x-offset.x;
5831 box_q[0].y=polygon_primitive[0].point.y-offset.y;
5832 box_q[1].x=polygon_primitive[n].point.x-offset.x;
5833 box_q[1].y=polygon_primitive[n].point.y-offset.y;
5836 Create strokes for the line join attribute: bevel, miter, round.
5840 path_q[p++]=box_q[0];
5841 path_p[q++]=box_p[0];
5842 for (i=(long) n+1; i < (long) number_vertices; i++)
5845 Compute the slope for this line segment, q.
5847 dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x;
5848 dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y;
5849 dot_product=dx.q*dx.q+dy.q*dy.q;
5850 if (dot_product < 0.25)
5853 inverse_slope.q=0.0;
5854 if (fabs(dx.q) < MagickEpsilon)
5857 slope.q=dy.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5859 slope.q=dy.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5862 if (fabs(dy.q) <= MagickEpsilon)
5865 inverse_slope.q=dx.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5867 inverse_slope.q=dx.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5872 inverse_slope.q=(-1.0/slope.q);
5874 offset.x=sqrt((double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0)));
5875 offset.y=(double) (offset.x*inverse_slope.q);
5876 dot_product=dy.q*offset.x-dx.q*offset.y;
5877 if (dot_product > 0.0)
5879 box_p[2].x=polygon_primitive[n].point.x-offset.x;
5880 box_p[2].y=polygon_primitive[n].point.y-offset.y;
5881 box_p[3].x=polygon_primitive[i].point.x-offset.x;
5882 box_p[3].y=polygon_primitive[i].point.y-offset.y;
5883 box_q[2].x=polygon_primitive[n].point.x+offset.x;
5884 box_q[2].y=polygon_primitive[n].point.y+offset.y;
5885 box_q[3].x=polygon_primitive[i].point.x+offset.x;
5886 box_q[3].y=polygon_primitive[i].point.y+offset.y;
5890 box_p[2].x=polygon_primitive[n].point.x+offset.x;
5891 box_p[2].y=polygon_primitive[n].point.y+offset.y;
5892 box_p[3].x=polygon_primitive[i].point.x+offset.x;
5893 box_p[3].y=polygon_primitive[i].point.y+offset.y;
5894 box_q[2].x=polygon_primitive[n].point.x-offset.x;
5895 box_q[2].y=polygon_primitive[n].point.y-offset.y;
5896 box_q[3].x=polygon_primitive[i].point.x-offset.x;
5897 box_q[3].y=polygon_primitive[i].point.y-offset.y;
5899 if (fabs((double) (slope.p-slope.q)) <= MagickEpsilon)
5906 box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+
5907 box_p[3].y)/(slope.p-slope.q));
5908 box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y);
5909 box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+
5910 box_q[3].y)/(slope.p-slope.q));
5911 box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y);
5913 if (q >= (long) (max_strokes-6*BezierQuantum-360))
5915 max_strokes+=6*BezierQuantum+360;
5916 path_p=(PointInfo *) ResizeQuantumMemory(path_p,(size_t) max_strokes,
5918 path_q=(PointInfo *) ResizeQuantumMemory(path_q,(size_t) max_strokes,
5920 if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL))
5922 polygon_primitive=(PrimitiveInfo *)
5923 RelinquishMagickMemory(polygon_primitive);
5924 return((PrimitiveInfo *) NULL);
5927 dot_product=dx.q*dy.p-dx.p*dy.q;
5928 if (dot_product <= 0.0)
5929 switch (draw_info->linejoin)
5933 path_q[q++]=box_q[1];
5934 path_q[q++]=box_q[2];
5935 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5936 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5937 if (dot_product <= miterlimit)
5938 path_p[p++]=box_p[4];
5941 path_p[p++]=box_p[1];
5942 path_p[p++]=box_p[2];
5948 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5949 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5950 if (dot_product <= miterlimit)
5952 path_q[q++]=box_q[4];
5953 path_p[p++]=box_p[4];
5957 path_q[q++]=box_q[1];
5958 path_q[q++]=box_q[2];
5959 path_p[p++]=box_p[1];
5960 path_p[p++]=box_p[2];
5966 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5967 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5968 if (dot_product <= miterlimit)
5969 path_p[p++]=box_p[4];
5972 path_p[p++]=box_p[1];
5973 path_p[p++]=box_p[2];
5975 center=polygon_primitive[n].point;
5976 theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x);
5977 theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x);
5978 if (theta.q < theta.p)
5979 theta.q+=(MagickRealType) (2.0*MagickPI);
5980 arc_segments=(unsigned long) ceil((double) ((theta.q-theta.p)/
5981 (2.0*sqrt((double) (1.0/mid)))));
5982 path_q[q].x=box_q[1].x;
5983 path_q[q].y=box_q[1].y;
5985 for (j=1; j < (long) arc_segments; j++)
5987 delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments);
5988 path_q[q].x=(double) (center.x+mid*cos(fmod((double)
5989 (theta.p+delta_theta),DegreesToRadians(360.0))));
5990 path_q[q].y=(double) (center.y+mid*sin(fmod((double)
5991 (theta.p+delta_theta),DegreesToRadians(360.0))));
5994 path_q[q++]=box_q[2];
6001 switch (draw_info->linejoin)
6005 path_p[p++]=box_p[1];
6006 path_p[p++]=box_p[2];
6007 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6008 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6009 if (dot_product <= miterlimit)
6010 path_q[q++]=box_q[4];
6013 path_q[q++]=box_q[1];
6014 path_q[q++]=box_q[2];
6020 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6021 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6022 if (dot_product <= miterlimit)
6024 path_q[q++]=box_q[4];
6025 path_p[p++]=box_p[4];
6029 path_q[q++]=box_q[1];
6030 path_q[q++]=box_q[2];
6031 path_p[p++]=box_p[1];
6032 path_p[p++]=box_p[2];
6038 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6039 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6040 if (dot_product <= miterlimit)
6041 path_q[q++]=box_q[4];
6044 path_q[q++]=box_q[1];
6045 path_q[q++]=box_q[2];
6047 center=polygon_primitive[n].point;
6048 theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x);
6049 theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x);
6050 if (theta.p < theta.q)
6051 theta.p+=(MagickRealType) (2.0*MagickPI);
6052 arc_segments=(unsigned long) ceil((double) ((theta.p-theta.q)/
6053 (2.0*sqrt((double) (1.0/mid)))));
6054 path_p[p++]=box_p[1];
6055 for (j=1; j < (long) arc_segments; j++)
6057 delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments);
6058 path_p[p].x=(double) (center.x+mid*cos(fmod((double)
6059 (theta.p+delta_theta),DegreesToRadians(360.0))));
6060 path_p[p].y=(double) (center.y+mid*sin(fmod((double)
6061 (theta.p+delta_theta),DegreesToRadians(360.0))));
6064 path_p[p++]=box_p[2];
6071 inverse_slope.p=inverse_slope.q;
6080 path_p[p++]=box_p[1];
6081 path_q[q++]=box_q[1];
6083 Trace stroked polygon.
6085 stroke_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
6086 (p+q+2UL*closed_path+2UL),sizeof(*stroke_polygon));
6087 if (stroke_polygon != (PrimitiveInfo *) NULL)
6089 for (i=0; i < (long) p; i++)
6091 stroke_polygon[i]=polygon_primitive[0];
6092 stroke_polygon[i].point=path_p[i];
6094 if (closed_path != MagickFalse)
6096 stroke_polygon[i]=polygon_primitive[0];
6097 stroke_polygon[i].point=stroke_polygon[0].point;
6100 for ( ; i < (long) (p+q+closed_path); i++)
6102 stroke_polygon[i]=polygon_primitive[0];
6103 stroke_polygon[i].point=path_q[p+q+closed_path-(i+1)];
6105 if (closed_path != MagickFalse)
6107 stroke_polygon[i]=polygon_primitive[0];
6108 stroke_polygon[i].point=stroke_polygon[p+closed_path].point;
6111 stroke_polygon[i]=polygon_primitive[0];
6112 stroke_polygon[i].point=stroke_polygon[0].point;
6114 stroke_polygon[i].primitive=UndefinedPrimitive;
6115 stroke_polygon[0].coordinates=(unsigned long) (p+q+2*closed_path+1);
6117 path_p=(PointInfo *) RelinquishMagickMemory(path_p);
6118 path_q=(PointInfo *) RelinquishMagickMemory(path_q);
6119 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive);
6120 return(stroke_polygon);