cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % DDDD RRRR AAA W W % |
| 7 | % D D R R A A W W % |
| 8 | % D D RRRR AAAAA W W W % |
| 9 | % D D R RN A A WW WW % |
| 10 | % DDDD R R A A W W % |
| 11 | % % |
| 12 | % % |
| 13 | % MagickCore Image Drawing Methods % |
| 14 | % % |
| 15 | % % |
| 16 | % Software Design % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 17 | % Cristy % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 18 | % July 1998 % |
| 19 | % % |
| 20 | % % |
Cristy | 7ce65e7 | 2015-12-12 18:03:16 -0500 | [diff] [blame] | 21 | % Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 22 | % dedicated to making software imaging solutions freely available. % |
| 23 | % % |
| 24 | % You may not use this file except in compliance with the License. You may % |
| 25 | % obtain a copy of the License at % |
| 26 | % % |
| 27 | % http://www.imagemagick.org/script/license.php % |
| 28 | % % |
| 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. % |
| 34 | % % |
| 35 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 36 | % |
| 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. |
| 42 | % |
| 43 | */ |
| 44 | |
| 45 | /* |
| 46 | Include declarations. |
| 47 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 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" |
Cristy | ba4ad2d | 2016-06-07 09:15:26 -0400 | [diff] [blame] | 53 | #include "MagickCore/cache-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 54 | #include "MagickCore/cache-view.h" |
cristy | 6a2180c | 2013-05-27 10:28:36 +0000 | [diff] [blame] | 55 | #include "MagickCore/channel.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 56 | #include "MagickCore/color.h" |
cristy | 9b7a4fc | 2012-04-08 22:26:56 +0000 | [diff] [blame] | 57 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 58 | #include "MagickCore/composite.h" |
| 59 | #include "MagickCore/composite-private.h" |
| 60 | #include "MagickCore/constitute.h" |
| 61 | #include "MagickCore/draw.h" |
| 62 | #include "MagickCore/draw-private.h" |
| 63 | #include "MagickCore/enhance.h" |
| 64 | #include "MagickCore/exception.h" |
| 65 | #include "MagickCore/exception-private.h" |
| 66 | #include "MagickCore/gem.h" |
| 67 | #include "MagickCore/geometry.h" |
| 68 | #include "MagickCore/image-private.h" |
| 69 | #include "MagickCore/list.h" |
| 70 | #include "MagickCore/log.h" |
| 71 | #include "MagickCore/monitor.h" |
| 72 | #include "MagickCore/monitor-private.h" |
| 73 | #include "MagickCore/option.h" |
| 74 | #include "MagickCore/paint.h" |
| 75 | #include "MagickCore/pixel-accessor.h" |
cristy | 35f1530 | 2012-06-07 14:59:02 +0000 | [diff] [blame] | 76 | #include "MagickCore/pixel-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 77 | #include "MagickCore/property.h" |
| 78 | #include "MagickCore/resample.h" |
| 79 | #include "MagickCore/resample-private.h" |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 80 | #include "MagickCore/resource_.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 81 | #include "MagickCore/string_.h" |
| 82 | #include "MagickCore/string-private.h" |
| 83 | #include "MagickCore/thread-private.h" |
| 84 | #include "MagickCore/token.h" |
dirk | 06f5901 | 2016-03-13 20:51:16 +0100 | [diff] [blame] | 85 | #include "MagickCore/transform-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 86 | #include "MagickCore/utility.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 87 | |
| 88 | /* |
| 89 | Define declarations. |
| 90 | */ |
| 91 | #define BezierQuantum 200 |
Cristy | cebc568 | 2016-06-24 15:24:30 -0400 | [diff] [blame] | 92 | #define DrawEpsilon (1.0e-10) |
Cristy | ade0d8e | 2016-06-10 08:40:09 -0400 | [diff] [blame] | 93 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | Typedef declarations. |
| 97 | */ |
| 98 | typedef struct _EdgeInfo |
| 99 | { |
| 100 | SegmentInfo |
| 101 | bounds; |
| 102 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 103 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 104 | scanline; |
| 105 | |
| 106 | PointInfo |
| 107 | *points; |
| 108 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 109 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 110 | number_points; |
| 111 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 112 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 113 | direction; |
| 114 | |
| 115 | MagickBooleanType |
| 116 | ghostline; |
| 117 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 118 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 119 | highwater; |
| 120 | } EdgeInfo; |
| 121 | |
| 122 | typedef struct _ElementInfo |
| 123 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 124 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 125 | cx, |
| 126 | cy, |
| 127 | major, |
| 128 | minor, |
| 129 | angle; |
| 130 | } ElementInfo; |
| 131 | |
| 132 | typedef struct _PolygonInfo |
| 133 | { |
| 134 | EdgeInfo |
| 135 | *edges; |
| 136 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 137 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 138 | number_edges; |
| 139 | } PolygonInfo; |
| 140 | |
| 141 | typedef enum |
| 142 | { |
| 143 | MoveToCode, |
| 144 | OpenCode, |
| 145 | GhostlineCode, |
| 146 | LineToCode, |
| 147 | EndCode |
| 148 | } PathInfoCode; |
| 149 | |
| 150 | typedef struct _PathInfo |
| 151 | { |
| 152 | PointInfo |
| 153 | point; |
| 154 | |
| 155 | PathInfoCode |
| 156 | code; |
| 157 | } PathInfo; |
| 158 | |
| 159 | /* |
| 160 | Forward declarations. |
| 161 | */ |
| 162 | static MagickBooleanType |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 163 | DrawStrokePolygon(Image *,const DrawInfo *,const PrimitiveInfo *, |
| 164 | ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 165 | |
| 166 | static PrimitiveInfo |
| 167 | *TraceStrokePolygon(const DrawInfo *,const PrimitiveInfo *); |
| 168 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 169 | static size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 170 | TracePath(PrimitiveInfo *,const char *); |
| 171 | |
| 172 | static void |
| 173 | TraceArc(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo), |
| 174 | TraceArcPath(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 175 | const double,const MagickBooleanType,const MagickBooleanType), |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 176 | TraceBezier(PrimitiveInfo *,const size_t), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 177 | TraceCircle(PrimitiveInfo *,const PointInfo,const PointInfo), |
cristy | e6bc777 | 2014-11-23 03:37:33 +0000 | [diff] [blame] | 178 | TraceEllipse(PrimitiveInfo *,const PointInfo,const PointInfo, |
| 179 | const PointInfo), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 180 | TraceLine(PrimitiveInfo *,const PointInfo,const PointInfo), |
| 181 | TraceRectangle(PrimitiveInfo *,const PointInfo,const PointInfo), |
| 182 | TraceRoundRectangle(PrimitiveInfo *,const PointInfo,const PointInfo, |
| 183 | PointInfo), |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 184 | TraceSquareLinecap(PrimitiveInfo *,const size_t,const double); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 185 | |
| 186 | /* |
| 187 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 188 | % % |
| 189 | % % |
| 190 | % % |
| 191 | % A c q u i r e D r a w I n f o % |
| 192 | % % |
| 193 | % % |
| 194 | % % |
| 195 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 196 | % |
| 197 | % AcquireDrawInfo() returns a DrawInfo structure properly initialized. |
| 198 | % |
| 199 | % The format of the AcquireDrawInfo method is: |
| 200 | % |
| 201 | % DrawInfo *AcquireDrawInfo(void) |
| 202 | % |
| 203 | */ |
| 204 | MagickExport DrawInfo *AcquireDrawInfo(void) |
| 205 | { |
| 206 | DrawInfo |
| 207 | *draw_info; |
| 208 | |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 209 | draw_info=(DrawInfo *) AcquireMagickMemory(sizeof(*draw_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 210 | if (draw_info == (DrawInfo *) NULL) |
| 211 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 212 | GetDrawInfo((ImageInfo *) NULL,draw_info); |
| 213 | return(draw_info); |
| 214 | } |
| 215 | |
| 216 | /* |
| 217 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 218 | % % |
| 219 | % % |
| 220 | % % |
| 221 | % C l o n e D r a w I n f o % |
| 222 | % % |
| 223 | % % |
| 224 | % % |
| 225 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 226 | % |
anthony | 36fe175 | 2011-09-29 11:28:37 +0000 | [diff] [blame] | 227 | % CloneDrawInfo() makes a copy of the given draw_info structure. If NULL |
cristy | 430522c | 2012-09-03 00:07:16 +0000 | [diff] [blame] | 228 | % is specified, a new DrawInfo structure is created initialized to default |
| 229 | % values. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 230 | % |
| 231 | % The format of the CloneDrawInfo method is: |
| 232 | % |
| 233 | % DrawInfo *CloneDrawInfo(const ImageInfo *image_info, |
| 234 | % const DrawInfo *draw_info) |
| 235 | % |
| 236 | % A description of each parameter follows: |
| 237 | % |
| 238 | % o image_info: the image info. |
| 239 | % |
| 240 | % o draw_info: the draw info. |
| 241 | % |
| 242 | */ |
| 243 | MagickExport DrawInfo *CloneDrawInfo(const ImageInfo *image_info, |
| 244 | const DrawInfo *draw_info) |
| 245 | { |
| 246 | DrawInfo |
| 247 | *clone_info; |
| 248 | |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 249 | ExceptionInfo |
| 250 | *exception; |
| 251 | |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 252 | clone_info=(DrawInfo *) AcquireMagickMemory(sizeof(*clone_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 253 | if (clone_info == (DrawInfo *) NULL) |
| 254 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 255 | GetDrawInfo(image_info,clone_info); |
| 256 | if (draw_info == (DrawInfo *) NULL) |
| 257 | return(clone_info); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 258 | exception=AcquireExceptionInfo(); |
cristy | c381376 | 2015-06-07 13:41:56 +0000 | [diff] [blame] | 259 | if (clone_info->primitive != (char *) NULL) |
| 260 | (void) CloneString(&clone_info->primitive,draw_info->primitive); |
| 261 | if (draw_info->geometry != (char *) NULL) |
| 262 | (void) CloneString(&clone_info->geometry,draw_info->geometry); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 263 | clone_info->viewbox=draw_info->viewbox; |
| 264 | clone_info->affine=draw_info->affine; |
| 265 | clone_info->gravity=draw_info->gravity; |
| 266 | clone_info->fill=draw_info->fill; |
| 267 | clone_info->stroke=draw_info->stroke; |
| 268 | clone_info->stroke_width=draw_info->stroke_width; |
| 269 | if (draw_info->fill_pattern != (Image *) NULL) |
| 270 | clone_info->fill_pattern=CloneImage(draw_info->fill_pattern,0,0,MagickTrue, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 271 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 272 | if (draw_info->stroke_pattern != (Image *) NULL) |
| 273 | clone_info->stroke_pattern=CloneImage(draw_info->stroke_pattern,0,0, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 274 | MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 275 | clone_info->stroke_antialias=draw_info->stroke_antialias; |
| 276 | clone_info->text_antialias=draw_info->text_antialias; |
| 277 | clone_info->fill_rule=draw_info->fill_rule; |
| 278 | clone_info->linecap=draw_info->linecap; |
| 279 | clone_info->linejoin=draw_info->linejoin; |
| 280 | clone_info->miterlimit=draw_info->miterlimit; |
| 281 | clone_info->dash_offset=draw_info->dash_offset; |
| 282 | clone_info->decorate=draw_info->decorate; |
| 283 | clone_info->compose=draw_info->compose; |
cristy | c381376 | 2015-06-07 13:41:56 +0000 | [diff] [blame] | 284 | if (draw_info->text != (char *) NULL) |
| 285 | (void) CloneString(&clone_info->text,draw_info->text); |
| 286 | if (draw_info->font != (char *) NULL) |
| 287 | (void) CloneString(&clone_info->font,draw_info->font); |
| 288 | if (draw_info->metrics != (char *) NULL) |
| 289 | (void) CloneString(&clone_info->metrics,draw_info->metrics); |
| 290 | if (draw_info->family != (char *) NULL) |
| 291 | (void) CloneString(&clone_info->family,draw_info->family); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 292 | clone_info->style=draw_info->style; |
| 293 | clone_info->stretch=draw_info->stretch; |
| 294 | clone_info->weight=draw_info->weight; |
cristy | c381376 | 2015-06-07 13:41:56 +0000 | [diff] [blame] | 295 | if (draw_info->encoding != (char *) NULL) |
| 296 | (void) CloneString(&clone_info->encoding,draw_info->encoding); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 297 | clone_info->pointsize=draw_info->pointsize; |
| 298 | clone_info->kerning=draw_info->kerning; |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 299 | clone_info->interline_spacing=draw_info->interline_spacing; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 300 | clone_info->interword_spacing=draw_info->interword_spacing; |
cristy | c9b1295 | 2010-03-28 01:12:28 +0000 | [diff] [blame] | 301 | clone_info->direction=draw_info->direction; |
cristy | c381376 | 2015-06-07 13:41:56 +0000 | [diff] [blame] | 302 | if (draw_info->density != (char *) NULL) |
| 303 | (void) CloneString(&clone_info->density,draw_info->density); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 304 | clone_info->align=draw_info->align; |
| 305 | clone_info->undercolor=draw_info->undercolor; |
| 306 | clone_info->border_color=draw_info->border_color; |
cristy | c381376 | 2015-06-07 13:41:56 +0000 | [diff] [blame] | 307 | if (draw_info->server_name != (char *) NULL) |
| 308 | (void) CloneString(&clone_info->server_name,draw_info->server_name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 309 | if (draw_info->dash_pattern != (double *) NULL) |
| 310 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 311 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 312 | x; |
| 313 | |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 314 | for (x=0; fabs(draw_info->dash_pattern[x]) >= DrawEpsilon; x++) ; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 315 | clone_info->dash_pattern=(double *) AcquireQuantumMemory((size_t) x+1UL, |
| 316 | sizeof(*clone_info->dash_pattern)); |
| 317 | if (clone_info->dash_pattern == (double *) NULL) |
| 318 | ThrowFatalException(ResourceLimitFatalError, |
| 319 | "UnableToAllocateDashPattern"); |
| 320 | (void) CopyMagickMemory(clone_info->dash_pattern,draw_info->dash_pattern, |
| 321 | (size_t) (x+1)*sizeof(*clone_info->dash_pattern)); |
| 322 | } |
| 323 | clone_info->gradient=draw_info->gradient; |
| 324 | if (draw_info->gradient.stops != (StopInfo *) NULL) |
| 325 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 326 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 327 | number_stops; |
| 328 | |
| 329 | number_stops=clone_info->gradient.number_stops; |
| 330 | clone_info->gradient.stops=(StopInfo *) AcquireQuantumMemory((size_t) |
| 331 | number_stops,sizeof(*clone_info->gradient.stops)); |
| 332 | if (clone_info->gradient.stops == (StopInfo *) NULL) |
| 333 | ThrowFatalException(ResourceLimitFatalError, |
| 334 | "UnableToAllocateDashPattern"); |
| 335 | (void) CopyMagickMemory(clone_info->gradient.stops, |
| 336 | draw_info->gradient.stops,(size_t) number_stops* |
| 337 | sizeof(*clone_info->gradient.stops)); |
| 338 | } |
cristy | c381376 | 2015-06-07 13:41:56 +0000 | [diff] [blame] | 339 | if (draw_info->clip_mask != (char *) NULL) |
| 340 | (void) CloneString(&clone_info->clip_mask,draw_info->clip_mask); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 341 | clone_info->bounds=draw_info->bounds; |
| 342 | clone_info->clip_units=draw_info->clip_units; |
| 343 | clone_info->render=draw_info->render; |
Cristy | 48bcfe0 | 2016-07-13 18:05:02 -0400 | [diff] [blame] | 344 | clone_info->fill_alpha=draw_info->fill_alpha; |
| 345 | clone_info->stroke_alpha=draw_info->stroke_alpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 346 | clone_info->element_reference=draw_info->element_reference; |
| 347 | clone_info->debug=IsEventLogging(); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 348 | exception=DestroyExceptionInfo(exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 349 | return(clone_info); |
| 350 | } |
| 351 | |
| 352 | /* |
| 353 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 354 | % % |
| 355 | % % |
| 356 | % % |
| 357 | + C o n v e r t P a t h T o P o l y g o n % |
| 358 | % % |
| 359 | % % |
| 360 | % % |
| 361 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 362 | % |
| 363 | % ConvertPathToPolygon() converts a path to the more efficient sorted |
| 364 | % rendering form. |
| 365 | % |
| 366 | % The format of the ConvertPathToPolygon method is: |
| 367 | % |
| 368 | % PolygonInfo *ConvertPathToPolygon(const DrawInfo *draw_info, |
| 369 | % const PathInfo *path_info) |
| 370 | % |
| 371 | % A description of each parameter follows: |
| 372 | % |
| 373 | % o Method ConvertPathToPolygon returns the path in a more efficient sorted |
| 374 | % rendering form of type PolygonInfo. |
| 375 | % |
| 376 | % o draw_info: Specifies a pointer to an DrawInfo structure. |
| 377 | % |
| 378 | % o path_info: Specifies a pointer to an PathInfo structure. |
| 379 | % |
| 380 | % |
| 381 | */ |
| 382 | |
| 383 | #if defined(__cplusplus) || defined(c_plusplus) |
| 384 | extern "C" { |
| 385 | #endif |
| 386 | |
| 387 | static int CompareEdges(const void *x,const void *y) |
| 388 | { |
| 389 | register const EdgeInfo |
| 390 | *p, |
| 391 | *q; |
| 392 | |
| 393 | /* |
| 394 | Compare two edges. |
| 395 | */ |
| 396 | p=(const EdgeInfo *) x; |
| 397 | q=(const EdgeInfo *) y; |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 398 | if ((p->points[0].y-DrawEpsilon) > q->points[0].y) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 399 | return(1); |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 400 | if ((p->points[0].y+DrawEpsilon) < q->points[0].y) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 401 | return(-1); |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 402 | if ((p->points[0].x-DrawEpsilon) > q->points[0].x) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 403 | return(1); |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 404 | if ((p->points[0].x+DrawEpsilon) < q->points[0].x) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 405 | return(-1); |
| 406 | if (((p->points[1].x-p->points[0].x)*(q->points[1].y-q->points[0].y)- |
| 407 | (p->points[1].y-p->points[0].y)*(q->points[1].x-q->points[0].x)) > 0.0) |
| 408 | return(1); |
| 409 | return(-1); |
| 410 | } |
| 411 | |
| 412 | #if defined(__cplusplus) || defined(c_plusplus) |
| 413 | } |
| 414 | #endif |
| 415 | |
| 416 | static void LogPolygonInfo(const PolygonInfo *polygon_info) |
| 417 | { |
| 418 | register EdgeInfo |
| 419 | *p; |
| 420 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 421 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 422 | i, |
| 423 | j; |
| 424 | |
| 425 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin active-edge"); |
| 426 | p=polygon_info->edges; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 427 | for (i=0; i < (ssize_t) polygon_info->number_edges; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 428 | { |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 429 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," edge %.20g:", |
| 430 | (double) i); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 431 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," direction: %s", |
| 432 | p->direction != MagickFalse ? "down" : "up"); |
| 433 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," ghostline: %s", |
| 434 | p->ghostline != MagickFalse ? "transparent" : "opaque"); |
| 435 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 436 | " bounds: %g,%g - %g,%g",p->bounds.x1,p->bounds.y1, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 437 | p->bounds.x2,p->bounds.y2); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 438 | for (j=0; j < (ssize_t) p->number_points; j++) |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 439 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," %g,%g", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 440 | p->points[j].x,p->points[j].y); |
| 441 | p++; |
| 442 | } |
| 443 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end active-edge"); |
| 444 | } |
| 445 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 446 | static void ReversePoints(PointInfo *points,const size_t number_points) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 447 | { |
| 448 | PointInfo |
| 449 | point; |
| 450 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 451 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 452 | i; |
| 453 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 454 | for (i=0; i < (ssize_t) (number_points >> 1); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 455 | { |
| 456 | point=points[i]; |
| 457 | points[i]=points[number_points-(i+1)]; |
| 458 | points[number_points-(i+1)]=point; |
| 459 | } |
| 460 | } |
| 461 | |
dirk | d2a7a2d | 2016-03-17 23:07:42 +0100 | [diff] [blame] | 462 | static PolygonInfo *ConvertPathToPolygon(const PathInfo *path_info) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 463 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 464 | long |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 465 | direction, |
| 466 | next_direction; |
| 467 | |
| 468 | PointInfo |
| 469 | point, |
| 470 | *points; |
| 471 | |
| 472 | PolygonInfo |
| 473 | *polygon_info; |
| 474 | |
| 475 | SegmentInfo |
| 476 | bounds; |
| 477 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 478 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 479 | i, |
| 480 | n; |
| 481 | |
| 482 | MagickBooleanType |
| 483 | ghostline; |
| 484 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 485 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 486 | edge, |
| 487 | number_edges, |
| 488 | number_points; |
| 489 | |
| 490 | /* |
| 491 | Convert a path to the more efficient sorted rendering form. |
| 492 | */ |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 493 | polygon_info=(PolygonInfo *) AcquireMagickMemory(sizeof(*polygon_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 494 | if (polygon_info == (PolygonInfo *) NULL) |
| 495 | return((PolygonInfo *) NULL); |
| 496 | number_edges=16; |
Cristy | 49201ac | 2016-05-18 07:17:34 -0400 | [diff] [blame] | 497 | polygon_info->edges=(EdgeInfo *) AcquireQuantumMemory(number_edges, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 498 | sizeof(*polygon_info->edges)); |
| 499 | if (polygon_info->edges == (EdgeInfo *) NULL) |
| 500 | return((PolygonInfo *) NULL); |
Cristy | 49201ac | 2016-05-18 07:17:34 -0400 | [diff] [blame] | 501 | (void) ResetMagickMemory(polygon_info->edges,0,number_edges* |
| 502 | sizeof(*polygon_info->edges)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 503 | direction=0; |
| 504 | edge=0; |
| 505 | ghostline=MagickFalse; |
| 506 | n=0; |
| 507 | number_points=0; |
| 508 | points=(PointInfo *) NULL; |
| 509 | (void) ResetMagickMemory(&point,0,sizeof(point)); |
| 510 | (void) ResetMagickMemory(&bounds,0,sizeof(bounds)); |
| 511 | for (i=0; path_info[i].code != EndCode; i++) |
| 512 | { |
| 513 | if ((path_info[i].code == MoveToCode) || (path_info[i].code == OpenCode) || |
| 514 | (path_info[i].code == GhostlineCode)) |
| 515 | { |
| 516 | /* |
| 517 | Move to. |
| 518 | */ |
| 519 | if ((points != (PointInfo *) NULL) && (n >= 2)) |
| 520 | { |
| 521 | if (edge == number_edges) |
| 522 | { |
| 523 | number_edges<<=1; |
| 524 | polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory( |
| 525 | polygon_info->edges,(size_t) number_edges, |
| 526 | sizeof(*polygon_info->edges)); |
| 527 | if (polygon_info->edges == (EdgeInfo *) NULL) |
| 528 | return((PolygonInfo *) NULL); |
| 529 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 530 | polygon_info->edges[edge].number_points=(size_t) n; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 531 | polygon_info->edges[edge].scanline=(-1.0); |
| 532 | polygon_info->edges[edge].highwater=0; |
| 533 | polygon_info->edges[edge].ghostline=ghostline; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 534 | polygon_info->edges[edge].direction=(ssize_t) (direction > 0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 535 | if (direction < 0) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 536 | ReversePoints(points,(size_t) n); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 537 | polygon_info->edges[edge].points=points; |
| 538 | polygon_info->edges[edge].bounds=bounds; |
| 539 | polygon_info->edges[edge].bounds.y1=points[0].y; |
| 540 | polygon_info->edges[edge].bounds.y2=points[n-1].y; |
| 541 | points=(PointInfo *) NULL; |
| 542 | ghostline=MagickFalse; |
| 543 | edge++; |
| 544 | } |
| 545 | if (points == (PointInfo *) NULL) |
| 546 | { |
| 547 | number_points=16; |
| 548 | points=(PointInfo *) AcquireQuantumMemory((size_t) number_points, |
| 549 | sizeof(*points)); |
| 550 | if (points == (PointInfo *) NULL) |
| 551 | return((PolygonInfo *) NULL); |
| 552 | } |
| 553 | ghostline=path_info[i].code == GhostlineCode ? MagickTrue : MagickFalse; |
| 554 | point=path_info[i].point; |
| 555 | points[0]=point; |
| 556 | bounds.x1=point.x; |
| 557 | bounds.x2=point.x; |
| 558 | direction=0; |
| 559 | n=1; |
| 560 | continue; |
| 561 | } |
| 562 | /* |
| 563 | Line to. |
| 564 | */ |
| 565 | next_direction=((path_info[i].point.y > point.y) || |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 566 | ((fabs(path_info[i].point.y-point.y) < DrawEpsilon) && |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 567 | (path_info[i].point.x > point.x))) ? 1 : -1; |
cristy | 15cace9 | 2014-01-14 16:37:23 +0000 | [diff] [blame] | 568 | if ((points != (PointInfo *) NULL) && (direction != 0) && |
| 569 | (direction != next_direction)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 570 | { |
| 571 | /* |
| 572 | New edge. |
| 573 | */ |
| 574 | point=points[n-1]; |
| 575 | if (edge == number_edges) |
| 576 | { |
| 577 | number_edges<<=1; |
| 578 | polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory( |
| 579 | polygon_info->edges,(size_t) number_edges, |
| 580 | sizeof(*polygon_info->edges)); |
| 581 | if (polygon_info->edges == (EdgeInfo *) NULL) |
| 582 | return((PolygonInfo *) NULL); |
| 583 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 584 | polygon_info->edges[edge].number_points=(size_t) n; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 585 | polygon_info->edges[edge].scanline=(-1.0); |
| 586 | polygon_info->edges[edge].highwater=0; |
| 587 | polygon_info->edges[edge].ghostline=ghostline; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 588 | polygon_info->edges[edge].direction=(ssize_t) (direction > 0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 589 | if (direction < 0) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 590 | ReversePoints(points,(size_t) n); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 591 | polygon_info->edges[edge].points=points; |
| 592 | polygon_info->edges[edge].bounds=bounds; |
| 593 | polygon_info->edges[edge].bounds.y1=points[0].y; |
| 594 | polygon_info->edges[edge].bounds.y2=points[n-1].y; |
| 595 | number_points=16; |
| 596 | points=(PointInfo *) AcquireQuantumMemory((size_t) number_points, |
| 597 | sizeof(*points)); |
| 598 | if (points == (PointInfo *) NULL) |
| 599 | return((PolygonInfo *) NULL); |
| 600 | n=1; |
| 601 | ghostline=MagickFalse; |
| 602 | points[0]=point; |
| 603 | bounds.x1=point.x; |
| 604 | bounds.x2=point.x; |
| 605 | edge++; |
| 606 | } |
| 607 | direction=next_direction; |
| 608 | if (points == (PointInfo *) NULL) |
| 609 | continue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 610 | if (n == (ssize_t) number_points) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 611 | { |
| 612 | number_points<<=1; |
| 613 | points=(PointInfo *) ResizeQuantumMemory(points,(size_t) number_points, |
| 614 | sizeof(*points)); |
| 615 | if (points == (PointInfo *) NULL) |
| 616 | return((PolygonInfo *) NULL); |
| 617 | } |
| 618 | point=path_info[i].point; |
| 619 | points[n]=point; |
| 620 | if (point.x < bounds.x1) |
| 621 | bounds.x1=point.x; |
| 622 | if (point.x > bounds.x2) |
| 623 | bounds.x2=point.x; |
| 624 | n++; |
| 625 | } |
| 626 | if (points != (PointInfo *) NULL) |
| 627 | { |
| 628 | if (n < 2) |
| 629 | points=(PointInfo *) RelinquishMagickMemory(points); |
| 630 | else |
| 631 | { |
| 632 | if (edge == number_edges) |
| 633 | { |
| 634 | number_edges<<=1; |
| 635 | polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory( |
| 636 | polygon_info->edges,(size_t) number_edges, |
| 637 | sizeof(*polygon_info->edges)); |
| 638 | if (polygon_info->edges == (EdgeInfo *) NULL) |
| 639 | return((PolygonInfo *) NULL); |
| 640 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 641 | polygon_info->edges[edge].number_points=(size_t) n; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 642 | polygon_info->edges[edge].scanline=(-1.0); |
| 643 | polygon_info->edges[edge].highwater=0; |
| 644 | polygon_info->edges[edge].ghostline=ghostline; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 645 | polygon_info->edges[edge].direction=(ssize_t) (direction > 0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 646 | if (direction < 0) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 647 | ReversePoints(points,(size_t) n); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 648 | polygon_info->edges[edge].points=points; |
| 649 | polygon_info->edges[edge].bounds=bounds; |
| 650 | polygon_info->edges[edge].bounds.y1=points[0].y; |
| 651 | polygon_info->edges[edge].bounds.y2=points[n-1].y; |
| 652 | ghostline=MagickFalse; |
| 653 | edge++; |
| 654 | } |
| 655 | } |
| 656 | polygon_info->number_edges=edge; |
| 657 | qsort(polygon_info->edges,(size_t) polygon_info->number_edges, |
| 658 | sizeof(*polygon_info->edges),CompareEdges); |
| 659 | if (IsEventLogging() != MagickFalse) |
| 660 | LogPolygonInfo(polygon_info); |
| 661 | return(polygon_info); |
| 662 | } |
| 663 | |
| 664 | /* |
| 665 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 666 | % % |
| 667 | % % |
| 668 | % % |
| 669 | + C o n v e r t P r i m i t i v e T o P a t h % |
| 670 | % % |
| 671 | % % |
| 672 | % % |
| 673 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 674 | % |
| 675 | % ConvertPrimitiveToPath() converts a PrimitiveInfo structure into a vector |
| 676 | % path structure. |
| 677 | % |
| 678 | % The format of the ConvertPrimitiveToPath method is: |
| 679 | % |
| 680 | % PathInfo *ConvertPrimitiveToPath(const DrawInfo *draw_info, |
| 681 | % const PrimitiveInfo *primitive_info) |
| 682 | % |
| 683 | % A description of each parameter follows: |
| 684 | % |
| 685 | % o Method ConvertPrimitiveToPath returns a vector path structure of type |
| 686 | % PathInfo. |
| 687 | % |
| 688 | % o draw_info: a structure of type DrawInfo. |
| 689 | % |
| 690 | % o primitive_info: Specifies a pointer to an PrimitiveInfo structure. |
| 691 | % |
| 692 | % |
| 693 | */ |
| 694 | |
| 695 | static void LogPathInfo(const PathInfo *path_info) |
| 696 | { |
| 697 | register const PathInfo |
| 698 | *p; |
| 699 | |
| 700 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin vector-path"); |
| 701 | for (p=path_info; p->code != EndCode; p++) |
| 702 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 703 | " %g,%g %s",p->point.x,p->point.y,p->code == GhostlineCode ? |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 704 | "moveto ghostline" : p->code == OpenCode ? "moveto open" : |
| 705 | p->code == MoveToCode ? "moveto" : p->code == LineToCode ? "lineto" : |
| 706 | "?"); |
| 707 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end vector-path"); |
| 708 | } |
| 709 | |
dirk | d2a7a2d | 2016-03-17 23:07:42 +0100 | [diff] [blame] | 710 | static PathInfo *ConvertPrimitiveToPath(const PrimitiveInfo *primitive_info) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 711 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 712 | PathInfo |
| 713 | *path_info; |
| 714 | |
| 715 | PathInfoCode |
| 716 | code; |
| 717 | |
| 718 | PointInfo |
| 719 | p, |
| 720 | q; |
| 721 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 722 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 723 | i, |
| 724 | n; |
| 725 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 726 | ssize_t |
| 727 | coordinates, |
| 728 | start; |
| 729 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 730 | /* |
| 731 | Converts a PrimitiveInfo structure into a vector path structure. |
| 732 | */ |
| 733 | switch (primitive_info->primitive) |
| 734 | { |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 735 | case AlphaPrimitive: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 736 | case ColorPrimitive: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 737 | case ImagePrimitive: |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 738 | case PointPrimitive: |
| 739 | case TextPrimitive: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 740 | return((PathInfo *) NULL); |
| 741 | default: |
| 742 | break; |
| 743 | } |
| 744 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ; |
| 745 | path_info=(PathInfo *) AcquireQuantumMemory((size_t) (2UL*i+3UL), |
| 746 | sizeof(*path_info)); |
| 747 | if (path_info == (PathInfo *) NULL) |
| 748 | return((PathInfo *) NULL); |
| 749 | coordinates=0; |
| 750 | n=0; |
| 751 | p.x=(-1.0); |
| 752 | p.y=(-1.0); |
| 753 | q.x=(-1.0); |
| 754 | q.y=(-1.0); |
| 755 | start=0; |
| 756 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) |
| 757 | { |
| 758 | code=LineToCode; |
| 759 | if (coordinates <= 0) |
| 760 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 761 | coordinates=(ssize_t) primitive_info[i].coordinates; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 762 | p=primitive_info[i].point; |
| 763 | start=n; |
| 764 | code=MoveToCode; |
| 765 | } |
| 766 | coordinates--; |
| 767 | /* |
| 768 | Eliminate duplicate points. |
| 769 | */ |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 770 | if ((i == 0) || (fabs(q.x-primitive_info[i].point.x) >= DrawEpsilon) || |
| 771 | (fabs(q.y-primitive_info[i].point.y) >= DrawEpsilon)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 772 | { |
| 773 | path_info[n].code=code; |
| 774 | path_info[n].point=primitive_info[i].point; |
| 775 | q=primitive_info[i].point; |
| 776 | n++; |
| 777 | } |
| 778 | if (coordinates > 0) |
| 779 | continue; |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 780 | if ((fabs(p.x-primitive_info[i].point.x) < DrawEpsilon) && |
| 781 | (fabs(p.y-primitive_info[i].point.y) < DrawEpsilon)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 782 | continue; |
| 783 | /* |
| 784 | Mark the p point as open if it does not match the q. |
| 785 | */ |
| 786 | path_info[start].code=OpenCode; |
| 787 | path_info[n].code=GhostlineCode; |
| 788 | path_info[n].point=primitive_info[i].point; |
| 789 | n++; |
| 790 | path_info[n].code=LineToCode; |
| 791 | path_info[n].point=p; |
| 792 | n++; |
| 793 | } |
| 794 | path_info[n].code=EndCode; |
| 795 | path_info[n].point.x=0.0; |
| 796 | path_info[n].point.y=0.0; |
| 797 | if (IsEventLogging() != MagickFalse) |
| 798 | LogPathInfo(path_info); |
| 799 | return(path_info); |
| 800 | } |
| 801 | |
| 802 | /* |
| 803 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 804 | % % |
| 805 | % % |
| 806 | % % |
| 807 | % D e s t r o y D r a w I n f o % |
| 808 | % % |
| 809 | % % |
| 810 | % % |
| 811 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 812 | % |
| 813 | % DestroyDrawInfo() deallocates memory associated with an DrawInfo |
| 814 | % structure. |
| 815 | % |
| 816 | % The format of the DestroyDrawInfo method is: |
| 817 | % |
| 818 | % DrawInfo *DestroyDrawInfo(DrawInfo *draw_info) |
| 819 | % |
| 820 | % A description of each parameter follows: |
| 821 | % |
| 822 | % o draw_info: the draw info. |
| 823 | % |
| 824 | */ |
| 825 | MagickExport DrawInfo *DestroyDrawInfo(DrawInfo *draw_info) |
| 826 | { |
| 827 | if (draw_info->debug != MagickFalse) |
| 828 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 829 | assert(draw_info != (DrawInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 830 | assert(draw_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 831 | if (draw_info->primitive != (char *) NULL) |
| 832 | draw_info->primitive=DestroyString(draw_info->primitive); |
| 833 | if (draw_info->text != (char *) NULL) |
| 834 | draw_info->text=DestroyString(draw_info->text); |
| 835 | if (draw_info->geometry != (char *) NULL) |
| 836 | draw_info->geometry=DestroyString(draw_info->geometry); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 837 | if (draw_info->fill_pattern != (Image *) NULL) |
| 838 | draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern); |
| 839 | if (draw_info->stroke_pattern != (Image *) NULL) |
| 840 | draw_info->stroke_pattern=DestroyImage(draw_info->stroke_pattern); |
| 841 | if (draw_info->font != (char *) NULL) |
| 842 | draw_info->font=DestroyString(draw_info->font); |
| 843 | if (draw_info->metrics != (char *) NULL) |
| 844 | draw_info->metrics=DestroyString(draw_info->metrics); |
| 845 | if (draw_info->family != (char *) NULL) |
| 846 | draw_info->family=DestroyString(draw_info->family); |
| 847 | if (draw_info->encoding != (char *) NULL) |
| 848 | draw_info->encoding=DestroyString(draw_info->encoding); |
| 849 | if (draw_info->density != (char *) NULL) |
| 850 | draw_info->density=DestroyString(draw_info->density); |
| 851 | if (draw_info->server_name != (char *) NULL) |
| 852 | draw_info->server_name=(char *) |
| 853 | RelinquishMagickMemory(draw_info->server_name); |
| 854 | if (draw_info->dash_pattern != (double *) NULL) |
| 855 | draw_info->dash_pattern=(double *) RelinquishMagickMemory( |
| 856 | draw_info->dash_pattern); |
| 857 | if (draw_info->gradient.stops != (StopInfo *) NULL) |
| 858 | draw_info->gradient.stops=(StopInfo *) RelinquishMagickMemory( |
| 859 | draw_info->gradient.stops); |
| 860 | if (draw_info->clip_mask != (char *) NULL) |
| 861 | draw_info->clip_mask=DestroyString(draw_info->clip_mask); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 862 | draw_info->signature=(~MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 863 | draw_info=(DrawInfo *) RelinquishMagickMemory(draw_info); |
| 864 | return(draw_info); |
| 865 | } |
| 866 | |
| 867 | /* |
| 868 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 869 | % % |
| 870 | % % |
| 871 | % % |
| 872 | + D e s t r o y E d g e % |
| 873 | % % |
| 874 | % % |
| 875 | % % |
| 876 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 877 | % |
| 878 | % DestroyEdge() destroys the specified polygon edge. |
| 879 | % |
| 880 | % The format of the DestroyEdge method is: |
| 881 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 882 | % ssize_t DestroyEdge(PolygonInfo *polygon_info,const int edge) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 883 | % |
| 884 | % A description of each parameter follows: |
| 885 | % |
| 886 | % o polygon_info: Specifies a pointer to an PolygonInfo structure. |
| 887 | % |
| 888 | % o edge: the polygon edge number to destroy. |
| 889 | % |
| 890 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 891 | static size_t DestroyEdge(PolygonInfo *polygon_info, |
| 892 | const size_t edge) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 893 | { |
| 894 | assert(edge < polygon_info->number_edges); |
| 895 | polygon_info->edges[edge].points=(PointInfo *) RelinquishMagickMemory( |
| 896 | polygon_info->edges[edge].points); |
| 897 | polygon_info->number_edges--; |
| 898 | if (edge < polygon_info->number_edges) |
| 899 | (void) CopyMagickMemory(polygon_info->edges+edge,polygon_info->edges+edge+1, |
| 900 | (size_t) (polygon_info->number_edges-edge)*sizeof(*polygon_info->edges)); |
| 901 | return(polygon_info->number_edges); |
| 902 | } |
| 903 | |
| 904 | /* |
| 905 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 906 | % % |
| 907 | % % |
| 908 | % % |
| 909 | + D e s t r o y P o l y g o n I n f o % |
| 910 | % % |
| 911 | % % |
| 912 | % % |
| 913 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 914 | % |
| 915 | % DestroyPolygonInfo() destroys the PolygonInfo data structure. |
| 916 | % |
| 917 | % The format of the DestroyPolygonInfo method is: |
| 918 | % |
| 919 | % PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info) |
| 920 | % |
| 921 | % A description of each parameter follows: |
| 922 | % |
| 923 | % o polygon_info: Specifies a pointer to an PolygonInfo structure. |
| 924 | % |
| 925 | */ |
| 926 | static PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info) |
| 927 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 928 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 929 | i; |
| 930 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 931 | for (i=0; i < (ssize_t) polygon_info->number_edges; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 932 | polygon_info->edges[i].points=(PointInfo *) |
| 933 | RelinquishMagickMemory(polygon_info->edges[i].points); |
| 934 | polygon_info->edges=(EdgeInfo *) RelinquishMagickMemory(polygon_info->edges); |
| 935 | return((PolygonInfo *) RelinquishMagickMemory(polygon_info)); |
| 936 | } |
| 937 | |
| 938 | /* |
| 939 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 940 | % % |
| 941 | % % |
| 942 | % % |
| 943 | % D r a w A f f i n e I m a g e % |
| 944 | % % |
| 945 | % % |
| 946 | % % |
| 947 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 948 | % |
| 949 | % DrawAffineImage() composites the source over the destination image as |
| 950 | % dictated by the affine transform. |
| 951 | % |
| 952 | % The format of the DrawAffineImage method is: |
| 953 | % |
| 954 | % MagickBooleanType DrawAffineImage(Image *image,const Image *source, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 955 | % const AffineMatrix *affine,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 956 | % |
| 957 | % A description of each parameter follows: |
| 958 | % |
| 959 | % o image: the image. |
| 960 | % |
| 961 | % o source: the source image. |
| 962 | % |
| 963 | % o affine: the affine transform. |
| 964 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 965 | % o exception: return any errors or warnings in this structure. |
| 966 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 967 | */ |
cristy | efa9e8a | 2011-11-07 01:56:51 +0000 | [diff] [blame] | 968 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 969 | static SegmentInfo AffineEdge(const Image *image,const AffineMatrix *affine, |
| 970 | const double y,const SegmentInfo *edge) |
| 971 | { |
| 972 | double |
| 973 | intercept, |
| 974 | z; |
| 975 | |
| 976 | register double |
| 977 | x; |
| 978 | |
| 979 | SegmentInfo |
| 980 | inverse_edge; |
| 981 | |
| 982 | /* |
| 983 | Determine left and right edges. |
| 984 | */ |
| 985 | inverse_edge.x1=edge->x1; |
| 986 | inverse_edge.y1=edge->y1; |
| 987 | inverse_edge.x2=edge->x2; |
| 988 | inverse_edge.y2=edge->y2; |
| 989 | z=affine->ry*y+affine->tx; |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 990 | if (affine->sx >= DrawEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 991 | { |
| 992 | intercept=(-z/affine->sx); |
cristy | efa9e8a | 2011-11-07 01:56:51 +0000 | [diff] [blame] | 993 | x=intercept; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 994 | if (x > inverse_edge.x1) |
| 995 | inverse_edge.x1=x; |
| 996 | intercept=(-z+(double) image->columns)/affine->sx; |
cristy | efa9e8a | 2011-11-07 01:56:51 +0000 | [diff] [blame] | 997 | x=intercept; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 998 | if (x < inverse_edge.x2) |
| 999 | inverse_edge.x2=x; |
| 1000 | } |
| 1001 | else |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 1002 | if (affine->sx < -DrawEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1003 | { |
| 1004 | intercept=(-z+(double) image->columns)/affine->sx; |
cristy | efa9e8a | 2011-11-07 01:56:51 +0000 | [diff] [blame] | 1005 | x=intercept; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1006 | if (x > inverse_edge.x1) |
| 1007 | inverse_edge.x1=x; |
| 1008 | intercept=(-z/affine->sx); |
cristy | efa9e8a | 2011-11-07 01:56:51 +0000 | [diff] [blame] | 1009 | x=intercept; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1010 | if (x < inverse_edge.x2) |
| 1011 | inverse_edge.x2=x; |
| 1012 | } |
| 1013 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1014 | if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->columns)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1015 | { |
| 1016 | inverse_edge.x2=edge->x1; |
| 1017 | return(inverse_edge); |
| 1018 | } |
| 1019 | /* |
| 1020 | Determine top and bottom edges. |
| 1021 | */ |
| 1022 | z=affine->sy*y+affine->ty; |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 1023 | if (affine->rx >= DrawEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1024 | { |
| 1025 | intercept=(-z/affine->rx); |
cristy | efa9e8a | 2011-11-07 01:56:51 +0000 | [diff] [blame] | 1026 | x=intercept; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1027 | if (x > inverse_edge.x1) |
| 1028 | inverse_edge.x1=x; |
| 1029 | intercept=(-z+(double) image->rows)/affine->rx; |
cristy | efa9e8a | 2011-11-07 01:56:51 +0000 | [diff] [blame] | 1030 | x=intercept; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1031 | if (x < inverse_edge.x2) |
| 1032 | inverse_edge.x2=x; |
| 1033 | } |
| 1034 | else |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 1035 | if (affine->rx < -DrawEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1036 | { |
| 1037 | intercept=(-z+(double) image->rows)/affine->rx; |
cristy | efa9e8a | 2011-11-07 01:56:51 +0000 | [diff] [blame] | 1038 | x=intercept; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1039 | if (x > inverse_edge.x1) |
| 1040 | inverse_edge.x1=x; |
| 1041 | intercept=(-z/affine->rx); |
cristy | efa9e8a | 2011-11-07 01:56:51 +0000 | [diff] [blame] | 1042 | x=intercept; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1043 | if (x < inverse_edge.x2) |
| 1044 | inverse_edge.x2=x; |
| 1045 | } |
| 1046 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1047 | if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1048 | { |
| 1049 | inverse_edge.x2=edge->x2; |
| 1050 | return(inverse_edge); |
| 1051 | } |
| 1052 | return(inverse_edge); |
| 1053 | } |
| 1054 | |
| 1055 | static AffineMatrix InverseAffineMatrix(const AffineMatrix *affine) |
| 1056 | { |
| 1057 | AffineMatrix |
| 1058 | inverse_affine; |
| 1059 | |
| 1060 | double |
| 1061 | determinant; |
| 1062 | |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 1063 | determinant=PerceptibleReciprocal(affine->sx*affine->sy-affine->rx* |
cristy | 35f1530 | 2012-06-07 14:59:02 +0000 | [diff] [blame] | 1064 | affine->ry); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1065 | inverse_affine.sx=determinant*affine->sy; |
| 1066 | inverse_affine.rx=determinant*(-affine->rx); |
| 1067 | inverse_affine.ry=determinant*(-affine->ry); |
| 1068 | inverse_affine.sy=determinant*affine->sx; |
| 1069 | inverse_affine.tx=(-affine->tx)*inverse_affine.sx-affine->ty* |
| 1070 | inverse_affine.ry; |
| 1071 | inverse_affine.ty=(-affine->tx)*inverse_affine.rx-affine->ty* |
| 1072 | inverse_affine.sy; |
| 1073 | return(inverse_affine); |
| 1074 | } |
| 1075 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1076 | MagickExport MagickBooleanType DrawAffineImage(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1077 | const Image *source,const AffineMatrix *affine,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1078 | { |
| 1079 | AffineMatrix |
| 1080 | inverse_affine; |
| 1081 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 1082 | CacheView |
| 1083 | *image_view, |
| 1084 | *source_view; |
| 1085 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1086 | MagickBooleanType |
| 1087 | status; |
| 1088 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1089 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1090 | zero; |
| 1091 | |
| 1092 | PointInfo |
| 1093 | extent[4], |
| 1094 | min, |
dirk | c93932a | 2015-10-01 16:56:10 +0200 | [diff] [blame] | 1095 | max; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1096 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1097 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1098 | i; |
| 1099 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1100 | SegmentInfo |
| 1101 | edge; |
| 1102 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1103 | ssize_t |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 1104 | start, |
| 1105 | stop, |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1106 | y; |
| 1107 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1108 | /* |
| 1109 | Determine bounding box. |
| 1110 | */ |
| 1111 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1112 | assert(image->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1113 | if (image->debug != MagickFalse) |
| 1114 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1115 | assert(source != (const Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1116 | assert(source->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1117 | assert(affine != (AffineMatrix *) NULL); |
| 1118 | extent[0].x=0.0; |
| 1119 | extent[0].y=0.0; |
| 1120 | extent[1].x=(double) source->columns-1.0; |
| 1121 | extent[1].y=0.0; |
| 1122 | extent[2].x=(double) source->columns-1.0; |
| 1123 | extent[2].y=(double) source->rows-1.0; |
| 1124 | extent[3].x=0.0; |
| 1125 | extent[3].y=(double) source->rows-1.0; |
| 1126 | for (i=0; i < 4; i++) |
| 1127 | { |
dirk | c93932a | 2015-10-01 16:56:10 +0200 | [diff] [blame] | 1128 | PointInfo |
| 1129 | point; |
| 1130 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1131 | point=extent[i]; |
| 1132 | extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx; |
| 1133 | extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty; |
| 1134 | } |
| 1135 | min=extent[0]; |
| 1136 | max=extent[0]; |
| 1137 | for (i=1; i < 4; i++) |
| 1138 | { |
| 1139 | if (min.x > extent[i].x) |
| 1140 | min.x=extent[i].x; |
| 1141 | if (min.y > extent[i].y) |
| 1142 | min.y=extent[i].y; |
| 1143 | if (max.x < extent[i].x) |
| 1144 | max.x=extent[i].x; |
| 1145 | if (max.y < extent[i].y) |
| 1146 | max.y=extent[i].y; |
| 1147 | } |
| 1148 | /* |
| 1149 | Affine transform image. |
| 1150 | */ |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 1151 | if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1152 | return(MagickFalse); |
| 1153 | status=MagickTrue; |
| 1154 | edge.x1=MagickMax(min.x,0.0); |
| 1155 | edge.y1=MagickMax(min.y,0.0); |
| 1156 | edge.x2=MagickMin(max.x,(double) image->columns-1.0); |
| 1157 | edge.y2=MagickMin(max.y,(double) image->rows-1.0); |
| 1158 | inverse_affine=InverseAffineMatrix(affine); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1159 | GetPixelInfo(image,&zero); |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 1160 | start=(ssize_t) ceil(edge.y1-0.5); |
cristy | 8071c47 | 2012-09-24 12:41:06 +0000 | [diff] [blame] | 1161 | stop=(ssize_t) floor(edge.y2+0.5); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 1162 | source_view=AcquireVirtualCacheView(source,exception); |
| 1163 | image_view=AcquireAuthenticCacheView(image,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 1164 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 9a5a52f | 2012-10-09 14:40:31 +0000 | [diff] [blame] | 1165 | #pragma omp parallel for schedule(static,4) shared(status) \ |
cristy | cb7dfcc | 2013-01-06 18:34:59 +0000 | [diff] [blame] | 1166 | magick_threads(source,image,1,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1167 | #endif |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 1168 | for (y=start; y <= stop; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1169 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1170 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1171 | composite, |
| 1172 | pixel; |
| 1173 | |
| 1174 | PointInfo |
| 1175 | point; |
| 1176 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1177 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1178 | x; |
| 1179 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1180 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 1181 | *magick_restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1182 | |
| 1183 | SegmentInfo |
| 1184 | inverse_edge; |
| 1185 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1186 | ssize_t |
| 1187 | x_offset; |
| 1188 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1189 | inverse_edge=AffineEdge(source,&inverse_affine,(double) y,&edge); |
| 1190 | if (inverse_edge.x2 < inverse_edge.x1) |
| 1191 | continue; |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1192 | q=GetCacheViewAuthenticPixels(image_view,(ssize_t) ceil(inverse_edge.x1- |
cristy | 592aefd | 2013-02-03 15:41:39 +0000 | [diff] [blame] | 1193 | 0.5),y,(size_t) (floor(inverse_edge.x2+0.5)-ceil(inverse_edge.x1-0.5)+1), |
| 1194 | 1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1195 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1196 | continue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1197 | pixel=zero; |
| 1198 | composite=zero; |
| 1199 | x_offset=0; |
cristy | 8071c47 | 2012-09-24 12:41:06 +0000 | [diff] [blame] | 1200 | for (x=(ssize_t) ceil(inverse_edge.x1-0.5); x <= (ssize_t) floor(inverse_edge.x2+0.5); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1201 | { |
| 1202 | point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+ |
| 1203 | inverse_affine.tx; |
| 1204 | point.y=(double) x*inverse_affine.rx+y*inverse_affine.sy+ |
| 1205 | inverse_affine.ty; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1206 | (void) InterpolatePixelInfo(source,source_view,UndefinedInterpolatePixel, |
| 1207 | point.x,point.y,&pixel,exception); |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 1208 | GetPixelInfoPixel(image,q,&composite); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1209 | CompositePixelInfoOver(&pixel,pixel.alpha,&composite,composite.alpha, |
| 1210 | &composite); |
cristy | 11a06d3 | 2015-01-04 12:03:27 +0000 | [diff] [blame] | 1211 | SetPixelViaPixelInfo(image,&composite,q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1212 | x_offset++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1213 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1214 | } |
| 1215 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 1216 | status=MagickFalse; |
| 1217 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1218 | source_view=DestroyCacheView(source_view); |
| 1219 | image_view=DestroyCacheView(image_view); |
| 1220 | return(status); |
| 1221 | } |
| 1222 | |
| 1223 | /* |
| 1224 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1225 | % % |
| 1226 | % % |
| 1227 | % % |
| 1228 | + D r a w B o u n d i n g R e c t a n g l e s % |
| 1229 | % % |
| 1230 | % % |
| 1231 | % % |
| 1232 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1233 | % |
| 1234 | % DrawBoundingRectangles() draws the bounding rectangles on the image. This |
| 1235 | % is only useful for developers debugging the rendering algorithm. |
| 1236 | % |
| 1237 | % The format of the DrawBoundingRectangles method is: |
| 1238 | % |
| 1239 | % void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1240 | % PolygonInfo *polygon_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1241 | % |
| 1242 | % A description of each parameter follows: |
| 1243 | % |
| 1244 | % o image: the image. |
| 1245 | % |
| 1246 | % o draw_info: the draw info. |
| 1247 | % |
| 1248 | % o polygon_info: Specifies a pointer to a PolygonInfo structure. |
| 1249 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1250 | % o exception: return any errors or warnings in this structure. |
| 1251 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1252 | */ |
| 1253 | static void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1254 | const PolygonInfo *polygon_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1255 | { |
| 1256 | DrawInfo |
| 1257 | *clone_info; |
| 1258 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1259 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1260 | mid; |
| 1261 | |
| 1262 | PointInfo |
| 1263 | end, |
| 1264 | resolution, |
| 1265 | start; |
| 1266 | |
| 1267 | PrimitiveInfo |
| 1268 | primitive_info[6]; |
| 1269 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1270 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1271 | i; |
| 1272 | |
| 1273 | SegmentInfo |
| 1274 | bounds; |
| 1275 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1276 | ssize_t |
| 1277 | coordinates; |
| 1278 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1279 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
Cristy | dd6065a | 2016-09-19 15:55:49 -0400 | [diff] [blame] | 1280 | (void) QueryColorCompliance("#000F",AllCompliance,&clone_info->fill, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1281 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1282 | resolution.x=DefaultResolution; |
| 1283 | resolution.y=DefaultResolution; |
| 1284 | if (clone_info->density != (char *) NULL) |
| 1285 | { |
| 1286 | GeometryInfo |
| 1287 | geometry_info; |
| 1288 | |
| 1289 | MagickStatusType |
| 1290 | flags; |
| 1291 | |
| 1292 | flags=ParseGeometry(clone_info->density,&geometry_info); |
| 1293 | resolution.x=geometry_info.rho; |
| 1294 | resolution.y=geometry_info.sigma; |
| 1295 | if ((flags & SigmaValue) == MagickFalse) |
| 1296 | resolution.y=resolution.x; |
| 1297 | } |
| 1298 | mid=(resolution.x/72.0)*ExpandAffine(&clone_info->affine)* |
| 1299 | clone_info->stroke_width/2.0; |
| 1300 | bounds.x1=0.0; |
| 1301 | bounds.y1=0.0; |
| 1302 | bounds.x2=0.0; |
| 1303 | bounds.y2=0.0; |
| 1304 | if (polygon_info != (PolygonInfo *) NULL) |
| 1305 | { |
| 1306 | bounds=polygon_info->edges[0].bounds; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1307 | for (i=1; i < (ssize_t) polygon_info->number_edges; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1308 | { |
| 1309 | if (polygon_info->edges[i].bounds.x1 < (double) bounds.x1) |
| 1310 | bounds.x1=polygon_info->edges[i].bounds.x1; |
| 1311 | if (polygon_info->edges[i].bounds.y1 < (double) bounds.y1) |
| 1312 | bounds.y1=polygon_info->edges[i].bounds.y1; |
| 1313 | if (polygon_info->edges[i].bounds.x2 > (double) bounds.x2) |
| 1314 | bounds.x2=polygon_info->edges[i].bounds.x2; |
| 1315 | if (polygon_info->edges[i].bounds.y2 > (double) bounds.y2) |
| 1316 | bounds.y2=polygon_info->edges[i].bounds.y2; |
| 1317 | } |
| 1318 | bounds.x1-=mid; |
| 1319 | bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double) |
cristy | 6c5494a | 2012-09-22 00:30:37 +0000 | [diff] [blame] | 1320 | image->columns ? (double) image->columns-1 : bounds.x1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1321 | bounds.y1-=mid; |
| 1322 | bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double) |
cristy | 6c5494a | 2012-09-22 00:30:37 +0000 | [diff] [blame] | 1323 | image->rows ? (double) image->rows-1 : bounds.y1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1324 | bounds.x2+=mid; |
| 1325 | bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double) |
cristy | 6c5494a | 2012-09-22 00:30:37 +0000 | [diff] [blame] | 1326 | image->columns ? (double) image->columns-1 : bounds.x2; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1327 | bounds.y2+=mid; |
| 1328 | bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double) |
cristy | 6c5494a | 2012-09-22 00:30:37 +0000 | [diff] [blame] | 1329 | image->rows ? (double) image->rows-1 : bounds.y2; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1330 | for (i=0; i < (ssize_t) polygon_info->number_edges; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1331 | { |
| 1332 | if (polygon_info->edges[i].direction != 0) |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1333 | (void) QueryColorCompliance("red",AllCompliance,&clone_info->stroke, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1334 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1335 | else |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1336 | (void) QueryColorCompliance("green",AllCompliance,&clone_info->stroke, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1337 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1338 | start.x=(double) (polygon_info->edges[i].bounds.x1-mid); |
| 1339 | start.y=(double) (polygon_info->edges[i].bounds.y1-mid); |
| 1340 | end.x=(double) (polygon_info->edges[i].bounds.x2+mid); |
| 1341 | end.y=(double) (polygon_info->edges[i].bounds.y2+mid); |
| 1342 | primitive_info[0].primitive=RectanglePrimitive; |
| 1343 | TraceRectangle(primitive_info,start,end); |
| 1344 | primitive_info[0].method=ReplaceMethod; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1345 | coordinates=(ssize_t) primitive_info[0].coordinates; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1346 | primitive_info[coordinates].primitive=UndefinedPrimitive; |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1347 | (void) DrawPrimitive(image,clone_info,primitive_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1348 | } |
| 1349 | } |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1350 | (void) QueryColorCompliance("blue",AllCompliance,&clone_info->stroke, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1351 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1352 | start.x=(double) (bounds.x1-mid); |
| 1353 | start.y=(double) (bounds.y1-mid); |
| 1354 | end.x=(double) (bounds.x2+mid); |
| 1355 | end.y=(double) (bounds.y2+mid); |
| 1356 | primitive_info[0].primitive=RectanglePrimitive; |
| 1357 | TraceRectangle(primitive_info,start,end); |
| 1358 | primitive_info[0].method=ReplaceMethod; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1359 | coordinates=(ssize_t) primitive_info[0].coordinates; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1360 | primitive_info[coordinates].primitive=UndefinedPrimitive; |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1361 | (void) DrawPrimitive(image,clone_info,primitive_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1362 | clone_info=DestroyDrawInfo(clone_info); |
| 1363 | } |
| 1364 | |
| 1365 | /* |
| 1366 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1367 | % % |
| 1368 | % % |
| 1369 | % % |
| 1370 | % D r a w C l i p P a t h % |
| 1371 | % % |
| 1372 | % % |
| 1373 | % % |
| 1374 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1375 | % |
| 1376 | % DrawClipPath() draws the clip path on the image mask. |
| 1377 | % |
| 1378 | % The format of the DrawClipPath method is: |
| 1379 | % |
| 1380 | % MagickBooleanType DrawClipPath(Image *image,const DrawInfo *draw_info, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1381 | % const char *name,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1382 | % |
| 1383 | % A description of each parameter follows: |
| 1384 | % |
| 1385 | % o image: the image. |
| 1386 | % |
| 1387 | % o draw_info: the draw info. |
| 1388 | % |
| 1389 | % o name: the name of the clip path. |
| 1390 | % |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1391 | % o exception: return any errors or warnings in this structure. |
| 1392 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1393 | */ |
| 1394 | MagickExport MagickBooleanType DrawClipPath(Image *image, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1395 | const DrawInfo *draw_info,const char *name,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1396 | { |
| 1397 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1398 | filename[MagickPathExtent]; |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1399 | |
| 1400 | Image |
| 1401 | *clip_mask; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1402 | |
| 1403 | const char |
| 1404 | *value; |
| 1405 | |
| 1406 | DrawInfo |
| 1407 | *clone_info; |
| 1408 | |
| 1409 | MagickStatusType |
| 1410 | status; |
| 1411 | |
| 1412 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1413 | assert(image->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1414 | if (image->debug != MagickFalse) |
| 1415 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1416 | assert(draw_info != (const DrawInfo *) NULL); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1417 | (void) FormatLocaleString(filename,MagickPathExtent,"%s",name); |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1418 | value=GetImageArtifact(image,filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1419 | if (value == (const char *) NULL) |
| 1420 | return(MagickFalse); |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1421 | clip_mask=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
| 1422 | if (clip_mask == (Image *) NULL) |
| 1423 | return(MagickFalse); |
Cristy | 76eb72f | 2016-11-27 08:21:05 -0500 | [diff] [blame^] | 1424 | (void) QueryColorCompliance("#0000",AllCompliance, |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1425 | &clip_mask->background_color,exception); |
Cristy | 726812f | 2016-05-04 19:09:35 -0400 | [diff] [blame] | 1426 | clip_mask->background_color.alpha=(MagickRealType) TransparentAlpha; |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1427 | (void) SetImageBackgroundColor(clip_mask,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1428 | if (image->debug != MagickFalse) |
| 1429 | (void) LogMagickEvent(DrawEvent,GetMagickModule(),"\nbegin clip-path %s", |
| 1430 | draw_info->clip_mask); |
| 1431 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 1432 | (void) CloneString(&clone_info->primitive,value); |
Cristy | 76eb72f | 2016-11-27 08:21:05 -0500 | [diff] [blame^] | 1433 | (void) QueryColorCompliance("#ffffff",AllCompliance,&clone_info->fill, |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 1434 | exception); |
Cristy | 76eb72f | 2016-11-27 08:21:05 -0500 | [diff] [blame^] | 1435 | clone_info->clip_mask=(char *) NULL; |
| 1436 | status=NegateImage(clip_mask,MagickFalse,exception); |
cristy | acd0d4c | 2015-07-25 16:12:33 +0000 | [diff] [blame] | 1437 | (void) SetImageMask(image,ReadPixelMask,clip_mask,exception); |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1438 | clip_mask=DestroyImage(clip_mask); |
Cristy | 76eb72f | 2016-11-27 08:21:05 -0500 | [diff] [blame^] | 1439 | status&=DrawImage(image,clone_info,exception); |
cristy | 8e50818 | 2012-09-22 00:21:17 +0000 | [diff] [blame] | 1440 | clone_info=DestroyDrawInfo(clone_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1441 | if (image->debug != MagickFalse) |
| 1442 | (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end clip-path"); |
| 1443 | return(status != 0 ? MagickTrue : MagickFalse); |
| 1444 | } |
| 1445 | |
| 1446 | /* |
| 1447 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1448 | % % |
| 1449 | % % |
| 1450 | % % |
| 1451 | + D r a w D a s h P o l y g o n % |
| 1452 | % % |
| 1453 | % % |
| 1454 | % % |
| 1455 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1456 | % |
| 1457 | % DrawDashPolygon() draws a dashed polygon (line, rectangle, ellipse) on the |
| 1458 | % image while respecting the dash offset and dash pattern attributes. |
| 1459 | % |
| 1460 | % The format of the DrawDashPolygon method is: |
| 1461 | % |
| 1462 | % MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1463 | % const PrimitiveInfo *primitive_info,Image *image, |
| 1464 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1465 | % |
| 1466 | % A description of each parameter follows: |
| 1467 | % |
| 1468 | % o draw_info: the draw info. |
| 1469 | % |
| 1470 | % o primitive_info: Specifies a pointer to a PrimitiveInfo structure. |
| 1471 | % |
| 1472 | % o image: the image. |
| 1473 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1474 | % o exception: return any errors or warnings in this structure. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1475 | % |
| 1476 | */ |
| 1477 | static MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1478 | const PrimitiveInfo *primitive_info,Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1479 | { |
| 1480 | DrawInfo |
| 1481 | *clone_info; |
| 1482 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1483 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1484 | length, |
| 1485 | maximum_length, |
| 1486 | offset, |
| 1487 | scale, |
| 1488 | total_length; |
| 1489 | |
| 1490 | MagickStatusType |
| 1491 | status; |
| 1492 | |
| 1493 | PrimitiveInfo |
| 1494 | *dash_polygon; |
| 1495 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1496 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1497 | i; |
| 1498 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1499 | register double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1500 | dx, |
| 1501 | dy; |
| 1502 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1503 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1504 | number_vertices; |
| 1505 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1506 | ssize_t |
| 1507 | j, |
| 1508 | n; |
| 1509 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1510 | assert(draw_info != (const DrawInfo *) NULL); |
| 1511 | if (image->debug != MagickFalse) |
| 1512 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-dash"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1513 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1514 | number_vertices=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1515 | dash_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t) |
| 1516 | (2UL*number_vertices+1UL),sizeof(*dash_polygon)); |
| 1517 | if (dash_polygon == (PrimitiveInfo *) NULL) |
| 1518 | return(MagickFalse); |
Cristy | 9cdadd9 | 2016-05-03 18:17:01 -0400 | [diff] [blame] | 1519 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 1520 | clone_info->miterlimit=0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1521 | dash_polygon[0]=primitive_info[0]; |
| 1522 | scale=ExpandAffine(&draw_info->affine); |
| 1523 | length=scale*(draw_info->dash_pattern[0]-0.5); |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 1524 | offset=fabs(draw_info->dash_offset) >= DrawEpsilon ? |
Cristy | fc7b06d | 2016-06-24 10:17:46 -0400 | [diff] [blame] | 1525 | scale*draw_info->dash_offset : 0.0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1526 | j=1; |
| 1527 | for (n=0; offset > 0.0; j=0) |
| 1528 | { |
| 1529 | if (draw_info->dash_pattern[n] <= 0.0) |
| 1530 | break; |
| 1531 | length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5)); |
| 1532 | if (offset > length) |
| 1533 | { |
| 1534 | offset-=length; |
| 1535 | n++; |
cristy | 4d0ca34 | 2014-05-01 00:42:09 +0000 | [diff] [blame] | 1536 | length=scale*(draw_info->dash_pattern[n]+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1537 | continue; |
| 1538 | } |
| 1539 | if (offset < length) |
| 1540 | { |
| 1541 | length-=offset; |
| 1542 | offset=0.0; |
| 1543 | break; |
| 1544 | } |
| 1545 | offset=0.0; |
| 1546 | n++; |
| 1547 | } |
| 1548 | status=MagickTrue; |
| 1549 | maximum_length=0.0; |
| 1550 | total_length=0.0; |
Cristy | 726812f | 2016-05-04 19:09:35 -0400 | [diff] [blame] | 1551 | for (i=1; (i < (ssize_t) number_vertices) && (length >= 0.0); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1552 | { |
| 1553 | dx=primitive_info[i].point.x-primitive_info[i-1].point.x; |
| 1554 | dy=primitive_info[i].point.y-primitive_info[i-1].point.y; |
| 1555 | maximum_length=hypot((double) dx,dy); |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 1556 | if (fabs(length) < DrawEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1557 | { |
| 1558 | n++; |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 1559 | if (fabs(draw_info->dash_pattern[n]) < DrawEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1560 | n=0; |
| 1561 | length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5)); |
| 1562 | } |
Cristy | 9cdadd9 | 2016-05-03 18:17:01 -0400 | [diff] [blame] | 1563 | for (total_length=0.0; (length >= 0.0) && (maximum_length >= (total_length+length)); ) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1564 | { |
| 1565 | total_length+=length; |
| 1566 | if ((n & 0x01) != 0) |
| 1567 | { |
| 1568 | dash_polygon[0]=primitive_info[0]; |
| 1569 | dash_polygon[0].point.x=(double) (primitive_info[i-1].point.x+dx* |
| 1570 | total_length/maximum_length); |
| 1571 | dash_polygon[0].point.y=(double) (primitive_info[i-1].point.y+dy* |
| 1572 | total_length/maximum_length); |
| 1573 | j=1; |
| 1574 | } |
| 1575 | else |
| 1576 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1577 | if ((j+1) > (ssize_t) (2*number_vertices)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1578 | break; |
| 1579 | dash_polygon[j]=primitive_info[i-1]; |
| 1580 | dash_polygon[j].point.x=(double) (primitive_info[i-1].point.x+dx* |
| 1581 | total_length/maximum_length); |
| 1582 | dash_polygon[j].point.y=(double) (primitive_info[i-1].point.y+dy* |
| 1583 | total_length/maximum_length); |
| 1584 | dash_polygon[j].coordinates=1; |
| 1585 | j++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1586 | dash_polygon[0].coordinates=(size_t) j; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1587 | dash_polygon[j].primitive=UndefinedPrimitive; |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 1588 | status&=DrawStrokePolygon(image,clone_info,dash_polygon,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1589 | } |
| 1590 | n++; |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 1591 | if (fabs(draw_info->dash_pattern[n]) < DrawEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1592 | n=0; |
| 1593 | length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5)); |
| 1594 | } |
| 1595 | length-=(maximum_length-total_length); |
| 1596 | if ((n & 0x01) != 0) |
| 1597 | continue; |
| 1598 | dash_polygon[j]=primitive_info[i]; |
| 1599 | dash_polygon[j].coordinates=1; |
| 1600 | j++; |
| 1601 | } |
cristy | cbda611 | 2012-05-27 20:57:16 +0000 | [diff] [blame] | 1602 | if ((total_length <= maximum_length) && ((n & 0x01) == 0) && (j > 1)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1603 | { |
| 1604 | dash_polygon[j]=primitive_info[i-1]; |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 1605 | dash_polygon[j].point.x+=DrawEpsilon; |
| 1606 | dash_polygon[j].point.y+=DrawEpsilon; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1607 | dash_polygon[j].coordinates=1; |
| 1608 | j++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1609 | dash_polygon[0].coordinates=(size_t) j; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1610 | dash_polygon[j].primitive=UndefinedPrimitive; |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 1611 | status&=DrawStrokePolygon(image,clone_info,dash_polygon,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1612 | } |
| 1613 | dash_polygon=(PrimitiveInfo *) RelinquishMagickMemory(dash_polygon); |
| 1614 | clone_info=DestroyDrawInfo(clone_info); |
| 1615 | if (image->debug != MagickFalse) |
| 1616 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-dash"); |
| 1617 | return(status != 0 ? MagickTrue : MagickFalse); |
| 1618 | } |
| 1619 | |
| 1620 | /* |
| 1621 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1622 | % % |
| 1623 | % % |
| 1624 | % % |
| 1625 | % D r a w I m a g e % |
| 1626 | % % |
| 1627 | % % |
| 1628 | % % |
| 1629 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1630 | % |
| 1631 | % DrawImage() draws a graphic primitive on your image. The primitive |
| 1632 | % may be represented as a string or filename. Precede the filename with an |
| 1633 | % "at" sign (@) and the contents of the file are drawn on the image. You |
| 1634 | % can affect how text is drawn by setting one or more members of the draw |
| 1635 | % info structure. |
| 1636 | % |
| 1637 | % The format of the DrawImage method is: |
| 1638 | % |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1639 | % MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info, |
| 1640 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1641 | % |
| 1642 | % A description of each parameter follows: |
| 1643 | % |
| 1644 | % o image: the image. |
| 1645 | % |
| 1646 | % o draw_info: the draw info. |
| 1647 | % |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1648 | % o exception: return any errors or warnings in this structure. |
| 1649 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1650 | */ |
| 1651 | |
| 1652 | static inline MagickBooleanType IsPoint(const char *point) |
| 1653 | { |
| 1654 | char |
| 1655 | *p; |
| 1656 | |
| 1657 | double |
| 1658 | value; |
| 1659 | |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1660 | value=StringToDouble(point,&p); |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 1661 | return((fabs(value) < DrawEpsilon) && (p == point) ? MagickFalse : MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1662 | } |
| 1663 | |
| 1664 | static inline void TracePoint(PrimitiveInfo *primitive_info, |
| 1665 | const PointInfo point) |
| 1666 | { |
| 1667 | primitive_info->coordinates=1; |
| 1668 | primitive_info->point=point; |
| 1669 | } |
| 1670 | |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1671 | MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info, |
| 1672 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1673 | { |
| 1674 | #define RenderImageTag "Render/Image" |
| 1675 | |
| 1676 | AffineMatrix |
| 1677 | affine, |
| 1678 | current; |
| 1679 | |
| 1680 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1681 | keyword[MagickPathExtent], |
| 1682 | geometry[MagickPathExtent], |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 1683 | *next_token, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1684 | pattern[MagickPathExtent], |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1685 | *primitive, |
| 1686 | *token; |
| 1687 | |
| 1688 | const char |
| 1689 | *q; |
| 1690 | |
Cristy | dd6065a | 2016-09-19 15:55:49 -0400 | [diff] [blame] | 1691 | double |
| 1692 | angle, |
| 1693 | factor, |
| 1694 | primitive_extent; |
| 1695 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1696 | DrawInfo |
| 1697 | **graphic_context; |
| 1698 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1699 | MagickBooleanType |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 1700 | proceed; |
| 1701 | |
Cristy | 58affb9 | 2016-06-01 10:08:14 -0400 | [diff] [blame] | 1702 | MagickSizeType |
| 1703 | length, |
| 1704 | number_points; |
| 1705 | |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 1706 | MagickStatusType |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1707 | status; |
| 1708 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1709 | PointInfo |
| 1710 | point; |
| 1711 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1712 | PrimitiveInfo |
| 1713 | *primitive_info; |
| 1714 | |
| 1715 | PrimitiveType |
| 1716 | primitive_type; |
| 1717 | |
| 1718 | register const char |
| 1719 | *p; |
| 1720 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1721 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1722 | i, |
| 1723 | x; |
| 1724 | |
| 1725 | SegmentInfo |
| 1726 | bounds; |
| 1727 | |
| 1728 | size_t |
dirk | fc0f124 | 2016-03-26 00:36:39 +0100 | [diff] [blame] | 1729 | extent, |
dirk | b6f578b | 2015-07-12 17:56:39 +0000 | [diff] [blame] | 1730 | number_stops; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1731 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1732 | ssize_t |
| 1733 | j, |
| 1734 | k, |
| 1735 | n; |
| 1736 | |
dirk | b6f578b | 2015-07-12 17:56:39 +0000 | [diff] [blame] | 1737 | StopInfo |
| 1738 | *stops; |
| 1739 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1740 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1741 | assert(image->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1742 | if (image->debug != MagickFalse) |
| 1743 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1744 | assert(draw_info != (DrawInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1745 | assert(draw_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1746 | if (image->debug != MagickFalse) |
| 1747 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 1748 | if ((draw_info->primitive == (char *) NULL) || |
| 1749 | (*draw_info->primitive == '\0')) |
| 1750 | return(MagickFalse); |
| 1751 | if (image->debug != MagickFalse) |
| 1752 | (void) LogMagickEvent(DrawEvent,GetMagickModule(),"begin draw-image"); |
| 1753 | if (*draw_info->primitive != '@') |
| 1754 | primitive=AcquireString(draw_info->primitive); |
| 1755 | else |
cristy | 3a5987c | 2013-11-07 14:18:46 +0000 | [diff] [blame] | 1756 | primitive=FileToString(draw_info->primitive+1,~0UL,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1757 | if (primitive == (char *) NULL) |
| 1758 | return(MagickFalse); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1759 | primitive_extent=(double) strlen(primitive); |
Cristy | ddb2a06 | 2016-10-02 11:07:10 -0400 | [diff] [blame] | 1760 | (void) SetImageArtifact(image,"MVG",primitive); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1761 | n=0; |
dirk | b6f578b | 2015-07-12 17:56:39 +0000 | [diff] [blame] | 1762 | number_stops=0; |
| 1763 | stops=(StopInfo *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1764 | /* |
| 1765 | Allocate primitive info memory. |
| 1766 | */ |
Cristy | ca0dd94 | 2016-09-20 20:48:15 -0400 | [diff] [blame] | 1767 | graphic_context=(DrawInfo **) AcquireMagickMemory(sizeof(*graphic_context)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1768 | if (graphic_context == (DrawInfo **) NULL) |
| 1769 | { |
| 1770 | primitive=DestroyString(primitive); |
| 1771 | ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", |
| 1772 | image->filename); |
| 1773 | } |
cristy | 430522c | 2012-09-03 00:07:16 +0000 | [diff] [blame] | 1774 | number_points=6553; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1775 | primitive_info=(PrimitiveInfo *) AcquireQuantumMemory((size_t) number_points, |
| 1776 | sizeof(*primitive_info)); |
| 1777 | if (primitive_info == (PrimitiveInfo *) NULL) |
| 1778 | { |
| 1779 | primitive=DestroyString(primitive); |
| 1780 | for ( ; n >= 0; n--) |
| 1781 | graphic_context[n]=DestroyDrawInfo(graphic_context[n]); |
| 1782 | graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context); |
| 1783 | ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", |
| 1784 | image->filename); |
| 1785 | } |
| 1786 | graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 1787 | graphic_context[n]->viewbox=image->page; |
| 1788 | if ((image->page.width == 0) || (image->page.height == 0)) |
| 1789 | { |
| 1790 | graphic_context[n]->viewbox.width=image->columns; |
| 1791 | graphic_context[n]->viewbox.height=image->rows; |
| 1792 | } |
| 1793 | token=AcquireString(primitive); |
dirk | fc0f124 | 2016-03-26 00:36:39 +0100 | [diff] [blame] | 1794 | extent=strlen(token)+MagickPathExtent; |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1795 | if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1796 | return(MagickFalse); |
| 1797 | status=MagickTrue; |
| 1798 | for (q=primitive; *q != '\0'; ) |
| 1799 | { |
| 1800 | /* |
| 1801 | Interpret graphic primitive. |
| 1802 | */ |
Cristy | 726812f | 2016-05-04 19:09:35 -0400 | [diff] [blame] | 1803 | GetNextToken(q,&q,MagickPathExtent,keyword); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1804 | if (*keyword == '\0') |
| 1805 | break; |
| 1806 | if (*keyword == '#') |
| 1807 | { |
| 1808 | /* |
| 1809 | Comment. |
| 1810 | */ |
| 1811 | while ((*q != '\n') && (*q != '\0')) |
| 1812 | q++; |
| 1813 | continue; |
| 1814 | } |
| 1815 | p=q-strlen(keyword)-1; |
| 1816 | primitive_type=UndefinedPrimitive; |
| 1817 | current=graphic_context[n]->affine; |
| 1818 | GetAffineMatrix(&affine); |
| 1819 | switch (*keyword) |
| 1820 | { |
| 1821 | case ';': |
| 1822 | break; |
| 1823 | case 'a': |
| 1824 | case 'A': |
| 1825 | { |
| 1826 | if (LocaleCompare("affine",keyword) == 0) |
Cristy | 4c16bb8 | 2016-07-10 19:21:52 -0400 | [diff] [blame] | 1827 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1828 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 1829 | affine.sx=StringToDouble(token,&next_token); |
| 1830 | if (token == next_token) |
| 1831 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1832 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1833 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1834 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 1835 | affine.rx=StringToDouble(token,&next_token); |
| 1836 | if (token == next_token) |
| 1837 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1838 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1839 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1840 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 1841 | affine.ry=StringToDouble(token,&next_token); |
| 1842 | if (token == next_token) |
| 1843 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1844 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1845 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1846 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 1847 | affine.sy=StringToDouble(token,&next_token); |
| 1848 | if (token == next_token) |
| 1849 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1850 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1851 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1852 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 1853 | affine.tx=StringToDouble(token,&next_token); |
| 1854 | if (token == next_token) |
| 1855 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1856 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1857 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1858 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 1859 | affine.ty=StringToDouble(token,&next_token); |
| 1860 | if (token == next_token) |
| 1861 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1862 | break; |
| 1863 | } |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 1864 | if (LocaleCompare("alpha",keyword) == 0) |
| 1865 | { |
| 1866 | primitive_type=AlphaPrimitive; |
| 1867 | break; |
| 1868 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1869 | if (LocaleCompare("arc",keyword) == 0) |
| 1870 | { |
| 1871 | primitive_type=ArcPrimitive; |
| 1872 | break; |
| 1873 | } |
| 1874 | status=MagickFalse; |
| 1875 | break; |
| 1876 | } |
| 1877 | case 'b': |
| 1878 | case 'B': |
| 1879 | { |
| 1880 | if (LocaleCompare("bezier",keyword) == 0) |
| 1881 | { |
| 1882 | primitive_type=BezierPrimitive; |
| 1883 | break; |
| 1884 | } |
| 1885 | if (LocaleCompare("border-color",keyword) == 0) |
| 1886 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1887 | GetNextToken(q,&q,extent,token); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1888 | (void) QueryColorCompliance(token,AllCompliance, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1889 | &graphic_context[n]->border_color,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1890 | break; |
| 1891 | } |
| 1892 | status=MagickFalse; |
| 1893 | break; |
| 1894 | } |
| 1895 | case 'c': |
| 1896 | case 'C': |
| 1897 | { |
| 1898 | if (LocaleCompare("clip-path",keyword) == 0) |
| 1899 | { |
| 1900 | /* |
| 1901 | Create clip mask. |
| 1902 | */ |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1903 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1904 | (void) CloneString(&graphic_context[n]->clip_mask,token); |
| 1905 | (void) DrawClipPath(image,graphic_context[n], |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1906 | graphic_context[n]->clip_mask,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1907 | break; |
| 1908 | } |
| 1909 | if (LocaleCompare("clip-rule",keyword) == 0) |
| 1910 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1911 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1912 | fill_rule; |
| 1913 | |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1914 | GetNextToken(q,&q,extent,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1915 | fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1916 | token); |
| 1917 | if (fill_rule == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 1918 | status=MagickFalse; |
| 1919 | else |
| 1920 | graphic_context[n]->fill_rule=(FillRule) fill_rule; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1921 | break; |
| 1922 | } |
| 1923 | if (LocaleCompare("clip-units",keyword) == 0) |
| 1924 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1925 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1926 | clip_units; |
| 1927 | |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1928 | GetNextToken(q,&q,extent,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1929 | clip_units=ParseCommandOption(MagickClipPathOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1930 | token); |
| 1931 | if (clip_units == -1) |
| 1932 | { |
| 1933 | status=MagickFalse; |
| 1934 | break; |
| 1935 | } |
| 1936 | graphic_context[n]->clip_units=(ClipPathUnits) clip_units; |
| 1937 | if (clip_units == ObjectBoundingBox) |
| 1938 | { |
| 1939 | GetAffineMatrix(¤t); |
| 1940 | affine.sx=draw_info->bounds.x2; |
| 1941 | affine.sy=draw_info->bounds.y2; |
| 1942 | affine.tx=draw_info->bounds.x1; |
| 1943 | affine.ty=draw_info->bounds.y1; |
| 1944 | break; |
| 1945 | } |
| 1946 | break; |
| 1947 | } |
| 1948 | if (LocaleCompare("circle",keyword) == 0) |
| 1949 | { |
| 1950 | primitive_type=CirclePrimitive; |
| 1951 | break; |
| 1952 | } |
| 1953 | if (LocaleCompare("color",keyword) == 0) |
| 1954 | { |
| 1955 | primitive_type=ColorPrimitive; |
| 1956 | break; |
| 1957 | } |
| 1958 | status=MagickFalse; |
| 1959 | break; |
| 1960 | } |
| 1961 | case 'd': |
| 1962 | case 'D': |
| 1963 | { |
| 1964 | if (LocaleCompare("decorate",keyword) == 0) |
| 1965 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1966 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1967 | decorate; |
| 1968 | |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1969 | GetNextToken(q,&q,extent,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1970 | decorate=ParseCommandOption(MagickDecorateOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1971 | token); |
| 1972 | if (decorate == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 1973 | status=MagickFalse; |
| 1974 | else |
| 1975 | graphic_context[n]->decorate=(DecorationType) decorate; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1976 | break; |
| 1977 | } |
dirk | 4777847 | 2015-07-11 10:20:41 +0000 | [diff] [blame] | 1978 | if (LocaleCompare("density",keyword) == 0) |
| 1979 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1980 | GetNextToken(q,&q,extent,token); |
dirk | 4777847 | 2015-07-11 10:20:41 +0000 | [diff] [blame] | 1981 | (void) CloneString(&graphic_context[n]->density,token); |
| 1982 | break; |
| 1983 | } |
dirk | c084d39 | 2014-01-27 19:08:45 +0000 | [diff] [blame] | 1984 | if (LocaleCompare("direction",keyword) == 0) |
| 1985 | { |
| 1986 | ssize_t |
| 1987 | direction; |
| 1988 | |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 1989 | GetNextToken(q,&q,extent,token); |
dirk | c084d39 | 2014-01-27 19:08:45 +0000 | [diff] [blame] | 1990 | direction=ParseCommandOption(MagickDirectionOptions,MagickFalse, |
| 1991 | token); |
| 1992 | if (direction == -1) |
| 1993 | status=MagickFalse; |
| 1994 | else |
| 1995 | graphic_context[n]->direction=(DirectionType) direction; |
| 1996 | break; |
| 1997 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1998 | status=MagickFalse; |
| 1999 | break; |
| 2000 | } |
| 2001 | case 'e': |
| 2002 | case 'E': |
| 2003 | { |
| 2004 | if (LocaleCompare("ellipse",keyword) == 0) |
| 2005 | { |
| 2006 | primitive_type=EllipsePrimitive; |
| 2007 | break; |
| 2008 | } |
| 2009 | if (LocaleCompare("encoding",keyword) == 0) |
| 2010 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2011 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2012 | (void) CloneString(&graphic_context[n]->encoding,token); |
| 2013 | break; |
| 2014 | } |
| 2015 | status=MagickFalse; |
| 2016 | break; |
| 2017 | } |
| 2018 | case 'f': |
| 2019 | case 'F': |
| 2020 | { |
| 2021 | if (LocaleCompare("fill",keyword) == 0) |
| 2022 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2023 | GetNextToken(q,&q,extent,token); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2024 | (void) FormatLocaleString(pattern,MagickPathExtent,"%s",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2025 | if (GetImageArtifact(image,pattern) != (const char *) NULL) |
| 2026 | (void) DrawPatternPath(image,draw_info,token, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 2027 | &graphic_context[n]->fill_pattern,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2028 | else |
| 2029 | { |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 2030 | status&=QueryColorCompliance(token,AllCompliance, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2031 | &graphic_context[n]->fill,exception); |
Cristy | 48bcfe0 | 2016-07-13 18:05:02 -0400 | [diff] [blame] | 2032 | if (graphic_context[n]->fill_alpha != OpaqueAlpha) |
| 2033 | graphic_context[n]->fill.alpha=graphic_context[n]->fill_alpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2034 | if (status == MagickFalse) |
| 2035 | { |
| 2036 | ImageInfo |
| 2037 | *pattern_info; |
| 2038 | |
| 2039 | pattern_info=AcquireImageInfo(); |
| 2040 | (void) CopyMagickString(pattern_info->filename,token, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2041 | MagickPathExtent); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2042 | graphic_context[n]->fill_pattern=ReadImage(pattern_info, |
| 2043 | exception); |
| 2044 | CatchException(exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2045 | pattern_info=DestroyImageInfo(pattern_info); |
| 2046 | } |
| 2047 | } |
| 2048 | break; |
| 2049 | } |
dirk | c8e845f | 2015-04-07 19:32:12 +0000 | [diff] [blame] | 2050 | if (LocaleCompare("fill-opacity",keyword) == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2051 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2052 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2053 | factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0; |
Cristy | b529843 | 2016-09-19 20:07:29 -0400 | [diff] [blame] | 2054 | graphic_context[n]->fill.alpha=QuantumRange-ClampToQuantum( |
| 2055 | (MagickRealType) QuantumRange*(1.0-factor*StringToDouble(token, |
| 2056 | &next_token))); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2057 | if (token == next_token) |
| 2058 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2059 | break; |
| 2060 | } |
| 2061 | if (LocaleCompare("fill-rule",keyword) == 0) |
| 2062 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2063 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2064 | fill_rule; |
| 2065 | |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2066 | GetNextToken(q,&q,extent,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2067 | fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2068 | token); |
| 2069 | if (fill_rule == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2070 | status=MagickFalse; |
| 2071 | else |
| 2072 | graphic_context[n]->fill_rule=(FillRule) fill_rule; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2073 | break; |
| 2074 | } |
| 2075 | if (LocaleCompare("font",keyword) == 0) |
| 2076 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2077 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2078 | (void) CloneString(&graphic_context[n]->font,token); |
| 2079 | if (LocaleCompare("none",token) == 0) |
Cristy | e4f4113 | 2016-07-10 08:13:20 -0400 | [diff] [blame] | 2080 | graphic_context[n]->font=(char *) RelinquishMagickMemory( |
| 2081 | graphic_context[n]->font); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2082 | break; |
| 2083 | } |
| 2084 | if (LocaleCompare("font-family",keyword) == 0) |
| 2085 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2086 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2087 | (void) CloneString(&graphic_context[n]->family,token); |
| 2088 | break; |
| 2089 | } |
| 2090 | if (LocaleCompare("font-size",keyword) == 0) |
| 2091 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2092 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2093 | graphic_context[n]->pointsize=StringToDouble(token,&next_token); |
| 2094 | if (token == next_token) |
| 2095 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2096 | break; |
| 2097 | } |
| 2098 | if (LocaleCompare("font-stretch",keyword) == 0) |
| 2099 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2100 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2101 | stretch; |
| 2102 | |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2103 | GetNextToken(q,&q,extent,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2104 | stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2105 | if (stretch == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2106 | status=MagickFalse; |
| 2107 | else |
| 2108 | graphic_context[n]->stretch=(StretchType) stretch; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2109 | break; |
| 2110 | } |
| 2111 | if (LocaleCompare("font-style",keyword) == 0) |
| 2112 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2113 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2114 | style; |
| 2115 | |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2116 | GetNextToken(q,&q,extent,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2117 | style=ParseCommandOption(MagickStyleOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2118 | if (style == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2119 | status=MagickFalse; |
| 2120 | else |
| 2121 | graphic_context[n]->style=(StyleType) style; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2122 | break; |
| 2123 | } |
| 2124 | if (LocaleCompare("font-weight",keyword) == 0) |
| 2125 | { |
dirk | 341d2ec | 2015-07-31 20:55:15 +0000 | [diff] [blame] | 2126 | ssize_t |
| 2127 | weight; |
| 2128 | |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2129 | GetNextToken(q,&q,extent,token); |
Cristy | 4c038a5 | 2016-05-01 18:20:49 -0400 | [diff] [blame] | 2130 | weight=ParseCommandOption(MagickWeightOptions,MagickFalse,token); |
dirk | 341d2ec | 2015-07-31 20:55:15 +0000 | [diff] [blame] | 2131 | if (weight == -1) |
Cristy | 726812f | 2016-05-04 19:09:35 -0400 | [diff] [blame] | 2132 | weight=(ssize_t) StringToUnsignedLong(token); |
dirk | 341d2ec | 2015-07-31 20:55:15 +0000 | [diff] [blame] | 2133 | graphic_context[n]->weight=(size_t) weight; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2134 | break; |
| 2135 | } |
| 2136 | status=MagickFalse; |
| 2137 | break; |
| 2138 | } |
| 2139 | case 'g': |
| 2140 | case 'G': |
| 2141 | { |
| 2142 | if (LocaleCompare("gradient-units",keyword) == 0) |
| 2143 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2144 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2145 | break; |
| 2146 | } |
| 2147 | if (LocaleCompare("gravity",keyword) == 0) |
| 2148 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2149 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2150 | gravity; |
| 2151 | |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2152 | GetNextToken(q,&q,extent,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2153 | gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2154 | if (gravity == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2155 | status=MagickFalse; |
| 2156 | else |
| 2157 | graphic_context[n]->gravity=(GravityType) gravity; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2158 | break; |
| 2159 | } |
| 2160 | status=MagickFalse; |
| 2161 | break; |
| 2162 | } |
| 2163 | case 'i': |
| 2164 | case 'I': |
| 2165 | { |
| 2166 | if (LocaleCompare("image",keyword) == 0) |
| 2167 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2168 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2169 | compose; |
| 2170 | |
| 2171 | primitive_type=ImagePrimitive; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2172 | GetNextToken(q,&q,extent,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2173 | compose=ParseCommandOption(MagickComposeOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2174 | if (compose == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2175 | status=MagickFalse; |
| 2176 | else |
| 2177 | graphic_context[n]->compose=(CompositeOperator) compose; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2178 | break; |
| 2179 | } |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2180 | if (LocaleCompare("interline-spacing",keyword) == 0) |
| 2181 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2182 | GetNextToken(q,&q,extent,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2183 | graphic_context[n]->interline_spacing=StringToDouble(token, |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2184 | &next_token); |
| 2185 | if (token == next_token) |
| 2186 | status=MagickFalse; |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2187 | break; |
| 2188 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2189 | if (LocaleCompare("interword-spacing",keyword) == 0) |
| 2190 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2191 | GetNextToken(q,&q,extent,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2192 | graphic_context[n]->interword_spacing=StringToDouble(token, |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2193 | &next_token); |
| 2194 | if (token == next_token) |
| 2195 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2196 | break; |
| 2197 | } |
| 2198 | status=MagickFalse; |
| 2199 | break; |
| 2200 | } |
| 2201 | case 'k': |
| 2202 | case 'K': |
| 2203 | { |
| 2204 | if (LocaleCompare("kerning",keyword) == 0) |
| 2205 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2206 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2207 | graphic_context[n]->kerning=StringToDouble(token,&next_token); |
| 2208 | if (token == next_token) |
| 2209 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2210 | break; |
| 2211 | } |
| 2212 | status=MagickFalse; |
| 2213 | break; |
| 2214 | } |
| 2215 | case 'l': |
| 2216 | case 'L': |
| 2217 | { |
| 2218 | if (LocaleCompare("line",keyword) == 0) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2219 | primitive_type=LinePrimitive; |
| 2220 | else |
| 2221 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2222 | break; |
| 2223 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2224 | case 'o': |
| 2225 | case 'O': |
| 2226 | { |
| 2227 | if (LocaleCompare("offset",keyword) == 0) |
| 2228 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2229 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2230 | break; |
| 2231 | } |
| 2232 | if (LocaleCompare("opacity",keyword) == 0) |
| 2233 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2234 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2235 | factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0; |
Cristy | ae2e0fb | 2016-07-13 18:08:36 -0400 | [diff] [blame] | 2236 | graphic_context[n]->fill_alpha=QuantumRange*(1.0-(QuantumScale* |
| 2237 | graphic_context[n]->fill_alpha*(1.0-factor*StringToDouble(token, |
| 2238 | &next_token)))); |
| 2239 | graphic_context[n]->stroke_alpha=QuantumRange*(1.0-(QuantumScale* |
| 2240 | graphic_context[n]->stroke_alpha*(1.0-factor*StringToDouble(token, |
| 2241 | &next_token)))); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2242 | if (token == next_token) |
| 2243 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2244 | break; |
| 2245 | } |
| 2246 | status=MagickFalse; |
| 2247 | break; |
| 2248 | } |
| 2249 | case 'p': |
| 2250 | case 'P': |
| 2251 | { |
| 2252 | if (LocaleCompare("path",keyword) == 0) |
| 2253 | { |
| 2254 | primitive_type=PathPrimitive; |
| 2255 | break; |
| 2256 | } |
| 2257 | if (LocaleCompare("point",keyword) == 0) |
| 2258 | { |
| 2259 | primitive_type=PointPrimitive; |
| 2260 | break; |
| 2261 | } |
| 2262 | if (LocaleCompare("polyline",keyword) == 0) |
| 2263 | { |
| 2264 | primitive_type=PolylinePrimitive; |
| 2265 | break; |
| 2266 | } |
| 2267 | if (LocaleCompare("polygon",keyword) == 0) |
| 2268 | { |
| 2269 | primitive_type=PolygonPrimitive; |
| 2270 | break; |
| 2271 | } |
| 2272 | if (LocaleCompare("pop",keyword) == 0) |
| 2273 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2274 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2275 | if (LocaleCompare("clip-path",token) == 0) |
| 2276 | break; |
| 2277 | if (LocaleCompare("defs",token) == 0) |
| 2278 | break; |
| 2279 | if (LocaleCompare("gradient",token) == 0) |
| 2280 | break; |
| 2281 | if (LocaleCompare("graphic-context",token) == 0) |
| 2282 | { |
| 2283 | if (n <= 0) |
| 2284 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2285 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2286 | DrawError,"UnbalancedGraphicContextPushPop","`%s'",token); |
Cristy | 91dac17 | 2016-06-01 10:14:08 -0400 | [diff] [blame] | 2287 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2288 | n=0; |
| 2289 | break; |
| 2290 | } |
| 2291 | if (graphic_context[n]->clip_mask != (char *) NULL) |
| 2292 | if (LocaleCompare(graphic_context[n]->clip_mask, |
| 2293 | graphic_context[n-1]->clip_mask) != 0) |
cristy | acd0d4c | 2015-07-25 16:12:33 +0000 | [diff] [blame] | 2294 | (void) SetImageMask(image,ReadPixelMask,(Image *) NULL, |
| 2295 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2296 | graphic_context[n]=DestroyDrawInfo(graphic_context[n]); |
| 2297 | n--; |
| 2298 | break; |
| 2299 | } |
| 2300 | if (LocaleCompare("pattern",token) == 0) |
| 2301 | break; |
| 2302 | status=MagickFalse; |
| 2303 | break; |
| 2304 | } |
| 2305 | if (LocaleCompare("push",keyword) == 0) |
| 2306 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2307 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2308 | if (LocaleCompare("clip-path",token) == 0) |
| 2309 | { |
| 2310 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2311 | name[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2312 | |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2313 | GetNextToken(q,&q,extent,token); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2314 | (void) FormatLocaleString(name,MagickPathExtent,"%s",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2315 | for (p=q; *q != '\0'; ) |
| 2316 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2317 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2318 | if (LocaleCompare(token,"pop") != 0) |
| 2319 | continue; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2320 | GetNextToken(q,(const char **) NULL,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2321 | if (LocaleCompare(token,"clip-path") != 0) |
| 2322 | continue; |
| 2323 | break; |
| 2324 | } |
| 2325 | (void) CopyMagickString(token,p,(size_t) (q-p-4+1)); |
| 2326 | (void) SetImageArtifact(image,name,token); |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2327 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2328 | break; |
| 2329 | } |
| 2330 | if (LocaleCompare("gradient",token) == 0) |
| 2331 | { |
| 2332 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2333 | key[2*MagickPathExtent], |
| 2334 | name[MagickPathExtent], |
| 2335 | type[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2336 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2337 | SegmentInfo |
| 2338 | segment; |
| 2339 | |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2340 | GetNextToken(q,&q,extent,token); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2341 | (void) CopyMagickString(name,token,MagickPathExtent); |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2342 | GetNextToken(q,&q,extent,token); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2343 | (void) CopyMagickString(type,token,MagickPathExtent); |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2344 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2345 | segment.x1=StringToDouble(token,&next_token); |
| 2346 | if (token == next_token) |
| 2347 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2348 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2349 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2350 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2351 | segment.y1=StringToDouble(token,&next_token); |
| 2352 | if (token == next_token) |
| 2353 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2354 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2355 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2356 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2357 | segment.x2=StringToDouble(token,&next_token); |
| 2358 | if (token == next_token) |
| 2359 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2360 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2361 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2362 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2363 | segment.y2=StringToDouble(token,&next_token); |
| 2364 | if (token == next_token) |
| 2365 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2366 | if (LocaleCompare(type,"radial") == 0) |
| 2367 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2368 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2369 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2370 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2371 | } |
| 2372 | for (p=q; *q != '\0'; ) |
| 2373 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2374 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2375 | if (LocaleCompare(token,"pop") != 0) |
| 2376 | continue; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2377 | GetNextToken(q,(const char **) NULL,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2378 | if (LocaleCompare(token,"gradient") != 0) |
| 2379 | continue; |
| 2380 | break; |
| 2381 | } |
| 2382 | (void) CopyMagickString(token,p,(size_t) (q-p-4+1)); |
| 2383 | bounds.x1=graphic_context[n]->affine.sx*segment.x1+ |
| 2384 | graphic_context[n]->affine.ry*segment.y1+ |
| 2385 | graphic_context[n]->affine.tx; |
| 2386 | bounds.y1=graphic_context[n]->affine.rx*segment.x1+ |
| 2387 | graphic_context[n]->affine.sy*segment.y1+ |
| 2388 | graphic_context[n]->affine.ty; |
| 2389 | bounds.x2=graphic_context[n]->affine.sx*segment.x2+ |
| 2390 | graphic_context[n]->affine.ry*segment.y2+ |
| 2391 | graphic_context[n]->affine.tx; |
| 2392 | bounds.y2=graphic_context[n]->affine.rx*segment.x2+ |
| 2393 | graphic_context[n]->affine.sy*segment.y2+ |
| 2394 | graphic_context[n]->affine.ty; |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2395 | (void) FormatLocaleString(key,MagickPathExtent,"%s",name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2396 | (void) SetImageArtifact(image,key,token); |
dirk | 84c7c04 | 2015-07-12 13:01:35 +0000 | [diff] [blame] | 2397 | (void) FormatLocaleString(key,MagickPathExtent,"%s-type",name); |
| 2398 | (void) SetImageArtifact(image,key,type); |
Cristy | 726812f | 2016-05-04 19:09:35 -0400 | [diff] [blame] | 2399 | (void) FormatLocaleString(key,MagickPathExtent,"%s-geometry", |
| 2400 | name); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2401 | (void) FormatLocaleString(geometry,MagickPathExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 2402 | "%gx%g%+.15g%+.15g", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2403 | MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0), |
| 2404 | MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0), |
| 2405 | bounds.x1,bounds.y1); |
| 2406 | (void) SetImageArtifact(image,key,geometry); |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2407 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2408 | break; |
| 2409 | } |
| 2410 | if (LocaleCompare("pattern",token) == 0) |
| 2411 | { |
dirk | c93932a | 2015-10-01 16:56:10 +0200 | [diff] [blame] | 2412 | char |
| 2413 | key[2*MagickPathExtent], |
| 2414 | name[MagickPathExtent]; |
| 2415 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2416 | RectangleInfo |
dirk | c93932a | 2015-10-01 16:56:10 +0200 | [diff] [blame] | 2417 | pattern_bounds; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2418 | |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2419 | GetNextToken(q,&q,extent,token); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2420 | (void) CopyMagickString(name,token,MagickPathExtent); |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2421 | GetNextToken(q,&q,extent,token); |
dirk | c93932a | 2015-10-01 16:56:10 +0200 | [diff] [blame] | 2422 | pattern_bounds.x=(ssize_t) ceil(StringToDouble(token, |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2423 | &next_token)-0.5); |
| 2424 | if (token == next_token) |
| 2425 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2426 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2427 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2428 | GetNextToken(q,&q,extent,token); |
dirk | c93932a | 2015-10-01 16:56:10 +0200 | [diff] [blame] | 2429 | pattern_bounds.y=(ssize_t) ceil(StringToDouble(token, |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2430 | &next_token)-0.5); |
| 2431 | if (token == next_token) |
| 2432 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2433 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2434 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2435 | GetNextToken(q,&q,extent,token); |
dirk | c93932a | 2015-10-01 16:56:10 +0200 | [diff] [blame] | 2436 | pattern_bounds.width=(size_t) floor(StringToDouble(token, |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2437 | &next_token)+0.5); |
| 2438 | if (token == next_token) |
| 2439 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2440 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2441 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2442 | GetNextToken(q,&q,extent,token); |
dirk | c93932a | 2015-10-01 16:56:10 +0200 | [diff] [blame] | 2443 | pattern_bounds.height=(size_t) floor(StringToDouble(token, |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2444 | &next_token)+0.5); |
| 2445 | if (token == next_token) |
| 2446 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2447 | for (p=q; *q != '\0'; ) |
| 2448 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2449 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2450 | if (LocaleCompare(token,"pop") != 0) |
| 2451 | continue; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2452 | GetNextToken(q,(const char **) NULL,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2453 | if (LocaleCompare(token,"pattern") != 0) |
| 2454 | continue; |
| 2455 | break; |
| 2456 | } |
| 2457 | (void) CopyMagickString(token,p,(size_t) (q-p-4+1)); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2458 | (void) FormatLocaleString(key,MagickPathExtent,"%s",name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2459 | (void) SetImageArtifact(image,key,token); |
dirk | c93932a | 2015-10-01 16:56:10 +0200 | [diff] [blame] | 2460 | (void) FormatLocaleString(key,MagickPathExtent,"%s-geometry", |
| 2461 | name); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2462 | (void) FormatLocaleString(geometry,MagickPathExtent, |
dirk | c93932a | 2015-10-01 16:56:10 +0200 | [diff] [blame] | 2463 | "%.20gx%.20g%+.20g%+.20g",(double)pattern_bounds.width, |
| 2464 | (double)pattern_bounds.height,(double)pattern_bounds.x, |
| 2465 | (double)pattern_bounds.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2466 | (void) SetImageArtifact(image,key,geometry); |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2467 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2468 | break; |
| 2469 | } |
| 2470 | if (LocaleCompare("graphic-context",token) == 0) |
| 2471 | { |
| 2472 | n++; |
| 2473 | graphic_context=(DrawInfo **) ResizeQuantumMemory( |
| 2474 | graphic_context,(size_t) (n+1),sizeof(*graphic_context)); |
| 2475 | if (graphic_context == (DrawInfo **) NULL) |
| 2476 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2477 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2478 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2479 | image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2480 | break; |
| 2481 | } |
| 2482 | graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL, |
| 2483 | graphic_context[n-1]); |
| 2484 | break; |
| 2485 | } |
| 2486 | if (LocaleCompare("defs",token) == 0) |
| 2487 | break; |
| 2488 | status=MagickFalse; |
| 2489 | break; |
| 2490 | } |
| 2491 | status=MagickFalse; |
| 2492 | break; |
| 2493 | } |
| 2494 | case 'r': |
| 2495 | case 'R': |
| 2496 | { |
| 2497 | if (LocaleCompare("rectangle",keyword) == 0) |
| 2498 | { |
| 2499 | primitive_type=RectanglePrimitive; |
| 2500 | break; |
| 2501 | } |
| 2502 | if (LocaleCompare("rotate",keyword) == 0) |
| 2503 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2504 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2505 | angle=StringToDouble(token,&next_token); |
| 2506 | if (token == next_token) |
| 2507 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2508 | affine.sx=cos(DegreesToRadians(fmod((double) angle,360.0))); |
| 2509 | affine.rx=sin(DegreesToRadians(fmod((double) angle,360.0))); |
| 2510 | affine.ry=(-sin(DegreesToRadians(fmod((double) angle,360.0)))); |
| 2511 | affine.sy=cos(DegreesToRadians(fmod((double) angle,360.0))); |
| 2512 | break; |
| 2513 | } |
| 2514 | if (LocaleCompare("roundRectangle",keyword) == 0) |
| 2515 | { |
| 2516 | primitive_type=RoundRectanglePrimitive; |
| 2517 | break; |
| 2518 | } |
| 2519 | status=MagickFalse; |
| 2520 | break; |
| 2521 | } |
| 2522 | case 's': |
| 2523 | case 'S': |
| 2524 | { |
| 2525 | if (LocaleCompare("scale",keyword) == 0) |
| 2526 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2527 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2528 | affine.sx=StringToDouble(token,&next_token); |
| 2529 | if (token == next_token) |
| 2530 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2531 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2532 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2533 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2534 | affine.sy=StringToDouble(token,&next_token); |
| 2535 | if (token == next_token) |
| 2536 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2537 | break; |
| 2538 | } |
| 2539 | if (LocaleCompare("skewX",keyword) == 0) |
| 2540 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2541 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2542 | angle=StringToDouble(token,&next_token); |
| 2543 | if (token == next_token) |
| 2544 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2545 | affine.ry=sin(DegreesToRadians(angle)); |
| 2546 | break; |
| 2547 | } |
| 2548 | if (LocaleCompare("skewY",keyword) == 0) |
| 2549 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2550 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2551 | angle=StringToDouble(token,&next_token); |
| 2552 | if (token == next_token) |
| 2553 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2554 | affine.rx=(-tan(DegreesToRadians(angle)/2.0)); |
| 2555 | break; |
| 2556 | } |
| 2557 | if (LocaleCompare("stop-color",keyword) == 0) |
| 2558 | { |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 2559 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2560 | stop_color; |
| 2561 | |
dirk | b6f578b | 2015-07-12 17:56:39 +0000 | [diff] [blame] | 2562 | number_stops++; |
| 2563 | if (number_stops == 1) |
| 2564 | stops=(StopInfo *) AcquireQuantumMemory(2,sizeof(*stops)); |
| 2565 | else if (number_stops > 2) |
| 2566 | stops=(StopInfo *) ResizeQuantumMemory(stops,number_stops, |
| 2567 | sizeof(*stops)); |
| 2568 | if (stops == (StopInfo *) NULL) |
| 2569 | { |
| 2570 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 2571 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 2572 | image->filename); |
| 2573 | break; |
| 2574 | } |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2575 | GetNextToken(q,&q,extent,token); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 2576 | (void) QueryColorCompliance(token,AllCompliance,&stop_color, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2577 | exception); |
dirk | b6f578b | 2015-07-12 17:56:39 +0000 | [diff] [blame] | 2578 | stops[number_stops-1].color=stop_color; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2579 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2580 | stops[number_stops-1].offset=StringToDouble(token,&next_token); |
| 2581 | if (token == next_token) |
| 2582 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2583 | break; |
| 2584 | } |
| 2585 | if (LocaleCompare("stroke",keyword) == 0) |
| 2586 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2587 | GetNextToken(q,&q,extent,token); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2588 | (void) FormatLocaleString(pattern,MagickPathExtent,"%s",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2589 | if (GetImageArtifact(image,pattern) != (const char *) NULL) |
| 2590 | (void) DrawPatternPath(image,draw_info,token, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 2591 | &graphic_context[n]->stroke_pattern,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2592 | else |
| 2593 | { |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 2594 | status&=QueryColorCompliance(token,AllCompliance, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2595 | &graphic_context[n]->stroke,exception); |
Cristy | 48bcfe0 | 2016-07-13 18:05:02 -0400 | [diff] [blame] | 2596 | if (graphic_context[n]->stroke_alpha != OpaqueAlpha) |
| 2597 | graphic_context[n]->stroke.alpha= |
| 2598 | graphic_context[n]->stroke_alpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2599 | if (status == MagickFalse) |
| 2600 | { |
| 2601 | ImageInfo |
| 2602 | *pattern_info; |
| 2603 | |
| 2604 | pattern_info=AcquireImageInfo(); |
| 2605 | (void) CopyMagickString(pattern_info->filename,token, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2606 | MagickPathExtent); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2607 | graphic_context[n]->stroke_pattern=ReadImage(pattern_info, |
| 2608 | exception); |
| 2609 | CatchException(exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2610 | pattern_info=DestroyImageInfo(pattern_info); |
| 2611 | } |
| 2612 | } |
| 2613 | break; |
| 2614 | } |
| 2615 | if (LocaleCompare("stroke-antialias",keyword) == 0) |
| 2616 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2617 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2618 | graphic_context[n]->stroke_antialias= |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2619 | StringToLong(token) != 0 ? MagickTrue : MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2620 | break; |
| 2621 | } |
| 2622 | if (LocaleCompare("stroke-dasharray",keyword) == 0) |
| 2623 | { |
| 2624 | if (graphic_context[n]->dash_pattern != (double *) NULL) |
| 2625 | graphic_context[n]->dash_pattern=(double *) |
| 2626 | RelinquishMagickMemory(graphic_context[n]->dash_pattern); |
| 2627 | if (IsPoint(q) != MagickFalse) |
| 2628 | { |
| 2629 | const char |
dirk | c93932a | 2015-10-01 16:56:10 +0200 | [diff] [blame] | 2630 | *r; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2631 | |
dirk | c93932a | 2015-10-01 16:56:10 +0200 | [diff] [blame] | 2632 | r=q; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2633 | GetNextToken(r,&r,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2634 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2635 | GetNextToken(r,&r,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2636 | for (x=0; IsPoint(token) != MagickFalse; x++) |
| 2637 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2638 | GetNextToken(r,&r,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2639 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2640 | GetNextToken(r,&r,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2641 | } |
| 2642 | graphic_context[n]->dash_pattern=(double *) |
| 2643 | AcquireQuantumMemory((size_t) (2UL*x+1UL), |
| 2644 | sizeof(*graphic_context[n]->dash_pattern)); |
| 2645 | if (graphic_context[n]->dash_pattern == (double *) NULL) |
| 2646 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2647 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2648 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2649 | image->filename); |
Cristy | 91dac17 | 2016-06-01 10:14:08 -0400 | [diff] [blame] | 2650 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2651 | break; |
| 2652 | } |
| 2653 | for (j=0; j < x; j++) |
| 2654 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2655 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2656 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2657 | GetNextToken(q,&q,extent,token); |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 2658 | graphic_context[n]->dash_pattern[j]=StringToDouble(token, |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2659 | &next_token); |
| 2660 | if (token == next_token) |
| 2661 | status=MagickFalse; |
Cristy | 9cdadd9 | 2016-05-03 18:17:01 -0400 | [diff] [blame] | 2662 | if (graphic_context[n]->dash_pattern[j] < 0.0) |
| 2663 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2664 | } |
| 2665 | if ((x & 0x01) != 0) |
| 2666 | for ( ; j < (2*x); j++) |
| 2667 | graphic_context[n]->dash_pattern[j]= |
| 2668 | graphic_context[n]->dash_pattern[j-x]; |
| 2669 | graphic_context[n]->dash_pattern[j]=0.0; |
| 2670 | break; |
| 2671 | } |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2672 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2673 | break; |
| 2674 | } |
| 2675 | if (LocaleCompare("stroke-dashoffset",keyword) == 0) |
| 2676 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2677 | GetNextToken(q,&q,extent,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2678 | graphic_context[n]->dash_offset=StringToDouble(token, |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2679 | &next_token); |
| 2680 | if (token == next_token) |
| 2681 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2682 | break; |
| 2683 | } |
| 2684 | if (LocaleCompare("stroke-linecap",keyword) == 0) |
| 2685 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2686 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2687 | linecap; |
| 2688 | |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2689 | GetNextToken(q,&q,extent,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2690 | linecap=ParseCommandOption(MagickLineCapOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2691 | if (linecap == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2692 | status=MagickFalse; |
| 2693 | else |
| 2694 | graphic_context[n]->linecap=(LineCap) linecap; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2695 | break; |
| 2696 | } |
| 2697 | if (LocaleCompare("stroke-linejoin",keyword) == 0) |
| 2698 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2699 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2700 | linejoin; |
| 2701 | |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2702 | GetNextToken(q,&q,extent,token); |
cristy | 7118edf | 2011-10-08 13:33:25 +0000 | [diff] [blame] | 2703 | linejoin=ParseCommandOption(MagickLineJoinOptions,MagickFalse, |
| 2704 | token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2705 | if (linejoin == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2706 | status=MagickFalse; |
| 2707 | else |
| 2708 | graphic_context[n]->linejoin=(LineJoin) linejoin; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2709 | break; |
| 2710 | } |
| 2711 | if (LocaleCompare("stroke-miterlimit",keyword) == 0) |
| 2712 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2713 | GetNextToken(q,&q,extent,token); |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 2714 | graphic_context[n]->miterlimit=StringToUnsignedLong(token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2715 | break; |
| 2716 | } |
| 2717 | if (LocaleCompare("stroke-opacity",keyword) == 0) |
| 2718 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2719 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2720 | factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0; |
Cristy | b529843 | 2016-09-19 20:07:29 -0400 | [diff] [blame] | 2721 | graphic_context[n]->stroke.alpha=QuantumRange-ClampToQuantum( |
| 2722 | (MagickRealType) QuantumRange*(1.0-factor*StringToDouble(token, |
| 2723 | &next_token))); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2724 | if (token == next_token) |
| 2725 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2726 | break; |
| 2727 | } |
| 2728 | if (LocaleCompare("stroke-width",keyword) == 0) |
| 2729 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2730 | GetNextToken(q,&q,extent,token); |
Cristy | e4f4113 | 2016-07-10 08:13:20 -0400 | [diff] [blame] | 2731 | graphic_context[n]->stroke_width=StringToDouble(token,&next_token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2732 | if (token == next_token) |
| 2733 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2734 | break; |
| 2735 | } |
| 2736 | status=MagickFalse; |
| 2737 | break; |
| 2738 | } |
| 2739 | case 't': |
| 2740 | case 'T': |
| 2741 | { |
| 2742 | if (LocaleCompare("text",keyword) == 0) |
| 2743 | { |
| 2744 | primitive_type=TextPrimitive; |
| 2745 | break; |
| 2746 | } |
| 2747 | if (LocaleCompare("text-align",keyword) == 0) |
| 2748 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2749 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2750 | align; |
| 2751 | |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2752 | GetNextToken(q,&q,extent,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2753 | align=ParseCommandOption(MagickAlignOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2754 | if (align == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2755 | status=MagickFalse; |
| 2756 | else |
| 2757 | graphic_context[n]->align=(AlignType) align; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2758 | break; |
| 2759 | } |
| 2760 | if (LocaleCompare("text-anchor",keyword) == 0) |
| 2761 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2762 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2763 | align; |
| 2764 | |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2765 | GetNextToken(q,&q,extent,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2766 | align=ParseCommandOption(MagickAlignOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2767 | if (align == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2768 | status=MagickFalse; |
| 2769 | else |
| 2770 | graphic_context[n]->align=(AlignType) align; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2771 | break; |
| 2772 | } |
| 2773 | if (LocaleCompare("text-antialias",keyword) == 0) |
| 2774 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2775 | GetNextToken(q,&q,extent,token); |
Cristy | e4f4113 | 2016-07-10 08:13:20 -0400 | [diff] [blame] | 2776 | graphic_context[n]->text_antialias=StringToLong(token) != 0 ? |
| 2777 | MagickTrue : MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2778 | break; |
| 2779 | } |
| 2780 | if (LocaleCompare("text-undercolor",keyword) == 0) |
| 2781 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2782 | GetNextToken(q,&q,extent,token); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 2783 | (void) QueryColorCompliance(token,AllCompliance, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2784 | &graphic_context[n]->undercolor,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2785 | break; |
| 2786 | } |
| 2787 | if (LocaleCompare("translate",keyword) == 0) |
| 2788 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2789 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2790 | affine.tx=StringToDouble(token,&next_token); |
| 2791 | if (token == next_token) |
| 2792 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2793 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2794 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2795 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2796 | affine.ty=StringToDouble(token,&next_token); |
| 2797 | if (token == next_token) |
| 2798 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2799 | break; |
| 2800 | } |
| 2801 | status=MagickFalse; |
| 2802 | break; |
| 2803 | } |
| 2804 | case 'v': |
| 2805 | case 'V': |
| 2806 | { |
| 2807 | if (LocaleCompare("viewbox",keyword) == 0) |
| 2808 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2809 | GetNextToken(q,&q,extent,token); |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 2810 | graphic_context[n]->viewbox.x=(ssize_t) ceil(StringToDouble(token, |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2811 | &next_token)-0.5); |
| 2812 | if (token == next_token) |
| 2813 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2814 | GetNextToken(q,&q,extent,token); |
cristy | 06609ee | 2010-03-17 20:21:27 +0000 | [diff] [blame] | 2815 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2816 | GetNextToken(q,&q,extent,token); |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 2817 | graphic_context[n]->viewbox.y=(ssize_t) ceil(StringToDouble(token, |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2818 | &next_token)-0.5); |
| 2819 | if (token == next_token) |
| 2820 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2821 | GetNextToken(q,&q,extent,token); |
cristy | 06609ee | 2010-03-17 20:21:27 +0000 | [diff] [blame] | 2822 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2823 | GetNextToken(q,&q,extent,token); |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 2824 | graphic_context[n]->viewbox.width=(size_t) floor(StringToDouble( |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2825 | token,&next_token)+0.5); |
| 2826 | if (token == next_token) |
| 2827 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2828 | GetNextToken(q,&q,extent,token); |
cristy | 06609ee | 2010-03-17 20:21:27 +0000 | [diff] [blame] | 2829 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2830 | GetNextToken(q,&q,extent,token); |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 2831 | graphic_context[n]->viewbox.height=(size_t) floor(StringToDouble( |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2832 | token,&next_token)+0.5); |
| 2833 | if (token == next_token) |
| 2834 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2835 | break; |
| 2836 | } |
| 2837 | status=MagickFalse; |
| 2838 | break; |
| 2839 | } |
| 2840 | default: |
| 2841 | { |
| 2842 | status=MagickFalse; |
| 2843 | break; |
| 2844 | } |
| 2845 | } |
| 2846 | if (status == MagickFalse) |
| 2847 | break; |
Cristy | 48bcfe0 | 2016-07-13 18:05:02 -0400 | [diff] [blame] | 2848 | if ((fabs(affine.sx-1.0) >= DrawEpsilon) || |
| 2849 | (fabs(affine.rx) >= DrawEpsilon) || (fabs(affine.ry) >= DrawEpsilon) || |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 2850 | (fabs(affine.sy-1.0) >= DrawEpsilon) || |
Cristy | 48bcfe0 | 2016-07-13 18:05:02 -0400 | [diff] [blame] | 2851 | (fabs(affine.tx) >= DrawEpsilon) || (fabs(affine.ty) >= DrawEpsilon)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2852 | { |
cristy | fbd7009 | 2010-12-01 19:31:14 +0000 | [diff] [blame] | 2853 | graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx; |
| 2854 | graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx; |
| 2855 | graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy; |
| 2856 | graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy; |
| 2857 | graphic_context[n]->affine.tx=current.sx*affine.tx+current.ry*affine.ty+ |
| 2858 | current.tx; |
| 2859 | graphic_context[n]->affine.ty=current.rx*affine.tx+current.sy*affine.ty+ |
| 2860 | current.ty; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2861 | } |
| 2862 | if (primitive_type == UndefinedPrimitive) |
| 2863 | { |
dirk | b6f578b | 2015-07-12 17:56:39 +0000 | [diff] [blame] | 2864 | if (*q == '\0') |
| 2865 | { |
| 2866 | if (number_stops > 1) |
| 2867 | { |
| 2868 | GradientType |
| 2869 | type; |
| 2870 | |
| 2871 | type=LinearGradient; |
| 2872 | if (draw_info->gradient.type == RadialGradient) |
| 2873 | type=RadialGradient; |
| 2874 | (void) GradientImage(image,type,PadSpread,stops,number_stops, |
Cristy | d84051a | 2016-07-05 07:01:47 -0400 | [diff] [blame] | 2875 | exception); |
dirk | b6f578b | 2015-07-12 17:56:39 +0000 | [diff] [blame] | 2876 | } |
| 2877 | if (number_stops > 0) |
| 2878 | stops=(StopInfo *) RelinquishMagickMemory(stops); |
| 2879 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2880 | if (image->debug != MagickFalse) |
Cristy | d84051a | 2016-07-05 07:01:47 -0400 | [diff] [blame] | 2881 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",(int) |
| 2882 | (q-p),p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2883 | continue; |
| 2884 | } |
| 2885 | /* |
| 2886 | Parse the primitive attributes. |
| 2887 | */ |
| 2888 | i=0; |
| 2889 | j=0; |
| 2890 | primitive_info[0].point.x=0.0; |
| 2891 | primitive_info[0].point.y=0.0; |
| 2892 | for (x=0; *q != '\0'; x++) |
| 2893 | { |
| 2894 | /* |
| 2895 | Define points. |
| 2896 | */ |
| 2897 | if (IsPoint(q) == MagickFalse) |
| 2898 | break; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2899 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2900 | point.x=StringToDouble(token,&next_token); |
| 2901 | if (token == next_token) |
| 2902 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2903 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2904 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2905 | GetNextToken(q,&q,extent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 2906 | point.y=StringToDouble(token,&next_token); |
| 2907 | if (token == next_token) |
| 2908 | status=MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2909 | GetNextToken(q,(const char **) NULL,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2910 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2911 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2912 | primitive_info[i].primitive=primitive_type; |
| 2913 | primitive_info[i].point=point; |
| 2914 | primitive_info[i].coordinates=0; |
| 2915 | primitive_info[i].method=FloodfillMethod; |
| 2916 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2917 | if (i < (ssize_t) number_points) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2918 | continue; |
| 2919 | number_points<<=1; |
| 2920 | primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info, |
| 2921 | (size_t) number_points,sizeof(*primitive_info)); |
Cristy | 58affb9 | 2016-06-01 10:08:14 -0400 | [diff] [blame] | 2922 | if ((primitive_info == (PrimitiveInfo *) NULL) || |
| 2923 | (number_points != (MagickSizeType) ((size_t) number_points))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2924 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2925 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2926 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2927 | break; |
| 2928 | } |
| 2929 | } |
| 2930 | primitive_info[j].primitive=primitive_type; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2931 | primitive_info[j].coordinates=(size_t) x; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2932 | primitive_info[j].method=FloodfillMethod; |
| 2933 | primitive_info[j].text=(char *) NULL; |
| 2934 | /* |
| 2935 | Circumscribe primitive within a circle. |
| 2936 | */ |
| 2937 | bounds.x1=primitive_info[j].point.x; |
| 2938 | bounds.y1=primitive_info[j].point.y; |
| 2939 | bounds.x2=primitive_info[j].point.x; |
| 2940 | bounds.y2=primitive_info[j].point.y; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2941 | for (k=1; k < (ssize_t) primitive_info[j].coordinates; k++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2942 | { |
| 2943 | point=primitive_info[j+k].point; |
| 2944 | if (point.x < bounds.x1) |
| 2945 | bounds.x1=point.x; |
| 2946 | if (point.y < bounds.y1) |
| 2947 | bounds.y1=point.y; |
| 2948 | if (point.x > bounds.x2) |
| 2949 | bounds.x2=point.x; |
| 2950 | if (point.y > bounds.y2) |
| 2951 | bounds.y2=point.y; |
| 2952 | } |
| 2953 | /* |
| 2954 | Speculate how many points our primitive might consume. |
| 2955 | */ |
| 2956 | length=primitive_info[j].coordinates; |
| 2957 | switch (primitive_type) |
| 2958 | { |
| 2959 | case RectanglePrimitive: |
| 2960 | { |
| 2961 | length*=5; |
| 2962 | break; |
| 2963 | } |
| 2964 | case RoundRectanglePrimitive: |
| 2965 | { |
cristy | 1bdb233 | 2014-11-23 14:02:08 +0000 | [diff] [blame] | 2966 | double |
| 2967 | alpha, |
| 2968 | beta, |
| 2969 | radius; |
| 2970 | |
| 2971 | alpha=bounds.x2-bounds.x1; |
| 2972 | beta=bounds.y2-bounds.y1; |
| 2973 | radius=hypot((double) alpha,(double) beta); |
| 2974 | length*=5; |
| 2975 | length+=2*((size_t) ceil((double) MagickPI*radius))+6*BezierQuantum+360; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2976 | break; |
| 2977 | } |
| 2978 | case BezierPrimitive: |
| 2979 | { |
| 2980 | if (primitive_info[j].coordinates > 107) |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2981 | (void) ThrowMagickException(exception,GetMagickModule(),DrawError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2982 | "TooManyBezierCoordinates","`%s'",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2983 | length=BezierQuantum*primitive_info[j].coordinates; |
| 2984 | break; |
| 2985 | } |
| 2986 | case PathPrimitive: |
| 2987 | { |
| 2988 | char |
| 2989 | *s, |
| 2990 | *t; |
| 2991 | |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2992 | GetNextToken(q,&q,extent,token); |
cristy | 40a08ad | 2010-02-09 02:27:44 +0000 | [diff] [blame] | 2993 | length=1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2994 | t=token; |
| 2995 | for (s=token; *s != '\0'; s=t) |
| 2996 | { |
cristy | 00976d8 | 2011-02-20 20:31:28 +0000 | [diff] [blame] | 2997 | double |
| 2998 | value; |
| 2999 | |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 3000 | value=StringToDouble(s,&t); |
cristy | 00976d8 | 2011-02-20 20:31:28 +0000 | [diff] [blame] | 3001 | (void) value; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3002 | if (s == t) |
| 3003 | { |
| 3004 | t++; |
| 3005 | continue; |
| 3006 | } |
cristy | ef7a6ce | 2011-05-14 15:01:11 +0000 | [diff] [blame] | 3007 | length++; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3008 | } |
Cristy | ddca5f7 | 2016-08-04 10:23:02 -0400 | [diff] [blame] | 3009 | length=length*BezierQuantum; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3010 | break; |
| 3011 | } |
| 3012 | case CirclePrimitive: |
| 3013 | case ArcPrimitive: |
| 3014 | case EllipsePrimitive: |
| 3015 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3016 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3017 | alpha, |
| 3018 | beta, |
| 3019 | radius; |
| 3020 | |
| 3021 | alpha=bounds.x2-bounds.x1; |
| 3022 | beta=bounds.y2-bounds.y1; |
| 3023 | radius=hypot((double) alpha,(double) beta); |
cristy | f53f26f | 2011-05-16 00:56:05 +0000 | [diff] [blame] | 3024 | length=2*((size_t) ceil((double) MagickPI*radius))+6*BezierQuantum+360; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3025 | break; |
| 3026 | } |
| 3027 | default: |
| 3028 | break; |
| 3029 | } |
Cristy | 58affb9 | 2016-06-01 10:08:14 -0400 | [diff] [blame] | 3030 | if ((i+length) >= number_points) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3031 | { |
| 3032 | /* |
| 3033 | Resize based on speculative points required by primitive. |
| 3034 | */ |
cristy | 9ce61b9 | 2010-05-12 16:30:26 +0000 | [diff] [blame] | 3035 | number_points+=length+1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3036 | primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info, |
| 3037 | (size_t) number_points,sizeof(*primitive_info)); |
Cristy | 58affb9 | 2016-06-01 10:08:14 -0400 | [diff] [blame] | 3038 | if ((primitive_info == (PrimitiveInfo *) NULL) || |
| 3039 | (number_points != (MagickSizeType) ((size_t) number_points))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3040 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3041 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 3042 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3043 | image->filename); |
| 3044 | break; |
| 3045 | } |
| 3046 | } |
| 3047 | switch (primitive_type) |
| 3048 | { |
| 3049 | case PointPrimitive: |
| 3050 | default: |
| 3051 | { |
| 3052 | if (primitive_info[j].coordinates != 1) |
| 3053 | { |
| 3054 | status=MagickFalse; |
| 3055 | break; |
| 3056 | } |
| 3057 | TracePoint(primitive_info+j,primitive_info[j].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3058 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3059 | break; |
| 3060 | } |
| 3061 | case LinePrimitive: |
| 3062 | { |
| 3063 | if (primitive_info[j].coordinates != 2) |
| 3064 | { |
| 3065 | status=MagickFalse; |
| 3066 | break; |
| 3067 | } |
| 3068 | TraceLine(primitive_info+j,primitive_info[j].point, |
| 3069 | primitive_info[j+1].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3070 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3071 | break; |
| 3072 | } |
| 3073 | case RectanglePrimitive: |
| 3074 | { |
| 3075 | if (primitive_info[j].coordinates != 2) |
| 3076 | { |
| 3077 | status=MagickFalse; |
| 3078 | break; |
| 3079 | } |
| 3080 | TraceRectangle(primitive_info+j,primitive_info[j].point, |
| 3081 | primitive_info[j+1].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3082 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3083 | break; |
| 3084 | } |
| 3085 | case RoundRectanglePrimitive: |
| 3086 | { |
| 3087 | if (primitive_info[j].coordinates != 3) |
| 3088 | { |
| 3089 | status=MagickFalse; |
| 3090 | break; |
| 3091 | } |
| 3092 | TraceRoundRectangle(primitive_info+j,primitive_info[j].point, |
| 3093 | primitive_info[j+1].point,primitive_info[j+2].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3094 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3095 | break; |
| 3096 | } |
| 3097 | case ArcPrimitive: |
| 3098 | { |
| 3099 | if (primitive_info[j].coordinates != 3) |
| 3100 | { |
| 3101 | primitive_type=UndefinedPrimitive; |
| 3102 | break; |
| 3103 | } |
| 3104 | TraceArc(primitive_info+j,primitive_info[j].point, |
| 3105 | primitive_info[j+1].point,primitive_info[j+2].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3106 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3107 | break; |
| 3108 | } |
| 3109 | case EllipsePrimitive: |
| 3110 | { |
| 3111 | if (primitive_info[j].coordinates != 3) |
| 3112 | { |
| 3113 | status=MagickFalse; |
| 3114 | break; |
| 3115 | } |
| 3116 | TraceEllipse(primitive_info+j,primitive_info[j].point, |
| 3117 | primitive_info[j+1].point,primitive_info[j+2].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3118 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3119 | break; |
| 3120 | } |
| 3121 | case CirclePrimitive: |
| 3122 | { |
| 3123 | if (primitive_info[j].coordinates != 2) |
| 3124 | { |
| 3125 | status=MagickFalse; |
| 3126 | break; |
| 3127 | } |
| 3128 | TraceCircle(primitive_info+j,primitive_info[j].point, |
| 3129 | primitive_info[j+1].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3130 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3131 | break; |
| 3132 | } |
| 3133 | case PolylinePrimitive: |
| 3134 | break; |
| 3135 | case PolygonPrimitive: |
| 3136 | { |
| 3137 | primitive_info[i]=primitive_info[j]; |
| 3138 | primitive_info[i].coordinates=0; |
| 3139 | primitive_info[j].coordinates++; |
| 3140 | i++; |
| 3141 | break; |
| 3142 | } |
| 3143 | case BezierPrimitive: |
| 3144 | { |
| 3145 | if (primitive_info[j].coordinates < 3) |
| 3146 | { |
| 3147 | status=MagickFalse; |
| 3148 | break; |
| 3149 | } |
| 3150 | TraceBezier(primitive_info+j,primitive_info[j].coordinates); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3151 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3152 | break; |
| 3153 | } |
| 3154 | case PathPrimitive: |
| 3155 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3156 | i=(ssize_t) (j+TracePath(primitive_info+j,token)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3157 | break; |
| 3158 | } |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 3159 | case AlphaPrimitive: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3160 | case ColorPrimitive: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3161 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3162 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3163 | method; |
| 3164 | |
| 3165 | if (primitive_info[j].coordinates != 1) |
| 3166 | { |
| 3167 | status=MagickFalse; |
| 3168 | break; |
| 3169 | } |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 3170 | GetNextToken(q,&q,extent,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 3171 | method=ParseCommandOption(MagickMethodOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3172 | if (method == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 3173 | status=MagickFalse; |
| 3174 | else |
| 3175 | primitive_info[j].method=(PaintMethod) method; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3176 | break; |
| 3177 | } |
| 3178 | case TextPrimitive: |
| 3179 | { |
| 3180 | if (primitive_info[j].coordinates != 1) |
| 3181 | { |
| 3182 | status=MagickFalse; |
| 3183 | break; |
| 3184 | } |
| 3185 | if (*token != ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 3186 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3187 | primitive_info[j].text=AcquireString(token); |
| 3188 | break; |
| 3189 | } |
| 3190 | case ImagePrimitive: |
| 3191 | { |
| 3192 | if (primitive_info[j].coordinates != 2) |
| 3193 | { |
| 3194 | status=MagickFalse; |
| 3195 | break; |
| 3196 | } |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 3197 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3198 | primitive_info[j].text=AcquireString(token); |
| 3199 | break; |
| 3200 | } |
| 3201 | } |
| 3202 | if (primitive_info == (PrimitiveInfo *) NULL) |
| 3203 | break; |
| 3204 | if (image->debug != MagickFalse) |
| 3205 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",(int) (q-p),p); |
| 3206 | if (status == MagickFalse) |
| 3207 | break; |
| 3208 | primitive_info[i].primitive=UndefinedPrimitive; |
| 3209 | if (i == 0) |
| 3210 | continue; |
| 3211 | /* |
| 3212 | Transform points. |
| 3213 | */ |
| 3214 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) |
| 3215 | { |
| 3216 | point=primitive_info[i].point; |
| 3217 | primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+ |
| 3218 | graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx; |
| 3219 | primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+ |
| 3220 | graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty; |
| 3221 | point=primitive_info[i].point; |
| 3222 | if (point.x < graphic_context[n]->bounds.x1) |
| 3223 | graphic_context[n]->bounds.x1=point.x; |
| 3224 | if (point.y < graphic_context[n]->bounds.y1) |
| 3225 | graphic_context[n]->bounds.y1=point.y; |
| 3226 | if (point.x > graphic_context[n]->bounds.x2) |
| 3227 | graphic_context[n]->bounds.x2=point.x; |
| 3228 | if (point.y > graphic_context[n]->bounds.y2) |
| 3229 | graphic_context[n]->bounds.y2=point.y; |
| 3230 | if (primitive_info[i].primitive == ImagePrimitive) |
| 3231 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3232 | if (i >= (ssize_t) number_points) |
cristy | 9ce61b9 | 2010-05-12 16:30:26 +0000 | [diff] [blame] | 3233 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3234 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3235 | if (graphic_context[n]->render != MagickFalse) |
| 3236 | { |
| 3237 | if ((n != 0) && (graphic_context[n]->clip_mask != (char *) NULL) && |
| 3238 | (LocaleCompare(graphic_context[n]->clip_mask, |
| 3239 | graphic_context[n-1]->clip_mask) != 0)) |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 3240 | status&=DrawClipPath(image,graphic_context[n], |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 3241 | graphic_context[n]->clip_mask,exception); |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 3242 | status&=DrawPrimitive(image,graphic_context[n],primitive_info, |
| 3243 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3244 | } |
| 3245 | if (primitive_info->text != (char *) NULL) |
| 3246 | primitive_info->text=(char *) RelinquishMagickMemory( |
| 3247 | primitive_info->text); |
| 3248 | proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType) |
| 3249 | primitive_extent); |
| 3250 | if (proceed == MagickFalse) |
| 3251 | break; |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 3252 | if (status == 0) |
| 3253 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3254 | } |
| 3255 | if (image->debug != MagickFalse) |
| 3256 | (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end draw-image"); |
| 3257 | /* |
| 3258 | Relinquish resources. |
| 3259 | */ |
| 3260 | token=DestroyString(token); |
| 3261 | if (primitive_info != (PrimitiveInfo *) NULL) |
| 3262 | primitive_info=(PrimitiveInfo *) RelinquishMagickMemory(primitive_info); |
| 3263 | primitive=DestroyString(primitive); |
| 3264 | for ( ; n >= 0; n--) |
| 3265 | graphic_context[n]=DestroyDrawInfo(graphic_context[n]); |
| 3266 | graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context); |
| 3267 | if (status == MagickFalse) |
| 3268 | ThrowBinaryException(DrawError,"NonconformingDrawingPrimitiveDefinition", |
| 3269 | keyword); |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 3270 | return(status != 0 ? MagickTrue : MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3271 | } |
| 3272 | |
| 3273 | /* |
| 3274 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3275 | % % |
| 3276 | % % |
| 3277 | % % |
| 3278 | % D r a w G r a d i e n t I m a g e % |
| 3279 | % % |
| 3280 | % % |
| 3281 | % % |
| 3282 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3283 | % |
| 3284 | % DrawGradientImage() draws a linear gradient on the image. |
| 3285 | % |
| 3286 | % The format of the DrawGradientImage method is: |
| 3287 | % |
| 3288 | % MagickBooleanType DrawGradientImage(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3289 | % const DrawInfo *draw_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3290 | % |
| 3291 | % A description of each parameter follows: |
| 3292 | % |
| 3293 | % o image: the image. |
| 3294 | % |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 3295 | % o draw_info: the draw info. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3296 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3297 | % o exception: return any errors or warnings in this structure. |
| 3298 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3299 | */ |
| 3300 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3301 | static inline double GetStopColorOffset(const GradientInfo *gradient, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3302 | const ssize_t x,const ssize_t y) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3303 | { |
| 3304 | switch (gradient->type) |
| 3305 | { |
| 3306 | case UndefinedGradient: |
| 3307 | case LinearGradient: |
| 3308 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3309 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3310 | gamma, |
| 3311 | length, |
| 3312 | offset, |
| 3313 | scale; |
| 3314 | |
| 3315 | PointInfo |
| 3316 | p, |
| 3317 | q; |
| 3318 | |
| 3319 | const SegmentInfo |
| 3320 | *gradient_vector; |
| 3321 | |
| 3322 | gradient_vector=(&gradient->gradient_vector); |
| 3323 | p.x=gradient_vector->x2-gradient_vector->x1; |
| 3324 | p.y=gradient_vector->y2-gradient_vector->y1; |
| 3325 | q.x=(double) x-gradient_vector->x1; |
| 3326 | q.y=(double) y-gradient_vector->y1; |
| 3327 | length=sqrt(q.x*q.x+q.y*q.y); |
| 3328 | gamma=sqrt(p.x*p.x+p.y*p.y)*length; |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 3329 | gamma=PerceptibleReciprocal(gamma); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3330 | scale=p.x*q.x+p.y*q.y; |
| 3331 | offset=gamma*scale*length; |
| 3332 | return(offset); |
| 3333 | } |
| 3334 | case RadialGradient: |
| 3335 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3336 | PointInfo |
| 3337 | v; |
| 3338 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3339 | if (gradient->spread == RepeatSpread) |
Cristy | 50a6c9d | 2015-10-18 08:31:57 -0400 | [diff] [blame] | 3340 | { |
| 3341 | v.x=(double) x-gradient->center.x; |
| 3342 | v.y=(double) y-gradient->center.y; |
| 3343 | return(sqrt(v.x*v.x+v.y*v.y)); |
| 3344 | } |
Cristy | 8af8043 | 2015-10-19 17:35:23 -0400 | [diff] [blame] | 3345 | v.x=(double) (((x-gradient->center.x)*cos(DegreesToRadians( |
| 3346 | gradient->angle)))+((y-gradient->center.y)*sin(DegreesToRadians( |
| 3347 | gradient->angle))))/gradient->radii.x; |
| 3348 | v.y=(double) (((x-gradient->center.x)*sin(DegreesToRadians( |
| 3349 | gradient->angle)))-((y-gradient->center.y)*cos(DegreesToRadians( |
| 3350 | gradient->angle))))/gradient->radii.y; |
Cristy | 50a6c9d | 2015-10-18 08:31:57 -0400 | [diff] [blame] | 3351 | return(sqrt(v.x*v.x+v.y*v.y)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3352 | } |
| 3353 | } |
| 3354 | return(0.0); |
| 3355 | } |
| 3356 | |
dirk | b6f578b | 2015-07-12 17:56:39 +0000 | [diff] [blame] | 3357 | static int StopInfoCompare(const void *x,const void *y) |
| 3358 | { |
| 3359 | StopInfo |
| 3360 | *stop_1, |
| 3361 | *stop_2; |
| 3362 | |
| 3363 | stop_1=(StopInfo *) x; |
| 3364 | stop_2=(StopInfo *) y; |
dirk | b6f578b | 2015-07-12 17:56:39 +0000 | [diff] [blame] | 3365 | if (stop_1->offset > stop_2->offset) |
| 3366 | return(1); |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 3367 | if (fabs(stop_1->offset-stop_2->offset) <= DrawEpsilon) |
dirk | b6f578b | 2015-07-12 17:56:39 +0000 | [diff] [blame] | 3368 | return(0); |
| 3369 | return(-1); |
| 3370 | } |
| 3371 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3372 | MagickExport MagickBooleanType DrawGradientImage(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3373 | const DrawInfo *draw_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3374 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 3375 | CacheView |
| 3376 | *image_view; |
| 3377 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3378 | const GradientInfo |
| 3379 | *gradient; |
| 3380 | |
| 3381 | const SegmentInfo |
| 3382 | *gradient_vector; |
| 3383 | |
cristy | 75c658f | 2012-12-30 16:09:36 +0000 | [diff] [blame] | 3384 | double |
| 3385 | length; |
| 3386 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3387 | MagickBooleanType |
| 3388 | status; |
| 3389 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3390 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3391 | zero; |
| 3392 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3393 | PointInfo |
| 3394 | point; |
| 3395 | |
| 3396 | RectangleInfo |
| 3397 | bounding_box; |
| 3398 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 3399 | ssize_t |
| 3400 | y; |
| 3401 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3402 | /* |
| 3403 | Draw linear or radial gradient on image. |
| 3404 | */ |
| 3405 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 3406 | assert(image->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3407 | if (image->debug != MagickFalse) |
| 3408 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3409 | assert(draw_info != (const DrawInfo *) NULL); |
| 3410 | gradient=(&draw_info->gradient); |
dirk | b6f578b | 2015-07-12 17:56:39 +0000 | [diff] [blame] | 3411 | qsort(gradient->stops,gradient->number_stops,sizeof(StopInfo), |
| 3412 | StopInfoCompare); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3413 | gradient_vector=(&gradient->gradient_vector); |
| 3414 | point.x=gradient_vector->x2-gradient_vector->x1; |
| 3415 | point.y=gradient_vector->y2-gradient_vector->y1; |
| 3416 | length=sqrt(point.x*point.x+point.y*point.y); |
| 3417 | bounding_box=gradient->bounding_box; |
| 3418 | status=MagickTrue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3419 | GetPixelInfo(image,&zero); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 3420 | image_view=AcquireAuthenticCacheView(image,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3421 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 9a5a52f | 2012-10-09 14:40:31 +0000 | [diff] [blame] | 3422 | #pragma omp parallel for schedule(static,4) shared(status) \ |
cristy | cb7dfcc | 2013-01-06 18:34:59 +0000 | [diff] [blame] | 3423 | magick_threads(image,image,1,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3424 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3425 | for (y=bounding_box.y; y < (ssize_t) bounding_box.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3426 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3427 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3428 | composite, |
| 3429 | pixel; |
| 3430 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3431 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3432 | alpha, |
| 3433 | offset; |
| 3434 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3435 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 3436 | *magick_restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3437 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3438 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3439 | i, |
| 3440 | x; |
| 3441 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 3442 | ssize_t |
| 3443 | j; |
| 3444 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3445 | if (status == MagickFalse) |
| 3446 | continue; |
| 3447 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3448 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3449 | { |
| 3450 | status=MagickFalse; |
| 3451 | continue; |
| 3452 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3453 | pixel=zero; |
| 3454 | composite=zero; |
| 3455 | offset=GetStopColorOffset(gradient,0,y); |
| 3456 | if (gradient->type != RadialGradient) |
| 3457 | offset/=length; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3458 | for (x=bounding_box.x; x < (ssize_t) bounding_box.width; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3459 | { |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 3460 | GetPixelInfoPixel(image,q,&pixel); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3461 | switch (gradient->spread) |
| 3462 | { |
| 3463 | case UndefinedSpread: |
| 3464 | case PadSpread: |
| 3465 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3466 | if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) || |
| 3467 | (y != (ssize_t) ceil(gradient_vector->y1-0.5))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3468 | { |
| 3469 | offset=GetStopColorOffset(gradient,x,y); |
| 3470 | if (gradient->type != RadialGradient) |
| 3471 | offset/=length; |
| 3472 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3473 | for (i=0; i < (ssize_t) gradient->number_stops; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3474 | if (offset < gradient->stops[i].offset) |
| 3475 | break; |
| 3476 | if ((offset < 0.0) || (i == 0)) |
| 3477 | composite=gradient->stops[0].color; |
| 3478 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3479 | if ((offset > 1.0) || (i == (ssize_t) gradient->number_stops)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3480 | composite=gradient->stops[gradient->number_stops-1].color; |
| 3481 | else |
| 3482 | { |
| 3483 | j=i; |
| 3484 | i--; |
| 3485 | alpha=(offset-gradient->stops[i].offset)/ |
| 3486 | (gradient->stops[j].offset-gradient->stops[i].offset); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3487 | CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3488 | &gradient->stops[j].color,alpha,&composite); |
| 3489 | } |
| 3490 | break; |
| 3491 | } |
| 3492 | case ReflectSpread: |
| 3493 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3494 | if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) || |
| 3495 | (y != (ssize_t) ceil(gradient_vector->y1-0.5))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3496 | { |
| 3497 | offset=GetStopColorOffset(gradient,x,y); |
| 3498 | if (gradient->type != RadialGradient) |
| 3499 | offset/=length; |
| 3500 | } |
| 3501 | if (offset < 0.0) |
| 3502 | offset=(-offset); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3503 | if ((ssize_t) fmod(offset,2.0) == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3504 | offset=fmod(offset,1.0); |
| 3505 | else |
| 3506 | offset=1.0-fmod(offset,1.0); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3507 | for (i=0; i < (ssize_t) gradient->number_stops; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3508 | if (offset < gradient->stops[i].offset) |
| 3509 | break; |
| 3510 | if (i == 0) |
| 3511 | composite=gradient->stops[0].color; |
| 3512 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3513 | if (i == (ssize_t) gradient->number_stops) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3514 | composite=gradient->stops[gradient->number_stops-1].color; |
| 3515 | else |
| 3516 | { |
| 3517 | j=i; |
| 3518 | i--; |
| 3519 | alpha=(offset-gradient->stops[i].offset)/ |
| 3520 | (gradient->stops[j].offset-gradient->stops[i].offset); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3521 | CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3522 | &gradient->stops[j].color,alpha,&composite); |
| 3523 | } |
| 3524 | break; |
| 3525 | } |
| 3526 | case RepeatSpread: |
| 3527 | { |
| 3528 | MagickBooleanType |
| 3529 | antialias; |
| 3530 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3531 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3532 | repeat; |
| 3533 | |
| 3534 | antialias=MagickFalse; |
| 3535 | repeat=0.0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3536 | if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) || |
| 3537 | (y != (ssize_t) ceil(gradient_vector->y1-0.5))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3538 | { |
| 3539 | offset=GetStopColorOffset(gradient,x,y); |
| 3540 | if (gradient->type == LinearGradient) |
| 3541 | { |
| 3542 | repeat=fmod(offset,length); |
| 3543 | if (repeat < 0.0) |
| 3544 | repeat=length-fmod(-repeat,length); |
| 3545 | else |
| 3546 | repeat=fmod(offset,length); |
| 3547 | antialias=(repeat < length) && ((repeat+1.0) > length) ? |
| 3548 | MagickTrue : MagickFalse; |
| 3549 | offset=repeat/length; |
| 3550 | } |
| 3551 | else |
| 3552 | { |
| 3553 | repeat=fmod(offset,gradient->radius); |
| 3554 | if (repeat < 0.0) |
| 3555 | repeat=gradient->radius-fmod(-repeat,gradient->radius); |
| 3556 | else |
| 3557 | repeat=fmod(offset,gradient->radius); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3558 | antialias=repeat+1.0 > gradient->radius ? MagickTrue : |
| 3559 | MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3560 | offset=repeat/gradient->radius; |
| 3561 | } |
| 3562 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3563 | for (i=0; i < (ssize_t) gradient->number_stops; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3564 | if (offset < gradient->stops[i].offset) |
| 3565 | break; |
| 3566 | if (i == 0) |
| 3567 | composite=gradient->stops[0].color; |
| 3568 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3569 | if (i == (ssize_t) gradient->number_stops) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3570 | composite=gradient->stops[gradient->number_stops-1].color; |
| 3571 | else |
| 3572 | { |
| 3573 | j=i; |
| 3574 | i--; |
| 3575 | alpha=(offset-gradient->stops[i].offset)/ |
| 3576 | (gradient->stops[j].offset-gradient->stops[i].offset); |
| 3577 | if (antialias != MagickFalse) |
| 3578 | { |
| 3579 | if (gradient->type == LinearGradient) |
| 3580 | alpha=length-repeat; |
| 3581 | else |
| 3582 | alpha=gradient->radius-repeat; |
| 3583 | i=0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3584 | j=(ssize_t) gradient->number_stops-1L; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3585 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3586 | CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3587 | &gradient->stops[j].color,alpha,&composite); |
| 3588 | } |
| 3589 | break; |
| 3590 | } |
| 3591 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3592 | CompositePixelInfoOver(&composite,composite.alpha,&pixel,pixel.alpha, |
| 3593 | &pixel); |
cristy | 11a06d3 | 2015-01-04 12:03:27 +0000 | [diff] [blame] | 3594 | SetPixelViaPixelInfo(image,&pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3595 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3596 | } |
| 3597 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 3598 | status=MagickFalse; |
| 3599 | } |
| 3600 | image_view=DestroyCacheView(image_view); |
| 3601 | return(status); |
| 3602 | } |
| 3603 | |
| 3604 | /* |
| 3605 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3606 | % % |
| 3607 | % % |
| 3608 | % % |
| 3609 | % D r a w P a t t e r n P a t h % |
| 3610 | % % |
| 3611 | % % |
| 3612 | % % |
| 3613 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3614 | % |
| 3615 | % DrawPatternPath() draws a pattern. |
| 3616 | % |
| 3617 | % The format of the DrawPatternPath method is: |
| 3618 | % |
| 3619 | % MagickBooleanType DrawPatternPath(Image *image,const DrawInfo *draw_info, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 3620 | % const char *name,Image **pattern,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3621 | % |
| 3622 | % A description of each parameter follows: |
| 3623 | % |
| 3624 | % o image: the image. |
| 3625 | % |
| 3626 | % o draw_info: the draw info. |
| 3627 | % |
| 3628 | % o name: the pattern name. |
| 3629 | % |
| 3630 | % o image: the image. |
| 3631 | % |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 3632 | % o exception: return any errors or warnings in this structure. |
| 3633 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3634 | */ |
| 3635 | MagickExport MagickBooleanType DrawPatternPath(Image *image, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 3636 | const DrawInfo *draw_info,const char *name,Image **pattern, |
| 3637 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3638 | { |
| 3639 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 3640 | property[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3641 | |
| 3642 | const char |
| 3643 | *geometry, |
dirk | 84c7c04 | 2015-07-12 13:01:35 +0000 | [diff] [blame] | 3644 | *path, |
| 3645 | *type; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3646 | |
| 3647 | DrawInfo |
| 3648 | *clone_info; |
| 3649 | |
| 3650 | ImageInfo |
| 3651 | *image_info; |
| 3652 | |
| 3653 | MagickBooleanType |
| 3654 | status; |
| 3655 | |
| 3656 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 3657 | assert(image->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3658 | if (image->debug != MagickFalse) |
| 3659 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3660 | assert(draw_info != (const DrawInfo *) NULL); |
| 3661 | assert(name != (const char *) NULL); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 3662 | (void) FormatLocaleString(property,MagickPathExtent,"%s",name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3663 | path=GetImageArtifact(image,property); |
| 3664 | if (path == (const char *) NULL) |
| 3665 | return(MagickFalse); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 3666 | (void) FormatLocaleString(property,MagickPathExtent,"%s-geometry",name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3667 | geometry=GetImageArtifact(image,property); |
| 3668 | if (geometry == (const char *) NULL) |
| 3669 | return(MagickFalse); |
| 3670 | if ((*pattern) != (Image *) NULL) |
| 3671 | *pattern=DestroyImage(*pattern); |
| 3672 | image_info=AcquireImageInfo(); |
| 3673 | image_info->size=AcquireString(geometry); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3674 | *pattern=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3675 | image_info=DestroyImageInfo(image_info); |
cristy | ca61154 | 2013-02-19 00:54:03 +0000 | [diff] [blame] | 3676 | (void) QueryColorCompliance("#000000ff",AllCompliance, |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 3677 | &(*pattern)->background_color,exception); |
| 3678 | (void) SetImageBackgroundColor(*pattern,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3679 | if (image->debug != MagickFalse) |
| 3680 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
| 3681 | "begin pattern-path %s %s",name,geometry); |
| 3682 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 3683 | clone_info->fill_pattern=NewImageList(); |
| 3684 | clone_info->stroke_pattern=NewImageList(); |
dirk | 84c7c04 | 2015-07-12 13:01:35 +0000 | [diff] [blame] | 3685 | (void) FormatLocaleString(property,MagickPathExtent,"%s-type",name); |
| 3686 | type=GetImageArtifact(image,property); |
| 3687 | if (type != (const char *) NULL) |
| 3688 | clone_info->gradient.type=(GradientType) ParseCommandOption( |
| 3689 | MagickGradientOptions,MagickFalse,type); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3690 | (void) CloneString(&clone_info->primitive,path); |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 3691 | status=DrawImage(*pattern,clone_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3692 | clone_info=DestroyDrawInfo(clone_info); |
| 3693 | if (image->debug != MagickFalse) |
| 3694 | (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end pattern-path"); |
| 3695 | return(status); |
| 3696 | } |
| 3697 | |
| 3698 | /* |
| 3699 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3700 | % % |
| 3701 | % % |
| 3702 | % % |
| 3703 | + D r a w P o l y g o n P r i m i t i v e % |
| 3704 | % % |
| 3705 | % % |
| 3706 | % % |
| 3707 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3708 | % |
| 3709 | % DrawPolygonPrimitive() draws a polygon on the image. |
| 3710 | % |
| 3711 | % The format of the DrawPolygonPrimitive method is: |
| 3712 | % |
| 3713 | % MagickBooleanType DrawPolygonPrimitive(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3714 | % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info, |
| 3715 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3716 | % |
| 3717 | % A description of each parameter follows: |
| 3718 | % |
| 3719 | % o image: the image. |
| 3720 | % |
| 3721 | % o draw_info: the draw info. |
| 3722 | % |
| 3723 | % o primitive_info: Specifies a pointer to a PrimitiveInfo structure. |
| 3724 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3725 | % o exception: return any errors or warnings in this structure. |
| 3726 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3727 | */ |
| 3728 | |
| 3729 | static PolygonInfo **DestroyPolygonThreadSet(PolygonInfo **polygon_info) |
| 3730 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3731 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3732 | i; |
| 3733 | |
| 3734 | assert(polygon_info != (PolygonInfo **) NULL); |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 3735 | for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3736 | if (polygon_info[i] != (PolygonInfo *) NULL) |
| 3737 | polygon_info[i]=DestroyPolygonInfo(polygon_info[i]); |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 3738 | polygon_info=(PolygonInfo **) RelinquishMagickMemory(polygon_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3739 | return(polygon_info); |
| 3740 | } |
| 3741 | |
dirk | d2a7a2d | 2016-03-17 23:07:42 +0100 | [diff] [blame] | 3742 | static PolygonInfo **AcquirePolygonThreadSet( |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3743 | const PrimitiveInfo *primitive_info) |
| 3744 | { |
| 3745 | PathInfo |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 3746 | *magick_restrict path_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3747 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3748 | PolygonInfo |
| 3749 | **polygon_info; |
| 3750 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 3751 | register ssize_t |
| 3752 | i; |
| 3753 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3754 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3755 | number_threads; |
| 3756 | |
cristy | 9357bdd | 2012-07-30 12:28:34 +0000 | [diff] [blame] | 3757 | number_threads=(size_t) GetMagickResourceLimit(ThreadResource); |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 3758 | polygon_info=(PolygonInfo **) AcquireQuantumMemory(number_threads, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3759 | sizeof(*polygon_info)); |
| 3760 | if (polygon_info == (PolygonInfo **) NULL) |
| 3761 | return((PolygonInfo **) NULL); |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 3762 | (void) ResetMagickMemory(polygon_info,0,number_threads*sizeof(*polygon_info)); |
dirk | d2a7a2d | 2016-03-17 23:07:42 +0100 | [diff] [blame] | 3763 | path_info=ConvertPrimitiveToPath(primitive_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3764 | if (path_info == (PathInfo *) NULL) |
| 3765 | return(DestroyPolygonThreadSet(polygon_info)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3766 | for (i=0; i < (ssize_t) number_threads; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3767 | { |
dirk | d2a7a2d | 2016-03-17 23:07:42 +0100 | [diff] [blame] | 3768 | polygon_info[i]=ConvertPathToPolygon(path_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3769 | if (polygon_info[i] == (PolygonInfo *) NULL) |
| 3770 | return(DestroyPolygonThreadSet(polygon_info)); |
| 3771 | } |
| 3772 | path_info=(PathInfo *) RelinquishMagickMemory(path_info); |
| 3773 | return(polygon_info); |
| 3774 | } |
| 3775 | |
cristy | 884d162 | 2012-09-03 18:10:10 +0000 | [diff] [blame] | 3776 | static double GetFillAlpha(PolygonInfo *polygon_info,const double mid, |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3777 | const MagickBooleanType fill,const FillRule fill_rule,const ssize_t x, |
| 3778 | const ssize_t y,double *stroke_alpha) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3779 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3780 | double |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3781 | alpha, |
| 3782 | beta, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3783 | distance, |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3784 | subpath_alpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3785 | |
| 3786 | PointInfo |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3787 | delta; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3788 | |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3789 | register const PointInfo |
| 3790 | *q; |
| 3791 | |
cristy | 884d162 | 2012-09-03 18:10:10 +0000 | [diff] [blame] | 3792 | register EdgeInfo |
| 3793 | *p; |
| 3794 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3795 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3796 | i; |
| 3797 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 3798 | ssize_t |
| 3799 | j, |
| 3800 | winding_number; |
| 3801 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3802 | /* |
| 3803 | Compute fill & stroke opacity for this (x,y) point. |
| 3804 | */ |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3805 | *stroke_alpha=0.0; |
| 3806 | subpath_alpha=0.0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3807 | p=polygon_info->edges; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3808 | for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3809 | { |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3810 | if ((double) y <= (p->bounds.y1-mid-0.5)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3811 | break; |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3812 | if ((double) y > (p->bounds.y2+mid+0.5)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3813 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3814 | (void) DestroyEdge(polygon_info,(size_t) j); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3815 | continue; |
| 3816 | } |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3817 | if (((double) x <= (p->bounds.x1-mid-0.5)) || |
| 3818 | ((double) x > (p->bounds.x2+mid+0.5))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3819 | continue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3820 | i=(ssize_t) MagickMax((double) p->highwater,1.0); |
| 3821 | for ( ; i < (ssize_t) p->number_points; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3822 | { |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3823 | if ((double) y <= (p->points[i-1].y-mid-0.5)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3824 | break; |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3825 | if ((double) y > (p->points[i].y+mid+0.5)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3826 | continue; |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3827 | if (p->scanline != (double) y) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3828 | { |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3829 | p->scanline=(double) y; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3830 | p->highwater=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3831 | } |
| 3832 | /* |
| 3833 | Compute distance between a point and an edge. |
| 3834 | */ |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3835 | q=p->points+i-1; |
| 3836 | delta.x=(q+1)->x-q->x; |
| 3837 | delta.y=(q+1)->y-q->y; |
| 3838 | beta=delta.x*(x-q->x)+delta.y*(y-q->y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3839 | if (beta < 0.0) |
| 3840 | { |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3841 | delta.x=(double) x-q->x; |
| 3842 | delta.y=(double) y-q->y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3843 | distance=delta.x*delta.x+delta.y*delta.y; |
| 3844 | } |
| 3845 | else |
| 3846 | { |
| 3847 | alpha=delta.x*delta.x+delta.y*delta.y; |
| 3848 | if (beta > alpha) |
| 3849 | { |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3850 | delta.x=(double) x-(q+1)->x; |
| 3851 | delta.y=(double) y-(q+1)->y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3852 | distance=delta.x*delta.x+delta.y*delta.y; |
| 3853 | } |
| 3854 | else |
| 3855 | { |
cristy | 592aefd | 2013-02-03 15:41:39 +0000 | [diff] [blame] | 3856 | alpha=1.0/alpha; |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3857 | beta=delta.x*(y-q->y)-delta.y*(x-q->x); |
cristy | 4b67d75 | 2012-07-07 23:50:17 +0000 | [diff] [blame] | 3858 | distance=alpha*beta*beta; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3859 | } |
| 3860 | } |
| 3861 | /* |
| 3862 | Compute stroke & subpath opacity. |
| 3863 | */ |
| 3864 | beta=0.0; |
| 3865 | if (p->ghostline == MagickFalse) |
| 3866 | { |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3867 | alpha=mid+0.5; |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3868 | if ((*stroke_alpha < 1.0) && |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3869 | (distance <= ((alpha+0.25)*(alpha+0.25)))) |
| 3870 | { |
| 3871 | alpha=mid-0.5; |
| 3872 | if (distance <= ((alpha+0.25)*(alpha+0.25))) |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3873 | *stroke_alpha=1.0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3874 | else |
| 3875 | { |
| 3876 | beta=1.0; |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 3877 | if (fabs(distance-1.0) >= DrawEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3878 | beta=sqrt((double) distance); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3879 | alpha=beta-mid-0.5; |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3880 | if (*stroke_alpha < ((alpha-0.25)*(alpha-0.25))) |
| 3881 | *stroke_alpha=(alpha-0.25)*(alpha-0.25); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3882 | } |
| 3883 | } |
| 3884 | } |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3885 | if ((fill == MagickFalse) || (distance > 1.0) || (subpath_alpha >= 1.0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3886 | continue; |
| 3887 | if (distance <= 0.0) |
| 3888 | { |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3889 | subpath_alpha=1.0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3890 | continue; |
| 3891 | } |
| 3892 | if (distance > 1.0) |
| 3893 | continue; |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 3894 | if (fabs(beta) < DrawEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3895 | { |
| 3896 | beta=1.0; |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 3897 | if (fabs(distance-1.0) >= DrawEpsilon) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3898 | beta=sqrt(distance); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3899 | } |
| 3900 | alpha=beta-1.0; |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3901 | if (subpath_alpha < (alpha*alpha)) |
| 3902 | subpath_alpha=alpha*alpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3903 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3904 | } |
| 3905 | /* |
| 3906 | Compute fill opacity. |
| 3907 | */ |
| 3908 | if (fill == MagickFalse) |
| 3909 | return(0.0); |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3910 | if (subpath_alpha >= 1.0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3911 | return(1.0); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3912 | /* |
| 3913 | Determine winding number. |
| 3914 | */ |
| 3915 | winding_number=0; |
| 3916 | p=polygon_info->edges; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3917 | for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3918 | { |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3919 | if ((double) y <= p->bounds.y1) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3920 | break; |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3921 | if (((double) y > p->bounds.y2) || ((double) x <= p->bounds.x1)) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3922 | continue; |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3923 | if ((double) x > p->bounds.x2) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3924 | { |
| 3925 | winding_number+=p->direction ? 1 : -1; |
| 3926 | continue; |
| 3927 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3928 | i=(ssize_t) MagickMax((double) p->highwater,1.0); |
| 3929 | for ( ; i < (ssize_t) p->number_points; i++) |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3930 | if ((double) y <= p->points[i].y) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3931 | break; |
| 3932 | q=p->points+i-1; |
| 3933 | if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x))) |
| 3934 | winding_number+=p->direction ? 1 : -1; |
| 3935 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3936 | if (fill_rule != NonZeroRule) |
| 3937 | { |
| 3938 | if ((MagickAbsoluteValue(winding_number) & 0x01) != 0) |
| 3939 | return(1.0); |
| 3940 | } |
| 3941 | else |
| 3942 | if (MagickAbsoluteValue(winding_number) != 0) |
| 3943 | return(1.0); |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3944 | return(subpath_alpha); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3945 | } |
| 3946 | |
| 3947 | static MagickBooleanType DrawPolygonPrimitive(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3948 | const DrawInfo *draw_info,const PrimitiveInfo *primitive_info, |
| 3949 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3950 | { |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3951 | CacheView |
| 3952 | *image_view; |
| 3953 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3954 | MagickBooleanType |
| 3955 | fill, |
| 3956 | status; |
| 3957 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3958 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3959 | mid; |
| 3960 | |
| 3961 | PolygonInfo |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 3962 | **magick_restrict polygon_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3963 | |
| 3964 | register EdgeInfo |
| 3965 | *p; |
| 3966 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3967 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3968 | i; |
| 3969 | |
| 3970 | SegmentInfo |
| 3971 | bounds; |
| 3972 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 3973 | ssize_t |
dirk | 84c7c04 | 2015-07-12 13:01:35 +0000 | [diff] [blame] | 3974 | start_y, |
| 3975 | stop_y, |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 3976 | y; |
| 3977 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3978 | /* |
| 3979 | Compute bounding box. |
| 3980 | */ |
| 3981 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 3982 | assert(image->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3983 | if (image->debug != MagickFalse) |
| 3984 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3985 | assert(draw_info != (DrawInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 3986 | assert(draw_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3987 | assert(primitive_info != (PrimitiveInfo *) NULL); |
| 3988 | if (primitive_info->coordinates == 0) |
| 3989 | return(MagickTrue); |
dirk | d2a7a2d | 2016-03-17 23:07:42 +0100 | [diff] [blame] | 3990 | polygon_info=AcquirePolygonThreadSet(primitive_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3991 | if (polygon_info == (PolygonInfo **) NULL) |
| 3992 | return(MagickFalse); |
dirk | 93b02b7 | 2013-11-16 16:03:36 +0000 | [diff] [blame] | 3993 | DisableMSCWarning(4127) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3994 | if (0) |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3995 | DrawBoundingRectangles(image,draw_info,polygon_info[0],exception); |
dirk | 93b02b7 | 2013-11-16 16:03:36 +0000 | [diff] [blame] | 3996 | RestoreMSCWarning |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3997 | if (image->debug != MagickFalse) |
| 3998 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-polygon"); |
| 3999 | fill=(primitive_info->method == FillToBorderMethod) || |
| 4000 | (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse; |
| 4001 | mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0; |
| 4002 | bounds=polygon_info[0]->edges[0].bounds; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4003 | for (i=1; i < (ssize_t) polygon_info[0]->number_edges; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4004 | { |
| 4005 | p=polygon_info[0]->edges+i; |
| 4006 | if (p->bounds.x1 < bounds.x1) |
| 4007 | bounds.x1=p->bounds.x1; |
| 4008 | if (p->bounds.y1 < bounds.y1) |
| 4009 | bounds.y1=p->bounds.y1; |
| 4010 | if (p->bounds.x2 > bounds.x2) |
| 4011 | bounds.x2=p->bounds.x2; |
| 4012 | if (p->bounds.y2 > bounds.y2) |
| 4013 | bounds.y2=p->bounds.y2; |
| 4014 | } |
| 4015 | bounds.x1-=(mid+1.0); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4016 | bounds.x1=bounds.x1 < 0.0 ? 0.0 : (size_t) ceil(bounds.x1-0.5) >= |
cristy | 6c5494a | 2012-09-22 00:30:37 +0000 | [diff] [blame] | 4017 | image->columns ? (double) image->columns-1 : bounds.x1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4018 | bounds.y1-=(mid+1.0); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4019 | bounds.y1=bounds.y1 < 0.0 ? 0.0 : (size_t) ceil(bounds.y1-0.5) >= |
cristy | 6c5494a | 2012-09-22 00:30:37 +0000 | [diff] [blame] | 4020 | image->rows ? (double) image->rows-1 : bounds.y1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4021 | bounds.x2+=(mid+1.0); |
cristy | 8071c47 | 2012-09-24 12:41:06 +0000 | [diff] [blame] | 4022 | bounds.x2=bounds.x2 < 0.0 ? 0.0 : (size_t) floor(bounds.x2+0.5) >= |
cristy | 6c5494a | 2012-09-22 00:30:37 +0000 | [diff] [blame] | 4023 | image->columns ? (double) image->columns-1 : bounds.x2; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4024 | bounds.y2+=(mid+1.0); |
cristy | 8071c47 | 2012-09-24 12:41:06 +0000 | [diff] [blame] | 4025 | bounds.y2=bounds.y2 < 0.0 ? 0.0 : (size_t) floor(bounds.y2+0.5) >= |
cristy | 6c5494a | 2012-09-22 00:30:37 +0000 | [diff] [blame] | 4026 | image->rows ? (double) image->rows-1 : bounds.y2; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4027 | status=MagickTrue; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 4028 | image_view=AcquireAuthenticCacheView(image,exception); |
cristy | b8cb022 | 2015-05-05 11:25:32 +0000 | [diff] [blame] | 4029 | if ((primitive_info->coordinates == 1) || |
| 4030 | (polygon_info[0]->number_edges == 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4031 | { |
| 4032 | /* |
| 4033 | Draw point. |
| 4034 | */ |
dirk | 84c7c04 | 2015-07-12 13:01:35 +0000 | [diff] [blame] | 4035 | start_y=(ssize_t) ceil(bounds.y1-0.5); |
| 4036 | stop_y=(ssize_t) floor(bounds.y2+0.5); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 4037 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 9a5a52f | 2012-10-09 14:40:31 +0000 | [diff] [blame] | 4038 | #pragma omp parallel for schedule(static,4) shared(status) \ |
cristy | cb7dfcc | 2013-01-06 18:34:59 +0000 | [diff] [blame] | 4039 | magick_threads(image,image,1,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4040 | #endif |
dirk | 84c7c04 | 2015-07-12 13:01:35 +0000 | [diff] [blame] | 4041 | for (y=start_y; y <= stop_y; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4042 | { |
| 4043 | MagickBooleanType |
| 4044 | sync; |
| 4045 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4046 | PixelInfo |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4047 | pixel; |
| 4048 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4049 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4050 | x; |
| 4051 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4052 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 4053 | *magick_restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4054 | |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 4055 | ssize_t |
dirk | 84c7c04 | 2015-07-12 13:01:35 +0000 | [diff] [blame] | 4056 | start_x, |
| 4057 | stop_x; |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 4058 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4059 | if (status == MagickFalse) |
| 4060 | continue; |
dirk | 84c7c04 | 2015-07-12 13:01:35 +0000 | [diff] [blame] | 4061 | start_x=(ssize_t) ceil(bounds.x1-0.5); |
| 4062 | stop_x=(ssize_t) floor(bounds.x2+0.5); |
| 4063 | x=start_x; |
| 4064 | q=GetCacheViewAuthenticPixels(image_view,x,y,(size_t) (stop_x-x+1),1, |
cristy | f707b30 | 2012-09-04 23:51:26 +0000 | [diff] [blame] | 4065 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4066 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4067 | { |
| 4068 | status=MagickFalse; |
| 4069 | continue; |
| 4070 | } |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4071 | GetPixelInfo(image,&pixel); |
dirk | 84c7c04 | 2015-07-12 13:01:35 +0000 | [diff] [blame] | 4072 | for ( ; x <= stop_x; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4073 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4074 | if ((x == (ssize_t) ceil(primitive_info->point.x-0.5)) && |
| 4075 | (y == (ssize_t) ceil(primitive_info->point.y-0.5))) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4076 | { |
dirk | 50be538 | 2016-03-14 12:42:50 +0100 | [diff] [blame] | 4077 | GetFillColor(draw_info,x-start_x,y-start_y,&pixel,exception); |
cristy | 11a06d3 | 2015-01-04 12:03:27 +0000 | [diff] [blame] | 4078 | SetPixelViaPixelInfo(image,&pixel,q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4079 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4080 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4081 | } |
| 4082 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 4083 | if (sync == MagickFalse) |
| 4084 | status=MagickFalse; |
| 4085 | } |
| 4086 | image_view=DestroyCacheView(image_view); |
| 4087 | polygon_info=DestroyPolygonThreadSet(polygon_info); |
| 4088 | if (image->debug != MagickFalse) |
| 4089 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
| 4090 | " end draw-polygon"); |
| 4091 | return(status); |
| 4092 | } |
| 4093 | /* |
| 4094 | Draw polygon or line. |
| 4095 | */ |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 4096 | if (image->alpha_trait == UndefinedPixelTrait) |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 4097 | (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception); |
dirk | 84c7c04 | 2015-07-12 13:01:35 +0000 | [diff] [blame] | 4098 | start_y=(ssize_t) ceil(bounds.y1-0.5); |
| 4099 | stop_y=(ssize_t) floor(bounds.y2+0.5); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 4100 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 9a5a52f | 2012-10-09 14:40:31 +0000 | [diff] [blame] | 4101 | #pragma omp parallel for schedule(static,4) shared(status) \ |
cristy | cb7dfcc | 2013-01-06 18:34:59 +0000 | [diff] [blame] | 4102 | magick_threads(image,image,1,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4103 | #endif |
dirk | 84c7c04 | 2015-07-12 13:01:35 +0000 | [diff] [blame] | 4104 | for (y=start_y; y <= stop_y; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4105 | { |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 4106 | const int |
| 4107 | id = GetOpenMPThreadId(); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 4108 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4109 | double |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 4110 | fill_alpha, |
| 4111 | stroke_alpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4112 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4113 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4114 | fill_color, |
| 4115 | stroke_color; |
| 4116 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4117 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 4118 | *magick_restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4119 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 4120 | register ssize_t |
| 4121 | x; |
| 4122 | |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 4123 | ssize_t |
dirk | 84c7c04 | 2015-07-12 13:01:35 +0000 | [diff] [blame] | 4124 | start_x, |
| 4125 | stop_x; |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 4126 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4127 | if (status == MagickFalse) |
| 4128 | continue; |
dirk | 84c7c04 | 2015-07-12 13:01:35 +0000 | [diff] [blame] | 4129 | start_x=(ssize_t) ceil(bounds.x1-0.5); |
| 4130 | stop_x=(ssize_t) floor(bounds.x2+0.5); |
Cristy | dd6065a | 2016-09-19 15:55:49 -0400 | [diff] [blame] | 4131 | q=GetCacheViewAuthenticPixels(image_view,start_x,y,(size_t) (stop_x-start_x+ 1),1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4132 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4133 | { |
| 4134 | status=MagickFalse; |
| 4135 | continue; |
| 4136 | } |
dirk | 84c7c04 | 2015-07-12 13:01:35 +0000 | [diff] [blame] | 4137 | for (x=start_x; x <= stop_x; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4138 | { |
| 4139 | /* |
| 4140 | Fill and/or stroke. |
| 4141 | */ |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 4142 | fill_alpha=GetFillAlpha(polygon_info[id],mid,fill,draw_info->fill_rule, |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 4143 | x,y,&stroke_alpha); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4144 | if (draw_info->stroke_antialias == MagickFalse) |
| 4145 | { |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 4146 | fill_alpha=fill_alpha > 0.25 ? 1.0 : 0.0; |
| 4147 | stroke_alpha=stroke_alpha > 0.25 ? 1.0 : 0.0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4148 | } |
dirk | 50be538 | 2016-03-14 12:42:50 +0100 | [diff] [blame] | 4149 | GetFillColor(draw_info,x-start_x,y-start_y,&fill_color,exception); |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 4150 | fill_alpha=fill_alpha*fill_color.alpha; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4151 | CompositePixelOver(image,&fill_color,fill_alpha,q,(double) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4152 | GetPixelAlpha(image,q),q); |
dirk | 50be538 | 2016-03-14 12:42:50 +0100 | [diff] [blame] | 4153 | GetStrokeColor(draw_info,x-start_x,y-start_y,&stroke_color,exception); |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 4154 | stroke_alpha=stroke_alpha*stroke_color.alpha; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4155 | CompositePixelOver(image,&stroke_color,stroke_alpha,q,(double) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4156 | GetPixelAlpha(image,q),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4157 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4158 | } |
| 4159 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 4160 | status=MagickFalse; |
| 4161 | } |
| 4162 | image_view=DestroyCacheView(image_view); |
| 4163 | polygon_info=DestroyPolygonThreadSet(polygon_info); |
| 4164 | if (image->debug != MagickFalse) |
| 4165 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-polygon"); |
| 4166 | return(status); |
| 4167 | } |
| 4168 | |
| 4169 | /* |
| 4170 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4171 | % % |
| 4172 | % % |
| 4173 | % % |
| 4174 | % D r a w P r i m i t i v e % |
| 4175 | % % |
| 4176 | % % |
| 4177 | % % |
| 4178 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4179 | % |
| 4180 | % DrawPrimitive() draws a primitive (line, rectangle, ellipse) on the image. |
| 4181 | % |
| 4182 | % The format of the DrawPrimitive method is: |
| 4183 | % |
| 4184 | % MagickBooleanType DrawPrimitive(Image *image,const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4185 | % PrimitiveInfo *primitive_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4186 | % |
| 4187 | % A description of each parameter follows: |
| 4188 | % |
| 4189 | % o image: the image. |
| 4190 | % |
| 4191 | % o draw_info: the draw info. |
| 4192 | % |
| 4193 | % o primitive_info: Specifies a pointer to a PrimitiveInfo structure. |
| 4194 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4195 | % o exception: return any errors or warnings in this structure. |
| 4196 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4197 | */ |
| 4198 | |
| 4199 | static void LogPrimitiveInfo(const PrimitiveInfo *primitive_info) |
| 4200 | { |
| 4201 | const char |
| 4202 | *methods[] = |
| 4203 | { |
| 4204 | "point", |
| 4205 | "replace", |
| 4206 | "floodfill", |
| 4207 | "filltoborder", |
| 4208 | "reset", |
| 4209 | "?" |
| 4210 | }; |
| 4211 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4212 | PointInfo |
| 4213 | p, |
| 4214 | q, |
| 4215 | point; |
| 4216 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4217 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4218 | i, |
| 4219 | x; |
| 4220 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 4221 | ssize_t |
| 4222 | coordinates, |
| 4223 | y; |
| 4224 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4225 | x=(ssize_t) ceil(primitive_info->point.x-0.5); |
| 4226 | y=(ssize_t) ceil(primitive_info->point.y-0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4227 | switch (primitive_info->primitive) |
| 4228 | { |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4229 | case AlphaPrimitive: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4230 | { |
| 4231 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4232 | "AlphaPrimitive %.20g,%.20g %s",(double) x,(double) y, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4233 | methods[primitive_info->method]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4234 | return; |
| 4235 | } |
| 4236 | case ColorPrimitive: |
| 4237 | { |
| 4238 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4239 | "ColorPrimitive %.20g,%.20g %s",(double) x,(double) y, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4240 | methods[primitive_info->method]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4241 | return; |
| 4242 | } |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4243 | case ImagePrimitive: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4244 | { |
| 4245 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4246 | "ImagePrimitive %.20g,%.20g",(double) x,(double) y); |
| 4247 | return; |
| 4248 | } |
| 4249 | case PointPrimitive: |
| 4250 | { |
| 4251 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
| 4252 | "PointPrimitive %.20g,%.20g %s",(double) x,(double) y, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4253 | methods[primitive_info->method]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4254 | return; |
| 4255 | } |
| 4256 | case TextPrimitive: |
| 4257 | { |
| 4258 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4259 | "TextPrimitive %.20g,%.20g",(double) x,(double) y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4260 | return; |
| 4261 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4262 | default: |
| 4263 | break; |
| 4264 | } |
| 4265 | coordinates=0; |
| 4266 | p=primitive_info[0].point; |
| 4267 | q.x=(-1.0); |
| 4268 | q.y=(-1.0); |
| 4269 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) |
| 4270 | { |
| 4271 | point=primitive_info[i].point; |
| 4272 | if (coordinates <= 0) |
| 4273 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4274 | coordinates=(ssize_t) primitive_info[i].coordinates; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4275 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4276 | " begin open (%.20g)",(double) coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4277 | p=point; |
| 4278 | } |
| 4279 | point=primitive_info[i].point; |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 4280 | if ((fabs(q.x-point.x) >= DrawEpsilon) || |
| 4281 | (fabs(q.y-point.y) >= DrawEpsilon)) |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 4282 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4283 | " %.20g: %.18g,%.18g",(double) coordinates,point.x,point.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4284 | else |
| 4285 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | 14388de | 2011-05-15 14:57:16 +0000 | [diff] [blame] | 4286 | " %.20g: %g %g (duplicate)",(double) coordinates,point.x,point.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4287 | q=point; |
| 4288 | coordinates--; |
| 4289 | if (coordinates > 0) |
| 4290 | continue; |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 4291 | if ((fabs(p.x-point.x) >= DrawEpsilon) || |
| 4292 | (fabs(p.y-point.y) >= DrawEpsilon)) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4293 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end last (%.20g)", |
| 4294 | (double) coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4295 | else |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4296 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end open (%.20g)", |
| 4297 | (double) coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4298 | } |
| 4299 | } |
| 4300 | |
| 4301 | MagickExport MagickBooleanType DrawPrimitive(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4302 | const DrawInfo *draw_info,const PrimitiveInfo *primitive_info, |
| 4303 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4304 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 4305 | CacheView |
| 4306 | *image_view; |
| 4307 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4308 | MagickStatusType |
| 4309 | status; |
| 4310 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4311 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4312 | i, |
| 4313 | x; |
| 4314 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 4315 | ssize_t |
| 4316 | y; |
| 4317 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4318 | if (image->debug != MagickFalse) |
| 4319 | { |
| 4320 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
| 4321 | " begin draw-primitive"); |
| 4322 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 4323 | " affine: %g,%g,%g,%g,%g,%g",draw_info->affine.sx, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4324 | draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy, |
| 4325 | draw_info->affine.tx,draw_info->affine.ty); |
| 4326 | } |
cristy | a6400b1 | 2013-03-15 12:20:18 +0000 | [diff] [blame] | 4327 | if ((IsGrayColorspace(image->colorspace) != MagickFalse) && |
cristy | 4dab380 | 2013-03-15 22:08:15 +0000 | [diff] [blame] | 4328 | ((IsPixelInfoGray(&draw_info->fill) == MagickFalse) || |
| 4329 | (IsPixelInfoGray(&draw_info->stroke) == MagickFalse))) |
cristy | 0c81d06 | 2013-04-21 15:22:02 +0000 | [diff] [blame] | 4330 | (void) SetImageColorspace(image,sRGBColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4331 | status=MagickTrue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4332 | x=(ssize_t) ceil(primitive_info->point.x-0.5); |
| 4333 | y=(ssize_t) ceil(primitive_info->point.y-0.5); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 4334 | image_view=AcquireAuthenticCacheView(image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4335 | switch (primitive_info->primitive) |
| 4336 | { |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4337 | case AlphaPrimitive: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4338 | { |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 4339 | if (image->alpha_trait == UndefinedPixelTrait) |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 4340 | (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4341 | switch (primitive_info->method) |
| 4342 | { |
| 4343 | case PointMethod: |
| 4344 | default: |
| 4345 | { |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4346 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4347 | pixel; |
| 4348 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4349 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4350 | *q; |
| 4351 | |
| 4352 | q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4353 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4354 | break; |
dirk | 50be538 | 2016-03-14 12:42:50 +0100 | [diff] [blame] | 4355 | GetFillColor(draw_info,x,y,&pixel,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 4356 | SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4357 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
| 4358 | break; |
| 4359 | } |
| 4360 | case ReplaceMethod: |
| 4361 | { |
| 4362 | MagickBooleanType |
| 4363 | sync; |
| 4364 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4365 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4366 | pixel, |
| 4367 | target; |
| 4368 | |
cristy | f05d494 | 2012-03-17 16:26:09 +0000 | [diff] [blame] | 4369 | (void) GetOneCacheViewVirtualPixelInfo(image_view,x,y,&target, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4370 | exception); |
cristy | f2a82ee | 2014-05-26 17:49:54 +0000 | [diff] [blame] | 4371 | GetPixelInfo(image,&pixel); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4372 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4373 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4374 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 4375 | *magick_restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4376 | |
| 4377 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, |
| 4378 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4379 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4380 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4381 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4382 | { |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4383 | GetPixelInfoPixel(image,q,&pixel); |
| 4384 | if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4385 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4386 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4387 | continue; |
| 4388 | } |
dirk | 50be538 | 2016-03-14 12:42:50 +0100 | [diff] [blame] | 4389 | GetFillColor(draw_info,x,y,&pixel,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 4390 | SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4391 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4392 | } |
| 4393 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 4394 | if (sync == MagickFalse) |
| 4395 | break; |
| 4396 | } |
| 4397 | break; |
| 4398 | } |
| 4399 | case FloodfillMethod: |
| 4400 | case FillToBorderMethod: |
| 4401 | { |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 4402 | ChannelType |
| 4403 | channel_mask; |
| 4404 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4405 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4406 | target; |
| 4407 | |
cristy | 3aa9375 | 2011-12-18 15:54:24 +0000 | [diff] [blame] | 4408 | (void) GetOneVirtualPixelInfo(image,TileVirtualPixelMethod,x,y, |
cristy | 5201002 | 2011-10-21 18:07:37 +0000 | [diff] [blame] | 4409 | &target,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4410 | if (primitive_info->method == FillToBorderMethod) |
| 4411 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4412 | target.red=(double) draw_info->border_color.red; |
| 4413 | target.green=(double) draw_info->border_color.green; |
| 4414 | target.blue=(double) draw_info->border_color.blue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4415 | } |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4416 | channel_mask=SetImageChannelMask(image,AlphaChannel); |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4417 | status&=FloodfillPaintImage(image,draw_info,&target,x,y, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4418 | primitive_info->method == FloodfillMethod ? MagickFalse : |
cristy | 189e84c | 2011-08-27 18:08:53 +0000 | [diff] [blame] | 4419 | MagickTrue,exception); |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4420 | (void) SetImageChannelMask(image,channel_mask); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4421 | break; |
| 4422 | } |
| 4423 | case ResetMethod: |
| 4424 | { |
| 4425 | MagickBooleanType |
| 4426 | sync; |
| 4427 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4428 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4429 | pixel; |
| 4430 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4431 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4432 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4433 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 4434 | *magick_restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4435 | |
| 4436 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, |
| 4437 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4438 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4439 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4440 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4441 | { |
dirk | 50be538 | 2016-03-14 12:42:50 +0100 | [diff] [blame] | 4442 | GetFillColor(draw_info,x,y,&pixel,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 4443 | SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4444 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4445 | } |
| 4446 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 4447 | if (sync == MagickFalse) |
| 4448 | break; |
| 4449 | } |
| 4450 | break; |
| 4451 | } |
| 4452 | } |
| 4453 | break; |
| 4454 | } |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4455 | case ColorPrimitive: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4456 | { |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4457 | switch (primitive_info->method) |
| 4458 | { |
| 4459 | case PointMethod: |
| 4460 | default: |
| 4461 | { |
| 4462 | PixelInfo |
| 4463 | pixel; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4464 | |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4465 | register Quantum |
| 4466 | *q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4467 | |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4468 | q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception); |
| 4469 | if (q == (Quantum *) NULL) |
| 4470 | break; |
| 4471 | GetPixelInfo(image,&pixel); |
dirk | 50be538 | 2016-03-14 12:42:50 +0100 | [diff] [blame] | 4472 | GetFillColor(draw_info,x,y,&pixel,exception); |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4473 | SetPixelViaPixelInfo(image,&pixel,q); |
| 4474 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
| 4475 | break; |
| 4476 | } |
| 4477 | case ReplaceMethod: |
| 4478 | { |
| 4479 | MagickBooleanType |
| 4480 | sync; |
| 4481 | |
| 4482 | PixelInfo |
| 4483 | pixel, |
| 4484 | target; |
| 4485 | |
| 4486 | (void) GetOneCacheViewVirtualPixelInfo(image_view,x,y,&target, |
| 4487 | exception); |
| 4488 | for (y=0; y < (ssize_t) image->rows; y++) |
| 4489 | { |
| 4490 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 4491 | *magick_restrict q; |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4492 | |
| 4493 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, |
| 4494 | exception); |
| 4495 | if (q == (Quantum *) NULL) |
| 4496 | break; |
| 4497 | for (x=0; x < (ssize_t) image->columns; x++) |
| 4498 | { |
| 4499 | GetPixelInfoPixel(image,q,&pixel); |
| 4500 | if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse) |
| 4501 | { |
| 4502 | q+=GetPixelChannels(image); |
| 4503 | continue; |
| 4504 | } |
dirk | 50be538 | 2016-03-14 12:42:50 +0100 | [diff] [blame] | 4505 | GetFillColor(draw_info,x,y,&pixel,exception); |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4506 | SetPixelViaPixelInfo(image,&pixel,q); |
| 4507 | q+=GetPixelChannels(image); |
| 4508 | } |
| 4509 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 4510 | if (sync == MagickFalse) |
| 4511 | break; |
| 4512 | } |
| 4513 | break; |
| 4514 | } |
| 4515 | case FloodfillMethod: |
| 4516 | case FillToBorderMethod: |
| 4517 | { |
| 4518 | PixelInfo |
| 4519 | target; |
| 4520 | |
| 4521 | (void) GetOneVirtualPixelInfo(image,TileVirtualPixelMethod,x,y, |
| 4522 | &target,exception); |
| 4523 | if (primitive_info->method == FillToBorderMethod) |
| 4524 | { |
| 4525 | target.red=(double) draw_info->border_color.red; |
| 4526 | target.green=(double) draw_info->border_color.green; |
| 4527 | target.blue=(double) draw_info->border_color.blue; |
| 4528 | } |
| 4529 | status&=FloodfillPaintImage(image,draw_info,&target,x,y, |
| 4530 | primitive_info->method == FloodfillMethod ? MagickFalse : |
| 4531 | MagickTrue,exception); |
| 4532 | break; |
| 4533 | } |
| 4534 | case ResetMethod: |
| 4535 | { |
| 4536 | MagickBooleanType |
| 4537 | sync; |
| 4538 | |
| 4539 | PixelInfo |
| 4540 | pixel; |
| 4541 | |
| 4542 | GetPixelInfo(image,&pixel); |
| 4543 | for (y=0; y < (ssize_t) image->rows; y++) |
| 4544 | { |
| 4545 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 4546 | *magick_restrict q; |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4547 | |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4548 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, |
| 4549 | exception); |
| 4550 | if (q == (Quantum *) NULL) |
| 4551 | break; |
| 4552 | for (x=0; x < (ssize_t) image->columns; x++) |
| 4553 | { |
dirk | 50be538 | 2016-03-14 12:42:50 +0100 | [diff] [blame] | 4554 | GetFillColor(draw_info,x,y,&pixel,exception); |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4555 | SetPixelViaPixelInfo(image,&pixel,q); |
| 4556 | q+=GetPixelChannels(image); |
| 4557 | } |
| 4558 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 4559 | if (sync == MagickFalse) |
| 4560 | break; |
| 4561 | } |
| 4562 | break; |
| 4563 | } |
| 4564 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4565 | break; |
| 4566 | } |
| 4567 | case ImagePrimitive: |
| 4568 | { |
| 4569 | AffineMatrix |
| 4570 | affine; |
| 4571 | |
| 4572 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 4573 | composite_geometry[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4574 | |
| 4575 | Image |
| 4576 | *composite_image; |
| 4577 | |
| 4578 | ImageInfo |
| 4579 | *clone_info; |
| 4580 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 4581 | RectangleInfo |
| 4582 | geometry; |
| 4583 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4584 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4585 | x1, |
| 4586 | y1; |
| 4587 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4588 | if (primitive_info->text == (char *) NULL) |
| 4589 | break; |
| 4590 | clone_info=AcquireImageInfo(); |
| 4591 | if (LocaleNCompare(primitive_info->text,"data:",5) == 0) |
| 4592 | composite_image=ReadInlineImage(clone_info,primitive_info->text, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4593 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4594 | else |
| 4595 | { |
| 4596 | (void) CopyMagickString(clone_info->filename,primitive_info->text, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 4597 | MagickPathExtent); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4598 | composite_image=ReadImage(clone_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4599 | } |
| 4600 | clone_info=DestroyImageInfo(clone_info); |
| 4601 | if (composite_image == (Image *) NULL) |
| 4602 | break; |
| 4603 | (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor) |
| 4604 | NULL,(void *) NULL); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4605 | x1=(ssize_t) ceil(primitive_info[1].point.x-0.5); |
| 4606 | y1=(ssize_t) ceil(primitive_info[1].point.y-0.5); |
| 4607 | if (((x1 != 0L) && (x1 != (ssize_t) composite_image->columns)) || |
| 4608 | ((y1 != 0L) && (y1 != (ssize_t) composite_image->rows))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4609 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4610 | /* |
| 4611 | Resize image. |
| 4612 | */ |
dirk | c93932a | 2015-10-01 16:56:10 +0200 | [diff] [blame] | 4613 | (void) FormatLocaleString(composite_geometry,MagickPathExtent, |
| 4614 | "%gx%g!",primitive_info[1].point.x,primitive_info[1].point.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4615 | composite_image->filter=image->filter; |
dirk | c93932a | 2015-10-01 16:56:10 +0200 | [diff] [blame] | 4616 | (void) TransformImage(&composite_image,(char *) NULL, |
| 4617 | composite_geometry,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4618 | } |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 4619 | if (composite_image->alpha_trait == UndefinedPixelTrait) |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 4620 | (void) SetImageAlphaChannel(composite_image,OpaqueAlphaChannel, |
| 4621 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4622 | if (draw_info->alpha != OpaqueAlpha) |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 4623 | (void) SetImageAlpha(composite_image,draw_info->alpha,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4624 | SetGeometry(image,&geometry); |
| 4625 | image->gravity=draw_info->gravity; |
| 4626 | geometry.x=x; |
| 4627 | geometry.y=y; |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 4628 | (void) FormatLocaleString(composite_geometry,MagickPathExtent, |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 4629 | "%.20gx%.20g%+.20g%+.20g",(double) composite_image->columns,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4630 | composite_image->rows,(double) geometry.x,(double) geometry.y); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4631 | (void) ParseGravityGeometry(image,composite_geometry,&geometry,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4632 | affine=draw_info->affine; |
| 4633 | affine.tx=(double) geometry.x; |
| 4634 | affine.ty=(double) geometry.y; |
| 4635 | composite_image->interpolate=image->interpolate; |
cristy | d5f3fc3 | 2011-04-26 14:44:36 +0000 | [diff] [blame] | 4636 | if (draw_info->compose == OverCompositeOp) |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4637 | (void) DrawAffineImage(image,composite_image,&affine,exception); |
cristy | d5f3fc3 | 2011-04-26 14:44:36 +0000 | [diff] [blame] | 4638 | else |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 4639 | (void) CompositeImage(image,composite_image,draw_info->compose, |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 4640 | MagickTrue,geometry.x,geometry.y,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4641 | composite_image=DestroyImage(composite_image); |
| 4642 | break; |
| 4643 | } |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4644 | case PointPrimitive: |
| 4645 | { |
| 4646 | PixelInfo |
| 4647 | fill_color; |
| 4648 | |
| 4649 | register Quantum |
| 4650 | *q; |
| 4651 | |
| 4652 | if ((y < 0) || (y >= (ssize_t) image->rows)) |
| 4653 | break; |
| 4654 | if ((x < 0) || (x >= (ssize_t) image->columns)) |
| 4655 | break; |
| 4656 | q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception); |
| 4657 | if (q == (Quantum *) NULL) |
| 4658 | break; |
dirk | 50be538 | 2016-03-14 12:42:50 +0100 | [diff] [blame] | 4659 | GetFillColor(draw_info,x,y,&fill_color,exception); |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4660 | CompositePixelOver(image,&fill_color,(double) fill_color.alpha,q, |
| 4661 | (double) GetPixelAlpha(image,q),q); |
| 4662 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
| 4663 | break; |
| 4664 | } |
| 4665 | case TextPrimitive: |
| 4666 | { |
| 4667 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 4668 | geometry[MagickPathExtent]; |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4669 | |
| 4670 | DrawInfo |
| 4671 | *clone_info; |
| 4672 | |
| 4673 | if (primitive_info->text == (char *) NULL) |
| 4674 | break; |
| 4675 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 4676 | (void) CloneString(&clone_info->text,primitive_info->text); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 4677 | (void) FormatLocaleString(geometry,MagickPathExtent,"%+f%+f", |
dirk | 34e1a21 | 2015-03-22 16:45:12 +0000 | [diff] [blame] | 4678 | primitive_info->point.x,primitive_info->point.y); |
| 4679 | (void) CloneString(&clone_info->geometry,geometry); |
| 4680 | status&=AnnotateImage(image,clone_info,exception); |
| 4681 | clone_info=DestroyDrawInfo(clone_info); |
| 4682 | break; |
| 4683 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4684 | default: |
| 4685 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4686 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4687 | mid, |
| 4688 | scale; |
| 4689 | |
| 4690 | DrawInfo |
| 4691 | *clone_info; |
| 4692 | |
| 4693 | if (IsEventLogging() != MagickFalse) |
| 4694 | LogPrimitiveInfo(primitive_info); |
| 4695 | scale=ExpandAffine(&draw_info->affine); |
| 4696 | if ((draw_info->dash_pattern != (double *) NULL) && |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 4697 | (fabs(draw_info->dash_pattern[0]) >= DrawEpsilon) && |
Cristy | 67d73ab | 2016-06-25 17:07:21 -0400 | [diff] [blame] | 4698 | (fabs(scale*draw_info->stroke_width) >= DrawEpsilon) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4699 | (draw_info->stroke.alpha != (Quantum) TransparentAlpha)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4700 | { |
| 4701 | /* |
| 4702 | Draw dash polygon. |
| 4703 | */ |
| 4704 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 4705 | clone_info->stroke_width=0.0; |
Cristy | 726812f | 2016-05-04 19:09:35 -0400 | [diff] [blame] | 4706 | clone_info->stroke.alpha=(MagickRealType) TransparentAlpha; |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4707 | status&=DrawPolygonPrimitive(image,clone_info,primitive_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4708 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4709 | clone_info=DestroyDrawInfo(clone_info); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4710 | (void) DrawDashPolygon(draw_info,primitive_info,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4711 | break; |
| 4712 | } |
| 4713 | mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0; |
dirk | 4d928fd | 2016-03-15 18:36:10 +0100 | [diff] [blame] | 4714 | if ((mid > 1.0) && |
| 4715 | ((draw_info->stroke.alpha != (Quantum) TransparentAlpha) || |
| 4716 | (draw_info->stroke_pattern != (Image *) NULL))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4717 | { |
| 4718 | MagickBooleanType |
| 4719 | closed_path; |
| 4720 | |
| 4721 | /* |
| 4722 | Draw strokes while respecting line cap/join attributes. |
| 4723 | */ |
| 4724 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ; |
| 4725 | closed_path= |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 4726 | (fabs(primitive_info[i-1].point.x-primitive_info[0].point.x) < DrawEpsilon) && |
| 4727 | (fabs(primitive_info[i-1].point.y-primitive_info[0].point.y) < DrawEpsilon) ? |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4728 | MagickTrue : MagickFalse; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4729 | i=(ssize_t) primitive_info[0].coordinates; |
Cristy | ebe99d0 | 2016-07-06 10:02:05 -0400 | [diff] [blame] | 4730 | if (((closed_path != MagickFalse) && |
| 4731 | (draw_info->linejoin == RoundJoin)) || |
| 4732 | (primitive_info[i].primitive != UndefinedPrimitive)) |
| 4733 | { |
| 4734 | (void) DrawPolygonPrimitive(image,draw_info,primitive_info, |
| 4735 | exception); |
| 4736 | break; |
| 4737 | } |
| 4738 | if (draw_info->linecap == RoundCap) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4739 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4740 | (void) DrawPolygonPrimitive(image,draw_info,primitive_info, |
| 4741 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4742 | break; |
| 4743 | } |
| 4744 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 4745 | clone_info->stroke_width=0.0; |
Cristy | 726812f | 2016-05-04 19:09:35 -0400 | [diff] [blame] | 4746 | clone_info->stroke.alpha=(MagickRealType) TransparentAlpha; |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4747 | status&=DrawPolygonPrimitive(image,clone_info,primitive_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4748 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4749 | clone_info=DestroyDrawInfo(clone_info); |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4750 | status&=DrawStrokePolygon(image,draw_info,primitive_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4751 | break; |
| 4752 | } |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4753 | status&=DrawPolygonPrimitive(image,draw_info,primitive_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4754 | break; |
| 4755 | } |
| 4756 | } |
| 4757 | image_view=DestroyCacheView(image_view); |
| 4758 | if (image->debug != MagickFalse) |
| 4759 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-primitive"); |
| 4760 | return(status != 0 ? MagickTrue : MagickFalse); |
| 4761 | } |
| 4762 | |
| 4763 | /* |
| 4764 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4765 | % % |
| 4766 | % % |
| 4767 | % % |
| 4768 | + D r a w S t r o k e P o l y g o n % |
| 4769 | % % |
| 4770 | % % |
| 4771 | % % |
| 4772 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4773 | % |
| 4774 | % DrawStrokePolygon() draws a stroked polygon (line, rectangle, ellipse) on |
| 4775 | % the image while respecting the line cap and join attributes. |
| 4776 | % |
| 4777 | % The format of the DrawStrokePolygon method is: |
| 4778 | % |
| 4779 | % MagickBooleanType DrawStrokePolygon(Image *image, |
| 4780 | % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info) |
| 4781 | % |
| 4782 | % A description of each parameter follows: |
| 4783 | % |
| 4784 | % o image: the image. |
| 4785 | % |
| 4786 | % o draw_info: the draw info. |
| 4787 | % |
| 4788 | % o primitive_info: Specifies a pointer to a PrimitiveInfo structure. |
| 4789 | % |
| 4790 | % |
| 4791 | */ |
| 4792 | |
| 4793 | static void DrawRoundLinecap(Image *image,const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4794 | const PrimitiveInfo *primitive_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4795 | { |
| 4796 | PrimitiveInfo |
| 4797 | linecap[5]; |
| 4798 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4799 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4800 | i; |
| 4801 | |
| 4802 | for (i=0; i < 4; i++) |
| 4803 | linecap[i]=(*primitive_info); |
| 4804 | linecap[0].coordinates=4; |
Cristy | c1f3dad | 2016-06-24 19:39:49 -0400 | [diff] [blame] | 4805 | linecap[1].point.x+=2.0*DrawEpsilon; |
| 4806 | linecap[2].point.x+=2.0*DrawEpsilon; |
| 4807 | linecap[2].point.y+=2.0*DrawEpsilon; |
| 4808 | linecap[3].point.y+=2.0*DrawEpsilon; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4809 | linecap[4].primitive=UndefinedPrimitive; |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4810 | (void) DrawPolygonPrimitive(image,draw_info,linecap,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4811 | } |
| 4812 | |
| 4813 | static MagickBooleanType DrawStrokePolygon(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4814 | const DrawInfo *draw_info,const PrimitiveInfo *primitive_info, |
| 4815 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4816 | { |
| 4817 | DrawInfo |
| 4818 | *clone_info; |
| 4819 | |
| 4820 | MagickBooleanType |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4821 | closed_path; |
| 4822 | |
| 4823 | MagickStatusType |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4824 | status; |
| 4825 | |
| 4826 | PrimitiveInfo |
| 4827 | *stroke_polygon; |
| 4828 | |
| 4829 | register const PrimitiveInfo |
| 4830 | *p, |
| 4831 | *q; |
| 4832 | |
| 4833 | /* |
| 4834 | Draw stroked polygon. |
| 4835 | */ |
| 4836 | if (image->debug != MagickFalse) |
| 4837 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
| 4838 | " begin draw-stroke-polygon"); |
| 4839 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 4840 | clone_info->fill=draw_info->stroke; |
cristy | 2d2d562 | 2012-01-19 19:11:29 +0000 | [diff] [blame] | 4841 | if (clone_info->fill_pattern != (Image *) NULL) |
| 4842 | clone_info->fill_pattern=DestroyImage(clone_info->fill_pattern); |
cristy | 2195b75 | 2012-01-19 16:04:04 +0000 | [diff] [blame] | 4843 | if (clone_info->stroke_pattern != (Image *) NULL) |
cristy | 2d2d562 | 2012-01-19 19:11:29 +0000 | [diff] [blame] | 4844 | clone_info->fill_pattern=CloneImage(clone_info->stroke_pattern,0,0, |
| 4845 | MagickTrue,exception); |
Cristy | 726812f | 2016-05-04 19:09:35 -0400 | [diff] [blame] | 4846 | clone_info->stroke.alpha=(MagickRealType) TransparentAlpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4847 | clone_info->stroke_width=0.0; |
| 4848 | clone_info->fill_rule=NonZeroRule; |
| 4849 | status=MagickTrue; |
| 4850 | for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=p->coordinates) |
| 4851 | { |
| 4852 | stroke_polygon=TraceStrokePolygon(draw_info,p); |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4853 | status&=DrawPolygonPrimitive(image,clone_info,stroke_polygon,exception); |
| 4854 | if (status == 0) |
| 4855 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4856 | stroke_polygon=(PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon); |
| 4857 | q=p+p->coordinates-1; |
Cristy | 48bcfe0 | 2016-07-13 18:05:02 -0400 | [diff] [blame] | 4858 | closed_path=(fabs(q->point.x-p->point.x) < DrawEpsilon) && |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 4859 | (fabs(q->point.y-p->point.y) < DrawEpsilon) ? MagickTrue : MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4860 | if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse)) |
| 4861 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4862 | DrawRoundLinecap(image,draw_info,p,exception); |
| 4863 | DrawRoundLinecap(image,draw_info,q,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4864 | } |
| 4865 | } |
| 4866 | clone_info=DestroyDrawInfo(clone_info); |
| 4867 | if (image->debug != MagickFalse) |
| 4868 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
| 4869 | " end draw-stroke-polygon"); |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4870 | return(status != 0 ? MagickTrue : MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4871 | } |
| 4872 | |
| 4873 | /* |
| 4874 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4875 | % % |
| 4876 | % % |
| 4877 | % % |
| 4878 | % G e t A f f i n e M a t r i x % |
| 4879 | % % |
| 4880 | % % |
| 4881 | % % |
| 4882 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4883 | % |
| 4884 | % GetAffineMatrix() returns an AffineMatrix initialized to the identity |
| 4885 | % matrix. |
| 4886 | % |
| 4887 | % The format of the GetAffineMatrix method is: |
| 4888 | % |
| 4889 | % void GetAffineMatrix(AffineMatrix *affine_matrix) |
| 4890 | % |
| 4891 | % A description of each parameter follows: |
| 4892 | % |
| 4893 | % o affine_matrix: the affine matrix. |
| 4894 | % |
| 4895 | */ |
| 4896 | MagickExport void GetAffineMatrix(AffineMatrix *affine_matrix) |
| 4897 | { |
| 4898 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 4899 | assert(affine_matrix != (AffineMatrix *) NULL); |
| 4900 | (void) ResetMagickMemory(affine_matrix,0,sizeof(*affine_matrix)); |
| 4901 | affine_matrix->sx=1.0; |
| 4902 | affine_matrix->sy=1.0; |
| 4903 | } |
| 4904 | |
| 4905 | /* |
| 4906 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4907 | % % |
| 4908 | % % |
| 4909 | % % |
| 4910 | + G e t D r a w I n f o % |
| 4911 | % % |
| 4912 | % % |
| 4913 | % % |
| 4914 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4915 | % |
anthony | 9c88e8f | 2011-09-29 11:31:53 +0000 | [diff] [blame] | 4916 | % GetDrawInfo() initializes draw_info to default values from image_info. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4917 | % |
| 4918 | % The format of the GetDrawInfo method is: |
| 4919 | % |
| 4920 | % void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info) |
| 4921 | % |
| 4922 | % A description of each parameter follows: |
| 4923 | % |
| 4924 | % o image_info: the image info.. |
| 4925 | % |
| 4926 | % o draw_info: the draw info. |
| 4927 | % |
| 4928 | */ |
| 4929 | MagickExport void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info) |
| 4930 | { |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 4931 | char |
| 4932 | *next_token; |
| 4933 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4934 | const char |
| 4935 | *option; |
| 4936 | |
| 4937 | ExceptionInfo |
| 4938 | *exception; |
| 4939 | |
cristy | c381376 | 2015-06-07 13:41:56 +0000 | [diff] [blame] | 4940 | ImageInfo |
| 4941 | *clone_info; |
| 4942 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4943 | /* |
| 4944 | Initialize draw attributes. |
| 4945 | */ |
| 4946 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 4947 | assert(draw_info != (DrawInfo *) NULL); |
| 4948 | (void) ResetMagickMemory(draw_info,0,sizeof(*draw_info)); |
cristy | c381376 | 2015-06-07 13:41:56 +0000 | [diff] [blame] | 4949 | clone_info=CloneImageInfo(image_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4950 | GetAffineMatrix(&draw_info->affine); |
| 4951 | exception=AcquireExceptionInfo(); |
cristy | fad60c9 | 2012-01-19 18:32:39 +0000 | [diff] [blame] | 4952 | (void) QueryColorCompliance("#000F",AllCompliance,&draw_info->fill, |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 4953 | exception); |
cristy | 86c364d | 2014-08-27 23:37:32 +0000 | [diff] [blame] | 4954 | (void) QueryColorCompliance("#0000",AllCompliance,&draw_info->stroke, |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 4955 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4956 | draw_info->stroke_width=1.0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4957 | draw_info->fill_rule=EvenOddRule; |
Cristy | 48bcfe0 | 2016-07-13 18:05:02 -0400 | [diff] [blame] | 4958 | draw_info->fill_alpha=OpaqueAlpha; |
| 4959 | draw_info->stroke_alpha=OpaqueAlpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4960 | draw_info->linecap=ButtCap; |
| 4961 | draw_info->linejoin=MiterJoin; |
| 4962 | draw_info->miterlimit=10; |
| 4963 | draw_info->decorate=NoDecoration; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4964 | draw_info->pointsize=12.0; |
Cristy | 726812f | 2016-05-04 19:09:35 -0400 | [diff] [blame] | 4965 | draw_info->undercolor.alpha=(MagickRealType) TransparentAlpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4966 | draw_info->compose=OverCompositeOp; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4967 | draw_info->render=MagickTrue; |
| 4968 | draw_info->debug=IsEventLogging(); |
cristy | c381376 | 2015-06-07 13:41:56 +0000 | [diff] [blame] | 4969 | draw_info->stroke_antialias=clone_info->antialias; |
| 4970 | if (clone_info->font != (char *) NULL) |
| 4971 | draw_info->font=AcquireString(clone_info->font); |
| 4972 | if (clone_info->density != (char *) NULL) |
| 4973 | draw_info->density=AcquireString(clone_info->density); |
| 4974 | draw_info->text_antialias=clone_info->antialias; |
dirk | 3af104d | 2016-06-25 22:14:34 +0200 | [diff] [blame] | 4975 | if (fabs(clone_info->pointsize) >= DrawEpsilon) |
cristy | c381376 | 2015-06-07 13:41:56 +0000 | [diff] [blame] | 4976 | draw_info->pointsize=clone_info->pointsize; |
| 4977 | draw_info->border_color=clone_info->border_color; |
| 4978 | if (clone_info->server_name != (char *) NULL) |
| 4979 | draw_info->server_name=AcquireString(clone_info->server_name); |
cristy | c381376 | 2015-06-07 13:41:56 +0000 | [diff] [blame] | 4980 | option=GetImageOption(clone_info,"direction"); |
| 4981 | if (option != (const char *) NULL) |
| 4982 | draw_info->direction=(DirectionType) ParseCommandOption( |
| 4983 | MagickDirectionOptions,MagickFalse,option); |
| 4984 | else |
| 4985 | draw_info->direction=UndefinedDirection; |
dirk | d91d18e | 2015-07-30 18:41:02 +0000 | [diff] [blame] | 4986 | option=GetImageOption(clone_info,"encoding"); |
| 4987 | if (option != (const char *) NULL) |
| 4988 | (void) CloneString(&draw_info->encoding,option); |
dirk | 6409f34 | 2015-08-01 08:06:56 +0000 | [diff] [blame] | 4989 | option=GetImageOption(clone_info,"family"); |
| 4990 | if (option != (const char *) NULL) |
| 4991 | (void) CloneString(&draw_info->family,option); |
cristy | c381376 | 2015-06-07 13:41:56 +0000 | [diff] [blame] | 4992 | option=GetImageOption(clone_info,"fill"); |
| 4993 | if (option != (const char *) NULL) |
| 4994 | (void) QueryColorCompliance(option,AllCompliance,&draw_info->fill, |
| 4995 | exception); |
dirk | 5acf702 | 2015-07-30 18:37:03 +0000 | [diff] [blame] | 4996 | option=GetImageOption(clone_info,"gravity"); |
| 4997 | if (option != (const char *) NULL) |
| 4998 | draw_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions, |
| 4999 | MagickFalse,option); |
| 5000 | option=GetImageOption(clone_info,"interline-spacing"); |
| 5001 | if (option != (const char *) NULL) |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5002 | draw_info->interline_spacing=StringToDouble(option,&next_token); |
dirk | 5acf702 | 2015-07-30 18:37:03 +0000 | [diff] [blame] | 5003 | option=GetImageOption(clone_info,"interword-spacing"); |
| 5004 | if (option != (const char *) NULL) |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5005 | draw_info->interword_spacing=StringToDouble(option,&next_token); |
dirk | 5acf702 | 2015-07-30 18:37:03 +0000 | [diff] [blame] | 5006 | option=GetImageOption(clone_info,"kerning"); |
| 5007 | if (option != (const char *) NULL) |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5008 | draw_info->kerning=StringToDouble(option,&next_token); |
cristy | c381376 | 2015-06-07 13:41:56 +0000 | [diff] [blame] | 5009 | option=GetImageOption(clone_info,"stroke"); |
| 5010 | if (option != (const char *) NULL) |
| 5011 | (void) QueryColorCompliance(option,AllCompliance,&draw_info->stroke, |
| 5012 | exception); |
| 5013 | option=GetImageOption(clone_info,"strokewidth"); |
| 5014 | if (option != (const char *) NULL) |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5015 | draw_info->stroke_width=StringToDouble(option,&next_token); |
dirk | cd7357c | 2015-07-30 18:47:36 +0000 | [diff] [blame] | 5016 | option=GetImageOption(clone_info,"style"); |
| 5017 | if (option != (const char *) NULL) |
| 5018 | draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions, |
| 5019 | MagickFalse,option); |
cristy | c381376 | 2015-06-07 13:41:56 +0000 | [diff] [blame] | 5020 | option=GetImageOption(clone_info,"undercolor"); |
| 5021 | if (option != (const char *) NULL) |
| 5022 | (void) QueryColorCompliance(option,AllCompliance,&draw_info->undercolor, |
| 5023 | exception); |
dirk | 5acf702 | 2015-07-30 18:37:03 +0000 | [diff] [blame] | 5024 | option=GetImageOption(clone_info,"weight"); |
cristy | c381376 | 2015-06-07 13:41:56 +0000 | [diff] [blame] | 5025 | if (option != (const char *) NULL) |
dirk | 5acf702 | 2015-07-30 18:37:03 +0000 | [diff] [blame] | 5026 | { |
| 5027 | ssize_t |
| 5028 | weight; |
| 5029 | |
| 5030 | weight=ParseCommandOption(MagickWeightOptions,MagickFalse,option); |
| 5031 | if (weight == -1) |
Cristy | 726812f | 2016-05-04 19:09:35 -0400 | [diff] [blame] | 5032 | weight=(ssize_t) StringToUnsignedLong(option); |
dirk | 5acf702 | 2015-07-30 18:37:03 +0000 | [diff] [blame] | 5033 | draw_info->weight=(size_t) weight; |
| 5034 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5035 | exception=DestroyExceptionInfo(exception); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 5036 | draw_info->signature=MagickCoreSignature; |
cristy | c381376 | 2015-06-07 13:41:56 +0000 | [diff] [blame] | 5037 | clone_info=DestroyImageInfo(clone_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5038 | } |
| 5039 | |
| 5040 | /* |
| 5041 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5042 | % % |
| 5043 | % % |
| 5044 | % % |
| 5045 | + P e r m u t a t e % |
| 5046 | % % |
| 5047 | % % |
| 5048 | % % |
| 5049 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5050 | % |
| 5051 | % Permutate() returns the permuation of the (n,k). |
| 5052 | % |
| 5053 | % The format of the Permutate method is: |
| 5054 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5055 | % void Permutate(ssize_t n,ssize_t k) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5056 | % |
| 5057 | % A description of each parameter follows: |
| 5058 | % |
| 5059 | % o n: |
| 5060 | % |
| 5061 | % o k: |
| 5062 | % |
| 5063 | % |
| 5064 | */ |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5065 | static inline double Permutate(const ssize_t n,const ssize_t k) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5066 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5067 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5068 | r; |
| 5069 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5070 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5071 | i; |
| 5072 | |
| 5073 | r=1.0; |
| 5074 | for (i=k+1; i <= n; i++) |
| 5075 | r*=i; |
| 5076 | for (i=1; i <= (n-k); i++) |
| 5077 | r/=i; |
| 5078 | return(r); |
| 5079 | } |
| 5080 | |
| 5081 | /* |
| 5082 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5083 | % % |
| 5084 | % % |
| 5085 | % % |
| 5086 | + T r a c e P r i m i t i v e % |
| 5087 | % % |
| 5088 | % % |
| 5089 | % % |
| 5090 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5091 | % |
| 5092 | % TracePrimitive is a collection of methods for generating graphic |
| 5093 | % primitives such as arcs, ellipses, paths, etc. |
| 5094 | % |
| 5095 | */ |
| 5096 | |
| 5097 | static void TraceArc(PrimitiveInfo *primitive_info,const PointInfo start, |
| 5098 | const PointInfo end,const PointInfo degrees) |
| 5099 | { |
| 5100 | PointInfo |
| 5101 | center, |
| 5102 | radii; |
| 5103 | |
| 5104 | center.x=0.5*(end.x+start.x); |
| 5105 | center.y=0.5*(end.y+start.y); |
| 5106 | radii.x=fabs(center.x-start.x); |
| 5107 | radii.y=fabs(center.y-start.y); |
| 5108 | TraceEllipse(primitive_info,center,radii,degrees); |
| 5109 | } |
| 5110 | |
| 5111 | static void TraceArcPath(PrimitiveInfo *primitive_info,const PointInfo start, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5112 | const PointInfo end,const PointInfo arc,const double angle, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5113 | const MagickBooleanType large_arc,const MagickBooleanType sweep) |
| 5114 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5115 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5116 | alpha, |
| 5117 | beta, |
| 5118 | delta, |
| 5119 | factor, |
| 5120 | gamma, |
| 5121 | theta; |
| 5122 | |
| 5123 | PointInfo |
| 5124 | center, |
| 5125 | points[3], |
| 5126 | radii; |
| 5127 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5128 | register double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5129 | cosine, |
| 5130 | sine; |
| 5131 | |
| 5132 | register PrimitiveInfo |
| 5133 | *p; |
| 5134 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5135 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5136 | i; |
| 5137 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5138 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5139 | arc_segments; |
| 5140 | |
Cristy | 48bcfe0 | 2016-07-13 18:05:02 -0400 | [diff] [blame] | 5141 | if ((fabs(start.x-end.x) < DrawEpsilon) && |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 5142 | (fabs(start.y-end.y) < DrawEpsilon)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5143 | { |
| 5144 | TracePoint(primitive_info,end); |
| 5145 | return; |
| 5146 | } |
| 5147 | radii.x=fabs(arc.x); |
| 5148 | radii.y=fabs(arc.y); |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 5149 | if ((fabs(radii.x) < DrawEpsilon) || (fabs(radii.y) < DrawEpsilon)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5150 | { |
| 5151 | TraceLine(primitive_info,start,end); |
| 5152 | return; |
| 5153 | } |
| 5154 | cosine=cos(DegreesToRadians(fmod((double) angle,360.0))); |
| 5155 | sine=sin(DegreesToRadians(fmod((double) angle,360.0))); |
| 5156 | center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2); |
| 5157 | center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2); |
| 5158 | delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/ |
| 5159 | (radii.y*radii.y); |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 5160 | if (delta < DrawEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5161 | { |
| 5162 | TraceLine(primitive_info,start,end); |
| 5163 | return; |
| 5164 | } |
| 5165 | if (delta > 1.0) |
| 5166 | { |
| 5167 | radii.x*=sqrt((double) delta); |
| 5168 | radii.y*=sqrt((double) delta); |
| 5169 | } |
| 5170 | points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x); |
| 5171 | points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y); |
| 5172 | points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x); |
| 5173 | points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y); |
| 5174 | alpha=points[1].x-points[0].x; |
| 5175 | beta=points[1].y-points[0].y; |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5176 | factor=PerceptibleReciprocal(alpha*alpha+beta*beta)-0.25; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5177 | if (factor <= 0.0) |
| 5178 | factor=0.0; |
| 5179 | else |
| 5180 | { |
| 5181 | factor=sqrt((double) factor); |
| 5182 | if (sweep == large_arc) |
| 5183 | factor=(-factor); |
| 5184 | } |
| 5185 | center.x=(double) ((points[0].x+points[1].x)/2-factor*beta); |
| 5186 | center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha); |
| 5187 | alpha=atan2(points[0].y-center.y,points[0].x-center.x); |
| 5188 | theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha; |
| 5189 | if ((theta < 0.0) && (sweep != MagickFalse)) |
Cristy | dd6065a | 2016-09-19 15:55:49 -0400 | [diff] [blame] | 5190 | theta+=2.0*MagickPI; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5191 | else |
| 5192 | if ((theta > 0.0) && (sweep == MagickFalse)) |
Cristy | dd6065a | 2016-09-19 15:55:49 -0400 | [diff] [blame] | 5193 | theta-=2.0*MagickPI; |
| 5194 | arc_segments=(size_t) ceil(fabs((double) (theta/(0.5*MagickPI+DrawEpsilon)))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5195 | p=primitive_info; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5196 | for (i=0; i < (ssize_t) arc_segments; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5197 | { |
| 5198 | beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments)); |
| 5199 | gamma=(8.0/3.0)*sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))* |
| 5200 | sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))/ |
| 5201 | sin(fmod((double) beta,DegreesToRadians(360.0))); |
| 5202 | points[0].x=(double) (center.x+cos(fmod((double) (alpha+(double) i*theta/ |
| 5203 | arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((double) (alpha+ |
| 5204 | (double) i*theta/arc_segments),DegreesToRadians(360.0)))); |
| 5205 | points[0].y=(double) (center.y+sin(fmod((double) (alpha+(double) i*theta/ |
| 5206 | arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((double) (alpha+ |
| 5207 | (double) i*theta/arc_segments),DegreesToRadians(360.0)))); |
| 5208 | points[2].x=(double) (center.x+cos(fmod((double) (alpha+(double) (i+1)* |
| 5209 | theta/arc_segments),DegreesToRadians(360.0)))); |
| 5210 | points[2].y=(double) (center.y+sin(fmod((double) (alpha+(double) (i+1)* |
| 5211 | theta/arc_segments),DegreesToRadians(360.0)))); |
| 5212 | points[1].x=(double) (points[2].x+gamma*sin(fmod((double) (alpha+(double) |
| 5213 | (i+1)*theta/arc_segments),DegreesToRadians(360.0)))); |
| 5214 | points[1].y=(double) (points[2].y-gamma*cos(fmod((double) (alpha+(double) |
| 5215 | (i+1)*theta/arc_segments),DegreesToRadians(360.0)))); |
| 5216 | p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x; |
| 5217 | p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y; |
| 5218 | (p+1)->point.x=(double) (cosine*radii.x*points[0].x-sine*radii.y* |
| 5219 | points[0].y); |
| 5220 | (p+1)->point.y=(double) (sine*radii.x*points[0].x+cosine*radii.y* |
| 5221 | points[0].y); |
| 5222 | (p+2)->point.x=(double) (cosine*radii.x*points[1].x-sine*radii.y* |
| 5223 | points[1].y); |
| 5224 | (p+2)->point.y=(double) (sine*radii.x*points[1].x+cosine*radii.y* |
| 5225 | points[1].y); |
| 5226 | (p+3)->point.x=(double) (cosine*radii.x*points[2].x-sine*radii.y* |
| 5227 | points[2].y); |
| 5228 | (p+3)->point.y=(double) (sine*radii.x*points[2].x+cosine*radii.y* |
| 5229 | points[2].y); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5230 | if (i == (ssize_t) (arc_segments-1)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5231 | (p+3)->point=end; |
| 5232 | TraceBezier(p,4); |
| 5233 | p+=p->coordinates; |
| 5234 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5235 | primitive_info->coordinates=(size_t) (p-primitive_info); |
| 5236 | for (i=0; i < (ssize_t) primitive_info->coordinates; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5237 | { |
| 5238 | p->primitive=primitive_info->primitive; |
| 5239 | p--; |
| 5240 | } |
| 5241 | } |
| 5242 | |
| 5243 | static void TraceBezier(PrimitiveInfo *primitive_info, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5244 | const size_t number_coordinates) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5245 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5246 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5247 | alpha, |
| 5248 | *coefficients, |
| 5249 | weight; |
| 5250 | |
| 5251 | PointInfo |
| 5252 | end, |
| 5253 | point, |
| 5254 | *points; |
| 5255 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 5256 | register PrimitiveInfo |
| 5257 | *p; |
| 5258 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5259 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5260 | i, |
| 5261 | j; |
| 5262 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5263 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5264 | control_points, |
| 5265 | quantum; |
| 5266 | |
| 5267 | /* |
| 5268 | Allocate coeficients. |
| 5269 | */ |
| 5270 | quantum=number_coordinates; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5271 | for (i=0; i < (ssize_t) number_coordinates; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5272 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5273 | for (j=i+1; j < (ssize_t) number_coordinates; j++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5274 | { |
| 5275 | alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5276 | if (alpha > (double) quantum) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5277 | quantum=(size_t) alpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5278 | alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5279 | if (alpha > (double) quantum) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5280 | quantum=(size_t) alpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5281 | } |
| 5282 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5283 | quantum=(size_t) MagickMin((double) quantum/number_coordinates, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5284 | (double) BezierQuantum); |
| 5285 | control_points=quantum*number_coordinates; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5286 | coefficients=(double *) AcquireQuantumMemory((size_t) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5287 | number_coordinates,sizeof(*coefficients)); |
| 5288 | points=(PointInfo *) AcquireQuantumMemory((size_t) control_points, |
| 5289 | sizeof(*points)); |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 5290 | if ((coefficients == (double *) NULL) || (points == (PointInfo *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5291 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 5292 | /* |
| 5293 | Compute bezier points. |
| 5294 | */ |
| 5295 | end=primitive_info[number_coordinates-1].point; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5296 | for (i=0; i < (ssize_t) number_coordinates; i++) |
| 5297 | coefficients[i]=Permutate((ssize_t) number_coordinates-1,i); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5298 | weight=0.0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5299 | for (i=0; i < (ssize_t) control_points; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5300 | { |
| 5301 | p=primitive_info; |
| 5302 | point.x=0.0; |
| 5303 | point.y=0.0; |
| 5304 | alpha=pow((double) (1.0-weight),(double) number_coordinates-1.0); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5305 | for (j=0; j < (ssize_t) number_coordinates; j++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5306 | { |
| 5307 | point.x+=alpha*coefficients[j]*p->point.x; |
| 5308 | point.y+=alpha*coefficients[j]*p->point.y; |
| 5309 | alpha*=weight/(1.0-weight); |
| 5310 | p++; |
| 5311 | } |
| 5312 | points[i]=point; |
| 5313 | weight+=1.0/control_points; |
| 5314 | } |
| 5315 | /* |
| 5316 | Bezier curves are just short segmented polys. |
| 5317 | */ |
| 5318 | p=primitive_info; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5319 | for (i=0; i < (ssize_t) control_points; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5320 | { |
| 5321 | TracePoint(p,points[i]); |
| 5322 | p+=p->coordinates; |
| 5323 | } |
| 5324 | TracePoint(p,end); |
| 5325 | p+=p->coordinates; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5326 | primitive_info->coordinates=(size_t) (p-primitive_info); |
| 5327 | for (i=0; i < (ssize_t) primitive_info->coordinates; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5328 | { |
| 5329 | p->primitive=primitive_info->primitive; |
| 5330 | p--; |
| 5331 | } |
| 5332 | points=(PointInfo *) RelinquishMagickMemory(points); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5333 | coefficients=(double *) RelinquishMagickMemory(coefficients); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5334 | } |
| 5335 | |
| 5336 | static void TraceCircle(PrimitiveInfo *primitive_info,const PointInfo start, |
| 5337 | const PointInfo end) |
| 5338 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5339 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5340 | alpha, |
| 5341 | beta, |
| 5342 | radius; |
| 5343 | |
| 5344 | PointInfo |
| 5345 | offset, |
| 5346 | degrees; |
| 5347 | |
| 5348 | alpha=end.x-start.x; |
| 5349 | beta=end.y-start.y; |
| 5350 | radius=hypot((double) alpha,(double) beta); |
| 5351 | offset.x=(double) radius; |
| 5352 | offset.y=(double) radius; |
| 5353 | degrees.x=0.0; |
| 5354 | degrees.y=360.0; |
| 5355 | TraceEllipse(primitive_info,start,offset,degrees); |
| 5356 | } |
| 5357 | |
| 5358 | static void TraceEllipse(PrimitiveInfo *primitive_info,const PointInfo start, |
| 5359 | const PointInfo stop,const PointInfo degrees) |
| 5360 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5361 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5362 | delta, |
| 5363 | step, |
| 5364 | y; |
| 5365 | |
| 5366 | PointInfo |
| 5367 | angle, |
| 5368 | point; |
| 5369 | |
| 5370 | register PrimitiveInfo |
| 5371 | *p; |
| 5372 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5373 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5374 | i; |
| 5375 | |
| 5376 | /* |
| 5377 | Ellipses are just short segmented polys. |
| 5378 | */ |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 5379 | if ((fabs(stop.x) < DrawEpsilon) && (fabs(stop.y) < DrawEpsilon)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5380 | { |
| 5381 | TracePoint(primitive_info,start); |
| 5382 | return; |
| 5383 | } |
| 5384 | delta=2.0/MagickMax(stop.x,stop.y); |
Cristy | dd6065a | 2016-09-19 15:55:49 -0400 | [diff] [blame] | 5385 | step=MagickPI/8.0; |
| 5386 | if ((delta >= 0.0) && (delta < (MagickPI/8.0))) |
| 5387 | step=MagickPI/(4*(MagickPI/delta/2+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5388 | angle.x=DegreesToRadians(degrees.x); |
| 5389 | y=degrees.y; |
| 5390 | while (y < degrees.x) |
| 5391 | y+=360.0; |
Cristy | dd6065a | 2016-09-19 15:55:49 -0400 | [diff] [blame] | 5392 | angle.y=DegreesToRadians(y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5393 | for (p=primitive_info; angle.x < angle.y; angle.x+=step) |
| 5394 | { |
| 5395 | point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*stop.x+start.x; |
| 5396 | point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*stop.y+start.y; |
| 5397 | TracePoint(p,point); |
| 5398 | p+=p->coordinates; |
| 5399 | } |
| 5400 | point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*stop.x+start.x; |
| 5401 | point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*stop.y+start.y; |
| 5402 | TracePoint(p,point); |
| 5403 | p+=p->coordinates; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5404 | primitive_info->coordinates=(size_t) (p-primitive_info); |
| 5405 | for (i=0; i < (ssize_t) primitive_info->coordinates; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5406 | { |
| 5407 | p->primitive=primitive_info->primitive; |
| 5408 | p--; |
| 5409 | } |
| 5410 | } |
| 5411 | |
| 5412 | static void TraceLine(PrimitiveInfo *primitive_info,const PointInfo start, |
| 5413 | const PointInfo end) |
| 5414 | { |
| 5415 | TracePoint(primitive_info,start); |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 5416 | if ((fabs(start.x-end.x) < DrawEpsilon) && |
| 5417 | (fabs(start.y-end.y) < DrawEpsilon)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5418 | { |
| 5419 | primitive_info->primitive=PointPrimitive; |
| 5420 | primitive_info->coordinates=1; |
| 5421 | return; |
| 5422 | } |
| 5423 | TracePoint(primitive_info+1,end); |
| 5424 | (primitive_info+1)->primitive=primitive_info->primitive; |
| 5425 | primitive_info->coordinates=2; |
| 5426 | } |
| 5427 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5428 | static size_t TracePath(PrimitiveInfo *primitive_info,const char *path) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5429 | { |
| 5430 | char |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5431 | *next_token, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 5432 | token[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5433 | |
| 5434 | const char |
| 5435 | *p; |
| 5436 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5437 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5438 | x, |
| 5439 | y; |
| 5440 | |
Cristy | dd6065a | 2016-09-19 15:55:49 -0400 | [diff] [blame] | 5441 | int |
| 5442 | attribute, |
| 5443 | last_attribute; |
| 5444 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5445 | PointInfo |
cristy | 6124e6b | 2015-04-08 11:56:05 +0000 | [diff] [blame] | 5446 | end = {0.0, 0.0}, |
| 5447 | points[4] = { {0.0,0.0}, {0.0,0.0}, {0.0,0.0}, {0.0,0.0} }, |
| 5448 | point = {0.0, 0.0}, |
| 5449 | start = {0.0, 0.0}; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5450 | |
| 5451 | PrimitiveType |
| 5452 | primitive_type; |
| 5453 | |
| 5454 | register PrimitiveInfo |
| 5455 | *q; |
| 5456 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5457 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5458 | i; |
| 5459 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5460 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5461 | number_coordinates, |
| 5462 | z_count; |
| 5463 | |
| 5464 | attribute=0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5465 | number_coordinates=0; |
| 5466 | z_count=0; |
| 5467 | primitive_type=primitive_info->primitive; |
| 5468 | q=primitive_info; |
| 5469 | for (p=path; *p != '\0'; ) |
| 5470 | { |
| 5471 | while (isspace((int) ((unsigned char) *p)) != 0) |
| 5472 | p++; |
| 5473 | if (*p == '\0') |
| 5474 | break; |
| 5475 | last_attribute=attribute; |
| 5476 | attribute=(int) (*p++); |
| 5477 | switch (attribute) |
| 5478 | { |
| 5479 | case 'a': |
| 5480 | case 'A': |
| 5481 | { |
Cristy | dd6065a | 2016-09-19 15:55:49 -0400 | [diff] [blame] | 5482 | double |
| 5483 | angle; |
| 5484 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5485 | MagickBooleanType |
| 5486 | large_arc, |
| 5487 | sweep; |
| 5488 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5489 | PointInfo |
| 5490 | arc; |
| 5491 | |
| 5492 | /* |
| 5493 | Compute arc points. |
| 5494 | */ |
| 5495 | do |
| 5496 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5497 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5498 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5499 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5500 | arc.x=StringToDouble(token,&next_token); |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5501 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5502 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5503 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5504 | arc.y=StringToDouble(token,&next_token); |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5505 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5506 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5507 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5508 | angle=StringToDouble(token,&next_token); |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5509 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5510 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5511 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5512 | large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5513 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5514 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5515 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5516 | sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5517 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5518 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5519 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5520 | x=StringToDouble(token,&next_token); |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5521 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5522 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5523 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5524 | y=StringToDouble(token,&next_token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5525 | end.x=(double) (attribute == (int) 'A' ? x : point.x+x); |
| 5526 | end.y=(double) (attribute == (int) 'A' ? y : point.y+y); |
| 5527 | TraceArcPath(q,point,end,arc,angle,large_arc,sweep); |
| 5528 | q+=q->coordinates; |
| 5529 | point=end; |
cristy | 671fcfc | 2011-12-13 13:28:31 +0000 | [diff] [blame] | 5530 | while (isspace((int) ((unsigned char) *p)) != 0) |
| 5531 | p++; |
| 5532 | if (*p == ',') |
| 5533 | p++; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5534 | } while (IsPoint(p) != MagickFalse); |
| 5535 | break; |
| 5536 | } |
| 5537 | case 'c': |
| 5538 | case 'C': |
| 5539 | { |
| 5540 | /* |
| 5541 | Compute bezier points. |
| 5542 | */ |
| 5543 | do |
| 5544 | { |
| 5545 | points[0]=point; |
| 5546 | for (i=1; i < 4; i++) |
| 5547 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5548 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5549 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5550 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5551 | x=StringToDouble(token,&next_token); |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5552 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5553 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5554 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5555 | y=StringToDouble(token,&next_token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5556 | end.x=(double) (attribute == (int) 'C' ? x : point.x+x); |
| 5557 | end.y=(double) (attribute == (int) 'C' ? y : point.y+y); |
| 5558 | points[i]=end; |
| 5559 | } |
| 5560 | for (i=0; i < 4; i++) |
| 5561 | (q+i)->point=points[i]; |
| 5562 | TraceBezier(q,4); |
| 5563 | q+=q->coordinates; |
| 5564 | point=end; |
| 5565 | } while (IsPoint(p) != MagickFalse); |
| 5566 | break; |
| 5567 | } |
| 5568 | case 'H': |
| 5569 | case 'h': |
| 5570 | { |
| 5571 | do |
| 5572 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5573 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5574 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5575 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5576 | x=StringToDouble(token,&next_token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5577 | point.x=(double) (attribute == (int) 'H' ? x: point.x+x); |
| 5578 | TracePoint(q,point); |
| 5579 | q+=q->coordinates; |
| 5580 | } while (IsPoint(p) != MagickFalse); |
| 5581 | break; |
| 5582 | } |
| 5583 | case 'l': |
| 5584 | case 'L': |
| 5585 | { |
| 5586 | do |
| 5587 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5588 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5589 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5590 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5591 | x=StringToDouble(token,&next_token); |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5592 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5593 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5594 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5595 | y=StringToDouble(token,&next_token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5596 | point.x=(double) (attribute == (int) 'L' ? x : point.x+x); |
| 5597 | point.y=(double) (attribute == (int) 'L' ? y : point.y+y); |
| 5598 | TracePoint(q,point); |
| 5599 | q+=q->coordinates; |
| 5600 | } while (IsPoint(p) != MagickFalse); |
| 5601 | break; |
| 5602 | } |
| 5603 | case 'M': |
| 5604 | case 'm': |
| 5605 | { |
| 5606 | if (q != primitive_info) |
| 5607 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5608 | primitive_info->coordinates=(size_t) (q-primitive_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5609 | number_coordinates+=primitive_info->coordinates; |
| 5610 | primitive_info=q; |
| 5611 | } |
| 5612 | i=0; |
| 5613 | do |
| 5614 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5615 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5616 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5617 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5618 | x=StringToDouble(token,&next_token); |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5619 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5620 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5621 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5622 | y=StringToDouble(token,&next_token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5623 | point.x=(double) (attribute == (int) 'M' ? x : point.x+x); |
| 5624 | point.y=(double) (attribute == (int) 'M' ? y : point.y+y); |
| 5625 | if (i == 0) |
| 5626 | start=point; |
| 5627 | i++; |
| 5628 | TracePoint(q,point); |
| 5629 | q+=q->coordinates; |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 5630 | if ((i != 0) && (attribute == (int) 'M')) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5631 | { |
| 5632 | TracePoint(q,point); |
| 5633 | q+=q->coordinates; |
| 5634 | } |
| 5635 | } while (IsPoint(p) != MagickFalse); |
| 5636 | break; |
| 5637 | } |
| 5638 | case 'q': |
| 5639 | case 'Q': |
| 5640 | { |
| 5641 | /* |
| 5642 | Compute bezier points. |
| 5643 | */ |
| 5644 | do |
| 5645 | { |
| 5646 | points[0]=point; |
| 5647 | for (i=1; i < 3; i++) |
| 5648 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5649 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5650 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5651 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5652 | x=StringToDouble(token,&next_token); |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5653 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5654 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5655 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5656 | y=StringToDouble(token,&next_token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5657 | if (*p == ',') |
| 5658 | p++; |
| 5659 | end.x=(double) (attribute == (int) 'Q' ? x : point.x+x); |
| 5660 | end.y=(double) (attribute == (int) 'Q' ? y : point.y+y); |
| 5661 | points[i]=end; |
| 5662 | } |
| 5663 | for (i=0; i < 3; i++) |
| 5664 | (q+i)->point=points[i]; |
| 5665 | TraceBezier(q,3); |
| 5666 | q+=q->coordinates; |
| 5667 | point=end; |
| 5668 | } while (IsPoint(p) != MagickFalse); |
| 5669 | break; |
| 5670 | } |
| 5671 | case 's': |
| 5672 | case 'S': |
| 5673 | { |
| 5674 | /* |
| 5675 | Compute bezier points. |
| 5676 | */ |
| 5677 | do |
| 5678 | { |
| 5679 | points[0]=points[3]; |
| 5680 | points[1].x=2.0*points[3].x-points[2].x; |
| 5681 | points[1].y=2.0*points[3].y-points[2].y; |
| 5682 | for (i=2; i < 4; i++) |
| 5683 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5684 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5685 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5686 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5687 | x=StringToDouble(token,&next_token); |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5688 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5689 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5690 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5691 | y=StringToDouble(token,&next_token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5692 | if (*p == ',') |
| 5693 | p++; |
| 5694 | end.x=(double) (attribute == (int) 'S' ? x : point.x+x); |
| 5695 | end.y=(double) (attribute == (int) 'S' ? y : point.y+y); |
| 5696 | points[i]=end; |
| 5697 | } |
| 5698 | if (strchr("CcSs",last_attribute) == (char *) NULL) |
| 5699 | { |
cristy | 889e187 | 2014-12-13 20:45:28 +0000 | [diff] [blame] | 5700 | points[0]=point; |
| 5701 | points[1]=point; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5702 | } |
| 5703 | for (i=0; i < 4; i++) |
| 5704 | (q+i)->point=points[i]; |
| 5705 | TraceBezier(q,4); |
| 5706 | q+=q->coordinates; |
| 5707 | point=end; |
| 5708 | } while (IsPoint(p) != MagickFalse); |
| 5709 | break; |
| 5710 | } |
| 5711 | case 't': |
| 5712 | case 'T': |
| 5713 | { |
| 5714 | /* |
| 5715 | Compute bezier points. |
| 5716 | */ |
| 5717 | do |
| 5718 | { |
| 5719 | points[0]=points[2]; |
| 5720 | points[1].x=2.0*points[2].x-points[1].x; |
| 5721 | points[1].y=2.0*points[2].y-points[1].y; |
| 5722 | for (i=2; i < 3; i++) |
| 5723 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5724 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5725 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5726 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5727 | x=StringToDouble(token,&next_token); |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5728 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5729 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5730 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5731 | y=StringToDouble(token,&next_token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5732 | end.x=(double) (attribute == (int) 'T' ? x : point.x+x); |
| 5733 | end.y=(double) (attribute == (int) 'T' ? y : point.y+y); |
| 5734 | points[i]=end; |
| 5735 | } |
| 5736 | if (strchr("QqTt",last_attribute) == (char *) NULL) |
| 5737 | { |
cristy | 9d8e3fe | 2014-12-13 20:45:52 +0000 | [diff] [blame] | 5738 | points[0]=point; |
| 5739 | points[1]=point; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5740 | } |
| 5741 | for (i=0; i < 3; i++) |
| 5742 | (q+i)->point=points[i]; |
| 5743 | TraceBezier(q,3); |
| 5744 | q+=q->coordinates; |
| 5745 | point=end; |
| 5746 | } while (IsPoint(p) != MagickFalse); |
| 5747 | break; |
| 5748 | } |
| 5749 | case 'v': |
| 5750 | case 'V': |
| 5751 | { |
| 5752 | do |
| 5753 | { |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5754 | GetNextToken(p,&p,MagickPathExtent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5755 | if (*token == ',') |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 5756 | GetNextToken(p,&p,MagickPathExtent,token); |
Cristy | 3ed6c69 | 2016-05-23 19:24:23 -0400 | [diff] [blame] | 5757 | y=StringToDouble(token,&next_token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5758 | point.y=(double) (attribute == (int) 'V' ? y : point.y+y); |
| 5759 | TracePoint(q,point); |
| 5760 | q+=q->coordinates; |
| 5761 | } while (IsPoint(p) != MagickFalse); |
| 5762 | break; |
| 5763 | } |
| 5764 | case 'z': |
| 5765 | case 'Z': |
| 5766 | { |
| 5767 | point=start; |
| 5768 | TracePoint(q,point); |
| 5769 | q+=q->coordinates; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5770 | primitive_info->coordinates=(size_t) (q-primitive_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5771 | number_coordinates+=primitive_info->coordinates; |
| 5772 | primitive_info=q; |
| 5773 | z_count++; |
| 5774 | break; |
| 5775 | } |
| 5776 | default: |
| 5777 | { |
| 5778 | if (isalpha((int) ((unsigned char) attribute)) != 0) |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 5779 | (void) FormatLocaleFile(stderr,"attribute not recognized: %c\n", |
| 5780 | attribute); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5781 | break; |
| 5782 | } |
| 5783 | } |
| 5784 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5785 | primitive_info->coordinates=(size_t) (q-primitive_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5786 | number_coordinates+=primitive_info->coordinates; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5787 | for (i=0; i < (ssize_t) number_coordinates; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5788 | { |
| 5789 | q--; |
| 5790 | q->primitive=primitive_type; |
| 5791 | if (z_count > 1) |
| 5792 | q->method=FillToBorderMethod; |
| 5793 | } |
| 5794 | q=primitive_info; |
| 5795 | return(number_coordinates); |
| 5796 | } |
| 5797 | |
| 5798 | static void TraceRectangle(PrimitiveInfo *primitive_info,const PointInfo start, |
| 5799 | const PointInfo end) |
| 5800 | { |
| 5801 | PointInfo |
| 5802 | point; |
| 5803 | |
| 5804 | register PrimitiveInfo |
| 5805 | *p; |
| 5806 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5807 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5808 | i; |
| 5809 | |
| 5810 | p=primitive_info; |
| 5811 | TracePoint(p,start); |
| 5812 | p+=p->coordinates; |
| 5813 | point.x=start.x; |
| 5814 | point.y=end.y; |
| 5815 | TracePoint(p,point); |
| 5816 | p+=p->coordinates; |
| 5817 | TracePoint(p,end); |
| 5818 | p+=p->coordinates; |
| 5819 | point.x=end.x; |
| 5820 | point.y=start.y; |
| 5821 | TracePoint(p,point); |
| 5822 | p+=p->coordinates; |
| 5823 | TracePoint(p,start); |
| 5824 | p+=p->coordinates; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5825 | primitive_info->coordinates=(size_t) (p-primitive_info); |
| 5826 | for (i=0; i < (ssize_t) primitive_info->coordinates; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5827 | { |
| 5828 | p->primitive=primitive_info->primitive; |
| 5829 | p--; |
| 5830 | } |
| 5831 | } |
| 5832 | |
| 5833 | static void TraceRoundRectangle(PrimitiveInfo *primitive_info, |
| 5834 | const PointInfo start,const PointInfo end,PointInfo arc) |
| 5835 | { |
| 5836 | PointInfo |
| 5837 | degrees, |
| 5838 | offset, |
| 5839 | point; |
| 5840 | |
| 5841 | register PrimitiveInfo |
| 5842 | *p; |
| 5843 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5844 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5845 | i; |
| 5846 | |
| 5847 | p=primitive_info; |
| 5848 | offset.x=fabs(end.x-start.x); |
| 5849 | offset.y=fabs(end.y-start.y); |
| 5850 | if (arc.x > (0.5*offset.x)) |
| 5851 | arc.x=0.5*offset.x; |
| 5852 | if (arc.y > (0.5*offset.y)) |
| 5853 | arc.y=0.5*offset.y; |
| 5854 | point.x=start.x+offset.x-arc.x; |
| 5855 | point.y=start.y+arc.y; |
| 5856 | degrees.x=270.0; |
| 5857 | degrees.y=360.0; |
| 5858 | TraceEllipse(p,point,arc,degrees); |
| 5859 | p+=p->coordinates; |
| 5860 | point.x=start.x+offset.x-arc.x; |
| 5861 | point.y=start.y+offset.y-arc.y; |
| 5862 | degrees.x=0.0; |
| 5863 | degrees.y=90.0; |
| 5864 | TraceEllipse(p,point,arc,degrees); |
| 5865 | p+=p->coordinates; |
| 5866 | point.x=start.x+arc.x; |
| 5867 | point.y=start.y+offset.y-arc.y; |
| 5868 | degrees.x=90.0; |
| 5869 | degrees.y=180.0; |
| 5870 | TraceEllipse(p,point,arc,degrees); |
| 5871 | p+=p->coordinates; |
| 5872 | point.x=start.x+arc.x; |
| 5873 | point.y=start.y+arc.y; |
| 5874 | degrees.x=180.0; |
| 5875 | degrees.y=270.0; |
| 5876 | TraceEllipse(p,point,arc,degrees); |
| 5877 | p+=p->coordinates; |
| 5878 | TracePoint(p,primitive_info->point); |
| 5879 | p+=p->coordinates; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5880 | primitive_info->coordinates=(size_t) (p-primitive_info); |
| 5881 | for (i=0; i < (ssize_t) primitive_info->coordinates; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5882 | { |
| 5883 | p->primitive=primitive_info->primitive; |
| 5884 | p--; |
| 5885 | } |
| 5886 | } |
| 5887 | |
| 5888 | static void TraceSquareLinecap(PrimitiveInfo *primitive_info, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5889 | const size_t number_vertices,const double offset) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5890 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5891 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5892 | distance; |
| 5893 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5894 | register double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5895 | dx, |
| 5896 | dy; |
| 5897 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5898 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5899 | i; |
| 5900 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 5901 | ssize_t |
| 5902 | j; |
| 5903 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5904 | dx=0.0; |
| 5905 | dy=0.0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5906 | for (i=1; i < (ssize_t) number_vertices; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5907 | { |
| 5908 | dx=primitive_info[0].point.x-primitive_info[i].point.x; |
| 5909 | dy=primitive_info[0].point.y-primitive_info[i].point.y; |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 5910 | if ((fabs((double) dx) >= DrawEpsilon) || |
| 5911 | (fabs((double) dy) >= DrawEpsilon)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5912 | break; |
| 5913 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5914 | if (i == (ssize_t) number_vertices) |
| 5915 | i=(ssize_t) number_vertices-1L; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5916 | distance=hypot((double) dx,(double) dy); |
| 5917 | primitive_info[0].point.x=(double) (primitive_info[i].point.x+ |
| 5918 | dx*(distance+offset)/distance); |
| 5919 | primitive_info[0].point.y=(double) (primitive_info[i].point.y+ |
| 5920 | dy*(distance+offset)/distance); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5921 | for (j=(ssize_t) number_vertices-2; j >= 0; j--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5922 | { |
| 5923 | dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x; |
| 5924 | dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y; |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 5925 | if ((fabs((double) dx) >= DrawEpsilon) || |
| 5926 | (fabs((double) dy) >= DrawEpsilon)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5927 | break; |
| 5928 | } |
| 5929 | distance=hypot((double) dx,(double) dy); |
| 5930 | primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+ |
| 5931 | dx*(distance+offset)/distance); |
| 5932 | primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+ |
| 5933 | dy*(distance+offset)/distance); |
| 5934 | } |
| 5935 | |
| 5936 | static PrimitiveInfo *TraceStrokePolygon(const DrawInfo *draw_info, |
| 5937 | const PrimitiveInfo *primitive_info) |
| 5938 | { |
| 5939 | typedef struct _LineSegment |
| 5940 | { |
| 5941 | double |
| 5942 | p, |
| 5943 | q; |
| 5944 | } LineSegment; |
| 5945 | |
Cristy | dd6065a | 2016-09-19 15:55:49 -0400 | [diff] [blame] | 5946 | double |
| 5947 | delta_theta, |
| 5948 | dot_product, |
| 5949 | mid, |
| 5950 | miterlimit; |
| 5951 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5952 | LineSegment |
| 5953 | dx, |
| 5954 | dy, |
| 5955 | inverse_slope, |
| 5956 | slope, |
| 5957 | theta; |
| 5958 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5959 | MagickBooleanType |
| 5960 | closed_path; |
| 5961 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5962 | PointInfo |
| 5963 | box_p[5], |
| 5964 | box_q[5], |
| 5965 | center, |
| 5966 | offset, |
| 5967 | *path_p, |
| 5968 | *path_q; |
| 5969 | |
| 5970 | PrimitiveInfo |
| 5971 | *polygon_primitive, |
| 5972 | *stroke_polygon; |
| 5973 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5974 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5975 | i; |
| 5976 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5977 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5978 | arc_segments, |
| 5979 | max_strokes, |
| 5980 | number_vertices; |
| 5981 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 5982 | ssize_t |
| 5983 | j, |
| 5984 | n, |
| 5985 | p, |
| 5986 | q; |
| 5987 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5988 | /* |
| 5989 | Allocate paths. |
| 5990 | */ |
| 5991 | number_vertices=primitive_info->coordinates; |
| 5992 | max_strokes=2*number_vertices+6*BezierQuantum+360; |
| 5993 | path_p=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes, |
| 5994 | sizeof(*path_p)); |
| 5995 | path_q=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes, |
| 5996 | sizeof(*path_q)); |
| 5997 | polygon_primitive=(PrimitiveInfo *) AcquireQuantumMemory((size_t) |
| 5998 | number_vertices+2UL,sizeof(*polygon_primitive)); |
| 5999 | if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL) || |
| 6000 | (polygon_primitive == (PrimitiveInfo *) NULL)) |
| 6001 | return((PrimitiveInfo *) NULL); |
| 6002 | (void) CopyMagickMemory(polygon_primitive,primitive_info,(size_t) |
| 6003 | number_vertices*sizeof(*polygon_primitive)); |
| 6004 | closed_path= |
Cristy | dd6065a | 2016-09-19 15:55:49 -0400 | [diff] [blame] | 6005 | (fabs(primitive_info[number_vertices-1].point.x-primitive_info[0].point.x) < DrawEpsilon) && |
| 6006 | (fabs(primitive_info[number_vertices-1].point.y-primitive_info[0].point.y) < DrawEpsilon) ? |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6007 | MagickTrue : MagickFalse; |
| 6008 | if ((draw_info->linejoin == RoundJoin) || |
| 6009 | ((draw_info->linejoin == MiterJoin) && (closed_path != MagickFalse))) |
| 6010 | { |
| 6011 | polygon_primitive[number_vertices]=primitive_info[1]; |
| 6012 | number_vertices++; |
| 6013 | } |
| 6014 | polygon_primitive[number_vertices].primitive=UndefinedPrimitive; |
| 6015 | /* |
| 6016 | Compute the slope for the first line segment, p. |
| 6017 | */ |
| 6018 | dx.p=0.0; |
| 6019 | dy.p=0.0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6020 | for (n=1; n < (ssize_t) number_vertices; n++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6021 | { |
| 6022 | dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x; |
| 6023 | dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y; |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 6024 | if ((fabs(dx.p) >= DrawEpsilon) || (fabs(dy.p) >= DrawEpsilon)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6025 | break; |
| 6026 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6027 | if (n == (ssize_t) number_vertices) |
| 6028 | n=(ssize_t) number_vertices-1L; |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 6029 | slope.p=0.0; |
| 6030 | inverse_slope.p=0.0; |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 6031 | if (fabs(dx.p) < DrawEpsilon) |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 6032 | { |
| 6033 | if (dx.p >= 0.0) |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 6034 | slope.p=dy.p < 0.0 ? -1.0/DrawEpsilon : 1.0/DrawEpsilon; |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 6035 | else |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 6036 | slope.p=dy.p < 0.0 ? 1.0/DrawEpsilon : -1.0/DrawEpsilon; |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 6037 | } |
| 6038 | else |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 6039 | if (fabs(dy.p) < DrawEpsilon) |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 6040 | { |
| 6041 | if (dy.p >= 0.0) |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 6042 | inverse_slope.p=dx.p < 0.0 ? -1.0/DrawEpsilon : 1.0/DrawEpsilon; |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 6043 | else |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 6044 | inverse_slope.p=dx.p < 0.0 ? 1.0/DrawEpsilon : -1.0/DrawEpsilon; |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 6045 | } |
| 6046 | else |
| 6047 | { |
| 6048 | slope.p=dy.p/dx.p; |
| 6049 | inverse_slope.p=(-1.0/slope.p); |
| 6050 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6051 | mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0; |
Cristy | dd6065a | 2016-09-19 15:55:49 -0400 | [diff] [blame] | 6052 | miterlimit=(double) (draw_info->miterlimit*draw_info->miterlimit*mid*mid); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6053 | if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse)) |
| 6054 | TraceSquareLinecap(polygon_primitive,number_vertices,mid); |
| 6055 | offset.x=sqrt((double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0))); |
| 6056 | offset.y=(double) (offset.x*inverse_slope.p); |
| 6057 | if ((dy.p*offset.x-dx.p*offset.y) > 0.0) |
| 6058 | { |
| 6059 | box_p[0].x=polygon_primitive[0].point.x-offset.x; |
| 6060 | box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p; |
| 6061 | box_p[1].x=polygon_primitive[n].point.x-offset.x; |
| 6062 | box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p; |
| 6063 | box_q[0].x=polygon_primitive[0].point.x+offset.x; |
| 6064 | box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p; |
| 6065 | box_q[1].x=polygon_primitive[n].point.x+offset.x; |
| 6066 | box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p; |
| 6067 | } |
| 6068 | else |
| 6069 | { |
| 6070 | box_p[0].x=polygon_primitive[0].point.x+offset.x; |
| 6071 | box_p[0].y=polygon_primitive[0].point.y+offset.y; |
| 6072 | box_p[1].x=polygon_primitive[n].point.x+offset.x; |
| 6073 | box_p[1].y=polygon_primitive[n].point.y+offset.y; |
| 6074 | box_q[0].x=polygon_primitive[0].point.x-offset.x; |
| 6075 | box_q[0].y=polygon_primitive[0].point.y-offset.y; |
| 6076 | box_q[1].x=polygon_primitive[n].point.x-offset.x; |
| 6077 | box_q[1].y=polygon_primitive[n].point.y-offset.y; |
| 6078 | } |
| 6079 | /* |
| 6080 | Create strokes for the line join attribute: bevel, miter, round. |
| 6081 | */ |
| 6082 | p=0; |
| 6083 | q=0; |
| 6084 | path_q[p++]=box_q[0]; |
| 6085 | path_p[q++]=box_p[0]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6086 | for (i=(ssize_t) n+1; i < (ssize_t) number_vertices; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6087 | { |
| 6088 | /* |
| 6089 | Compute the slope for this line segment, q. |
| 6090 | */ |
| 6091 | dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x; |
| 6092 | dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y; |
| 6093 | dot_product=dx.q*dx.q+dy.q*dy.q; |
| 6094 | if (dot_product < 0.25) |
| 6095 | continue; |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 6096 | slope.q=0.0; |
| 6097 | inverse_slope.q=0.0; |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 6098 | if (fabs(dx.q) < DrawEpsilon) |
Cristy | 48bcfe0 | 2016-07-13 18:05:02 -0400 | [diff] [blame] | 6099 | { |
| 6100 | if (dx.q >= 0.0) |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 6101 | slope.q=dy.q < 0.0 ? -1.0/DrawEpsilon : 1.0/DrawEpsilon; |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 6102 | else |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 6103 | slope.q=dy.q < 0.0 ? 1.0/DrawEpsilon : -1.0/DrawEpsilon; |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 6104 | } |
Cristy | 48bcfe0 | 2016-07-13 18:05:02 -0400 | [diff] [blame] | 6105 | else |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 6106 | if (fabs(dy.q) < DrawEpsilon) |
Cristy | 48bcfe0 | 2016-07-13 18:05:02 -0400 | [diff] [blame] | 6107 | { |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 6108 | if (dy.q >= 0.0) |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 6109 | inverse_slope.q=dx.q < 0.0 ? -1.0/DrawEpsilon : 1.0/DrawEpsilon; |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 6110 | else |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 6111 | inverse_slope.q=dx.q < 0.0 ? 1.0/DrawEpsilon : -1.0/DrawEpsilon; |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 6112 | } |
| 6113 | else |
Cristy | 48bcfe0 | 2016-07-13 18:05:02 -0400 | [diff] [blame] | 6114 | { |
Cristy | 4280d54 | 2016-06-11 12:48:49 -0400 | [diff] [blame] | 6115 | slope.q=dy.q/dx.q; |
| 6116 | inverse_slope.q=(-1.0/slope.q); |
| 6117 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6118 | offset.x=sqrt((double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0))); |
| 6119 | offset.y=(double) (offset.x*inverse_slope.q); |
| 6120 | dot_product=dy.q*offset.x-dx.q*offset.y; |
| 6121 | if (dot_product > 0.0) |
| 6122 | { |
| 6123 | box_p[2].x=polygon_primitive[n].point.x-offset.x; |
| 6124 | box_p[2].y=polygon_primitive[n].point.y-offset.y; |
| 6125 | box_p[3].x=polygon_primitive[i].point.x-offset.x; |
| 6126 | box_p[3].y=polygon_primitive[i].point.y-offset.y; |
| 6127 | box_q[2].x=polygon_primitive[n].point.x+offset.x; |
| 6128 | box_q[2].y=polygon_primitive[n].point.y+offset.y; |
| 6129 | box_q[3].x=polygon_primitive[i].point.x+offset.x; |
| 6130 | box_q[3].y=polygon_primitive[i].point.y+offset.y; |
| 6131 | } |
| 6132 | else |
| 6133 | { |
| 6134 | box_p[2].x=polygon_primitive[n].point.x+offset.x; |
| 6135 | box_p[2].y=polygon_primitive[n].point.y+offset.y; |
| 6136 | box_p[3].x=polygon_primitive[i].point.x+offset.x; |
| 6137 | box_p[3].y=polygon_primitive[i].point.y+offset.y; |
| 6138 | box_q[2].x=polygon_primitive[n].point.x-offset.x; |
| 6139 | box_q[2].y=polygon_primitive[n].point.y-offset.y; |
| 6140 | box_q[3].x=polygon_primitive[i].point.x-offset.x; |
| 6141 | box_q[3].y=polygon_primitive[i].point.y-offset.y; |
| 6142 | } |
Cristy | 911b586 | 2016-06-24 17:45:06 -0400 | [diff] [blame] | 6143 | if (fabs((double) (slope.p-slope.q)) < DrawEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6144 | { |
| 6145 | box_p[4]=box_p[1]; |
| 6146 | box_q[4]=box_q[1]; |
| 6147 | } |
| 6148 | else |
| 6149 | { |
| 6150 | box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+ |
| 6151 | box_p[3].y)/(slope.p-slope.q)); |
| 6152 | box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y); |
| 6153 | box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+ |
| 6154 | box_q[3].y)/(slope.p-slope.q)); |
| 6155 | box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y); |
| 6156 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6157 | if (q >= (ssize_t) (max_strokes-6*BezierQuantum-360)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6158 | { |
Cristy | 726812f | 2016-05-04 19:09:35 -0400 | [diff] [blame] | 6159 | if (~max_strokes < (6*BezierQuantum+360)) |
| 6160 | { |
| 6161 | path_p=(PointInfo *) RelinquishMagickMemory(path_p); |
| 6162 | path_q=(PointInfo *) RelinquishMagickMemory(path_q); |
| 6163 | } |
| 6164 | else |
| 6165 | { |
| 6166 | max_strokes+=6*BezierQuantum+360; |
| 6167 | path_p=(PointInfo *) ResizeQuantumMemory(path_p,max_strokes, |
| 6168 | sizeof(*path_p)); |
| 6169 | path_q=(PointInfo *) ResizeQuantumMemory(path_q,max_strokes, |
| 6170 | sizeof(*path_q)); |
| 6171 | } |
| 6172 | if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL)) |
| 6173 | { |
| 6174 | if (path_p != (PointInfo *) NULL) |
| 6175 | path_p=(PointInfo *) RelinquishMagickMemory(path_p); |
| 6176 | if (path_q != (PointInfo *) NULL) |
| 6177 | path_q=(PointInfo *) RelinquishMagickMemory(path_q); |
| 6178 | polygon_primitive=(PrimitiveInfo *) |
| 6179 | RelinquishMagickMemory(polygon_primitive); |
| 6180 | return((PrimitiveInfo *) NULL); |
| 6181 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6182 | } |
| 6183 | dot_product=dx.q*dy.p-dx.p*dy.q; |
| 6184 | if (dot_product <= 0.0) |
| 6185 | switch (draw_info->linejoin) |
| 6186 | { |
| 6187 | case BevelJoin: |
| 6188 | { |
| 6189 | path_q[q++]=box_q[1]; |
| 6190 | path_q[q++]=box_q[2]; |
| 6191 | dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ |
| 6192 | (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); |
| 6193 | if (dot_product <= miterlimit) |
| 6194 | path_p[p++]=box_p[4]; |
| 6195 | else |
| 6196 | { |
| 6197 | path_p[p++]=box_p[1]; |
| 6198 | path_p[p++]=box_p[2]; |
| 6199 | } |
| 6200 | break; |
| 6201 | } |
| 6202 | case MiterJoin: |
| 6203 | { |
| 6204 | dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ |
| 6205 | (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); |
| 6206 | if (dot_product <= miterlimit) |
| 6207 | { |
| 6208 | path_q[q++]=box_q[4]; |
| 6209 | path_p[p++]=box_p[4]; |
| 6210 | } |
| 6211 | else |
| 6212 | { |
| 6213 | path_q[q++]=box_q[1]; |
| 6214 | path_q[q++]=box_q[2]; |
| 6215 | path_p[p++]=box_p[1]; |
| 6216 | path_p[p++]=box_p[2]; |
| 6217 | } |
| 6218 | break; |
| 6219 | } |
| 6220 | case RoundJoin: |
| 6221 | { |
| 6222 | dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ |
| 6223 | (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); |
| 6224 | if (dot_product <= miterlimit) |
| 6225 | path_p[p++]=box_p[4]; |
| 6226 | else |
| 6227 | { |
| 6228 | path_p[p++]=box_p[1]; |
| 6229 | path_p[p++]=box_p[2]; |
| 6230 | } |
| 6231 | center=polygon_primitive[n].point; |
| 6232 | theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x); |
| 6233 | theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x); |
| 6234 | if (theta.q < theta.p) |
Cristy | dd6065a | 2016-09-19 15:55:49 -0400 | [diff] [blame] | 6235 | theta.q+=2.0*MagickPI; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6236 | arc_segments=(size_t) ceil((double) ((theta.q-theta.p)/ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6237 | (2.0*sqrt((double) (1.0/mid))))); |
| 6238 | path_q[q].x=box_q[1].x; |
| 6239 | path_q[q].y=box_q[1].y; |
| 6240 | q++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6241 | for (j=1; j < (ssize_t) arc_segments; j++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6242 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 6243 | delta_theta=(double) (j*(theta.q-theta.p)/arc_segments); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6244 | path_q[q].x=(double) (center.x+mid*cos(fmod((double) |
| 6245 | (theta.p+delta_theta),DegreesToRadians(360.0)))); |
| 6246 | path_q[q].y=(double) (center.y+mid*sin(fmod((double) |
| 6247 | (theta.p+delta_theta),DegreesToRadians(360.0)))); |
| 6248 | q++; |
| 6249 | } |
| 6250 | path_q[q++]=box_q[2]; |
| 6251 | break; |
| 6252 | } |
| 6253 | default: |
| 6254 | break; |
| 6255 | } |
| 6256 | else |
| 6257 | switch (draw_info->linejoin) |
| 6258 | { |
| 6259 | case BevelJoin: |
| 6260 | { |
| 6261 | path_p[p++]=box_p[1]; |
| 6262 | path_p[p++]=box_p[2]; |
| 6263 | dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ |
| 6264 | (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); |
| 6265 | if (dot_product <= miterlimit) |
| 6266 | path_q[q++]=box_q[4]; |
| 6267 | else |
| 6268 | { |
| 6269 | path_q[q++]=box_q[1]; |
| 6270 | path_q[q++]=box_q[2]; |
| 6271 | } |
| 6272 | break; |
| 6273 | } |
| 6274 | case MiterJoin: |
| 6275 | { |
| 6276 | dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ |
| 6277 | (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); |
| 6278 | if (dot_product <= miterlimit) |
| 6279 | { |
| 6280 | path_q[q++]=box_q[4]; |
| 6281 | path_p[p++]=box_p[4]; |
| 6282 | } |
| 6283 | else |
| 6284 | { |
| 6285 | path_q[q++]=box_q[1]; |
| 6286 | path_q[q++]=box_q[2]; |
| 6287 | path_p[p++]=box_p[1]; |
| 6288 | path_p[p++]=box_p[2]; |
| 6289 | } |
| 6290 | break; |
| 6291 | } |
| 6292 | case RoundJoin: |
| 6293 | { |
| 6294 | dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ |
| 6295 | (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); |
| 6296 | if (dot_product <= miterlimit) |
| 6297 | path_q[q++]=box_q[4]; |
| 6298 | else |
| 6299 | { |
| 6300 | path_q[q++]=box_q[1]; |
| 6301 | path_q[q++]=box_q[2]; |
| 6302 | } |
| 6303 | center=polygon_primitive[n].point; |
| 6304 | theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x); |
| 6305 | theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x); |
| 6306 | if (theta.p < theta.q) |
Cristy | dd6065a | 2016-09-19 15:55:49 -0400 | [diff] [blame] | 6307 | theta.p+=2.0*MagickPI; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6308 | arc_segments=(size_t) ceil((double) ((theta.p-theta.q)/ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6309 | (2.0*sqrt((double) (1.0/mid))))); |
| 6310 | path_p[p++]=box_p[1]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6311 | for (j=1; j < (ssize_t) arc_segments; j++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6312 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 6313 | delta_theta=(double) (j*(theta.q-theta.p)/arc_segments); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6314 | path_p[p].x=(double) (center.x+mid*cos(fmod((double) |
| 6315 | (theta.p+delta_theta),DegreesToRadians(360.0)))); |
| 6316 | path_p[p].y=(double) (center.y+mid*sin(fmod((double) |
| 6317 | (theta.p+delta_theta),DegreesToRadians(360.0)))); |
| 6318 | p++; |
| 6319 | } |
| 6320 | path_p[p++]=box_p[2]; |
| 6321 | break; |
| 6322 | } |
| 6323 | default: |
| 6324 | break; |
| 6325 | } |
| 6326 | slope.p=slope.q; |
| 6327 | inverse_slope.p=inverse_slope.q; |
| 6328 | box_p[0]=box_p[2]; |
| 6329 | box_p[1]=box_p[3]; |
| 6330 | box_q[0]=box_q[2]; |
| 6331 | box_q[1]=box_q[3]; |
| 6332 | dx.p=dx.q; |
| 6333 | dy.p=dy.q; |
| 6334 | n=i; |
| 6335 | } |
| 6336 | path_p[p++]=box_p[1]; |
| 6337 | path_q[q++]=box_q[1]; |
| 6338 | /* |
| 6339 | Trace stroked polygon. |
| 6340 | */ |
| 6341 | stroke_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t) |
| 6342 | (p+q+2UL*closed_path+2UL),sizeof(*stroke_polygon)); |
| 6343 | if (stroke_polygon != (PrimitiveInfo *) NULL) |
| 6344 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6345 | for (i=0; i < (ssize_t) p; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6346 | { |
| 6347 | stroke_polygon[i]=polygon_primitive[0]; |
| 6348 | stroke_polygon[i].point=path_p[i]; |
| 6349 | } |
| 6350 | if (closed_path != MagickFalse) |
| 6351 | { |
| 6352 | stroke_polygon[i]=polygon_primitive[0]; |
| 6353 | stroke_polygon[i].point=stroke_polygon[0].point; |
| 6354 | i++; |
| 6355 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6356 | for ( ; i < (ssize_t) (p+q+closed_path); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6357 | { |
| 6358 | stroke_polygon[i]=polygon_primitive[0]; |
| 6359 | stroke_polygon[i].point=path_q[p+q+closed_path-(i+1)]; |
| 6360 | } |
| 6361 | if (closed_path != MagickFalse) |
| 6362 | { |
| 6363 | stroke_polygon[i]=polygon_primitive[0]; |
| 6364 | stroke_polygon[i].point=stroke_polygon[p+closed_path].point; |
| 6365 | i++; |
| 6366 | } |
| 6367 | stroke_polygon[i]=polygon_primitive[0]; |
| 6368 | stroke_polygon[i].point=stroke_polygon[0].point; |
| 6369 | i++; |
| 6370 | stroke_polygon[i].primitive=UndefinedPrimitive; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6371 | stroke_polygon[0].coordinates=(size_t) (p+q+2*closed_path+1); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6372 | } |
| 6373 | path_p=(PointInfo *) RelinquishMagickMemory(path_p); |
| 6374 | path_q=(PointInfo *) RelinquishMagickMemory(path_q); |
| 6375 | polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive); |
| 6376 | return(stroke_polygon); |
| 6377 | } |