2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 % D D RRRR AAAAA W W W %
13 % MagickCore Image Drawing Methods %
21 % Copyright 1999-2012 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 "MagickCore/studio.h"
49 #include "MagickCore/annotate.h"
50 #include "MagickCore/artifact.h"
51 #include "MagickCore/blob.h"
52 #include "MagickCore/cache.h"
53 #include "MagickCore/cache-view.h"
54 #include "MagickCore/color.h"
55 #include "MagickCore/colorspace-private.h"
56 #include "MagickCore/composite.h"
57 #include "MagickCore/composite-private.h"
58 #include "MagickCore/constitute.h"
59 #include "MagickCore/draw.h"
60 #include "MagickCore/draw-private.h"
61 #include "MagickCore/enhance.h"
62 #include "MagickCore/exception.h"
63 #include "MagickCore/exception-private.h"
64 #include "MagickCore/gem.h"
65 #include "MagickCore/geometry.h"
66 #include "MagickCore/image-private.h"
67 #include "MagickCore/list.h"
68 #include "MagickCore/log.h"
69 #include "MagickCore/monitor.h"
70 #include "MagickCore/monitor-private.h"
71 #include "MagickCore/option.h"
72 #include "MagickCore/paint.h"
73 #include "MagickCore/pixel-accessor.h"
74 #include "MagickCore/property.h"
75 #include "MagickCore/resample.h"
76 #include "MagickCore/resample-private.h"
77 #include "MagickCore/resource_.h"
78 #include "MagickCore/string_.h"
79 #include "MagickCore/string-private.h"
80 #include "MagickCore/thread-private.h"
81 #include "MagickCore/token.h"
82 #include "MagickCore/transform.h"
83 #include "MagickCore/utility.h"
88 #define BezierQuantum 200
93 typedef struct _EdgeInfo
117 typedef struct _ElementInfo
127 typedef struct _PolygonInfo
145 typedef struct _PathInfo
155 Forward declarations.
157 static MagickBooleanType
158 DrawStrokePolygon(Image *,const DrawInfo *,const PrimitiveInfo *,
162 *TraceStrokePolygon(const DrawInfo *,const PrimitiveInfo *);
165 TracePath(PrimitiveInfo *,const char *);
168 TraceArc(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo),
169 TraceArcPath(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo,
170 const MagickRealType,const MagickBooleanType,const MagickBooleanType),
171 TraceBezier(PrimitiveInfo *,const size_t),
172 TraceCircle(PrimitiveInfo *,const PointInfo,const PointInfo),
173 TraceEllipse(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo),
174 TraceLine(PrimitiveInfo *,const PointInfo,const PointInfo),
175 TraceRectangle(PrimitiveInfo *,const PointInfo,const PointInfo),
176 TraceRoundRectangle(PrimitiveInfo *,const PointInfo,const PointInfo,
178 TraceSquareLinecap(PrimitiveInfo *,const size_t,const MagickRealType);
181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 % A c q u i r e D r a w I n f o %
189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 % AcquireDrawInfo() returns a DrawInfo structure properly initialized.
193 % The format of the AcquireDrawInfo method is:
195 % DrawInfo *AcquireDrawInfo(void)
198 MagickExport DrawInfo *AcquireDrawInfo(void)
203 draw_info=(DrawInfo *) AcquireMagickMemory(sizeof(*draw_info));
204 if (draw_info == (DrawInfo *) NULL)
205 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
206 GetDrawInfo((ImageInfo *) NULL,draw_info);
211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215 % C l o n e D r a w I n f o %
219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 % CloneDrawInfo() makes a copy of the given draw_info structure. If NULL
222 % is specified, a new draw_info structure is created initialized to
223 % default values, according to the given image_info.
225 % The format of the CloneDrawInfo method is:
227 % DrawInfo *CloneDrawInfo(const ImageInfo *image_info,
228 % const DrawInfo *draw_info)
230 % A description of each parameter follows:
232 % o image_info: the image info.
234 % o draw_info: the draw info.
237 MagickExport DrawInfo *CloneDrawInfo(const ImageInfo *image_info,
238 const DrawInfo *draw_info)
246 clone_info=(DrawInfo *) AcquireMagickMemory(sizeof(*clone_info));
247 if (clone_info == (DrawInfo *) NULL)
248 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
249 GetDrawInfo(image_info,clone_info);
250 if (draw_info == (DrawInfo *) NULL)
252 exception=AcquireExceptionInfo();
253 (void) CloneString(&clone_info->primitive,draw_info->primitive);
254 (void) CloneString(&clone_info->geometry,draw_info->geometry);
255 clone_info->viewbox=draw_info->viewbox;
256 clone_info->affine=draw_info->affine;
257 clone_info->gravity=draw_info->gravity;
258 clone_info->fill=draw_info->fill;
259 clone_info->stroke=draw_info->stroke;
260 clone_info->stroke_width=draw_info->stroke_width;
261 if (draw_info->fill_pattern != (Image *) NULL)
262 clone_info->fill_pattern=CloneImage(draw_info->fill_pattern,0,0,MagickTrue,
264 if (draw_info->stroke_pattern != (Image *) NULL)
265 clone_info->stroke_pattern=CloneImage(draw_info->stroke_pattern,0,0,
266 MagickTrue,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 (void) CloneString(&clone_info->text,draw_info->text);
277 (void) CloneString(&clone_info->font,draw_info->font);
278 (void) CloneString(&clone_info->metrics,draw_info->metrics);
279 (void) CloneString(&clone_info->family,draw_info->family);
280 clone_info->style=draw_info->style;
281 clone_info->stretch=draw_info->stretch;
282 clone_info->weight=draw_info->weight;
283 (void) CloneString(&clone_info->encoding,draw_info->encoding);
284 clone_info->pointsize=draw_info->pointsize;
285 clone_info->kerning=draw_info->kerning;
286 clone_info->interline_spacing=draw_info->interline_spacing;
287 clone_info->interword_spacing=draw_info->interword_spacing;
288 clone_info->direction=draw_info->direction;
289 (void) CloneString(&clone_info->density,draw_info->density);
290 clone_info->align=draw_info->align;
291 clone_info->undercolor=draw_info->undercolor;
292 clone_info->border_color=draw_info->border_color;
293 (void) CloneString(&clone_info->server_name,draw_info->server_name);
294 if (draw_info->dash_pattern != (double *) NULL)
299 for (x=0; draw_info->dash_pattern[x] != 0.0; x++) ;
300 clone_info->dash_pattern=(double *) AcquireQuantumMemory((size_t) x+1UL,
301 sizeof(*clone_info->dash_pattern));
302 if (clone_info->dash_pattern == (double *) NULL)
303 ThrowFatalException(ResourceLimitFatalError,
304 "UnableToAllocateDashPattern");
305 (void) CopyMagickMemory(clone_info->dash_pattern,draw_info->dash_pattern,
306 (size_t) (x+1)*sizeof(*clone_info->dash_pattern));
308 clone_info->gradient=draw_info->gradient;
309 if (draw_info->gradient.stops != (StopInfo *) NULL)
314 number_stops=clone_info->gradient.number_stops;
315 clone_info->gradient.stops=(StopInfo *) AcquireQuantumMemory((size_t)
316 number_stops,sizeof(*clone_info->gradient.stops));
317 if (clone_info->gradient.stops == (StopInfo *) NULL)
318 ThrowFatalException(ResourceLimitFatalError,
319 "UnableToAllocateDashPattern");
320 (void) CopyMagickMemory(clone_info->gradient.stops,
321 draw_info->gradient.stops,(size_t) number_stops*
322 sizeof(*clone_info->gradient.stops));
324 (void) CloneString(&clone_info->clip_mask,draw_info->clip_mask);
325 clone_info->bounds=draw_info->bounds;
326 clone_info->clip_units=draw_info->clip_units;
327 clone_info->render=draw_info->render;
328 clone_info->alpha=draw_info->alpha;
329 clone_info->element_reference=draw_info->element_reference;
330 clone_info->debug=IsEventLogging();
331 exception=DestroyExceptionInfo(exception);
336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
340 + C o n v e r t P a t h T o P o l y g o n %
344 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
346 % ConvertPathToPolygon() converts a path to the more efficient sorted
349 % The format of the ConvertPathToPolygon method is:
351 % PolygonInfo *ConvertPathToPolygon(const DrawInfo *draw_info,
352 % const PathInfo *path_info)
354 % A description of each parameter follows:
356 % o Method ConvertPathToPolygon returns the path in a more efficient sorted
357 % rendering form of type PolygonInfo.
359 % o draw_info: Specifies a pointer to an DrawInfo structure.
361 % o path_info: Specifies a pointer to an PathInfo structure.
366 #if defined(__cplusplus) || defined(c_plusplus)
370 static int CompareEdges(const void *x,const void *y)
372 register const EdgeInfo
379 p=(const EdgeInfo *) x;
380 q=(const EdgeInfo *) y;
381 if ((p->points[0].y-MagickEpsilon) > q->points[0].y)
383 if ((p->points[0].y+MagickEpsilon) < q->points[0].y)
385 if ((p->points[0].x-MagickEpsilon) > q->points[0].x)
387 if ((p->points[0].x+MagickEpsilon) < q->points[0].x)
389 if (((p->points[1].x-p->points[0].x)*(q->points[1].y-q->points[0].y)-
390 (p->points[1].y-p->points[0].y)*(q->points[1].x-q->points[0].x)) > 0.0)
395 #if defined(__cplusplus) || defined(c_plusplus)
399 static void LogPolygonInfo(const PolygonInfo *polygon_info)
408 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin active-edge");
409 p=polygon_info->edges;
410 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
412 (void) LogMagickEvent(DrawEvent,GetMagickModule()," edge %.20g:",
414 (void) LogMagickEvent(DrawEvent,GetMagickModule()," direction: %s",
415 p->direction != MagickFalse ? "down" : "up");
416 (void) LogMagickEvent(DrawEvent,GetMagickModule()," ghostline: %s",
417 p->ghostline != MagickFalse ? "transparent" : "opaque");
418 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
419 " bounds: %g %g - %g %g",p->bounds.x1,p->bounds.y1,
420 p->bounds.x2,p->bounds.y2);
421 for (j=0; j < (ssize_t) p->number_points; j++)
422 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %g %g",
423 p->points[j].x,p->points[j].y);
426 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end active-edge");
429 static void ReversePoints(PointInfo *points,const size_t number_points)
437 for (i=0; i < (ssize_t) (number_points >> 1); i++)
440 points[i]=points[number_points-(i+1)];
441 points[number_points-(i+1)]=point;
445 static PolygonInfo *ConvertPathToPolygon(
446 const DrawInfo *magick_unused(draw_info),const PathInfo *path_info)
475 Convert a path to the more efficient sorted rendering form.
477 polygon_info=(PolygonInfo *) AcquireMagickMemory(sizeof(*polygon_info));
478 if (polygon_info == (PolygonInfo *) NULL)
479 return((PolygonInfo *) NULL);
481 polygon_info->edges=(EdgeInfo *) AcquireQuantumMemory((size_t) number_edges,
482 sizeof(*polygon_info->edges));
483 if (polygon_info->edges == (EdgeInfo *) NULL)
484 return((PolygonInfo *) NULL);
487 ghostline=MagickFalse;
490 points=(PointInfo *) NULL;
491 (void) ResetMagickMemory(&point,0,sizeof(point));
492 (void) ResetMagickMemory(&bounds,0,sizeof(bounds));
493 for (i=0; path_info[i].code != EndCode; i++)
495 if ((path_info[i].code == MoveToCode) || (path_info[i].code == OpenCode) ||
496 (path_info[i].code == GhostlineCode))
501 if ((points != (PointInfo *) NULL) && (n >= 2))
503 if (edge == number_edges)
506 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
507 polygon_info->edges,(size_t) number_edges,
508 sizeof(*polygon_info->edges));
509 if (polygon_info->edges == (EdgeInfo *) NULL)
510 return((PolygonInfo *) NULL);
512 polygon_info->edges[edge].number_points=(size_t) n;
513 polygon_info->edges[edge].scanline=(-1.0);
514 polygon_info->edges[edge].highwater=0;
515 polygon_info->edges[edge].ghostline=ghostline;
516 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
518 ReversePoints(points,(size_t) n);
519 polygon_info->edges[edge].points=points;
520 polygon_info->edges[edge].bounds=bounds;
521 polygon_info->edges[edge].bounds.y1=points[0].y;
522 polygon_info->edges[edge].bounds.y2=points[n-1].y;
523 points=(PointInfo *) NULL;
524 ghostline=MagickFalse;
527 if (points == (PointInfo *) NULL)
530 points=(PointInfo *) AcquireQuantumMemory((size_t) number_points,
532 if (points == (PointInfo *) NULL)
533 return((PolygonInfo *) NULL);
535 ghostline=path_info[i].code == GhostlineCode ? MagickTrue : MagickFalse;
536 point=path_info[i].point;
547 next_direction=((path_info[i].point.y > point.y) ||
548 ((path_info[i].point.y == point.y) &&
549 (path_info[i].point.x > point.x))) ? 1 : -1;
550 if ((direction != 0) && (direction != next_direction))
556 if (edge == number_edges)
559 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
560 polygon_info->edges,(size_t) number_edges,
561 sizeof(*polygon_info->edges));
562 if (polygon_info->edges == (EdgeInfo *) NULL)
563 return((PolygonInfo *) NULL);
565 polygon_info->edges[edge].number_points=(size_t) n;
566 polygon_info->edges[edge].scanline=(-1.0);
567 polygon_info->edges[edge].highwater=0;
568 polygon_info->edges[edge].ghostline=ghostline;
569 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
571 ReversePoints(points,(size_t) n);
572 polygon_info->edges[edge].points=points;
573 polygon_info->edges[edge].bounds=bounds;
574 polygon_info->edges[edge].bounds.y1=points[0].y;
575 polygon_info->edges[edge].bounds.y2=points[n-1].y;
577 points=(PointInfo *) AcquireQuantumMemory((size_t) number_points,
579 if (points == (PointInfo *) NULL)
580 return((PolygonInfo *) NULL);
582 ghostline=MagickFalse;
588 direction=next_direction;
589 if (points == (PointInfo *) NULL)
591 if (n == (ssize_t) number_points)
594 points=(PointInfo *) ResizeQuantumMemory(points,(size_t) number_points,
596 if (points == (PointInfo *) NULL)
597 return((PolygonInfo *) NULL);
599 point=path_info[i].point;
601 if (point.x < bounds.x1)
603 if (point.x > bounds.x2)
607 if (points != (PointInfo *) NULL)
610 points=(PointInfo *) RelinquishMagickMemory(points);
613 if (edge == number_edges)
616 polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
617 polygon_info->edges,(size_t) number_edges,
618 sizeof(*polygon_info->edges));
619 if (polygon_info->edges == (EdgeInfo *) NULL)
620 return((PolygonInfo *) NULL);
622 polygon_info->edges[edge].number_points=(size_t) n;
623 polygon_info->edges[edge].scanline=(-1.0);
624 polygon_info->edges[edge].highwater=0;
625 polygon_info->edges[edge].ghostline=ghostline;
626 polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
628 ReversePoints(points,(size_t) n);
629 polygon_info->edges[edge].points=points;
630 polygon_info->edges[edge].bounds=bounds;
631 polygon_info->edges[edge].bounds.y1=points[0].y;
632 polygon_info->edges[edge].bounds.y2=points[n-1].y;
633 ghostline=MagickFalse;
637 polygon_info->number_edges=edge;
638 qsort(polygon_info->edges,(size_t) polygon_info->number_edges,
639 sizeof(*polygon_info->edges),CompareEdges);
640 if (IsEventLogging() != MagickFalse)
641 LogPolygonInfo(polygon_info);
642 return(polygon_info);
646 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
650 + C o n v e r t P r i m i t i v e T o P a t h %
654 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
656 % ConvertPrimitiveToPath() converts a PrimitiveInfo structure into a vector
659 % The format of the ConvertPrimitiveToPath method is:
661 % PathInfo *ConvertPrimitiveToPath(const DrawInfo *draw_info,
662 % const PrimitiveInfo *primitive_info)
664 % A description of each parameter follows:
666 % o Method ConvertPrimitiveToPath returns a vector path structure of type
669 % o draw_info: a structure of type DrawInfo.
671 % o primitive_info: Specifies a pointer to an PrimitiveInfo structure.
676 static void LogPathInfo(const PathInfo *path_info)
678 register const PathInfo
681 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin vector-path");
682 for (p=path_info; p->code != EndCode; p++)
683 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
684 " %g %g %s",p->point.x,p->point.y,p->code == GhostlineCode ?
685 "moveto ghostline" : p->code == OpenCode ? "moveto open" :
686 p->code == MoveToCode ? "moveto" : p->code == LineToCode ? "lineto" :
688 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end vector-path");
691 static PathInfo *ConvertPrimitiveToPath(
692 const DrawInfo *magick_unused(draw_info),const PrimitiveInfo *primitive_info)
713 Converts a PrimitiveInfo structure into a vector path structure.
715 switch (primitive_info->primitive)
722 return((PathInfo *) NULL);
726 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
727 path_info=(PathInfo *) AcquireQuantumMemory((size_t) (2UL*i+3UL),
729 if (path_info == (PathInfo *) NULL)
730 return((PathInfo *) NULL);
738 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
741 if (coordinates <= 0)
743 coordinates=(ssize_t) primitive_info[i].coordinates;
744 p=primitive_info[i].point;
750 Eliminate duplicate points.
752 if ((i == 0) || (fabs(q.x-primitive_info[i].point.x) > MagickEpsilon) ||
753 (fabs(q.y-primitive_info[i].point.y) > MagickEpsilon))
755 path_info[n].code=code;
756 path_info[n].point=primitive_info[i].point;
757 q=primitive_info[i].point;
762 if ((fabs(p.x-primitive_info[i].point.x) <= MagickEpsilon) &&
763 (fabs(p.y-primitive_info[i].point.y) <= MagickEpsilon))
766 Mark the p point as open if it does not match the q.
768 path_info[start].code=OpenCode;
769 path_info[n].code=GhostlineCode;
770 path_info[n].point=primitive_info[i].point;
772 path_info[n].code=LineToCode;
773 path_info[n].point=p;
776 path_info[n].code=EndCode;
777 path_info[n].point.x=0.0;
778 path_info[n].point.y=0.0;
779 if (IsEventLogging() != MagickFalse)
780 LogPathInfo(path_info);
785 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
789 % D e s t r o y D r a w I n f o %
793 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
795 % DestroyDrawInfo() deallocates memory associated with an DrawInfo
798 % The format of the DestroyDrawInfo method is:
800 % DrawInfo *DestroyDrawInfo(DrawInfo *draw_info)
802 % A description of each parameter follows:
804 % o draw_info: the draw info.
807 MagickExport DrawInfo *DestroyDrawInfo(DrawInfo *draw_info)
809 if (draw_info->debug != MagickFalse)
810 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
811 assert(draw_info != (DrawInfo *) NULL);
812 assert(draw_info->signature == MagickSignature);
813 if (draw_info->primitive != (char *) NULL)
814 draw_info->primitive=DestroyString(draw_info->primitive);
815 if (draw_info->text != (char *) NULL)
816 draw_info->text=DestroyString(draw_info->text);
817 if (draw_info->geometry != (char *) NULL)
818 draw_info->geometry=DestroyString(draw_info->geometry);
819 if (draw_info->fill_pattern != (Image *) NULL)
820 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
821 if (draw_info->stroke_pattern != (Image *) NULL)
822 draw_info->stroke_pattern=DestroyImage(draw_info->stroke_pattern);
823 if (draw_info->font != (char *) NULL)
824 draw_info->font=DestroyString(draw_info->font);
825 if (draw_info->metrics != (char *) NULL)
826 draw_info->metrics=DestroyString(draw_info->metrics);
827 if (draw_info->family != (char *) NULL)
828 draw_info->family=DestroyString(draw_info->family);
829 if (draw_info->encoding != (char *) NULL)
830 draw_info->encoding=DestroyString(draw_info->encoding);
831 if (draw_info->density != (char *) NULL)
832 draw_info->density=DestroyString(draw_info->density);
833 if (draw_info->server_name != (char *) NULL)
834 draw_info->server_name=(char *)
835 RelinquishMagickMemory(draw_info->server_name);
836 if (draw_info->dash_pattern != (double *) NULL)
837 draw_info->dash_pattern=(double *) RelinquishMagickMemory(
838 draw_info->dash_pattern);
839 if (draw_info->gradient.stops != (StopInfo *) NULL)
840 draw_info->gradient.stops=(StopInfo *) RelinquishMagickMemory(
841 draw_info->gradient.stops);
842 if (draw_info->clip_mask != (char *) NULL)
843 draw_info->clip_mask=DestroyString(draw_info->clip_mask);
844 draw_info->signature=(~MagickSignature);
845 draw_info=(DrawInfo *) RelinquishMagickMemory(draw_info);
850 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
854 + D e s t r o y E d g e %
858 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
860 % DestroyEdge() destroys the specified polygon edge.
862 % The format of the DestroyEdge method is:
864 % ssize_t DestroyEdge(PolygonInfo *polygon_info,const int edge)
866 % A description of each parameter follows:
868 % o polygon_info: Specifies a pointer to an PolygonInfo structure.
870 % o edge: the polygon edge number to destroy.
873 static size_t DestroyEdge(PolygonInfo *polygon_info,
876 assert(edge < polygon_info->number_edges);
877 polygon_info->edges[edge].points=(PointInfo *) RelinquishMagickMemory(
878 polygon_info->edges[edge].points);
879 polygon_info->number_edges--;
880 if (edge < polygon_info->number_edges)
881 (void) CopyMagickMemory(polygon_info->edges+edge,polygon_info->edges+edge+1,
882 (size_t) (polygon_info->number_edges-edge)*sizeof(*polygon_info->edges));
883 return(polygon_info->number_edges);
887 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
891 + D e s t r o y P o l y g o n I n f o %
895 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
897 % DestroyPolygonInfo() destroys the PolygonInfo data structure.
899 % The format of the DestroyPolygonInfo method is:
901 % PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info)
903 % A description of each parameter follows:
905 % o polygon_info: Specifies a pointer to an PolygonInfo structure.
908 static PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info)
913 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
914 polygon_info->edges[i].points=(PointInfo *)
915 RelinquishMagickMemory(polygon_info->edges[i].points);
916 polygon_info->edges=(EdgeInfo *) RelinquishMagickMemory(polygon_info->edges);
917 return((PolygonInfo *) RelinquishMagickMemory(polygon_info));
921 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
925 % D r a w A f f i n e I m a g e %
929 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
931 % DrawAffineImage() composites the source over the destination image as
932 % dictated by the affine transform.
934 % The format of the DrawAffineImage method is:
936 % MagickBooleanType DrawAffineImage(Image *image,const Image *source,
937 % const AffineMatrix *affine,ExceptionInfo *exception)
939 % A description of each parameter follows:
941 % o image: the image.
943 % o source: the source image.
945 % o affine: the affine transform.
947 % o exception: return any errors or warnings in this structure.
951 static SegmentInfo AffineEdge(const Image *image,const AffineMatrix *affine,
952 const double y,const SegmentInfo *edge)
965 Determine left and right edges.
967 inverse_edge.x1=edge->x1;
968 inverse_edge.y1=edge->y1;
969 inverse_edge.x2=edge->x2;
970 inverse_edge.y2=edge->y2;
971 z=affine->ry*y+affine->tx;
972 if (affine->sx > MagickEpsilon)
974 intercept=(-z/affine->sx);
976 if (x > inverse_edge.x1)
978 intercept=(-z+(double) image->columns)/affine->sx;
980 if (x < inverse_edge.x2)
984 if (affine->sx < -MagickEpsilon)
986 intercept=(-z+(double) image->columns)/affine->sx;
988 if (x > inverse_edge.x1)
990 intercept=(-z/affine->sx);
992 if (x < inverse_edge.x2)
996 if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->columns))
998 inverse_edge.x2=edge->x1;
999 return(inverse_edge);
1002 Determine top and bottom edges.
1004 z=affine->sy*y+affine->ty;
1005 if (affine->rx > MagickEpsilon)
1007 intercept=(-z/affine->rx);
1009 if (x > inverse_edge.x1)
1011 intercept=(-z+(double) image->rows)/affine->rx;
1013 if (x < inverse_edge.x2)
1017 if (affine->rx < -MagickEpsilon)
1019 intercept=(-z+(double) image->rows)/affine->rx;
1021 if (x > inverse_edge.x1)
1023 intercept=(-z/affine->rx);
1025 if (x < inverse_edge.x2)
1029 if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->rows))
1031 inverse_edge.x2=edge->x2;
1032 return(inverse_edge);
1034 return(inverse_edge);
1037 static AffineMatrix InverseAffineMatrix(const AffineMatrix *affine)
1045 determinant=1.0/(affine->sx*affine->sy-affine->rx*affine->ry);
1046 inverse_affine.sx=determinant*affine->sy;
1047 inverse_affine.rx=determinant*(-affine->rx);
1048 inverse_affine.ry=determinant*(-affine->ry);
1049 inverse_affine.sy=determinant*affine->sx;
1050 inverse_affine.tx=(-affine->tx)*inverse_affine.sx-affine->ty*
1052 inverse_affine.ty=(-affine->tx)*inverse_affine.rx-affine->ty*
1054 return(inverse_affine);
1057 static inline ssize_t MagickAbsoluteValue(const ssize_t x)
1064 static inline double MagickMax(const double x,const double y)
1071 static inline double MagickMin(const double x,const double y)
1078 MagickExport MagickBooleanType DrawAffineImage(Image *image,
1079 const Image *source,const AffineMatrix *affine,ExceptionInfo *exception)
1116 Determine bounding box.
1118 assert(image != (Image *) NULL);
1119 assert(image->signature == MagickSignature);
1120 if (image->debug != MagickFalse)
1121 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1122 assert(source != (const Image *) NULL);
1123 assert(source->signature == MagickSignature);
1124 assert(affine != (AffineMatrix *) NULL);
1127 extent[1].x=(double) source->columns-1.0;
1129 extent[2].x=(double) source->columns-1.0;
1130 extent[2].y=(double) source->rows-1.0;
1132 extent[3].y=(double) source->rows-1.0;
1133 for (i=0; i < 4; i++)
1136 extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx;
1137 extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty;
1141 for (i=1; i < 4; i++)
1143 if (min.x > extent[i].x)
1145 if (min.y > extent[i].y)
1147 if (max.x < extent[i].x)
1149 if (max.y < extent[i].y)
1153 Affine transform image.
1155 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1156 return(MagickFalse);
1158 edge.x1=MagickMax(min.x,0.0);
1159 edge.y1=MagickMax(min.y,0.0);
1160 edge.x2=MagickMin(max.x,(double) image->columns-1.0);
1161 edge.y2=MagickMin(max.y,(double) image->rows-1.0);
1162 inverse_affine=InverseAffineMatrix(affine);
1163 GetPixelInfo(image,&zero);
1164 start=(ssize_t) ceil(edge.y1-0.5);
1165 stop=(ssize_t) ceil(edge.y2-0.5);
1166 height=(size_t) (floor(edge.y2+0.5)-ceil(edge.y1-0.5));
1167 width=(size_t) (floor(edge.x2+0.5)-ceil(edge.x1-0.5));
1168 source_view=AcquireVirtualCacheView(source,exception);
1169 image_view=AcquireAuthenticCacheView(image,exception);
1170 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1171 #pragma omp parallel for schedule(static) shared(status) \
1172 dynamic_number_threads(width,height,1)
1174 for (y=start; y <= stop; y++)
1195 inverse_edge=AffineEdge(source,&inverse_affine,(double) y,&edge);
1196 if (inverse_edge.x2 < inverse_edge.x1)
1198 q=GetCacheViewAuthenticPixels(image_view,(ssize_t) ceil(inverse_edge.x1-
1199 0.5),y,(size_t) ((ssize_t) floor(inverse_edge.x2+0.5)-(ssize_t) floor(
1200 inverse_edge.x1+0.5)+1),1,exception);
1201 if (q == (Quantum *) NULL)
1206 for (x=(ssize_t) ceil(inverse_edge.x1-0.5); x <= (ssize_t) floor(inverse_edge.x2+0.5); x++)
1208 point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+
1210 point.y=(double) x*inverse_affine.rx+y*inverse_affine.sy+
1212 (void) InterpolatePixelInfo(source,source_view,UndefinedInterpolatePixel,
1213 point.x,point.y,&pixel,exception);
1214 GetPixelInfoPixel(image,q,&composite);
1215 CompositePixelInfoOver(&pixel,pixel.alpha,&composite,composite.alpha,
1217 SetPixelInfoPixel(image,&composite,q);
1219 q+=GetPixelChannels(image);
1221 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1224 source_view=DestroyCacheView(source_view);
1225 image_view=DestroyCacheView(image_view);
1230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1234 + D r a w B o u n d i n g R e c t a n g l e s %
1238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1240 % DrawBoundingRectangles() draws the bounding rectangles on the image. This
1241 % is only useful for developers debugging the rendering algorithm.
1243 % The format of the DrawBoundingRectangles method is:
1245 % void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info,
1246 % PolygonInfo *polygon_info,ExceptionInfo *exception)
1248 % A description of each parameter follows:
1250 % o image: the image.
1252 % o draw_info: the draw info.
1254 % o polygon_info: Specifies a pointer to a PolygonInfo structure.
1256 % o exception: return any errors or warnings in this structure.
1259 static void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info,
1260 const PolygonInfo *polygon_info,ExceptionInfo *exception)
1285 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1286 (void) QueryColorCompliance("#0000",AllCompliance,&clone_info->fill,
1288 resolution.x=DefaultResolution;
1289 resolution.y=DefaultResolution;
1290 if (clone_info->density != (char *) NULL)
1298 flags=ParseGeometry(clone_info->density,&geometry_info);
1299 resolution.x=geometry_info.rho;
1300 resolution.y=geometry_info.sigma;
1301 if ((flags & SigmaValue) == MagickFalse)
1302 resolution.y=resolution.x;
1304 mid=(resolution.x/72.0)*ExpandAffine(&clone_info->affine)*
1305 clone_info->stroke_width/2.0;
1310 if (polygon_info != (PolygonInfo *) NULL)
1312 bounds=polygon_info->edges[0].bounds;
1313 for (i=1; i < (ssize_t) polygon_info->number_edges; i++)
1315 if (polygon_info->edges[i].bounds.x1 < (double) bounds.x1)
1316 bounds.x1=polygon_info->edges[i].bounds.x1;
1317 if (polygon_info->edges[i].bounds.y1 < (double) bounds.y1)
1318 bounds.y1=polygon_info->edges[i].bounds.y1;
1319 if (polygon_info->edges[i].bounds.x2 > (double) bounds.x2)
1320 bounds.x2=polygon_info->edges[i].bounds.x2;
1321 if (polygon_info->edges[i].bounds.y2 > (double) bounds.y2)
1322 bounds.y2=polygon_info->edges[i].bounds.y2;
1325 bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double)
1326 image->columns ? (double) image->columns-1 : bounds.x1;
1328 bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double)
1329 image->rows ? (double) image->rows-1 : bounds.y1;
1331 bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double)
1332 image->columns ? (double) image->columns-1 : bounds.x2;
1334 bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double)
1335 image->rows ? (double) image->rows-1 : bounds.y2;
1336 for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
1338 if (polygon_info->edges[i].direction != 0)
1339 (void) QueryColorCompliance("red",AllCompliance,&clone_info->stroke,
1342 (void) QueryColorCompliance("green",AllCompliance,&clone_info->stroke,
1344 start.x=(double) (polygon_info->edges[i].bounds.x1-mid);
1345 start.y=(double) (polygon_info->edges[i].bounds.y1-mid);
1346 end.x=(double) (polygon_info->edges[i].bounds.x2+mid);
1347 end.y=(double) (polygon_info->edges[i].bounds.y2+mid);
1348 primitive_info[0].primitive=RectanglePrimitive;
1349 TraceRectangle(primitive_info,start,end);
1350 primitive_info[0].method=ReplaceMethod;
1351 coordinates=(ssize_t) primitive_info[0].coordinates;
1352 primitive_info[coordinates].primitive=UndefinedPrimitive;
1353 (void) DrawPrimitive(image,clone_info,primitive_info,exception);
1356 (void) QueryColorCompliance("blue",AllCompliance,&clone_info->stroke,
1358 start.x=(double) (bounds.x1-mid);
1359 start.y=(double) (bounds.y1-mid);
1360 end.x=(double) (bounds.x2+mid);
1361 end.y=(double) (bounds.y2+mid);
1362 primitive_info[0].primitive=RectanglePrimitive;
1363 TraceRectangle(primitive_info,start,end);
1364 primitive_info[0].method=ReplaceMethod;
1365 coordinates=(ssize_t) primitive_info[0].coordinates;
1366 primitive_info[coordinates].primitive=UndefinedPrimitive;
1367 (void) DrawPrimitive(image,clone_info,primitive_info,exception);
1368 clone_info=DestroyDrawInfo(clone_info);
1372 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1376 % D r a w C l i p P a t h %
1380 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1382 % DrawClipPath() draws the clip path on the image mask.
1384 % The format of the DrawClipPath method is:
1386 % MagickBooleanType DrawClipPath(Image *image,const DrawInfo *draw_info,
1387 % const char *name,ExceptionInfo *exception)
1389 % A description of each parameter follows:
1391 % o image: the image.
1393 % o draw_info: the draw info.
1395 % o name: the name of the clip path.
1397 % o exception: return any errors or warnings in this structure.
1400 MagickExport MagickBooleanType DrawClipPath(Image *image,
1401 const DrawInfo *draw_info,const char *name,ExceptionInfo *exception)
1404 filename[MaxTextExtent];
1418 assert(image != (Image *) NULL);
1419 assert(image->signature == MagickSignature);
1420 if (image->debug != MagickFalse)
1421 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1422 assert(draw_info != (const DrawInfo *) NULL);
1423 (void) FormatLocaleString(filename,MaxTextExtent,"%s",name);
1424 value=GetImageArtifact(image,filename);
1425 if (value == (const char *) NULL)
1426 return(MagickFalse);
1427 clip_mask=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1428 if (clip_mask == (Image *) NULL)
1429 return(MagickFalse);
1430 (void) QueryColorCompliance("#0000",AllCompliance,
1431 &clip_mask->background_color,exception);
1432 clip_mask->background_color.alpha=(Quantum) TransparentAlpha;
1433 (void) SetImageBackgroundColor(clip_mask,exception);
1434 if (image->debug != MagickFalse)
1435 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"\nbegin clip-path %s",
1436 draw_info->clip_mask);
1437 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1438 (void) CloneString(&clone_info->primitive,value);
1439 (void) QueryColorCompliance("#ffffff",AllCompliance,&clone_info->fill,
1441 clone_info->clip_mask=(char *) NULL;
1442 status=NegateImage(clip_mask,MagickFalse,exception);
1443 (void) SetImageMask(image,clip_mask,exception);
1444 clip_mask=DestroyImage(clip_mask);
1445 clone_info=DestroyDrawInfo(clone_info);
1446 status=DrawImage(image,clone_info,exception);
1447 if (image->debug != MagickFalse)
1448 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end clip-path");
1449 return(status != 0 ? MagickTrue : MagickFalse);
1453 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1457 + D r a w D a s h P o l y g o n %
1461 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1463 % DrawDashPolygon() draws a dashed polygon (line, rectangle, ellipse) on the
1464 % image while respecting the dash offset and dash pattern attributes.
1466 % The format of the DrawDashPolygon method is:
1468 % MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info,
1469 % const PrimitiveInfo *primitive_info,Image *image,
1470 % ExceptionInfo *exception)
1472 % A description of each parameter follows:
1474 % o draw_info: the draw info.
1476 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
1478 % o image: the image.
1480 % o exception: return any errors or warnings in this structure.
1483 static MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info,
1484 const PrimitiveInfo *primitive_info,Image *image,ExceptionInfo *exception)
1505 register MagickRealType
1516 assert(draw_info != (const DrawInfo *) NULL);
1517 if (image->debug != MagickFalse)
1518 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-dash");
1519 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1520 clone_info->miterlimit=0;
1521 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
1522 number_vertices=(size_t) i;
1523 dash_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
1524 (2UL*number_vertices+1UL),sizeof(*dash_polygon));
1525 if (dash_polygon == (PrimitiveInfo *) NULL)
1526 return(MagickFalse);
1527 dash_polygon[0]=primitive_info[0];
1528 scale=ExpandAffine(&draw_info->affine);
1529 length=scale*(draw_info->dash_pattern[0]-0.5);
1530 offset=draw_info->dash_offset != 0.0 ? scale*draw_info->dash_offset : 0.0;
1532 for (n=0; offset > 0.0; j=0)
1534 if (draw_info->dash_pattern[n] <= 0.0)
1536 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1537 if (offset > length)
1541 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1544 if (offset < length)
1556 for (i=1; i < (ssize_t) number_vertices; i++)
1558 dx=primitive_info[i].point.x-primitive_info[i-1].point.x;
1559 dy=primitive_info[i].point.y-primitive_info[i-1].point.y;
1560 maximum_length=hypot((double) dx,dy);
1564 if (draw_info->dash_pattern[n] == 0.0)
1566 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1568 for (total_length=0.0; (total_length+length) < maximum_length; )
1570 total_length+=length;
1571 if ((n & 0x01) != 0)
1573 dash_polygon[0]=primitive_info[0];
1574 dash_polygon[0].point.x=(double) (primitive_info[i-1].point.x+dx*
1575 total_length/maximum_length);
1576 dash_polygon[0].point.y=(double) (primitive_info[i-1].point.y+dy*
1577 total_length/maximum_length);
1582 if ((j+1) > (ssize_t) (2*number_vertices))
1584 dash_polygon[j]=primitive_info[i-1];
1585 dash_polygon[j].point.x=(double) (primitive_info[i-1].point.x+dx*
1586 total_length/maximum_length);
1587 dash_polygon[j].point.y=(double) (primitive_info[i-1].point.y+dy*
1588 total_length/maximum_length);
1589 dash_polygon[j].coordinates=1;
1591 dash_polygon[0].coordinates=(size_t) j;
1592 dash_polygon[j].primitive=UndefinedPrimitive;
1593 status|=DrawStrokePolygon(image,clone_info,dash_polygon,exception);
1596 if (draw_info->dash_pattern[n] == 0.0)
1598 length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5));
1600 length-=(maximum_length-total_length);
1601 if ((n & 0x01) != 0)
1603 dash_polygon[j]=primitive_info[i];
1604 dash_polygon[j].coordinates=1;
1607 if ((total_length < maximum_length) && ((n & 0x01) == 0) && (j > 1))
1609 dash_polygon[j]=primitive_info[i-1];
1610 dash_polygon[j].point.x+=MagickEpsilon;
1611 dash_polygon[j].point.y+=MagickEpsilon;
1612 dash_polygon[j].coordinates=1;
1614 dash_polygon[0].coordinates=(size_t) j;
1615 dash_polygon[j].primitive=UndefinedPrimitive;
1616 status|=DrawStrokePolygon(image,clone_info,dash_polygon,exception);
1618 dash_polygon=(PrimitiveInfo *) RelinquishMagickMemory(dash_polygon);
1619 clone_info=DestroyDrawInfo(clone_info);
1620 if (image->debug != MagickFalse)
1621 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-dash");
1622 return(status != 0 ? MagickTrue : MagickFalse);
1626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1630 % D r a w I m a g e %
1634 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1636 % DrawImage() draws a graphic primitive on your image. The primitive
1637 % may be represented as a string or filename. Precede the filename with an
1638 % "at" sign (@) and the contents of the file are drawn on the image. You
1639 % can affect how text is drawn by setting one or more members of the draw
1642 % The format of the DrawImage method is:
1644 % MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info,
1645 % ExceptionInfo *exception)
1647 % A description of each parameter follows:
1649 % o image: the image.
1651 % o draw_info: the draw info.
1653 % o exception: return any errors or warnings in this structure.
1657 static inline MagickBooleanType IsPoint(const char *point)
1665 value=StringToDouble(point,&p);
1666 return((value == 0.0) && (p == point) ? MagickFalse : MagickTrue);
1669 static inline void TracePoint(PrimitiveInfo *primitive_info,
1670 const PointInfo point)
1672 primitive_info->coordinates=1;
1673 primitive_info->point=point;
1676 MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info,
1677 ExceptionInfo *exception)
1679 #define RenderImageTag "Render/Image"
1686 key[2*MaxTextExtent],
1687 keyword[MaxTextExtent],
1688 geometry[MaxTextExtent],
1689 name[MaxTextExtent],
1690 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,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 **) AcquireMagickMemory(
1769 sizeof(*graphic_context));
1770 if (graphic_context == (DrawInfo **) NULL)
1772 primitive=DestroyString(primitive);
1773 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1777 primitive_info=(PrimitiveInfo *) AcquireQuantumMemory((size_t) number_points,
1778 sizeof(*primitive_info));
1779 if (primitive_info == (PrimitiveInfo *) NULL)
1781 primitive=DestroyString(primitive);
1782 for ( ; n >= 0; n--)
1783 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
1784 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
1785 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1788 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,draw_info);
1789 graphic_context[n]->viewbox=image->page;
1790 if ((image->page.width == 0) || (image->page.height == 0))
1792 graphic_context[n]->viewbox.width=image->columns;
1793 graphic_context[n]->viewbox.height=image->rows;
1795 token=AcquireString(primitive);
1796 (void) QueryColorCompliance("#000000",AllCompliance,&start_color,
1798 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1799 return(MagickFalse);
1800 if (IsGrayColorspace(image->colorspace) != MagickFalse)
1801 (void) TransformImageColorspace(image,sRGBColorspace,exception);
1803 for (q=primitive; *q != '\0'; )
1806 Interpret graphic primitive.
1808 GetMagickToken(q,&q,keyword);
1809 if (*keyword == '\0')
1811 if (*keyword == '#')
1816 while ((*q != '\n') && (*q != '\0'))
1820 p=q-strlen(keyword)-1;
1821 primitive_type=UndefinedPrimitive;
1822 current=graphic_context[n]->affine;
1823 GetAffineMatrix(&affine);
1831 if (LocaleCompare("affine",keyword) == 0)
1833 GetMagickToken(q,&q,token);
1834 affine.sx=StringToDouble(token,(char **) NULL);
1835 GetMagickToken(q,&q,token);
1837 GetMagickToken(q,&q,token);
1838 affine.rx=StringToDouble(token,(char **) NULL);
1839 GetMagickToken(q,&q,token);
1841 GetMagickToken(q,&q,token);
1842 affine.ry=StringToDouble(token,(char **) NULL);
1843 GetMagickToken(q,&q,token);
1845 GetMagickToken(q,&q,token);
1846 affine.sy=StringToDouble(token,(char **) NULL);
1847 GetMagickToken(q,&q,token);
1849 GetMagickToken(q,&q,token);
1850 affine.tx=StringToDouble(token,(char **) NULL);
1851 GetMagickToken(q,&q,token);
1853 GetMagickToken(q,&q,token);
1854 affine.ty=StringToDouble(token,(char **) NULL);
1857 if (LocaleCompare("arc",keyword) == 0)
1859 primitive_type=ArcPrimitive;
1868 if (LocaleCompare("bezier",keyword) == 0)
1870 primitive_type=BezierPrimitive;
1873 if (LocaleCompare("border-color",keyword) == 0)
1875 GetMagickToken(q,&q,token);
1876 (void) QueryColorCompliance(token,AllCompliance,
1877 &graphic_context[n]->border_color,exception);
1886 if (LocaleCompare("clip-path",keyword) == 0)
1891 GetMagickToken(q,&q,token);
1892 (void) CloneString(&graphic_context[n]->clip_mask,token);
1893 (void) DrawClipPath(image,graphic_context[n],
1894 graphic_context[n]->clip_mask,exception);
1897 if (LocaleCompare("clip-rule",keyword) == 0)
1902 GetMagickToken(q,&q,token);
1903 fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse,
1905 if (fill_rule == -1)
1908 graphic_context[n]->fill_rule=(FillRule) fill_rule;
1911 if (LocaleCompare("clip-units",keyword) == 0)
1916 GetMagickToken(q,&q,token);
1917 clip_units=ParseCommandOption(MagickClipPathOptions,MagickFalse,
1919 if (clip_units == -1)
1924 graphic_context[n]->clip_units=(ClipPathUnits) clip_units;
1925 if (clip_units == ObjectBoundingBox)
1927 GetAffineMatrix(¤t);
1928 affine.sx=draw_info->bounds.x2;
1929 affine.sy=draw_info->bounds.y2;
1930 affine.tx=draw_info->bounds.x1;
1931 affine.ty=draw_info->bounds.y1;
1936 if (LocaleCompare("circle",keyword) == 0)
1938 primitive_type=CirclePrimitive;
1941 if (LocaleCompare("color",keyword) == 0)
1943 primitive_type=ColorPrimitive;
1952 if (LocaleCompare("decorate",keyword) == 0)
1957 GetMagickToken(q,&q,token);
1958 decorate=ParseCommandOption(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) FormatLocaleString(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,exception);
1998 status=QueryColorCompliance(token,AllCompliance,
1999 &graphic_context[n]->fill,exception);
2000 if (status == MagickFalse)
2005 pattern_info=AcquireImageInfo();
2006 (void) CopyMagickString(pattern_info->filename,token,
2008 graphic_context[n]->fill_pattern=ReadImage(pattern_info,
2010 CatchException(exception);
2011 pattern_info=DestroyImageInfo(pattern_info);
2016 if (LocaleCompare("fill-alpha",keyword) == 0)
2018 GetMagickToken(q,&q,token);
2019 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2020 graphic_context[n]->fill.alpha=(MagickRealType) QuantumRange*
2021 factor*StringToDouble(token,(char **) NULL);
2024 if (LocaleCompare("fill-rule",keyword) == 0)
2029 GetMagickToken(q,&q,token);
2030 fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse,
2032 if (fill_rule == -1)
2035 graphic_context[n]->fill_rule=(FillRule) fill_rule;
2038 if (LocaleCompare("font",keyword) == 0)
2040 GetMagickToken(q,&q,token);
2041 (void) CloneString(&graphic_context[n]->font,token);
2042 if (LocaleCompare("none",token) == 0)
2043 graphic_context[n]->font=(char *)
2044 RelinquishMagickMemory(graphic_context[n]->font);
2047 if (LocaleCompare("font-family",keyword) == 0)
2049 GetMagickToken(q,&q,token);
2050 (void) CloneString(&graphic_context[n]->family,token);
2053 if (LocaleCompare("font-size",keyword) == 0)
2055 GetMagickToken(q,&q,token);
2056 graphic_context[n]->pointsize=StringToDouble(token,(char **) NULL);
2059 if (LocaleCompare("font-stretch",keyword) == 0)
2064 GetMagickToken(q,&q,token);
2065 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,token);
2069 graphic_context[n]->stretch=(StretchType) stretch;
2072 if (LocaleCompare("font-style",keyword) == 0)
2077 GetMagickToken(q,&q,token);
2078 style=ParseCommandOption(MagickStyleOptions,MagickFalse,token);
2082 graphic_context[n]->style=(StyleType) style;
2085 if (LocaleCompare("font-weight",keyword) == 0)
2087 GetMagickToken(q,&q,token);
2088 graphic_context[n]->weight=StringToUnsignedLong(token);
2089 if (LocaleCompare(token,"all") == 0)
2090 graphic_context[n]->weight=0;
2091 if (LocaleCompare(token,"bold") == 0)
2092 graphic_context[n]->weight=700;
2093 if (LocaleCompare(token,"bolder") == 0)
2094 if (graphic_context[n]->weight <= 800)
2095 graphic_context[n]->weight+=100;
2096 if (LocaleCompare(token,"lighter") == 0)
2097 if (graphic_context[n]->weight >= 100)
2098 graphic_context[n]->weight-=100;
2099 if (LocaleCompare(token,"normal") == 0)
2100 graphic_context[n]->weight=400;
2109 if (LocaleCompare("gradient-units",keyword) == 0)
2111 GetMagickToken(q,&q,token);
2114 if (LocaleCompare("gravity",keyword) == 0)
2119 GetMagickToken(q,&q,token);
2120 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,token);
2124 graphic_context[n]->gravity=(GravityType) gravity;
2133 if (LocaleCompare("image",keyword) == 0)
2138 primitive_type=ImagePrimitive;
2139 GetMagickToken(q,&q,token);
2140 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,token);
2144 graphic_context[n]->compose=(CompositeOperator) compose;
2147 if (LocaleCompare("interline-spacing",keyword) == 0)
2149 GetMagickToken(q,&q,token);
2150 graphic_context[n]->interline_spacing=StringToDouble(token,
2154 if (LocaleCompare("interword-spacing",keyword) == 0)
2156 GetMagickToken(q,&q,token);
2157 graphic_context[n]->interword_spacing=StringToDouble(token,
2167 if (LocaleCompare("kerning",keyword) == 0)
2169 GetMagickToken(q,&q,token);
2170 graphic_context[n]->kerning=StringToDouble(token,(char **) NULL);
2179 if (LocaleCompare("line",keyword) == 0)
2180 primitive_type=LinePrimitive;
2188 if (LocaleCompare("matte",keyword) == 0)
2189 primitive_type=MattePrimitive;
2197 if (LocaleCompare("offset",keyword) == 0)
2199 GetMagickToken(q,&q,token);
2202 if (LocaleCompare("opacity",keyword) == 0)
2204 GetMagickToken(q,&q,token);
2205 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2206 graphic_context[n]->alpha=ClampToQuantum((MagickRealType)
2207 QuantumRange*(1.0-((1.0-QuantumScale*graphic_context[n]->alpha)*
2208 factor*StringToDouble(token,(char **) NULL))));
2209 graphic_context[n]->fill.alpha=(double) graphic_context[n]->alpha;
2210 graphic_context[n]->stroke.alpha=(double) graphic_context[n]->alpha;
2219 if (LocaleCompare("path",keyword) == 0)
2221 primitive_type=PathPrimitive;
2224 if (LocaleCompare("point",keyword) == 0)
2226 primitive_type=PointPrimitive;
2229 if (LocaleCompare("polyline",keyword) == 0)
2231 primitive_type=PolylinePrimitive;
2234 if (LocaleCompare("polygon",keyword) == 0)
2236 primitive_type=PolygonPrimitive;
2239 if (LocaleCompare("pop",keyword) == 0)
2241 GetMagickToken(q,&q,token);
2242 if (LocaleCompare("clip-path",token) == 0)
2244 if (LocaleCompare("defs",token) == 0)
2246 if (LocaleCompare("gradient",token) == 0)
2248 if (LocaleCompare("graphic-context",token) == 0)
2252 (void) ThrowMagickException(exception,GetMagickModule(),
2253 DrawError,"UnbalancedGraphicContextPushPop","'%s'",token);
2257 if (graphic_context[n]->clip_mask != (char *) NULL)
2258 if (LocaleCompare(graphic_context[n]->clip_mask,
2259 graphic_context[n-1]->clip_mask) != 0)
2260 (void) SetImageMask(image,(Image *) NULL,exception);
2261 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
2265 if (LocaleCompare("pattern",token) == 0)
2270 if (LocaleCompare("push",keyword) == 0)
2272 GetMagickToken(q,&q,token);
2273 if (LocaleCompare("clip-path",token) == 0)
2276 name[MaxTextExtent];
2278 GetMagickToken(q,&q,token);
2279 (void) FormatLocaleString(name,MaxTextExtent,"%s",token);
2280 for (p=q; *q != '\0'; )
2282 GetMagickToken(q,&q,token);
2283 if (LocaleCompare(token,"pop") != 0)
2285 GetMagickToken(q,(const char **) NULL,token);
2286 if (LocaleCompare(token,"clip-path") != 0)
2290 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2291 (void) SetImageArtifact(image,name,token);
2292 GetMagickToken(q,&q,token);
2295 if (LocaleCompare("gradient",token) == 0)
2298 key[2*MaxTextExtent],
2299 name[MaxTextExtent],
2300 type[MaxTextExtent];
2305 GetMagickToken(q,&q,token);
2306 (void) CopyMagickString(name,token,MaxTextExtent);
2307 GetMagickToken(q,&q,token);
2308 (void) CopyMagickString(type,token,MaxTextExtent);
2309 GetMagickToken(q,&q,token);
2310 segment.x1=StringToDouble(token,(char **) NULL);
2311 GetMagickToken(q,&q,token);
2313 GetMagickToken(q,&q,token);
2314 segment.y1=StringToDouble(token,(char **) NULL);
2315 GetMagickToken(q,&q,token);
2317 GetMagickToken(q,&q,token);
2318 segment.x2=StringToDouble(token,(char **) NULL);
2319 GetMagickToken(q,&q,token);
2321 GetMagickToken(q,&q,token);
2322 segment.y2=StringToDouble(token,(char **) NULL);
2323 if (LocaleCompare(type,"radial") == 0)
2325 GetMagickToken(q,&q,token);
2327 GetMagickToken(q,&q,token);
2329 for (p=q; *q != '\0'; )
2331 GetMagickToken(q,&q,token);
2332 if (LocaleCompare(token,"pop") != 0)
2334 GetMagickToken(q,(const char **) NULL,token);
2335 if (LocaleCompare(token,"gradient") != 0)
2339 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2340 bounds.x1=graphic_context[n]->affine.sx*segment.x1+
2341 graphic_context[n]->affine.ry*segment.y1+
2342 graphic_context[n]->affine.tx;
2343 bounds.y1=graphic_context[n]->affine.rx*segment.x1+
2344 graphic_context[n]->affine.sy*segment.y1+
2345 graphic_context[n]->affine.ty;
2346 bounds.x2=graphic_context[n]->affine.sx*segment.x2+
2347 graphic_context[n]->affine.ry*segment.y2+
2348 graphic_context[n]->affine.tx;
2349 bounds.y2=graphic_context[n]->affine.rx*segment.x2+
2350 graphic_context[n]->affine.sy*segment.y2+
2351 graphic_context[n]->affine.ty;
2352 (void) FormatLocaleString(key,MaxTextExtent,"%s",name);
2353 (void) SetImageArtifact(image,key,token);
2354 (void) FormatLocaleString(key,MaxTextExtent,"%s-geometry",name);
2355 (void) FormatLocaleString(geometry,MaxTextExtent,
2356 "%gx%g%+.15g%+.15g",
2357 MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0),
2358 MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0),
2359 bounds.x1,bounds.y1);
2360 (void) SetImageArtifact(image,key,geometry);
2361 GetMagickToken(q,&q,token);
2364 if (LocaleCompare("pattern",token) == 0)
2369 GetMagickToken(q,&q,token);
2370 (void) CopyMagickString(name,token,MaxTextExtent);
2371 GetMagickToken(q,&q,token);
2372 bounds.x=(ssize_t) ceil(StringToDouble(token,(char **) NULL)-
2374 GetMagickToken(q,&q,token);
2376 GetMagickToken(q,&q,token);
2377 bounds.y=(ssize_t) ceil(StringToDouble(token,(char **) NULL)-
2379 GetMagickToken(q,&q,token);
2381 GetMagickToken(q,&q,token);
2382 bounds.width=(size_t) floor(StringToDouble(token,
2383 (char **) NULL)+0.5);
2384 GetMagickToken(q,&q,token);
2386 GetMagickToken(q,&q,token);
2387 bounds.height=(size_t) floor(StringToDouble(token,
2388 (char **) NULL)+0.5);
2389 for (p=q; *q != '\0'; )
2391 GetMagickToken(q,&q,token);
2392 if (LocaleCompare(token,"pop") != 0)
2394 GetMagickToken(q,(const char **) NULL,token);
2395 if (LocaleCompare(token,"pattern") != 0)
2399 (void) CopyMagickString(token,p,(size_t) (q-p-4+1));
2400 (void) FormatLocaleString(key,MaxTextExtent,"%s",name);
2401 (void) SetImageArtifact(image,key,token);
2402 (void) FormatLocaleString(key,MaxTextExtent,"%s-geometry",name);
2403 (void) FormatLocaleString(geometry,MaxTextExtent,
2404 "%.20gx%.20g%+.20g%+.20g",(double) bounds.width,(double)
2405 bounds.height,(double) bounds.x,(double) bounds.y);
2406 (void) SetImageArtifact(image,key,geometry);
2407 GetMagickToken(q,&q,token);
2410 if (LocaleCompare("graphic-context",token) == 0)
2413 graphic_context=(DrawInfo **) ResizeQuantumMemory(
2414 graphic_context,(size_t) (n+1),sizeof(*graphic_context));
2415 if (graphic_context == (DrawInfo **) NULL)
2417 (void) ThrowMagickException(exception,GetMagickModule(),
2418 ResourceLimitError,"MemoryAllocationFailed","'%s'",
2422 graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,
2423 graphic_context[n-1]);
2426 if (LocaleCompare("defs",token) == 0)
2437 if (LocaleCompare("rectangle",keyword) == 0)
2439 primitive_type=RectanglePrimitive;
2442 if (LocaleCompare("rotate",keyword) == 0)
2444 GetMagickToken(q,&q,token);
2445 angle=StringToDouble(token,(char **) NULL);
2446 affine.sx=cos(DegreesToRadians(fmod((double) angle,360.0)));
2447 affine.rx=sin(DegreesToRadians(fmod((double) angle,360.0)));
2448 affine.ry=(-sin(DegreesToRadians(fmod((double) angle,360.0))));
2449 affine.sy=cos(DegreesToRadians(fmod((double) angle,360.0)));
2452 if (LocaleCompare("roundRectangle",keyword) == 0)
2454 primitive_type=RoundRectanglePrimitive;
2463 if (LocaleCompare("scale",keyword) == 0)
2465 GetMagickToken(q,&q,token);
2466 affine.sx=StringToDouble(token,(char **) NULL);
2467 GetMagickToken(q,&q,token);
2469 GetMagickToken(q,&q,token);
2470 affine.sy=StringToDouble(token,(char **) NULL);
2473 if (LocaleCompare("skewX",keyword) == 0)
2475 GetMagickToken(q,&q,token);
2476 angle=StringToDouble(token,(char **) NULL);
2477 affine.ry=sin(DegreesToRadians(angle));
2480 if (LocaleCompare("skewY",keyword) == 0)
2482 GetMagickToken(q,&q,token);
2483 angle=StringToDouble(token,(char **) NULL);
2484 affine.rx=(-tan(DegreesToRadians(angle)/2.0));
2487 if (LocaleCompare("stop-color",keyword) == 0)
2492 GetMagickToken(q,&q,token);
2493 (void) QueryColorCompliance(token,AllCompliance,&stop_color,
2495 (void) GradientImage(image,LinearGradient,ReflectSpread,
2496 &start_color,&stop_color,exception);
2497 start_color=stop_color;
2498 GetMagickToken(q,&q,token);
2501 if (LocaleCompare("stroke",keyword) == 0)
2503 GetMagickToken(q,&q,token);
2504 (void) FormatLocaleString(pattern,MaxTextExtent,"%s",token);
2505 if (GetImageArtifact(image,pattern) != (const char *) NULL)
2506 (void) DrawPatternPath(image,draw_info,token,
2507 &graphic_context[n]->stroke_pattern,exception);
2510 status=QueryColorCompliance(token,AllCompliance,
2511 &graphic_context[n]->stroke,exception);
2512 if (status == MagickFalse)
2517 pattern_info=AcquireImageInfo();
2518 (void) CopyMagickString(pattern_info->filename,token,
2520 graphic_context[n]->stroke_pattern=ReadImage(pattern_info,
2522 CatchException(exception);
2523 pattern_info=DestroyImageInfo(pattern_info);
2528 if (LocaleCompare("stroke-antialias",keyword) == 0)
2530 GetMagickToken(q,&q,token);
2531 graphic_context[n]->stroke_antialias=
2532 StringToLong(token) != 0 ? MagickTrue : MagickFalse;
2535 if (LocaleCompare("stroke-dasharray",keyword) == 0)
2537 if (graphic_context[n]->dash_pattern != (double *) NULL)
2538 graphic_context[n]->dash_pattern=(double *)
2539 RelinquishMagickMemory(graphic_context[n]->dash_pattern);
2540 if (IsPoint(q) != MagickFalse)
2546 GetMagickToken(p,&p,token);
2548 GetMagickToken(p,&p,token);
2549 for (x=0; IsPoint(token) != MagickFalse; x++)
2551 GetMagickToken(p,&p,token);
2553 GetMagickToken(p,&p,token);
2555 graphic_context[n]->dash_pattern=(double *)
2556 AcquireQuantumMemory((size_t) (2UL*x+1UL),
2557 sizeof(*graphic_context[n]->dash_pattern));
2558 if (graphic_context[n]->dash_pattern == (double *) NULL)
2560 (void) ThrowMagickException(exception,GetMagickModule(),
2561 ResourceLimitError,"MemoryAllocationFailed","'%s'",
2565 for (j=0; j < x; j++)
2567 GetMagickToken(q,&q,token);
2569 GetMagickToken(q,&q,token);
2570 graphic_context[n]->dash_pattern[j]=StringToDouble(token,
2573 if ((x & 0x01) != 0)
2574 for ( ; j < (2*x); j++)
2575 graphic_context[n]->dash_pattern[j]=
2576 graphic_context[n]->dash_pattern[j-x];
2577 graphic_context[n]->dash_pattern[j]=0.0;
2580 GetMagickToken(q,&q,token);
2583 if (LocaleCompare("stroke-dashoffset",keyword) == 0)
2585 GetMagickToken(q,&q,token);
2586 graphic_context[n]->dash_offset=StringToDouble(token,
2590 if (LocaleCompare("stroke-linecap",keyword) == 0)
2595 GetMagickToken(q,&q,token);
2596 linecap=ParseCommandOption(MagickLineCapOptions,MagickFalse,token);
2600 graphic_context[n]->linecap=(LineCap) linecap;
2603 if (LocaleCompare("stroke-linejoin",keyword) == 0)
2608 GetMagickToken(q,&q,token);
2609 linejoin=ParseCommandOption(MagickLineJoinOptions,MagickFalse,
2614 graphic_context[n]->linejoin=(LineJoin) linejoin;
2617 if (LocaleCompare("stroke-miterlimit",keyword) == 0)
2619 GetMagickToken(q,&q,token);
2620 graphic_context[n]->miterlimit=StringToUnsignedLong(token);
2623 if (LocaleCompare("stroke-opacity",keyword) == 0)
2625 GetMagickToken(q,&q,token);
2626 factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0;
2627 graphic_context[n]->stroke.alpha=(MagickRealType) QuantumRange*
2628 factor*StringToDouble(token,(char **) NULL);
2631 if (LocaleCompare("stroke-width",keyword) == 0)
2633 GetMagickToken(q,&q,token);
2634 graphic_context[n]->stroke_width=StringToDouble(token,
2644 if (LocaleCompare("text",keyword) == 0)
2646 primitive_type=TextPrimitive;
2649 if (LocaleCompare("text-align",keyword) == 0)
2654 GetMagickToken(q,&q,token);
2655 align=ParseCommandOption(MagickAlignOptions,MagickFalse,token);
2659 graphic_context[n]->align=(AlignType) align;
2662 if (LocaleCompare("text-anchor",keyword) == 0)
2667 GetMagickToken(q,&q,token);
2668 align=ParseCommandOption(MagickAlignOptions,MagickFalse,token);
2672 graphic_context[n]->align=(AlignType) align;
2675 if (LocaleCompare("text-antialias",keyword) == 0)
2677 GetMagickToken(q,&q,token);
2678 graphic_context[n]->text_antialias=
2679 StringToLong(token) != 0 ? MagickTrue : MagickFalse;
2682 if (LocaleCompare("text-undercolor",keyword) == 0)
2684 GetMagickToken(q,&q,token);
2685 (void) QueryColorCompliance(token,AllCompliance,
2686 &graphic_context[n]->undercolor,exception);
2689 if (LocaleCompare("translate",keyword) == 0)
2691 GetMagickToken(q,&q,token);
2692 affine.tx=StringToDouble(token,(char **) NULL);
2693 GetMagickToken(q,&q,token);
2695 GetMagickToken(q,&q,token);
2696 affine.ty=StringToDouble(token,(char **) NULL);
2705 if (LocaleCompare("viewbox",keyword) == 0)
2707 GetMagickToken(q,&q,token);
2708 graphic_context[n]->viewbox.x=(ssize_t) ceil(StringToDouble(token,
2709 (char **) NULL)-0.5);
2710 GetMagickToken(q,&q,token);
2712 GetMagickToken(q,&q,token);
2713 graphic_context[n]->viewbox.y=(ssize_t) ceil(StringToDouble(token,
2714 (char **) NULL)-0.5);
2715 GetMagickToken(q,&q,token);
2717 GetMagickToken(q,&q,token);
2718 graphic_context[n]->viewbox.width=(size_t) floor(StringToDouble(
2719 token,(char **) NULL)+0.5);
2720 GetMagickToken(q,&q,token);
2722 GetMagickToken(q,&q,token);
2723 graphic_context[n]->viewbox.height=(size_t) floor(StringToDouble(
2724 token,(char **) NULL)+0.5);
2736 if (status == MagickFalse)
2738 if ((affine.sx != 1.0) || (affine.rx != 0.0) || (affine.ry != 0.0) ||
2739 (affine.sy != 1.0) || (affine.tx != 0.0) || (affine.ty != 0.0))
2741 graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
2742 graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
2743 graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
2744 graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
2745 graphic_context[n]->affine.tx=current.sx*affine.tx+current.ry*affine.ty+
2747 graphic_context[n]->affine.ty=current.rx*affine.tx+current.sy*affine.ty+
2750 if (primitive_type == UndefinedPrimitive)
2752 if (image->debug != MagickFalse)
2753 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",
2758 Parse the primitive attributes.
2762 primitive_info[0].point.x=0.0;
2763 primitive_info[0].point.y=0.0;
2764 for (x=0; *q != '\0'; x++)
2769 if (IsPoint(q) == MagickFalse)
2771 GetMagickToken(q,&q,token);
2772 point.x=StringToDouble(token,(char **) NULL);
2773 GetMagickToken(q,&q,token);
2775 GetMagickToken(q,&q,token);
2776 point.y=StringToDouble(token,(char **) NULL);
2777 GetMagickToken(q,(const char **) NULL,token);
2779 GetMagickToken(q,&q,token);
2780 primitive_info[i].primitive=primitive_type;
2781 primitive_info[i].point=point;
2782 primitive_info[i].coordinates=0;
2783 primitive_info[i].method=FloodfillMethod;
2785 if (i < (ssize_t) number_points)
2788 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,
2789 (size_t) number_points,sizeof(*primitive_info));
2790 if (primitive_info == (PrimitiveInfo *) NULL)
2792 (void) ThrowMagickException(exception,GetMagickModule(),
2793 ResourceLimitError,"MemoryAllocationFailed","'%s'",image->filename);
2797 primitive_info[j].primitive=primitive_type;
2798 primitive_info[j].coordinates=(size_t) x;
2799 primitive_info[j].method=FloodfillMethod;
2800 primitive_info[j].text=(char *) NULL;
2802 Circumscribe primitive within a circle.
2804 bounds.x1=primitive_info[j].point.x;
2805 bounds.y1=primitive_info[j].point.y;
2806 bounds.x2=primitive_info[j].point.x;
2807 bounds.y2=primitive_info[j].point.y;
2808 for (k=1; k < (ssize_t) primitive_info[j].coordinates; k++)
2810 point=primitive_info[j+k].point;
2811 if (point.x < bounds.x1)
2813 if (point.y < bounds.y1)
2815 if (point.x > bounds.x2)
2817 if (point.y > bounds.y2)
2821 Speculate how many points our primitive might consume.
2823 length=primitive_info[j].coordinates;
2824 switch (primitive_type)
2826 case RectanglePrimitive:
2831 case RoundRectanglePrimitive:
2833 length*=5+8*BezierQuantum;
2836 case BezierPrimitive:
2838 if (primitive_info[j].coordinates > 107)
2839 (void) ThrowMagickException(exception,GetMagickModule(),DrawError,
2840 "TooManyBezierCoordinates","'%s'",token);
2841 length=BezierQuantum*primitive_info[j].coordinates;
2850 GetMagickToken(q,&q,token);
2853 for (s=token; *s != '\0'; s=t)
2858 value=StringToDouble(s,&t);
2867 length=length*BezierQuantum/2;
2870 case CirclePrimitive:
2872 case EllipsePrimitive:
2879 alpha=bounds.x2-bounds.x1;
2880 beta=bounds.y2-bounds.y1;
2881 radius=hypot((double) alpha,(double) beta);
2882 length=2*((size_t) ceil((double) MagickPI*radius))+6*BezierQuantum+360;
2888 if ((size_t) (i+length) >= number_points)
2891 Resize based on speculative points required by primitive.
2893 number_points+=length+1;
2894 primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info,
2895 (size_t) number_points,sizeof(*primitive_info));
2896 if (primitive_info == (PrimitiveInfo *) NULL)
2898 (void) ThrowMagickException(exception,GetMagickModule(),
2899 ResourceLimitError,"MemoryAllocationFailed","'%s'",
2904 switch (primitive_type)
2906 case PointPrimitive:
2909 if (primitive_info[j].coordinates != 1)
2914 TracePoint(primitive_info+j,primitive_info[j].point);
2915 i=(ssize_t) (j+primitive_info[j].coordinates);
2920 if (primitive_info[j].coordinates != 2)
2925 TraceLine(primitive_info+j,primitive_info[j].point,
2926 primitive_info[j+1].point);
2927 i=(ssize_t) (j+primitive_info[j].coordinates);
2930 case RectanglePrimitive:
2932 if (primitive_info[j].coordinates != 2)
2937 TraceRectangle(primitive_info+j,primitive_info[j].point,
2938 primitive_info[j+1].point);
2939 i=(ssize_t) (j+primitive_info[j].coordinates);
2942 case RoundRectanglePrimitive:
2944 if (primitive_info[j].coordinates != 3)
2949 TraceRoundRectangle(primitive_info+j,primitive_info[j].point,
2950 primitive_info[j+1].point,primitive_info[j+2].point);
2951 i=(ssize_t) (j+primitive_info[j].coordinates);
2956 if (primitive_info[j].coordinates != 3)
2958 primitive_type=UndefinedPrimitive;
2961 TraceArc(primitive_info+j,primitive_info[j].point,
2962 primitive_info[j+1].point,primitive_info[j+2].point);
2963 i=(ssize_t) (j+primitive_info[j].coordinates);
2966 case EllipsePrimitive:
2968 if (primitive_info[j].coordinates != 3)
2973 TraceEllipse(primitive_info+j,primitive_info[j].point,
2974 primitive_info[j+1].point,primitive_info[j+2].point);
2975 i=(ssize_t) (j+primitive_info[j].coordinates);
2978 case CirclePrimitive:
2980 if (primitive_info[j].coordinates != 2)
2985 TraceCircle(primitive_info+j,primitive_info[j].point,
2986 primitive_info[j+1].point);
2987 i=(ssize_t) (j+primitive_info[j].coordinates);
2990 case PolylinePrimitive:
2992 case PolygonPrimitive:
2994 primitive_info[i]=primitive_info[j];
2995 primitive_info[i].coordinates=0;
2996 primitive_info[j].coordinates++;
3000 case BezierPrimitive:
3002 if (primitive_info[j].coordinates < 3)
3007 TraceBezier(primitive_info+j,primitive_info[j].coordinates);
3008 i=(ssize_t) (j+primitive_info[j].coordinates);
3013 i=(ssize_t) (j+TracePath(primitive_info+j,token));
3016 case ColorPrimitive:
3017 case MattePrimitive:
3022 if (primitive_info[j].coordinates != 1)
3027 GetMagickToken(q,&q,token);
3028 method=ParseCommandOption(MagickMethodOptions,MagickFalse,token);
3032 primitive_info[j].method=(PaintMethod) method;
3037 if (primitive_info[j].coordinates != 1)
3043 GetMagickToken(q,&q,token);
3044 primitive_info[j].text=AcquireString(token);
3047 case ImagePrimitive:
3049 if (primitive_info[j].coordinates != 2)
3054 GetMagickToken(q,&q,token);
3055 primitive_info[j].text=AcquireString(token);
3059 if (primitive_info == (PrimitiveInfo *) NULL)
3061 if (image->debug != MagickFalse)
3062 (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",(int) (q-p),p);
3063 if (status == MagickFalse)
3065 primitive_info[i].primitive=UndefinedPrimitive;
3071 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
3073 point=primitive_info[i].point;
3074 primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+
3075 graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx;
3076 primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+
3077 graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty;
3078 point=primitive_info[i].point;
3079 if (point.x < graphic_context[n]->bounds.x1)
3080 graphic_context[n]->bounds.x1=point.x;
3081 if (point.y < graphic_context[n]->bounds.y1)
3082 graphic_context[n]->bounds.y1=point.y;
3083 if (point.x > graphic_context[n]->bounds.x2)
3084 graphic_context[n]->bounds.x2=point.x;
3085 if (point.y > graphic_context[n]->bounds.y2)
3086 graphic_context[n]->bounds.y2=point.y;
3087 if (primitive_info[i].primitive == ImagePrimitive)
3089 if (i >= (ssize_t) number_points)
3090 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
3092 if (graphic_context[n]->render != MagickFalse)
3094 if ((n != 0) && (graphic_context[n]->clip_mask != (char *) NULL) &&
3095 (LocaleCompare(graphic_context[n]->clip_mask,
3096 graphic_context[n-1]->clip_mask) != 0))
3097 (void) DrawClipPath(image,graphic_context[n],
3098 graphic_context[n]->clip_mask,exception);
3099 (void) DrawPrimitive(image,graphic_context[n],primitive_info,exception);
3101 if (primitive_info->text != (char *) NULL)
3102 primitive_info->text=(char *) RelinquishMagickMemory(
3103 primitive_info->text);
3104 proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType)
3106 if (proceed == MagickFalse)
3109 if (image->debug != MagickFalse)
3110 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end draw-image");
3112 Relinquish resources.
3114 token=DestroyString(token);
3115 if (primitive_info != (PrimitiveInfo *) NULL)
3116 primitive_info=(PrimitiveInfo *) RelinquishMagickMemory(primitive_info);
3117 primitive=DestroyString(primitive);
3118 for ( ; n >= 0; n--)
3119 graphic_context[n]=DestroyDrawInfo(graphic_context[n]);
3120 graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context);
3121 if (status == MagickFalse)
3122 ThrowBinaryException(DrawError,"NonconformingDrawingPrimitiveDefinition",
3128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3132 % D r a w G r a d i e n t I m a g e %
3136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3138 % DrawGradientImage() draws a linear gradient on the image.
3140 % The format of the DrawGradientImage method is:
3142 % MagickBooleanType DrawGradientImage(Image *image,
3143 % const DrawInfo *draw_info,ExceptionInfo *exception)
3145 % A description of each parameter follows:
3147 % o image: the image.
3149 % o draw_info: the draw info.
3151 % o exception: return any errors or warnings in this structure.
3155 static inline MagickRealType GetStopColorOffset(const GradientInfo *gradient,
3156 const ssize_t x,const ssize_t y)
3158 switch (gradient->type)
3160 case UndefinedGradient:
3161 case LinearGradient:
3176 gradient_vector=(&gradient->gradient_vector);
3177 p.x=gradient_vector->x2-gradient_vector->x1;
3178 p.y=gradient_vector->y2-gradient_vector->y1;
3179 q.x=(double) x-gradient_vector->x1;
3180 q.y=(double) y-gradient_vector->y1;
3181 length=sqrt(q.x*q.x+q.y*q.y);
3182 gamma=sqrt(p.x*p.x+p.y*p.y)*length;
3183 gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
3184 scale=p.x*q.x+p.y*q.y;
3185 offset=gamma*scale*length;
3188 case RadialGradient:
3197 v.x=(double) x-gradient->center.x;
3198 v.y=(double) y-gradient->center.y;
3199 length=sqrt(v.x*v.x+v.y*v.y);
3200 if (gradient->spread == RepeatSpread)
3202 offset=length/gradient->radius;
3209 MagickExport MagickBooleanType DrawGradientImage(Image *image,
3210 const DrawInfo *draw_info,ExceptionInfo *exception)
3244 Draw linear or radial gradient on image.
3246 assert(image != (Image *) NULL);
3247 assert(image->signature == MagickSignature);
3248 if (image->debug != MagickFalse)
3249 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3250 assert(draw_info != (const DrawInfo *) NULL);
3251 gradient=(&draw_info->gradient);
3252 gradient_vector=(&gradient->gradient_vector);
3253 point.x=gradient_vector->x2-gradient_vector->x1;
3254 point.y=gradient_vector->y2-gradient_vector->y1;
3255 length=sqrt(point.x*point.x+point.y*point.y);
3256 bounding_box=gradient->bounding_box;
3258 GetPixelInfo(image,&zero);
3259 height=bounding_box.height-bounding_box.y;
3260 width=bounding_box.width-bounding_box.x;
3261 image_view=AcquireAuthenticCacheView(image,exception);
3262 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3263 #pragma omp parallel for schedule(static) shared(status) \
3264 dynamic_number_threads(width,height,1)
3266 for (y=bounding_box.y; y < (ssize_t) bounding_box.height; y++)
3286 if (status == MagickFalse)
3288 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3289 if (q == (Quantum *) NULL)
3296 offset=GetStopColorOffset(gradient,0,y);
3297 if (gradient->type != RadialGradient)
3299 for (x=bounding_box.x; x < (ssize_t) bounding_box.width; x++)
3301 GetPixelInfoPixel(image,q,&pixel);
3302 switch (gradient->spread)
3304 case UndefinedSpread:
3307 if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) ||
3308 (y != (ssize_t) ceil(gradient_vector->y1-0.5)))
3310 offset=GetStopColorOffset(gradient,x,y);
3311 if (gradient->type != RadialGradient)
3314 for (i=0; i < (ssize_t) gradient->number_stops; i++)
3315 if (offset < gradient->stops[i].offset)
3317 if ((offset < 0.0) || (i == 0))
3318 composite=gradient->stops[0].color;
3320 if ((offset > 1.0) || (i == (ssize_t) gradient->number_stops))
3321 composite=gradient->stops[gradient->number_stops-1].color;
3326 alpha=(offset-gradient->stops[i].offset)/
3327 (gradient->stops[j].offset-gradient->stops[i].offset);
3328 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
3329 &gradient->stops[j].color,alpha,&composite);
3335 if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) ||
3336 (y != (ssize_t) ceil(gradient_vector->y1-0.5)))
3338 offset=GetStopColorOffset(gradient,x,y);
3339 if (gradient->type != RadialGradient)
3344 if ((ssize_t) fmod(offset,2.0) == 0)
3345 offset=fmod(offset,1.0);
3347 offset=1.0-fmod(offset,1.0);
3348 for (i=0; i < (ssize_t) gradient->number_stops; i++)
3349 if (offset < gradient->stops[i].offset)
3352 composite=gradient->stops[0].color;
3354 if (i == (ssize_t) gradient->number_stops)
3355 composite=gradient->stops[gradient->number_stops-1].color;
3360 alpha=(offset-gradient->stops[i].offset)/
3361 (gradient->stops[j].offset-gradient->stops[i].offset);
3362 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
3363 &gradient->stops[j].color,alpha,&composite);
3375 antialias=MagickFalse;
3377 if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) ||
3378 (y != (ssize_t) ceil(gradient_vector->y1-0.5)))
3380 offset=GetStopColorOffset(gradient,x,y);
3381 if (gradient->type == LinearGradient)
3383 repeat=fmod(offset,length);
3385 repeat=length-fmod(-repeat,length);
3387 repeat=fmod(offset,length);
3388 antialias=(repeat < length) && ((repeat+1.0) > length) ?
3389 MagickTrue : MagickFalse;
3390 offset=repeat/length;
3394 repeat=fmod(offset,gradient->radius);
3396 repeat=gradient->radius-fmod(-repeat,gradient->radius);
3398 repeat=fmod(offset,gradient->radius);
3399 antialias=repeat+1.0 > gradient->radius ? MagickTrue :
3401 offset=repeat/gradient->radius;
3404 for (i=0; i < (ssize_t) gradient->number_stops; i++)
3405 if (offset < gradient->stops[i].offset)
3408 composite=gradient->stops[0].color;
3410 if (i == (ssize_t) gradient->number_stops)
3411 composite=gradient->stops[gradient->number_stops-1].color;
3416 alpha=(offset-gradient->stops[i].offset)/
3417 (gradient->stops[j].offset-gradient->stops[i].offset);
3418 if (antialias != MagickFalse)
3420 if (gradient->type == LinearGradient)
3421 alpha=length-repeat;
3423 alpha=gradient->radius-repeat;
3425 j=(ssize_t) gradient->number_stops-1L;
3427 CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha,
3428 &gradient->stops[j].color,alpha,&composite);
3433 CompositePixelInfoOver(&composite,composite.alpha,&pixel,pixel.alpha,
3435 SetPixelInfoPixel(image,&pixel,q);
3436 q+=GetPixelChannels(image);
3438 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3441 image_view=DestroyCacheView(image_view);
3446 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3450 % D r a w P a t t e r n P a t h %
3454 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3456 % DrawPatternPath() draws a pattern.
3458 % The format of the DrawPatternPath method is:
3460 % MagickBooleanType DrawPatternPath(Image *image,const DrawInfo *draw_info,
3461 % const char *name,Image **pattern,ExceptionInfo *exception)
3463 % A description of each parameter follows:
3465 % o image: the image.
3467 % o draw_info: the draw info.
3469 % o name: the pattern name.
3471 % o image: the image.
3473 % o exception: return any errors or warnings in this structure.
3476 MagickExport MagickBooleanType DrawPatternPath(Image *image,
3477 const DrawInfo *draw_info,const char *name,Image **pattern,
3478 ExceptionInfo *exception)
3481 property[MaxTextExtent];
3496 assert(image != (Image *) NULL);
3497 assert(image->signature == MagickSignature);
3498 if (image->debug != MagickFalse)
3499 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3500 assert(draw_info != (const DrawInfo *) NULL);
3501 assert(name != (const char *) NULL);
3502 (void) FormatLocaleString(property,MaxTextExtent,"%s",name);
3503 path=GetImageArtifact(image,property);
3504 if (path == (const char *) NULL)
3505 return(MagickFalse);
3506 (void) FormatLocaleString(property,MaxTextExtent,"%s-geometry",name);
3507 geometry=GetImageArtifact(image,property);
3508 if (geometry == (const char *) NULL)
3509 return(MagickFalse);
3510 if ((*pattern) != (Image *) NULL)
3511 *pattern=DestroyImage(*pattern);
3512 image_info=AcquireImageInfo();
3513 image_info->size=AcquireString(geometry);
3514 *pattern=AcquireImage(image_info,exception);
3515 image_info=DestroyImageInfo(image_info);
3516 (void) QueryColorCompliance("#00000000",AllCompliance,
3517 &(*pattern)->background_color,exception);
3518 (void) SetImageBackgroundColor(*pattern,exception);
3519 if (image->debug != MagickFalse)
3520 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
3521 "begin pattern-path %s %s",name,geometry);
3522 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
3523 clone_info->fill_pattern=NewImageList();
3524 clone_info->stroke_pattern=NewImageList();
3525 (void) CloneString(&clone_info->primitive,path);
3526 status=DrawImage(*pattern,clone_info,exception);
3527 clone_info=DestroyDrawInfo(clone_info);
3528 if (image->debug != MagickFalse)
3529 (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end pattern-path");
3534 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3538 + D r a w P o l y g o n P r i m i t i v e %
3542 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3544 % DrawPolygonPrimitive() draws a polygon on the image.
3546 % The format of the DrawPolygonPrimitive method is:
3548 % MagickBooleanType DrawPolygonPrimitive(Image *image,
3549 % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info,
3550 % ExceptionInfo *exception)
3552 % A description of each parameter follows:
3554 % o image: the image.
3556 % o draw_info: the draw info.
3558 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
3560 % o exception: return any errors or warnings in this structure.
3564 static PolygonInfo **DestroyPolygonThreadSet(PolygonInfo **polygon_info)
3569 assert(polygon_info != (PolygonInfo **) NULL);
3570 for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++)
3571 if (polygon_info[i] != (PolygonInfo *) NULL)
3572 polygon_info[i]=DestroyPolygonInfo(polygon_info[i]);
3573 polygon_info=(PolygonInfo **) RelinquishMagickMemory(polygon_info);
3574 return(polygon_info);
3577 static PolygonInfo **AcquirePolygonThreadSet(const DrawInfo *draw_info,
3578 const PrimitiveInfo *primitive_info)
3581 *restrict path_info;
3592 number_threads=GetOpenMPMaximumThreads();
3593 polygon_info=(PolygonInfo **) AcquireQuantumMemory(number_threads,
3594 sizeof(*polygon_info));
3595 if (polygon_info == (PolygonInfo **) NULL)
3596 return((PolygonInfo **) NULL);
3597 (void) ResetMagickMemory(polygon_info,0,number_threads*sizeof(*polygon_info));
3598 path_info=ConvertPrimitiveToPath(draw_info,primitive_info);
3599 if (path_info == (PathInfo *) NULL)
3600 return(DestroyPolygonThreadSet(polygon_info));
3601 for (i=0; i < (ssize_t) number_threads; i++)
3603 polygon_info[i]=ConvertPathToPolygon(draw_info,path_info);
3604 if (polygon_info[i] == (PolygonInfo *) NULL)
3605 return(DestroyPolygonThreadSet(polygon_info));
3607 path_info=(PathInfo *) RelinquishMagickMemory(path_info);
3608 return(polygon_info);
3611 static MagickRealType GetFillAlpha(PolygonInfo *polygon_info,
3612 const MagickRealType mid,const MagickBooleanType fill,
3613 const FillRule fill_rule,const double x,const double y,
3614 MagickRealType *stroke_alpha)
3628 register const PointInfo
3639 Compute fill & stroke opacity for this (x,y) point.
3643 p=polygon_info->edges;
3644 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
3646 if (y <= (p->bounds.y1-mid-0.5))
3648 if (y > (p->bounds.y2+mid+0.5))
3650 (void) DestroyEdge(polygon_info,(size_t) j);
3653 if ((x <= (p->bounds.x1-mid-0.5)) || (x > (p->bounds.x2+mid+0.5)))
3655 i=(ssize_t) MagickMax((double) p->highwater,1.0);
3656 for ( ; i < (ssize_t) p->number_points; i++)
3658 if (y <= (p->points[i-1].y-mid-0.5))
3660 if (y > (p->points[i].y+mid+0.5))
3662 if (p->scanline != y)
3665 p->highwater=(size_t) i;
3668 Compute distance between a point and an edge.
3671 delta.x=(q+1)->x-q->x;
3672 delta.y=(q+1)->y-q->y;
3673 beta=delta.x*(x-q->x)+delta.y*(y-q->y);
3678 distance=delta.x*delta.x+delta.y*delta.y;
3682 alpha=delta.x*delta.x+delta.y*delta.y;
3687 distance=delta.x*delta.x+delta.y*delta.y;
3692 beta=delta.x*(y-q->y)-delta.y*(x-q->x);
3693 distance=alpha*beta*beta;
3697 Compute stroke & subpath opacity.
3700 if (p->ghostline == MagickFalse)
3703 if ((*stroke_alpha < 1.0) &&
3704 (distance <= ((alpha+0.25)*(alpha+0.25))))
3707 if (distance <= ((alpha+0.25)*(alpha+0.25)))
3712 if (distance != 1.0)
3713 beta=sqrt((double) distance);
3715 if (*stroke_alpha < ((alpha-0.25)*(alpha-0.25)))
3716 *stroke_alpha=(alpha-0.25)*(alpha-0.25);
3720 if ((fill == MagickFalse) || (distance > 1.0) || (subpath_alpha >= 1.0))
3722 if (distance <= 0.0)
3732 if (distance != 1.0)
3733 beta=sqrt(distance);
3736 if (subpath_alpha < (alpha*alpha))
3737 subpath_alpha=alpha*alpha;
3741 Compute fill opacity.
3743 if (fill == MagickFalse)
3745 if (subpath_alpha >= 1.0)
3748 Determine winding number.
3751 p=polygon_info->edges;
3752 for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++)
3754 if (y <= p->bounds.y1)
3756 if ((y > p->bounds.y2) || (x <= p->bounds.x1))
3758 if (x > p->bounds.x2)
3760 winding_number+=p->direction ? 1 : -1;
3763 i=(ssize_t) MagickMax((double) p->highwater,1.0);
3764 for ( ; i < (ssize_t) p->number_points; i++)
3765 if (y <= p->points[i].y)
3768 if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x)))
3769 winding_number+=p->direction ? 1 : -1;
3771 if (fill_rule != NonZeroRule)
3773 if ((MagickAbsoluteValue(winding_number) & 0x01) != 0)
3777 if (MagickAbsoluteValue(winding_number) != 0)
3779 return(subpath_alpha);
3782 static MagickBooleanType DrawPolygonPrimitive(Image *image,
3783 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info,
3784 ExceptionInfo *exception)
3797 **restrict polygon_info;
3818 Compute bounding box.
3820 assert(image != (Image *) NULL);
3821 assert(image->signature == MagickSignature);
3822 if (image->debug != MagickFalse)
3823 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3824 assert(draw_info != (DrawInfo *) NULL);
3825 assert(draw_info->signature == MagickSignature);
3826 assert(primitive_info != (PrimitiveInfo *) NULL);
3827 if (primitive_info->coordinates == 0)
3829 polygon_info=AcquirePolygonThreadSet(draw_info,primitive_info);
3830 if (polygon_info == (PolygonInfo **) NULL)
3831 return(MagickFalse);
3833 DrawBoundingRectangles(image,draw_info,polygon_info[0],exception);
3834 if (image->debug != MagickFalse)
3835 (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-polygon");
3836 fill=(primitive_info->method == FillToBorderMethod) ||
3837 (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse;
3838 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
3839 bounds=polygon_info[0]->edges[0].bounds;
3840 for (i=1; i < (ssize_t) polygon_info[0]->number_edges; i++)
3842 p=polygon_info[0]->edges+i;
3843 if (p->bounds.x1 < bounds.x1)
3844 bounds.x1=p->bounds.x1;
3845 if (p->bounds.y1 < bounds.y1)
3846 bounds.y1=p->bounds.y1;
3847 if (p->bounds.x2 > bounds.x2)
3848 bounds.x2=p->bounds.x2;
3849 if (p->bounds.y2 > bounds.y2)
3850 bounds.y2=p->bounds.y2;
3852 bounds.x1-=(mid+1.0);
3853 bounds.x1=bounds.x1 < 0.0 ? 0.0 : (size_t) ceil(bounds.x1-0.5) >=
3854 image->columns ? (double) image->columns-1.0 : bounds.x1;
3855 bounds.y1-=(mid+1.0);
3856 bounds.y1=bounds.y1 < 0.0 ? 0.0 : (size_t) ceil(bounds.y1-0.5) >=
3857 image->rows ? (double) image->rows-1.0 : bounds.y1;
3858 bounds.x2+=(mid+1.0);
3859 bounds.x2=bounds.x2 < 0.0 ? 0.0 : (size_t) floor(bounds.x2+0.5) >=
3860 image->columns ? (double) image->columns-1.0 : bounds.x2;
3861 bounds.y2+=(mid+1.0);
3862 bounds.y2=bounds.y2 < 0.0 ? 0.0 : (size_t) floor(bounds.y2+0.5) >=
3863 image->rows ? (double) image->rows-1.0 : bounds.y2;
3865 image_view=AcquireAuthenticCacheView(image,exception);
3866 height=(size_t) (floor(bounds.y2+0.5)-ceil(bounds.y1-0.5));
3867 width=(size_t) (floor(bounds.x2+0.5)-ceil(bounds.x1-0.5));
3868 if (primitive_info->coordinates == 1)
3873 start=(ssize_t) ceil(bounds.y1-0.5);
3874 stop=(ssize_t) floor(bounds.y2+0.5);
3875 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3876 #pragma omp parallel for schedule(static) shared(status) \
3877 dynamic_number_threads(width,height,1)
3879 for (y=start; y <= stop; y++)
3897 if (status == MagickFalse)
3899 start=(ssize_t) ceil(bounds.x1-0.5);
3900 stop=(ssize_t) floor(bounds.x2+0.5);
3902 q=GetCacheViewAuthenticPixels(image_view,x,y,(size_t) (stop-x+1),
3904 if (q == (Quantum *) NULL)
3909 GetPixelInfo(image,&pixel);
3910 for ( ; x <= stop; x++)
3912 if ((x == (ssize_t) ceil(primitive_info->point.x-0.5)) &&
3913 (y == (ssize_t) ceil(primitive_info->point.y-0.5)))
3915 (void) GetStrokeColor(draw_info,x,y,&pixel,exception);
3916 SetPixelInfoPixel(image,&pixel,q);
3918 q+=GetPixelChannels(image);
3920 sync=SyncCacheViewAuthenticPixels(image_view,exception);
3921 if (sync == MagickFalse)
3924 image_view=DestroyCacheView(image_view);
3925 polygon_info=DestroyPolygonThreadSet(polygon_info);
3926 if (image->debug != MagickFalse)
3927 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
3928 " end draw-polygon");
3932 Draw polygon or line.
3934 if (image->matte == MagickFalse)
3935 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3936 start=(ssize_t) ceil(bounds.y1-0.5);
3937 stop=(ssize_t) floor(bounds.y2+0.5);
3938 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3939 #pragma omp parallel for schedule(static) shared(status) \
3940 dynamic_number_threads(width,height,1)
3942 for (y=start; y <= stop; y++)
3945 id = GetOpenMPThreadId();
3965 if (status == MagickFalse)
3967 start=(ssize_t) ceil(bounds.x1-0.5);
3968 stop=(ssize_t) floor(bounds.x2+0.5);
3969 q=GetCacheViewAuthenticPixels(image_view,start,y,(size_t) (stop-start+1),1,
3971 if (q == (Quantum *) NULL)
3976 for (x=start; x <= stop; x++)
3981 fill_alpha=GetFillAlpha(polygon_info[id],mid,fill,draw_info->fill_rule,
3982 (double) x,(double) y,&stroke_alpha);
3983 if (draw_info->stroke_antialias == MagickFalse)
3985 fill_alpha=fill_alpha > 0.25 ? 1.0 : 0.0;
3986 stroke_alpha=stroke_alpha > 0.25 ? 1.0 : 0.0;
3988 (void) GetFillColor(draw_info,x,y,&fill_color,exception);
3989 fill_alpha=fill_alpha*fill_color.alpha;
3990 CompositePixelOver(image,&fill_color,fill_alpha,q,(MagickRealType)
3991 GetPixelAlpha(image,q),q);
3992 (void) GetStrokeColor(draw_info,x,y,&stroke_color,exception);
3993 stroke_alpha=stroke_alpha*stroke_color.alpha;
3994 CompositePixelOver(image,&stroke_color,stroke_alpha,q,(MagickRealType)
3995 GetPixelAlpha(image,q),q);
3996 q+=GetPixelChannels(image);
3998 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4001 image_view=DestroyCacheView(image_view);
4002 polygon_info=DestroyPolygonThreadSet(polygon_info);
4003 if (image->debug != MagickFalse)
4004 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-polygon");
4009 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4013 % D r a w P r i m i t i v e %
4017 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4019 % DrawPrimitive() draws a primitive (line, rectangle, ellipse) on the image.
4021 % The format of the DrawPrimitive method is:
4023 % MagickBooleanType DrawPrimitive(Image *image,const DrawInfo *draw_info,
4024 % PrimitiveInfo *primitive_info,ExceptionInfo *exception)
4026 % A description of each parameter follows:
4028 % o image: the image.
4030 % o draw_info: the draw info.
4032 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
4034 % o exception: return any errors or warnings in this structure.
4038 static void LogPrimitiveInfo(const PrimitiveInfo *primitive_info)
4064 x=(ssize_t) ceil(primitive_info->point.x-0.5);
4065 y=(ssize_t) ceil(primitive_info->point.y-0.5);
4066 switch (primitive_info->primitive)
4068 case PointPrimitive:
4070 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4071 "PointPrimitive %.20g,%.20g %s",(double) x,(double) y,
4072 methods[primitive_info->method]);
4075 case ColorPrimitive:
4077 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4078 "ColorPrimitive %.20g,%.20g %s",(double) x,(double) y,
4079 methods[primitive_info->method]);
4082 case MattePrimitive:
4084 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4085 "MattePrimitive %.20g,%.20g %s",(double) x,(double) y,
4086 methods[primitive_info->method]);
4091 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4092 "TextPrimitive %.20g,%.20g",(double) x,(double) y);
4095 case ImagePrimitive:
4097 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4098 "ImagePrimitive %.20g,%.20g",(double) x,(double) y);
4105 p=primitive_info[0].point;
4108 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
4110 point=primitive_info[i].point;
4111 if (coordinates <= 0)
4113 coordinates=(ssize_t) primitive_info[i].coordinates;
4114 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4115 " begin open (%.20g)",(double) coordinates);
4118 point=primitive_info[i].point;
4119 if ((fabs(q.x-point.x) > MagickEpsilon) ||
4120 (fabs(q.y-point.y) > MagickEpsilon))
4121 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4122 " %.20g: %.18g,%.18g",(double) coordinates,point.x,point.y);
4124 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4125 " %.20g: %g %g (duplicate)",(double) coordinates,point.x,point.y);
4128 if (coordinates > 0)
4130 if ((fabs(p.x-point.x) > MagickEpsilon) ||
4131 (fabs(p.y-point.y) > MagickEpsilon))
4132 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end last (%.20g)",
4133 (double) coordinates);
4135 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end open (%.20g)",
4136 (double) coordinates);
4140 MagickExport MagickBooleanType DrawPrimitive(Image *image,
4141 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info,
4142 ExceptionInfo *exception)
4157 if (image->debug != MagickFalse)
4159 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4160 " begin draw-primitive");
4161 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4162 " affine: %g %g %g %g %g %g",draw_info->affine.sx,
4163 draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy,
4164 draw_info->affine.tx,draw_info->affine.ty);
4167 x=(ssize_t) ceil(primitive_info->point.x-0.5);
4168 y=(ssize_t) ceil(primitive_info->point.y-0.5);
4169 image_view=AcquireAuthenticCacheView(image,exception);
4170 switch (primitive_info->primitive)
4172 case PointPrimitive:
4180 if ((y < 0) || (y >= (ssize_t) image->rows))
4182 if ((x < 0) || (x >= (ssize_t) image->columns))
4184 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4185 if (q == (Quantum *) NULL)
4187 (void) GetFillColor(draw_info,x,y,&fill_color,exception);
4188 CompositePixelOver(image,&fill_color,(MagickRealType) fill_color.alpha,q,
4189 (MagickRealType) GetPixelAlpha(image,q),q);
4190 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4193 case ColorPrimitive:
4195 switch (primitive_info->method)
4206 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4207 if (q == (Quantum *) NULL)
4209 GetPixelInfo(image,&pixel);
4210 (void) GetFillColor(draw_info,x,y,&pixel,exception);
4211 SetPixelInfoPixel(image,&pixel,q);
4212 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4224 (void) GetOneCacheViewVirtualPixelInfo(image_view,x,y,&target,
4226 for (y=0; y < (ssize_t) image->rows; y++)
4231 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4233 if (q == (Quantum *) NULL)
4235 for (x=0; x < (ssize_t) image->columns; x++)
4237 GetPixelInfoPixel(image,q,&pixel);
4238 if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse)
4240 q+=GetPixelChannels(image);
4243 (void) GetFillColor(draw_info,x,y,&pixel,exception);
4244 SetPixelInfoPixel(image,&pixel,q);
4245 q+=GetPixelChannels(image);
4247 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4248 if (sync == MagickFalse)
4253 case FloodfillMethod:
4254 case FillToBorderMethod:
4259 (void) GetOneVirtualPixelInfo(image,TileVirtualPixelMethod,x,y,
4261 if (primitive_info->method == FillToBorderMethod)
4263 target.red=(MagickRealType) draw_info->border_color.red;
4264 target.green=(MagickRealType) draw_info->border_color.green;
4265 target.blue=(MagickRealType) draw_info->border_color.blue;
4267 (void) FloodfillPaintImage(image,draw_info,&target,x,y,
4268 primitive_info->method == FloodfillMethod ? MagickFalse :
4269 MagickTrue,exception);
4280 GetPixelInfo(image,&pixel);
4281 for (y=0; y < (ssize_t) image->rows; y++)
4289 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4291 if (q == (Quantum *) NULL)
4293 for (x=0; x < (ssize_t) image->columns; x++)
4295 (void) GetFillColor(draw_info,x,y,&pixel,exception);
4296 SetPixelInfoPixel(image,&pixel,q);
4297 q+=GetPixelChannels(image);
4299 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4300 if (sync == MagickFalse)
4308 case MattePrimitive:
4310 if (image->matte == MagickFalse)
4311 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
4312 switch (primitive_info->method)
4323 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception);
4324 if (q == (Quantum *) NULL)
4326 (void) GetFillColor(draw_info,x,y,&pixel,exception);
4327 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
4328 (void) SyncCacheViewAuthenticPixels(image_view,exception);
4340 (void) GetOneCacheViewVirtualPixelInfo(image_view,x,y,&target,
4342 for (y=0; y < (ssize_t) image->rows; y++)
4350 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4352 if (q == (Quantum *) NULL)
4354 for (x=0; x < (ssize_t) image->columns; x++)
4356 GetPixelInfoPixel(image,q,&pixel);
4357 if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse)
4359 q+=GetPixelChannels(image);
4362 (void) GetFillColor(draw_info,x,y,&pixel,exception);
4363 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
4364 q+=GetPixelChannels(image);
4366 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4367 if (sync == MagickFalse)
4372 case FloodfillMethod:
4373 case FillToBorderMethod:
4381 (void) GetOneVirtualPixelInfo(image,TileVirtualPixelMethod,x,y,
4383 if (primitive_info->method == FillToBorderMethod)
4385 target.red=(MagickRealType) draw_info->border_color.red;
4386 target.green=(MagickRealType) draw_info->border_color.green;
4387 target.blue=(MagickRealType) draw_info->border_color.blue;
4389 channel_mask=SetPixelChannelMask(image,AlphaChannel);
4390 (void) FloodfillPaintImage(image,draw_info,&target,x,y,
4391 primitive_info->method == FloodfillMethod ? MagickFalse :
4392 MagickTrue,exception);
4393 (void) SetPixelChannelMask(image,channel_mask);
4404 for (y=0; y < (ssize_t) image->rows; y++)
4412 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
4414 if (q == (Quantum *) NULL)
4416 for (x=0; x < (ssize_t) image->columns; x++)
4418 (void) GetFillColor(draw_info,x,y,&pixel,exception);
4419 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
4420 q+=GetPixelChannels(image);
4422 sync=SyncCacheViewAuthenticPixels(image_view,exception);
4423 if (sync == MagickFalse)
4434 geometry[MaxTextExtent];
4439 if (primitive_info->text == (char *) NULL)
4441 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4442 (void) CloneString(&clone_info->text,primitive_info->text);
4443 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
4444 primitive_info->point.x,primitive_info->point.y);
4445 (void) CloneString(&clone_info->geometry,geometry);
4446 status=AnnotateImage(image,clone_info,exception);
4447 clone_info=DestroyDrawInfo(clone_info);
4450 case ImagePrimitive:
4456 composite_geometry[MaxTextExtent];
4471 if (primitive_info->text == (char *) NULL)
4473 clone_info=AcquireImageInfo();
4474 if (LocaleNCompare(primitive_info->text,"data:",5) == 0)
4475 composite_image=ReadInlineImage(clone_info,primitive_info->text,
4479 (void) CopyMagickString(clone_info->filename,primitive_info->text,
4481 composite_image=ReadImage(clone_info,exception);
4483 clone_info=DestroyImageInfo(clone_info);
4484 if (composite_image == (Image *) NULL)
4486 (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor)
4487 NULL,(void *) NULL);
4488 x1=(ssize_t) ceil(primitive_info[1].point.x-0.5);
4489 y1=(ssize_t) ceil(primitive_info[1].point.y-0.5);
4490 if (((x1 != 0L) && (x1 != (ssize_t) composite_image->columns)) ||
4491 ((y1 != 0L) && (y1 != (ssize_t) composite_image->rows)))
4494 geometry[MaxTextExtent];
4499 (void) FormatLocaleString(geometry,MaxTextExtent,"%gx%g!",
4500 primitive_info[1].point.x,primitive_info[1].point.y);
4501 composite_image->filter=image->filter;
4502 (void) TransformImage(&composite_image,(char *) NULL,geometry,
4505 if (composite_image->matte == MagickFalse)
4506 (void) SetImageAlphaChannel(composite_image,OpaqueAlphaChannel,
4508 if (draw_info->alpha != OpaqueAlpha)
4509 (void) SetImageAlpha(composite_image,draw_info->alpha,exception);
4510 SetGeometry(image,&geometry);
4511 image->gravity=draw_info->gravity;
4514 (void) FormatLocaleString(composite_geometry,MaxTextExtent,
4515 "%.20gx%.20g%+.20g%+.20g",(double) composite_image->columns,(double)
4516 composite_image->rows,(double) geometry.x,(double) geometry.y);
4517 (void) ParseGravityGeometry(image,composite_geometry,&geometry,exception);
4518 affine=draw_info->affine;
4519 affine.tx=(double) geometry.x;
4520 affine.ty=(double) geometry.y;
4521 composite_image->interpolate=image->interpolate;
4522 if (draw_info->compose == OverCompositeOp)
4523 (void) DrawAffineImage(image,composite_image,&affine,exception);
4525 (void) CompositeImage(image,composite_image,draw_info->compose,
4526 MagickTrue,geometry.x,geometry.y,exception);
4527 composite_image=DestroyImage(composite_image);
4539 if (IsEventLogging() != MagickFalse)
4540 LogPrimitiveInfo(primitive_info);
4541 scale=ExpandAffine(&draw_info->affine);
4542 if ((draw_info->dash_pattern != (double *) NULL) &&
4543 (draw_info->dash_pattern[0] != 0.0) &&
4544 ((scale*draw_info->stroke_width) > MagickEpsilon) &&
4545 (draw_info->stroke.alpha != (Quantum) TransparentAlpha))
4550 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4551 clone_info->stroke_width=0.0;
4552 clone_info->stroke.alpha=(Quantum) TransparentAlpha;
4553 status=DrawPolygonPrimitive(image,clone_info,primitive_info,
4555 clone_info=DestroyDrawInfo(clone_info);
4556 (void) DrawDashPolygon(draw_info,primitive_info,image,exception);
4559 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
4561 (draw_info->stroke.alpha != (Quantum) TransparentAlpha))
4567 Draw strokes while respecting line cap/join attributes.
4569 for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
4571 (primitive_info[i-1].point.x == primitive_info[0].point.x) &&
4572 (primitive_info[i-1].point.y == primitive_info[0].point.y) ?
4573 MagickTrue : MagickFalse;
4574 i=(ssize_t) primitive_info[0].coordinates;
4575 if ((((draw_info->linecap == RoundCap) ||
4576 (closed_path != MagickFalse)) &&
4577 (draw_info->linejoin == RoundJoin)) ||
4578 (primitive_info[i].primitive != UndefinedPrimitive))
4580 (void) DrawPolygonPrimitive(image,draw_info,primitive_info,
4584 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4585 clone_info->stroke_width=0.0;
4586 clone_info->stroke.alpha=(Quantum) TransparentAlpha;
4587 status=DrawPolygonPrimitive(image,clone_info,primitive_info,
4589 clone_info=DestroyDrawInfo(clone_info);
4590 status|=DrawStrokePolygon(image,draw_info,primitive_info,exception);
4593 status=DrawPolygonPrimitive(image,draw_info,primitive_info,exception);
4597 image_view=DestroyCacheView(image_view);
4598 if (image->debug != MagickFalse)
4599 (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-primitive");
4600 return(status != 0 ? MagickTrue : MagickFalse);
4604 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4608 + D r a w S t r o k e P o l y g o n %
4612 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4614 % DrawStrokePolygon() draws a stroked polygon (line, rectangle, ellipse) on
4615 % the image while respecting the line cap and join attributes.
4617 % The format of the DrawStrokePolygon method is:
4619 % MagickBooleanType DrawStrokePolygon(Image *image,
4620 % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info)
4622 % A description of each parameter follows:
4624 % o image: the image.
4626 % o draw_info: the draw info.
4628 % o primitive_info: Specifies a pointer to a PrimitiveInfo structure.
4633 static void DrawRoundLinecap(Image *image,const DrawInfo *draw_info,
4634 const PrimitiveInfo *primitive_info,ExceptionInfo *exception)
4642 for (i=0; i < 4; i++)
4643 linecap[i]=(*primitive_info);
4644 linecap[0].coordinates=4;
4645 linecap[1].point.x+=(double) (10.0*MagickEpsilon);
4646 linecap[2].point.x+=(double) (10.0*MagickEpsilon);
4647 linecap[2].point.y+=(double) (10.0*MagickEpsilon);
4648 linecap[3].point.y+=(double) (10.0*MagickEpsilon);
4649 linecap[4].primitive=UndefinedPrimitive;
4650 (void) DrawPolygonPrimitive(image,draw_info,linecap,exception);
4653 static MagickBooleanType DrawStrokePolygon(Image *image,
4654 const DrawInfo *draw_info,const PrimitiveInfo *primitive_info,
4655 ExceptionInfo *exception)
4667 register const PrimitiveInfo
4672 Draw stroked polygon.
4674 if (image->debug != MagickFalse)
4675 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4676 " begin draw-stroke-polygon");
4677 clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
4678 clone_info->fill=draw_info->stroke;
4679 if (clone_info->fill_pattern != (Image *) NULL)
4680 clone_info->fill_pattern=DestroyImage(clone_info->fill_pattern);
4681 if (clone_info->stroke_pattern != (Image *) NULL)
4682 clone_info->fill_pattern=CloneImage(clone_info->stroke_pattern,0,0,
4683 MagickTrue,exception);
4684 clone_info->stroke.alpha=(Quantum) TransparentAlpha;
4685 clone_info->stroke_width=0.0;
4686 clone_info->fill_rule=NonZeroRule;
4688 for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=p->coordinates)
4690 stroke_polygon=TraceStrokePolygon(draw_info,p);
4691 status=DrawPolygonPrimitive(image,clone_info,stroke_polygon,exception);
4692 stroke_polygon=(PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon);
4693 q=p+p->coordinates-1;
4694 closed_path=(q->point.x == p->point.x) && (q->point.y == p->point.y) ?
4695 MagickTrue : MagickFalse;
4696 if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse))
4698 DrawRoundLinecap(image,draw_info,p,exception);
4699 DrawRoundLinecap(image,draw_info,q,exception);
4702 clone_info=DestroyDrawInfo(clone_info);
4703 if (image->debug != MagickFalse)
4704 (void) LogMagickEvent(DrawEvent,GetMagickModule(),
4705 " end draw-stroke-polygon");
4710 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4714 % G e t A f f i n e M a t r i x %
4718 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4720 % GetAffineMatrix() returns an AffineMatrix initialized to the identity
4723 % The format of the GetAffineMatrix method is:
4725 % void GetAffineMatrix(AffineMatrix *affine_matrix)
4727 % A description of each parameter follows:
4729 % o affine_matrix: the affine matrix.
4732 MagickExport void GetAffineMatrix(AffineMatrix *affine_matrix)
4734 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4735 assert(affine_matrix != (AffineMatrix *) NULL);
4736 (void) ResetMagickMemory(affine_matrix,0,sizeof(*affine_matrix));
4737 affine_matrix->sx=1.0;
4738 affine_matrix->sy=1.0;
4742 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4746 + G e t D r a w I n f o %
4750 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4752 % GetDrawInfo() initializes draw_info to default values from image_info.
4754 % The format of the GetDrawInfo method is:
4756 % void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info)
4758 % A description of each parameter follows:
4760 % o image_info: the image info..
4762 % o draw_info: the draw info.
4765 MagickExport void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info)
4774 Initialize draw attributes.
4776 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4777 assert(draw_info != (DrawInfo *) NULL);
4778 (void) ResetMagickMemory(draw_info,0,sizeof(*draw_info));
4779 GetAffineMatrix(&draw_info->affine);
4780 exception=AcquireExceptionInfo();
4781 (void) QueryColorCompliance("#000F",AllCompliance,&draw_info->fill,
4783 (void) QueryColorCompliance("#FFF0",AllCompliance,&draw_info->stroke,
4785 draw_info->stroke_width=1.0;
4786 draw_info->alpha=OpaqueAlpha;
4787 draw_info->fill_rule=EvenOddRule;
4788 draw_info->linecap=ButtCap;
4789 draw_info->linejoin=MiterJoin;
4790 draw_info->miterlimit=10;
4791 draw_info->decorate=NoDecoration;
4792 draw_info->pointsize=12.0;
4793 draw_info->undercolor.alpha=(Quantum) TransparentAlpha;
4794 draw_info->compose=OverCompositeOp;
4795 draw_info->render=MagickTrue;
4796 draw_info->debug=IsEventLogging();
4797 if (image_info != (ImageInfo *) NULL)
4799 draw_info->stroke_antialias=image_info->antialias;
4800 if (image_info->font != (char *) NULL)
4801 draw_info->font=AcquireString(image_info->font);
4802 if (image_info->density != (char *) NULL)
4803 draw_info->density=AcquireString(image_info->density);
4804 draw_info->text_antialias=image_info->antialias;
4805 if (image_info->pointsize != 0.0)
4806 draw_info->pointsize=image_info->pointsize;
4807 draw_info->border_color=image_info->border_color;
4808 if (image_info->server_name != (char *) NULL)
4809 draw_info->server_name=AcquireString(image_info->server_name);
4810 option=GetImageOption(image_info,"encoding");
4811 if (option != (const char *) NULL)
4812 (void) CloneString(&draw_info->encoding,option);
4813 option=GetImageOption(image_info,"kerning");
4814 if (option != (const char *) NULL)
4815 draw_info->kerning=StringToDouble(option,(char **) NULL);
4816 option=GetImageOption(image_info,"interline-spacing");
4817 if (option != (const char *) NULL)
4818 draw_info->interline_spacing=StringToDouble(option,(char **) NULL);
4819 option=GetImageOption(image_info,"interword-spacing");
4820 if (option != (const char *) NULL)
4821 draw_info->interword_spacing=StringToDouble(option,(char **) NULL);
4822 option=GetImageOption(image_info,"direction");
4823 if (option != (const char *) NULL)
4824 draw_info->direction=(DirectionType) ParseCommandOption(
4825 MagickDirectionOptions,MagickFalse,option);
4827 draw_info->direction=UndefinedDirection;
4828 option=GetImageOption(image_info,"fill");
4829 if (option != (const char *) NULL)
4830 (void) QueryColorCompliance(option,AllCompliance,&draw_info->fill,
4832 option=GetImageOption(image_info,"stroke");
4833 if (option != (const char *) NULL)
4834 (void) QueryColorCompliance(option,AllCompliance,&draw_info->stroke,
4836 option=GetImageOption(image_info,"strokewidth");
4837 if (option != (const char *) NULL)
4838 draw_info->stroke_width=StringToDouble(option,(char **) NULL);
4839 option=GetImageOption(image_info,"undercolor");
4840 if (option != (const char *) NULL)
4841 (void) QueryColorCompliance(option,AllCompliance,&draw_info->undercolor,
4843 option=GetImageOption(image_info,"gravity");
4844 if (option != (const char *) NULL)
4845 draw_info->gravity=(GravityType) ParseCommandOption(
4846 MagickGravityOptions,MagickFalse,option);
4848 exception=DestroyExceptionInfo(exception);
4849 draw_info->signature=MagickSignature;
4853 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4857 + P e r m u t a t e %
4861 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4863 % Permutate() returns the permuation of the (n,k).
4865 % The format of the Permutate method is:
4867 % void Permutate(ssize_t n,ssize_t k)
4869 % A description of each parameter follows:
4877 static inline MagickRealType Permutate(const ssize_t n,const ssize_t k)
4886 for (i=k+1; i <= n; i++)
4888 for (i=1; i <= (n-k); i++)
4894 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4898 + T r a c e P r i m i t i v e %
4902 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4904 % TracePrimitive is a collection of methods for generating graphic
4905 % primitives such as arcs, ellipses, paths, etc.
4909 static void TraceArc(PrimitiveInfo *primitive_info,const PointInfo start,
4910 const PointInfo end,const PointInfo degrees)
4916 center.x=0.5*(end.x+start.x);
4917 center.y=0.5*(end.y+start.y);
4918 radii.x=fabs(center.x-start.x);
4919 radii.y=fabs(center.y-start.y);
4920 TraceEllipse(primitive_info,center,radii,degrees);
4923 static void TraceArcPath(PrimitiveInfo *primitive_info,const PointInfo start,
4924 const PointInfo end,const PointInfo arc,const MagickRealType angle,
4925 const MagickBooleanType large_arc,const MagickBooleanType sweep)
4940 register MagickRealType
4944 register PrimitiveInfo
4953 if ((start.x == end.x) && (start.y == end.y))
4955 TracePoint(primitive_info,end);
4958 radii.x=fabs(arc.x);
4959 radii.y=fabs(arc.y);
4960 if ((radii.x == 0.0) || (radii.y == 0.0))
4962 TraceLine(primitive_info,start,end);
4965 cosine=cos(DegreesToRadians(fmod((double) angle,360.0)));
4966 sine=sin(DegreesToRadians(fmod((double) angle,360.0)));
4967 center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2);
4968 center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2);
4969 delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/
4971 if (delta < MagickEpsilon)
4973 TraceLine(primitive_info,start,end);
4978 radii.x*=sqrt((double) delta);
4979 radii.y*=sqrt((double) delta);
4981 points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x);
4982 points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y);
4983 points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x);
4984 points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y);
4985 alpha=points[1].x-points[0].x;
4986 beta=points[1].y-points[0].y;
4987 factor=1.0/(alpha*alpha+beta*beta)-0.25;
4992 factor=sqrt((double) factor);
4993 if (sweep == large_arc)
4996 center.x=(double) ((points[0].x+points[1].x)/2-factor*beta);
4997 center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha);
4998 alpha=atan2(points[0].y-center.y,points[0].x-center.x);
4999 theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha;
5000 if ((theta < 0.0) && (sweep != MagickFalse))
5001 theta+=(MagickRealType) (2.0*MagickPI);
5003 if ((theta > 0.0) && (sweep == MagickFalse))
5004 theta-=(MagickRealType) (2.0*MagickPI);
5005 arc_segments=(size_t) ceil(fabs((double) (theta/(0.5*MagickPI+
5008 for (i=0; i < (ssize_t) arc_segments; i++)
5010 beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments));
5011 gamma=(8.0/3.0)*sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))*
5012 sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))/
5013 sin(fmod((double) beta,DegreesToRadians(360.0)));
5014 points[0].x=(double) (center.x+cos(fmod((double) (alpha+(double) i*theta/
5015 arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((double) (alpha+
5016 (double) i*theta/arc_segments),DegreesToRadians(360.0))));
5017 points[0].y=(double) (center.y+sin(fmod((double) (alpha+(double) i*theta/
5018 arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((double) (alpha+
5019 (double) i*theta/arc_segments),DegreesToRadians(360.0))));
5020 points[2].x=(double) (center.x+cos(fmod((double) (alpha+(double) (i+1)*
5021 theta/arc_segments),DegreesToRadians(360.0))));
5022 points[2].y=(double) (center.y+sin(fmod((double) (alpha+(double) (i+1)*
5023 theta/arc_segments),DegreesToRadians(360.0))));
5024 points[1].x=(double) (points[2].x+gamma*sin(fmod((double) (alpha+(double)
5025 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
5026 points[1].y=(double) (points[2].y-gamma*cos(fmod((double) (alpha+(double)
5027 (i+1)*theta/arc_segments),DegreesToRadians(360.0))));
5028 p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x;
5029 p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y;
5030 (p+1)->point.x=(double) (cosine*radii.x*points[0].x-sine*radii.y*
5032 (p+1)->point.y=(double) (sine*radii.x*points[0].x+cosine*radii.y*
5034 (p+2)->point.x=(double) (cosine*radii.x*points[1].x-sine*radii.y*
5036 (p+2)->point.y=(double) (sine*radii.x*points[1].x+cosine*radii.y*
5038 (p+3)->point.x=(double) (cosine*radii.x*points[2].x-sine*radii.y*
5040 (p+3)->point.y=(double) (sine*radii.x*points[2].x+cosine*radii.y*
5042 if (i == (ssize_t) (arc_segments-1))
5047 primitive_info->coordinates=(size_t) (p-primitive_info);
5048 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5050 p->primitive=primitive_info->primitive;
5055 static void TraceBezier(PrimitiveInfo *primitive_info,
5056 const size_t number_coordinates)
5068 register PrimitiveInfo
5080 Allocate coeficients.
5082 quantum=number_coordinates;
5083 for (i=0; i < (ssize_t) number_coordinates; i++)
5085 for (j=i+1; j < (ssize_t) number_coordinates; j++)
5087 alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x);
5088 if (alpha > (MagickRealType) quantum)
5089 quantum=(size_t) alpha;
5090 alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y);
5091 if (alpha > (MagickRealType) quantum)
5092 quantum=(size_t) alpha;
5095 quantum=(size_t) MagickMin((double) quantum/number_coordinates,
5096 (double) BezierQuantum);
5097 control_points=quantum*number_coordinates;
5098 coefficients=(MagickRealType *) AcquireQuantumMemory((size_t)
5099 number_coordinates,sizeof(*coefficients));
5100 points=(PointInfo *) AcquireQuantumMemory((size_t) control_points,
5102 if ((coefficients == (MagickRealType *) NULL) ||
5103 (points == (PointInfo *) NULL))
5104 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
5106 Compute bezier points.
5108 end=primitive_info[number_coordinates-1].point;
5109 for (i=0; i < (ssize_t) number_coordinates; i++)
5110 coefficients[i]=Permutate((ssize_t) number_coordinates-1,i);
5112 for (i=0; i < (ssize_t) control_points; i++)
5117 alpha=pow((double) (1.0-weight),(double) number_coordinates-1.0);
5118 for (j=0; j < (ssize_t) number_coordinates; j++)
5120 point.x+=alpha*coefficients[j]*p->point.x;
5121 point.y+=alpha*coefficients[j]*p->point.y;
5122 alpha*=weight/(1.0-weight);
5126 weight+=1.0/control_points;
5129 Bezier curves are just short segmented polys.
5132 for (i=0; i < (ssize_t) control_points; i++)
5134 TracePoint(p,points[i]);
5139 primitive_info->coordinates=(size_t) (p-primitive_info);
5140 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5142 p->primitive=primitive_info->primitive;
5145 points=(PointInfo *) RelinquishMagickMemory(points);
5146 coefficients=(MagickRealType *) RelinquishMagickMemory(coefficients);
5149 static void TraceCircle(PrimitiveInfo *primitive_info,const PointInfo start,
5150 const PointInfo end)
5161 alpha=end.x-start.x;
5163 radius=hypot((double) alpha,(double) beta);
5164 offset.x=(double) radius;
5165 offset.y=(double) radius;
5168 TraceEllipse(primitive_info,start,offset,degrees);
5171 static void TraceEllipse(PrimitiveInfo *primitive_info,const PointInfo start,
5172 const PointInfo stop,const PointInfo degrees)
5183 register PrimitiveInfo
5190 Ellipses are just short segmented polys.
5192 if ((stop.x == 0.0) && (stop.y == 0.0))
5194 TracePoint(primitive_info,start);
5197 delta=2.0/MagickMax(stop.x,stop.y);
5198 step=(MagickRealType) (MagickPI/8.0);
5199 if ((delta >= 0.0) && (delta < (MagickRealType) (MagickPI/8.0)))
5200 step=(MagickRealType) (MagickPI/(4*(MagickPI/delta/2+0.5)));
5201 angle.x=DegreesToRadians(degrees.x);
5203 while (y < degrees.x)
5205 angle.y=(double) (DegreesToRadians(y)-MagickEpsilon);
5206 for (p=primitive_info; angle.x < angle.y; angle.x+=step)
5208 point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*stop.x+start.x;
5209 point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*stop.y+start.y;
5210 TracePoint(p,point);
5213 point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*stop.x+start.x;
5214 point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*stop.y+start.y;
5215 TracePoint(p,point);
5217 primitive_info->coordinates=(size_t) (p-primitive_info);
5218 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5220 p->primitive=primitive_info->primitive;
5225 static void TraceLine(PrimitiveInfo *primitive_info,const PointInfo start,
5226 const PointInfo end)
5228 TracePoint(primitive_info,start);
5229 if ((fabs(start.x-end.x) <= MagickEpsilon) &&
5230 (fabs(start.y-end.y) <= MagickEpsilon))
5232 primitive_info->primitive=PointPrimitive;
5233 primitive_info->coordinates=1;
5236 TracePoint(primitive_info+1,end);
5237 (primitive_info+1)->primitive=primitive_info->primitive;
5238 primitive_info->coordinates=2;
5241 static size_t TracePath(PrimitiveInfo *primitive_info,const char *path)
5244 token[MaxTextExtent];
5266 register PrimitiveInfo
5281 number_coordinates=0;
5283 primitive_type=primitive_info->primitive;
5285 for (p=path; *p != '\0'; )
5287 while (isspace((int) ((unsigned char) *p)) != 0)
5291 last_attribute=attribute;
5292 attribute=(int) (*p++);
5313 GetMagickToken(p,&p,token);
5315 GetMagickToken(p,&p,token);
5316 arc.x=StringToDouble(token,(char **) NULL);
5317 GetMagickToken(p,&p,token);
5319 GetMagickToken(p,&p,token);
5320 arc.y=StringToDouble(token,(char **) NULL);
5321 GetMagickToken(p,&p,token);
5323 GetMagickToken(p,&p,token);
5324 angle=StringToDouble(token,(char **) NULL);
5325 GetMagickToken(p,&p,token);
5327 GetMagickToken(p,&p,token);
5328 large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
5329 GetMagickToken(p,&p,token);
5331 GetMagickToken(p,&p,token);
5332 sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse;
5333 GetMagickToken(p,&p,token);
5335 GetMagickToken(p,&p,token);
5336 x=StringToDouble(token,(char **) NULL);
5337 GetMagickToken(p,&p,token);
5339 GetMagickToken(p,&p,token);
5340 y=StringToDouble(token,(char **) NULL);
5341 end.x=(double) (attribute == (int) 'A' ? x : point.x+x);
5342 end.y=(double) (attribute == (int) 'A' ? y : point.y+y);
5343 TraceArcPath(q,point,end,arc,angle,large_arc,sweep);
5346 while (isspace((int) ((unsigned char) *p)) != 0)
5350 } while (IsPoint(p) != MagickFalse);
5357 Compute bezier points.
5362 for (i=1; i < 4; i++)
5364 GetMagickToken(p,&p,token);
5366 GetMagickToken(p,&p,token);
5367 x=StringToDouble(token,(char **) NULL);
5368 GetMagickToken(p,&p,token);
5370 GetMagickToken(p,&p,token);
5371 y=StringToDouble(token,(char **) NULL);
5372 end.x=(double) (attribute == (int) 'C' ? x : point.x+x);
5373 end.y=(double) (attribute == (int) 'C' ? y : point.y+y);
5376 for (i=0; i < 4; i++)
5377 (q+i)->point=points[i];
5381 } while (IsPoint(p) != MagickFalse);
5389 GetMagickToken(p,&p,token);
5391 GetMagickToken(p,&p,token);
5392 x=StringToDouble(token,(char **) NULL);
5393 point.x=(double) (attribute == (int) 'H' ? x: point.x+x);
5394 TracePoint(q,point);
5396 } while (IsPoint(p) != MagickFalse);
5404 GetMagickToken(p,&p,token);
5406 GetMagickToken(p,&p,token);
5407 x=StringToDouble(token,(char **) NULL);
5408 GetMagickToken(p,&p,token);
5410 GetMagickToken(p,&p,token);
5411 y=StringToDouble(token,(char **) NULL);
5412 point.x=(double) (attribute == (int) 'L' ? x : point.x+x);
5413 point.y=(double) (attribute == (int) 'L' ? y : point.y+y);
5414 TracePoint(q,point);
5416 } while (IsPoint(p) != MagickFalse);
5422 if (q != primitive_info)
5424 primitive_info->coordinates=(size_t) (q-primitive_info);
5425 number_coordinates+=primitive_info->coordinates;
5431 GetMagickToken(p,&p,token);
5433 GetMagickToken(p,&p,token);
5434 x=StringToDouble(token,(char **) NULL);
5435 GetMagickToken(p,&p,token);
5437 GetMagickToken(p,&p,token);
5438 y=StringToDouble(token,(char **) NULL);
5439 point.x=(double) (attribute == (int) 'M' ? x : point.x+x);
5440 point.y=(double) (attribute == (int) 'M' ? y : point.y+y);
5444 TracePoint(q,point);
5446 if ((i != 0) && (attribute == (int) 'M'))
5448 TracePoint(q,point);
5451 } while (IsPoint(p) != MagickFalse);
5458 Compute bezier points.
5463 for (i=1; i < 3; i++)
5465 GetMagickToken(p,&p,token);
5467 GetMagickToken(p,&p,token);
5468 x=StringToDouble(token,(char **) NULL);
5469 GetMagickToken(p,&p,token);
5471 GetMagickToken(p,&p,token);
5472 y=StringToDouble(token,(char **) NULL);
5475 end.x=(double) (attribute == (int) 'Q' ? x : point.x+x);
5476 end.y=(double) (attribute == (int) 'Q' ? y : point.y+y);
5479 for (i=0; i < 3; i++)
5480 (q+i)->point=points[i];
5484 } while (IsPoint(p) != MagickFalse);
5491 Compute bezier points.
5495 points[0]=points[3];
5496 points[1].x=2.0*points[3].x-points[2].x;
5497 points[1].y=2.0*points[3].y-points[2].y;
5498 for (i=2; i < 4; i++)
5500 GetMagickToken(p,&p,token);
5502 GetMagickToken(p,&p,token);
5503 x=StringToDouble(token,(char **) NULL);
5504 GetMagickToken(p,&p,token);
5506 GetMagickToken(p,&p,token);
5507 y=StringToDouble(token,(char **) NULL);
5510 end.x=(double) (attribute == (int) 'S' ? x : point.x+x);
5511 end.y=(double) (attribute == (int) 'S' ? y : point.y+y);
5514 if (strchr("CcSs",last_attribute) == (char *) NULL)
5516 points[0]=points[2];
5517 points[1]=points[3];
5519 for (i=0; i < 4; i++)
5520 (q+i)->point=points[i];
5524 } while (IsPoint(p) != MagickFalse);
5531 Compute bezier points.
5535 points[0]=points[2];
5536 points[1].x=2.0*points[2].x-points[1].x;
5537 points[1].y=2.0*points[2].y-points[1].y;
5538 for (i=2; i < 3; i++)
5540 GetMagickToken(p,&p,token);
5542 GetMagickToken(p,&p,token);
5543 x=StringToDouble(token,(char **) NULL);
5544 GetMagickToken(p,&p,token);
5546 GetMagickToken(p,&p,token);
5547 y=StringToDouble(token,(char **) NULL);
5548 end.x=(double) (attribute == (int) 'T' ? x : point.x+x);
5549 end.y=(double) (attribute == (int) 'T' ? y : point.y+y);
5552 if (strchr("QqTt",last_attribute) == (char *) NULL)
5554 points[0]=points[2];
5555 points[1]=points[3];
5557 for (i=0; i < 3; i++)
5558 (q+i)->point=points[i];
5562 } while (IsPoint(p) != MagickFalse);
5570 GetMagickToken(p,&p,token);
5572 GetMagickToken(p,&p,token);
5573 y=StringToDouble(token,(char **) NULL);
5574 point.y=(double) (attribute == (int) 'V' ? y : point.y+y);
5575 TracePoint(q,point);
5577 } while (IsPoint(p) != MagickFalse);
5584 TracePoint(q,point);
5586 primitive_info->coordinates=(size_t) (q-primitive_info);
5587 number_coordinates+=primitive_info->coordinates;
5594 if (isalpha((int) ((unsigned char) attribute)) != 0)
5595 (void) FormatLocaleFile(stderr,"attribute not recognized: %c\n",
5601 primitive_info->coordinates=(size_t) (q-primitive_info);
5602 number_coordinates+=primitive_info->coordinates;
5603 for (i=0; i < (ssize_t) number_coordinates; i++)
5606 q->primitive=primitive_type;
5608 q->method=FillToBorderMethod;
5611 return(number_coordinates);
5614 static void TraceRectangle(PrimitiveInfo *primitive_info,const PointInfo start,
5615 const PointInfo end)
5620 register PrimitiveInfo
5627 TracePoint(p,start);
5631 TracePoint(p,point);
5637 TracePoint(p,point);
5639 TracePoint(p,start);
5641 primitive_info->coordinates=(size_t) (p-primitive_info);
5642 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5644 p->primitive=primitive_info->primitive;
5649 static void TraceRoundRectangle(PrimitiveInfo *primitive_info,
5650 const PointInfo start,const PointInfo end,PointInfo arc)
5657 register PrimitiveInfo
5664 offset.x=fabs(end.x-start.x);
5665 offset.y=fabs(end.y-start.y);
5666 if (arc.x > (0.5*offset.x))
5668 if (arc.y > (0.5*offset.y))
5670 point.x=start.x+offset.x-arc.x;
5671 point.y=start.y+arc.y;
5674 TraceEllipse(p,point,arc,degrees);
5676 point.x=start.x+offset.x-arc.x;
5677 point.y=start.y+offset.y-arc.y;
5680 TraceEllipse(p,point,arc,degrees);
5682 point.x=start.x+arc.x;
5683 point.y=start.y+offset.y-arc.y;
5686 TraceEllipse(p,point,arc,degrees);
5688 point.x=start.x+arc.x;
5689 point.y=start.y+arc.y;
5692 TraceEllipse(p,point,arc,degrees);
5694 TracePoint(p,primitive_info->point);
5696 primitive_info->coordinates=(size_t) (p-primitive_info);
5697 for (i=0; i < (ssize_t) primitive_info->coordinates; i++)
5699 p->primitive=primitive_info->primitive;
5704 static void TraceSquareLinecap(PrimitiveInfo *primitive_info,
5705 const size_t number_vertices,const MagickRealType offset)
5710 register MagickRealType
5722 for (i=1; i < (ssize_t) number_vertices; i++)
5724 dx=primitive_info[0].point.x-primitive_info[i].point.x;
5725 dy=primitive_info[0].point.y-primitive_info[i].point.y;
5726 if ((fabs((double) dx) >= MagickEpsilon) ||
5727 (fabs((double) dy) >= MagickEpsilon))
5730 if (i == (ssize_t) number_vertices)
5731 i=(ssize_t) number_vertices-1L;
5732 distance=hypot((double) dx,(double) dy);
5733 primitive_info[0].point.x=(double) (primitive_info[i].point.x+
5734 dx*(distance+offset)/distance);
5735 primitive_info[0].point.y=(double) (primitive_info[i].point.y+
5736 dy*(distance+offset)/distance);
5737 for (j=(ssize_t) number_vertices-2; j >= 0; j--)
5739 dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x;
5740 dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y;
5741 if ((fabs((double) dx) >= MagickEpsilon) ||
5742 (fabs((double) dy) >= MagickEpsilon))
5745 distance=hypot((double) dx,(double) dy);
5746 primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+
5747 dx*(distance+offset)/distance);
5748 primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+
5749 dy*(distance+offset)/distance);
5752 static PrimitiveInfo *TraceStrokePolygon(const DrawInfo *draw_info,
5753 const PrimitiveInfo *primitive_info)
5755 typedef struct _LineSegment
5807 number_vertices=primitive_info->coordinates;
5808 max_strokes=2*number_vertices+6*BezierQuantum+360;
5809 path_p=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes,
5811 path_q=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes,
5813 polygon_primitive=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
5814 number_vertices+2UL,sizeof(*polygon_primitive));
5815 if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL) ||
5816 (polygon_primitive == (PrimitiveInfo *) NULL))
5817 return((PrimitiveInfo *) NULL);
5818 (void) CopyMagickMemory(polygon_primitive,primitive_info,(size_t)
5819 number_vertices*sizeof(*polygon_primitive));
5821 (primitive_info[number_vertices-1].point.x == primitive_info[0].point.x) &&
5822 (primitive_info[number_vertices-1].point.y == primitive_info[0].point.y) ?
5823 MagickTrue : MagickFalse;
5824 if ((draw_info->linejoin == RoundJoin) ||
5825 ((draw_info->linejoin == MiterJoin) && (closed_path != MagickFalse)))
5827 polygon_primitive[number_vertices]=primitive_info[1];
5830 polygon_primitive[number_vertices].primitive=UndefinedPrimitive;
5832 Compute the slope for the first line segment, p.
5836 for (n=1; n < (ssize_t) number_vertices; n++)
5838 dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x;
5839 dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y;
5840 if ((fabs(dx.p) >= MagickEpsilon) || (fabs(dy.p) >= MagickEpsilon))
5843 if (n == (ssize_t) number_vertices)
5844 n=(ssize_t) number_vertices-1L;
5846 inverse_slope.p=0.0;
5847 if (fabs(dx.p) <= MagickEpsilon)
5850 slope.p=dy.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5852 slope.p=dy.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5855 if (fabs(dy.p) <= MagickEpsilon)
5858 inverse_slope.p=dx.p < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5860 inverse_slope.p=dx.p < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5865 inverse_slope.p=(-1.0/slope.p);
5867 mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0;
5868 miterlimit=(MagickRealType) (draw_info->miterlimit*draw_info->miterlimit*
5870 if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse))
5871 TraceSquareLinecap(polygon_primitive,number_vertices,mid);
5872 offset.x=sqrt((double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0)));
5873 offset.y=(double) (offset.x*inverse_slope.p);
5874 if ((dy.p*offset.x-dx.p*offset.y) > 0.0)
5876 box_p[0].x=polygon_primitive[0].point.x-offset.x;
5877 box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p;
5878 box_p[1].x=polygon_primitive[n].point.x-offset.x;
5879 box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p;
5880 box_q[0].x=polygon_primitive[0].point.x+offset.x;
5881 box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p;
5882 box_q[1].x=polygon_primitive[n].point.x+offset.x;
5883 box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p;
5887 box_p[0].x=polygon_primitive[0].point.x+offset.x;
5888 box_p[0].y=polygon_primitive[0].point.y+offset.y;
5889 box_p[1].x=polygon_primitive[n].point.x+offset.x;
5890 box_p[1].y=polygon_primitive[n].point.y+offset.y;
5891 box_q[0].x=polygon_primitive[0].point.x-offset.x;
5892 box_q[0].y=polygon_primitive[0].point.y-offset.y;
5893 box_q[1].x=polygon_primitive[n].point.x-offset.x;
5894 box_q[1].y=polygon_primitive[n].point.y-offset.y;
5897 Create strokes for the line join attribute: bevel, miter, round.
5901 path_q[p++]=box_q[0];
5902 path_p[q++]=box_p[0];
5903 for (i=(ssize_t) n+1; i < (ssize_t) number_vertices; i++)
5906 Compute the slope for this line segment, q.
5908 dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x;
5909 dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y;
5910 dot_product=dx.q*dx.q+dy.q*dy.q;
5911 if (dot_product < 0.25)
5914 inverse_slope.q=0.0;
5915 if (fabs(dx.q) < MagickEpsilon)
5918 slope.q=dy.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5920 slope.q=dy.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5923 if (fabs(dy.q) <= MagickEpsilon)
5926 inverse_slope.q=dx.q < 0.0 ? -1.0/MagickEpsilon : 1.0/MagickEpsilon;
5928 inverse_slope.q=dx.q < 0.0 ? 1.0/MagickEpsilon : -1.0/MagickEpsilon;
5933 inverse_slope.q=(-1.0/slope.q);
5935 offset.x=sqrt((double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0)));
5936 offset.y=(double) (offset.x*inverse_slope.q);
5937 dot_product=dy.q*offset.x-dx.q*offset.y;
5938 if (dot_product > 0.0)
5940 box_p[2].x=polygon_primitive[n].point.x-offset.x;
5941 box_p[2].y=polygon_primitive[n].point.y-offset.y;
5942 box_p[3].x=polygon_primitive[i].point.x-offset.x;
5943 box_p[3].y=polygon_primitive[i].point.y-offset.y;
5944 box_q[2].x=polygon_primitive[n].point.x+offset.x;
5945 box_q[2].y=polygon_primitive[n].point.y+offset.y;
5946 box_q[3].x=polygon_primitive[i].point.x+offset.x;
5947 box_q[3].y=polygon_primitive[i].point.y+offset.y;
5951 box_p[2].x=polygon_primitive[n].point.x+offset.x;
5952 box_p[2].y=polygon_primitive[n].point.y+offset.y;
5953 box_p[3].x=polygon_primitive[i].point.x+offset.x;
5954 box_p[3].y=polygon_primitive[i].point.y+offset.y;
5955 box_q[2].x=polygon_primitive[n].point.x-offset.x;
5956 box_q[2].y=polygon_primitive[n].point.y-offset.y;
5957 box_q[3].x=polygon_primitive[i].point.x-offset.x;
5958 box_q[3].y=polygon_primitive[i].point.y-offset.y;
5960 if (fabs((double) (slope.p-slope.q)) <= MagickEpsilon)
5967 box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+
5968 box_p[3].y)/(slope.p-slope.q));
5969 box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y);
5970 box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+
5971 box_q[3].y)/(slope.p-slope.q));
5972 box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y);
5974 if (q >= (ssize_t) (max_strokes-6*BezierQuantum-360))
5976 max_strokes+=6*BezierQuantum+360;
5977 path_p=(PointInfo *) ResizeQuantumMemory(path_p,(size_t) max_strokes,
5979 path_q=(PointInfo *) ResizeQuantumMemory(path_q,(size_t) max_strokes,
5981 if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL))
5983 polygon_primitive=(PrimitiveInfo *)
5984 RelinquishMagickMemory(polygon_primitive);
5985 return((PrimitiveInfo *) NULL);
5988 dot_product=dx.q*dy.p-dx.p*dy.q;
5989 if (dot_product <= 0.0)
5990 switch (draw_info->linejoin)
5994 path_q[q++]=box_q[1];
5995 path_q[q++]=box_q[2];
5996 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
5997 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
5998 if (dot_product <= miterlimit)
5999 path_p[p++]=box_p[4];
6002 path_p[p++]=box_p[1];
6003 path_p[p++]=box_p[2];
6009 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6010 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6011 if (dot_product <= miterlimit)
6013 path_q[q++]=box_q[4];
6014 path_p[p++]=box_p[4];
6018 path_q[q++]=box_q[1];
6019 path_q[q++]=box_q[2];
6020 path_p[p++]=box_p[1];
6021 path_p[p++]=box_p[2];
6027 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6028 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6029 if (dot_product <= miterlimit)
6030 path_p[p++]=box_p[4];
6033 path_p[p++]=box_p[1];
6034 path_p[p++]=box_p[2];
6036 center=polygon_primitive[n].point;
6037 theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x);
6038 theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x);
6039 if (theta.q < theta.p)
6040 theta.q+=(MagickRealType) (2.0*MagickPI);
6041 arc_segments=(size_t) ceil((double) ((theta.q-theta.p)/
6042 (2.0*sqrt((double) (1.0/mid)))));
6043 path_q[q].x=box_q[1].x;
6044 path_q[q].y=box_q[1].y;
6046 for (j=1; j < (ssize_t) arc_segments; j++)
6048 delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments);
6049 path_q[q].x=(double) (center.x+mid*cos(fmod((double)
6050 (theta.p+delta_theta),DegreesToRadians(360.0))));
6051 path_q[q].y=(double) (center.y+mid*sin(fmod((double)
6052 (theta.p+delta_theta),DegreesToRadians(360.0))));
6055 path_q[q++]=box_q[2];
6062 switch (draw_info->linejoin)
6066 path_p[p++]=box_p[1];
6067 path_p[p++]=box_p[2];
6068 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6069 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6070 if (dot_product <= miterlimit)
6071 path_q[q++]=box_q[4];
6074 path_q[q++]=box_q[1];
6075 path_q[q++]=box_q[2];
6081 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6082 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6083 if (dot_product <= miterlimit)
6085 path_q[q++]=box_q[4];
6086 path_p[p++]=box_p[4];
6090 path_q[q++]=box_q[1];
6091 path_q[q++]=box_q[2];
6092 path_p[p++]=box_p[1];
6093 path_p[p++]=box_p[2];
6099 dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+
6100 (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y);
6101 if (dot_product <= miterlimit)
6102 path_q[q++]=box_q[4];
6105 path_q[q++]=box_q[1];
6106 path_q[q++]=box_q[2];
6108 center=polygon_primitive[n].point;
6109 theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x);
6110 theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x);
6111 if (theta.p < theta.q)
6112 theta.p+=(MagickRealType) (2.0*MagickPI);
6113 arc_segments=(size_t) ceil((double) ((theta.p-theta.q)/
6114 (2.0*sqrt((double) (1.0/mid)))));
6115 path_p[p++]=box_p[1];
6116 for (j=1; j < (ssize_t) arc_segments; j++)
6118 delta_theta=(MagickRealType) (j*(theta.q-theta.p)/arc_segments);
6119 path_p[p].x=(double) (center.x+mid*cos(fmod((double)
6120 (theta.p+delta_theta),DegreesToRadians(360.0))));
6121 path_p[p].y=(double) (center.y+mid*sin(fmod((double)
6122 (theta.p+delta_theta),DegreesToRadians(360.0))));
6125 path_p[p++]=box_p[2];
6132 inverse_slope.p=inverse_slope.q;
6141 path_p[p++]=box_p[1];
6142 path_q[q++]=box_q[1];
6144 Trace stroked polygon.
6146 stroke_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t)
6147 (p+q+2UL*closed_path+2UL),sizeof(*stroke_polygon));
6148 if (stroke_polygon != (PrimitiveInfo *) NULL)
6150 for (i=0; i < (ssize_t) p; i++)
6152 stroke_polygon[i]=polygon_primitive[0];
6153 stroke_polygon[i].point=path_p[i];
6155 if (closed_path != MagickFalse)
6157 stroke_polygon[i]=polygon_primitive[0];
6158 stroke_polygon[i].point=stroke_polygon[0].point;
6161 for ( ; i < (ssize_t) (p+q+closed_path); i++)
6163 stroke_polygon[i]=polygon_primitive[0];
6164 stroke_polygon[i].point=path_q[p+q+closed_path-(i+1)];
6166 if (closed_path != MagickFalse)
6168 stroke_polygon[i]=polygon_primitive[0];
6169 stroke_polygon[i].point=stroke_polygon[p+closed_path].point;
6172 stroke_polygon[i]=polygon_primitive[0];
6173 stroke_polygon[i].point=stroke_polygon[0].point;
6175 stroke_polygon[i].primitive=UndefinedPrimitive;
6176 stroke_polygon[0].coordinates=(size_t) (p+q+2*closed_path+1);
6178 path_p=(PointInfo *) RelinquishMagickMemory(path_p);
6179 path_q=(PointInfo *) RelinquishMagickMemory(path_q);
6180 polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive);
6181 return(stroke_polygon);