/MagickCore/draw.c
C | 7487 lines | 6298 code | 331 blank | 858 comment | 1382 complexity | 21ae1370ce1858972c291d10c68a9f34 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
Large files files are truncated, but you can click here to view the full file
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % DDDD RRRR AAA W W %
- % D D R R A A W W %
- % D D RRRR AAAAA W W W %
- % D D R RN A A WW WW %
- % DDDD R R A A W W %
- % %
- % %
- % MagickCore Image Drawing Methods %
- % %
- % %
- % Software Design %
- % Cristy %
- % July 1998 %
- % %
- % %
- % Copyright 1999-2019 ImageMagick Studio LLC, a non-profit organization %
- % dedicated to making software imaging solutions freely available. %
- % %
- % You may not use this file except in compliance with the License. You may %
- % obtain a copy of the License at %
- % %
- % https://imagemagick.org/script/license.php %
- % %
- % Unless required by applicable law or agreed to in writing, software %
- % distributed under the License is distributed on an "AS IS" BASIS, %
- % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
- % See the License for the specific language governing permissions and %
- % limitations under the License. %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % Bill Radcliffe of Corbis (www.corbis.com) contributed the polygon
- % rendering code based on Paul Heckbert's "Concave Polygon Scan Conversion",
- % Graphics Gems, 1990. Leonard Rosenthal and David Harr of Appligent
- % (www.appligent.com) contributed the dash pattern, linecap stroking
- % algorithm, and minor rendering improvements.
- %
- */
- /*
- Include declarations.
- */
- #include "MagickCore/studio.h"
- #include "MagickCore/annotate.h"
- #include "MagickCore/artifact.h"
- #include "MagickCore/blob.h"
- #include "MagickCore/cache.h"
- #include "MagickCore/cache-private.h"
- #include "MagickCore/cache-view.h"
- #include "MagickCore/channel.h"
- #include "MagickCore/color.h"
- #include "MagickCore/colorspace-private.h"
- #include "MagickCore/composite.h"
- #include "MagickCore/composite-private.h"
- #include "MagickCore/constitute.h"
- #include "MagickCore/draw.h"
- #include "MagickCore/draw-private.h"
- #include "MagickCore/enhance.h"
- #include "MagickCore/exception.h"
- #include "MagickCore/exception-private.h"
- #include "MagickCore/gem.h"
- #include "MagickCore/geometry.h"
- #include "MagickCore/image-private.h"
- #include "MagickCore/list.h"
- #include "MagickCore/log.h"
- #include "MagickCore/memory-private.h"
- #include "MagickCore/monitor.h"
- #include "MagickCore/monitor-private.h"
- #include "MagickCore/option.h"
- #include "MagickCore/paint.h"
- #include "MagickCore/pixel-accessor.h"
- #include "MagickCore/pixel-private.h"
- #include "MagickCore/property.h"
- #include "MagickCore/resample.h"
- #include "MagickCore/resample-private.h"
- #include "MagickCore/resource_.h"
- #include "MagickCore/splay-tree.h"
- #include "MagickCore/string_.h"
- #include "MagickCore/string-private.h"
- #include "MagickCore/thread-private.h"
- #include "MagickCore/token.h"
- #include "MagickCore/transform-private.h"
- #include "MagickCore/utility.h"
- /*
- Define declarations.
- */
- #define BezierQuantum 200
- #define PrimitiveExtentPad 2048
- #define MaxBezierCoordinates 4194304
- #define ThrowPointExpectedException(token,exception) \
- { \
- (void) ThrowMagickException(exception,GetMagickModule(),DrawError, \
- "NonconformingDrawingPrimitiveDefinition","`%s'",token); \
- status=MagickFalse; \
- break; \
- }
- /*
- Typedef declarations.
- */
- typedef struct _EdgeInfo
- {
- SegmentInfo
- bounds;
- double
- scanline;
- PointInfo
- *points;
- size_t
- number_points;
- ssize_t
- direction;
- MagickBooleanType
- ghostline;
- size_t
- highwater;
- } EdgeInfo;
- typedef struct _ElementInfo
- {
- double
- cx,
- cy,
- major,
- minor,
- angle;
- } ElementInfo;
- typedef struct _MVGInfo
- {
- PrimitiveInfo
- **primitive_info;
- size_t
- *extent;
- ssize_t
- offset;
- PointInfo
- point;
- ExceptionInfo
- *exception;
- } MVGInfo;
- typedef struct _PolygonInfo
- {
- EdgeInfo
- *edges;
- size_t
- number_edges;
- } PolygonInfo;
- typedef enum
- {
- MoveToCode,
- OpenCode,
- GhostlineCode,
- LineToCode,
- EndCode
- } PathInfoCode;
- typedef struct _PathInfo
- {
- PointInfo
- point;
- PathInfoCode
- code;
- } PathInfo;
- /*
- Forward declarations.
- */
- static Image
- *DrawClippingMask(Image *,const DrawInfo *,const char *,const char *,
- ExceptionInfo *);
- static MagickBooleanType
- DrawStrokePolygon(Image *,const DrawInfo *,const PrimitiveInfo *,
- ExceptionInfo *),
- RenderMVGContent(Image *,const DrawInfo *,const size_t,ExceptionInfo *),
- TraceArc(MVGInfo *,const PointInfo,const PointInfo,const PointInfo),
- TraceArcPath(MVGInfo *,const PointInfo,const PointInfo,const PointInfo,
- const double,const MagickBooleanType,const MagickBooleanType),
- TraceBezier(MVGInfo *,const size_t),
- TraceCircle(MVGInfo *,const PointInfo,const PointInfo),
- TraceEllipse(MVGInfo *,const PointInfo,const PointInfo,const PointInfo),
- TraceLine(PrimitiveInfo *,const PointInfo,const PointInfo),
- TraceRectangle(PrimitiveInfo *,const PointInfo,const PointInfo),
- TraceRoundRectangle(MVGInfo *,const PointInfo,const PointInfo,PointInfo),
- TraceSquareLinecap(PrimitiveInfo *,const size_t,const double);
- static PrimitiveInfo
- *TraceStrokePolygon(const Image *,const DrawInfo *,const PrimitiveInfo *);
- static size_t
- TracePath(MVGInfo *,const char *,ExceptionInfo *);
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % A c q u i r e D r a w I n f o %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % AcquireDrawInfo() returns a DrawInfo structure properly initialized.
- %
- % The format of the AcquireDrawInfo method is:
- %
- % DrawInfo *AcquireDrawInfo(void)
- %
- */
- MagickExport DrawInfo *AcquireDrawInfo(void)
- {
- DrawInfo
- *draw_info;
- draw_info=(DrawInfo *) AcquireCriticalMemory(sizeof(*draw_info));
- GetDrawInfo((ImageInfo *) NULL,draw_info);
- return(draw_info);
- }
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % C l o n e D r a w I n f o %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % CloneDrawInfo() makes a copy of the given draw_info structure. If NULL
- % is specified, a new DrawInfo structure is created initialized to default
- % values.
- %
- % The format of the CloneDrawInfo method is:
- %
- % DrawInfo *CloneDrawInfo(const ImageInfo *image_info,
- % const DrawInfo *draw_info)
- %
- % A description of each parameter follows:
- %
- % o image_info: the image info.
- %
- % o draw_info: the draw info.
- %
- */
- MagickExport DrawInfo *CloneDrawInfo(const ImageInfo *image_info,
- const DrawInfo *draw_info)
- {
- DrawInfo
- *clone_info;
- ExceptionInfo
- *exception;
- clone_info=(DrawInfo *) AcquireCriticalMemory(sizeof(*clone_info));
- GetDrawInfo(image_info,clone_info);
- if (draw_info == (DrawInfo *) NULL)
- return(clone_info);
- exception=AcquireExceptionInfo();
- if (draw_info->primitive != (char *) NULL)
- (void) CloneString(&clone_info->primitive,draw_info->primitive);
- if (draw_info->geometry != (char *) NULL)
- (void) CloneString(&clone_info->geometry,draw_info->geometry);
- clone_info->compliance=draw_info->compliance;
- clone_info->viewbox=draw_info->viewbox;
- clone_info->affine=draw_info->affine;
- clone_info->gravity=draw_info->gravity;
- clone_info->fill=draw_info->fill;
- clone_info->stroke=draw_info->stroke;
- clone_info->stroke_width=draw_info->stroke_width;
- if (draw_info->fill_pattern != (Image *) NULL)
- clone_info->fill_pattern=CloneImage(draw_info->fill_pattern,0,0,MagickTrue,
- exception);
- if (draw_info->stroke_pattern != (Image *) NULL)
- clone_info->stroke_pattern=CloneImage(draw_info->stroke_pattern,0,0,
- MagickTrue,exception);
- clone_info->stroke_antialias=draw_info->stroke_antialias;
- clone_info->text_antialias=draw_info->text_antialias;
- clone_info->fill_rule=draw_info->fill_rule;
- clone_info->linecap=draw_info->linecap;
- clone_info->linejoin=draw_info->linejoin;
- clone_info->miterlimit=draw_info->miterlimit;
- clone_info->dash_offset=draw_info->dash_offset;
- clone_info->decorate=draw_info->decorate;
- clone_info->compose=draw_info->compose;
- if (draw_info->text != (char *) NULL)
- (void) CloneString(&clone_info->text,draw_info->text);
- if (draw_info->font != (char *) NULL)
- (void) CloneString(&clone_info->font,draw_info->font);
- if (draw_info->metrics != (char *) NULL)
- (void) CloneString(&clone_info->metrics,draw_info->metrics);
- if (draw_info->family != (char *) NULL)
- (void) CloneString(&clone_info->family,draw_info->family);
- clone_info->style=draw_info->style;
- clone_info->stretch=draw_info->stretch;
- clone_info->weight=draw_info->weight;
- if (draw_info->encoding != (char *) NULL)
- (void) CloneString(&clone_info->encoding,draw_info->encoding);
- clone_info->pointsize=draw_info->pointsize;
- clone_info->kerning=draw_info->kerning;
- clone_info->interline_spacing=draw_info->interline_spacing;
- clone_info->interword_spacing=draw_info->interword_spacing;
- clone_info->direction=draw_info->direction;
- if (draw_info->density != (char *) NULL)
- (void) CloneString(&clone_info->density,draw_info->density);
- clone_info->align=draw_info->align;
- clone_info->undercolor=draw_info->undercolor;
- clone_info->border_color=draw_info->border_color;
- if (draw_info->server_name != (char *) NULL)
- (void) CloneString(&clone_info->server_name,draw_info->server_name);
- if (draw_info->dash_pattern != (double *) NULL)
- {
- register ssize_t
- x;
- for (x=0; fabs(draw_info->dash_pattern[x]) >= MagickEpsilon; x++) ;
- clone_info->dash_pattern=(double *) AcquireQuantumMemory((size_t) (2*x+2),
- sizeof(*clone_info->dash_pattern));
- if (clone_info->dash_pattern == (double *) NULL)
- ThrowFatalException(ResourceLimitFatalError,
- "UnableToAllocateDashPattern");
- (void) memset(clone_info->dash_pattern,0,(size_t) (2*x+2)*
- sizeof(*clone_info->dash_pattern));
- (void) memcpy(clone_info->dash_pattern,draw_info->dash_pattern,(size_t)
- (x+1)*sizeof(*clone_info->dash_pattern));
- }
- clone_info->gradient=draw_info->gradient;
- if (draw_info->gradient.stops != (StopInfo *) NULL)
- {
- size_t
- number_stops;
- number_stops=clone_info->gradient.number_stops;
- clone_info->gradient.stops=(StopInfo *) AcquireQuantumMemory((size_t)
- number_stops,sizeof(*clone_info->gradient.stops));
- if (clone_info->gradient.stops == (StopInfo *) NULL)
- ThrowFatalException(ResourceLimitFatalError,
- "UnableToAllocateDashPattern");
- (void) memcpy(clone_info->gradient.stops,draw_info->gradient.stops,
- (size_t) number_stops*sizeof(*clone_info->gradient.stops));
- }
- clone_info->bounds=draw_info->bounds;
- clone_info->fill_alpha=draw_info->fill_alpha;
- clone_info->stroke_alpha=draw_info->stroke_alpha;
- clone_info->element_reference=draw_info->element_reference;
- clone_info->clip_path=draw_info->clip_path;
- clone_info->clip_units=draw_info->clip_units;
- if (draw_info->clip_mask != (char *) NULL)
- (void) CloneString(&clone_info->clip_mask,draw_info->clip_mask);
- if (draw_info->clipping_mask != (Image *) NULL)
- clone_info->clipping_mask=CloneImage(draw_info->clipping_mask,0,0,
- MagickTrue,exception);
- if (draw_info->composite_mask != (Image *) NULL)
- clone_info->composite_mask=CloneImage(draw_info->composite_mask,0,0,
- MagickTrue,exception);
- clone_info->render=draw_info->render;
- clone_info->debug=IsEventLogging();
- exception=DestroyExceptionInfo(exception);
- return(clone_info);
- }
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- + C o n v e r t P a t h T o P o l y g o n %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % ConvertPathToPolygon() converts a path to the more efficient sorted
- % rendering form.
- %
- % The format of the ConvertPathToPolygon method is:
- %
- % PolygonInfo *ConvertPathToPolygon(const PathInfo *path_info)
- %
- % A description of each parameter follows:
- %
- % o Method ConvertPathToPolygon returns the path in a more efficient sorted
- % rendering form of type PolygonInfo.
- %
- % o draw_info: Specifies a pointer to an DrawInfo structure.
- %
- % o path_info: Specifies a pointer to an PathInfo structure.
- %
- %
- */
- #if defined(__cplusplus) || defined(c_plusplus)
- extern "C" {
- #endif
- static int DrawCompareEdges(const void *p_edge,const void *q_edge)
- {
- #define DrawCompareEdge(p,q) \
- { \
- if (((p)-(q)) < 0.0) \
- return(-1); \
- if (((p)-(q)) > 0.0) \
- return(1); \
- }
- register const PointInfo
- *p,
- *q;
- /*
- Edge sorting for right-handed coordinate system.
- */
- p=((const EdgeInfo *) p_edge)->points;
- q=((const EdgeInfo *) q_edge)->points;
- DrawCompareEdge(p[0].y,q[0].y);
- DrawCompareEdge(p[0].x,q[0].x);
- DrawCompareEdge((p[1].x-p[0].x)*(q[1].y-q[0].y),(p[1].y-p[0].y)*
- (q[1].x-q[0].x));
- DrawCompareEdge(p[1].y,q[1].y);
- DrawCompareEdge(p[1].x,q[1].x);
- return(0);
- }
- #if defined(__cplusplus) || defined(c_plusplus)
- }
- #endif
- static void LogPolygonInfo(const PolygonInfo *polygon_info)
- {
- register EdgeInfo
- *p;
- register ssize_t
- i,
- j;
- (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin active-edge");
- p=polygon_info->edges;
- for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
- {
- (void) LogMagickEvent(DrawEvent,GetMagickModule()," edge %.20g:",
- (double) i);
- (void) LogMagickEvent(DrawEvent,GetMagickModule()," direction: %s",
- p->direction != MagickFalse ? "down" : "up");
- (void) LogMagickEvent(DrawEvent,GetMagickModule()," ghostline: %s",
- p->ghostline != MagickFalse ? "transparent" : "opaque");
- (void) LogMagickEvent(DrawEvent,GetMagickModule(),
- " bounds: %g,%g - %g,%g",p->bounds.x1,p->bounds.y1,
- p->bounds.x2,p->bounds.y2);
- for (j=0; j < (ssize_t) p->number_points; j++)
- (void) LogMagickEvent(DrawEvent,GetMagickModule()," %g,%g",
- p->points[j].x,p->points[j].y);
- p++;
- }
- (void) LogMagickEvent(DrawEvent,GetMagickModule()," end active-edge");
- }
- static void ReversePoints(PointInfo *points,const size_t number_points)
- {
- PointInfo
- point;
- register ssize_t
- i;
- for (i=0; i < (ssize_t) (number_points >> 1); i++)
- {
- point=points[i];
- points[i]=points[number_points-(i+1)];
- points[number_points-(i+1)]=point;
- }
- }
- static PolygonInfo *ConvertPathToPolygon(const PathInfo *path_info)
- {
- long
- direction,
- next_direction;
- PointInfo
- point,
- *points;
- PolygonInfo
- *polygon_info;
- SegmentInfo
- bounds;
- register ssize_t
- i,
- n;
- MagickBooleanType
- ghostline;
- size_t
- edge,
- number_edges,
- number_points;
- /*
- Convert a path to the more efficient sorted rendering form.
- */
- polygon_info=(PolygonInfo *) AcquireMagickMemory(sizeof(*polygon_info));
- if (polygon_info == (PolygonInfo *) NULL)
- return((PolygonInfo *) NULL);
- number_edges=16;
- polygon_info->edges=(EdgeInfo *) AcquireQuantumMemory(number_edges,
- sizeof(*polygon_info->edges));
- if (polygon_info->edges == (EdgeInfo *) NULL)
- return((PolygonInfo *) NULL);
- (void) memset(polygon_info->edges,0,number_edges*
- sizeof(*polygon_info->edges));
- direction=0;
- edge=0;
- ghostline=MagickFalse;
- n=0;
- number_points=0;
- points=(PointInfo *) NULL;
- (void) memset(&point,0,sizeof(point));
- (void) memset(&bounds,0,sizeof(bounds));
- polygon_info->edges[edge].number_points=(size_t) n;
- polygon_info->edges[edge].scanline=0.0;
- polygon_info->edges[edge].highwater=0;
- polygon_info->edges[edge].ghostline=ghostline;
- polygon_info->edges[edge].direction=(ssize_t) direction;
- polygon_info->edges[edge].points=points;
- polygon_info->edges[edge].bounds=bounds;
- polygon_info->number_edges=0;
- for (i=0; path_info[i].code != EndCode; i++)
- {
- if ((path_info[i].code == MoveToCode) || (path_info[i].code == OpenCode) ||
- (path_info[i].code == GhostlineCode))
- {
- /*
- Move to.
- */
- if ((points != (PointInfo *) NULL) && (n >= 2))
- {
- if (edge == number_edges)
- {
- number_edges<<=1;
- polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
- polygon_info->edges,(size_t) number_edges,
- sizeof(*polygon_info->edges));
- if (polygon_info->edges == (EdgeInfo *) NULL)
- return((PolygonInfo *) NULL);
- }
- polygon_info->edges[edge].number_points=(size_t) n;
- polygon_info->edges[edge].scanline=(-1.0);
- polygon_info->edges[edge].highwater=0;
- polygon_info->edges[edge].ghostline=ghostline;
- polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
- if (direction < 0)
- ReversePoints(points,(size_t) n);
- polygon_info->edges[edge].points=points;
- polygon_info->edges[edge].bounds=bounds;
- polygon_info->edges[edge].bounds.y1=points[0].y;
- polygon_info->edges[edge].bounds.y2=points[n-1].y;
- points=(PointInfo *) NULL;
- ghostline=MagickFalse;
- edge++;
- }
- if (points == (PointInfo *) NULL)
- {
- number_points=16;
- points=(PointInfo *) AcquireQuantumMemory((size_t) number_points,
- sizeof(*points));
- if (points == (PointInfo *) NULL)
- return((PolygonInfo *) NULL);
- }
- ghostline=path_info[i].code == GhostlineCode ? MagickTrue : MagickFalse;
- point=path_info[i].point;
- points[0]=point;
- bounds.x1=point.x;
- bounds.x2=point.x;
- direction=0;
- n=1;
- continue;
- }
- /*
- Line to.
- */
- next_direction=((path_info[i].point.y > point.y) ||
- ((fabs(path_info[i].point.y-point.y) < MagickEpsilon) &&
- (path_info[i].point.x > point.x))) ? 1 : -1;
- if ((points != (PointInfo *) NULL) && (direction != 0) &&
- (direction != next_direction))
- {
- /*
- New edge.
- */
- point=points[n-1];
- if (edge == number_edges)
- {
- number_edges<<=1;
- polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
- polygon_info->edges,(size_t) number_edges,
- sizeof(*polygon_info->edges));
- if (polygon_info->edges == (EdgeInfo *) NULL)
- return((PolygonInfo *) NULL);
- }
- polygon_info->edges[edge].number_points=(size_t) n;
- polygon_info->edges[edge].scanline=(-1.0);
- polygon_info->edges[edge].highwater=0;
- polygon_info->edges[edge].ghostline=ghostline;
- polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
- if (direction < 0)
- ReversePoints(points,(size_t) n);
- polygon_info->edges[edge].points=points;
- polygon_info->edges[edge].bounds=bounds;
- polygon_info->edges[edge].bounds.y1=points[0].y;
- polygon_info->edges[edge].bounds.y2=points[n-1].y;
- number_points=16;
- points=(PointInfo *) AcquireQuantumMemory((size_t) number_points,
- sizeof(*points));
- if (points == (PointInfo *) NULL)
- return((PolygonInfo *) NULL);
- n=1;
- ghostline=MagickFalse;
- points[0]=point;
- bounds.x1=point.x;
- bounds.x2=point.x;
- edge++;
- }
- direction=next_direction;
- if (points == (PointInfo *) NULL)
- continue;
- if (n == (ssize_t) number_points)
- {
- number_points<<=1;
- points=(PointInfo *) ResizeQuantumMemory(points,(size_t) number_points,
- sizeof(*points));
- if (points == (PointInfo *) NULL)
- return((PolygonInfo *) NULL);
- }
- point=path_info[i].point;
- points[n]=point;
- if (point.x < bounds.x1)
- bounds.x1=point.x;
- if (point.x > bounds.x2)
- bounds.x2=point.x;
- n++;
- }
- if (points != (PointInfo *) NULL)
- {
- if (n < 2)
- points=(PointInfo *) RelinquishMagickMemory(points);
- else
- {
- if (edge == number_edges)
- {
- number_edges<<=1;
- polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory(
- polygon_info->edges,(size_t) number_edges,
- sizeof(*polygon_info->edges));
- if (polygon_info->edges == (EdgeInfo *) NULL)
- return((PolygonInfo *) NULL);
- }
- polygon_info->edges[edge].number_points=(size_t) n;
- polygon_info->edges[edge].scanline=(-1.0);
- polygon_info->edges[edge].highwater=0;
- polygon_info->edges[edge].ghostline=ghostline;
- polygon_info->edges[edge].direction=(ssize_t) (direction > 0);
- if (direction < 0)
- ReversePoints(points,(size_t) n);
- polygon_info->edges[edge].points=points;
- polygon_info->edges[edge].bounds=bounds;
- polygon_info->edges[edge].bounds.y1=points[0].y;
- polygon_info->edges[edge].bounds.y2=points[n-1].y;
- ghostline=MagickFalse;
- edge++;
- }
- }
- polygon_info->number_edges=edge;
- qsort(polygon_info->edges,(size_t) polygon_info->number_edges,
- sizeof(*polygon_info->edges),DrawCompareEdges);
- if (IsEventLogging() != MagickFalse)
- LogPolygonInfo(polygon_info);
- return(polygon_info);
- }
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- + C o n v e r t P r i m i t i v e T o P a t h %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % ConvertPrimitiveToPath() converts a PrimitiveInfo structure into a vector
- % path structure.
- %
- % The format of the ConvertPrimitiveToPath method is:
- %
- % PathInfo *ConvertPrimitiveToPath(const DrawInfo *draw_info,
- % const PrimitiveInfo *primitive_info)
- %
- % A description of each parameter follows:
- %
- % o Method ConvertPrimitiveToPath returns a vector path structure of type
- % PathInfo.
- %
- % o draw_info: a structure of type DrawInfo.
- %
- % o primitive_info: Specifies a pointer to an PrimitiveInfo structure.
- %
- %
- */
- static void LogPathInfo(const PathInfo *path_info)
- {
- register const PathInfo
- *p;
- (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin vector-path");
- for (p=path_info; p->code != EndCode; p++)
- (void) LogMagickEvent(DrawEvent,GetMagickModule(),
- " %g,%g %s",p->point.x,p->point.y,p->code == GhostlineCode ?
- "moveto ghostline" : p->code == OpenCode ? "moveto open" :
- p->code == MoveToCode ? "moveto" : p->code == LineToCode ? "lineto" :
- "?");
- (void) LogMagickEvent(DrawEvent,GetMagickModule()," end vector-path");
- }
- static PathInfo *ConvertPrimitiveToPath(const PrimitiveInfo *primitive_info)
- {
- MagickBooleanType
- closed_subpath;
- PathInfo
- *path_info;
- PathInfoCode
- code;
- PointInfo
- p,
- q;
- register ssize_t
- i,
- n;
- ssize_t
- coordinates,
- start;
- /*
- Converts a PrimitiveInfo structure into a vector path structure.
- */
- switch (primitive_info->primitive)
- {
- case AlphaPrimitive:
- case ColorPrimitive:
- case ImagePrimitive:
- case PointPrimitive:
- case TextPrimitive:
- return((PathInfo *) NULL);
- default:
- break;
- }
- for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ;
- path_info=(PathInfo *) AcquireQuantumMemory((size_t) (3UL*i+1UL),
- sizeof(*path_info));
- if (path_info == (PathInfo *) NULL)
- return((PathInfo *) NULL);
- coordinates=0;
- closed_subpath=MagickFalse;
- n=0;
- p.x=(-1.0);
- p.y=(-1.0);
- q.x=(-1.0);
- q.y=(-1.0);
- start=0;
- for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++)
- {
- code=LineToCode;
- if (coordinates <= 0)
- {
- /*
- New subpath.
- */
- coordinates=(ssize_t) primitive_info[i].coordinates;
- p=primitive_info[i].point;
- start=n;
- code=MoveToCode;
- closed_subpath=primitive_info[i].closed_subpath;
- }
- coordinates--;
- if ((code == MoveToCode) || (coordinates <= 0) ||
- (fabs(q.x-primitive_info[i].point.x) >= MagickEpsilon) ||
- (fabs(q.y-primitive_info[i].point.y) >= MagickEpsilon))
- {
- /*
- Eliminate duplicate points.
- */
- path_info[n].code=code;
- path_info[n].point=primitive_info[i].point;
- q=primitive_info[i].point;
- n++;
- }
- if (coordinates > 0)
- continue; /* next point in current subpath */
- if (closed_subpath != MagickFalse)
- {
- closed_subpath=MagickFalse;
- continue;
- }
- /*
- Mark the p point as open if the subpath is not closed.
- */
- path_info[start].code=OpenCode;
- path_info[n].code=GhostlineCode;
- path_info[n].point=primitive_info[i].point;
- n++;
- path_info[n].code=LineToCode;
- path_info[n].point=p;
- n++;
- }
- path_info[n].code=EndCode;
- path_info[n].point.x=0.0;
- path_info[n].point.y=0.0;
- if (IsEventLogging() != MagickFalse)
- LogPathInfo(path_info);
- path_info=(PathInfo *) ResizeQuantumMemory(path_info,(size_t) (n+1),
- sizeof(*path_info));
- return(path_info);
- }
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % D e s t r o y D r a w I n f o %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % DestroyDrawInfo() deallocates memory associated with an DrawInfo structure.
- %
- % The format of the DestroyDrawInfo method is:
- %
- % DrawInfo *DestroyDrawInfo(DrawInfo *draw_info)
- %
- % A description of each parameter follows:
- %
- % o draw_info: the draw info.
- %
- */
- MagickExport DrawInfo *DestroyDrawInfo(DrawInfo *draw_info)
- {
- assert(draw_info != (DrawInfo *) NULL);
- if (draw_info->debug != MagickFalse)
- (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
- assert(draw_info->signature == MagickCoreSignature);
- if (draw_info->primitive != (char *) NULL)
- draw_info->primitive=DestroyString(draw_info->primitive);
- if (draw_info->text != (char *) NULL)
- draw_info->text=DestroyString(draw_info->text);
- if (draw_info->geometry != (char *) NULL)
- draw_info->geometry=DestroyString(draw_info->geometry);
- if (draw_info->fill_pattern != (Image *) NULL)
- draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
- if (draw_info->stroke_pattern != (Image *) NULL)
- draw_info->stroke_pattern=DestroyImage(draw_info->stroke_pattern);
- if (draw_info->font != (char *) NULL)
- draw_info->font=DestroyString(draw_info->font);
- if (draw_info->metrics != (char *) NULL)
- draw_info->metrics=DestroyString(draw_info->metrics);
- if (draw_info->family != (char *) NULL)
- draw_info->family=DestroyString(draw_info->family);
- if (draw_info->encoding != (char *) NULL)
- draw_info->encoding=DestroyString(draw_info->encoding);
- if (draw_info->density != (char *) NULL)
- draw_info->density=DestroyString(draw_info->density);
- if (draw_info->server_name != (char *) NULL)
- draw_info->server_name=(char *)
- RelinquishMagickMemory(draw_info->server_name);
- if (draw_info->dash_pattern != (double *) NULL)
- draw_info->dash_pattern=(double *) RelinquishMagickMemory(
- draw_info->dash_pattern);
- if (draw_info->gradient.stops != (StopInfo *) NULL)
- draw_info->gradient.stops=(StopInfo *) RelinquishMagickMemory(
- draw_info->gradient.stops);
- if (draw_info->clip_mask != (char *) NULL)
- draw_info->clip_mask=DestroyString(draw_info->clip_mask);
- if (draw_info->clipping_mask != (Image *) NULL)
- draw_info->clipping_mask=DestroyImage(draw_info->clipping_mask);
- if (draw_info->composite_mask != (Image *) NULL)
- draw_info->composite_mask=DestroyImage(draw_info->composite_mask);
- draw_info->signature=(~MagickCoreSignature);
- draw_info=(DrawInfo *) RelinquishMagickMemory(draw_info);
- return(draw_info);
- }
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- + D e s t r o y E d g e %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % DestroyEdge() destroys the specified polygon edge.
- %
- % The format of the DestroyEdge method is:
- %
- % ssize_t DestroyEdge(PolygonInfo *polygon_info,const int edge)
- %
- % A description of each parameter follows:
- %
- % o polygon_info: Specifies a pointer to an PolygonInfo structure.
- %
- % o edge: the polygon edge number to destroy.
- %
- */
- static size_t DestroyEdge(PolygonInfo *polygon_info,
- const size_t edge)
- {
- assert(edge < polygon_info->number_edges);
- polygon_info->edges[edge].points=(PointInfo *) RelinquishMagickMemory(
- polygon_info->edges[edge].points);
- polygon_info->number_edges--;
- if (edge < polygon_info->number_edges)
- (void) memmove(polygon_info->edges+edge,polygon_info->edges+edge+1,
- (size_t) (polygon_info->number_edges-edge)*sizeof(*polygon_info->edges));
- return(polygon_info->number_edges);
- }
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- + D e s t r o y P o l y g o n I n f o %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % DestroyPolygonInfo() destroys the PolygonInfo data structure.
- %
- % The format of the DestroyPolygonInfo method is:
- %
- % PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info)
- %
- % A description of each parameter follows:
- %
- % o polygon_info: Specifies a pointer to an PolygonInfo structure.
- %
- */
- static PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info)
- {
- register ssize_t
- i;
- for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
- polygon_info->edges[i].points=(PointInfo *)
- RelinquishMagickMemory(polygon_info->edges[i].points);
- polygon_info->edges=(EdgeInfo *) RelinquishMagickMemory(polygon_info->edges);
- return((PolygonInfo *) RelinquishMagickMemory(polygon_info));
- }
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % D r a w A f f i n e I m a g e %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % DrawAffineImage() composites the source over the destination image as
- % dictated by the affine transform.
- %
- % The format of the DrawAffineImage method is:
- %
- % MagickBooleanType DrawAffineImage(Image *image,const Image *source,
- % const AffineMatrix *affine,ExceptionInfo *exception)
- %
- % A description of each parameter follows:
- %
- % o image: the image.
- %
- % o source: the source image.
- %
- % o affine: the affine transform.
- %
- % o exception: return any errors or warnings in this structure.
- %
- */
- static SegmentInfo AffineEdge(const Image *image,const AffineMatrix *affine,
- const double y,const SegmentInfo *edge)
- {
- double
- intercept,
- z;
- register double
- x;
- SegmentInfo
- inverse_edge;
- /*
- Determine left and right edges.
- */
- inverse_edge.x1=edge->x1;
- inverse_edge.y1=edge->y1;
- inverse_edge.x2=edge->x2;
- inverse_edge.y2=edge->y2;
- z=affine->ry*y+affine->tx;
- if (affine->sx >= MagickEpsilon)
- {
- intercept=(-z/affine->sx);
- x=intercept;
- if (x > inverse_edge.x1)
- inverse_edge.x1=x;
- intercept=(-z+(double) image->columns)/affine->sx;
- x=intercept;
- if (x < inverse_edge.x2)
- inverse_edge.x2=x;
- }
- else
- if (affine->sx < -MagickEpsilon)
- {
- intercept=(-z+(double) image->columns)/affine->sx;
- x=intercept;
- if (x > inverse_edge.x1)
- inverse_edge.x1=x;
- intercept=(-z/affine->sx);
- x=intercept;
- if (x < inverse_edge.x2)
- inverse_edge.x2=x;
- }
- else
- if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->columns))
- {
- inverse_edge.x2=edge->x1;
- return(inverse_edge);
- }
- /*
- Determine top and bottom edges.
- */
- z=affine->sy*y+affine->ty;
- if (affine->rx >= MagickEpsilon)
- {
- intercept=(-z/affine->rx);
- x=intercept;
- if (x > inverse_edge.x1)
- inverse_edge.x1=x;
- intercept=(-z+(double) image->rows)/affine->rx;
- x=intercept;
- if (x < inverse_edge.x2)
- inverse_edge.x2=x;
- }
- else
- if (affine->rx < -MagickEpsilon)
- {
- intercept=(-z+(double) image->rows)/affine->rx;
- x=intercept;
- if (x > inverse_edge.x1)
- inverse_edge.x1=x;
- intercept=(-z/affine->rx);
- x=intercept;
- if (x < inverse_edge.x2)
- inverse_edge.x2=x;
- }
- else
- if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->rows))
- {
- inverse_edge.x2=edge->x2;
- return(inverse_edge);
- }
- return(inverse_edge);
- }
- static AffineMatrix InverseAffineMatrix(const AffineMatrix *affine)
- {
- AffineMatrix
- inverse_affine;
- double
- determinant;
- determinant=PerceptibleReciprocal(affine->sx*affine->sy-affine->rx*
- affine->ry);
- inverse_affine.sx=determinant*affine->sy;
- inverse_affine.rx=determinant*(-affine->rx);
- inverse_affine.ry=determinant*(-affine->ry);
- inverse_affine.sy=determinant*affine->sx;
- inverse_affine.tx=(-affine->tx)*inverse_affine.sx-affine->ty*
- inverse_affine.ry;
- inverse_affine.ty=(-affine->tx)*inverse_affine.rx-affine->ty*
- inverse_affine.sy;
- return(inverse_affine);
- }
- MagickExport MagickBooleanType DrawAffineImage(Image *image,
- const Image *source,const AffineMatrix *affine,ExceptionInfo *exception)
- {
- AffineMatrix
- inverse_affine;
- CacheView
- *image_view,
- *source_view;
- MagickBooleanType
- status;
- PixelInfo
- zero;
- PointInfo
- extent[4],
- min,
- max;
- register ssize_t
- i;
- SegmentInfo
- edge;
- ssize_t
- start,
- stop,
- y;
- /*
- Determine bounding box.
- */
- assert(image != (Image *) NULL);
- assert(image->signature == MagickCoreSignature);
- if (image->debug != MagickFalse)
- (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
- assert(source != (const Image *) NULL);
- assert(source->signature == MagickCoreSignature);
- assert(affine != (AffineMatrix *) NULL);
- extent[0].x=0.0;
- extent[0].y=0.0;
- extent[1].x=(double) source->columns-1.0;
- extent[1].y=0.0;
- extent[2].x=(double) source->columns-1.0;
- extent[2].y=(double) source->rows-1.0;
- extent[3].x=0.0;
- extent[3].y=(double) source->rows-1.0;
- for (i=0; i < 4; i++)
- {
- PointInfo
- point;
- point=extent[i];
- extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx;
- extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty;
- }
- min=extent[0];
- max=extent[0];
- for (i=1; i < 4; i++)
- {
- if (min.x > extent[i].x)
- min.x=extent[i].x;
- if (min.y > extent[i].y)
- min.y=extent[i].y;
- if (max.x < extent[i].x)
- max.x=extent[i].x;
- if (max.y < extent[i].y)
- max.y=extent[i].y;
- }
- /*
- Affine transform image.
- */
- if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
- return(MagickFalse);
- status=MagickTrue;
- edge.x1=MagickMax(min.x,0.0);
- edge.y1=MagickMax(min.y,0.0);
- edge.x2=MagickMin(max.x,(double) image->columns-1.0);
- edge.y2=MagickMin(max.y,(double) image->rows-1.0);
- inverse_affine=InverseAffineMatrix(affine);
- GetPixelInfo(image,&zero);
- start=(ssize_t) ceil(edge.y1-0.5);
- stop=(ssize_t) floor(edge.y2+0.5);
- source_view=AcquireVirtualCacheView(source,exception);
- image_view=AcquireAuthenticCacheView(image,exception);
- #if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(static) shared(status) \
- magick_number_threads(source,image,stop-start,1)
- #endif
- for (y=start; y <= stop; y++)
- {
- PixelInfo
- composite,
- pixel;
- PointInfo
- point;
- register ssize_t
- x;
- register Quantum
- *magick_restrict q;
- SegmentInfo
- inverse_edge;
- ssize_t
- x_offset;
- inverse_edge=AffineEdge(source,&inverse_affine,(double) y,&edge);
- if (inverse_edge.x2 < inverse_edge.x1)
- continue;
- q=GetCacheViewAuthenticPixels(image_view,(ssize_t) ceil(inverse_edge.x1-
- 0.5),y,(size_t) (floor(inverse_edge.x2+0.5)-ceil(inverse_edge.x1-0.5)+1),
- 1,exception);
- if (q == (Quantum *) NULL)
- continue;
- pixel=zero;
- composite=zero;
- x_offset=0;
- for (x=(ssize_t) ceil(inverse_edge.x1-0.5); x <= (ssize_t) floor(inverse_edge.x2+0.5); x++)
- {
- point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+
- inverse_affine.tx;
- point.y=(double) x*inverse_affine.rx+y*inverse_affine.sy+
- inverse_affine.ty;
- status=InterpolatePixelInfo(source,source_view,UndefinedInterpolatePixel,
- point.x,point.y,&pixel,exception);
- if (status == MagickFalse)
- break;
- GetPixelInfoPixel(image,q,&composite);
- CompositePixelInfoOver(&pixel,pixel.alpha,&composite,composite.alpha,
- &composite);
- SetPixelViaPixelInfo(image,&composite,q);
- x_offset++;
- q+=GetPixelChannels(image);
- }
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
- status=MagickFalse;
- }
- source_view=DestroyCacheView(source_view);
- image_view=DestroyCacheView(image_view);
- return(status);
- }
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- + D r a w B o u n d i n g R e c t a n g l e s %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % DrawBoundingRectangles() draws the bounding rectangles on the image. This
- % is only useful for developers debugging the rendering algorithm.
- %
- % The format of the DrawBoundingRectangles method is:
- %
- % MagickBooleanType DrawBoundingRectangles(Image *image,
- % const DrawInfo *draw_info,PolygonInfo *polygon_info,
- % ExceptionInfo *exception)
- %
- % A description of each parameter follows:
- %
- % o image: the image.
- %
- % o draw_info: the draw info.
- %
- % o polygon_info: Specifies a pointer to a PolygonInfo structure.
- %
- % o exception: return any errors or warnings in this structure.
- %
- */
- static inline double SaneStrokeWidth(const Image *image,
- const DrawInfo *draw_info)
- {
- return(MagickMin((double) draw_info->stroke_width,
- (2.0*sqrt(2.0)+MagickEpsilon)*MagickMax(image->columns,image->rows)));
- }
- static MagickBooleanType DrawBoundingRectangles(Image *image,
- const DrawInfo *draw_info,const PolygonInfo *polygon_info,
- ExceptionInfo *exception)
- {
- double
- mid;
- DrawInfo
- *clone_info;
- MagickStatusType
- status;
- PointInfo
- end,
- resolution,
- start;
- PrimitiveInfo
- primitive_info[6];
- register ssize_t
- i;
- SegmentInfo
- bounds;
- ssize_t
- coordinates;
- (void) memset(primitive_info,0,sizeof(primitive_info));
- clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info);
- status=QueryColorCompliance("#000F",AllCompliance,&clone_info->fill,
- exception);
- if (status == MagickFalse)
- {
- clone_info=DestroyDrawInfo(clone_info);
- return(MagickFalse);
- }
- resolution.x=96.0;
- resolution.y=96.0;
- if (clone_info->density != (char *) NULL)
- {
- GeometryInfo
- geometry_info;
- MagickStatusType
- flags;
- flags=ParseGeometry(clone_info->density,&geometry_info);
- resolution.x=geometry_info.rho;
- resolution.y=geometry_info.sigma;
- if ((flags & SigmaValue) == MagickFalse)
- resolution.y=resolution.x;
- }
- mid=(resolution.x/96.0)*ExpandAffine(&clone_info->affine)*
- SaneStrokeWidth(image,clone_info)/2.0;
- bounds.x1=0.0;
- bounds.y1=0.0;
- bounds.x2=0.0;
- bounds.y2=0.0;
- if (polygon_info != (PolygonInfo *) NULL)
- {
- bounds=polygon_info->edges[0].bounds;
- for (i=1; i < (ssize_t) polygon_info->number_edges; i++)
- {
- if (polygon_info->edges[i].bounds.x1 < (double) bounds.x1)
- bounds.x1=polygon_info->edges[i].bounds.x1;
- if (polygon_info->edges[i].bounds.y1 < (double) bounds.y1)
- bounds.y1=polygon_info->edges[i].bounds.y1;
- if (polygon_info->edges[i].bounds.x2 > (double) bounds.x2)
- bounds.x2=polygon_info->edges[i].bounds.x2;
- if (polygon_info->edges[i].bounds.y2 > (double) bounds.y2)
- bounds.y2=polygon_info->edges[i].bounds.y2;
- }
- bounds.x1-=mid;
- bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double)
- image->columns ? (double) image->columns-1 : bounds.x1;
- bounds.y1-=mid;
- bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double)
- image->rows ? (double) image->rows-1 : bounds.y1;
- bounds.x2+=mid;
- bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double)
- image->columns ? (double) image->columns-1 : bounds.x2;
- bounds.y2+=mid;
- bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double)
- image->rows ? (double) image->rows-1 : bounds.y2;
- for (i=0; i < (ssize_t) polygon_info->number_edges; i++)
- {
- if (polygon_info->edges[i].direction != 0)
- status=QueryColorCompliance("#f00",AllCompliance,&clone_info->stroke,
- exception);
- else
- status=QueryColorCompliance("#0f0",AllCompliance,&clone_info->stroke,
- exception);
- if (status == MagickFalse)
- break;
- start.x=(double) (polygon_info->edges[i].bounds.x1-mid);
- start.y=(double) (polygon_info->edges[i].bounds.y1-mid);
- end.x=(double) (polygon_info->edges[i].bounds.x2+mid);
- end.y=(double) (polygon_info->edges[i].bounds.y2+mid);
- primitive_info[0].primitive=RectanglePrimitive;
- status&=TraceRectangle(primitive_info,start,end);
- primitive_info[0].method=ReplaceMethod;
- coordinates=(ssize_t) primitive_info[0].coordinates;
- primitive_info[coordinates].primitive=UndefinedPrimitive;
- status=DrawPrimitive(image,clone_info,primitive_info,exception);
- if (status == MagickFalse)
- break;
- }
- if (i < (ssize_t) polygon_info->number_edges)
- {
- clone_info=DestroyDrawInfo(clone_info);
- return(status == 0 ? MagickFalse : MagickTrue);
- }
- }
- status=QueryColorCompliance("#00f",AllCompliance,&clone_info->stroke,
- exception);
- if (status == MagickFalse)
- {
- clone_info=DestroyDrawInfo(clone_info);
- return(MagickFalse);
- }
- start.x=(double) (bounds.x1-mid);
- start.y=(double) (bounds.y1-mid);
- end.x=(double) (bounds.x2+mid);
- end.y=(double) (bounds.y2+mid);
- primitive_info[0].primitive=RectanglePrimitive;
- status&=TraceRectangle(primitive_info,start,end);
- primitive_info[0].method=ReplaceMethod;
- coordinates=(ssize_t) primitive_info[0].coordinates;
- primitive_info[coordinates].primitive=UndefinedPrimitive;
- status=DrawPrimitive(image,clone_info,primitive_info,exception);
- clone_info=DestroyDrawInfo(clone_info);
- return(status == 0 ? MagickFalse : MagickTrue);
- }
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % D r a w C l i p P a t h %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % DrawClipPath() draws the clip path on the image mask.
- %
- % The format of the DrawClipPath method is:
- %
- % MagickBooleanType DrawClipPath(Image *image,const DrawInfo *draw_info,
- % const char *id,ExceptionInfo *exception)
- %
- % A description of each parameter follows:
- %
- % o image: the image.
- %
- % o draw_info: the draw info.
- %
- % o id: the clip path id.…
Large files files are truncated, but you can click here to view the full file